UnityMol  0.9.6-875
UnityMol viewer / In developement
ClickAtom.cs
Go to the documentation of this file.
1 
66 using UnityEngine;
67 using System;
68 using System.Collections;
69 using System.Collections.Generic;
70 using UI;
71 using Molecule.Model;
72 
73 public class ClickAtom : MonoBehaviour
74 {
75  LineRenderer mLine;
76  public List<GameObject> objList = new List<GameObject>();
77 
78 
79  private LineRenderer line;
80  //public bool clicked;
81  //private float coordinate_x=-100;
82  //private float coordinate_y=-100;
83  //private float coordinate_x2=0;
84  //private float coordinate_y2=0;
85 
86  private float width=0;
87  private float height=0;
88  private List<GameObject> haloList = new List<GameObject>();
89 
90  private List<string> atominfoList = new List<string>();
91  private Camera mainCamera = null;
92 
93  void Start(){
94  mainCamera = Camera.main;
95  }
96 
97  void Update ()
98  {
99  if(mainCamera == null)
100  mainCamera = Camera.main;
101  if (Input.GetButtonDown ("Fire1") && GUIUtility.hotControl == 0)
102  {
103  Ray sRay= mainCamera.ScreenPointToRay (Input.mousePosition);
104  RaycastHit sHit;
105  long atomnumber=0;
106  GameObject obj;
107  GameObject halo;
108  string atominfo;
109 
110 
111  if (Physics.Raycast(sRay, out sHit))
112  {
113  Vector3 mousePos = Input.mousePosition;
114  mousePos.y = Screen.height - mousePos.y;
116  && Rectangles.colorPickerRect.Contains (mousePos))
117  return;
118 
119  obj = sHit.collider.gameObject;
120 
121 
122  if(UIData.atomtype == UIData.AtomType.optihb){
123  if(objList.IndexOf(obj) >= 0)
124  return;
125 
126  atominfo="";
127  Vector3 vl=new Vector3();
128  vl=obj.transform.localPosition;
129 
130  halo=Instantiate(Resources.Load("transparentsphere"),vl,new Quaternion(0f,0f,0f,0f)) as GameObject;
131  float rad =obj.GetComponent<SphereCollider>().radius*2;
132  halo.transform.localScale = new Vector3(rad+1,rad+1,rad+1);
133  halo.transform.parent = obj.transform;
134 
135  string toparse = obj.name.Split(new string[] {"Collider_Atom_"}, StringSplitOptions.None)[1];
136  atomnumber = int.Parse(toparse);//obj.GetComponent<BallUpdate>().number;
137 
138  List<float[]> alist=MoleculeModel.atomsLocationlist;
139 
140  float[] a=alist[(int)atomnumber];
141 
142  if(UI.GUIDisplay.file_extension=="xgmml")
143  {
144 
145  atominfo+="ID : "+(MoleculeModel.CSidList[(int)atomnumber])[0];
146  atominfo+=" || Label : "+ (MoleculeModel.CSLabelList[(int)atomnumber])[0];
147  atominfo+=" || X : "+ (a[0]-MoleculeModel.Offset.x)+" , Y : "+(a[1]-MoleculeModel.Offset.y)+" , Z : " + (a[2]-MoleculeModel.Offset.z);
148  atominfo+=" || Radius : "+ ((MoleculeModel.CSRadiusList[(int)atomnumber]))[0];
149  if(MoleculeModel.CSSGDList.Count>1)
150  {
151  atominfo+=" || SGD symbol : "+((MoleculeModel.CSSGDList[(int)atomnumber]))[0];
152  width=750;
153  }
154  else
155  {
156  width=600;
157  }
158 
159  height=25;
160 
161  }
162  else
163  {
164  atominfo+="X : "+(-(a[0]-MoleculeModel.Offset.x))+" , Y : "+(a[1]-MoleculeModel.Offset.y)+" , Z : "+(a[2]-MoleculeModel.Offset.z);
165  atominfo+=" || Type : " + (MoleculeModel.atomsTypelist[(int)atomnumber]).type;
166  atominfo+="("+ MoleculeModel.atomsNamelist[(int)atomnumber]+")";
167  atominfo+=" nb "+ MoleculeModel.atomsNumberList[(int)atomnumber];
168  atominfo+=" || RES "+MoleculeModel.residueIds[(int)atomnumber]+": " + MoleculeModel.atomsResnamelist[(int)atomnumber];
169  atominfo+=" || Chain : " + (MoleculeModel.atomsChainList[(int)atomnumber]);
170 
171  width=500;
172  height=25;
173  MoleculeModel.target = new Vector3(a[0],a[1],a[2]);
174  }
175 
176 
177  objList.Add(obj);
178  haloList.Add(halo);
179  atominfoList.Add(atominfo);
180 
181 
182 
183 
184  }
185  else{
186  if(obj.GetComponent<BallUpdate>() == null || objList.IndexOf(obj) >= 0)
187  return;
188 
189  atominfo="";
190 
191  Vector3 vl=new Vector3();
192 
193  vl=obj.GetComponent<Renderer>().transform.localPosition;
194 
195  //Destroy(halo);
196  halo=Instantiate(Resources.Load("transparentsphere"),vl,new Quaternion(0f,0f,0f,0f)) as GameObject;
197  float rad = obj.GetComponent<BallUpdate>().GetRealRadius();
198  halo.transform.localScale = new Vector3(rad+1,rad+1,rad+1);
199  halo.transform.parent = obj.transform;
200 
201  atomnumber = obj.GetComponent<BallUpdate>().number;
202 
203  List<float[]> alist=MoleculeModel.atomsLocationlist;
204 
205  float[] a=alist[(int)atomnumber];
206 
207  if(UI.GUIDisplay.file_extension=="xgmml")
208  {
209 
210  atominfo+="ID : "+(MoleculeModel.CSidList[(int)atomnumber])[0];
211  atominfo+=" || Label : "+ (MoleculeModel.CSLabelList[(int)atomnumber])[0];
212  atominfo+=" || X : "+ (a[0]-MoleculeModel.Offset.x)+" , Y : "+(a[1]-MoleculeModel.Offset.y)+" , Z : " + (a[2]-MoleculeModel.Offset.z);
213  atominfo+=" || Radius : "+ ((MoleculeModel.CSRadiusList[(int)atomnumber]))[0];
214  if(MoleculeModel.CSSGDList.Count>1)
215  {
216  atominfo+=" || SGD symbol : "+((MoleculeModel.CSSGDList[(int)atomnumber]))[0];
217  width=750;
218  }
219  else
220  {
221  width=600;
222  }
223 
224  height=25;
225 
226  }
227  else
228  {
229  atominfo+="X : "+(-(a[0]-MoleculeModel.Offset.x))+" , Y : "+(a[1]-MoleculeModel.Offset.y)+" , Z : "+(a[2]-MoleculeModel.Offset.z);
230  atominfo+=" || Type : " + (MoleculeModel.atomsTypelist[(int)atomnumber]).type;
231  atominfo+="("+ MoleculeModel.atomsNamelist[(int)atomnumber]+")";
232  atominfo+=" nb "+ MoleculeModel.atomsNumberList[(int)atomnumber];
233  atominfo+=" || RES "+MoleculeModel.residueIds[(int)atomnumber]+": " + MoleculeModel.atomsResnamelist[(int)atomnumber];
234  atominfo+=" || Chain : " + (MoleculeModel.atomsChainList[(int)atomnumber]);
235 
236  width=500;
237  height=25;
238  // Debug.Log(atominfo);
239  MoleculeModel.target = new Vector3(a[0],a[1],a[2]);
240  }
241 
242  // coordinate_x= Input.mousePosition.x + 5;
243  // coordinate_y= Screen.height-Input.mousePosition.y + 20;
244  // coordinate_x2= Input.mousePosition.x ;
245  // coordinate_y2= Screen.height-Input.mousePosition.y ;
246 
247  objList.Add(obj);
248  haloList.Add(halo);
249  atominfoList.Add(atominfo);
250 
251  //clicked = true;
252  }
253  }
254  }
255 
256 
257  if (Input.GetButtonDown("Fire2") && GUIUtility.hotControl == 0)
258  {
259  Ray sRay= mainCamera.ScreenPointToRay (Input.mousePosition);
260  RaycastHit sHit;
261  GameObject obj;
262 
263  if (Physics.Raycast(sRay, out sHit))
264  {
265  obj = sHit.collider.gameObject;
266  if(obj.name != "transparentsphere(Clone)")
267  return;
268  int spot = haloList.IndexOf(obj);
269  Destroy(haloList[spot]);
270  objList.RemoveAt(spot);
271  haloList.RemoveAt(spot);
272  atominfoList.RemoveAt(spot);
273  //clicked = false;
274  }
275  }
276  }
277 
278  void OnGUI()
279  {
280  if(/*clicked &&*/ atominfoList.Count > 0)
281  {
282  for(int i=0; i < atominfoList.Count; i++){
283  Vector3 pos = mainCamera.WorldToScreenPoint(objList[i].transform.position);
284  GUI.Box(new Rect (pos.x + 5, Screen.height - pos.y + 20, width, height),atominfoList[i]);}
285  }
286 
287  }
288 
289  void OnDisable()
290  {
291  //clicked = false;
292  ClearSelection();
293  }
294 
295  public void ClearSelection()
296  {
297  foreach(GameObject halo in haloList)
298  Destroy(halo);
299  objList.Clear();
300  haloList.Clear();
301  atominfoList.Clear();
302  }
303 }
void OnGUI()
Definition: ClickAtom.cs:278
bool enabled
Definition: ColorPicker.cs:98
static Rect colorPickerRect
Definition: Rectangles.cs:246
static ColorPicker m_colorPicker
static Vector3 Offset
The offset for the molecule.
List< string > atominfoList
Definition: ClickAtom.cs:90
static List< string > atomsNamelist
The name of each atom.
static List< string > atomsChainList
The chain of each atom.
void Start()
Definition: ClickAtom.cs:93
static List< AtomModel > atomsTypelist
The type of each atom.
static List< int > residueIds
The residue identifiers.
float height
Definition: ClickAtom.cs:87
static List< float[]> CSRadiusList
static List< int[]> CSidList
Camera mainCamera
Definition: ClickAtom.cs:91
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
float width
Definition: ClickAtom.cs:86
LineRenderer mLine
Definition: ClickAtom.cs:75
LineRenderer line
Definition: ClickAtom.cs:79
!WiP manage GUI, and provide static strings for the GUI.
Definition: GUIDisplay.cs:94
static string file_extension
Definition: GUIDisplay.cs:121
void Update()
Definition: ClickAtom.cs:97
static AtomType atomtype
Definition: UIData.cs:139
void OnDisable()
Definition: ClickAtom.cs:289
static List< int > atomsNumberList
The number of each atoms (in the PDB file)
static List< string > atomsResnamelist
The name of the residue to which each atom belongs.
static List< string[]> CSLabelList
List< GameObject > objList
Definition: ClickAtom.cs:76
List< GameObject > haloList
Definition: ClickAtom.cs:88
static List< string[]> CSSGDList
void ClearSelection()
Definition: ClickAtom.cs:295
Definition: GUIDisplay.cs:66
static List< float[]> atomsLocationlist
The coordinates of each atom.