3 using System.Collections.Generic;
30 public List<GraphVertex>
molAsGraph =
new List<GraphVertex>();
31 public List<List<int>>
cycles =
new List<List<int>>();
35 public List<Vector3>
barylist =
new List<Vector3>();
38 private Vector3
LinearComb(
float scalar0, Vector3 vector0,
float scalar1, Vector3 vector1) {
39 return scalar0*vector0 + scalar1*vector1;
42 public List<Vector3>
vertices =
new List<Vector3>();
43 public List<Color32>
colors =
new List<Color32>();
44 public List<Vector3>
normals =
new List<Vector3>();
73 Vector3 returnVector =
new Vector3(point[0], point[1], point[2]);
85 public Dictionary <int, Dictionary<int, int[]> >
MeshIndexForAtom =
new Dictionary<int, Dictionary<int, int[]>>();
86 public Dictionary <int, string>
res_for_bond =
new Dictionary<int, string>();
105 MeshIndexForAtom[6]=
new Dictionary<int, int[]> () ;
106 MeshIndexForAtom[6][0] =
new int[2]{1,2};
107 MeshIndexForAtom[6][1] =
new int[2]{3,4};
108 MeshIndexForAtom[6][2] =
new int[2]{5,6};
109 MeshIndexForAtom[6][3] =
new int[2]{7,8};
110 MeshIndexForAtom[6][4] =
new int[2]{9,10};
111 MeshIndexForAtom[6][5] =
new int[2]{11,0};
113 MeshIndexForAtom[5]=
new Dictionary<int, int[]> () ;
114 MeshIndexForAtom[5][0]=
new int[2]{0,1};
115 MeshIndexForAtom[5][1]=
new int[2]{2,3};
116 MeshIndexForAtom[5][2]=
new int[2]{4,5};
117 MeshIndexForAtom[5][3]=
new int[2]{6,7};
118 MeshIndexForAtom[5][4]=
new int[2]{8,9};
123 for (
int i=0; i<atomsLocationlist.Count; i++){
126 tempVertex.
coordinate=(
new Vector3(atomsLocationlist[i][0],
127 atomsLocationlist[i][1],
128 atomsLocationlist[i][2]));
130 tempVertex.
resname=atomsResnamelist[i];
131 tempVertex.
type=atomsNamelist[i][0];
133 molAsGraph.Add(tempVertex);
140 for (
int i=0; i < bondEPList.Count; i++){
141 molAsGraph[bondEPList[i][0]].neighbor.Add(molAsGraph[bondEPList[i][1]]);
142 molAsGraph[bondEPList[i][1]].neighbor.Add(molAsGraph[bondEPList[i][0]]);
149 for (
int i=0; i<molAsGraph.Count; i++){
150 List<int> indexCycle =
new List<int>();
151 molAsGraph[i].SearchCycle(indexCycle, i);
155 for (
int j=0; j<molAsGraph.Count; j++)
156 molAsGraph[j].flag=
false;
158 if (indexCycle.Count>0){
160 if(!cycles.Any (x => x.OrderBy(y => y).SequenceEqual(indexCycle.OrderBy(z=>z)))){
161 cycles.Add(indexCycle);
162 residueslist.Add(molAsGraph[i].resname);
167 for (
int i=0; i<cycles.Count; i++){
168 for (
int j=0; j<cycles[i].Count; j++){
169 molAsGraph[cycles[i][j]].idRing = i;
175 for (
int i=0; i<molAsGraph.Count; i++){
176 List<int> trashlish =
new List<int>();
177 molAsGraph[i].SearchConnection(connectivityList,trashlish);
179 for (
int j=0; j<molAsGraph.Count; j++)
180 molAsGraph[j].flag=
false;
189 public List<List<GameObject>>
createSugarRibs(
float RibbonsThickness,
bool sugarOnly,
float thickness_Little,
float thickness_BIG,
190 float thickness_bond_6_C1_C4,
float thickness_6_other,
float thickness_bond_5,
191 float lighter_color_factor_ring,
float lighter_color_factor_bond,
int color_mode_ring,
int color_mode_bond,
193 sugarResname.AddMany(
"ABE",
"ACE",
"ALT",
"API",
"ARA",
"DHA",
"FRU",
"FUC",
"GAL",
"GLC",
"GUL",
"IDO",
"DKN",
"KDO",
"MAN",
"NEG",
"RHA",
"RIB",
"SIA",
"TAG",
"TAL",
"XYL");
194 SUGAR_ONLY=sugarOnly;
195 THICKNESS_LITTLE_MESH=thickness_Little;
196 THICKNESS_BIG_MESH=thickness_BIG;
197 THICKNESS_BOND_6_C1_C4=thickness_bond_6_C1_C4;
198 THICKNESS_BOND_6_OTHER=thickness_6_other;
199 THICKNESS_BOND_5=thickness_bond_5;
200 LIGHTER_COLOR_FACTOR_RING = lighter_color_factor_ring;
201 LIGHTER_COLOR_FACTOR_BOND = lighter_color_factor_bond;
202 COLOR_MODE_RING = color_mode_ring;
203 COLOR_MODE_BOND = color_mode_bond;
204 BONDCOLOR = bondcolor;
205 RINGCOLOR = ringcolor;
206 OXYSPHERESIZE = OxySphereSize;
207 OXYSPHERECOLOR = OxySphereColor;
208 THICKNESS = RibbonsThickness;
243 for (
int i=0; i<cycles.Count; i++){
244 Mesh sugarMesh =
new Mesh ();
245 List<int> trianglesSM =
new List<int> ();
246 List<Vector3> verticesSM =
new List<Vector3> ();
247 List<Color32> colorsSM =
new List<Color32> ();
248 resname=residueslist[i];
251 for (
int j=0; j<cycles[i].Count; j++){
257 colorsSM.Add(
new Color(0.7f,0.7f,0.7f,0.5f));
260 int size = cycles[i].Count;
261 int nbiter = (size-2)/2;
262 int reste = (size-2)%2;
264 for (
int j=0; j<nbiter; j++){
265 trianglesSM.AddMany(j,size-1-j,(size-1)-(j+1));
266 trianglesSM.AddMany(j,(size-1)-(j+1),j+1);
267 if ((reste==1) && (j==nbiter-1)){
268 trianglesSM.AddMany(j+1,(size-1)-(j+1),j+2);
274 sugarMesh.vertices = verticesSM.ToArray();
275 sugarMesh.triangles = trianglesSM.ToArray();
276 sugarMesh.colors32 = colorsSM.ToArray();
278 CycleMesh.Add(sugarMesh);
288 List<Vector3> verticesEn =
new List<Vector3>();
292 if (cycles[i].Count == 6){
320 }
else if (cycles[i].Count == 5){
349 Debug.Log(
"WARNING ==> RING WITH "+cycles[i].Count+
" :: REPRESENTATON NOT IMPLEMENTED");
358 List<Vector3> newVertices =
new List<Vector3>();
360 if (verticeEn.Count == 6){
396 for (
int i=0; i<cycles.Count; i++){
397 Mesh sugarMesh =
new Mesh ();
398 List<int> trianglesSM =
new List<int> ();
399 List<Vector3> verticesSM =
new List<Vector3> ();
400 List<Color32> colorsSM =
new List<Color32> ();
401 resname=residueslist[i];
407 for (
int j=0; j<verticesSM.Count; j++){
408 if (COLOR_MODE_RING == SUGAR){
412 colorsSM.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_RING));
413 }
else if (COLOR_MODE_RING == CHAIN){
417 colorsSM.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_RING));
418 }
else if (COLOR_MODE_RING == PICKER){
424 int size = verticesSM.Count;
425 int nbiter = (size-2)/2;
426 int reste = (size-2)%2;
429 for (
int j=0; j<nbiter; j++){
430 trianglesSM.AddMany(j,size-1-j,(size-1)-(j+1));
431 trianglesSM.AddMany(j,(size-1)-(j+1),j+1);
432 if ((reste==1) && (j==nbiter-1)){
433 trianglesSM.AddMany(j+1,(size-1)-(j+1),j+2);
439 sugarMesh.vertices = verticesSM.ToArray();
440 sugarMesh.triangles = trianglesSM.ToArray();
442 sugarMesh.colors32 = colorsSM.ToArray();
444 CycleBIGMesh.Add(sugarMesh);
457 private void generateRibbonsMesh(Mesh centralMesh,
int resnumber,
float thicknessCenter=1f,
bool center=
true){
458 Mesh meshUP =
new Mesh();
459 Mesh meshDOWN =
new Mesh();
460 Mesh meshSide =
new Mesh ();
461 List<Vector3> verticesSide =
new List<Vector3>();
462 List<Color32> sideColors =
new List<Color32> ();
467 Vector3[] newVerticesUP =
new Vector3[centralMesh.vertices.Length];
468 Vector3[] newVerticesDOWN =
new Vector3[centralMesh.vertices.Length];
469 List<Color32> colors =
new List<Color32>();
470 string resname = residueslist[resnumber];
474 for (
int j=0; j<centralMesh.vertices.Length; j++){
475 newVerticesUP[j].x = centralMesh.vertices[j].x + (normalMean.x*(THICKNESS*thicknessCenter));
476 newVerticesUP[j].y = centralMesh.vertices[j].y + (normalMean.y)*(THICKNESS*thicknessCenter);
477 newVerticesUP[j].z = centralMesh.vertices[j].z + (normalMean.z)*(THICKNESS*thicknessCenter);
479 newVerticesDOWN[j].x = centralMesh.vertices[j].x - (normalMean.x*(THICKNESS*thicknessCenter));
480 newVerticesDOWN[j].y = centralMesh.vertices[j].y - (normalMean.y)*(THICKNESS*thicknessCenter);
481 newVerticesDOWN[j].z = centralMesh.vertices[j].z - (normalMean.z)*(THICKNESS*thicknessCenter);
485 for (
int j=0; j<centralMesh.vertices.Length; j++){
489 colors.Add(
new Color(0.7f,0.7f,0.7f,0.5f));
492 meshUP.vertices = newVerticesUP;
493 meshUP.triangles = centralMesh.triangles;
494 meshUP.RecalculateNormals();
495 meshUP.colors32 = centralMesh.colors32;
499 meshDOWN.vertices = newVerticesDOWN;
501 meshDOWN.RecalculateNormals();
502 meshDOWN.colors32 = centralMesh.colors32;
510 for (
int i=0; i<meshUP.vertices.Length; i++){
511 verticesSide.AddMany(meshUP.vertices[i],meshDOWN.vertices[i]);
512 sideColors.AddMany(meshUP.colors32[i], meshDOWN.colors32[i]);
515 meshSide.vertices = verticesSide.ToArray ();
517 meshSide.RecalculateNormals ();
518 meshSide.colors32 = sideColors.ToArray();
522 meshesRingUp.Add (meshUP);
523 meshesRingDown.Add (meshDOWN);
524 meshesSideRing.Add (meshSide);
526 meshesBIGRingUp.Add (meshUP);
527 meshesBIGRingDown.Add (meshDOWN);
528 meshesBIGSideRing.Add (meshSide);
534 int key_index_for_bond_dict=-1;
535 foreach (
int i
in connectivityList.Keys){
536 string resname1 = residueslist[i];
538 for (
int j=0; j<connectivityList[i].Count / 3; j++){
539 key_index_for_bond_dict++;
540 List<Vector3> verticesUP =
new List<Vector3>();
541 List<Vector3> verticesDown =
new List<Vector3>();
542 List<Vector3> VerticesSide =
new List<Vector3>();
544 List<int> TrianglesUP =
new List<int>();
545 List<int> TrianglesDown =
new List<int>();
546 List<int> TrianglesSide =
new List<int>();
549 List<Color32> colorsUP =
new List<Color32>();
550 List<Color32> colorsDown =
new List<Color32>();
551 List<Color32> colorsSide =
new List<Color32>();
555 Mesh BondUP =
new Mesh();
556 Mesh BondDown =
new Mesh();
557 Mesh bondSide =
new Mesh();
559 Vector3 Au,Bu,Cu,Du, Ad,Bd, Cd, Dd;
562 int atom2 =
findRingAtomIndex(connectivityList[i][1+(3*j)], connectivityList[i][2+(3*j)]);
563 int res2 = connectivityList[i][1+(3*j)];
564 int size1 = cycles[i].Count;
565 int size2 = cycles[res2].Count;
566 string resname2 = residueslist[res2];
570 Au=meshesBIGRingUp[i].vertices[MeshIndexForAtom[size1][atom1][0]];
571 Bu=meshesBIGRingUp[i].vertices[MeshIndexForAtom[size1][atom1][1]];
572 Cu=meshesBIGRingUp[connectivityList[i][1+(3*j)]].vertices[MeshIndexForAtom[size2][atom2][1]];
573 Du=meshesBIGRingUp[connectivityList[i][1+(3*j)]].vertices[MeshIndexForAtom[size2][atom2][0]];
575 Ad=meshesBIGRingDown[i].vertices[MeshIndexForAtom[size1][atom1][0]];
576 Bd=meshesBIGRingDown[i].vertices[MeshIndexForAtom[size1][atom1][1]];
577 Cd=meshesBIGRingDown[connectivityList[i][1+(3*j)]].vertices[MeshIndexForAtom[size2][atom2][1]];
578 Dd=meshesBIGRingDown[connectivityList[i][1+(3*j)]].vertices[MeshIndexForAtom[size2][atom2][0]];
581 float AngleU = Vector3.Angle((Au-Bu), (Cu-Du));
586 verticesUP.AddMany(Au,Bu,Dd,Cd);
587 verticesDown.AddMany(Ad,Bd,Du,Cu);
589 verticesUP.AddMany(Au,Bu,Cu,Du);
590 verticesDown.AddMany(Ad,Bd,Cd,Dd);
593 VerticesSide.AddMany(verticesUP[0],verticesDown[0]);
594 VerticesSide.AddMany(verticesUP[1],verticesDown[1]);
595 VerticesSide.AddMany(verticesUP[3],verticesDown[3]);
596 VerticesSide.AddMany(verticesUP[2],verticesDown[2]);
598 TrianglesUP.AddMany(0,1,2,
601 TrianglesDown.AddMany(3,2,1,
604 TrianglesSide.AddMany(0,1,2, 2,1,3, 2,3,4, 4,3,5,
605 4,5,6, 6,5,7, 6,7,0, 0,7,1);
609 if (COLOR_MODE_BOND == SUGAR){
617 colorsUP.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
618 colorsDown.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
619 colorsUP.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
620 colorsDown.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
629 colorsUP.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
630 colorsDown.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
631 colorsUP.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
632 colorsDown.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
635 }
else if (COLOR_MODE_BOND == CHAIN){
642 colorsUP.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
643 colorsDown.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
644 colorsUP.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
645 colorsDown.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
653 colorsUP.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
654 colorsDown.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
655 colorsUP.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
656 colorsDown.Add(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
659 }
else if (COLOR_MODE_BOND == PICKER){
660 for (
int k=0; k<4;k++){
662 colorsDown.Add(
lightColor(BONDCOLOR.
color, LIGHTER_COLOR_FACTOR_BOND));
668 colorsSide.AddMany(colorsUP[0], colorsDown[0]);
669 colorsSide.AddMany(colorsUP[1], colorsDown[1]);
670 colorsSide.AddMany(colorsUP[2], colorsDown[2]);
671 colorsSide.AddMany(colorsUP[3], colorsDown[3]);
673 BondUP.vertices = verticesUP.ToArray();
674 BondUP.triangles = TrianglesUP.ToArray();
675 BondUP.colors32 = colorsUP.ToArray();
677 BondDown.vertices = verticesDown.ToArray();
678 BondDown.triangles = TrianglesDown.ToArray();
679 BondDown.colors32 = colorsDown.ToArray();
681 bondSide.vertices = VerticesSide.ToArray();
682 bondSide.triangles = TrianglesSide.ToArray();
683 bondSide.colors32 = colorsSide.ToArray();
685 BondUP.RecalculateNormals();
686 BondDown.RecalculateNormals();
687 bondSide.RecalculateNormals();
688 meshesBondUp.Add(BondUP);
689 meshesBondDown.Add(BondDown);
690 meshesBondSide.Add(bondSide);
692 res_for_bond[key_index_for_bond_dict] = resname1 +
"_"+chain1+
"_"+resname2+
"_"+chain2;
702 GameObject oxysphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
703 oxysphere.tag =
"OxySphere";
704 Vector3 point =
new Vector3(atomsLocationlist [pos] [0],atomsLocationlist [pos] [1],atomsLocationlist [pos] [2]);
705 oxysphere.transform.position = point;
706 string resname = residueslist[res];
707 string chain = resChainList[res];
712 oxysphere.GetComponent<Renderer>().material.color =
new Color(0.7f,0.7f,0.7f,0.5f);
713 }
else if (sugartype==2){
716 oxysphere.GetComponent<Renderer>().material.color = Color.red;
718 oxysphere.transform.localScale =
new Vector3(OXYSPHERESIZE, OXYSPHERESIZE, OXYSPHERESIZE);
725 List<GameObject> result =
new List<GameObject>();
726 for (
int i=0; i<this.cycles.Count; i++) {
727 for (
int j=0; j<this.cycles[i].Count; j++) {
728 if (atomsNamelist[cycles[i][j]][0] ==
'O'){
744 public GameObject
CreateSugarRibbonsObj(Mesh mesh,
string res=
"",
string chain=
"",
string tag=
"SugarRibbons",
int id=0){
746 if (tag==
"SugarRibbons_BOND")
747 SRobj =
new GameObject(
"SugarRibbons_"+res+
"_"+chain+
"_BOND_"+
id);
749 SRobj =
new GameObject(
"SugarRibbons_"+res+
"_"+chain);
751 SRobj.AddComponent<MeshFilter>();
752 SRobj.AddComponent<MeshRenderer>();
755 Vector3[] vertices = mesh.vertices;
756 Vector2[] uvs =
new Vector2[vertices.Length];
758 while (i < uvs.Length) {
759 uvs[i] =
new Vector2(vertices[i].x, vertices[i].z);
765 SRobj.GetComponent<MeshFilter> ().mesh = mesh;
766 SRobj.GetComponent<Renderer>().material =
new Material (Shader.Find (
"Custom/Ribbons"));
775 int triangleCount = mesh.triangles.Length / 3;
776 int vertexCount = mesh.vertices.Length;
778 Vector3[] tan1 =
new Vector3[vertexCount];
779 Vector3[] tan2 =
new Vector3[vertexCount];
780 Vector4[] tangents =
new Vector4[vertexCount];
782 while(a < triangleCount)
784 long i1 = mesh.triangles[a++];
785 long i2 = mesh.triangles[a++];
786 long i3 = mesh.triangles[a++];
788 Vector3 v1 = mesh.vertices[i1];
789 Vector3 v2 = mesh.vertices[i2];
790 Vector3 v3 = mesh.vertices[i3];
792 Vector2 w1 = mesh.uv[i1];
793 Vector2 w2 = mesh.uv[i2];
794 Vector2 w3 = mesh.uv[i3];
796 float x1 = v2.x - v1.x;
797 float x2 = v3.x - v1.x;
798 float y1 = v2.y - v1.y;
799 float y2 = v3.y - v1.y;
800 float z1 = v2.z - v1.z;
801 float z2 = v3.z - v1.z;
803 float s1 = w2.x - w1.x;
804 float s2 = w3.x - w1.x;
805 float t1 = w2.y - w1.y;
806 float t2 = w3.y - w1.y;
808 float r = 1.0f / (s1 * t2 - s2 * t1);
810 Vector3 sdir =
new Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
811 Vector3 tdir =
new Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
821 for (a = 0; a < vertexCount; a++)
823 Vector3 n = mesh.normals[a];
825 tangents[a] = (t - n * Vector3.Dot(n, t)).normalized;
826 tangents[a].w = (Vector3.Dot(Vector3.Cross(n, t), tan2[a]) < 0.0f) ? -1.0f : 1.0f;
828 mesh.tangents = tangents;
832 GameObject lineObject;
834 lineObject =
new GameObject(
"measureline");
835 line = lineObject.AddComponent<LineRenderer>();
836 line.material =
new Material (Shader.Find(
"Particles/Alpha Blended"));
837 line.SetColors(Color.red, Color.red);
838 line.SetWidth(0.3f, 0.3f);
839 line.SetPosition(0, a);
840 line.SetPosition(1,b);
850 List<List<GameObject>> result =
new List<List<GameObject>>();
852 result.Add(
new List<GameObject>());
854 for (
int i=0; i<CycleMesh.Count; i++) {
863 for (
int i=0; i<meshesRingUp.Count; i++){
865 result[0].Add(
CreateSugarRibbonsObj (meshesRingUp[i],residueslist[i],resChainList[i],
"SugarRibbons_RING_little"));
866 result[0].Add(
CreateSugarRibbonsObj (meshesRingDown[i],residueslist[i],resChainList[i],
"SugarRibbons_RING_little"));
867 result[0].Add(
CreateSugarRibbonsObj(meshesSideRing[i],residueslist[i],resChainList[i],
"SugarRibbons_RING_little"));
870 result[1].Add(
CreateSugarRibbonsObj (meshesBIGRingUp[i],residueslist[i],resChainList[i],
"SugarRibbons_RING_BIG"));
871 result[1].Add(
CreateSugarRibbonsObj (meshesBIGRingDown[i],residueslist[i],resChainList[i],
"SugarRibbons_RING_BIG"));
872 result[1].Add(
CreateSugarRibbonsObj(meshesBIGSideRing[i],residueslist[i],resChainList[i],
"SugarRibbons_RING_BIG"));
875 for (
int i=0; i<meshesBondUp.Count; i++){
876 result[2].Add(
CreateSugarRibbonsObj (meshesBondUp[i],residueslist[i],resChainList[i],
"SugarRibbons_BOND",i));
877 result[2].Add(
CreateSugarRibbonsObj (meshesBondDown[i],residueslist[i],resChainList[i],
"SugarRibbons_BOND",i));
878 result[2].Add(
CreateSugarRibbonsObj (meshesBondSide[i],residueslist[i],resChainList[i],
"SugarRibbons_BOND",i));
891 for (
int i=0; i<objs.Count; i++){
892 Color32[] colours = objs[i].GetComponent<MeshFilter> ().mesh.colors32;
893 for (
int j=0; j< colours.Length; j++){
896 objs[i].GetComponent<MeshFilter> ().mesh.colors32 = colours;
900 for (
int i=0; i<objs.Count; i++){
901 Color32[] colours = objs[i].GetComponent<MeshFilter> ().mesh.colors32;
903 for (
int j=0; j< colours.Length; j++){
907 objs[i].GetComponent<MeshFilter> ().mesh.colors32 = colours;
912 for (
int i=0; i<objs.Count; i++){
913 Color32[] colours = objs[i].GetComponent<MeshFilter> ().mesh.colors32;
914 int SIZE = objs[i].GetComponent<MeshFilter> ().mesh.vertices.Length;
915 int ID =
int.Parse(objs[i].ToString().Split(
'_')[4].Split(
' ')[0]);
916 string resname1 = res_for_bond[ID].Split(
'_')[0];
917 string resname2 = res_for_bond[ID].Split(
'_')[2];
918 string chain1 = res_for_bond[ID].Split(
'_')[1];
919 string chain2 = res_for_bond[ID].Split(
'_')[3];
926 col1 =
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND);
930 col2 =
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND);
935 col1 = (
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
939 col2 = (
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_BOND));
956 objs[i].GetComponent<MeshFilter> ().mesh.colors32 = colours;
961 for (
int i=0; i<objs.Count; i++){
962 Color32[] colours = objs[i].GetComponent<MeshFilter> ().mesh.colors32;
963 string resname = objs[i].ToString().Split(
'_')[1];
964 string chain = objs[i].ToString().Split(
'_')[2].Split(
' ')[0];
965 for (
int j=0; j<colours.Length; j++){
970 colours[j]=(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_RING));
971 }
else if (type == CHAIN){
975 colours[j]=(
lightColor(
new Color(0.7f,0.7f,0.7f,0.5f), LIGHTER_COLOR_FACTOR_RING));
979 objs[i].GetComponent<MeshFilter> ().mesh.colors32 = colours;
985 Debug.Log(
"Calculation of cycles barycenters");
986 Vector3 barycenter =
new Vector3();
988 float xTot, yTot ,zTot;
989 for (
int i=0; i<cycles.Count; i++){
993 for (
int j=0; j<cycles[i].Count; j++){
994 xTot=xTot+atomsLocationlist [cycles [i] [j]] [0];
995 yTot=yTot+atomsLocationlist [cycles [i] [j]] [1];
996 zTot=zTot+atomsLocationlist [cycles [i] [j]] [2];
999 barycenter.x=xTot/(cycles[i].Count);
1000 barycenter.y=yTot/(cycles[i].Count);
1001 barycenter.z=zTot/(cycles[i].Count);
1002 barylist.Add(barycenter);
1008 float totX, totY, totZ;
1009 totX = totY = totZ = 0;
1010 Vector3 barycenter =
new Vector3();
1012 for (
int i=0; i<mesh.vertices.Length; i++){
1013 totX+=mesh.vertices[i][0];
1014 totY+=mesh.vertices[i][1];
1015 totZ+=mesh.vertices[i][2];
1017 barycenter.x = totX/mesh.vertices.Length;
1018 barycenter.y = totY/mesh.vertices.Length;
1019 barycenter.z = totZ/mesh.vertices.Length;
1030 return new Vector3(x,y,z);
1034 for (
int i=0; i<cycles[ringIndex].Count; i++){
1035 if (cycles[ringIndex][i] == AtomNumber)
1042 Vector3 v =
new Vector3 (atomsLocationlist[cycles[index_res][number]][0],
1043 atomsLocationlist[cycles[index_res][number]][1],
1044 atomsLocationlist[cycles[index_res][number]][2]);
1051 Vector3 v =
new Vector3 ();
1052 Vector3 dir=
new Vector3();
1056 v = a - (dir * size);
1063 GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
1065 go.AddComponent<Animation>();
1066 go.transform.position = point;
1067 go.GetComponent<Renderer>().material.color = color;
1068 go.transform.localScale =
new Vector3(size, size, size);
1073 float xTot, yTot, zTot;
1074 xTot = yTot = zTot = 0;
1075 Vector3 normalMean =
new Vector3();
1076 mesh.RecalculateNormals();
1077 for (
int i=0; i<mesh.normals.Length; i++){
1078 xTot+=mesh.normals[i].x;
1079 yTot+=mesh.normals[i].y;
1080 zTot+=mesh.normals[i].z;
1083 normalMean.x = xTot/mesh.normals.Length;
1084 normalMean.y = yTot/mesh.normals.Length;
1085 normalMean.z = zTot/mesh.normals.Length;
1093 List<int> newTriangles =
new List<int>();
1095 for (
int i=mesh.triangles.Length-1; i>=0; i--){
1096 newTriangles.Add(mesh.triangles[i]);
1099 return newTriangles.ToArray();
1104 List<int> triangles =
new List<int>();
1105 int size = mesh.vertices.Length;
1107 for (
int i=0; i<size -2; i=i+2){
1108 triangles.AddMany(i, i+1, i+2);
1109 triangles.AddMany(i+2, i+1, i+3);
1112 triangles.AddMany(size-2, size-1, 0);
1113 triangles.AddMany (0, size-1, 1);
1115 return triangles.ToArray();
1118 public Color
lightColor(Color color,
float correctionFactor = 0.35f){
1119 if (correctionFactor>=0)
1120 return Color.Lerp(color, Color.white, correctionFactor);
1122 return Color.Lerp(color, Color.black, -correctionFactor);
1128 CycleBIGMesh.Clear();
1129 meshesRingUp.Clear();
1130 meshesRingDown.Clear();
1131 meshesSideRing.Clear();
1132 meshesBIGRingUp.Clear();
1133 meshesBIGRingDown.Clear();
1134 meshesBIGSideRing.Clear();
1135 meshesBondUp.Clear();
1136 meshesBondDown.Clear();
1137 meshesBondSide.Clear();
ColorObject OXYSPHERECOLOR
List< Mesh > meshesBIGRingDown
Vector3 float3toVector3(float[] point)
int[] invertTrianglesMesh(Mesh mesh)
List< string > sugarResname
Vector3 calculMeshBarycenter(Mesh mesh)
void generateRibbonsMesh(Mesh centralMesh, int resnumber, float thicknessCenter=1f, bool center=true)
List< int > residuesNumberlist
Vector3 calcMidPoint(Vector3 a, Vector3 b)
Color lightColor(Color color, float correctionFactor=0.35f)
Dictionary< int, string > res_for_bond
void changeColor(int which)
List< string > residueslist
float LIGHTER_COLOR_FACTOR_BOND
List< string > atomsNamelist
GameObject CreateOxygenSphere(int pos, int res, int sugartype=0)
Vector3 LinearComb(float scalar0, Vector3 vector0, float scalar1, Vector3 vector1)
List< Mesh > CycleBIGMesh
void generateCycleMesh2()
static List< string > atomsSugarNamelist
int[] generateTriangleSide(Mesh mesh)
List< List< int > > cycles
float THICKNESS_BOND_6_C1_C4
static List< string > atomsNamelist
The name of each atom.
List< Mesh > meshesRingUp
List< Mesh > meshesSideRing
float THICKNESS_BOND_6_OTHER
int findRingAtomIndex(int ringIndex, int AtomNumber)
static List< float[]> atomsSugarLocationlist
List< GraphVertex > molAsGraph
void generateBiggerCycleMesh(float scaling=0.60f)
void debugline(Vector3 a, Vector3 b)
void createDebugSphere(Vector3 point, Color color, float size=1f)
static Dictionary< string, Color > ChainColorDict
List< List< GameObject > > createSugarRibs(float RibbonsThickness, bool sugarOnly, float thickness_Little, float thickness_BIG, float thickness_bond_6_C1_C4, float thickness_6_other, float thickness_bond_5, float lighter_color_factor_ring, float lighter_color_factor_bond, int color_mode_ring, int color_mode_bond, ColorObject bondcolor, ColorObject ringcolor, float OxySphereSize, ColorObject OxySphereColor)
List< Mesh > meshesBIGRingUp
List< Mesh > meshesRingDown
List< Mesh > meshesBondSide
void updateColorBond(List< GameObject > objs, int type)
Vector3 calculMidPoint(Vector3 a, Vector3 b)
SugarRibbons(bool SugarOnly)
static List< int[]> bondEPSugarList
List< GameObject > ShowOxySphere(int colortype)
List< string > atomsResnamelist
Dictionary< int, Dictionary< int, int[]> > MeshIndexForAtom
List< Vector3 > makeFlatVertex(List< Vector3 > verticeEn)
List< List< GameObject > > createSugarRibbons()
List< float[]> atomsLocationlist
static void Solve(Mesh mesh)
List< Mesh > meshesBondDown
!WiP manage GUI, and provide static strings for the GUI.
Vector3 CycleAtomToVector3(int index_res, int number)
static List< int[]> bondEPList
The bonds between atoms.
List< string > resChainList
This class is made to convert an atom (postion X,Y,Z) to a object with a list of neighbor.
Vector3 calcullittleRibbonsControlPoint(Vector3 a, Vector3 b, float size=0.7f)
GameObject CreateSugarRibbonsObj(Mesh mesh, string res="", string chain="", string tag="SugarRibbons", int id=0)
For each mesh, we create Two mesh (to have a ribbon with tchickness)
static List< string > resSugarChainList
static List< string > atomsResnamelist
The name of the residue to which each atom belongs.
static Dictionary< string, Color > colorByResiduesDict
static List< string > resChainList
The chain of each residue (only work if residues are numbered by chain).
void updateColorRing(List< GameObject > objs, ColorObject newColor)
List< Vector3 > enlargeMesh(int i, float scaling)
List< Mesh > meshesBIGSideRing
Vector3 calculMeanNormalMesh(Mesh mesh)
Dictionary< int, List< int > > connectivityList
void updateColorBond(List< GameObject > objs, ColorObject newColor)
List< Mesh > meshesBondUp
void updateColorRing(List< GameObject > objs, int type)
float THICKNESS_LITTLE_MESH
static List< string > atomsSugarResnamelist
static List< float[]> atomsLocationlist
The coordinates of each atom.
float LIGHTER_COLOR_FACTOR_RING