Skip to content

Commit 590971c

Browse files
authored
Merge pull request #1 from luksgrin/master
Added protein-RNA docking example 1A1T
2 parents 8572d5d + e099acb commit 590971c

File tree

10 files changed

+41804
-0
lines changed

10 files changed

+41804
-0
lines changed

tutorials/0.9.3/rna_docking/1a1t.pdb

+38,406
Large diffs are not rendered by default.

tutorials/0.9.3/rna_docking/data/1A1T_A.pdb

+867
Large diffs are not rendered by default.

tutorials/0.9.3/rna_docking/data/1A1T_B.pdb

+651
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
import os, re
3+
import argparse
4+
import pandas as pd
5+
from io import StringIO
6+
7+
def parseResultsList(filepath:str) -> pd.DataFrame:
8+
"""Parse solutions.list file into pandas data frame"""
9+
10+
with open(filepath) as file:
11+
filelines = file.readlines()
12+
13+
result = "".join(map(
14+
lambda line: "\t".join(filter(
15+
lambda x: x,
16+
(
17+
line.replace(
18+
pat[0],
19+
pat[0].replace(" ", "")
20+
) if (pat:=re.findall("\((.*?)\)", line)) else line
21+
).split(" ")
22+
)),
23+
filelines
24+
))
25+
26+
df = pd.read_csv(
27+
StringIO(result),
28+
sep="\t"
29+
)
30+
31+
df["Coordinates"] = (
32+
df["Coordinates"]
33+
.apply(
34+
lambda x: tuple(
35+
float(el)
36+
for el in x[1:-1].split(",")
37+
)
38+
)
39+
)
40+
41+
return df.sort_values("Scoring", ascending=False)
42+
43+
if __name__ =="__main__":
44+
45+
parser = argparse.ArgumentParser()
46+
parser.add_argument("input_solutions_file")
47+
parser.add_argument("-n", default=10)
48+
args = parser.parse_args()
49+
50+
solutionsFilePath = os.path.abspath(
51+
args.input_solutions_file
52+
)
53+
parentPath = os.path.dirname(
54+
solutionsFilePath
55+
)
56+
finalResultsPath = os.path.join(
57+
parentPath,
58+
"top_structures"
59+
)
60+
os.mkdir(finalResultsPath)
61+
62+
df = parseResultsList(solutionsFilePath).head(n=args.n).reset_index(drop=True)
63+
64+
top_structures = df.apply(
65+
lambda row: os.path.join(
66+
parentPath,
67+
"swarm_%s" % row["Swarm"],
68+
row["PDB"]
69+
),
70+
axis=1
71+
).reset_index()
72+
73+
top_structures.apply(
74+
lambda row: os.rename(
75+
row[0],
76+
os.path.join(
77+
finalResultsPath,
78+
"%s_%s" % (
79+
row["index"],
80+
os.path.basename(row[0])
81+
)
82+
)
83+
),
84+
axis=1
85+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import argparse
4+
from lightdock.pdbutil.PDBIO import read_atom_line
5+
6+
def _format_atom_name(atom_name):
7+
"""Format ATOM name with correct padding"""
8+
if len(atom_name) == 4:
9+
return atom_name
10+
else:
11+
return " %s" % atom_name
12+
13+
14+
def write_atom_line(atom, output):
15+
"""Writes a PDB file format line to output."""
16+
if atom.__class__.__name__ == "HetAtom":
17+
atom_type = "HETATM"
18+
else:
19+
atom_type = "ATOM "
20+
line = "%6s%5d %-4s%-1s%3s%2s%4d%1s %8.3f%8.3f%8.3f%6.2f%6.2f%12s\n" % (
21+
atom_type,
22+
atom.number,
23+
_format_atom_name(atom.name),
24+
atom.alternative,
25+
atom.residue_name,
26+
atom.chain_id,
27+
atom.residue_number,
28+
atom.residue_insertion,
29+
atom.x,
30+
atom.y,
31+
atom.z,
32+
atom.occupancy,
33+
atom.b_factor,
34+
atom.element,
35+
)
36+
output.write(line)
37+
38+
def _add_RNA_tag(atom):
39+
"""Adds R tag to RNA residues"""
40+
if not atom.residue_name.startswith("R"):
41+
atom.residue_name = "R" + atom.residue_name
42+
43+
return atom
44+
45+
def _remove_RNA_tag(atom):
46+
"""Removes R tag to RNA residues"""
47+
if atom.residue_name.startswith("R"):
48+
atom.residue_name = atom.residue_name[1:]
49+
50+
return atom
51+
52+
53+
if __name__ == "__main__":
54+
55+
parser = argparse.ArgumentParser()
56+
parser.add_argument("input_pdb_file")
57+
parser.add_argument("output_pdb_file")
58+
args = parser.parse_args()
59+
60+
with open(args.input_pdb_file) as ih:
61+
with open(args.output_pdb_file, 'w') as oh:
62+
63+
for line in ih:
64+
line = line.rstrip(os.linesep)
65+
66+
if line.startswith("ATOM "):
67+
atom = read_atom_line(line)
68+
69+
if atom.name in ("HO'3", "HO'5"):
70+
continue
71+
72+
write_atom_line(atom, oh)
73+
else:
74+
oh.write(line + os.linesep)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
ATOM 23 H5' DG B 1 -15.347 -3.940 -5.934 1.00 0.00 H new
5+
ATOM 24 H5'' DG B 1 -15.852 -4.851 -7.094 1.00 0.00 H new
6+
ATOM 25 H4' DG B 1 -15.214 -3.222 -8.238 1.00 0.00 H new
7+
ATOM 26 H3' DG B 1 -13.483 -5.075 -8.732 1.00 0.00 H new
8+
ATOM 27 H2' DG B 1 -11.785 -4.224 -7.287 1.00 0.00 H new
9+
ATOM 28 H2'' DG B 1 -11.314 -3.732 -8.690 1.00 0.00 H new
10+
ATOM 29 H1' DG B 1 -12.430 -1.717 -8.491 1.00 0.00 H new
11+
ATOM 30 H8 DG B 1 -10.897 -3.080 -5.447 1.00 0.00 H new
12+
ATOM 31 H1 DG B 1 -10.070 2.951 -6.160 1.00 0.00 H new
13+
ATOM 32 H21 DG B 1 -12.087 2.806 -8.716 1.00 0.00 H new
14+
ATOM 33 H22 DG B 1 -11.235 3.696 -7.879 1.00 0.00 H new
15+
"""
16+
17+
import os
18+
import argparse
19+
from lightdock.scoring.dna.data.amber import atoms_per_residue
20+
from lightdock.pdbutil.PDBIO import read_atom_line
21+
22+
23+
def _format_atom_name(atom_name):
24+
"""Format ATOM name with correct padding"""
25+
if len(atom_name) == 4:
26+
return atom_name
27+
else:
28+
return " %s" % atom_name
29+
30+
31+
def write_atom_line(atom, output):
32+
"""Writes a PDB file format line to output."""
33+
if atom.__class__.__name__ == "HetAtom":
34+
atom_type = "HETATM"
35+
else:
36+
atom_type = "ATOM "
37+
line = "%6s%5d %-4s%-1s%3s%2s%4d%1s %8.3f%8.3f%8.3f%6.2f%6.2f%12s\n" % (
38+
atom_type,
39+
atom.number,
40+
_format_atom_name(atom.name),
41+
atom.alternative,
42+
atom.residue_name,
43+
atom.chain_id,
44+
atom.residue_number,
45+
atom.residue_insertion,
46+
atom.x,
47+
atom.y,
48+
atom.z,
49+
atom.occupancy,
50+
atom.b_factor,
51+
atom.element,
52+
)
53+
output.write(line)
54+
55+
56+
translation = {
57+
"H5'": "H5'1",
58+
"H5''": "H5'2",
59+
"H2'": "H2'1",
60+
"H2''": "H2'2",
61+
"HO2'": "HO'2", # These ones were added by Lucas in November 2022
62+
"HO3'": "HO'3", #
63+
"HO5'": "HO'5" #
64+
}
65+
66+
67+
if __name__ == "__main__":
68+
69+
parser = argparse.ArgumentParser()
70+
parser.add_argument("input_pdb_file")
71+
parser.add_argument("output_pdb_file")
72+
args = parser.parse_args()
73+
74+
with open(args.input_pdb_file) as ih:
75+
with open(args.output_pdb_file, 'w') as oh:
76+
for line in ih:
77+
line = line.rstrip(os.linesep)
78+
if line.startswith("ATOM "):
79+
atom = read_atom_line(line)
80+
if atom.residue_name not in atoms_per_residue:
81+
print(f"Not supported atom: {atom.residue_name}.{atom.name}")
82+
else:
83+
if atom.name not in atoms_per_residue[atom.residue_name] and atom.is_hydrogen():
84+
try:
85+
atom.name = translation[atom.name]
86+
write_atom_line(atom, oh)
87+
except KeyError:
88+
print(f"Atom not found in mapping: {atom.residue_name}.{atom.name}")
89+
else:
90+
write_atom_line(atom, oh)
91+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import argparse
4+
from lightdock.pdbutil.PDBIO import read_atom_line
5+
6+
def _format_atom_name(atom_name):
7+
"""Format ATOM name with correct padding"""
8+
if len(atom_name) == 4:
9+
return atom_name
10+
else:
11+
return " %s" % atom_name
12+
13+
14+
def write_atom_line(atom, output):
15+
"""Writes a PDB file format line to output."""
16+
if atom.__class__.__name__ == "HetAtom":
17+
atom_type = "HETATM"
18+
else:
19+
atom_type = "ATOM "
20+
line = "%6s%5d %-4s%-1s%3s%2s%4d%1s %8.3f%8.3f%8.3f%6.2f%6.2f%12s\n" % (
21+
atom_type,
22+
atom.number,
23+
_format_atom_name(atom.name),
24+
atom.alternative,
25+
atom.residue_name,
26+
atom.chain_id,
27+
atom.residue_number,
28+
atom.residue_insertion,
29+
atom.x,
30+
atom.y,
31+
atom.z,
32+
atom.occupancy,
33+
atom.b_factor,
34+
atom.element,
35+
)
36+
output.write(line)
37+
38+
def _add_RNA_tag(atom):
39+
"""Adds R tag to RNA residues"""
40+
if not atom.residue_name.startswith("R"):
41+
atom.residue_name = "R" + atom.residue_name
42+
43+
return atom
44+
45+
def _remove_RNA_tag(atom):
46+
"""Removes R tag to RNA residues"""
47+
if atom.residue_name.startswith("R"):
48+
atom.residue_name = atom.residue_name[1:]
49+
50+
return atom
51+
52+
53+
if __name__ == "__main__":
54+
55+
parser = argparse.ArgumentParser()
56+
parser.add_argument("input_pdb_file", help="Input pdb file")
57+
parser.add_argument("output_pdb_file", help="Output pdb file")
58+
parser.add_argument("-r", default=False, action=argparse.BooleanOptionalAction, help="Removes `R` tag instead")
59+
args = parser.parse_args()
60+
61+
with open(args.input_pdb_file) as ih:
62+
with open(args.output_pdb_file, 'w') as oh:
63+
64+
for line in ih:
65+
line = line.rstrip(os.linesep)
66+
67+
if line.startswith("ATOM "):
68+
atom = read_atom_line(line)
69+
70+
if args.r:
71+
atom = _remove_RNA_tag(atom)
72+
else:
73+
atom = _add_RNA_tag(atom)
74+
75+
write_atom_line(atom, oh)
76+
else:
77+
oh.write(line + os.linesep)
34.3 MB
Binary file not shown.

0 commit comments

Comments
 (0)