-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdbgrep.py
More file actions
executable file
·96 lines (85 loc) · 2.3 KB
/
Copy pathpdbgrep.py
File metadata and controls
executable file
·96 lines (85 loc) · 2.3 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
#!/usr/bin/python
import sys,os
print " Not finished yet ! res_for_grep"
# Usage
if True:
usage= '''
Usage : $0 ligfile infile [radius] [res_for_grep] > outfile
default radius 5.0 A
default residues : all
'''
if len(sys.argv)<=2:
print usage
sys.exit()
else:
ligfile = sys.argv[1]
infile = sys.argv[2]
if len(sys.argv) >3 :
around = float(sys.argv[3]) # Angstrm
else:
around = 5.0
if len(sys.argv) > 4:
resi_to_grep = sys.argv[4]
def dist_2(a,b):
return (a[0]-b[0])**2+(a[1]-b[1])**2+(a[2]-b[2])**2
def res_dist_2( resa,resb ):
dist = min( [ dist_2( a,b ) for a in resa for b in resb ] )
return dist
def next_res(model):
current = None
res = list()
index = 0
for line in model:
if len(line)>5 and line[:6] in ('ATOM ','HETATM'):
resn = line[17:20]
chain = line[21]
resi = int(line[22:26])
index = (resn,chain,resi)
x = float(line[30:38])
y = float(line[38:46])
z = float(line[46:54])
if index == current or current == None :
res.append((x,y,z,line))
current = index
else:
yield index,res
res = list()
res.append((x,y,z,line))
current = index
# elif 'MODEL' in line:
# n = int(line.split()[1])
# yield n,'HEAD'
# elif 'ENDMDL' in line:
# yield None,'END'
yield index,res
### Next model
n = 1
def next_model(ifp):
global n
model = list()
for line in ifp:
if 'HEADER' in line or 'MODEL' in line :
model = list()
n_model = n
elif 'END' in line:
yield n_model,model
n += 1
else:
model.append(line)
### select ref
ref_coords = list()
for index, res in next_res(open(ligfile)):
# if index[0] == ref_resn :
if True:
ref_coords.extend(res)
# print ref_coords
### load resi
ifp = open(infile)
for n_model,model in next_model(ifp):
print "MODEL %d"%n_model
for index, res in next_res(model):
if res_dist_2(res,ref_coords) < around**2 :
for atom in res:
print atom[3],
print "ENDMDL"
ifp.close()