-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnicenPDB
executable file
·84 lines (67 loc) · 1.97 KB
/
nicenPDB
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
#!/usr/bin/env python3
##!/usr/bin/env python2
# Charles Christoffer ([email protected])
import sys
import os
from Bio.PDB import *
from Bio import BiopythonWarning
import warnings
sys.path.append(os.path.expanduser("~christ35/bin"))
sys.path.append(os.path.expanduser("~christ35/libraries"))
should_erase_altloc = "--erase-altloc" in sys.argv
should_erase_sidechains = "--erase-sidechains" in sys.argv
class MySelect(Select):
def accept_atom(self, atom):
if should_erase_sidechains and atom.name not in ["CA", "C", "N", "O"]:
print("yo",file=sys.stderr)
return 0
if atom.element == "H":
return 0
else:
if not should_erase_altloc:
return not atom.is_disordered() or atom.get_altloc() == 'A'
else:
if not atom.is_disordered() or atom.get_altloc() == 'A':
atom.set_altloc(' ')
return True
silence = True
if silence:
warnings.simplefilter('ignore', BiopythonWarning)
parser = PDBParser()
struct = parser.get_structure("stdin", sys.stdin)
for r in struct.get_residues():
r.segid = ""
for chain in struct.get_chains():
last_res = None
for r in chain:
last_res = r
if "OT1" in last_res:
#print list(last_res.get_atoms())
ot1 = last_res["OT1"]
last_res.detach_child("OT1")
ot1.id = "OXT"
ot1.fullname = " OXT"
last_res.add(ot1)
#print list(last_res.get_atoms())
if "OT2" in last_res:
#print list(last_res.get_atoms())
ot2 = last_res["OT2"]
last_res.detach_child("OT2")
ot2.id = "O"
ot2.fullname = " O "
last_res.add(ot2)
#print list(last_res.get_atoms())
#print list(last_res.get_atoms())
chain.child_list = list(sorted(chain.child_list, key=lambda x: x.get_id()))
#chain.child_dict = list(sorted(chain.child_dict))
for model in struct:
model.child_list = list(sorted(model.child_list, key=lambda x: x.get_id()))
#for atom in struct.get_atoms():
# if atom.get_id() in ["OT1", "OT2", "OXT"]:
# print atom.get_parent()
# print atom
#
#exit(1)
pdbio = PDBIO()
pdbio.set_structure(struct)
pdbio.save(sys.stdout, MySelect())