UnityMol  0.9.6-875
UnityMol viewer / In developement
ControlMolecule.cs
Go to the documentation of this file.
1 using System.Text;
66 
67 namespace Molecule.Control {
68  using UnityEngine;
69  using System.Collections;
70  using System.Collections.Generic;
71  using System.IO;
72  using Molecule.Model;
73  using ParseData.ParsePDB;
74  using UI;
75 
76  public class ControlMolecule {
77 
78  public ControlMolecule() {}
79 
80 
81  public static void CreateResidues() {
82  List<float[]> alist = MoleculeModel.atomsLocationlist;
83  List<string> aNamesList = MoleculeModel.atomsNamelist;
84  List<int> residueIds = MoleculeModel.residueIds;
85 
86  // List<string> resNamesPerResidue = new List<string>();
87  // List<Vector3> residues = new List<Vector3>();
88  List<Dictionary<string, Vector3>> residueDictList = new List<Dictionary<string, Vector3>>();
89  Dictionary<string, Vector3> residueDict = new Dictionary<string, Vector3>();
90 
91  // int nbAtoms = 0f;
92  // Vector3 currAtomSum = Vector3.zero;
93  Vector3 currAtom = Vector3.zero;
94 
95  int currResId = int.MinValue+1;
96  int prevResId = int.MinValue+1;
97 
98  Vector3 testVector = Vector3.zero;
99 
100  int index=0;
101  for(int i=0; i<alist.Count; i++) {
102 
103  currResId = residueIds[i];
104  // New residue encountered
105  // if(!string.Equals(currRes, prevRes)) {
106  // resNamesPerResidue.Add(prevRes);
107  // currAtomSum *= (1f/nbAtoms);
108  // residues.Add(currAtomSum);
109  // currAtomSum = Vector3.zero;
110  // nbAtoms = 0;
111  // }
112 
113  if(currResId != prevResId) {
114  if(residueDict != null && residueDict.Count > 0){
115  residueDictList.Add(residueDict);
116  }
117  residueDict = new Dictionary<string, Vector3>();
118  index++;
119 
120  }
121  prevResId = currResId;
122 
123  // We flip the x-coordinates because Unity is right-handed
124  currAtom = new Vector3(-alist[i][0], alist[i][1], alist[i][2]);// - MoleculeModel.Offset;
125  // currAtomSum += currAtom;
126  //Debug.Log(aNamesList[i] + ": " + currAtom.ToString());
127  //Debug.Log(currResId.ToString() + " :: " + prevResId.ToString());
128  // Sometimes there are multiple conformations for a residue in a PDB
129  // therefore multiple atoms of the same type. That generates collisions
130  // in the dictionary. C# doesn't like that.
131  if(!residueDict.TryGetValue(aNamesList[i], out testVector)){
132  residueDict.Add(aNamesList[i], currAtom);
133  }
134  else{
135  Debug.Log("Bizarre");
136  }
137  // nbAtoms ++;
138 
139 
140  }
141  MoleculeModel.residueDictionaries = residueDictList;
142 
143  /*
144  for(int i=0; i<residues.Count; i++) {
145  Debug.Log("Residue " + resNamesPerResidue[i] + ": " + residues[i].ToString());
146  }
147  */
148  Debug.Log(residueDictList.Count+" residues in the molecule");
149  }
150 
151  public static void CreateResiduesSugar2(){
152  List<float[]> alist = MoleculeModel.atomsLocationlist;
153  List<string> aNamesList = MoleculeModel.atomsNamelist;
154  List<int> residueIds = MoleculeModel.residueIds;
155 
156 
157  List<Dictionary<string, Vector3>> residueDictList = new List<Dictionary<string, Vector3>>();
158  Dictionary<string, Vector3> residueDict = new Dictionary<string, Vector3>();
159 
160  Vector3 currAtom;
161  Vector3 testVector;
162 
163  for (int i = 0 ; i<alist.Count; i++){
164 
165  if((i==alist.Count-1) || (residueIds[i] != residueIds[i+1])){
166  if(residueDict != null && residueDict.Count > 0){
167  residueDictList.Add(residueDict);
168  }
169  residueDict = new Dictionary<string, Vector3>();
170  }
171 
172  currAtom = new Vector3(-alist[i][0], alist[i][1], alist[i][2]);
173 
174  if(!residueDict.TryGetValue(aNamesList[i], out testVector)){
175  residueDict.Add(aNamesList[i], currAtom);
176  }
177  }
178 
179  MoleculeModel.residueDictionariesSugar = residueDictList;
180 
181  }
182 
186  public static void CheckHiRERNAModel()
187  {
188  Debug.Log("CheckHiRERNAModel");
189  if (MoleculeModel.atomsNamelist.Exists(x => x == "C1" || x == "G1" || x == "G2" || x == "U1" || x == "A1" || x == "A2"))
190  {
191  UIData.ffType = UIData.FFType.HiRERNA;
192  UIData.loadHireRNA = true;
193  }
194  Debug.Log (UIData.loadHireRNA);
195  }
196 
198  {
199  foreach (KeyValuePair<int, ArrayList> entry in MoleculeModel.residues)
200  {
201  int nbOfAtoms = entry.Value.Count;
202  int i = 0;
203  while (i != nbOfAtoms)
204  {
205  int atomIndex = (int)entry.Value[i];
206  string atomName = MoleculeModel.atomsNamelist[atomIndex];
207  if (atomName == "C1" || atomName == "G2" || atomName == "U1" || atomName == "A2")
208  {
209  MoleculeModel.baseIdx.Add(atomIndex);
210  i = nbOfAtoms;
211  }
212  else
213  {
214  i++;
215  }
216  }
217  }
218 
219  string filename = GUIDisplay.directorypath + "/scale_RNA.dat";
220  if (File.Exists(filename)) {
221  StreamReader sr = new StreamReader(filename);
222  string s;
223  // Debug.Log ("------------");
224  float num;
225  int t = 0;
226  string substr;
227  while((s=sr.ReadLine())!=null) {
228  substr = s.Substring (7, 10);
229  // Debug.Log(substr);
230  num = float.Parse(substr);
231  // Debug.Log ("Scale RNA " + t + " " + num);
232  MoleculeModel.scale_RNA.Add(num);
233  t++;
234  }
235  Debug.Log (MoleculeModel.scale_RNA.Count);
236  }
238 // Debug.Log ("------------");
239  }
240 
245  public static void BuildMoleculeComponents() {
246 
247  UpdateMoleculeCenter();
248 
249  if (UIData.ffType == UIData.FFType.HiRERNA) {
251  } else {
253  }
257 
258  //TODO : Do something smarter
259  int cptH = 0,cptC = 0,cptO = 0,cptN = 0,cptS = 0,cptP = 0,cptX = 0;
260  for(int i=0;i<MoleculeModel.atomsTypelist.Count;i++){
261  string atomType = MoleculeModel.atomsTypelist[i].type;
262  if(atomType == "H")
263  cptH ++;
264  else if(atomType == "C")
265  cptC ++;
266  else if(atomType == "O")
267  cptO ++;
268  else if(atomType == "N")
269  cptN ++;
270  else if(atomType == "S")
271  cptS ++;
272  else if(atomType == "P")
273  cptP ++;
274  else
275  cptX ++;
276  }
277  MoleculeModel.hydrogenNumber = cptH.ToString();
278  MoleculeModel.carbonNumber = cptC.ToString();
279  MoleculeModel.oxygenNumber = cptO.ToString();
280  MoleculeModel.nitrogenNumber = cptN.ToString();
281  MoleculeModel.sulphurNumber = cptS.ToString();
282  MoleculeModel.phosphorusNumber = cptP.ToString();
283  MoleculeModel.unknownNumber = cptX.ToString();
284 
285 
286 
287 
288 
289  } // End of BuildMoleculeComponents
290 
291  public static void UpdateMoleculeCenter(){
292 
293  List<float[]> alist = MoleculeModel.atomsLocationlist;
294  List<float[]> alistSugar = MoleculeModel.atomsSugarLocationlist;
295  List<float[]> calist = MoleculeModel.CatomsLocationlist;
296 
297 
298  //Compute barycenter
299  Vector3 minPoint= new Vector3(float.MaxValue,float.MaxValue,float.MaxValue);
300  Vector3 maxPoint= new Vector3(float.MinValue,float.MinValue,float.MinValue);
301  Vector3 bary = Vector3.zero;
302 
303  for(int i=0; i<alist.Count; i++) {
304  float[] position= alist[i];
305  minPoint = Vector3.Min(minPoint, new Vector3(position[0],position[1],position[2]));
306  maxPoint = Vector3.Max(maxPoint, new Vector3(position[0],position[1],position[2]));
307  bary = bary+(new Vector3(position[0],position[1],position[2]));
308  }
309  Vector3 centerPoint = bary/alist.Count;
310  MoleculeModel.target = Vector3.zero;
311  Debug.Log("centerPoint:"+centerPoint + " min/max " + minPoint + "/" + maxPoint);
312 
313  MoleculeModel.Offset = -centerPoint;
314 
315  bary = Vector3.zero;
316  Debug.Log("alist.Count:"+alist.Count);
317  for(int i=0; i<alist.Count; i++) {
318  float[] position= alist[i];
319  //AurĂ©lien : changed vect size
320  float[] vect=new float[4];
321  vect[0]=position[0]+MoleculeModel.Offset.x;
322  vect[1]=position[1]+MoleculeModel.Offset.y;
323  vect[2]=position[2]+MoleculeModel.Offset.z;
324  //AurĂ©lien : keeping the index
325  vect[3] = position[3];
326  alist[i]=vect;
327  bary = bary+(new Vector3(vect[0],vect[1],vect[2]));
328  }
329 
330  for(int i=0; i<alistSugar.Count; i++) {
331  float[] position= alistSugar[i];
332  float[] vect=new float[3];
333  vect[0]=position[0]+MoleculeModel.Offset.x;
334  vect[1]=position[1]+MoleculeModel.Offset.y;
335  vect[2]=position[2]+MoleculeModel.Offset.z;
336  //vect[3] = 0;
337  alistSugar[i]=vect;
338 
339  }
340 
341 
342  bary = bary/alist.Count;
343  Debug.Log("Bary center :" + bary);
344 
347  MoleculeModel.Center = bary;
348 
349  for(int i=0; i<calist.Count; i++) {
350  float[] position= calist[i] as float[];
351  float[] vect=new float[4];
352  vect[0] = position[0]+MoleculeModel.Offset.x;
353  vect[1] = position[1]+MoleculeModel.Offset.y;
354  vect[2] = position[2]+MoleculeModel.Offset.z;
355  vect[3] = 0;
356  calist[i]=vect;
357  }
358 
362 
365  MoleculeModel.cameraLocation.z=MoleculeModel.target.z-(Vector3.Distance(maxPoint,minPoint));
366 
367 
368 
369  }
370 
371 
387  public static void CreateSplines() {
388  List<float[]> alist = MoleculeModel.atomsLocationlist;
389  List<float[]> calist = MoleculeModel.CatomsLocationlist;
390  List<string> caChainlist = MoleculeModel.CaSplineChainList;
391  List<string> atomsNameList = MoleculeModel.atomsNamelist;
392  List<AtomModel> typelist = MoleculeModel.atomsTypelist;
393 
394  // Trace interpolation from C-alpha positions
395  // Only if there are more than 2 C-alpha
396  if(calist.Count > 2) {
397 
400  calist = new List<float[]>(MoleculeModel.backupCatomsLocationlist);
401  caChainlist = new List<string>(MoleculeModel.backupCaSplineChainList);
402  /*
403  int j = 0;
404  for(int i=1;i<residlist.Count;i++){
405 
406  if(atomsNameList[i] == "CA"){
407  if((atomsNameList[i-1] == atomsNameList[i]) && (residlist[i-1] == residlist[i])){
408  calist.RemoveAt(j);
409  caChainlist.RemoveAt(j);
410  Debug.Log ("Remove");
411  }
412  j++;
413  }
414  } */
415 
416  GenInterpolationArray geninterpolationarray = new GenInterpolationArray();
417  geninterpolationarray.InputKeyNodes=calist;
418  geninterpolationarray.InputTypeArray=caChainlist;
419  geninterpolationarray.CalculateSplineArray();
420  calist=null;
421  caChainlist=null;
422  calist=geninterpolationarray.OutputKeyNodes;
423  caChainlist=geninterpolationarray.OutputTypeArray;
424  }
426  MoleculeModel.CaSplineTypeList = new List<AtomModel>();
427 
428  for(int k=0; k<calist.Count; k++){
429  MoleculeModel.CaSplineTypeList.Add(AtomModel.GetModel("chain"+caChainlist[k]));}
430  MoleculeModel.CaSplineChainList=caChainlist;
431 
432  if(UIData.ffType == UIData.FFType.HiRERNA)
433  {
436  }
437  else {
438  //MoleculeModel.bondList=ControlMolecule.CreateBondsList(alist,typelist);
442  }
443  MoleculeModel.atomsnumber = alist.Count;
445  } // End of CreateSplines
446 
447  public static List<int[]> CreateBondsList(List<float[]> atomsLocationlist, List<AtomModel> atomsTypelist) {
448  List<int[]> bond=new List<int[]>();
449  int test=0;
450  for(int i=0;i<atomsLocationlist.Count;i++) {
451  float [] atom0 = atomsLocationlist[i];
452  string atomtype0 = (atomsTypelist[i]).type;
453  float x0 = atom0[0];
454  float y0 = atom0[1];
455  float z0 = atom0[2];
456 
457  for(int j=1;j<80;j++) {
458  if(i+j < atomsLocationlist.Count) {
459  float[] atom1 = atomsLocationlist[i+j];
460  string atomtype1 = (atomsTypelist[i+j]).type;
461 
462  float cutoff = 1.6f;
463  if ((atomtype0=="H") && (atomtype1=="H")) continue;
464  if ((atomtype0=="S") || (atomtype1=="S")) cutoff = 1.84f;
465  if ((atomtype0=="O" && atomtype1=="P") || (atomtype1=="O" && atomtype0=="P")) cutoff = 1.84f;
466  if ((atomtype0=="O" && atomtype1=="H") || (atomtype1=="O" && atomtype0=="H")) cutoff = 1.84f;
467 
468  float x1=atom1[0];
469  float y1=atom1[1];
470  float z1=atom1[2];
471 
472  float sqDist = (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1) + (z0-z1)*(z0-z1);
473  // faster than sqrt
474  if(sqDist <= cutoff*cutoff) {
475  int [] atomsIds = {i,i+j};
476  bond.Add(atomsIds);
477  test=test+1;
478  }
479  }
480  }
481  }
482  return bond;
483  }
484 
485  public static List<int[]> CreateBondsListWindow(List<float[]> atomsLocationlist, List<AtomModel> atomsTypelist) {
486  List<int[]> bond=new List<int[]>();
487 
488 
491  }
492 
493  //From Benoist UnityMol prototype
494 
495 
496  // Window size: bond search assumes that particles are somehow ordered.
497  // There is therefore no need to search for a bond w particles after
498  // the current particle.
499  int w = 40;
500 
501  // Number of particles in the collection.
502  int N = atomsLocationlist.Count;
503 
504  for(int i=0;i<N;i++) {
505  float[] atom0 = atomsLocationlist[i];
506  string atomtype0 = (atomsTypelist[i]).type;
507 
508  float x0=atom0[0];
509  float y0=atom0[1];
510  float z0=atom0[2];
511 
512  for (int j=i+1; j<(i+w < N ? (i+w):N); j++){
513 
514  string atomtype1 = (atomsTypelist[j]).type;
515 
516  float[] atom1 = atomsLocationlist[j];
517  string a1name = MoleculeModel.atomsNamelist[j];
518 
519  float cutoff = 1.7f;
520  if ((atomtype0=="H") && (atomtype1=="H")) continue;
521  else if ((a1name == "CAL") && (atomtype0=="O")) cutoff = 3.5f;
522  else if ((atomtype0=="S") || (atomtype1=="S")) cutoff = 1.91f;
523  else if ((atomtype0=="P") || (atomtype1=="P")) cutoff = 1.7f;
524  else if ((atomtype0=="O" && atomtype1=="H") || (atomtype1=="O" && atomtype0=="H")) cutoff = 1.84f;
525 
526 
527  float x1=atom1[0];
528  float y1=atom1[1];
529  float z1=atom1[2];
530 
531  float sqDist = (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1) + (z0-z1)*(z0-z1);
532 
533  if(sqDist <= cutoff*cutoff) {
534  int [] atomsIds = {i,j};
535  bond.Add(atomsIds);
536 
537  if (MoleculeModel.bondEPDict.ContainsKey(i))
538  MoleculeModel.bondEPDict[i].Add (j);
539  else
540  MoleculeModel.bondEPDict[i]=new List<int>(j);
541 
542  }
543 
544  }
545 
546  }
547  return bond;
548 
549  }
550  public static List<int[]> CreateBondsEPList(List<float[]> atomsLocationlist, List<AtomModel> atomsTypelist) {
551  List<int[]> bond=new List<int[]>();
552  List<int> h_already_in=new List<int>(); // T.T. to not link a hydrogen 2 times
553 
556  }
557 
558  for(int i=0;i<atomsLocationlist.Count;i++) {
559  float[] atom0 = atomsLocationlist[i];
560  string atomtype0 = (atomsTypelist[i]).type;
561 
562  float x0=atom0[0];
563  float y0=atom0[1];
564  float z0=atom0[2];
565 
566  /*
567  * UPDATE BY T.T. but it will lost in eficiency...
568  * for sugar, it can have 600 distance atoms between 2 bounded atom,
569  * so we can't stop to search a neighbor after 150 atoms (for example).
570  * So I change the way to calcul bounded atoms, but for verry big complexe, it can
571  * be longer to calcul bounded atoms.
572  * there is the old code :
573  * for (int j=1;j<150;j++){
574  * if(i+j<atomsLocationlist.Count) {
575  * .....
576  * .....
577  * then replace all indexes [j] by [i+j]
578  *
579  */
580  //for(int j=1;j<700;j++) {
581  // if(i+j<atomsLocationlist.Count) {
582  for(int j=i+1; j<atomsLocationlist.Count; j++){
583  float[] atom1 = atomsLocationlist[j];
584  string atomtype1 = (atomsTypelist[j]).type;
585  string a1name = MoleculeModel.atomsNamelist[j];
586 
587  float cutoff = 1.7f;
588  if ((atomtype0=="H") && (atomtype1=="H")) continue;
589  else if ((a1name == "CAL") && (atomtype0=="O")) cutoff = 3.5f;
590  else if ((atomtype0=="S") || (atomtype1=="S")) cutoff = 1.91f;
591  else if ((atomtype0=="P") || (atomtype1=="P")) cutoff = 1.7f;
592  else if ((atomtype0=="O" && atomtype1=="H") || (atomtype1=="O" && atomtype0=="H")) cutoff = 1.84f;
593 
594  float x1=atom1[0];
595  float y1=atom1[1];
596  float z1=atom1[2];
597 
598  float sqDist = (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1) + (z0-z1)*(z0-z1);
599  // faster than sqrt
600 
601  /*** T.T.
602  * I change it to evoid to add a H elready bounded in the bond list.
603  * old code :
604  * if(sqDist <= cutoff*cutoff) {
605  bond.Add(atomsIds);
606  h_already_in.Add(j);
607  }
608  * */
609  if(sqDist <= cutoff*cutoff) {
610 
611  if (atomtype0=="H"){
612  if (!h_already_in.Contains(i)){
613  int [] atomsIds = {i,j};
614  bond.Add(atomsIds);
615  h_already_in.Add(i);
616 
617  if (MoleculeModel.bondEPDict.ContainsKey(i))
618  MoleculeModel.bondEPDict[i].Add (j);
619  else
620  MoleculeModel.bondEPDict[i]=new List<int>(j);
621  }
622  }else if (atomtype1=="H"){
623  if (!h_already_in.Contains(j)){
624  int [] atomsIds = {i,j};
625  bond.Add(atomsIds);
626  h_already_in.Add(j);
627 
628  if (MoleculeModel.bondEPDict.ContainsKey(i))
629  MoleculeModel.bondEPDict[i].Add (j);
630  else
631  MoleculeModel.bondEPDict[i]=new List<int>(j);
632  }
633  }
634  else{
635  int [] atomsIds = {i,j};
636  bond.Add(atomsIds);
637 
638  if (MoleculeModel.bondEPDict.ContainsKey(i))
639  MoleculeModel.bondEPDict[i].Add (j);
640  else
641  MoleculeModel.bondEPDict[i]=new List<int>(j);
642  }
643 
644  }
645  //}
646  }
647  }
648  //In the case where we want to calculate bonds, and then add other bond inside the PDB.
650  for (int i=0; i<MoleculeModel.BondListFromPDB.Count; i++){
651  int atom1 = MoleculeModel.BondListFromPDB[i][0];
652  int atom2 = MoleculeModel.BondListFromPDB[i][1];
653 
654  if (MoleculeModel.bondEPDict.ContainsKey(atom1)){
655  if (!MoleculeModel.bondEPDict[atom1].Contains(atom2)) // If the bond is not already added in the bond list
656  bond.Add (new int[2] {atom1, atom2});
657  }
658  }
659  }
660 
661  return bond;
662  }
663 
664 
665 
666  //AurĂ©lien : bond update function called in Molecule3D.update()
667  public static void UpdateBondsFromGameObject(ArrayList atoms)
668  {
669  //float [] atom0 = new float[3];
670  //float [] atom1 = new float[3];
671  string atomtype0;
672  string atomtype1;
673  float cutoff;
674  float diffx;
675  float diffy;
676  float diffz;
677  bool exists;
678 
679  /*float x0;
680  float y0;
681  float z0;
682  float x1;
683  float y1;
684  float z1;*/
685 
686  GameObject clubatom0 = null;
687  GameObject clubatom1 = null;
688  int count = MoleculeModel.atomsLocationlist.Count;
689 
690  for(int i=0;i<MoleculeModel.atomsLocationlist.Count;i++)
691  {
692  /*atom0[0] = (atoms[i] as GameObject).transform.position.x;
693  atom0[1] = (atoms[i] as GameObject).transform.position.y;
694  atom0[2] = (atoms[i] as GameObject).transform.position.z;*/
695  atomtype0=(atoms[i] as GameObject).tag;
696 
697  /*x0=atom0[0];
698  y0=atom0[1];
699  z0=atom0[2];*/
700 
701  for(int j=1;j<count-i;j++)
702  {
703  /*atom1[0] = (atoms[i+j] as GameObject).transform.position.x;
704  atom1[1] = (atoms[i+j] as GameObject).transform.position.y;
705  atom1[2] = (atoms[i+j] as GameObject).transform.position.z;*/
706  atomtype1 = (atoms[i+j] as GameObject).tag;
707  cutoff = 1.6f;
708 
709  if((atomtype0=="H")&&(atomtype1=="H"))continue;
710  if((atomtype0=="S")||(atomtype1=="S"))cutoff = 1.84f;
711  if((atomtype0=="P")||(atomtype1=="P"))cutoff = 1.7f;
712 
713 
714  /*x1=atom1[0];
715  y1=atom1[1];
716  z1=atom1[2];*/
717 
718  diffx = ((atoms[i] as GameObject).transform.position.x-(atoms[i+j] as GameObject).transform.position.x);
719  diffx *= diffx;
720  diffy =((atoms[i] as GameObject).transform.position.y-(atoms[i+j] as GameObject).transform.position.y);
721  diffy *= diffy;
722  diffz = ((atoms[i] as GameObject).transform.position.z-(atoms[i+j] as GameObject).transform.position.z);
723  diffz *= diffz;
724  if((diffx + diffy + diffz) <= cutoff*cutoff)
725  {
726 
727  Debug.Log ("Cutoff");
728  exists = false;
729  foreach(GameObject club in MoleculeModel.clubs)
730  {
731  StickUpdate comp = (club as GameObject).GetComponent<StickUpdate>();
732  clubatom0 = (GameObject)MoleculeModel.atoms[comp.atomnumber1];
733  if(clubatom0 == atoms[i])
734  {
735  clubatom1 = (GameObject)MoleculeModel.atoms[comp.atomnumber2];
736  if(clubatom1 == atoms[i+j])
737  {
738  exists = true;
739  break;
740  }
741  }
742  }
744  {
745  GameObject Stick;
746  // Stick=GameObject.CreatePrimitive(PrimitiveType.Cube);
747  Stick = (GameObject)GameObject.Instantiate(Resources.Load("HStickPrefab"));
748  // RuntimePlatform platform = Application.platform;
749  // switch(platform)
750  // {
751  // case RuntimePlatform.WindowsPlayer:
752  // case RuntimePlatform.WindowsWebPlayer:
753  // case RuntimePlatform.WindowsEditor:
754  // Stick.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/Stick HyperBalls D3D");
755  // break;
756  // default :
757  // Stick.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/Stick HyperBalls OpenGL");
758  // break;
759  // }
760  // StickUpdate comp = Stick.AddComponent<StickUpdate>();
761  StickUpdate comp = Stick.GetComponent<StickUpdate>();
762 
763  comp.atomnumber1= i;
764  comp.atomnumber2= i+j;
765  comp.enabled = true;
766  Stick.GetComponent<Renderer>().material.SetFloat("_Shrink", 0.01f);
767  Stick.tag="Club";
768  Stick.GetComponent<Collider>().enabled = false;
769 
770  float[] fposAtom1 = MoleculeModel.atomsLocationlist[comp.atomnumber1];
771  Vector3 posAtom1 = new Vector3(fposAtom1[0],fposAtom1[1],fposAtom1[2]);
772 
773 
774  Stick.transform.position = posAtom1;
775  Stick.transform.parent = Molecule.View.DisplayBond.BondCubeStyle.BondCubeParent.transform;
776  MoleculeModel.clubs = GameObject.FindGameObjectsWithTag("Club");
777  }
778  }
779  else
780  {
781  foreach(GameObject club in MoleculeModel.clubs)
782  {
783  StickUpdate comp = (club as GameObject).GetComponent<StickUpdate>();
784  clubatom0 = (GameObject)MoleculeModel.atoms[comp.atomnumber1];
785  if(clubatom0 == atoms[i])
786  {
787  clubatom1 = (GameObject)MoleculeModel.atoms[comp.atomnumber2];
788  if(clubatom1 == atoms[i+j])
789  {
790  GameObject.DestroyImmediate(club);
791  MoleculeModel.clubs = GameObject.FindGameObjectsWithTag("Club");
792  break;
793  }
794  }
795  }
796  }
797  }
798  }
799  }
800 
810  public static List<int[]> CreateBondsCAList(List<string> caChainlist) {
811  List<int[]> bond=new List<int[]>();
812 
813  for(int i=1; i<caChainlist.Count; i++) {
814  if(caChainlist[i-1] == caChainlist[i]) {
815  int[] splineIds = {i-1,i};
816  bond.Add(splineIds);
817  }
818  }
819  Debug.Log("bond.Count:"+bond.Count);
820  return bond;
821  }
822 
823  public static string CreateSequenceString() {
824  int nucleotide_count = MoleculeModel.residues.Count;
825  StringBuilder sequence = new StringBuilder(new string('.', nucleotide_count), nucleotide_count);
826  int i = 0;
827  foreach(KeyValuePair<int, ArrayList> entry in MoleculeModel.residues)
828  {
829  int atomId = (int)entry.Value[0];
830  sequence[i] = MoleculeModel.atomsResnamelist[atomId][0];
831  i++;
832  }
833  return sequence.ToString();
834  }
835 
836  public static List<int[]> CreateBondsList_HiRERNA(List<string> atomnames) {
837  //We suppose the names are ordered as this:
838  //P O5* C5* CA CY b1 [b2]
839  List<int[]> bonds = new List<int[]>();
840  int N = atomnames.Count;
841  int k;
842 // int[] bond;
843  for(int i=0; i<N-1; ++i) {
844  string a1 = atomnames[i];
845  if(a1 == "P") {
846  //Backward search for "CA"
847  for(k=i; k>=0 && k>=i-5 && (atomnames[k])!="CA"; --k);
848  if(k>=0 && k>=i-5) bonds.Add(new int[] {i,k});
849 
850  //Forward search for "O5*"
851  if(atomnames[i+1] == "O5*")
852  bonds.Add(new int[] {i,i+1});
853  else
854  Debug.Log("Atom "+ (i+1) as string + "O5* missing");
855  }
856  else if(a1 == "O5*") {
857  //Forward search for "C5*"
858  if(atomnames[i+1] == "C5*")
859  bonds.Add(new int[] {i,i+1});
860  else
861  Debug.Log("Atom "+ (i+1) as string + "C5* missing");
862  }
863  else if(a1 == "C5*") {
864  //Forward search for "CA"
865  if(atomnames[i+1] == "CA")
866  bonds.Add(new int[] {i,i+1});
867  else
868  Debug.Log("Atom "+ (i+1) as string + "CA missing");
869  }
870  else if(a1 == "CA") {
871  //Forward search for "CY"
872  if(atomnames[i+1] == "CY")
873  bonds.Add(new int[] {i,i+1});
874  else
875  Debug.Log("Atom "+ (i+1) as string + "CY missing");
876  }
877  else if(a1 == "CY") {
878  //Forward search for G1, A1, U1 or C1
879  string a2 = atomnames[i+1];
880  if(a2 == "G1" || a2 == "A1" || a2 == "U1" || a2 == "C1")
881  bonds.Add(new int[] {i,i+1});
882  else
883  Debug.Log("Atom "+ (i+1) as string + "b1 missing");
884  }
885  else if(a1 == "G1") {
886  //Forward search for "G2"
887  if(atomnames[i+1] == "G2")
888  bonds.Add(new int[] {i,i+1});
889  else
890  Debug.Log("Atom "+ (i+1) as string + "G2 missing");
891  }
892  else if(a1 == "A1") {
893  //Forward search for "A2"
894  if(atomnames[i+1] == "A2")
895  bonds.Add(new int[] {i,i+1});
896  else
897  Debug.Log("Atom "+ (i+1) as string + "A2 missing");
898  }
899  }
900  Debug.Log("HiRERNA bond count : " + bonds.Count);
901  return bonds;
902  }
903 
904 
905  // not the atomsLocationList from MoleculeModel
906  public static List<int[]> CreateBondsCSList(List<int[]> atomsLocationlist) {
907  //int k=0;
908  //string clubs="";
909  List<int[]> bond=new List<int[]>();
910 // Debug.Log("atomsLocationlist.Count " + atomsLocationlist.Count);
911 // Debug.Log("atomsTypelist.Count " + atomsTypelist.Count);
912 
913  Debug.Log("atomsLocationlist.Count:"+atomsLocationlist.Count);
914 
915 // int[] ary = (int[])((MoleculeModel.CSidList).ToArray(typeof(int)));
916  for(int i=0;i<atomsLocationlist.Count;i++) {
917 // Debug.Log("atomsLocationlist[i][0]="+(atomsLocationlist[i] as float[])[0]);
918  int[] atom0 = atomsLocationlist[i];
919 // string atomtype0=atomsTypelist[i] as string;
920 
921  //Debug.Log("i ********** " + i);
922 
923  int source=atom0[0];
924  int target=atom0[1];
925 // Vector3 atom0position=new Vector3();
926 // Vector3 atom1position=new Vector3();
927  int atom0sign=0;
928  int atom1sign=0;
929 
930  //Vector3 atomtype=new Vector3();
931 // Debug.Log("source="+source+",target="+target);
932  for(int j=0;j<MoleculeModel.CSidList.Count;j++) {
933 
934 // Debug.Log("source="+source+",target="+target);
935  int [] number=MoleculeModel.CSidList[j];
936 // Debug.Log("number[0]="+number[0]);
937 // int number=ary[j];
938 // int number=int.Parse(MoleculeModel.CSidList[j] as string);
939 
940  if(source==number[0])
941  atom0sign=j;
942  if(target==number[0])
943  atom1sign=j;
944  }
945  bond.Add(new int[] {atom0sign, atom1sign});
946 // atomtype.x=atom0sign;
947 // atomtype.y=atom1sign;
948 // atomtype.z=0;
949 
950 // // Debug.Log("atom0sign="+atom0sign+",atom1sign="+atom1sign);
951 
952 // float [] atom00=(MoleculeModel.atomsLocationlist[atom0sign]) as float[];
953 // float [] atom11=(MoleculeModel.atomsLocationlist[atom1sign]) as float[];
954 
955 // atom0position.x=atom00[0];
956 // atom0position.y=atom00[1];
957 // atom0position.z=atom00[2];
958 
959 // atom1position.x=atom11[0];
960 // atom1position.y=atom11[1];
961 // atom1position.z=atom11[2];
962 
963 
964 // Vector3 [] location=new Vector3[3];
965 // location[0]=atom0position;
966 // location[1]=atom1position;
967 // location[2]=atomtype;
968 
969 // bond.Add(location);
970  }
971 
972  return bond;
973  }
974 
975 
976  // public static GameObject[] SetBoxes(GameObject[] Ces,GameObject[] Nes,GameObject[] Oes,
977  // GameObject[] Ses,GameObject[] Pes,GameObject[] Hes,GameObject[] NOes)
978  // {
979 
980  // GameObject[] boxes=new GameObject[Ces.Length+Nes.Length+Oes.Length+
981  // Ses.Length+Pes.Length+Hes.Length+NOes.Length];
982  // int i=0;
983  // for(int ci=0;ci<Ces.Length;ci++,i++)
984  // {
985  // boxes[i]=Ces[ci];
986 
987  // }
988 
989  // for(int ni=0;ni<Nes.Length;ni++,i++)
990  // {
991  // boxes[i]=Nes[ni];
992 
993  // }
994 
995  // for(int oi=0;oi<Oes.Length;oi++,i++)
996  // {
997  // boxes[i]=Oes[oi];
998 
999  // }
1000 
1001  // for(int si=0;si<Ses.Length;si++,i++)
1002  // {
1003  // boxes[i]=Ses[si];
1004 
1005  // }
1006 
1007  // for(int pi=0;pi<Pes.Length;pi++,i++)
1008  // {
1009  // boxes[i]=Pes[pi];
1010 
1011  // }
1012 
1013  // for(int hi=0;hi<Hes.Length;hi++,i++)
1014  // {
1015  // boxes[i]= Hes[hi];
1016 
1017  // }
1018 
1019  // for(int noi=0;noi<NOes.Length;noi++,i++)
1020  // {
1021  // boxes[i]=NOes[noi];
1022 
1023  // }
1024 
1025 
1026  // return boxes;
1027  // }
1028 
1029 
1030 
1031  }
1032 }
static List< Dictionary< string, Vector3 > > residueDictionaries
static List< int[]> CreateBondsList_HiRERNA(List< string > atomnames)
static List< int[]> CreateBondsListWindow(List< float[]> atomsLocationlist, List< AtomModel > atomsTypelist)
static List< int[]> bondCAList
The bonds between carbon alpha in the CA-Spline.
static List< int[]> BondListFromPDB
static List< int[]> CreateBondsCSList(List< int[]> atomsLocationlist)
static List< int[]> CreateBondsCAList(List< string > caChainlist)
Creates a bond list for the carbon alpha splines.
static AtomModel GetModel(string type)
Definition: AtomModel.cs:257
static Vector3 Offset
The offset for the molecule.
static List< int[]> CreateBondsEPList(List< float[]> atomsLocationlist, List< AtomModel > atomsTypelist)
static FFType ffType
Definition: UIData.cs:241
static List< string > atomsNamelist
The name of each atom.
static List< AtomModel > atomsTypelist
The type of each atom.
static List< float[]> atomsSugarLocationlist
static bool connectivity_calc
Definition: UIData.cs:112
static List< float > scale_RNA
RNA Scale parameters
static string directorypath
Definition: GUIDisplay.cs:118
static List< int > residueIds
The residue identifiers.
int atomnumber1
Definition: StickUpdate.cs:85
static List< int[]> CreateBondsList(List< float[]> atomsLocationlist, List< AtomModel > atomsTypelist)
static List< float[]> CatomsLocationlist
The coordinates of each Carbon alpha.
static void CheckHiRERNAModel()
Checks whether the loaded PDB file follows the HiRE-RNA coarse-grain model or not.
int atomnumber2
Definition: StickUpdate.cs:86
static List< int[]> CSidList
static bool loadHireRNA
Definition: UIData.cs:240
static void UpdateBondsFromGameObject(ArrayList atoms)
static List< AtomModel > atomsSugarTypelist
static List< string > backupCaSplineChainList
Sometimes inside pdbs lists are not sorted, and residues mixed So I had to create this list to sort r...
static List< int[]> bondEPSugarList
static List< float[]> CaSplineList
The coordinates of each Carbon alpha in the CA-Spline.
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
static Vector3 MaxValue
The "biggest" corner of the bounding box that encloses the molecule.
static List< string > CaSplineChainList
The chain of each carbon alpha in the CA-Spline.
!WiP manage GUI, and provide static strings for the GUI.
Definition: GUIDisplay.cs:94
static void CreateSplines()
Creates the carbon alpha splines.
static Dictionary< int, ArrayList > residues
The residues.
static List< int[]> bondEPList
The bonds between atoms.
static List< float[]> backupCatomsLocationlist
Backup of the coordinates of each Carbon alpha.
static List< Dictionary< string, Vector3 > > residueDictionariesSugar
static Vector3 MinValue
The "smallest" corner of the bounding box that encloses the molecule.
static List< string > atomsResnamelist
The name of the residue to which each atom belongs.
static void RNAView_init()
Definition: RNAView.cs:33
static void BuildMoleculeComponents()
Builds the molecule&#39;s components.
static GameObject[] clubs
static List< int > baseIdx
The index (in tables) of the base extremity.
static Vector3 Center
The barycenter of the molecule.
static void BuildHireRnaHydrogenBondsStructures()
static List< AtomModel > CaSplineTypeList
Type of each carbon alpha in the CA-Spline.
static bool connectivity_PDB
Definition: UIData.cs:113
Definition: GUIDisplay.cs:66
static List< float[]> atomsLocationlist
The coordinates of each atom.
static Dictionary< int, List< int > > bondEPDict
Dictionary of every bounded atoms (which atoms whith which atoms).