-
Notifications
You must be signed in to change notification settings - Fork 0
/
restohatom.py
41 lines (32 loc) · 878 Bytes
/
restohatom.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
#!/usr/bin/python
import sys
from optparse import OptionParser
p = OptionParser()
p.add_option("--resfile" , "-r" , metavar="[*.res or *.hat file]", dest="resfile")
p.add_option("--atomtype","-a",metavar="SE",dest="atomtype")
options,args = p.parse_args()
if len(sys.argv) <= 1 :
p.print_help()
exit()
infile = options.resfile
resfile = open(infile,"read")
for i in range(7):
resfile.readline()
import re
space = re.compile("\s+")
def hatomize(line):
elems = space.split(line)
outline ="ATOM Se %s %s %s\n" % (elems[2],elems[3],elems[4])
return outline
import os
outfile= os.path.splitext(infile)[0] + ".hatom"
hatomfile = open(outfile,"write")
inputatom = options.atomtype.upper()
atom = re.compile("%s.*" % inputatom)
resfile.seek(0)
for line in resfile:
print line
if atom.match(line):
myline = hatomize(line)
print myline
hatomfile.write(myline)