-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseparate_structure.py
62 lines (52 loc) · 2.28 KB
/
separate_structure.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
50
51
52
53
54
55
56
57
58
59
60
61
62
from pathlib import Path
from os import SEEK_CUR, SEEK_END
def separate_pdb(pdb_in: Path,
pdb_a: Path,
pdb_b: Path):
with pdb_in.open() as i, pdb_a.open("w") as a, pdb_b.open("w") as b:
curr_residue = -1
first_chain = True
for line in i:
if line.startswith("ATOM") or line.startswith("HETATM") or line.startswith("TER"):
residue_number = int(line[22:26].strip())
if curr_residue < 0:
curr_residue = residue_number
if residue_number - curr_residue > 10:
first_chain = False
if first_chain:
a.write(line)
else:
b.write(line[:21] + "B" + line[22:])
curr_residue = residue_number
def separate_results(p1, p2, fd_output_dir, output_dir):
outdir = fd_output_dir / f"{p1}-{p2}_results"
for i in range(1, 6):
outfile = outdir / f"{p1}-{p2}_{i}" / "unrelaxed_model_1.pdb"
afile = output_dir / f"{p1}-{p2}_{i}_A.pdb"
bfile = output_dir / f"{p1}-{p2}_{i}_B.pdb"
separate_pdb(outfile, afile, bfile)
def run(folddock_output_dir: Path,
interactions_file: Path,
output_dir: Path
):
assert folddock_output_dir.is_dir()
assert output_dir.is_dir()
assert interactions_file.is_file()
interactions = sorted([l.strip().split() for l in interactions_file.open()])
print(f"processing {len(interactions)} interactions")
for p1, p2 in interactions:
separate_results(p1, p2, folddock_output_dir, output_dir)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description="Extract the list of interactions that finished successfully")
parser.add_argument("-d", "--folddock-output-dir", required=True,
help="Path to the output directory")
parser.add_argument("-i", "--interactions-file", required=True,
help="Path to the interactions file")
parser.add_argument("-o", "--output-dir", required=True,
help="Path to the output file")
args = parser.parse_args()
run(Path(args.folddock_output_dir),
Path(args.interactions_file),
Path(args.output_dir))