UnityMol  0.9.6-875
UnityMol viewer / In developement
RNAView.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 using Molecule.Model;
4 using System.Collections.Generic;
5 
6 public class RNAView : MonoBehaviour {
7  public struct Hbparam
8  {
9  public float dref;
10  public float alpa;
11  public float alpb;
12  public int s;
13 
14  public Hbparam(float dreference, float alphaa, float alphab, int sv)
15  {
16  dref = dreference;
17  alpa = alphaa;
18  alpb = alphab;
19  s = sv;
20  }
21  }
22 
23  private static Hbparam[][][] hb_params;
24 
25  private static Dictionary<string, int> bases = new Dictionary<string, int>()
26  {
27  {"G2", 0},
28  {"A2", 1},
29  {"C1", 2},
30  {"U1", 3}
31  };
32 
33  public static void RNAView_init() {
34  hb_params = new Hbparam[4][][];
35 
36  hb_params[0] = new Hbparam[4][];
37  hb_params[0][0] = new Hbparam[2];
38  hb_params[0][0][0] = new Hbparam(6.24f, 2.77f, 1.20f, 2);
39  hb_params[0][0][1] = new Hbparam(7.33f, 2.93f, 1.27f, 1);
40 
41  hb_params[0][1] = new Hbparam[4];
42  hb_params[0][1][0] = new Hbparam(5.07f, 2.67f, 2.95f, 2);
43  hb_params[0][1][1] = new Hbparam(6.26f, 1.48f, 1.20f, 2);
44  hb_params[0][1][2] = new Hbparam(7.02f, 1.93f, 2.06f, 1);
45  hb_params[0][1][3] = new Hbparam(7.54f, 2.14f, 0.80f, 1);
46 
47  hb_params[0][2] = new Hbparam[2];
48  hb_params[0][2][0] = new Hbparam(4.80f, 2.76f, 2.17f, 3);
49  hb_params[0][2][1] = new Hbparam(7.40f, 1.28f, 2.89f, 1);
50 
51  hb_params[0][3] = new Hbparam[2];
52  hb_params[0][3][0] = new Hbparam(5.67f, 2.15f, 1.72f, 2);
53  hb_params[0][3][1] = new Hbparam(7.05f, 2.85f, 1.43f, 1);
54 
55  hb_params[1] = new Hbparam[4][];
56 
57  hb_params[1][0] = new Hbparam[4];
58  hb_params[1][0] = hb_params[0][1];
59 
60  hb_params[1][1] = new Hbparam[4];
61  hb_params[1][1][0] = new Hbparam(5.43f, 2.55f, 2.55f, 2);
62  hb_params[1][1][1] = new Hbparam(7.33f, 1.01f, 1.73f, 1);
63  hb_params[1][1][2] = new Hbparam(6.86f, 0.98f, 0.98f, 2);
64  hb_params[1][1][3] = new Hbparam(7.33f, 1.73f, 1.01f, 1);
65 
66  hb_params[1][2] = new Hbparam[2];
67  hb_params[1][2][0] = new Hbparam(5.60f, 2.40f, 1.82f, 1);
68  hb_params[1][2][1] = new Hbparam(6.94f, 2.07f, 1.48f, 1);
69 
70  hb_params[1][3] = new Hbparam[2];
71  hb_params[1][3][0] = new Hbparam(4.96f, 2.92f, 2.23f, 2);
72  hb_params[1][3][1] = new Hbparam(6.43f, 0.84f, 1.95f, 2);
73 
74  hb_params[2] = new Hbparam[4][];
75 
76  hb_params[2][0] = new Hbparam[2];
77  hb_params[2][0] = hb_params[0][2];
78 
79  hb_params[2][1] = new Hbparam[2];
80  hb_params[2][1] = hb_params[1][2];
81 
82  hb_params[2][2] = new Hbparam[1];
83  hb_params[2][2][0] = new Hbparam(4.91f, 2.22f, 2.24f, 2);
84 
85  hb_params[2][3] = new Hbparam[2];
86  hb_params[2][3][0] = new Hbparam(5.62f, 1.75f, 2.64f, 1);
87  hb_params[2][3][1] = new Hbparam(7.48f, 2.88f, 2.71f, 1);
88 
89  hb_params[3] = new Hbparam[4][];
90 
91  hb_params[3][0] = new Hbparam[2];
92  hb_params[3][0] = hb_params[0][3];
93 
94  hb_params[3][1] = new Hbparam[2];
95  hb_params[3][1] = hb_params[1][3];
96 
97  hb_params[3][2] = new Hbparam[2];
98  hb_params[3][2] = hb_params[2][3];
99 
100  hb_params[3][3] = new Hbparam[2];
101  hb_params[3][3][0] = new Hbparam(5.39f, 1.71f, 2.61f, 1);
102  hb_params[3][3][1] = new Hbparam(7.33f, 2.61f, 2.39f, 1);
103  }
104 
105  private static float Ehbond(float dij, float alpa, float alpb, Hbparam hbp)
106  {
107 // Debug.Log ("Entering Ehbond");
108 
109  alpa = Mathf.Cos (alpa - hbp.alpa);
110  alpb = Mathf.Cos (alpb - hbp.alpb);
111 
112 // Debug.Log("alpa: " + alpa);
113 // Debug.Log("alpb: " + alpb);
114 
115  float r = (dij - hbp.dref) / MoleculeModel.scale_RNA[12];
116 // Debug.Log ("SCALE_RNA[12]" + MoleculeModel.scale_RNA[12]);
117  float Vr = -hbp.s * Mathf.Exp(-r * r);
118  float Vangl = Mathf.Pow(alpa * alpb, MoleculeModel.scale_RNA[11]);
119 
120 // Debug.Log("r: " + r);
121 // Debug.Log("Vr: " + Vr);
122 // Debug.Log("Vangl: " + Vangl);
123 //
124 // Debug.Log ("Exiting Ehbond");
125  return MoleculeModel.scale_RNA[9] * Vr * Vangl;
126  }
127 
128  private static float angle(Vector3 a, Vector3 b, Vector3 c) {
129  Vector3 u = a - b;
130  Vector3 v = c - b;
131 
132  float w = Vector3.Dot(u, v);
133  w /= (u.magnitude * v.magnitude);
134  return Mathf.Acos(w);
135  }
136 
137  private static float PointToPlaneDistance(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 x) {
138  Vector3 n = Vector3.Cross (p2-p1, p3-p1);
139  n.Normalize();
140  return Vector3.Dot(n, x-p2);
141  }
142 
143  private static float NewPlane(Vector3 a, Vector3 b, Vector3 c, Vector3 d) {
144  float ppDistance = PointToPlaneDistance(a, b, c, d);
145  return MoleculeModel.scale_RNA[14] * Mathf.Exp(-Mathf.Pow(ppDistance / MoleculeModel.scale_RNA[13], 2)) / 6.0f;
146  }
147 
148  private static float ENewPlane(int atomId1, int atomId2) {
149  float Enp1 = 0;
150  float Enp2 = 0;
151 
152  for (int i = 0; i < 3; i++)
153  {
154  Enp1 += NewPlane(
159  );
160 
161  Enp2 += NewPlane(
166  );
167  }
168 // Debug.Log ("Enp: " + Enp1 + " " + Enp2);
169  return Enp1 * Enp2;
170  }
171 
172  private static float computeEnergyForBasePair(int residueId1, int residueId2) {
173 // Debug.Log ("---- " + residueId1 + " " + residueId2);
174  int i = MoleculeModel.baseIdx[residueId1-1];
175  int j = MoleculeModel.baseIdx[residueId2-1];
176 
179 
180  float dij = Vector3.Distance(posi, posj);
181 // Debug.Log ("Distance " + residueId1 + " " + residueId2 + " " + dij);
182  if (dij > 15)
183  {
184  return 0.0f;
185  }
186 
187  float Enp = ENewPlane(i, j);
188 
189  float ca = angle(
193  );
194  float cb = angle(
198  );
199 
200 // Debug.Log ("Enp " + Enp + " ca " + ca + " cb " + cb);
201 
202  float Ehb = 0.0f;
203  Hbparam param;
204 
205  string resA = MoleculeModel.atomsNamelist[i];
206  string resB = MoleculeModel.atomsNamelist[j];
207  int resAVal = bases[resA];
208  int resBVal = bases[resB];
209 // Debug.Log ("----------");
210 // Debug.Log (hb_params[0]);
211 // Debug.Log (hb_params.Length);
212 // Debug.Log (resAVal);
213 // Debug.Log (resBVal);
214  Hbparam[] parameterList = hb_params[resAVal][resBVal];
215 
216  for(int k = 0; k < parameterList.Length; k++)
217  {
218  param = parameterList[k];
219  Ehb += Ehbond(dij, ca, cb, param);
220  }
221 
222 // Debug.Log ("Ehb " + Ehb);
223 // Debug.Break();
224 
225  return Ehb * Enp;
226  }
227 
228  public static List<int[]> findHbonds()
229  {
230  List<int[]> bonds = new List<int[]>();
231  float threshold = 0.1f;
232  foreach(KeyValuePair<int, ArrayList> entry1 in MoleculeModel.residues)
233  {
234  foreach(KeyValuePair<int, ArrayList> entry2 in MoleculeModel.residues)
235  {
236  int atom1;
237  int atom2;
238  atom1 = (int)entry1.Value[entry1.Value.Count - 1];
239  atom2 = (int)entry2.Value[entry2.Value.Count - 1];
240 
241  string base1;
242  string base2;
243  base1 = MoleculeModel.atomsNamelist[atom1];
244  base2 = MoleculeModel.atomsNamelist[atom2];
245 
246  float energy;
247  if (bases[base1] > bases[base2])
248  {
249  energy = computeEnergyForBasePair(entry2.Key, entry1.Key);
250  }
251  else
252  {
253  energy = computeEnergyForBasePair(entry1.Key, entry2.Key);
254  }
255 
256 // Debug.Log(energy);
257  if (energy < -threshold)
258  {
259  bonds.Add(new int[]{entry1.Key, entry2.Key});
260  }
261  }
262  }
263  return bonds;
264  }
265 
266 
267 
268 
269 
270 
271 
272 
273 
274 // public static compute
275 // public static Vector3 computeBarycenter(List<GraphVertex> atoms)
276 // {
277 // Vector3 b = new Vector3(0.0f, 0.0f, 0.0f);
278 // for (int i = 0; i < atoms.Count; i++) {
279 // float[] atomPosition = MoleculeModel.atomsLocationlist[atoms[i].id];
280 // b.x += atomPosition[0];
281 // b.y += atomPosition[1];
282 // b.z += atomPosition[2];
283 // }
284 // b /= atoms.Count;
285 // return b;
286 // }
287 //
288 // public static List<List<GraphVertex>> getBases()
289 // {
290 // List<List<GraphVertex>> bases = new List<List<GraphVertex>>();
291 // List<GraphVertex> graph = GraphGenerator.GenerateGraph(true);
292 //
293 // /*
294 // * Find nitrogeneous base for each nucleotide
295 // */
296 // int l = MoleculeModel.residues.Count;
297 // foreach (KeyValuePair<int, ArrayList> entry in MoleculeModel.residues)
298 // {
299 // List<GraphVertex> currentBase = new List<GraphVertex>();
300 // List<GraphVertex> queue = new List<GraphVertex>();
301 //
302 // for (int i = 0; i < entry.Value.Count; i++)
303 // {
304 // int obj = (int)entry.Value[i];
305 //
306 // if ( (MoleculeModel.atomsTypelist[obj].type == "N")
307 // && (graph[obj].neighbor.Count == 3)
308 // && (graph[obj].neighbor[0].type == 'C')
309 // && (graph[obj].neighbor[1].type == 'C')
310 // && (graph[obj].neighbor[2].type == 'C'))
311 // {
312 // graph[obj].flag = true;
313 // currentBase.Add(graph[obj]);
314 // queue.Add (graph[obj].neighbor[0]);
315 // queue.Add (graph[obj].neighbor[1]);
316 // queue.Add (graph[obj].neighbor[2]);
317 //
318 // break;
319 // }
320 // }
321 //
322 // if (queue.Count == 3) {
323 // Debug.Log ("#############");
324 // GraphVertex seed = currentBase[0];
325 // for (int i = 0; i < queue.Count; i++) {
326 // bool keep = false;
327 // List<GraphVertex> neighbors = queue[i].neighbor;
328 // Debug.Log ("-------" + queue[i].id);
329 // // Check neighborhood
330 // for (int j = 0; j < neighbors.Count; j++) {
331 // GraphVertex n = neighbors[j];
332 // if (n.flag == false && n.type == 'N') {
333 // Debug.Log ("Keeping set flag to true");
334 // keep = true;
335 // break;
336 // }
337 // }
338 //
339 // if (keep) {
340 // Debug.Log ("Keeping");
341 // seed = graph[queue[i].id];
342 // seed.flag = true;
343 // currentBase.Add (queue[i]);
344 // break;
345 // }
346 // }
347 //
348 // queue.Clear();
349 // queue.Add (seed);
350 //
351 // Debug.Log (currentBase.Count);
352 // Debug.Log (seed.flag);
353 //
354 // for (int i = 0; i < seed.neighbor.Count; i++) {
355 // Debug.Log (seed.neighbor[i].flag);
356 // }
357 // Debug.Log("%%%%%%%%%");
358 // while (queue.Count > 0) {
359 // GraphVertex current = queue[0];
360 // queue.RemoveAt (0);
361 // List<GraphVertex> neighbors = current.neighbor;
362 // GraphVertex currentNeighbor;
363 // for (int i = 0; i < neighbors.Count; i++) {
364 // currentNeighbor = neighbors[i];
365 // Debug.Log (currentNeighbor.flag);
366 // if (currentNeighbor.flag == false && entry.Value.Contains(currentNeighbor.id)) {
367 // Debug.Log ("Queuing");
368 // currentNeighbor.flag = true;
369 // queue.Add (currentNeighbor);
370 // currentBase.Add (currentNeighbor);
371 // }
372 // }
373 // }
374 // }
375 // bases.Add(currentBase);
376 // }
377 // return bases;
378 // }
379 
380 }
static float ENewPlane(int atomId1, int atomId2)
Definition: RNAView.cs:148
static List< int[]> findHbonds()
Definition: RNAView.cs:228
static float angle(Vector3 a, Vector3 b, Vector3 c)
Definition: RNAView.cs:128
float alpa
Definition: RNAView.cs:10
static float computeEnergyForBasePair(int residueId1, int residueId2)
Definition: RNAView.cs:172
float alpb
Definition: RNAView.cs:11
static List< string > atomsNamelist
The name of each atom.
static List< Vector3 > atomsIMDSimulationLocationlist
The coordinates of each atom, simulated through an IMD simulation.
float dref
Definition: RNAView.cs:9
static List< float > scale_RNA
RNA Scale parameters
static float Ehbond(float dij, float alpa, float alpb, Hbparam hbp)
Definition: RNAView.cs:105
static Dictionary< int, ArrayList > residues
The residues.
static float NewPlane(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
Definition: RNAView.cs:143
static Hbparam[][][] hb_params
Definition: RNAView.cs:23
Hbparam(float dreference, float alphaa, float alphab, int sv)
Definition: RNAView.cs:14
static void RNAView_init()
Definition: RNAView.cs:33
static float PointToPlaneDistance(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 x)
Definition: RNAView.cs:137
static Dictionary< string, int > bases
Definition: RNAView.cs:25
static List< int > baseIdx
The index (in tables) of the base extremity.