-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatomtypeconvert.py
More file actions
executable file
·74 lines (62 loc) · 1.86 KB
/
Copy pathatomtypeconvert.py
File metadata and controls
executable file
·74 lines (62 loc) · 1.86 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
#!/usr/bin/python
import sys,os
# print usage if len(sys.argv)==1
if len(sys.argv)<4:
print "Usage: $0 'a2g|g2a' in.pdb [out.pdb]"
sys.exit()
ctype,infile,outfile=(sys.argv+["out.pdb"])[1:4]
# define a function which convert atom name e.g. "1HB2"->"HB21"
def fixatomname(str):
if str[0].isdigit() :
str="%4s"%(str[1:].strip()+str[0])
return str
# Load convert table
table = dict()
if ctype == 'g2a':
tablefile="%s/table_gmx2amb.dat"%os.environ['FQY_SCRIPT_PATH']
water = (' O HOH',' H1 HOH',' H2 HOH')
if ctype == 'a2g':
tablefile="%s/table_amb2gmx.dat"%os.environ['FQY_SCRIPT_PATH']
water = (' OW SOL',' HW1 SOL',' HW2 SOL')
ifp=open(tablefile,"r")
for line in ifp:
if line.strip()[0]=="#":continue
res,oldname,newname=line.strip().split(":")[0:3]
oldname=fixatomname(oldname)
newname=fixatomname(newname)
table[res,oldname]=newname
# Convert
ofp=open(outfile,"w")
ifp=open(infile,"r")
for line in ifp:
if line[0:6]!="ATOM " and line[0:6]!="HETATM":
ofp.write(line)
continue
res=line[17:20]
name=line[12:16]
name=fixatomname(name)
## When non-solvnet
if res not in ('HOH',"SOL",'WAT'):
if table.has_key((res,name)):
newname=table[res,name]
newline="%s%s%s"%(line[:12],newname,line[16:])
elif table.has_key(("*",name)):
newname=table["*",name]
newline="%s%s%s"%(line[:12],newname,line[16:])
else:
newline=line
## When water
else:
if 'O' in name:
newline="%s%s%s"%(line[:12],water[0],line[20:])
elif '1' in name:
newline="%s%s%s"%(line[:12],water[1],line[20:])
elif '2' in name:
newline="%s%s%s"%(line[:12],water[2],line[20:])
else:
newline = line
ofp.write(newline)
pass
ifp.close()
ofp.close()
print "Done"