-
Notifications
You must be signed in to change notification settings - Fork 1
/
stackdef.py
executable file
·361 lines (331 loc) · 12 KB
/
stackdef.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
### ------------------------------
### Definitions of stacking score
### (see Condon et al., JCTC 2014, 11, 2729-2742)
### compatibles with pyemma featurizer
### written by Giovanni Pinamonti (SISSA, Trieste)
### @FU-Berlin, November 2015
### ------------------------------
import numpy as np
import sys
import mdtraj
atom_name_base='name N1 or name C2 or name N2 or name O2 or name N3 or name C4 or name N4 or name O4 or name C5 or name C6 or name N6 or name O6 or name N7 or name C8 or name N9'
def get_comdist(traj,res1,res2):
top=traj.topology
l_b1=top.select('resid '+str(res1)+' and ('+atom_name_base+')')
l_b2=top.select('resid '+str(res2)+' and ('+atom_name_base+')')
tb1=traj.atom_slice(l_b1)
tb2=traj.atom_slice(l_b2)
pos1=tb1.xyz
pos2=tb2.xyz
d0=[]
natoms1=len(l_b1)
natoms2=len(l_b2)
for iframe in range(len(pos1)):
tmp_CoM1=np.array([sum(pos1[iframe,:,0]),sum(pos1[iframe,:,1]),sum(pos1[iframe,:,2])])/natoms1
tmp_CoM2=np.array([sum(pos2[iframe,:,0]),sum(pos2[iframe,:,1]),sum(pos2[iframe,:,2])])/natoms2
vec_d0=tmp_CoM1-tmp_CoM2
tmp_d0=np.sqrt(sum(vec_d0**2))
d0.append(tmp_d0)
d0=np.array(d0,dtype=np.float32).reshape(len(traj),1)
return d0
def get_omega21(traj,res1,res2):
top=traj.topology
l_nb1=top.select('resid '+str(res1)+' and ('+atom_name_base+')')
l_nb2=top.select('resid '+str(res2)+' and ('+atom_name_base+')')
tnb1=traj.atom_slice(l_nb1)
tnb2=traj.atom_slice(l_nb2)
#resname2=tnb2.top.residue(res2).name
resname2=top.residue(0).name
if resname2=='A':
l_C8_2=tnb2.top.select('name C8')
l_N6_2=tnb2.top.select('name N6')
if resname2=='G':
l_C8_2=tnb2.top.select('name C8')
l_N6_2=tnb2.top.select('name O6')
if resname2=='C':
l_C8_2=tnb2.top.select('name O2')
l_N6_2=tnb2.top.select('name N4')
if resname2=='U':
l_C8_2=tnb2.top.select('name O2')
l_N6_2=tnb2.top.select('name O4')
pos1=tnb1.xyz
pos2=tnb2.xyz
omegas=[]
natoms1=tnb1.n_atoms
natoms2=tnb2.n_atoms
a2s=tnb2.atom_slice(l_C8_2).xyz
b2s=tnb2.atom_slice(l_N6_2).xyz
for iframe in range(len(traj)):
CoM1=np.array([sum(pos1[iframe,:,0]),sum(pos1[iframe,:,1]),sum(pos1[iframe,:,2])])/natoms1
CoM2=np.array([sum(pos2[iframe,:,0]),sum(pos2[iframe,:,1]),sum(pos2[iframe,:,2])])/natoms2
d0=CoM1-CoM2
a2=a2s[iframe,0,:]-CoM2
b2=b2s[iframe,0,:]-CoM2
c2=np.cross(a2,b2)
len_c2=np.sqrt(sum(c2**2))
len_d0=np.sqrt(sum(d0**2))
omega=np.arccos(np.dot(c2,d0)/(len_c2*len_d0))
omegas.append(omega)
omegas=np.array(omegas,dtype=np.float32).reshape(len(traj),1)
return omegas
def get_omega12(traj,res1,res2):
top=traj.topology
l_nb1=top.select('resid '+str(res1)+' and ('+atom_name_base+')')
l_nb2=top.select('resid '+str(res2)+' and ('+atom_name_base+')')
tnb1=traj.atom_slice(l_nb1)
tnb2=traj.atom_slice(l_nb2)
resname1=tnb1.top.residue(0).name
if resname1=='A':
l_C8_1=tnb1.top.select('name C8')
l_N6_1=tnb1.top.select('name N6')
if resname1=='G':
l_C8_1=tnb1.top.select('name C8')
l_N6_1=tnb1.top.select('name O6')
if resname1=='C':
l_C8_1=tnb1.top.select('name O2')
l_N6_1=tnb1.top.select('name N4')
if resname1=='U':
l_C8_1=tnb1.top.select('name O2')
l_N6_1=tnb1.top.select('name O4')
pos1=tnb1.xyz
pos2=tnb2.xyz
omegas=[]
natoms1=tnb1.n_atoms
natoms2=tnb2.n_atoms
a1s=tnb1.atom_slice(l_C8_1).xyz
b1s=tnb1.atom_slice(l_N6_1).xyz
for iframe in range(len(traj)):
CoM1=np.array([sum(pos1[iframe,:,0]),sum(pos1[iframe,:,1]),sum(pos1[iframe,:,2])])/natoms1
CoM2=np.array([sum(pos2[iframe,:,0]),sum(pos2[iframe,:,1]),sum(pos2[iframe,:,2])])/natoms2
d0=CoM2-CoM1
a1=a1s[iframe,0,:]-CoM1
b1=b1s[iframe,0,:]-CoM1
c1=np.cross(a1,b1)
len_c1=np.sqrt(sum(c1**2))
len_d0=np.sqrt(sum(d0**2))
omega=np.arccos(np.dot(c1,d0)/(len_c1*len_d0))
#omegas.append(len_c1)
omegas.append(omega)
omegas=np.array(omegas,dtype=np.float32).reshape(len(traj),1)
return omegas
def get_chi(traj,res1,res2):
top=traj.topology
l_nb1=top.select('resid '+str(res1)+' and ('+atom_name_base+')')
l_nb2=top.select('resid '+str(res2)+' and ('+atom_name_base+')')
tnb1=traj.atom_slice(l_nb1)
tnb2=traj.atom_slice(l_nb2)
resname1=tnb1.top.residue(0).name
if resname1=='A':
l_C8_1=tnb1.top.select('name C8')
l_N6_1=tnb1.top.select('name N6')
if resname1=='G':
l_C8_1=tnb1.top.select('name C8')
l_N6_1=tnb1.top.select('name O6')
if resname1=='C':
l_C8_1=tnb1.top.select('name O2')
l_N6_1=tnb1.top.select('name N4')
if resname1=='U':
l_C8_1=tnb1.top.select('name O2')
l_N6_1=tnb1.top.select('name O4')
resname2=tnb2.top.residue(0).name
if resname2=='A':
l_C8_2=tnb2.top.select('name C8')
l_N6_2=tnb2.top.select('name N6')
if resname2=='G':
l_C8_2=tnb2.top.select('name C8')
l_N6_2=tnb2.top.select('name O6')
if resname2=='C':
l_C8_2=tnb2.top.select('name O2')
l_N6_2=tnb2.top.select('name N4')
if resname2=='U':
l_C8_2=tnb2.top.select('name O2')
l_N6_2=tnb2.top.select('name O4')
pos1=tnb1.xyz
pos2=tnb2.xyz
chis=[]
natoms1=tnb1.n_atoms
natoms2=tnb2.n_atoms
a1s=tnb1.atom_slice(l_C8_1).xyz
b1s=tnb1.atom_slice(l_N6_1).xyz
a2s=tnb2.atom_slice(l_C8_2).xyz
b2s=tnb2.atom_slice(l_N6_2).xyz
for iframe in range(len(traj)):
CoM1=np.array([sum(pos1[iframe,:,0]),sum(pos1[iframe,:,1]),sum(pos1[iframe,:,2])])/natoms1
CoM2=np.array([sum(pos2[iframe,:,0]),sum(pos2[iframe,:,1]),sum(pos2[iframe,:,2])])/natoms2
a1=a1s[iframe,0,:]-CoM1
b1=b1s[iframe,0,:]-CoM1
c1=np.cross(a1,b1)
len_c1=np.sqrt(sum(c1**2))
a2=a2s[iframe,0,:]-CoM2
b2=b2s[iframe,0,:]-CoM2
c2=np.cross(a2,b2)
len_c2=np.sqrt(sum(c2**2))
chi=np.arccos(np.dot(c1,c2)/(len_c1*len_c2))
chis.append(chi)
chis=np.array(chis,dtype=np.float32).reshape(len(traj),1)
return chis
def get_stack_score(traj,res1,res2):
top=traj.topology
l_nb1=top.select('resid '+str(res1)+' and ('+atom_name_base+')')
l_nb2=top.select('resid '+str(res2)+' and ('+atom_name_base+')')
tnb1=traj.atom_slice(l_nb1)
tnb2=traj.atom_slice(l_nb2)
pos1=tnb1.xyz
pos2=tnb2.xyz
score=[]
natoms1=tnb1.n_atoms
natoms2=tnb2.n_atoms
resname1=tnb1.top.residue(0).name
if resname1=='A':
l_C8_1=tnb1.top.select('name C8')
l_N6_1=tnb1.top.select('name N6')
if resname1=='G':
l_C8_1=tnb1.top.select('name C8')
l_N6_1=tnb1.top.select('name O6')
if resname1=='C':
l_C8_1=tnb1.top.select('name O2')
l_N6_1=tnb1.top.select('name N4')
if resname1=='U':
l_C8_1=tnb1.top.select('name O2')
l_N6_1=tnb1.top.select('name O4')
resname2=tnb2.top.residue(0).name
if resname2=='A':
l_C8_2=tnb2.top.select('name C8')
l_N6_2=tnb2.top.select('name N6')
if resname2=='G':
l_C8_2=tnb2.top.select('name C8')
l_N6_2=tnb2.top.select('name O6')
if resname2=='C':
l_C8_2=tnb2.top.select('name O2')
l_N6_2=tnb2.top.select('name N4')
if resname2=='U':
l_C8_2=tnb2.top.select('name O2')
l_N6_2=tnb2.top.select('name O4')
a2s=tnb2.atom_slice(l_C8_2).xyz
b2s=tnb2.atom_slice(l_N6_2).xyz
a1s=tnb1.atom_slice(l_C8_1).xyz
b1s=tnb1.atom_slice(l_N6_1).xyz
for iframe in range(len(pos1)):
#compute d0
CoM1=np.array([sum(pos1[iframe,:,0]),sum(pos1[iframe,:,1]),sum(pos1[iframe,:,2])])/natoms1
CoM2=np.array([sum(pos2[iframe,:,0]),sum(pos2[iframe,:,1]),sum(pos2[iframe,:,2])])/natoms2
d0=CoM1-CoM2
len_d0=np.sqrt(sum(d0**2))
#compute omega21
a2=a2s[iframe,0,:]-CoM2
b2=b2s[iframe,0,:]-CoM2
c2=np.cross(a2,b2)
len_c2=np.sqrt(sum(c2**2))
omega=np.arccos(np.dot(c2,d0)/(len_c2*len_d0))*180/np.pi
#compute chi
a1=a1s[iframe,0,:]-CoM1
b1=b1s[iframe,0,:]-CoM1
c1=np.cross(a1,b1)
len_c1=np.sqrt(sum(c1**2))
chi=np.arccos(np.dot(c1,c2)/(len_c1*len_c2))*180/np.pi
#now compute the score:
#d0
if len_d0<=0.35:
tmp_score=1
elif len_d0 <=0.5:
#tmp_score=(0.5-len_d0)/0.15
#tmp_score=(0.5-len_d0)**3/0.15**3
A=0.065258752
tmp_score=A/(len_d0**3)-8*A
else:
score.append(0)
continue
#omega
if omega<=25 or omega>=155:
tmp_score+=1
elif omega<=50:
tmp_score+=(50-omega)/25
elif omega>=130:
tmp_score+=(omega-130)/25
else:
score.append(0)
continue
#chi
if chi>45 and chi<135:
tmp_score*=-1
#append final score
score.append(tmp_score)
score=np.array(score,dtype=np.float32).reshape(len(traj),1)
return score
def get_stack_var(traj,res1,res2):
top=traj.topology
l_nb1=top.select('resid '+str(res1)+' and ('+atom_name_base+')')
l_nb2=top.select('resid '+str(res2)+' and ('+atom_name_base+')')
tnb1=traj.atom_slice(l_nb1)
tnb2=traj.atom_slice(l_nb2)
pos1=tnb1.xyz
pos2=tnb2.xyz
varis=[]
# len_d0s=[]
# omegas12=[]
# omegas21=[]
# chis=[]
natoms1=tnb1.n_atoms
natoms2=tnb2.n_atoms
resname1=tnb1.top.residue(0).name
if resname1=='A':
l_C8_1=tnb1.top.select('name C8')
l_N6_1=tnb1.top.select('name N6')
if resname1=='G':
l_C8_1=tnb1.top.select('name C8')
l_N6_1=tnb1.top.select('name O6')
if resname1=='C':
l_C8_1=tnb1.top.select('name O2')
l_N6_1=tnb1.top.select('name N4')
if resname1=='U':
l_C8_1=tnb1.top.select('name O2')
l_N6_1=tnb1.top.select('name O4')
resname2=tnb2.top.residue(0).name
if resname2=='A':
l_C8_2=tnb2.top.select('name C8')
l_N6_2=tnb2.top.select('name N6')
if resname2=='G':
l_C8_2=tnb2.top.select('name C8')
l_N6_2=tnb2.top.select('name O6')
if resname2=='C':
l_C8_2=tnb2.top.select('name O2')
l_N6_2=tnb2.top.select('name N4')
if resname2=='U':
l_C8_2=tnb2.top.select('name O2')
l_N6_2=tnb2.top.select('name O4')
a2s=tnb2.atom_slice(l_C8_2).xyz
b2s=tnb2.atom_slice(l_N6_2).xyz
a1s=tnb1.atom_slice(l_C8_1).xyz
b1s=tnb1.atom_slice(l_N6_1).xyz
for iframe in range(len(pos1)):
#compute d0
CoM1=np.array([sum(pos1[iframe,:,0]),sum(pos1[iframe,:,1]),sum(pos1[iframe,:,2])])/natoms1
CoM2=np.array([sum(pos2[iframe,:,0]),sum(pos2[iframe,:,1]),sum(pos2[iframe,:,2])])/natoms2
d0=CoM1-CoM2
len_d0=np.sqrt(sum(d0**2))
#compute omega12
a1=a1s[iframe,0,:]-CoM1
b1=b1s[iframe,0,:]-CoM1
c1=np.cross(a1,b1)
len_c1=np.sqrt(sum(c1**2))
omega12=np.arccos(np.dot(c1,d0)/(len_c1*len_d0))*180/np.pi
#compute omega21
a2=a2s[iframe,0,:]-CoM2
b2=b2s[iframe,0,:]-CoM2
c2=np.cross(a2,b2)
len_c2=np.sqrt(sum(c2**2))
omega21=np.arccos(np.dot(c2,d0)/(len_c2*len_d0))*180/np.pi
#compute chi
chi=np.arccos(np.dot(c1,c2)/(len_c1*len_c2))*180/np.pi
# len_d0s.append(len_d0)
# omegas12.append(omegas12)
# omegas21.append(omegas21)
# chis.append(chi)
varis.append(np.array([len_d0,omega12,omega21,chi]))
# len_d0s=np.array(len_d0s,dtype=np.float32).reshape(len(traj),1)
# omegas12=np.array(omegas12,dtype=np.float32).reshape(len(traj),1)
# omegas21=np.array(omegas21,dtype=np.float32).reshape(len(traj),1)
# chis=np.array(chis,dtype=np.float32).reshape(len(traj),1)
varis=np.array(varis,dtype=np.float32).reshape(len(traj),4)
# return np.array([len_d0s,omegas12,omegas21,chis]).T
return varis