UnityMol  0.9.6-875
UnityMol viewer / In developement
GraphVertex.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 using System.Collections.Generic;
4 
10 public class GraphVertex
11 {
12 
13  public List<GraphVertex> neighbor = new List<GraphVertex>(); //list of neighboor
14  public int idRing = -1 ; //-1 if this atom is not in a ring (only for C or O).
15  public char type;
16  public int id;
17  public string resname;
18  public Vector3 coordinate;
19  public bool flag=false;
20 
21 
32  public bool SearchCycle(List<int> vertex,int first, int size=0){
33  //we don't want to go to far in checking the size of the cycle.
34  if (size>20){
35  return false;
36  }
37 
38  //we search for every neighbor.
39  for (int i=0; i<neighbor.Count; i++){
40  if (neighbor[i].id==first){
41  if (size>3){
42  vertex.Add(id);
43  return true;
44  }
45 
46  }
47 
48  //if we found the first.
49  if(neighbor[i].flag==false){
50  flag=true;
51  if(neighbor[i].SearchCycle(vertex,first, size+1)==true){
52  vertex.Add(id);
53  return true;
54  }
55  }
56  }
57  return false;
58  }
59 
60 
61 
62  public bool AlreadyAdded(Dictionary <int,List<int>> connectivityList, int key, int atom){
63  bool added = false;;
64  if (connectivityList.ContainsKey(key)){
65 
66  for (int j=0; j<connectivityList[key].Count / 3; j++){
67  if (connectivityList[key][0+(3*j)] == atom)
68  added=true;
69  }
70 
71  if (added)
72  return true;
73  else
74  return false;
75  }
76  return false;
77  }
78 
79  public void addInDict(Dictionary <int,List<int>> connectivityList, int ring1, int atom1, int ring2, int atom2){
80 
81  if (! AlreadyAdded(connectivityList, ring1, atom1)){
82  if (connectivityList.ContainsKey(ring1))
83  connectivityList[ring1].AddMany(atom1, ring2, atom2);
84  else
85  connectivityList[ring1] = new List<int>( new int [] {atom1, ring2, atom2});
86  }
87  }
88 
89 
90  public bool SearchConnection(Dictionary <int,List<int>> connectivityList, List<int> trashlist, int r1=-1, int size=0){
91 
92  //we don't want to go to far in checking the size of the cycle.
93  if (size>3)
94  return false;
95 
96  if (size == 0 ){
97  r1 = this.idRing;
98  if (this.idRing==-1)
99  return false;
100  }
101 
102  if ((size == 1) && (this.idRing != -1))
103  return false;
104 
105 
106 
107  //we search for every neighbor.
108  for (int i=0; i<neighbor.Count; i++){
109  if (this.idRing != -1){
110  if ((size==2) || (size == 3)){
111  if (this.idRing != r1){
112  trashlist.Add(this.idRing);
113  trashlist.Add(this.id);
114  return true;
115  }
116  }
117  }
118 
119 
120 
121 
122 
123  //if we found the first.
124  if(neighbor[i].flag==false){
125  flag=true;
126  if(neighbor[i].SearchConnection(connectivityList,trashlist, r1, size+1)==true){
127  if (size==0){
128  int a1=this.id;
129  int r2 = trashlist[0];
130  int a2 = trashlist[1];
131  if (r1 < r2)
132  addInDict(connectivityList, r1, a1, r2, a2);
133  else
134  addInDict(connectivityList, r2, a2, r1, a1);
135  return true;
136  }else
137  return true;
138  }
139  }
140  }
141  return false;
142  }
143 
144 
145 }
146 
147 
string resname
Definition: GraphVertex.cs:17
Vector3 coordinate
Definition: GraphVertex.cs:18
bool SearchCycle(List< int > vertex, int first, int size=0)
This function will search recursivly a cycle : We "walk" from atom to atom, and if we find the atom w...
Definition: GraphVertex.cs:32
bool AlreadyAdded(Dictionary< int, List< int >> connectivityList, int key, int atom)
Definition: GraphVertex.cs:62
void addInDict(Dictionary< int, List< int >> connectivityList, int ring1, int atom1, int ring2, int atom2)
Definition: GraphVertex.cs:79
List< GraphVertex > neighbor
Definition: GraphVertex.cs:13
This class is made to convert an atom (postion X,Y,Z) to a object with a list of neighbor.
Definition: GraphVertex.cs:10
bool SearchConnection(Dictionary< int, List< int >> connectivityList, List< int > trashlist, int r1=-1, int size=0)
Definition: GraphVertex.cs:90