-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_helix_angle.py
325 lines (274 loc) · 10.3 KB
/
module_helix_angle.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
#!/usr/bin/env python
# ~*~ coding:utf-8 ~*~
"""
This script permit to calculate differetns angles between alpha-helix from a
PDB file or a MD simulation (CHARMM or GROMACS).
The differents angles are :
- helix - helix angle
- helix - helix bundle angle
- helix - helix torsion angle
"""
import lib.function_helix_angle as fct
import lib.math_angle as ma
import matplotlib.pyplot as plt
import numpy as np
import math
import sys
import os
__author__ = "Emmanuel Edouard MOUTOUSSAMY"
__version__ = "1.0.0"
__date__ = "2015/09"
__copyright__ = "CC_by_SA"
__dependencies__ = "os, sys, numpy, math, matplotlib, MDAnalysis"
#-----------------------------PDB-----------------------------------------------
def PDBHelix_vs_helix(pdb,limits_file = 0):
"""
Compute the angle between for all combination of two diffrents helix.
all the results is write on an output file.
Args : a pdb file and a limits file (optional)
"""
if limits_file == 0:
ss = fct.secondary_structure(pdb) # compute the helix position
else:
ss = fct.get_ss(limits_file,pdb)# get the helix position from helix list
list_helix = fct.search_helix(pdb,ss) # extract helix from a pdb
fct.print_limits(list_helix) # print and write the helix position
fct.get_inertie_mtx(list_helix) # compute the inertia matrix
fct.helix_evec(list_helix) # compute the eigen vector for each helix
print "\n"
print "Results :"
output = open("helix_helix_angle.dat","w")
header = "#Helix angle(degrees)\n"
output.write(header) # write the header on the output file
print header
start = 1
# this double loop allows to compute angle between each helix couple
for i in range(len(list_helix)):
axis1 = list_helix[i].eig_vec[:,0] # axis of helix 1
for j in range(start,len(list_helix)):
axis2 = list_helix[j].eig_vec[:,0] # axis for helix 2
axis1 = fct.check_vec_sens(axis1,axis2) # check the vectors direction
angle = math.acos(axis1.dot(axis2))*57.3
out = "%s-%s %.3f"%(list_helix[i].name,list_helix[j].name,angle)
output.write("%s\n"%out) # write the angle on the output file
print out
start += 1
print "The resutls file : helix_helix_angle.dat"
print ""
output.close()
def PDBHelix_vs_helixBunble(pdb,limits_file = 0):
"""
Allows to compute the angle between an helix and the protein axis on a pdb
file.
Args : a pdb file and a limits file (optional)
Return : a file which contain all the angle calculation
"""
if limits_file == 0:
ss = fct.secondary_structure(pdb) # compute the helix position
else:
ss = fct.get_ss(limits_file,pdb)# get the helix position from helix list
list_helix = fct.search_helix(pdb,ss) # extract helix from a pdb
fct.print_limits(list_helix) # print and write the helix position
fct.get_inertie_mtx(list_helix) # compute the inertia matrix
fct.helix_evec(list_helix)# compute the eigen vector for each helix
hb_axis = fct.helix_bundle_evec(list_helix) # compute the helix bundle axis
output = open("prot_angle.dat","w")
output.write("#Helix angle(degrees)\n")
axis1 = hb_axis[:,0]
i = 1
print "\nResults : "
for helix in list_helix:
axis2 = helix.eig_vec[:,0]
#Compute the helix-helix bundle angle :
angle = math.acos(axis1.dot(axis2))*57.3
out = "%s-helix_bundle_axis %.3f\n"%(helix.name,angle)
output.write(out)
print out
i += 1
output.close()
def PDBhelix_torsion_angle(pdb,limits_file = 0):
"""
Compute the torsion angle for helix which is contact in a pdbfile
"""
if limits_file == 0:
ss = fct.secondary_structure(pdb) # compute the helix position
else:
ss = fct.get_ss(limits_file,pdb)# get the helix position from helix list
list_helix = fct.search_helix(pdb,ss) # extract helix from a pdb
fct.print_limits(list_helix) # print and write the helix position
contact = fct.WhichIsInContact(list_helix)# Compute which helix is in contact
fct.get_inertie_mtx(list_helix) # compute the inertia matrix
fct.helix_evec(list_helix) # Compute the eigen vectors for each helix
output = open("torsion_angle.dat","w")
header = "#Helix torsion_angle(degrees)\n"
output.write(header)
print header
start = 1
for i in range(len(list_helix)):
h1 = list_helix[i]
for j in range(start,len(list_helix)):
h2 = list_helix[j]
ang = "%s-%s"%(h1.name,h2.name)
if ang in contact:
# Compute the torsion angle :
angle = ma.compute_torsion_angle(h1,h2)
out = "%s-%s %.3f\n"%(h1.name,h2.name,angle)
output.write(out)
print out
start += 1
output.close()
#-----------------------------MD simulaion--------------------------------------
def MDhelix_vs_helix(top,traj,output = 0,limits = 0):
"""
Compute the helix - helix angle during a MD simulation.
If output = "w", an output file is write.
Args : a topology, a trajectory file and an output (optional)
Return : a numpy matrix which contain all angle and a list which contain all
angle couple.
"""
#mk a directory and compute the number of frame in the trajectory:
last_frame,dir_name = fct.get_pdb(top,traj) #number of frame
row = 0
if output == "w":
output = open('results_helix_vs_helix.dat','w')
for i in range(last_frame):
print 'Compute helix-helix angle for frame : %i'%(i+1)
if i == 0:
if limits == 0:
# Compute the helix positions:
ss = fct.secondary_structure("%s/dssp_input.pdb"%dir_name)
else :
# Extract the helix positions from an input file
ss = fct.get_ss(limits,"%s/dssp_input.pdb"%dir_name)
#Extract helix from the frame:
list_helix = fct.search_helix("%s/frame_1.pdb"%dir_name,ss)
if i == 0:
#Print and write the helix positions
fct.print_limits(list_helix,"w")
# Create a numpy matrix with the good dimensions:
results_mtx = fct.mk_results_mtx(last_frame,list_helix)
names = fct.header_hvsh(output,list_helix)
# Extract helix from the frame:
list_helix = fct.search_helix("%s/frame_%i.pdb"%(dir_name,i+1),ss)
# Compute the inertia matrix:
fct.get_inertie_mtx(list_helix)
#Compute the eigen vectors :
fct.helix_evec(list_helix)
results_mtx,row = fct.compute_hvsh(i,output,list_helix,results_mtx,row)
if output != 0:
output.close()
# os.system("rm -rf %s"%dir_name)
return results_mtx,names
def MDhelix_vs_helixbundle(top,traj,output = 0,limits = 0):
"""
Compute the helix - helix bundle angle during a MD simulation.
If output = "w", an output file is write.
Args : a topology, a trajectory file and an output (optional)
Return : a numpy matrix which contain all angle and a list which contain all
the combination of angle.
"""
#mk a directory and compute the number of frame in the trajectory:
last_frame,dir_name = fct.get_pdb(top,traj)
row = 0
if output == "w":
output = open('results_helix_vs_helixbundle.dat','w')
for i in range(last_frame):
print 'Compute helix - helix bundle angle for frame : %i'%(i+1)
if i == 0:
if limits == 0 :
# Compute the helix positions:
ss = fct.secondary_structure("%s/dssp_input.pdb"%dir_name)
else:
# Extract the helix positions from an input file:
ss = fct.get_ss(limits,"%s/dssp_input.pdb"%dir_name)
list_helix = fct.search_helix("%s/frame_1.pdb"%dir_name,ss)
for helix in list_helix:
print helix.name,helix.res_start,helix.res_finish
if i == 0:
fct.print_limits(list_helix,"w")
results_mtx = np.zeros((last_frame,len(list_helix)))
names = fct.header_hvshb(output,list_helix)
list_helix = fct.search_helix("%s/frame_%i.pdb"%(dir_name,i+1),ss)
#Compute the inertia matrix :
fct.get_inertie_mtx(list_helix)
#Compute the eigen vectors :
fct.helix_evec(list_helix)
# Compute the helixbundle axis:
baxe = fct.helix_bundle_evec(list_helix)
results_mtx,row = fct.compute_hvshb(i,output,list_helix,baxe[:,0],\
results_mtx,row)
if output != 0:
output.close()
os.system("rm -rf %s"%dir_name)
return results_mtx,names
def MDhelix_torsion_angle(top,traj,output = 0):
#mk a directory and compute the number of frame in the trajectory:
last_frame,dirname = fct.get_pdb(top,traj)
row = 0
if output == "w":
output = open('results_helix_torsion_angle.dat','w')
for i in range(last_frame):
print 'Compute helix - helix torsion angle for frame : %i'%(i+1)
if i == 0:
ss = fct.secondary_structure("%s/dssp_input.pdb"%dirname)
list_helix = fct.search_helix("%s/frame_%i.pdb"%(dirname,i+1),ss)
if i == 0:
fct.print_limits(list_helix,"w")
contact = fct.WhichIsInContact(list_helix)
results_mtx = np.zeros((last_frame,len(contact)))
if output != 0:
fct.header_hta(output,contact)
fct.get_inertie_mtx(list_helix) #Compute inertia matrix
fct.helix_evec(list_helix) # Compute eigen vectors
fct.evec_correction(list_helix) # Correct the vector direction
fct.get_mass_center(list_helix) # Compute the mass center
results_mtx,row = fct.compute_hta(i,output,list_helix,\
contact,results_mtx,row)
if output != 0:
output.close()
os.system("rm -rf %s"%dirname)
return results_mtx,contact
#----------------------------PLOT-----------------------------------------------
def plot_all(results_mtx,names,dir_name = "plot"):
"""
Write all the graphics.
Args : the results matrix, a list which contain the name of the different
angle and a directory name.
"""
dir_name = fct.mk_directory(dir_name) # Make a directory
col = results_mtx.shape[1]
for i in range(col):
print "Writting graphic %s"%names[i]
val = results_mtx[:,i]
mean = np.mean(val)
plt.plot(range(len(val)),val,'.',color = "k") # plot
plt.title("%s (mean angle = %.2f degree)"%(names[i],mean)) # add title
plt.ylabel("angle (degrees)") # add y label
plt.xlabel("Time step") # add x label
plt.axhline(y=mean, color = 'red') # add a line for the mean value
plt.ylim((min(val)-10,max(val)+10))
plt.savefig("%s/plot_%s.png"%(dir_name,names[i])) # save
plt.clf()
def plot_angle(angle,names,results_mtx):
"""
Write just one angle.
Args : an angle name such as 'H1-H2' and a list which contain the name of the
different angle and the results matrix.
"""
col = "null"
# This loop allow to find the col of the angle in the results matrix
for i in range(len(names)):
if names[i] == angle:
col = i
if col == "null":
sys.exit("ERROR : angle not find")
val = results_mtx[:,col]
mean = np.mean(val)
plt.plot(range(len(val)),val,'.',color = "k") #Plot
plt.title("%s (mean angle = %.2f degree)"%(names[i],mean)) #Title
plt.ylabel("angle (degrees)") # add y label
plt.xlabel("Time step") # add x lab
plt.axhline(y=mean, color = 'red') # add a line for the mean value
plt.ylim((min(val)-10,max(val)+10))
plt.savefig("plot_%s.png"%(angle))# save
plt.clf()