Skip to content

Commit

Permalink
fix:mcdock rigid docking; test:remove mcdock rmsd assert (#87)
Browse files Browse the repository at this point in the history
* fix:mcdock rigid docking; test:remove mcdock rmsd assert

* style:pyright check

* build:tool test image reback to unidock_tools latest
  • Loading branch information
dp-yuanyn authored Mar 4, 2024
1 parent 0f1e30e commit b83599e
Show file tree
Hide file tree
Showing 6 changed files with 439 additions and 61 deletions.
94 changes: 85 additions & 9 deletions unidock_tools/tests/applications/test_mcdock.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pathlib import Path
import os
import shutil
import glob
import json
import subprocess
import logging
import pytest


Expand All @@ -16,30 +18,104 @@ def get_docking_args(testset_name):
calc_ligand = os.path.join(testset_dir_path, testset_name, f"{testset_name}_ligand_prep.sdf")
with open(os.path.join(testset_dir_path, testset_name, "docking_grid.json")) as f:
pocket = json.load(f)
return receptor, ref_ligand, calc_ligand, pocket
testset_info = {
"receptor": receptor,
"ref_ligand": ref_ligand,
"ligand": calc_ligand,
"pocket": pocket,
"confgen_ref_ligand": os.path.join(testset_dir_path, testset_name, f"{testset_name}_ligand_confgen.sdf")
}
return testset_info


@pytest.mark.parametrize("testset_name", testset_name_list)
def test_mcdock_steps(testset_name):
from rdkit import Chem
from unidock_tools.application.mcdock import MultiConfDock
import uuid
workdir = Path(f"mcdock_testdir_{uuid.uuid4().hex[:6]}")
testset_info = get_docking_args(testset_name)
pocket = testset_info["pocket"]
mcd = MultiConfDock(
receptor=Path(testset_info["receptor"]).resolve(),
ligands=[Path(testset_info["ligand"]).resolve()],
center_x=float(pocket["center_x"]),
center_y=float(pocket["center_y"]),
center_z=float(pocket["center_z"]),
size_x=float(pocket["size_x"]),
size_y=float(pocket["size_y"]),
size_z=float(pocket["size_z"]),
workdir=workdir
)
mcd.generate_conformation(max_nconf=200, min_rmsd=0.3)
confgen_result_file = glob.glob(os.path.join(workdir, "confgen_results", "*.sdf"))[0]
mols = Chem.SDMolSupplier(confgen_result_file, removeHs=False)
confgen_ref_ligand = testset_info["confgen_ref_ligand"]
confgen_ref_mols = Chem.SDMolSupplier(confgen_ref_ligand, removeHs=False)
for i in range(len(mols)):
assert (mols[i].GetConformer(0).GetPositions() == confgen_ref_mols[i].GetConformer(0).GetPositions()).all(), \
"confgen results error"

mcd.run_unidock(
scoring_function="vina",
exhaustiveness=128,
max_step=20,
num_modes=3,
refine_step=5,
seed=181129,
topn=100,
batch_size=20,
docking_dir_name="rigid_docking",
props_list=["fragAllInfo", "atomInfo"],
)
rigid_result_files = glob.glob(os.path.join(workdir, "rigid_docking", "*.sdf"))
for rigid_result_file in rigid_result_files:
mols = Chem.SDMolSupplier(rigid_result_file, removeHs=False)
assert len(mols) == 3, "rigid docking failed to generate and keep 3 pose"
assert not mols[0].HasProp("torsionInfo"), "rigid docking should not have torsion"
assert mols[0].GetProp("fragInfo").strip() == " ".join([str(i) for i in range(1, 1 + mols[0].GetNumAtoms())]), "rigid docking fragment should be the whole molecular"

mcd.run_unidock(
scoring_function="vina",
exhaustiveness=512,
max_step=40,
num_modes=1,
refine_step=5,
seed=181129,
topn=1,
batch_size=20,
local_only=True,
docking_dir_name="local_refine_docking",
props_list=["fragInfo", "torsionInfo", "atomInfo"],
)
local_refine_result_files = glob.glob(os.path.join(workdir, "local_refine_docking", "*.sdf"))
for local_refine_result_file in local_refine_result_files:
mols = Chem.SDMolSupplier(local_refine_result_file, removeHs=False)
assert len(mols) == 1, "local refine docking failed to generate and keep 1 pose"
assert mols[0].HasProp("torsionInfo"), "local refine docking should have torsion"
assert mols[0].HasProp("fragInfo"), "local refine docking should have fragment"

shutil.rmtree(workdir)


@pytest.mark.parametrize("testset_name", testset_name_list)
def test_mcdock_cmd_default(testset_name):
from unidock_tools.modules.docking import calc_rmsd

receptor, ref_ligand, ligand, pocket = get_docking_args(testset_name)
print(receptor)
print(ref_ligand)
print(ligand)
print(pocket)
testset_info = get_docking_args(testset_name)
receptor, ref_ligand, ligand, pocket = testset_info["receptor"], testset_info["ref_ligand"], testset_info["ligand"], testset_info["pocket"]
results_dir = "mcdock_results"
cmd = f"unidocktools mcdock -r {receptor} -l {ligand} -sd {results_dir} -g \
-cx {pocket['center_x']} -cy {pocket['center_y']} -cz {pocket['center_z']} \
-sx {pocket['size_x']} -sy {pocket['size_y']} -sz {pocket['size_z']}"
print(cmd)
logging.debug(cmd)
resp = subprocess.run(cmd, shell=True, capture_output=True, encoding="utf-8")
print(resp.stdout)
logging.info(resp.stdout)
assert resp.returncode == 0, f"run mcdock pipeline app err:\n{resp.stderr}"

result_ligand = os.path.join(results_dir, f"{testset_name}_ligand_prep.sdf")
assert os.path.exists(result_ligand), f"docking result file not found"

rmsd = calc_rmsd(ref_ligand, result_ligand)[0]
assert rmsd <= 4.0, f"rmsd not satisfied: {rmsd}"
#assert rmsd <= 8.0, f"best pose rmsd not satisfied: {rmsd}"
shutil.rmtree(results_dir, ignore_errors=True)
260 changes: 260 additions & 0 deletions unidock_tools/tests/inputs/mcdock/8AJX/8AJX_ligand_confgen.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 0.0005 -2.0996 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 -0.0000 -1.1402 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 0.0013 -1.1413 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3503 0.0023 -0.0175 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2876 0.0008 -2.2992 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 0.0011 0.9595 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 0.0005 -2.0996 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 -0.0000 -1.1402 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 0.0013 -1.1413 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3488 0.0012 -2.2658 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2892 0.0026 0.0160 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 -0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 0.0011 0.9595 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 -0.0005 2.0996 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 0.0000 1.1402 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 -0.0013 1.1413 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3503 -0.0023 0.0175 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2876 -0.0008 2.2992 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 -0.0011 -0.9595 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 2.0678 -0.3641 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 1.1229 -0.1980 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 1.1241 -0.1969 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3503 0.0177 -0.0007 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2876 2.2644 -0.3985 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 -0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 -0.9448 0.1677 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 -2.0676 -0.3651 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 -1.1229 -0.1980 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 -1.1237 -0.1994 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3503 -0.0168 -0.0053 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2876 -2.2641 -0.4000 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 0.9451 0.1655 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 0.0005 -2.0996 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 -0.0000 -1.1402 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 0.0013 -1.1413 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3485 1.1087 -1.3374 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2895 -1.1381 -0.9397 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 -0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 0.0011 0.9595 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 0.0005 -2.0996 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 -0.0000 -1.1402 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 0.0013 -1.1413 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3503 -1.1054 -1.3363 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2876 1.1418 -0.9415 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 -0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 0.0011 0.9595 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 2.0678 -0.3641 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 1.1229 -0.1980 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 1.1241 -0.1969 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3485 1.5096 0.8596 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2895 0.7278 -1.2840 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 -0.9448 0.1677 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 -2.0676 -0.3651 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 -1.1229 -0.1980 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 -1.1237 -0.1994 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3485 -1.1246 -1.3241 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2895 -1.1231 0.9576 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 -0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 0.9451 0.1655 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
8AJX_ligand_prep
RDKit 3D

10 9 0 0 0 0 0 0 0 0999 V2000
1.7230 -2.0676 -0.3651 H 0 0 0 0 0 0 0 0 0 0 0 0
2.2381 -1.1229 -0.1980 C 0 0 0 0 0 0 0 0 0 0 0 0
3.7745 -1.1237 -0.1994 C 0 0 0 0 0 0 0 0 0 0 0 0
4.3503 -1.5079 0.8566 O 0 0 0 0 0 0 0 0 0 0 0 0
4.2876 -0.7289 -1.2880 O 0 0 0 0 0 1 0 0 0 0 0 0
1.5363 -0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0513 0.9451 0.1655 H 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 0.0000 -0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.5139 0.0000 1.1576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.5752 -0.0004 -1.1240 O 0 0 0 0 0 1 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 2 0
6 7 1 0
6 8 1 0
8 9 2 0
8 10 1 0
M CHG 2 5 -1 10 -1
M END
$$$$
Loading

0 comments on commit b83599e

Please sign in to comment.