Przeglądaj źródła

Adds Chirality evaluation

Thomas Forest 5 lat temu
rodzic
commit
948ff2d3ab
2 zmienionych plików z 80 dodań i 36 usunięć
  1. 1 0
      src/dssp.py
  2. 79 36
      src/structure.py

+ 1 - 0
src/dssp.py Wyświetl plik

@@ -18,3 +18,4 @@ else:
18 18
     turns = get_turns(pdb_file.residues)
19 19
     get_helix(pdb_file.residues, turns)
20 20
     get_bends(pdb_file.residues)
21
+    get_chirality(pdb_file.residues)

+ 79 - 36
src/structure.py Wyświetl plik

@@ -1,4 +1,5 @@
1 1
 import math
2
+import numpy as np
2 3
 
3 4
 class Structure:
4 5
     def __init__(self, res):
@@ -30,8 +31,8 @@ def get_turns(residues):
30 31
         for j in range(3,6):
31 32
             if(i+j<len(residues)):
32 33
                 if(res.h_bond(residues[i+j])<-0.5):
33
-                    print("TURN", i+1, i+j+1)
34
-                    turns[i] = Turn(j,i)
34
+                    print(j,"TURN", residues[i].resid, residues[i+j].resid)
35
+                    turns[residues[i].resid] = Turn(j,residues[i].resid)
35 36
     return(turns)
36 37
 
37 38
 def get_bridges(residues):
@@ -47,8 +48,8 @@ def get_bridges(residues):
47 48
                and residues[j].h_bond(residues[i+1])<-0.5):
48 49
                 bridge = {'res1':residues[i-1].h_bond(residues[j]),
49 50
                           'res2':residues[j].h_bond(residues[i+1]),
50
-                          'ipos':i,
51
-                          'jpos':j,
51
+                          'ipos':residues[i].resid,
52
+                          'jpos':residues[j].resid,
52 53
                           'btype':"para"}
53 54
                 # if(residues[i-1].h_bond(residues[j])+
54 55
                 #    residues[j].h_bond(residues[i+1]))<E_min:
@@ -60,8 +61,8 @@ def get_bridges(residues):
60 61
                and residues[i].h_bond(residues[j+1])<-0.5):
61 62
                 bridge = {'res1':residues[j-1].h_bond(residues[i]),
62 63
                           'res2':residues[i].h_bond(residues[j+1]),
63
-                          'ipos':i,
64
-                          'jpos':j,
64
+                          'ipos':residues[i].resid,
65
+                          'jpos':residues[j].resid,
65 66
                           'btype':"para"}
66 67
                 # if(residues[j-1].h_bond(residues[i])+
67 68
                 #    residues[i].h_bond(residues[j+1]))<E_min:
@@ -73,8 +74,8 @@ def get_bridges(residues):
73 74
                and residues[j].h_bond(residues[i])<-0.5):
74 75
                 bridge = {'res1':residues[i].h_bond(residues[j]),
75 76
                           'res2':residues[j].h_bond(residues[i]),
76
-                          'ipos':i,
77
-                          'jpos':j,
77
+                          'ipos':residues[i].resid,
78
+                          'jpos':residues[j].resid,
78 79
                           'btype':"anti"}
79 80
                 # if(residues[i].h_bond(residues[j])+
80 81
                 #    residues[j].h_bond(residues[i]))<E_min:
@@ -86,8 +87,8 @@ def get_bridges(residues):
86 87
                and residues[j-1].h_bond(residues[i+1])<-0.5):
87 88
                 bridge = {'res1':residues[i-1].h_bond(residues[j+1]),
88 89
                           'res2':residues[j-1].h_bond(residues[i+1]),
89
-                          'ipos':i,
90
-                          'jpos':j,
90
+                          'ipos':residues[i].resid,
91
+                          'jpos':residues[j].resid,
91 92
                           'btype':"anti"}
92 93
                  # if(residues[i-1].h_bond(residues[j+1])+
93 94
                  #   residues[j-1].h_bond(residues[i+1]))<E_min:
@@ -128,40 +129,34 @@ def get_helix(residues, turns):
128 129
             i+=1
129 130
     return(helix)
130 131
 
132
+def get_ladder(bridges):
133
+    ladders = {}
134
+    for i in range(len(bridges)):
135
+        k = 1
136
+        while bridges[i] == bridges[i+k]:
137
+            k+=1
138
+        if k>1:
139
+            ladders[bridges[i].res_num] = k-1
140
+
131 141
 def get_bends(residues):
132 142
     bends = {}
133 143
     for i in range(2,len(residues)-2):
134
-        # print("angle",i,calculer_angles(residues[i-2].atoms["CA"].coords,
135
-        #                                 residues[i].atoms["CA"].coords,
136
-        #                                 residues[i+2].atoms["CA"].coords))
137
-        
138 144
         angle = vector_angles(vectors_substr(position_vector(residues[i].atoms["CA"].coords),
139 145
                                              position_vector(residues[i-2].atoms["CA"].coords)),
140 146
                               vectors_substr(position_vector(residues[i+2].atoms["CA"].coords),
141 147
                                              position_vector(residues[i].atoms["CA"].coords)))
