-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpdb_structure_analyse.py
More file actions
executable file
·258 lines (182 loc) · 7.84 KB
/
Copy pathpdb_structure_analyse.py
File metadata and controls
executable file
·258 lines (182 loc) · 7.84 KB
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
#!/usr/bin/env python
# encoding: utf-8
import Bio.PDB as bp
import sys
from numpy import pi, array, linalg, dot, zeros, set_printoptions
from collections import defaultdict
set_printoptions(linewidth=200)
def count_in_area(area, coordinates):
"""
area is an area specified as ( ( x_low, x_high ), ( y_low, y_high ) )
coordinates is an iterable containing N objects, each of which is an
iterable containing two items forming a 2D coordinate.
Returns the number of those coordinates which fall within the area.
"""
npcoords = array(coordinates)
#Check if each value is in its range
#i.e. xlo < x < xhi and ylo < y < yhi
truth = (npcoords >= [area[0][0],area[0][1]]) & \
(npcoords <= [area[1][0],area[1][1]])
#Check if each pair of values are both in their range together
truth2 = truth[1:,0] & truth[:-1,1]
count = truth2.sum()
return count
def get_phi_psi_hits( phi_psi ):
motifs = {
"alpha_in" : [ ( ( -pi/2, -5*pi/12 ) , ( -pi/6, -pi/12 ) ) ],
"alpha_in" : [ ( ( -pi/2, -5*pi/12 ) , ( -pi/6, -pi/12 ) ) ],
"alpha_l" : [ ( ( pi/6, pi/12 ) , ( pi/2, 5*pi/18 ) ) ],
"alpha_out" : [ ( ( -pi, -pi/2 ) , ( 0.0, pi/6 ) ) ],
"beta" : [ ( (-pi, pi/2 ) , (-5*pi/9, pi ) ) ,
( ( -pi , -pi ) , ( -5*pi/9, -5*pi/6 ) ) ,
( ( 5*pi/6, pi/2 ) , ( pi, pi ) ) ],
"ppii" : [ ( ( -5*pi/9, pi/2 ) , ( 0.0, pi ) ) ,
( ( -5*pi/9, -pi ) , ( 0.0, -5*pi/6 ) ) ],
"gamma" : [ ( ( -pi , pi/6 ) , ( 0.0, pi/2 ) ) ],
"gamma_l" : [ ( ( pi/3, -2*pi/3 ) , ( 2*pi/3, 0.0 ) ) ]
}
hits = {}
for motif_name in motifs:
hits[motif_name] = 0
for area in motifs[motif_name]:
hits[motif_name] += count_in_area( area, phi_psi )
hits["alpha_out"] -= hits["alpha_in"]
return hits
def hbond_angle_term( Nx, Ns_COx, Ns_CHx, Cx, Cs_CHx, Cs_NHx ):
vec_CO_N = Nx - Ns_COx
vec_CH_N = Nx - Ns_CHx
vec_N_H = vec_CO_N/linalg.norm(vec_CO_N) + vec_CH_N/linalg.norm(vec_CH_N)
vec_N_H = vec_N_H/linalg.norm(vec_N_H)
vec_CH_C = Cx - Cs_CHx
vec_NH_C = Cx - Cs_NHx
vec_C_O = vec_CH_C/linalg.norm(vec_CH_C) + vec_NH_C/linalg.norm(vec_NH_C)
vec_C_O = vec_C_O/linalg.norm(vec_C_O)
vec_N_C = Cx - Nx
vec_N_C = vec_N_C/linalg.norm(vec_N_C)
costhetaN = dot( vec_N_H, vec_N_C )
costhetaC = dot( vec_C_O, -vec_N_C )
if costhetaC > 0.0 and costhetaN > 0.0:
return costhetaC*costhetaC*costhetaN*costhetaN
return 0.0
def find_PLUM_hbonds( model, same_chain_allowed=True, threshold=0.5 ):
#settings
hb_dist_cut=8.0
sigma=4.11
#Create list of NH-
Ns = []
Cs = []
pairs_within_cutoff = []
hbond_pairs = []
for atom in model.get_atoms():
if atom.name == 'N':
Ns.append(atom)
elif atom.name == 'C':
Cs.append(atom)
#Build list of pairs qualifying on:
#not pro, within dist cutoff, not adjacent or same residue
for N in Ns:
#check N doesn't belong to Pro; can't Hbond
if N.get_parent().get_resname() == ' P':
continue
for C in Cs:
#Within cutoff?
if linalg.norm( N.get_coord() - C.get_coord() ) > hb_dist_cut:
continue
#Not on adjacent or the same residues?
dist = abs( N.parent.get_id()[1] - C.parent.get_id()[1] )
on_same_chain = ( N.parent.parent.get_id() == C.parent.parent.get_id() )
if on_same_chain == True:
if same_chain_allowed == False or dist < 2:
continue
pairs_within_cutoff.append( [N,C] )
for N,C in pairs_within_cutoff:
Ns_res = N.parent
Cs_res = C.parent
Ns_chain = Ns_res.parent
Cs_chain = Cs_res.parent
N_resid=Ns_res.get_id()[1]
C_resid=Cs_res.get_id()[1]
try:
Ns_CO = filter( lambda x: x.name == 'C', Ns_chain[N_resid-1] )[0]
Cs_NH = filter( lambda x: x.name == 'N', Cs_chain[C_resid+1] )[0]
except KeyError:
continue
Ns_CH = filter(lambda x : x.name == 'CA', Ns_res)[0]
Cs_CH = filter(lambda x : x.name == 'CA', Cs_res)[0]
angle_term = hbond_angle_term( N.get_coord(), Ns_CO.get_coord(), Ns_CH.get_coord(),
C.get_coord(), Cs_CH.get_coord(), Cs_NH.get_coord() )
dist = linalg.norm( N.get_coord() - C.get_coord() )
dist_term = 5*(sigma/dist)**12 - 6*(sigma/dist)**10
pre_energy = -dist_term*angle_term
if pre_energy > threshold:
hbond_pairs.append([N_resid, C_resid, pre_energy])
return hbond_pairs
def get_SC_capts( model, threshold, res_separation ):
SC_atoms = []
captured = []
for atom in model.get_atoms():
if ['N', 'CA', 'C'].count(atom.name) == 0:
SC_atoms.append(atom)
for i1, atom1 in enumerate(SC_atoms):
for atom2 in SC_atoms[i1+1:]:
same_chain = ( atom1.parent.parent.get_id() == atom2.parent.parent.get_id() )
dist = abs( atom1.parent.get_id()[1] - atom2.parent.get_id()[1] )
if same_chain and dist < res_separation:
continue
dist = linalg.norm( atom1.get_coord() - atom2.get_coord() )
if dist < threshold:
captured.append( (atom1, atom2) )
return captured
def resID_to_local_resID(resID, res_per_chain):
local_resID = resID
while local_resID > 0:
local_resID -= res_per_chain
return local_resID+res_per_chain
def hbond_hits_2D(PDB_files,res_per_chain,same_chain_allowed):
# PLUM hbonds
models = 0
pair_hits_ar = zeros([res_per_chain,res_per_chain],dtype=int)
for PDB_file in PDB_files:
print PDB_file
for i_model, model in enumerate(bp.PDBParser().get_structure("",PDB_file)):
models += 1
hbond_pairs = find_PLUM_hbonds( model, same_chain_allowed=same_chain_allowed, threshold = 0.2 )
hits_this = defaultdict(int, {})
for N_res, C_res, val in hbond_pairs:
global_pair = frozenset([N_res, C_res])
if hits_this[global_pair] == 0:
hits_this[global_pair] = 1
local_resID1 = resID_to_local_resID(N_res, res_per_chain)
local_resID2 = resID_to_local_resID(C_res, res_per_chain)
pair_hits_ar[local_resID1-1,local_resID2-1] += 1
pair_hits_ar[local_resID2-1,local_resID1-1] += 1
print pair_hits_ar
print ""
print pair_hits_ar.astype(float)/(models*8)
def hbond_hits_1D(PDB_files,res_per_chain,same_chain_allowed):
# PLUM hbonds
models = 0
hits_ar = zeros([res_per_chain],dtype=int)
for PDB_file in PDB_files:
print PDB_file
for i_model, model in enumerate(bp.PDBParser().get_structure("",PDB_file)):
models += 1
hbond_pairs = find_PLUM_hbonds( model, same_chain_allowed=same_chain_allowed, threshold = 0.2 )
hits_this = defaultdict(int, {})
for N_res, C_res, val in hbond_pairs:
global_res1 = N_res
global_res2 = C_res
if hits_this[global_res1] == 0:
hits_this[global_res1] = 1
local_resID1 = resID_to_local_resID(N_res, res_per_chain)
hits_ar[local_resID1-1] += 1
if hits_this[global_res2] == 0:
hits_this[global_res2] = 1
local_resID2 = resID_to_local_resID(C_res, res_per_chain)
hits_ar[local_resID2-1] += 1
print hits_ar
print ""
print hits_ar.astype(float)/(models*8)
if __name__ == '__main__':
PDB_files=sys.argv[1:]
hbond_hits_1D(PDB_files,30,False)