-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddter.py
More file actions
executable file
·39 lines (35 loc) · 1019 Bytes
/
Copy pathaddter.py
File metadata and controls
executable file
·39 lines (35 loc) · 1019 Bytes
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
#!/usr/bin/python
import sys,os
usage="""
Add 'TER' to each end of peptide
Usage $0 in.pdb out.pdb
"""
if len(sys.argv)<3:
print usage
sys.exit()
infile,outfile=sys.argv[1:3]
sys.stderr.write("!!!!! Warning addter.py is not completed by now, make sure 'N' atom is the first of each residue\n")
Nxyz,Cxyz=(None,None)
Newresiflag=True
oldindex=0
oldline=""
def distance(A,B):
if None in (A,B):
return 0
dist=( (A[0]-B[0])**2 + (A[1]-B[1])**2 + (A[2]-B[2])**2 ) ** 0.5
return dist
ofp=open(outfile,"w")
for line in open(infile,"r"):
if line[0:6] not in ("ATOM " , "HETATM"):
ofp.write(line)
continue
if line[12:16].strip()=="N":
Nxyz=(float(line[30:38]),float(line[38:46]),float(line[46:54]))
if line[12:16].strip()=="C":
Cxyz=(float(line[30:38]),float(line[38:46]),float(line[46:54]))
index=int(line[22:26])
if index!=oldindex and distance(Nxyz,Cxyz)>2.0:
ofp.write("TER\n")
oldindex=index
ofp.write(line)
ofp.close()