UnityMol  0.9.6-875
UnityMol viewer / In developement
Ribbons.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 using System.Collections.Generic;
4 
5 public class Ribbons {
6  // For handling multiple chains.
7  public static bool mustSplitDictList = false;
8  private Vector3 flipTestV;
12  private int uspacing;
13  private int vIndex;
14 
15  public List<int> handedlist = new List<int> ();
16  public List<int> sslist = new List<int> ();
17  private bool createss = false; // check if ss informations are present in the pdb file
18  public static string ribbontag = "RibbonObjA";
19  private static string currentchain = "";
20 
21  private const int HELIX = 0;
22  private const int STRAND = 1;
23  private const int COIL = 2;
24  private const int LHANDED = -1;
25  private const int RHANDED = 1;
26 
27  private static int RIBBON_DETAIL = 4; // Ribbon detail: from 1 (lowest) to 4 (highest)
28  private static int RENDER_MODE = 1; // 0 = lines, 1 = flat ribbons
29 
30  public static ColorObject HELIX_COLOR = new ColorObject(new Color32(255,0,0,255)); // red
31  public static ColorObject STRAND_COLOR = new ColorObject(new Color32(0,0,255,255)); // blue
32  public static ColorObject COIL_COLOR = new ColorObject(new Color32(255,255,255,255)); // light grey
33 
34  public static ColorObject ChainColorA = new ColorObject(new Color32( 10, 3,200,50));
35  public static ColorObject ChainColorB = new ColorObject(new Color32( 10,170, 34,50));
36  public static ColorObject ChainColorC = new ColorObject(new Color32( 0,150,150,50));
37  public static ColorObject ChainColorD = new ColorObject(new Color32( 0,180, 0,50));
38  public static ColorObject ChainColorE = new ColorObject(new Color32( 0,170,200,50));
39 
40  public static float HELIX_DIAM = 1.8f;
41  public static float THICKNESS = 0.3f;
42  public static float ARROW_WIDTH = 1.8f;
43 
44  public static float[] ribbonWidth = {1.5f, 1.7f, 0.3f}; // Ribbon widths for helix, strand and coil, respectively
45 
46  private float CalculateTorsionalAngle(Vector3 at0, Vector3 at1, Vector3 at2, Vector3 at3, bool print) {
47  Vector3 r01 = at0 - at1;
48  Vector3 r32 = at3 - at2;
49  Vector3 r12 = at1 - at2;
50 
51  Vector3 p = Vector3.Cross(r12, r01);
52  Vector3 q = Vector3.Cross(r12, r32);
53  Vector3 r = Vector3.Cross(r12, q);
54 
55  float u = Vector3.Dot(q,q);
56  float v = Vector3.Dot(r,r);
57 
58  float a;
59  if(u <= 0f || v <= 0f)
60  a = 360f;
61  else {
62  float u1 = Vector3.Dot(p,q);
63  float v1 = Vector3.Dot(p,r);
64 
65  u = u1 / Mathf.Sqrt(u);
66  v = v1 / Mathf.Sqrt(v);
67 
68  if(Mathf.Abs(u) > 0.01f || Mathf.Abs(v) > 0.01f)
69  a = Mathf.Rad2Deg * Mathf.Atan2(v,u);
70  else
71  a = 360f;
72  }
73  if(print)
74  Debug.Log(a.ToString());
75  return a;
76  }
77 
78  private float WeirdDistance(float x1, float y1, float x2, float y2) {
79  Vector2 one = new Vector2(x1, y1);
80  Vector2 two = new Vector2(x2, y2);
81  return Vector2.Distance(one, two);
82  }
83 
84  private void CalculateSecondaryStructures(List<Dictionary<string, Vector3>> residueDicts, int[] ss, int[] handedness) {
85  Debug.Log("Ribbons.cs::CalculateSecondaryStructures > Beginning.");
86  Vector3 c0, n1, ca1, c1, n2;
87  c0 = n1 = ca1 = c1 = n2 = Vector3.zero; // you have to init them
88  Dictionary<string, Vector3> res0, res1, res2;
89  int nbResDicts = residueDicts.Count;
90 
91  float[] phi = new float[nbResDicts];
92  float[] psi = new float[nbResDicts];
93  bool success = false;
94  for(int i=0; i<nbResDicts; i++) {
95  if(i == 0 || i == nbResDicts-1) {
96  phi[i] = 90f;
97  psi[i] = 90f;
98  } else {
99  res0 = residueDicts[i-1];
100  res1 = residueDicts[i];
101  res2 = residueDicts[i+1];
102 
103  success = true;
104 
105  success = success && res0.TryGetValue("C", out c0);
106  success = success && res1.TryGetValue("N", out n1);
107  success = success && res1.TryGetValue("CA", out ca1);
108  success = success && res1.TryGetValue("C", out c1);
109  success = success && res2.TryGetValue("N", out n2);
110 
111  if(!success)
112  Debug.Log("Ribbons.cs::CalculateSecondaryStructures > Failed to get all the vectors.");
113 
114  bool print = (i<100);
115  print = false;
116 
117  if(print)
118  Debug.Log(i.ToString() + ": " + c0.ToString() + " " + n1.ToString() + " " + ca1.ToString() + " " + c1.ToString() + " " + n2.ToString());
119 
120 
121  phi[i] = CalculateTorsionalAngle(c0, n1, ca1, c1, print);
122  psi[i] = CalculateTorsionalAngle(n1, ca1, c1, n2, print);
123 
124  }
125  }
126 
127  int firstHelix = 0;
128  int nconsRHelix = 0;
129  int nconsLHelix = 0;
130  int firstStrand = 0;
131  int nconsStrand = 0;
132  float extension = 0f;
133  float strandExtension = 0f;
134  for(int i=0; i<nbResDicts; i++) {
135  // Right-handed helix
136  if((WeirdDistance(phi[i], psi[i], -60f, -45f) < (30f + extension)) && (i < nbResDicts - 1)) {
137  if(nconsRHelix == 0)
138  firstHelix = i;
139  nconsRHelix++;
140  } else {
141  if(3 <= nconsRHelix) {
142  for(int k=firstHelix; k<i; k++) {
143  ss[k] = HELIX;
144  handedness[k] = RHANDED;
145  }
146  }
147  nconsRHelix = 0;
148  }
149 
150  // Left-handed helix
151  if((WeirdDistance(phi[i], psi[i], 60f, 45f) < (30f + extension)) && (i < nbResDicts - 1)) {
152  if(nconsLHelix == 0)
153  firstHelix = i;
154  nconsLHelix++;
155  } else {
156  if(3 <= nconsLHelix) {
157  for(int k=firstHelix; k<i; k++) {
158  ss[k] = HELIX;
159  handedness[k] = LHANDED;
160  }
161  }
162  nconsLHelix = 0;
163  }
164 
165  // Strand
166  if((WeirdDistance(phi[i], psi[i], -110f, 130f) < (30f + extension + strandExtension))
167  && (i< nbResDicts - 1)) {
168  if(nconsStrand == 0)
169  firstStrand = i;
170  nconsStrand++;
171  } else {
172  if(2 <= nconsStrand) {
173  for(int k=firstStrand; k<i; k++) {
174  ss[k] = STRAND;
175  handedness[k] = RHANDED;
176  }
177  }
178  nconsStrand = 0;
179  }
180 
181  ss[i] = COIL;
182  handedness[i] = RHANDED;
183  }
184  } // End of CalculateSecondaryStructures
185 
186  private Vector3 LinearComb(float scalar0, Vector3 vector0, float scalar1, Vector3 vector1) {
187  return scalar0*vector0 + scalar1*vector1;
188  }
189 
190  // Adds a new control point to the arrays CPCenter, CPRight and CPLeft
191  private void AddControlPoints(Vector3 ca0, Vector3 ox0, Vector3 ca1, int ss, int handedness) {
192 
193  Vector3 A, B, C, D, p0, cpt0, cpt1, cpt2;
194 
195  A = ca1 - ca0;
196  B = ox0 - ca0;
197 
198  // Vector normal to the peptide plane (pointing outside in the case of the
199  // alpha helix).
200  C = Vector3.Cross(A,B);
201 
202  // Vector contained in the peptide plane (perpendicular to its direction).
203  D = Vector3.Cross(C,A);
204 
205  C.Normalize();
206  D.Normalize();
207 
208  // Flipping test (to avoid self crossing in the strands).
209  if( (ss != HELIX) && (90f < Vector3.Angle(flipTestV, D) ) )
210  D = D * -1f; // flip detected, the plane vector is inverted
211 
212  // The central control point is constructed
213  cpt0 = LinearComb(0.5f, ca0, 0.5f, ca1);
214  splineCenter.SetCPoint(3, cpt0);
215 
216  if(ss == HELIX) {
217  // When residue i is contained in a helix, the control point is moved away
218  // from the helix axis, along the C direction.
219  p0 = Vector3.zero;
220  splineCenter.GetCPoint(3, out p0);
221  cpt0 = LinearComb(1f, p0, handedness*HELIX_DIAM, C);
222  splineCenter.SetCPoint(3, cpt0);
223  }
224 
225  // The control points for the side ribbons are constructed.
226  cpt1 = LinearComb(1f, cpt0, ribbonWidth[ss], D);
227  splineSide1.SetCPoint(3, cpt1);
228 
229  cpt2 = LinearComb(1f, cpt0, - ribbonWidth[ss], D);
230  splineSide2.SetCPoint(3, cpt2);
231 
232 
233  // Saving the plane vector (for the flipping test in the next call)
234  flipTestV = D;
235  } // End of AddControlPoints
236 
237 
238  private void ShiftControlPoints() {
239  splineSide1.ShiftBSplineCPoints();
240  splineCenter.ShiftBSplineCPoints();
241  splineSide2.ShiftBSplineCPoints();
242  }
243 
244 
245  private void ConstructControlPoints(List<Dictionary<string, Vector3>> residueDicts, int res, int ss, int handedness) {
246  //Debug.Log("Ribbons.cs::ConstructControlPoints > Beginning.");
247  Vector3 ca0, ox0, ca1;
248  Vector3 p0, p1, p2, p3;
249 
250  p1 = p2 = p3 = Vector3.zero;
251 
252  Dictionary<string, Vector3> res0, res1;
253  res0 = res1 = null;
254 
255  if(res == 0) {
256  // The control points 2 and 3 are created
257  flipTestV = Vector3.zero;
258 
259  res0 = residueDicts[res];
260  res1 = residueDicts[res + 1];
261 
262  bool success = true;
263  success = success && res0.TryGetValue("CA", out ca0);
264  success = success && res0.TryGetValue("O", out ox0);
265  success = success && res1.TryGetValue("CA", out ca1);
266 
267  if(!success)
268  Debug.Log("Ribbons.cs::ConstructControlPoints > Failed to get all the vectors.");
269 
270  AddControlPoints(ca0, ox0, ca1, ss, handedness);
271  splineSide1.CopyCPoints(3, 2);
272  splineCenter.CopyCPoints(3, 2);
273  splineSide2.CopyCPoints(3, 2);
274 
275  res0 = residueDicts[res + 1];
276  res1 = residueDicts[res + 2];
277  success = true;
278  success = success && res0.TryGetValue("CA", out ca0);
279  success = success && res0.TryGetValue("O", out ox0);
280  success = success && res1.TryGetValue("CA", out ca1);
281  if(!success)
282  Debug.Log("Ribbons.cs::ConstructControlPoints > Failed to get all the vectors.");
283  AddControlPoints(ca0, ox0, ca1, ss, handedness);
284 
285  // We still need the two first control points
286  // Moving backwards along the cp_center[2] - cp_center[3] direction
287  splineCenter.GetCPoint(2, out p2);
288  splineCenter.GetCPoint(3, out p3);
289 
290  p1 = LinearComb(2f, p2, -1f, p3);
291  splineCenter.SetCPoint(1, p1);
292  splineSide1.SetCPoint(1, LinearComb(1f, p1, ribbonWidth[ss], flipTestV));
293  splineSide2.SetCPoint(1, LinearComb(1f, p1, -ribbonWidth[ss], flipTestV));
294 
295  p0 = LinearComb(2f, p1, -1f, p2);
296 
297 
298  splineCenter.SetCPoint(0, p0);
299  splineSide1.SetCPoint(0, LinearComb(1f, p0, ribbonWidth[ss], flipTestV));
300  splineSide2.SetCPoint(0, LinearComb(1f, p0, -ribbonWidth[ss], flipTestV));
301  } else {
303  if ( (residueDicts.Count - 1 == res) || (residueDicts.Count - 2 == res) ) {
304  // Moving forward along the cp_center[1] - cp_center[2] direction
305  splineCenter.GetCPoint(1, out p1);
306  splineCenter.GetCPoint(2, out p2);
307 
308  p3 = LinearComb(2f, p2, -1f, p1);
309  splineCenter.SetCPoint(3, p3);
310  splineSide1.SetCPoint(3, LinearComb(1f, p3, ribbonWidth[ss], flipTestV));
311  splineSide2.SetCPoint(3, LinearComb(1f, p3, -ribbonWidth[ss], flipTestV));
312  } else {
313  res0 = residueDicts[res + 1];
314  res1 = residueDicts[res + 2];
315  bool success = true;
316  success = success && res0.TryGetValue("CA", out ca0);
317  success = success && res0.TryGetValue("O", out ox0);
318  success = success && res1.TryGetValue("CA", out ca1);
319  if(!success)
320  Debug.Log("Ribbons.cs::ConstructControlPoints > Failed to get all the vectors.");
321  AddControlPoints(ca0, ox0, ca1, ss, handedness);
322  }
323  }
324  splineSide1.UpdateMatrix3();
325  splineCenter.UpdateMatrix3();
326  splineSide2.UpdateMatrix3();
327  } // End of ConstructControlPoints
328 
329 
330  private void GenerateSpline(int n, List<Vector3> vertices) {
331  int ui;
332  float u;
333  Vector3 v1; // original Processing code includes a v0 that is never used
334 
335  v1 = Vector3.zero;
336 
337  if (n == 0)
338  splineSide1.Feval(0f, out v1);
339  else
340  if (n == 1)
341  splineCenter.Feval(0f, out v1);
342  else
343  splineSide2.Feval(0f, out v1);
344  vertices.Add(new Vector3(v1.x, v1.y, v1.z));
345 
346  for(ui=1; ui<=10; ui++) {
347  if(ui % uspacing == 0) {
348  u = 0.1f * ui;
349 
350  if(n == 0)
351  splineSide1.Feval(u, out v1);
352  else
353  if(n == 1)
354  splineCenter.Feval(u, out v1);
355  else
356  splineSide2.Feval(u, out v1);
357 
358  vertices.Add(new Vector3(v1.x, v1.y, v1.z));
359  }
360  }
361  } // End of GenerateSpline
362 
363  private void GenerateArrowRibbon(List<Vector3> vertices, List<Vector3> normals, List<int> triangles) {
364  Vector3 CentPoint0, CentPoint1, Sid1Point0, Sid1Point1, Sid2Point0, Sid2Point1,
365  Transversal, Tangent, Normal0, Normal1;
366  Vector3 CP0, CP1, S1P0, S1P1, S2P0, S2P1, Norm0, Norm1;
367  Vector3 leftVect0, rightVect0, leftVect1, rightVect1;
368  Vector3 Forward, LeftDiag0, RightDiag0, LeftDiag1, RightDiag1;
369  Forward = LeftDiag0 = RightDiag0 = LeftDiag1 = RightDiag1 = Vector3.zero;
370  leftVect0 = leftVect1 = rightVect0 = rightVect1 = Vector3.zero;
371  int ui;
372  float u=0f; // needs to be assigned
373  CentPoint0 = CentPoint1 = Sid1Point0 = Sid1Point1 = Sid2Point0 = Sid2Point1 = Transversal = Tangent = Normal0 = Normal1 = Vector3.zero;
374  CP0 = CP1 = S1P0 = S1P1 = S2P0 = S2P1 = Norm0 = Norm1 = Vector3.zero;
375  // The initial geometry is generated
376  splineSide1.Feval(0f, out Sid1Point1);
377  splineCenter.Feval(0f, out CentPoint1);
378  splineSide2.Feval(0f, out Sid2Point1);
379 
380  // The tangents at the three previous points are the same
381  splineSide2.Deval(0f, out Tangent);
382 
383  // Vector transversal to the ribbon
384  Transversal = Sid1Point1 - Sid2Point1;
385  Normal1 = Vector3.Cross(Transversal, Tangent);
386  Normal1.Normalize();
387  float extraWidthFactor = ARROW_WIDTH;
388  float pointOneAdjustment = 0.1f * ARROW_WIDTH;
389  float pointOneWidthFactor;
390 
391  Vector3 leftNormal0, leftNormal1, rightNormal0, rightNormal1;
392  for(ui=1; ui<=10; ui++) {
393  if(ui % uspacing == 0) {
394  u = 0.1f * (float)ui;
395  pointOneWidthFactor = extraWidthFactor - pointOneAdjustment;
396 
397  // The geometry of the previous iteration is saved
398  Sid1Point0 = Sid1Point1;
399  CentPoint0 = CentPoint1;
400  Sid2Point0 = Sid2Point1;
401  Normal0 = Normal1;
402 
403  // The new geometry is generated
404  splineSide1.Feval(u, out Sid1Point1);
405  splineCenter.Feval(u, out CentPoint1);
406  splineSide2.Feval(u, out Sid2Point1);
407 
408  // The tangents at the three previous points are the same
409  splineSide2.Deval(u, out Tangent);
410  // Vector transversal to the ribbon
411  Transversal = Sid1Point1 - Sid2Point1;
412  Normal1 = Vector3.Cross(Transversal, Tangent);
413  Normal1.Normalize();
414 
415 
416  S1P0 = new Vector3(-Sid1Point0.x, Sid1Point0.y, Sid1Point0.z);
417  S1P1 = new Vector3(-Sid1Point1.x, Sid1Point1.y, Sid1Point1.z);
418 
419  S2P0 = new Vector3(-Sid2Point0.x, Sid2Point0.y, Sid2Point0.z);
420  S2P1 = new Vector3(-Sid2Point1.x, Sid2Point1.y, Sid2Point1.z);
421 
422  CP0 = new Vector3(-CentPoint0.x, CentPoint0.y, CentPoint0.z);
423  CP1 = new Vector3(-CentPoint1.x, CentPoint1.y, CentPoint1.z);
424 
425  Norm0 = new Vector3(-Normal0.x, Normal0.y, Normal0.z);
426  Norm1 = new Vector3(-Normal1.x, Normal1.y, Normal1.z);
427 
428  leftVect0 = S1P0 - CP0;
429  leftVect1 = S1P1 - CP1;
430 
431  rightVect0 = S2P0 - CP0;
432  rightVect1 = S2P1 - CP1;
433 
434  leftNormal0 = leftVect0.normalized;
435  leftNormal1 = leftVect1.normalized;
436 
437  rightNormal0 = rightVect0.normalized;
438  rightNormal1 = rightVect1.normalized;
439 
440  /*
441  Forward = (CP1 - CP0).normalized;
442  LeftDiag = (Forward + leftNormal0).normalized;
443  RightDiag = (Forward + rightNormal0).normalized;
444  */
445 
446  Forward = CP1 - CP0;
447  LeftDiag0 = (Forward.magnitude*Forward + (leftVect0.magnitude + ARROW_WIDTH)*leftVect0).normalized;
448  LeftDiag1 = (Forward.magnitude*Forward + (leftVect1.magnitude + ARROW_WIDTH)*leftVect1).normalized;
449  RightDiag0 = (Forward.magnitude*Forward + (rightVect0.magnitude + ARROW_WIDTH)*rightVect0).normalized;
450  RightDiag1 = (Forward.magnitude*Forward + (rightVect1.magnitude + ARROW_WIDTH)*rightVect1).normalized;
451 
452 
453  // The (Sid1Point0, Sid1Point1, CentPoint1) triangle is added.
454  vertices.Add(S1P0 + extraWidthFactor * leftNormal0);
455  normals.Add(Norm0);
456 
457  vertices.Add(S1P1 + pointOneWidthFactor * leftNormal1);
458  normals.Add(Norm1);
459 
460  vertices.Add(CP1);
461  normals.Add(Norm1);
462 
463  triangles.Add(vIndex);
464  triangles.Add(vIndex+1);
465  triangles.Add(vIndex+2);
466 
467  // and duplicated above
468  vertices.Add(S1P0 + THICKNESS * Norm0 + extraWidthFactor * leftNormal0);
469  normals.Add(-Norm0);
470 
471  vertices.Add(S1P1 + THICKNESS * Norm1 + pointOneWidthFactor * leftNormal1);
472  normals.Add(-Norm1);
473 
474  vertices.Add(CP1 + THICKNESS * Norm1);
475  normals.Add(-Norm1);
476 
477  triangles.Add(vIndex+3);
478  triangles.Add(vIndex+4);
479  triangles.Add(vIndex+5);
480 
481  // The (Sid1Point0, CentPoint1, CentPoint0) triangle is added.
482  vertices.Add(S1P0 + extraWidthFactor * leftNormal0);
483  normals.Add(Norm0);
484 
485  vertices.Add(CP1);
486  normals.Add(Norm1);
487 
488  vertices.Add(CP0);
489  normals.Add(Norm0);
490 
491  triangles.Add(vIndex+6);
492  triangles.Add(vIndex+7);
493  triangles.Add(vIndex+8);
494 
495  // and duplicated above
496  vertices.Add(S1P0 + THICKNESS * Norm0 + extraWidthFactor * leftNormal0);
497  normals.Add(-Norm0);
498 
499  vertices.Add(CP1 + THICKNESS * Norm1);
500  normals.Add(-Norm1);
501 
502  vertices.Add(CP0 + THICKNESS * Norm0);
503  normals.Add(-Norm0);
504 
505  triangles.Add(vIndex+9);
506  triangles.Add(vIndex+10);
507  triangles.Add(vIndex+11);
508 
509  // (Sid2Point0, Sid2Point1, CentPoint1) triangle is added.
510  vertices.Add(S2P0 + extraWidthFactor * rightNormal0);
511  normals.Add(Norm0);
512 
513  vertices.Add(S2P1 + pointOneWidthFactor * rightNormal1);
514  normals.Add(Norm1);
515 
516  vertices.Add(CP1);
517  normals.Add(Norm1);
518 
519  triangles.Add(vIndex+12);
520  triangles.Add(vIndex+13);
521  triangles.Add(vIndex+14);
522 
523  // and duplicated above
524  vertices.Add(S2P0 + THICKNESS * Norm0 + extraWidthFactor * rightNormal0);
525  normals.Add(-Norm0);
526 
527  vertices.Add(S2P1 + THICKNESS * Norm1 + pointOneWidthFactor * rightNormal1);
528  normals.Add(-Norm1);
529 
530  vertices.Add(CP1 + THICKNESS * Norm1);
531  normals.Add(-Norm1);
532 
533  triangles.Add(vIndex+15);
534  triangles.Add(vIndex+16);
535  triangles.Add(vIndex+17);
536 
537  // (Sid2Point0, CentPoint1, CentPoint0) triangle is added.
538  vertices.Add(S2P0 + extraWidthFactor * rightNormal0);
539  normals.Add(Norm0);
540 
541  vertices.Add(CP1);
542  normals.Add(Norm1);
543 
544  vertices.Add(CP0);
545  normals.Add(Norm0);
546 
547  triangles.Add(vIndex+18);
548  triangles.Add(vIndex+19);
549  triangles.Add(vIndex+20);
550 
551  // and duplicated above
552 
553  vertices.Add(S2P0 + THICKNESS * Norm0 + extraWidthFactor * rightNormal0);
554  normals.Add(-Norm0);
555 
556  vertices.Add(CP1 + THICKNESS * Norm1);
557  normals.Add(-Norm1);
558 
559  vertices.Add(CP0 + THICKNESS * Norm0);
560  normals.Add(-Norm0);
561 
562  triangles.Add(vIndex+21);
563  triangles.Add(vIndex+22);
564  triangles.Add(vIndex+23);
565 
566  // Duplicating the side vertices and giving them the proper normals
567  // for the sides of the thick ribbons
568  vertices.Add(S1P0 + extraWidthFactor * leftNormal0);
569  normals.Add(LeftDiag0);
570 
571  vertices.Add(S1P1 + pointOneWidthFactor * leftNormal1);
572  normals.Add(LeftDiag1);
573 
574  vertices.Add(S2P0 + extraWidthFactor * rightNormal0);
575  normals.Add(RightDiag0);
576 
577  vertices.Add(S2P1 + pointOneWidthFactor * rightNormal1);
578  normals.Add(RightDiag1);
579 
580  // and duplicating them again, this time raising them as well
581  vertices.Add(S1P0 + THICKNESS * Norm0 + extraWidthFactor * leftNormal0);
582  normals.Add(LeftDiag0);
583 
584  vertices.Add(S1P1 + THICKNESS * Norm1 + pointOneWidthFactor * leftNormal1);
585  normals.Add(LeftDiag1);
586 
587  vertices.Add(S2P0 + THICKNESS * Norm0 + extraWidthFactor * rightNormal0);
588  normals.Add(RightDiag0);
589 
590  vertices.Add(S2P1 + THICKNESS * Norm1 + pointOneWidthFactor * rightNormal1);
591  normals.Add(RightDiag1);
592 
593  // Side triangles
594  triangles.Add(vIndex+24);
595  triangles.Add(vIndex+25);
596  triangles.Add(vIndex+28);
597 
598  triangles.Add(vIndex+25);
599  triangles.Add(vIndex+28);
600  triangles.Add(vIndex+29);
601 
602  triangles.Add(vIndex+26);
603  triangles.Add(vIndex+27);
604  triangles.Add(vIndex+30);
605 
606  triangles.Add(vIndex+27);
607  triangles.Add(vIndex+30);
608  triangles.Add(vIndex+31);
609 
610  // Backside triangles for the arrow
611  /*
612  triangles.Add(vIndex+24);
613  triangles.Add(vIndex+8);
614  triangles.Add(vIndex+28);
615 
616  triangles.Add(vIndex+8);
617  triangles.Add(vIndex+11);
618  triangles.Add(vIndex+28);
619 
620  triangles.Add(vIndex+8);
621  triangles.Add(vIndex+11);
622  triangles.Add(vIndex+30);
623 
624  triangles.Add(vIndex+8);
625  triangles.Add(vIndex+26);
626  triangles.Add(vIndex+30);
627  */
628  vIndex += 32;
629  extraWidthFactor = extraWidthFactor - pointOneAdjustment;
630  }
631  }
632  } // End of GenerateArrowRibbon
633 
634  private void GenerateFlatRibbon(List<Vector3> vertices, List<Vector3> normals, List<int> triangles) {
635  Vector3 CentPoint0, CentPoint1, Sid1Point0, Sid1Point1, Sid2Point0, Sid2Point1,
636  Transversal, Tangent, Normal0, Normal1;
637  Vector3 CP0, CP1, S1P0, S1P1, S2P0, S2P1, Norm0, Norm1;
638  int ui;
639  float u=0f; // needs to be assigned
640  CentPoint0 = CentPoint1 = Sid1Point0 = Sid1Point1 = Sid2Point0 = Sid2Point1 = Transversal = Tangent = Normal0 = Normal1 = Vector3.zero;
641  CP0 = CP1 = S1P0 = S1P1 = S2P0 = S2P1 = Norm0 = Norm1 = Vector3.zero;
642  // The initial geometry is generated
643  splineSide1.Feval(0f, out Sid1Point1);
644  splineCenter.Feval(0f, out CentPoint1);
645  splineSide2.Feval(0f, out Sid2Point1);
646 
647  // The tangents at the three previous points are the same
648  splineSide2.Deval(0f, out Tangent);
649 
650  // Vector transversal to the ribbon
651  Transversal = Sid1Point1 - Sid2Point1;
652  Normal1 = Vector3.Cross(Transversal, Tangent);
653  Normal1.Normalize();
654 
655  Vector3 leftNormal0, leftNormal1, rightNormal0, rightNormal1;
656  for(ui=1; ui<=10; ui++) {
657  if(ui % uspacing == 0) {
658  u = 0.1f * (float)ui;
659 
660  // The geometry of the previous iteration is saved
661  Sid1Point0 = Sid1Point1;
662  CentPoint0 = CentPoint1;
663  Sid2Point0 = Sid2Point1;
664  Normal0 = Normal1;
665 
666  // The new geometry is generated
667  splineSide1.Feval(u, out Sid1Point1);
668  splineCenter.Feval(u, out CentPoint1);
669  splineSide2.Feval(u, out Sid2Point1);
670 
671  // The tangents at the three previous points are the same
672  splineSide2.Deval(u, out Tangent);
673  // Vector transversal to the ribbon
674  Transversal = Sid1Point1 - Sid2Point1;
675  Normal1 = Vector3.Cross(Transversal, Tangent);
676  Normal1.Normalize();
677 
678  // The x coordinates must be flipped, but the original vectors can't be
679  // modified because they will be reused in the next iteration.
680  S1P0 = new Vector3(-Sid1Point0.x, Sid1Point0.y, Sid1Point0.z);
681  S1P1 = new Vector3(-Sid1Point1.x, Sid1Point1.y, Sid1Point1.z);
682 
683  S2P0 = new Vector3(-Sid2Point0.x, Sid2Point0.y, Sid2Point0.z);
684  S2P1 = new Vector3(-Sid2Point1.x, Sid2Point1.y, Sid2Point1.z);
685 
686  CP0 = new Vector3(-CentPoint0.x, CentPoint0.y, CentPoint0.z);
687  CP1 = new Vector3(-CentPoint1.x, CentPoint1.y, CentPoint1.z);
688 
689  Norm0 = new Vector3(-Normal0.x, Normal0.y, Normal0.z);
690  Norm1 = new Vector3(-Normal1.x, Normal1.y, Normal1.z);
691 
692  // Left and right may be reversed, but either way,
693  // these normals point outwards from the ribbons, horizontally.
694  leftNormal0 = (S1P0 - CP0).normalized;
695  leftNormal1 = (S1P1 - CP1).normalized;
696 
697  rightNormal0 = (S2P0 - CP0).normalized;
698  rightNormal1 = (S2P1 - CP1).normalized;
699 
700  // The (Sid1Point0, Sid1Point1, CentPoint1) triangle is added.
701  vertices.Add(S1P0);
702  normals.Add(Norm0);
703 
704  vertices.Add(S1P1);
705  normals.Add(Norm1);
706 
707  vertices.Add(CP1);
708  normals.Add(Norm1);
709 
710  triangles.Add(vIndex);
711  triangles.Add(vIndex+1);
712  triangles.Add(vIndex+2);
713 
714  // and duplicated above
715  vertices.Add(S1P0 + THICKNESS * Norm0);
716  normals.Add(-Norm0);
717 
718  vertices.Add(S1P1 + THICKNESS * Norm1);
719  normals.Add(-Norm1);
720 
721  vertices.Add(CP1 + THICKNESS * Norm1);
722  normals.Add(-Norm1);
723 
724  triangles.Add(vIndex+3);
725  triangles.Add(vIndex+4);
726  triangles.Add(vIndex+5);
727 
728  // The (Sid1Point0, CentPoint1, CentPoint0) triangle is added.
729  vertices.Add(S1P0);
730  normals.Add(Norm0);
731 
732  vertices.Add(CP1);
733  normals.Add(Norm1);
734 
735  vertices.Add(CP0);
736  normals.Add(Norm0);
737 
738  triangles.Add(vIndex+6);
739  triangles.Add(vIndex+7);
740  triangles.Add(vIndex+8);
741 
742  // and duplicated above
743  vertices.Add(S1P0 + THICKNESS * Norm0);
744  normals.Add(-Norm0);
745 
746  vertices.Add(CP1 + THICKNESS * Norm1);
747  normals.Add(-Norm1);
748 
749  vertices.Add(CP0 + THICKNESS * Norm0);
750  normals.Add(-Norm0);
751 
752  triangles.Add(vIndex+9);
753  triangles.Add(vIndex+10);
754  triangles.Add(vIndex+11);
755 
756  // (Sid2Point0, Sid2Point1, CentPoint1) triangle is added.
757  vertices.Add(S2P0);
758  normals.Add(Norm0);
759 
760  vertices.Add(S2P1);
761  normals.Add(Norm1);
762 
763  vertices.Add(CP1);
764  normals.Add(Norm1);
765 
766  triangles.Add(vIndex+12);
767  triangles.Add(vIndex+13);
768  triangles.Add(vIndex+14);
769 
770  // and duplicated above
771  vertices.Add(S2P0 + THICKNESS * Norm0);
772  normals.Add(-Norm0);
773 
774  vertices.Add(S2P1 + THICKNESS * Norm1);
775  normals.Add(-Norm1);
776 
777  vertices.Add(CP1 + THICKNESS * Norm1);
778  normals.Add(-Norm1);
779 
780  triangles.Add(vIndex+15);
781  triangles.Add(vIndex+16);
782  triangles.Add(vIndex+17);
783 
784  // (Sid2Point0, CentPoint1, CentPoint0) triangle is added.
785  vertices.Add(S2P0);
786  normals.Add(Norm0);
787 
788  vertices.Add(CP1);
789  normals.Add(Norm1);
790 
791  vertices.Add(CP0);
792  normals.Add(Norm0);
793 
794  triangles.Add(vIndex+18);
795  triangles.Add(vIndex+19);
796  triangles.Add(vIndex+20);
797 
798  // and duplicated above
799  vertices.Add(S2P0 + THICKNESS * Norm0);
800  normals.Add(-Norm0);
801 
802  vertices.Add(CP1 + THICKNESS * Norm1);
803  normals.Add(-Norm1);
804 
805  vertices.Add(CP0 + THICKNESS * Norm0);
806  normals.Add(-Norm0);
807 
808  triangles.Add(vIndex+21);
809  triangles.Add(vIndex+22);
810  triangles.Add(vIndex+23);
811 
812  // Duplicating the side vertices and giving them the proper normals
813  // for the sides of the thick ribbons
814  vertices.Add(S1P0);
815  normals.Add(leftNormal0);
816 
817  vertices.Add(S1P1);
818  normals.Add(leftNormal1);
819 
820  vertices.Add(S2P0);
821  normals.Add(rightNormal0);
822 
823  vertices.Add(S2P1);
824  normals.Add(rightNormal1);
825 
826  // and duplicating them again, this time raising them as well
827  vertices.Add(S1P0 + THICKNESS * Norm0);
828  normals.Add(leftNormal0);
829 
830  vertices.Add(S1P1 + THICKNESS * Norm1);
831  normals.Add(leftNormal1);
832 
833  vertices.Add(S2P0 + THICKNESS * Norm0);
834  normals.Add(rightNormal0);
835 
836  vertices.Add(S2P1 + THICKNESS * Norm1);
837  normals.Add(rightNormal1);
838 
839  // Side triangles
840  triangles.Add(vIndex+24);
841  triangles.Add(vIndex+25);
842  triangles.Add(vIndex+28);
843 
844  triangles.Add(vIndex+25);
845  triangles.Add(vIndex+28);
846  triangles.Add(vIndex+29);
847 
848  triangles.Add(vIndex+26);
849  triangles.Add(vIndex+27);
850  triangles.Add(vIndex+30);
851 
852  triangles.Add(vIndex+27);
853  triangles.Add(vIndex+30);
854  triangles.Add(vIndex+31);
855 
856  vIndex += 32;
857  }
858  }
859  } // End of GenerateFlatRibbons
860 
861  private List<int> Copy(List<int> l) {
862  List<int> result = new List<int>();
863  foreach(int i in l)
864  result.Add(i);
865  return result;
866  }
867 
868 
869  public void CreateRibbons() {
870 
871  List<Dictionary<string, Vector3>> residueDicts = Molecule.Model.MoleculeModel.residueDictionaries;
872  if(residueDicts.Count == 0)
873  return;
874  int[] ssarray = new int[residueDicts.Count];
875  int[] handedarray = new int[residueDicts.Count];
876 
877  // if both helix and strand list are empty, use the default algo to generate ss
878  if(Molecule.Model.MoleculeModel.ssHelixList.Count == 0
879  && Molecule.Model.MoleculeModel.ssStrandList.Count == 0)
880  createss = false;
881  // bug when the first residue < 0. Have to be fixed.
882  else if (Molecule.Model.MoleculeModel.firstresnb < 0)
883  createss = false;
884  // else use the ss informations contains in the pdb file
885  else
886  createss = true;
887 
888  Debug.Log ("Use info from pdb: " + createss);
889 
890  if (createss) {
891  CreateSSlist (ref sslist, ref handedlist);
892  ssarray = sslist.ToArray();
893  handedarray = handedlist.ToArray();
894  }
895 
896  if(!mustSplitDictList) {
897  CreateRibbons(residueDicts, sslist, handedlist);
898  return;
899  }
900 
901  Debug.Log("Ribbons.cs::CreateRibons() > Splitting");
902  List<int> splits = Copy(Molecule.Model.MoleculeModel.splits);
904  List<Dictionary<string, Vector3>> tmpDictList = new List<Dictionary<string, Vector3>>();
905  List<int> tmpHandednessList = new List<int> ();
906  List<int> tmpSSList = new List<int>();
907 
908 
909  //Split chains
910  while(resNb<residueDicts.Count && splits.Count>0) {
911 
912  if(resNb != splits[0]){
913  currentchain = Molecule.Model.MoleculeModel.resChainList2[resNb];
914  ribbontag = "RibbonObj" + currentchain;
915  tmpDictList.Add(residueDicts[resNb]);
916  if(ssarray.Length != 0){
917  tmpSSList.Add (ssarray[resNb]);
918  tmpHandednessList.Add (handedarray[resNb]);
919  }
920  }
921  else {
922  Debug.Log("Splitting at ResNB: " + resNb.ToString());
923  CreateRibbons(tmpDictList, tmpSSList, tmpHandednessList);
924  tmpDictList.Clear();
925  tmpSSList.Clear ();
926  tmpHandednessList.Clear ();
927  splits.RemoveAt(0);
928  }
929  resNb++;
930  }
931 // Debug.Log ("ribbontag " + ribbontag);
932  if(tmpDictList.Count > 0 && tmpSSList.Count > 0)
933  CreateRibbons(tmpDictList, tmpSSList, tmpHandednessList);
934  }
935 
936  private void CreateRibbons(List<Dictionary<string, Vector3>> residueDicts, List<int> sslist, List<int >handedlist) {
937 
938  // For line ribbons
939  List<Vector3> vertices0 = new List<Vector3>();
940  List<Vector3> vertices1 = new List<Vector3>();
941  List<Vector3> vertices2 = new List<Vector3>();
942 
943  // For flat ribbons
944  List<Vector3> vertices = new List<Vector3>();
945  List<Color32> colors = new List<Color32>();
946  List<Vector3> normals = new List<Vector3>();
947 
948  switch(RIBBON_DETAIL) {
949  case 1:
950  uspacing = 10;
951  break;
952  case 2:
953  uspacing = 5;
954  break;
955  case 3:
956  uspacing = 2;
957  break;
958  default:
959  uspacing = 1;
960  break;
961  }
962 
963  flipTestV = new Vector3();
964  splineSide1 = new BSpline(false);
965  splineCenter = new BSpline(false);
966  splineSide2 = new BSpline(false);
967 
968  int[] ss = new int[residueDicts.Count];
969  int[] handedness = new int[residueDicts.Count];
970  List<int> ssglic = new List<int> (); // Specific to Glic for now (split differents domains)
971  int nbRes = residueDicts.Count;
972  int colorOffset = nbRes - 1;
973 
974 
975  if (createss) { // if ss informations in the pdb file
976  ss = sslist.ToArray ();
977  handedness = handedlist.ToArray ();
978  } else {
979  CalculateSecondaryStructures (residueDicts, ss, handedness);
980  nbRes = residueDicts.Count;
981  // Colors and structures are misaligned without this offset. Not sure why.
982  // Keeping identical offsets?
983  colorOffset = nbRes - 1;
984  //int arrowOffset = nbRes - 1;
985  //colorOffset = 0;
986 
987  for (int i=1; i<nbRes-1; i++) {
988  if (ss [i - 1] == HELIX && ss [i + 1] == HELIX)
989  ss [i] = HELIX;
990  if (ss [i - 1] == STRAND && ss [i + 1] == STRAND)
991  ss [i] = STRAND;
992  }
993  }
994 
995  InitCol(); //Initialization Dictionary of colors
996 
997  List<int> triangles = new List<int>();
998  vIndex = 0;
999  bool isArrow;
1000  for(int i=0; i<nbRes; i++) {
1001 
1002  ConstructControlPoints(residueDicts, i, ss[i], handedness[i]);
1003  int colorIndex = (i+colorOffset) % nbRes;
1004  //int arrowIndex = (i+arrowOffset) % nbRes;
1005  isArrow = (ss[colorIndex] == STRAND && ( (colorIndex+1 == nbRes) || (ss[colorIndex+1] != STRAND) ));
1006 
1007  if(RENDER_MODE == 0) {
1008  GenerateSpline(0, vertices0);
1009  GenerateSpline(1, vertices1);
1010  GenerateSpline(2, vertices2);
1011  } else {
1012  if (isArrow && ARROW_WIDTH > 0f)
1013  GenerateArrowRibbon(vertices, normals, triangles);
1014  else
1015  GenerateFlatRibbon(vertices, normals, triangles);
1016 
1017  Color32 color;
1018 
1020  color = GetColorChain(currentchain);
1021  if(i > 185 && SecondaryStructureOldGUI.ssDivCol ){
1022  color.g += 100;
1023  color.b += 100;}
1024  }else{
1025 
1026  switch(ss[colorIndex]) {
1027  case HELIX:
1028  color = HELIX_COLOR.color;
1029  break;
1030  case STRAND:
1031  color = STRAND_COLOR.color;
1032  break;
1033  default:
1034  color = COIL_COLOR.color;
1035  break;
1036  }
1037  }
1038  for(int j=0; j<320; j++)
1039  colors.Add(color);
1040 
1041  ssglic.Add(ss[i]);
1042  }
1043  }
1044 
1045  if(RENDER_MODE == 0) {
1046  // Forget that for now
1047  } else {
1048  PostProcessing.GenerateMeshes(vertices, normals, triangles, colors, ss);
1049  }
1050 
1051  } // End of CreateRibbons
1052 
1058  private List<float[]> FindHelix (string chain){
1059 
1060  List<float[]> helix = Molecule.Model.MoleculeModel.ssHelixList;
1061  List<float[]> helixlist = new List<float[]> ();
1062 
1063  for (int i = 0; i < helix.Count; i++) {
1064  if (Molecule.Model.MoleculeModel.helixChainList [i] == chain)
1065  helixlist.Add (helix [i]);
1066  }
1067 
1068  // bug when list goes empty (dunno if necessary anymore)
1069  if(helixlist.Count != 0)
1070  helixlist.Add (helixlist[helixlist.Count - 1]);
1071  return helixlist;
1072  }
1073 
1079  private List<float[]> FindStrand (string chain){
1080 
1081  List<float[]> strand = Molecule.Model.MoleculeModel.ssStrandList;
1082  List<float[]> strandlist = new List<float[]> ();
1083 
1084  for (int i = 0; i < strand.Count; i++) {
1085  if (Molecule.Model.MoleculeModel.strandChainList [i] == chain){
1086  strandlist.Add (strand [i]);
1087  }
1088  }
1089  return strandlist;
1090  }
1091 
1092  private int ComputeNbRes(string chain){
1093 
1094  List<string> reschain = Molecule.Model.MoleculeModel.resChainList2;
1095  int nbres = 0;
1096 
1097  for (int i = 0; i < reschain.Count; i++) {
1098  if(reschain[i] == chain)
1099  nbres++;
1100  }
1101 
1102  return nbres;
1103  }
1104 
1105  private List<float[]> SortStrand( List<float[]> tmpstrandlist){
1106 
1107  for (int i = 0; i < tmpstrandlist.Count; i++) {
1108  for(int j = i; j < tmpstrandlist.Count; j++){
1109  if(tmpstrandlist[j][0] < tmpstrandlist[i][0]){
1110  float[] tmp = tmpstrandlist[i];
1111  tmpstrandlist[i] = tmpstrandlist[j];
1112  tmpstrandlist[j] = tmp;
1113  }
1114  }
1115  }
1116 
1117  int index = 0;
1118 
1119  while (index < tmpstrandlist.Count - 1)
1120  {
1121  if (tmpstrandlist[index][0] == tmpstrandlist[index + 1][0])
1122  tmpstrandlist.RemoveAt(index);
1123  else
1124  index++;
1125  }
1126 
1127  tmpstrandlist.Add (tmpstrandlist [tmpstrandlist.Count - 1]);
1128  return tmpstrandlist;
1129  } // End SortStrand
1130 
1132 
1138  private void CreateSSlist( ref List<int> sslist, ref List<int> handednesslist){
1139 
1140  foreach (string chain in Molecule.Model.MoleculeModel.existingChain) {
1141 
1142  int nbres = ComputeNbRes(chain);
1143 
1144  List<float[]> tmplisthelix2 = FindHelix(chain);
1145  List<float[]> tmpliststrand2 = FindStrand(chain);
1146 
1147  List<float[]> tmpliststrand = new List<float[]>();
1148  List<float[]> tmplisthelix = new List<float[]>();
1149 
1150  // Need to sort the ss lists
1151  if (tmpliststrand2.Count != 0)
1152  tmpliststrand = SortStrand(tmpliststrand2);
1153  else{
1154  // bug when the list goes empty (dunno if that's really necessary)
1155  float[] b = new float[2];
1156  b[0] = 0;
1157  b[1] = 0;
1158  tmpliststrand.Add(b);
1159  }
1160 
1161  if (tmplisthelix2.Count != 0){
1162  tmplisthelix = tmplisthelix2;
1163  }else{
1164  float[] b = new float[4];
1165  b[0] = 0;
1166  b[1] = 0;
1167  b[2] = 0;
1168  b[3] = 0;
1169  tmplisthelix.Add(b);
1170  }
1171 
1172  //Fill sslist with the informations extract from the pdb (use to generate ribbons)
1173  for(int j = firstresnb; j<nbres+firstresnb; j++){
1174  if(j >= tmpliststrand[0][0] && j < tmpliststrand[0][1]){
1175  sslist.Add(STRAND);
1176  handednesslist.Add (RHANDED);
1177  }
1178  else if(j == tmpliststrand[0][1]){
1179  sslist.Add(STRAND);
1180  handednesslist.Add (RHANDED);
1181  tmpliststrand.RemoveAt(0);
1182  }
1183  else if(j >= tmplisthelix[0][0] && j < tmplisthelix[0][1]){
1184  sslist.Add(HELIX);
1185  if(tmplisthelix[0][3] <= 5 && !UI.UIData.guided)
1186  handednesslist.Add (RHANDED);
1187  else
1188  handednesslist.Add (LHANDED);
1189  }
1190  else if(j == tmplisthelix[0][1]){
1191  sslist.Add(HELIX);
1192  handednesslist.Add (RHANDED);
1193  tmplisthelix.RemoveAt(0);
1194  }
1195  else{
1196  sslist.Add(COIL);
1197  handednesslist.Add (RHANDED);
1198  }
1199  }
1200  }
1201  sslist.RemoveAt (0);
1202  handednesslist.RemoveAt (0);
1203 
1204  }//End CreateSSlist
1205 
1206  private static Dictionary<string, Color32> ss_chain_col = null;
1207 
1208  public static void InitCol() {
1209  ss_chain_col = new Dictionary <string, Color32> ();
1210 
1211  // Color by Chain
1212 
1213  ss_chain_col.Add ("A", ChainColorA.color);
1214  ss_chain_col.Add ("AL", new Color32( 50, 50, 100, 255));
1215  ss_chain_col.Add ("B", ChainColorB.color);
1216  ss_chain_col.Add ("BL", new Color32(60, 120, 60, 255));
1217  ss_chain_col.Add ("C", ChainColorC.color);
1218  ss_chain_col.Add ("CL", new Color32(50, 90, 90, 255));
1219  ss_chain_col.Add ("D", ChainColorD.color);
1220  ss_chain_col.Add ("DL", new Color32(60, 150, 60, 255));
1221  ss_chain_col.Add ("E", ChainColorE.color);
1222  ss_chain_col.Add ("EL", new Color32(60, 150, 150, 255));
1223 
1224  }
1225 
1226  public static Color32 GetColorChain(string type) {
1227  Color32 value = new Color32(255, 255, 255, 255);
1228  if(ss_chain_col == null)
1229  return new Color32(255, 255, 255, 255);
1230  else if(!ss_chain_col.TryGetValue(type, out value))
1231  return new Color32(255, 255, 255, 255);
1232  else
1233  return ss_chain_col[type];
1234  }
1235 
1236 
1237 }
void AddControlPoints(Vector3 ca0, Vector3 ox0, Vector3 ca1, int ss, int handedness)
Definition: Ribbons.cs:191
void ShiftBSplineCPoints()
Definition: BSpline.cs:170
static List< Dictionary< string, Vector3 > > residueDictionaries
static ColorObject ChainColorD
Definition: Ribbons.cs:37
static string ribbontag
Definition: Ribbons.cs:18
static bool ssDivCol
When true, triggers the per domain coloring.
void GetCPoint(int n, out Vector3 p)
Definition: BSpline.cs:162
static List< string > resChainList2
The chain of each residue.
void Deval(float t, out Vector3 d)
Definition: BSpline.cs:286
void GenerateSpline(int n, List< Vector3 > vertices)
Definition: Ribbons.cs:330
static ColorObject ChainColorB
Definition: Ribbons.cs:35
void CopyCPoints(int n_source, int n_dest)
Definition: BSpline.cs:181
static Dictionary< string, Color32 > ss_chain_col
Definition: Ribbons.cs:1206
static float[] ribbonWidth
Definition: Ribbons.cs:44
static bool ssColChain
When true, triggers the per chain secondary structure coloring.
const int HELIX
Definition: Ribbons.cs:21
void CreateRibbons(List< Dictionary< string, Vector3 >> residueDicts, List< int > sslist, List< int >handedlist)
Definition: Ribbons.cs:936
static float HELIX_DIAM
Definition: Ribbons.cs:40
static ColorObject COIL_COLOR
Definition: Ribbons.cs:32
static bool guided
Definition: UIData.cs:201
BSpline splineSide2
Definition: Ribbons.cs:11
float CalculateTorsionalAngle(Vector3 at0, Vector3 at1, Vector3 at2, Vector3 at3, bool print)
Definition: Ribbons.cs:46
List< int > sslist
Definition: Ribbons.cs:16
int uspacing
Definition: Ribbons.cs:12
static List< string > helixChainList
The helix chain list (extract from the pdb).
const int LHANDED
Definition: Ribbons.cs:24
static int RENDER_MODE
Definition: Ribbons.cs:28
List< float[]> FindStrand(string chain)
Find strands by chain in ssStrandList (informations from the pdb file).
Definition: Ribbons.cs:1079
static ColorObject ChainColorC
Definition: Ribbons.cs:36
List< float[]> FindHelix(string chain)
Finds helices by chain in ssHelixList (informations from the pdb file).
Definition: Ribbons.cs:1058
Color color
Definition: ColorObject.cs:72
int vIndex
Definition: Ribbons.cs:13
List< float[]> SortStrand(List< float[]> tmpstrandlist)
Definition: Ribbons.cs:1105
void ShiftControlPoints()
Definition: Ribbons.cs:238
int firstresnb
Definition: Ribbons.cs:1131
static void GenerateMeshes(List< Vector3 > vertices, List< Vector3 > normals, List< int > triangles, List< Color32 > colors, int[] ss, string tag="RibbonObj", string gameobj="Ribbons")
static ColorObject ChainColorA
Definition: Ribbons.cs:34
static List< int > splits
Terminal residue number of each subunits.
int ComputeNbRes(string chain)
Definition: Ribbons.cs:1092
static bool mustSplitDictList
Definition: Ribbons.cs:7
static float ARROW_WIDTH
Definition: Ribbons.cs:42
static List< float[]> ssStrandList
First and last residue of each strand (extract from the pdb) float[0] is the first residue of each st...
void CreateRibbons()
Definition: Ribbons.cs:869
static List< float[]> ssHelixList
List of informations about each helix (extract from the pdb) float[0] is the first residue of each he...
static int RIBBON_DETAIL
Definition: Ribbons.cs:27
List< int > handedlist
Definition: Ribbons.cs:15
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
static Color32 GetColorChain(string type)
Definition: Ribbons.cs:1226
static ColorObject STRAND_COLOR
Definition: Ribbons.cs:31
void ConstructControlPoints(List< Dictionary< string, Vector3 >> residueDicts, int res, int ss, int handedness)
Definition: Ribbons.cs:245
void CalculateSecondaryStructures(List< Dictionary< string, Vector3 >> residueDicts, int[] ss, int[] handedness)
Definition: Ribbons.cs:84
void CreateSSlist(ref List< int > sslist, ref List< int > handednesslist)
Creates secondary structure list and handedness list using ss informations from the pdb file...
Definition: Ribbons.cs:1138
const int COIL
Definition: Ribbons.cs:23
void GenerateFlatRibbon(List< Vector3 > vertices, List< Vector3 > normals, List< int > triangles)
Definition: Ribbons.cs:634
static List< string > existingChain
List of the chains existing in the molecule.
static ColorObject ChainColorE
Definition: Ribbons.cs:38
static void InitCol()
Definition: Ribbons.cs:1208
static string currentchain
Definition: Ribbons.cs:19
BSpline splineCenter
Definition: Ribbons.cs:9
void GenerateArrowRibbon(List< Vector3 > vertices, List< Vector3 > normals, List< int > triangles)
Definition: Ribbons.cs:363
bool createss
Definition: Ribbons.cs:17
const int STRAND
Definition: Ribbons.cs:22
const int RHANDED
Definition: Ribbons.cs:25
void SetCPoint(int n, Vector3 p)
Definition: BSpline.cs:154
Vector3 LinearComb(float scalar0, Vector3 vector0, float scalar1, Vector3 vector1)
Definition: Ribbons.cs:186
static int firstresnb
First residue number in pdb.
static List< string > strandChainList
The strand chain list (extract from the pdb).
Vector3 flipTestV
Definition: Ribbons.cs:8
BSpline splineSide1
Definition: Ribbons.cs:10
void Feval(float t, out Vector3 p)
Definition: BSpline.cs:271
List< int > Copy(List< int > l)
Definition: Ribbons.cs:861
void UpdateMatrix3()
Definition: BSpline.cs:140
float WeirdDistance(float x1, float y1, float x2, float y2)
Definition: Ribbons.cs:78
static float THICKNESS
Definition: Ribbons.cs:41
static ColorObject HELIX_COLOR
Definition: Ribbons.cs:30
Definition: GUIDisplay.cs:66