/
run_reorder_box.py
executable file
·49 lines (43 loc) · 1.17 KB
/
run_reorder_box.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
40
41
42
43
44
45
46
47
48
49
from __future__ import division
import iotbx.pdb
import os
from cctbx import uctbx
"""
Re-order PDB files that were obtained from XYZ files, then place in P1 box.
"""
def reorder(path, prefix):
pdb_inp = iotbx.pdb.input(file_name="%s%s.pdb"%(path,prefix))
h = pdb_inp.construct_hierarchy()
rg = list(h.residue_groups())
rg.reverse()
#
c = iotbx.pdb.hierarchy.chain(id="A")
for rg_ in rg:
c.append_residue_group(rg_.detached_copy())
#
r = iotbx.pdb.hierarchy.root()
m = iotbx.pdb.hierarchy.model()
r.append_model(m)
m.append_chain(c)
atoms = r.atoms()
#
box = uctbx.non_crystallographic_unit_cell_with_the_sites_in_its_center(
sites_cart=atoms.extract_xyz(),
buffer_layer=3.)
atoms.set_xyz(new_xyz=box.sites_cart)
#
fo = open("%s-new.pdb"%prefix,"w")
print >> fo, iotbx.pdb.format_cryst1_record(
crystal_symmetry=box.crystal_symmetry())
for a in atoms:
a = a.set_b(30.)
print >> fo, a.format_atom_record()
fo.close()
def run():
path = "../00_original_pdb/"
for f in os.listdir(path):
if(f.endswith(".pdb")):
prefix = f[:-4]
reorder(path = path, prefix = prefix)
if __name__ == "__main__":
run()