Newer
Older
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
from eval.docking import docking
from eval.prepare import prepare
from eval.window import compute_box
import os
import csv
from eval.get_mutations import get_num_mutations
def get_energy(receptor_path, ligand_path):
#receptor_name = "0_whole"
#ligand_name = "0"
# compute the sizes of the docking "box" / window
docking_box = compute_box(receptor_path, ligand_path, padding=10)
#print(docking_box["center"])
# prepare source files to PDBQT files
receptor_path_preped = prepare(receptor_path)
ligand_path_preped = prepare(ligand_path)
try:
energy = docking(receptor_path_preped,
ligand_path_preped,
center=docking_box["center"],
box_size=docking_box["size"],
n_dockings=40,
n_poses=20)["Kd"]
print("Kd:", energy)
return energy
except Exception as e:
print(f"[!]Error: {e}.")
print("------")
return -1
output_path = "./summary.tsv"
res_path = "./data/PG_res/"
DATA = [["ID", "KD", "NUM_MUTATIONS"]]
for mol in os.listdir(res_path):
if mol.endswith(".sdf"):
print("-------------------------")
# We have a molecule that ends with sdf, which means that his receptors are also here
prefix = mol[0:-4]
for rec in os.listdir(res_path):
if rec.startswith(prefix) and rec.endswith(".pdb"):
# We have a receptor that starts with the prefix of the molecule
print("Doing:", rec, "with ligand:", mol)
energy = get_energy(os.path.join(res_path, rec),
os.path.join(res_path, mol))
numbers = "".join([s for s in rec.split() if s.isdigit()])
num_mutations = get_num_mutations(
os.path.join(res_path, rec),
os.path.join(res_path, numbers + "_whole.pdb"))
DATA.append([rec, energy, num_mutations])
if int(numbers) >= 3:
break
# Write the list of lists into the TSV file
with open(output_path, 'w', newline='') as file:
writer = csv.writer(file, delimiter='\t')
writer.writerows(DATA)