|
@@ -1,5 +1,6 @@
|
1
|
1
|
import math
|
2
|
2
|
import numpy as np
|
|
3
|
+from geom import *
|
3
|
4
|
|
4
|
5
|
class Structure:
|
5
|
6
|
def __init__(self, res):
|
|
@@ -25,305 +26,4 @@ class Helix(Structure):
|
25
|
26
|
self.residues = residues
|
26
|
27
|
self.res_num = res_num
|
27
|
28
|
Structure.res = res_num
|
28
|
|
-
|
29
|
|
-def get_turns(residues):
|
30
|
|
- # TODO : prevent redondency of overlapping turns
|
31
|
|
- turns = {}
|
32
|
|
- for i,res in enumerate(residues):
|
33
|
|
- for j in range(3,6):
|
34
|
|
- if(i+j<len(residues)):
|
35
|
|
- if(res.h_bond(residues[i+j])<-0.5):
|
36
|
|
- print(j,"TURN", residues[i].resid, residues[i+j].resid)
|
37
|
|
- turns[i] = Turn(j,residues[i].resid)
|
38
|
|
- return(turns)
|
39
|
|
-
|
40
|
|
-def get_bridges(residues):
|
41
|
|
- bridges = {}
|
42
|
|
- bridge = {}
|
43
|
|
- strongest_bridge = {}
|
44
|
|
- for i in range(1,len(residues)-4):
|
45
|
|
- E_min = 0
|
46
|
|
- for j in range(i+2,len(residues)-1):
|
47
|
|
- # select triplet with the minimal energy
|
48
|
|
-
|
49
|
|
- if(residues[i-1].h_bond(residues[j])<-0.5
|
50
|
|
- and residues[j].h_bond(residues[i+1])<-0.5):
|
51
|
|
- bridge = {'res1':residues[i-1].h_bond(residues[j]),
|
52
|
|
- 'res2':residues[j].h_bond(residues[i+1]),
|
53
|
|
- 'ipos':residues[i].resid,
|
54
|
|
- 'jpos':residues[j].resid,
|
55
|
|
- 'btype':"para"}
|
56
|
|
-
|
57
|
|
- if(residues[j-1].h_bond(residues[i])<-0.5
|
58
|
|
- and residues[i].h_bond(residues[j+1])<-0.5):
|
59
|
|
- bridge = {'res1':residues[j-1].h_bond(residues[i]),
|
60
|
|
- 'res2':residues[i].h_bond(residues[j+1]),
|
61
|
|
- 'ipos':residues[i].resid,
|
62
|
|
- 'jpos':residues[j].resid,
|
63
|
|
- 'btype':"para"}
|
64
|
|
-
|
65
|
|
- if(residues[i].h_bond(residues[j])<-0.5
|
66
|
|
- and residues[j].h_bond(residues[i])<-0.5):
|
67
|
|
- bridge = {'res1':residues[i].h_bond(residues[j]),
|
68
|
|
- 'res2':residues[j].h_bond(residues[i]),
|
69
|
|
- 'ipos':residues[i].resid,
|
70
|
|
- 'jpos':residues[j].resid,
|
71
|
|
- 'btype':"anti"}
|
72
|
|
-
|
73
|
|
- if(residues[i-1].h_bond(residues[j+1])<-0.5
|
74
|
|
- and residues[j-1].h_bond(residues[i+1])<-0.5):
|
75
|
|
- bridge = {'res1':residues[i-1].h_bond(residues[j+1]),
|
76
|
|
- 'res2':residues[j-1].h_bond(residues[i+1]),
|
77
|
|
- 'ipos':residues[i].resid,
|
78
|
|
- 'jpos':residues[j].resid,
|
79
|
|
- 'btype':"anti"}
|
80
|
|
-
|
81
|
|
- if(bridge):
|
82
|
|
- if(bridge['res1']+bridge['res2']<E_min):
|
83
|
|
- E_min = bridge['res1']+bridge['res2']
|
84
|
|
- strongest_bridge = bridge
|
85
|
|
- bridge = {}
|
86
|
|
- coord_bridge = [i,j]
|
87
|
|
- # finally add the strongest bridge at i and j pos
|
88
|
|
- if(strongest_bridge):
|
89
|
|
- bridges[coord_bridge[0]] = (Bridge(strongest_bridge['btype'],
|
90
|
|
- strongest_bridge['ipos'],
|
91
|
|
- strongest_bridge['jpos']))
|
92
|
|
- bridges[coord_bridge[1]] = (Bridge(strongest_bridge['btype'],
|
93
|
|
- strongest_bridge['jpos'],
|
94
|
|
- strongest_bridge['ipos']))
|
95
|
|
- if(len(bridges)>0):
|
96
|
|
- return(bridges)
|
97
|
|
- else:
|
98
|
|
- return(False)
|
99
|
|
-
|
100
|
|
-# def get_bonds(residues):
|
101
|
|
-# for i,res1 in enumerate(residues):
|
102
|
|
-# E_min = 0
|
103
|
|
-# strongest_bridge = []
|
104
|
|
-# for j in range(-5,6):
|
105
|
|
-# if(i+j < len(residues)):
|
106
|
|
-# res2 = residues[i+j]
|
107
|
|
-# if(res1.h_bond(res2)<-0.5) and (res1.h_bond(res2)<E_min):
|
108
|
|
-# E_min = res1.h_bond(res2)
|
109
|
|
-# strongest_bridge = [res1, res2]
|
110
|
|
-# if(len(strongest_bridge)>0):
|
111
|
|
-# diff = strongest_bridge[0].resid - strongest_bridge[1].resid
|
112
|
|
-# if( abs (diff) > 1 and abs(diff)<=5):
|
113
|
|
-# print(diff)
|
114
|
|
-
|
115
|
|
-def get_bonds(residues):
|
116
|
|
- bonds = {}
|
117
|
|
- k = 0
|
118
|
|
- for i,res in enumerate(residues):
|
119
|
|
- E_min = 0
|
120
|
|
- for j in range(-5,-2):
|
121
|
|
- if(i+j<len(residues)):
|
122
|
|
- if(residues[i+j].h_bond(res)<-0.5):
|
123
|
|
- k+=1
|
124
|
|
- #if(res.h_bond(residues[i+j])<E_min):
|
125
|
|
- E_min = res.h_bond(residues[i+j])
|
126
|
|
- res_a = res
|
127
|
|
- res_b = residues[i+j]
|
128
|
|
- if j not in bonds:
|
129
|
|
- bonds[j] = []
|
130
|
|
- bonds[j].append([res_a.resid, res_b.resid])
|
131
|
|
- #turns[residues[i].resid] = Turn(j,residues[i].resid)
|
132
|
|
- for key in bonds.keys():
|
133
|
|
- print(key, len(bonds[key]))
|
134
|
|
-
|
135
|
|
- print("LH",k)
|
136
|
|
-
|
137
|
|
-def get_helix(residues, turns):
|
138
|
|
- i = 1
|
139
|
|
- helix = []
|
140
|
|
- while i <= len(residues):
|
141
|
|
- if(i in turns.keys() and i-1 in turns.keys()):
|
142
|
|
- k = 0
|
143
|
|
- temp_res = []
|
144
|
|
- while(i+k in turns):
|
145
|
|
- k+=1
|
146
|
|
- temp_res.append(residues[i])
|
147
|
|
- last_res_pos = residues[i].resid+k
|
148
|
|
- if(k>=1):
|
149
|
|
- helix_size=last_res_pos - residues[i].resid
|
150
|
|
- print(turns[i].turn_type,"- HELIX at", residues[i].resid)
|
151
|
|
- helix.append(Helix(temp_res,residues[i].resid))
|
152
|
|
- i = i+k
|
153
|
|
- else:
|
154
|
|
- i+=1
|
155
|
|
- return(helix)
|
156
|
|
-
|
157
|
|
-def get_ladders(bridges, residues):
|
158
|
|
- ladders = {}
|
159
|
|
- i = 1
|
160
|
|
- while i < len(residues):
|
161
|
|
- k = 1
|
162
|
|
- if i in bridges.keys():
|
163
|
|
- temp_bridges = [bridges[i]]
|
164
|
|
- while ((i+k in bridges.keys()) and
|
165
|
|
- (bridges[i].bridge_type == bridges[i+k].bridge_type)):
|
166
|
|
- temp_bridges.append(bridges[i+k])
|
167
|
|
- k+=1
|
168
|
|
- if k>1:
|
169
|
|
- ladders[i] = k-1
|
170
|
|
- print("ladder", bridges[i].res_num, bridges[i+k-1].res_num)
|
171
|
|
- ladders[i] = {'start':bridges[i].res_num,
|
172
|
|
- 'end':bridges[i+k-1].res_num,
|
173
|
|
- 'bridges':temp_bridges}
|
174
|
|
- i+=k-1
|
175
|
|
- else:
|
176
|
|
- i+=1
|
177
|
|
- return ladders
|
178
|
29
|
|
179
|
|
-def get_sheets(ladders):
|
180
|
|
- """
|
181
|
|
- Bridges between ladders.
|
182
|
|
- Check if 1 bridge between one ladder and one or more other ladders.
|
183
|
|
- Iterate over all residues of one ladder and check if bridge with other residues
|
184
|
|
- of the other ladders.
|
185
|
|
- """
|
186
|
|
- sheets = {}
|
187
|
|
- for ladder in ladders:
|
188
|
|
- for ladd2 in ladders:
|
189
|
|
- for bridge in ladders[ladder]['bridges']:
|
190
|
|
- if bridge.res_partner in res_list(ladders[ladd2]):
|
191
|
|
- print("ladder",ladders[ladder]['start'], ladders[ladder]['end'],"bridge",bridge.res_num, bridge.res_partner,
|
192
|
|
- "ladder 2",ladders[ladd2]['start'], ladders[ladd2]['end'])
|
193
|
|
- #print("stop ladder 2")
|
194
|
|
- print("stop ladder 1")
|
195
|
|
-
|
196
|
|
-def res_list(ladder):
|
197
|
|
- # TODO : method in ladder class
|
198
|
|
- l=[]
|
199
|
|
- for i in range(ladder['start'], ladder['end']):
|
200
|
|
- l.append(i)
|
201
|
|
- return(l)
|
202
|
|
-
|
203
|
|
-def get_bends(residues):
|
204
|
|
- bends = {}
|
205
|
|
- for i in range(2,len(residues)-2):
|
206
|
|
- angle = math.degrees(vector_angles(vectors_substr(position_vector(residues[i].atoms["CA"].coords),
|
207
|
|
- position_vector(residues[i-2].atoms["CA"].coords)),
|
208
|
|
- vectors_substr(position_vector(residues[i+2].atoms["CA"].coords),
|
209
|
|
- position_vector(residues[i].atoms["CA"].coords))))
|
210
|
|
- if(angle>70):
|
211
|
|
- print("angle", residues[i].resid, angle)
|
212
|
|
- bends[residues[i].resid] = angle
|
213
|
|
- return(bends)
|
214
|
|
-
|
215
|
|
-def vector_from_pos(a, b):
|
216
|
|
- xAB = b[0]-a[0]
|
217
|
|
- yAB = b[1]-a[1]
|
218
|
|
- zAB = b[2]-a[2]
|
219
|
|
- coord_AB = [xAB,yAB,zAB]
|
220
|
|
- return coord_AB
|
221
|
|
-
|
222
|
|
-def vector_norm(v):
|
223
|
|
- norm = math.sqrt(v[0]**2 + v[1]**2 + v[2]**2)
|
224
|
|
- return norm
|
225
|
|
-
|
226
|
|
-def dot_product(v1,v2):
|
227
|
|
- dot_product = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]
|
228
|
|
- return(dot_product)
|
229
|
|
-
|
230
|
|
-def position_vector(c):
|
231
|
|
- vector = vector_from_pos([0,0,0],c)
|
232
|
|
- return vector
|
233
|
|
-
|
234
|
|
-def vectors_substr(v1, v2):
|
235
|
|
- return ([v1[0]-v2[0],
|
236
|
|
- v1[1]-v2[1],
|
237
|
|
- v1[2]-v2[2]])
|
238
|
|
-
|
239
|
|
-def vector_angles(v1,v2):
|
240
|
|
- dot_prod = dot_product(v1,v2)
|
241
|
|
- norm_v1 = vector_norm(v1)
|
242
|
|
- norm_v2 = vector_norm(v2)
|
243
|
|
- term = dot_prod/(abs(norm_v1)*abs(norm_v2))
|
244
|
|
- rad_angle = math.acos(term)
|
245
|
|
- return rad_angle
|
246
|
|
-
|
247
|
|
-def calc_dihedral(u1, u2, u3, u4):
|
248
|
|
- """ Calculate dihedral angle method. From bioPython.PDB
|
249
|
|
- (adapted to np.array)
|
250
|
|
- Calculate the dihedral angle between 4 vectors
|
251
|
|
- representing 4 connected points. The angle is in
|
252
|
|
- [-pi, pi].
|
253
|
|
-
|
254
|
|
- Adapted function of dihedral_angle_from_coordinates.py
|
255
|
|
- by Eric Alcaide.
|
256
|
|
- Source : https://gist.github.com/EricAlcaide
|
257
|
|
- URL : https://gist.github.com/EricAlcaide/30d6bfdb8358d3a57d010c9a501fda56
|
258
|
|
- """
|
259
|
|
- #convert coords to numpy arrays
|
260
|
|
- u1 = np.array(u1)
|
261
|
|
- u2 = np.array(u2)
|
262
|
|
- u3 = np.array(u3)
|
263
|
|
- u4 = np.array(u4)
|
264
|
|
-
|
265
|
|
- a1 = u2 - u1
|
266
|
|
- a2 = u3 - u2
|
267
|
|
- a3 = u4 - u3
|
268
|
|
-
|
269
|
|
- v1 = np.cross(a1, a2)
|
270
|
|
- v1 = v1 / (v1 * v1).sum(-1)**0.5
|
271
|
|
- v2 = np.cross(a2, a3)
|
272
|
|
- v2 = v2 / (v2 * v2).sum(-1)**0.5
|
273
|
|
- porm = np.sign((v1 * a3).sum(-1))
|
274
|
|
- rad = np.arccos((v1*v2).sum(-1) / ((v1**2).sum(-1) * (v2**2).sum(-1))**0.5)
|
275
|
|
- if not porm == 0:
|
276
|
|
- rad = rad * porm
|
277
|
|
-
|
278
|
|
- deg_angle = rad*(180/math.pi)
|
279
|
|
- return deg_angle
|
280
|
|
-
|
281
|
|
-
|
282
|
|
-def get_chirality(residues):
|
283
|
|
-
|
284
|
|
- for i in range(1,len(residues)-2):
|
285
|
|
- chirality = {}
|
286
|
|
- angle = calc_dihedral(residues[i-1].atoms["CA"].coords,
|
287
|
|
- residues[i].atoms["CA"].coords,
|
288
|
|
- residues[i+1].atoms["CA"].coords,
|
289
|
|
- residues[i+2].atoms["CA"].coords)
|
290
|
|
-
|
291
|
|
- if(angle>0 and angle<=180):
|
292
|
|
- sign="+"
|
293
|
|
- print("chirality", residues[i].resid, "+", angle)
|
294
|
|
-
|
295
|
|
- if(angle<=0 and angle > -180):
|
296
|
|
- sign="-"
|
297
|
|
- print("chirality", residues[i].resid, "-", angle)
|
298
|
|
-
|
299
|
|
- chirality[residues[i].resid] = sign
|
300
|
|
-
|
301
|
|
- return chirality
|
302
|
|
-
|
303
|
|
-
|
304
|
|
-def get_phi_psi(residues):
|
305
|
|
- for i in range(len(residues)):
|
306
|
|
- if(i==0):
|
307
|
|
- phi = 360.0
|
308
|
|
- else:
|
309
|
|
- phi = calc_dihedral(residues[i-1].atoms["C"].coords,
|
310
|
|
- residues[i].atoms["N"].coords,
|
311
|
|
- residues[i].atoms["CA"].coords,
|
312
|
|
- residues[i].atoms["C"].coords)
|
313
|
|
- if(i==len(residues)-1):
|
314
|
|
- psi = 360.0
|
315
|
|
- else:
|
316
|
|
- psi = calc_dihedral(residues[i].atoms["N"].coords,
|
317
|
|
- residues[i].atoms["CA"].coords,
|
318
|
|
- residues[i].atoms["C"].coords,
|
319
|
|
- residues[i+1].atoms["N"].coords)
|
320
|
|
-
|
321
|
|
- print("ANGLES", i, phi, psi)
|
322
|
|
-
|
323
|
|
-def get_TCO(res1, res2):
|
324
|
|
- CO_res1 = vector_from_pos(res1.atoms["C"].coords,
|
325
|
|
- res1.atoms["O"].coords)
|
326
|
|
- CO_res2 = vector_from_pos(res2.atoms["C"].coords,
|
327
|
|
- res2.atoms["O"].coords)
|
328
|
|
- angle = vector_angles(CO_res1, CO_res2)
|
329
|
|
- return(math.cos(angle))
|