142 148
         if(angle>70):
143 149
             print("angle", residues[i].resid, angle)
150
+            bends[residues[i].resid] = angle
144 151
     return(bends)
145 152
 
146
-def vecteur_deux_points (a, b):
153
+def vector_from_pos(a, b):
147 154
     xAB = b[0]-a[0]
148 155
     yAB = b[1]-a[1]
149 156
     zAB = b[2]-a[2]
150 157
     coord_AB = [xAB,yAB,zAB]
151 158
     return coord_AB
152 159
 
153
-def produit_scalaire (a, b, c):
154
-    coord_BA = vecteur_deux_points(b, a)
155
-    coord_BC = vecteur_deux_points(b, c)
156
-    dot_product = coord_BA[0]*coord_BC[0] + coord_BA[1]*coord_BC[1] + coord_BA[2]*coord_BC[2]
157
-    return dot_product
158
-
159
-
160
-def norme_vecteur (a,b):
161
-    vecteur = vecteur_deux_points(a,b)
162
-    norme = math.sqrt(vecteur[0]**2 + vecteur[1]**2 + vecteur[2]**2)
163
-    return norme
164
-
165 160
 def vector_norm(v):
166 161
     norm = math.sqrt(v[0]**2 + v[1]**2 + v[2]**2)
167 162
     return norm
@@ -171,7 +166,7 @@ def dot_product(v1,v2):
171 166
     return(dot_product)
172 167
 
173 168
 def position_vector(c):
174
-    vector = vecteur_deux_points([0,0,0],c)
169
+    vector = vector_from_pos([0,0,0],c)
175 170
     return vector
176 171
 
177 172
 def vectors_substr(v1, v2):
@@ -188,11 +183,59 @@ def vector_angles(v1,v2):
188 183
     deg_angle = rad_angle*(180/math.pi)
189 184
     return deg_angle
190 185
 
191
-def calculer_angles (a,b,c):
192
-    dot_product_ABC = produit_scalaire(a,b,c)
193
-    norme_BA = norme_vecteur (b,a)
194
-    norme_BC = norme_vecteur (b,c)
195
-    terme = dot_product_ABC/(abs(norme_BA)*abs(norme_BC))
196
-    angle_radian = math.acos(terme)
197
-    angle_degre = angle_radian*(180/math.pi)
198
-    return angle_degre
186
+def calc_dihedral(u1, u2, u3, u4):
187
+    """ Calculate dihedral angle method. From bioPython.PDB
188
+    (adapted to np.array)
189
+    Calculate the dihedral angle between 4 vectors
190
+    representing 4 connected points. The angle is in
191
+    [-pi, pi].
192
+
193
+    Adapted function of dihedral_angle_from_coordinates.py 
194
+    by Eric Alcaide.
195
+    Source : https://gist.github.com/EricAlcaide
196
+    URL : https://gist.github.com/EricAlcaide/30d6bfdb8358d3a57d010c9a501fda56
197
+    """
198
+    #convert coords to numpy arrays
199
+    u1 = np.array(u1)
200
+    u2 = np.array(u2)
201
+    u3 = np.array(u3)
202
+    u4 = np.array(u4)
203
+    
204
+    a1 = u2 - u1
205
+    a2 = u3 - u2
206
+    a3 = u4 - u3
207
+
208
+    v1 = np.cross(a1, a2)
209
+    v1 = v1 / (v1 * v1).sum(-1)**0.5
210
+    v2 = np.cross(a2, a3)
211
+    v2 = v2 / (v2 * v2).sum(-1)**0.5
212
+    porm = np.sign((v1 * a3).sum(-1))
213
+    rad = np.arccos((v1*v2).sum(-1) / ((v1**2).sum(-1) * (v2**2).sum(-1))**0.5)
214
+    if not porm == 0:
215
+        rad = rad * porm
216
+
217
+    deg_angle = rad*(180/math.pi)
218
+    return deg_angle
219
+
220
+
221
+def get_chirality(residues):
222
+
223
+    for i in range(1,len(residues)-2):
224
+        chirality = {}
225
+        angle = calc_dihedral(residues[i-1].atoms["CA"].coords,
226
+                              residues[i].atoms["CA"].coords,
227
+                              residues[i+1].atoms["CA"].coords,
228
+                              residues[i+2].atoms["CA"].coords)
229
+        
230
+        if(angle>0 and angle<=180):
231
+            sign="+"
232
+            print("angle", residues[i].resid, "+", angle)
233
+            
234
+        if(angle<=0 and angle > -180):
235
+            sign="-"
236
+            print("angle", residues[i].resid, "-", angle)
237
+            
238
+        chirality[residues[i].resid] = sign
239
+        
240
+    return chirality
241
+