UnityMol  0.9.6-875
UnityMol viewer / In developement
SugarManager.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 using System.Collections.Generic;
4 using Molecule.Model;
5 using UI;
6 
7 public class SugarManager {
8 
9 
10  //Parameters for SugarRibbons
11  public static float RibbonsThickness = 0.15f;
12  public static float OxySphereSize = 1f;
13  public static float OxySphereSizeCheck = 1f;
14  public static float thickness_Little=1.8f;
15  public static float thickness_BIG=1f;
16  public static float thickness_bond_6_C1_C4=0.2f;
17  public static float thickness_6_other=0.16f;
18  public static float thickness_bond_5=0.2f;
19  public static float lighter_color_factor_bond=0.35f;
20  public static float lighter_color_factor_bond_check=0.35f;
21  public static float lighter_color_factor_ring=0.35f;
22  public static float lighter_color_factor_ring_check=0.35f;
23  public static int ColorationModeRing=0;
24  public static int ColorationModeBond=0;
25 
26  //definition of sugarRibons and RingBlending, to avoid create them to each frame
27  public static SugarRibbons SR;
28  public static RingBlending ringblending;
29 
30  public static ColorObject BondColor = new ColorObject(Color.black);
31  public static ColorObject BondColorcheck = new ColorObject(Color.black);
32  public static ColorObject RingColor = new ColorObject(Color.black);
33  public static ColorObject OxySphereColor = new ColorObject(Color.red);
34  public static ColorObject OxySphereColorCheck = new ColorObject(Color.red);
35  public static ColorObject RingColorcheck = new ColorObject(Color.black);
36 
37  private static List<GameObject> ringBlendingList = new List<GameObject>();
38 
39  public static List<GameObject> sugarRibsBigList = new List<GameObject>();
40  public static List<GameObject> sugarRibsLittleList = new List<GameObject>();
41  public static List<GameObject> sugarRibsBondList = new List<GameObject>();
42 
43  private static List<GameObject> oxySphereList = new List<GameObject>();
44 
45 
46  public static void CreateRingBlending(){
47  if(ringblending == null)
48  ringblending = new RingBlending();
49  ringBlendingList.AddRange(ringblending.CreateRingBlending());
50  }
51  public static void DestroyRingBlending(){
52  for(int i=0;i<ringBlendingList.Count;i++)
53  GameObject.Destroy(ringBlendingList[i]);
54  ringBlendingList.Clear();
55  }
56 
57  public static void CreateSugarRibs(bool sugaronly){
58 
59  SR = new SugarRibbons(sugaronly);
60 
61  List<List<GameObject>> allrings = SR.createSugarRibs(RibbonsThickness, sugaronly, thickness_Little, thickness_BIG,
62  thickness_bond_6_C1_C4, thickness_6_other, thickness_bond_5, lighter_color_factor_ring, lighter_color_factor_bond,
63  ColorationModeRing, ColorationModeBond, BondColor, RingColor, OxySphereSize,OxySphereColor);
64 
65  sugarRibsLittleList.AddRange(allrings[0]);
66  sugarRibsBigList.AddRange(allrings[1]);
67  sugarRibsBondList.AddRange(allrings[2]);
68 
69  //Initialize bond & ring color to an "empty" color.
70  BondColorcheck.color=Color.white;
71  BondColor.color=Color.white;
72  RingColorcheck.color = Color.white;
73  RingColor.color = Color.white;
74  OxySphereColorCheck.color = Color.red;
75 
76  }
77 
78  public static void DestroySugarRibs(){
79  if(SR != null)
80  SR.cleanup();
81  for(int i=0;i<sugarRibsBigList.Count;i++)
82  GameObject.Destroy(sugarRibsBigList[i]);
83  sugarRibsBigList.Clear();
84  for(int i=0;i<sugarRibsLittleList.Count;i++)
85  GameObject.Destroy(sugarRibsLittleList[i]);
86  sugarRibsLittleList.Clear();
87  for(int i=0;i<sugarRibsBondList.Count;i++)
88  GameObject.Destroy(sugarRibsBondList[i]);
89  sugarRibsBondList.Clear();
90  }
91 
92  public static void ShowOxySphere(int colotype=0){
93  oxySphereList.AddRange(SR.ShowOxySphere(colotype));
94  }
95  public static void ShowRingOxySphere(){
96  oxySphereList.AddRange(ringblending.ShowOxySphere());
97  }
98  public static void DestroyOxySphere(){
99  for(int i=0;i<oxySphereList.Count;i++)
100  GameObject.Destroy(oxySphereList[i]);
101  oxySphereList.Clear();
102  }
103 
104  public static void UpdateOxySphereSize(){
105  for(int i=0;i<oxySphereList.Count;i++)
106  oxySphereList[i].transform.localScale = new Vector3(OxySphereSize, OxySphereSize, OxySphereSize);
107  }
108 
109  public static void UpdateOxySphereColor(){
110  for(int i=0;i<oxySphereList.Count;i++)
111  oxySphereList[i].GetComponent<Renderer>().material.color = OxySphereColor.color;
112  }
113  public static int OxySphereCount(){
114  return oxySphereList.Count;
115  }
116 
117  public static void UpdateSugarRibsRingColor(int mode = -1){
118 
119  if(mode == -1)
120  SR.updateColorRing(sugarRibsBigList,RingColor);
121  else
122  SR.updateColorRing(sugarRibsBigList,ColorationModeRing);
123  }
124  public static void UpdateSugarRibsBondColor(int mode = -1){
125  if(mode == -1)
126  SR.updateColorBond(sugarRibsBondList,BondColor);
127  else
128  SR.updateColorBond(sugarRibsBondList,ColorationModeBond);
129  }
130 
132 
133  RibbonsThickness=0.15f;
134  thickness_Little=1.8f;
135  thickness_BIG=1f;
136  thickness_bond_6_C1_C4=0.2f;
137  thickness_6_other=0.16f;
138  thickness_bond_5=0.2f;
139  lighter_color_factor_ring=0.35f;
140  lighter_color_factor_bond=0.35f;
141  ColorationModeRing=0;
142  ColorationModeBond=0;
143  OxySphereSize=1f;
144  OxySphereColor.color=Color.red;
145  lighter_color_factor_bond=0.35f;
146  lighter_color_factor_ring=0.35f;
147 
149  }
150 
151  public static void ResetSugarRibbons(bool sugaronly=false){
153 
155 
156  // Recreating them
157  CreateSugarRibs(sugaronly);
158 
159 
161 
162 
165  SR.ShowOxySphere (0);
166 
167  }
168  }
169 
170 
171 
172  public static void show_HyperBalls_Sugar(bool show){
173  //Dirty fix for 0.9.6 release => TODO add a function HideAtom in all managers
174 
175  if(UI.UIData.atomtype == UI.UIData.AtomType.hyperball && UI.UIData.bondtype == UI.UIData.BondType.hyperstick){
176  int i=0;
177  for (i=0; i<HBallManager.hballs.Length; i++){
178  int atom_number =(int) HBallManager.hballs[i].GetComponent<BallUpdate>().number;
179  if (MoleculeModel.sugarResname.Contains(MoleculeModel.atomsResnamelist[atom_number])){
180  HBallManager.hballs[i].GetComponent<Renderer>().enabled=show;
181  }
182  if (i<HStickManager.sticks.Length){
183 
186  HStickManager.sticks[i].GetComponent<Renderer>().enabled=show;
187  }
188  }
189  //If we didn't finish to check the bond list (more bond than atoms)
190  //we check the end of the list.
191  while(i<HStickManager.sticks.Length){
194  HStickManager.sticks[i].GetComponent<Renderer>().enabled=show;
195  i++;
196  }
197  }
198  if(UI.UIData.atomtype == UI.UIData.AtomType.optihb && UI.UIData.bondtype == UI.UIData.BondType.optihs){
199  GameObject hbmeshManagerObj = GameObject.FindGameObjectWithTag("HBallMeshManager");
200  HBallMeshManager hbmeshManager = hbmeshManagerObj.GetComponent<HBallMeshManager>();
201  GameObject hStickMeshManagerObj = GameObject.FindGameObjectWithTag("HStickMeshManager");
202  HStickMeshManager hStickMeshManager = hStickMeshManagerObj.GetComponent<HStickMeshManager>();
203 
204  hbmeshManager.ResetVisibility();
205  hStickMeshManager.ResetVisibility();
206 
207  for(int i=0;i<MoleculeModel.atomsTypelist.Count;i++){
209  hbmeshManager.hideAtom(i,show);
210  hStickMeshManager.hideBondForAtom(i,show);
211  }
212  }
213  hbmeshManager.ApplyTextures();
214  hStickMeshManager.ApplyTextures();
215 
216  }
217  }
218 
219  /*This fonction is made to hide hyperballs which are not Sugar Atoms*/
220  public static void Hide_No_Sugar_Hyperballs(bool show){
221  //Dirty fix for 0.9.6 release => TODO add a function HideAtom in all managers
222 
223  if(UI.UIData.atomtype == UI.UIData.AtomType.hyperball && UI.UIData.bondtype == UI.UIData.BondType.hyperstick){
224  int i=0;
225  for (i=0; i<HBallManager.hballs.Length; i++){
226  int atom_number =(int) HBallManager.hballs[i].GetComponent<BallUpdate>().number;
227  if (!MoleculeModel.sugarResname.Contains(MoleculeModel.atomsResnamelist[atom_number])){
228  HBallManager.hballs[i].GetComponent<Renderer>().enabled=show;
229  }
230  if (i<HStickManager.sticks.Length){
231 
234  HStickManager.sticks[i].GetComponent<Renderer>().enabled=show;
235  }
236  }
237  //If we didn't finish to check the bond list (more bond than atoms)
238  //we check the end of the list.
239  while(i<HStickManager.sticks.Length){
242  HStickManager.sticks[i].GetComponent<Renderer>().enabled=show;
243  i++;
244  }
245  }
246  if(UI.UIData.atomtype == UI.UIData.AtomType.optihb && UI.UIData.bondtype == UI.UIData.BondType.optihs){
247  GameObject hbmeshManagerObj = GameObject.FindGameObjectWithTag("HBallMeshManager");
248  HBallMeshManager hbmeshManager = hbmeshManagerObj.GetComponent<HBallMeshManager>();
249  GameObject hStickMeshManagerObj = GameObject.FindGameObjectWithTag("HStickMeshManager");
250  HStickMeshManager hStickMeshManager = hStickMeshManagerObj.GetComponent<HStickMeshManager>();
251  hbmeshManager.ResetVisibility();
252  hStickMeshManager.ResetVisibility();
253 
254  for(int i=0;i<MoleculeModel.atomsTypelist.Count;i++){
256  hbmeshManager.hideAtom(i,show);
257  hStickMeshManager.hideBondForAtom(i,show);
258  }
259  }
260  hbmeshManager.ApplyTextures();
261  hStickMeshManager.ApplyTextures();
262  }
263 
264  }
265 
266 
267 
268 }
static void UpdateOxySphereSize()
static void ShowRingOxySphere()
Definition: SugarManager.cs:95
static void CreateRingBlending()
Definition: SugarManager.cs:46
static StickUpdate[] sticks
static void DestroyOxySphere()
Definition: SugarManager.cs:98
static int ColorationModeBond
Definition: SugarManager.cs:24
static float OxySphereSizeCheck
Definition: SugarManager.cs:13
void hideAtom(int idAtom, bool show)
static void ResetSugarRibbons(bool sugaronly=false)
static float lighter_color_factor_bond
Definition: SugarManager.cs:19
static void DestroySugarRibs()
Definition: SugarManager.cs:78
static float thickness_6_other
Definition: SugarManager.cs:17
static bool toggle_OXYGEN
Definition: SugarOldGUI.cs:18
static float thickness_bond_6_C1_C4
Definition: SugarManager.cs:16
static void UpdateSugarRibsBondColor(int mode=-1)
static void ShowOxySphere(int colotype=0)
Definition: SugarManager.cs:92
static void show_HyperBalls_Sugar(bool show)
this class is made to fill cycle inside a molecule with a semi-transparent polygon to have a effect o...
Definition: RingBlending.cs:15
static void UpdateSugarRibsRingColor(int mode=-1)
static void DestroyRingBlending()
Definition: SugarManager.cs:51
static ColorObject OxySphereColorCheck
Definition: SugarManager.cs:34
List< GameObject > CreateRingBlending()
This function will convert the molecule to a "graph" (an object "GraphVertex" is made from each atoms...
Definition: RingBlending.cs:99
static ColorObject RingColorcheck
Definition: SugarManager.cs:35
static List< AtomModel > atomsTypelist
The type of each atom.
Color color
Definition: ColorObject.cs:72
List< GameObject > ShowOxySphere()
int atomnumber1
Definition: StickUpdate.cs:85
static int OxySphereCount()
static ColorObject BondColor
Definition: SugarManager.cs:30
static float RibbonsThickness
Definition: SugarManager.cs:11
static BallUpdateHB[] hballs
Definition: HBallManager.cs:77
List< List< GameObject > > createSugarRibs(float RibbonsThickness, bool sugarOnly, float thickness_Little, float thickness_BIG, float thickness_bond_6_C1_C4, float thickness_6_other, float thickness_bond_5, float lighter_color_factor_ring, float lighter_color_factor_bond, int color_mode_ring, int color_mode_bond, ColorObject bondcolor, ColorObject ringcolor, float OxySphereSize, ColorObject OxySphereColor)
int atomnumber2
Definition: StickUpdate.cs:86
static void CreateSugarRibs(bool sugaronly)
Definition: SugarManager.cs:57
static float lighter_color_factor_bond_check
Definition: SugarManager.cs:20
long number
Definition: BallUpdate.cs:84
static float thickness_bond_5
Definition: SugarManager.cs:18
void hideBondForAtom(int idAtom, bool show)
static float lighter_color_factor_ring
Definition: SugarManager.cs:21
static List< GameObject > ringBlendingList
Definition: SugarManager.cs:37
List< GameObject > ShowOxySphere(int colortype)
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
static BondType bondtype
Definition: UIData.cs:141
static List< GameObject > sugarRibsBondList
Definition: SugarManager.cs:41
static ColorObject RingColor
Definition: SugarManager.cs:32
static void UpdateOxySphereColor()
static ColorObject OxySphereColor
Definition: SugarManager.cs:33
static AtomType atomtype
Definition: UIData.cs:139
static List< GameObject > sugarRibsLittleList
Definition: SugarManager.cs:40
static void ResetDefaultParametersSugarRibbons()
static List< string > atomsResnamelist
The name of the residue to which each atom belongs.
static RingBlending ringblending
Definition: SugarManager.cs:28
void updateColorRing(List< GameObject > objs, ColorObject newColor)
static List< string > sugarResname
static float thickness_BIG
Definition: SugarManager.cs:15
static float lighter_color_factor_ring_check
Definition: SugarManager.cs:22
static float thickness_Little
Definition: SugarManager.cs:14
static List< GameObject > sugarRibsBigList
Definition: SugarManager.cs:39
static void Hide_No_Sugar_Hyperballs(bool show)
static float OxySphereSize
Definition: SugarManager.cs:12
static int ColorationModeRing
Definition: SugarManager.cs:23
void updateColorBond(List< GameObject > objs, ColorObject newColor)
static ColorObject BondColorcheck
Definition: SugarManager.cs:31
static List< GameObject > oxySphereList
Definition: SugarManager.cs:43
Definition: GUIDisplay.cs:66
static SugarRibbons SR
Definition: SugarManager.cs:27