File size: 4,567 Bytes
504d922 | 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | from __future__ import annotations
import json
import sys
import importlib.util
from pathlib import Path
from typing import Any
ROOT_DIR = Path(__file__).resolve().parents[1]
if str(ROOT_DIR) not in sys.path:
sys.path.insert(0, str(ROOT_DIR))
from libs.utils.logging_utils import get_logger
def _load_large_library_builder():
mod_path = ROOT_DIR / "libs/benchmark/large_library.py"
spec = importlib.util.spec_from_file_location("large_library_runtime", mod_path)
if spec is None or spec.loader is None:
raise RuntimeError(f"Cannot load module spec from {mod_path}")
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod.build_large_benchmark_library
def _cfg(
*,
output_dir: str,
docking_target_path: str,
reference_id: str,
pdb_id: str,
ligand_comp_id: str,
reference_smiles: str,
chembl_target_id: str,
shuffle_seed: int,
) -> dict[str, Any]:
return {
"benchmark_dataset": {
"output_dir": output_dir,
"target_size": 1000,
"min_similarity_keep": 0.30,
"pubchem_max_records": 12000,
"pubchem_thresholds": [95, 90, 85, 80, 75, 70, 65],
"chembl_target_id": chembl_target_id,
"chembl_max_rows": 12000,
"allow_generated_fallback": True,
"reuse_existing": False,
"shuffle_seed": int(shuffle_seed),
"reference_smiles": reference_smiles,
},
"target": {
"docking_target_path": docking_target_path,
},
"reference": {
"reference_id": reference_id,
"pdb_id": pdb_id,
"ligand_comp_id": ligand_comp_id,
"reference_smiles": reference_smiles,
},
}
def prepare_three_new_sets() -> dict[str, Any]:
logger = get_logger("prepare_three_new_sets")
build_large_benchmark_library = _load_large_library_builder()
specs = [
_cfg(
output_dir="data/ligands/prelim_set_egfr_4wkq",
docking_target_path="data/targets/prelim_set_egfr_4wkq/egfr_4wkq.pdb",
reference_id="ref_gefitinib_prelim",
pdb_id="4WKQ",
ligand_comp_id="IRE",
reference_smiles="COc1cc2ncnc(Nc3ccc(F)c(Cl)c3)c2cc1OCCCN1CCOCC1",
chembl_target_id="CHEMBL203",
shuffle_seed=20260423,
),
_cfg(
output_dir="data/ligands/prelim_set_abl1_1iep",
docking_target_path="data/targets/prelim_set_abl1_1iep/abl1_1iep.pdb",
reference_id="ref_imatinib_prelim",
pdb_id="1IEP",
ligand_comp_id="STI",
reference_smiles="Cc1ccc(NC(=O)c2ccc(CN3CCN(C)CC3)cc2)cc1Nc1nccc(-c2cccnc2)n1",
chembl_target_id="CHEMBL1862",
shuffle_seed=20260424,
),
_cfg(
output_dir="data/ligands/prelim_set_mdm2_4hg7",
docking_target_path="data/targets/prelim_set_mdm2_4hg7/mdm2_4hg7.pdb",
reference_id="ref_nutlin3a_prelim",
pdb_id="4HG7",
ligand_comp_id="NUT",
reference_smiles="Cc1nc2ccccc2n1CC(C)(C)c1cc(C(F)(F)F)cc(C(F)(F)F)c1",
chembl_target_id="CHEMBL5023",
shuffle_seed=20260425,
),
]
payload: list[dict[str, Any]] = []
for cfg in specs:
out = build_large_benchmark_library(cfg, ROOT_DIR, logger)
ref = out["reference_df"].iloc[0].to_dict()
payload.append(
{
"ligands_dir": cfg["benchmark_dataset"]["output_dir"],
"target_path": cfg["target"]["docking_target_path"],
"shared_library": str(Path(cfg["benchmark_dataset"]["output_dir"]) / "shared_library_shuffled.csv"),
"reference_csv": str(Path(cfg["benchmark_dataset"]["output_dir"]) / "reference_ligands.csv"),
"reference_id": str(ref["reference_id"]),
"reference_comp_id": str(ref["ligand_comp_id"]),
"library_size": int(out["shuffled_df"].shape[0]),
}
)
logger.info("Prepared %s size=%s", cfg["benchmark_dataset"]["output_dir"], out["shuffled_df"].shape[0])
manifest = {
"run_name": "prepare_three_new_sets",
"datasets": payload,
}
out_manifest = ROOT_DIR / "data/ligands/prelim_three_sets_manifest.json"
out_manifest.write_text(json.dumps(manifest, indent=2), encoding="utf-8")
return manifest
if __name__ == "__main__":
print(json.dumps(prepare_three_new_sets(), indent=2))
|