-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
68 lines (56 loc) · 1.4 KB
/
process.py
File metadata and controls
68 lines (56 loc) · 1.4 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
import re
import sys
import atom
import os
from optparse import OptionParser
class pdbfile(object):
non_atom_record = []
atom_record = []
linedict = {}
atomdict = {}
def __init__(self,file):
self.file = open(file,"read")
self.isatom = re.compile("^ATOM")
i = 0
for line in file:
self.linedict[i] = line
if self.isatom.match(line):
myatom = atom.Atom(line)
atomkey = (myatom.serial,myatom.name,myatom.chainid)
self.atomdict[atomkey] = myatom
i = i + 1
def make_chainid_segid_same(self):
outfile_name = os.path.splitext(self.file.name)[0] + "-mod-chain-segsame.pdb"
outfile = None
try:
outfile = open(outfile_name,"write")
except IOError:
print "Cannot open file for writing"
atomarray = []
self.file.seek(0)
for line in self.file:
if self.isatom.match(line):
if line[21:22] != line[72:73]:
newline = line[0:72] + line[21:22] + line[73:]
outfile.write(newline)
outfile.flush()
else:
outfile.write(line)
outfile.flush()
else:
outfile.write(line)
outfile.flush()
outfile.flush()
outfile.close()
if __name__=="__main__":
try:
p = OptionParser()
p.add_option("-i","--infile" , dest="pdbfile",metavar="*.pdb")
opttuple,spillover = p.parse_args()
file = opttuple.pdbfile
p = pdbfile(file)
p.make_chainid_segid_same()
except IOError:
p.print_help()
except TypeError:
p.print_help()