UnityMol  0.9.6-875
UnityMol viewer / In developement
CubeManager.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEngine.Rendering;
3 
4 using System.Collections;
5 using System.Collections.Generic;
6 using UI;
7 using Molecule.Model;
8 
10  private BallUpdateCube[] cubes;
11  static public GameObject[] cubeGameObjects;
12 
13  public override void Init () {
14  cubes = GameObject.FindObjectsOfType(typeof(BallUpdateCube)) as BallUpdateCube[];
15  BallUpdate.resetColors = true;
16  BallUpdate.resetRadii = true;
17  enabled = true;
18  isInit = true;
19  }
20 
21  public override void DestroyAll() {
22  Debug.Log("Destroying Cubes");
23  cubes = GameObject.FindObjectsOfType(typeof(BallUpdateCube)) as BallUpdateCube[];
24  foreach(BallUpdateCube cb in cubes) {
25  GameObject.Destroy(cb.gameObject);
26  }
27  isInit = false;
28  }
29 
30  public override void ToggleDistanceCueing(bool enabling) {
31 
32  }
33 
37  private void ResetColors() {
38  if(UIData.atomtype == UIData.AtomType.cube){
39  foreach(BallUpdateCube bc in cubes)
40  bc.GetComponent<Renderer>().material.SetColor("_Color", Molecule.Model.MoleculeModel.atomsColorList[(int)bc.number]);
41 
42  BallUpdate.resetColors = false;
44  }
45  }
46 
47 
63  public override void SetColor(Color col, List<string> atom, string residue = "All", string chain = "All") {
64 // Debug.Log("SetColor cball");
65  if(!atom.Contains ("All")){
66  if(residue == "All"){
67  if(chain == "All"){
68  // ---------- ATOM
69 // Debug.Log("ATOM");
71  foreach(BallUpdateCube cb in cubes){
72  if(atom.Contains(cb.tag))
74  }
75  }else{
76  foreach(BallUpdateCube cb in cubes){
77  if(atom.Contains(Molecule.Model.MoleculeModel.atomsNamelist[(int)cb.number]))
79  }
80  }
81  }
82  else{
83  // ---------- ATOM + CHAIN
84 // Debug.Log("ATOM+CHAIN");
86  foreach(BallUpdateCube cb in cubes){
87  if(atom.Contains(cb.tag)
88  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
90  }
91  }else{
92  foreach(BallUpdateCube cb in cubes){
93  if(atom.Contains(Molecule.Model.MoleculeModel.atomsNamelist[(int)cb.number])
94  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
96  }
97  }
98  }
99  }
100  else{
101  if(chain == "All"){
102  // ---------- ATOM + RESIDUE
103 // Debug.Log("ATOM+RESIDUE");
105  foreach(BallUpdateCube cb in cubes){
106  if(atom.Contains(cb.tag)
107  && Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue)
109  }
110  }else{
111  foreach(BallUpdateCube cb in cubes){
112  if(atom.Contains(Molecule.Model.MoleculeModel.atomsNamelist[(int)cb.number])
113  && Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue)
115  }
116  }
117  }
118  else{
119  // ---------- ATOM + RESIDUE + CHAIN
120 // Debug.Log("ATOM+RESIDUE+CHAIN");
122  foreach(BallUpdateCube cb in cubes){
123  if(atom.Contains(cb.tag)
124  && Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue
125  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
127  }
128  }else{
129  foreach(BallUpdateCube cb in cubes){
130  if(atom.Contains(Molecule.Model.MoleculeModel.atomsNamelist[(int)cb.number])
131  && Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue
132  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
134  }
135  }
136  }
137  }
138  }
139  else{
140  if(residue == "All"){
141  if(chain == "All"){
142  // ---------- EVERYTHING
143 // Debug.Log("EVERYTHING");
144  foreach(BallUpdateCube cb in cubes)
146  }
147  else{
148  // ---------- CHAIN
149 // Debug.Log("CHAIN");
150  foreach(BallUpdateCube cb in cubes){
151  if(Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
153  }
154  }
155  }
156  else{
157  if(chain == "All"){
158  // ---------- RESIDUE
159 // Debug.Log("RESIDUE");
160  foreach(BallUpdateCube cb in cubes){
161  if(Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue){
163  }
164  }
165  }
166  else{
167  // ---------- CHAIN + RESIDUE
168 // Debug.Log("RESIDUE+CHAIN");
169  foreach(BallUpdateCube cb in cubes){
170  if(Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue
171  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
173  }
174  }
175  }
176  }
177 
178  BallUpdate.resetColors = true;
179  }
180 
181 
182 
192  public override void SetColor(Color col, int atomNum) {
193  foreach(BallUpdateCube bc in cubes){
194  if(bc.GetComponent<BallUpdate>().number == atomNum)
196  }
197  BallUpdate.resetColors = true;
198  }
199 
212  public override void SetRadii(List<string> atom, string residue = "All", string chain = "All") {
213  if(!atom.Contains ("All")){
214  if(residue == "All"){
215  if(chain == "All"){
216  // ---------- ATOM
218  foreach(BallUpdateCube cb in cubes) {
219  if(atom.Contains(cb.tag))
221  }
222  }else{
223  foreach(BallUpdateCube cb in cubes) {
224  if(atom.Contains(Molecule.Model.MoleculeModel.atomsNamelist[(int)cb.number]))
226  }
227  }
228  }
229  else{
230  // ---------- ATOM + CHAIN
232  foreach(BallUpdateCube cb in cubes) {
233  if(atom.Contains(cb.tag)
234  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
236  }
237  }else{
238  foreach(BallUpdateCube cb in cubes) {
239  if(atom.Contains(Molecule.Model.MoleculeModel.atomsNamelist[(int)cb.number])
240  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
242  }
243  }
244  }
245  }
246  else{
247  if(chain == "All"){
248  // ---------- ATOM + RESIDUE
250  foreach(BallUpdateCube cb in cubes) {
251  if(atom.Contains(cb.tag)
252  && Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue)
254  }
255  }else{
256  foreach(BallUpdateCube cb in cubes) {
257  if(atom.Contains(Molecule.Model.MoleculeModel.atomsNamelist[(int)cb.number])
258  && Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue)
260  }
261  }
262  }
263  else{
264  // ---------- ATOM + CHAIN + RESIDUE
266  foreach(BallUpdateCube cb in cubes) {
267  if(atom.Contains(cb.tag)
268  && Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue
269  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
271  }
272  }else{
273  foreach(BallUpdateCube cb in cubes) {
274  if(atom.Contains(Molecule.Model.MoleculeModel.atomsNamelist[(int)cb.number])
275  && Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue
276  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
278  }
279  }
280  }
281  }
282  }
283  else{
284  if(residue == "All"){
285  if(chain == "All"){
286  // ---------- EVERYTHING
287  foreach(BallUpdateCube cb in cubes) {
289  }
290  }
291  else{
292  // ---------- CHAIN
293  foreach(BallUpdateCube cb in cubes) {
294  if(Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
296  }
297  }
298  }
299  else{
300  if(chain == "All"){
301  // ---------- RESIDUE
302  foreach(BallUpdateCube cb in cubes) {
303  if(Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue)
305  }
306  }
307  else{
308  // ---------- CHAIN + RESIDUE
309  foreach(BallUpdateCube cb in cubes) {
310  if(Molecule.Model.MoleculeModel.atomsResnamelist[(int)cb.number] == residue
311  && Molecule.Model.MoleculeModel.atomsChainList[(int)cb.number] == chain)
313  }
314  }
315  }
316  }
317  BallUpdate.resetRadii = true;
319  }
320 
327  public override void SetRadii(int id) {
328  foreach(BallUpdateCube cb in cubes) {
329  if((int)cb.number == id)
331  }
332  BallUpdate.resetRadii = true;
334  }
335 
345  public Color GetColor(Vector3 pos){
346  foreach(BallUpdateCube cb in cubes)
347  if(cb.transform.position == pos)
348  return cb.GetComponent<Renderer>().material.GetColor("_Color");
349  return Color.white;
350  }
351 
361  public override GameObject GetBall(int id){
362  return cubes[id].gameObject;
363  }
364 
365  public override void DisableRenderers() {
367  {
369  }
370  foreach(BallUpdateCube bc in cubes){
371  bc.GetComponent<Renderer>().enabled = false;
372  if(UIData.atomtype != UIData.AtomType.particleball) // Particles don't have their own collider so we must keep it
373  bc.GetComponent<Collider>().enabled = false; // Disable the collider at the same time to avoid ghost-clicking with atom selection
374  }
375  enabled = false;
376  }
377 
378  public override void EnableRenderers() {
380  {
382  }
384  foreach(BallUpdateCube bc in cubes){
385  bc.GetComponent<Renderer>().enabled = true;
386  bc.GetComponent<Collider>().enabled = true;
387  }
388  enabled = true;
389  }
390 
391  public override void EnableShadows(){
392  foreach(BallUpdateCube bc in cubes){
393  bc.GetComponent<Renderer>().shadowCastingMode = ShadowCastingMode.On;
394  bc.GetComponent<Renderer>().receiveShadows = true;
395  }
396  }
397  public override void DisableShadows(){
398  foreach(BallUpdateCube bc in cubes){
399  bc.GetComponent<Renderer>().shadowCastingMode = ShadowCastingMode.Off;
400  bc.GetComponent<Renderer>().receiveShadows = false;
401  }
402  }
403 
404  public override void ResetRadii() {
405  if(UIData.atomtype == UIData.AtomType.cube){
406  foreach(BallUpdateCube cb in cubes) {
407  float buffer = Molecule.Model.MoleculeModel.atomsTypelist[(int)cb.number].radius
410  cb.transform.localScale = new Vector3(buffer, buffer, buffer);
411  }
413  BallUpdate.resetRadii = false;
414  }
415  }
416 
421  for (int i=0; i<cubeGameObjects.Length; i++) {
422  MouseOverMoleculeIMDSimulation mover = (MouseOverMoleculeIMDSimulation) cubeGameObjects[i].AddComponent<MouseOverMoleculeIMDSimulation>();
423  mover.setAtomId(i);
424  }
425  }
426 
431  for (int i=0; i<cubeGameObjects.Length; i++) {
432  Destroy(cubes[i].GetComponent<MouseOverMoleculeIMDSimulation>());
433  }
434  }
435 
436  // Update is called once per frame
437  void Update () {
438  if(UIData.atomtype != UIData.AtomType.cube) {
439  if(GameObject.FindObjectsOfType(typeof(BallUpdateCube)).Length >0) // Sometimes they're already destroyed at this point. Maybe. Can't hurt to make sure.
441  return;
442  }
443 
445  //Debug.Log("CUBE RESETCOLOR CALL" + UIData.atomtype);
446  ResetColors();
447  }
448 
450  ResetRadii();
451  }
452 
453  public override void ResetPositions(){
454  for (int j=0; j<cubes.Length; j++){
455  int i = (int)cubes[j].number;
456  cubes[j].transform.localPosition = new Vector3(MoleculeModel.atomsLocationlist[i][0],
459  }
460  }
461 
462  public override void ResetIMDSimulationPositions(){
463  for (int j=0; j<cubes.Length; j++){
464  int i = (int)cubes[j].number;
465  cubes[j].transform.localPosition = MoleculeModel.atomsIMDSimulationLocationlist[i];
466  }
467  }
468 
469  // Returns the closest atom game object in space from a given position during an IMD simulation.
471  BallUpdateCube closestAtom = cubes[0];
472  BallUpdateCube tempAtom;
473 
474  SingleAtomSelection selection = new SingleAtomSelection();
475 
476  float minDist = Vector3.Distance(closestAtom.gameObject.transform.position, position);
477  float tempDist;
478 
479  for (int i = 1; i < cubes.Length; i++) {
480  tempAtom = cubes[i];
481  tempDist = Vector3.Distance(tempAtom.gameObject.transform.position, position);
482  if (tempDist < minDist) {
483  minDist = tempDist;
484  closestAtom = tempAtom;
485  }
486  }
487 
488  selection.go = closestAtom.gameObject;
489  selection.pdbIndex = (int) closestAtom.number;
490 
491  return selection;
492  }
493 
494  public override void showHydrogens(bool hide) {
495  for (int j=0; j<cubes.Length; j++){
496  if (cubes[j].tag=="H")
497  cubes[j].GetComponent<Renderer>().enabled=!hide;
498  }
499  }
500 
501 }
static float newScale
Definition: GUIDisplay.cs:144
override void DestroyAll()
Definition: CubeManager.cs:21
BallUpdateCube[] cubes
Definition: CubeManager.cs:10
override void ToggleDistanceCueing(bool enabling)
Definition: CubeManager.cs:30
void CreateMouseOversIMDSimulation()
Creates the mouse overs, needed when IMD simulation and mouse interaction are required.
Definition: CubeManager.cs:420
override void ResetPositions()
Definition: CubeManager.cs:453
override void SetColor(Color col, int atomNum)
Sets the color of a specific atom.
Definition: CubeManager.cs:192
override void SetColor(Color col, List< string > atom, string residue="All", string chain="All")
Sets the color of atoms.
Definition: CubeManager.cs:63
static bool isFileLoaded
Definition: UIData.cs:115
override void Init()
Initializes this instance of the manager.
Definition: CubeManager.cs:13
static List< string > atomsNamelist
The name of each atom.
static List< string > atomsChainList
The chain of each atom.
static List< AtomModel > atomsTypelist
The type of each atom.
void ResetColors()
Resets the colors of all cubes and sticks.
Definition: CubeManager.cs:37
static bool resetColors
Definition: BallUpdate.cs:73
static List< Vector3 > atomsIMDSimulationLocationlist
The coordinates of each atom, simulated through an IMD simulation.
void Update()
Definition: CubeManager.cs:437
override void ResetIMDSimulationPositions()
Definition: CubeManager.cs:462
long number
Definition: BallUpdate.cs:84
override void DisableRenderers()
Disables the renderers for all objects managed by the instance of the manager.
Definition: CubeManager.cs:365
static void setCurrentAtomManager(GenericManager manager)
Definition: UnityMolMain.cs:63
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
override void ResetRadii()
Definition: CubeManager.cs:404
!WiP manage GUI, and provide static strings for the GUI.
Definition: GUIDisplay.cs:94
void DestroyMouseOversIMDSimulation()
Destroys the mouse overs
Definition: CubeManager.cs:430
static List< Color > atomsColorList
The color of each atom.
static float radiusFactor
Definition: BallUpdate.cs:81
override void showHydrogens(bool hide)
Definition: CubeManager.cs:494
override void EnableShadows()
Definition: CubeManager.cs:391
override void EnableRenderers()
Enables the renderers for all objects managed by the instance of the manager.
Definition: CubeManager.cs:378
static float oldRadiusFactor
Definition: BallUpdate.cs:82
Color GetColor(Vector3 pos)
Gets the color of the atom at the location "pos".
Definition: CubeManager.cs:345
static bool bondsReadyToBeReset
Definition: BallUpdate.cs:75
static AtomType atomtype
Definition: UIData.cs:139
static List< string > atomsResnamelist
The name of the residue to which each atom belongs.
static bool quickSelection
Definition: GUIDisplay.cs:157
override void DisableShadows()
Definition: CubeManager.cs:397
SingleAtomSelection getClosestAtomGameObject(Vector3 position)
Definition: CubeManager.cs:470
static GameObject[] cubeGameObjects
Definition: CubeManager.cs:11
override void SetRadii(int id)
Changes the scale for Atom selection.
Definition: CubeManager.cs:327
override GameObject GetBall(int id)
Gets the GameObject from cubes at the position "id".
Definition: CubeManager.cs:361
override void SetRadii(List< string > atom, string residue="All", string chain="All")
Changes the scale of the atoms.
Definition: CubeManager.cs:212
Definition: GUIDisplay.cs:66
static List< float > atomsLocalScaleList
static bool resetRadii
Definition: BallUpdate.cs:76
static List< float[]> atomsLocationlist
The coordinates of each atom.