Download pipeline/run_benchmark.py from QPromaQ/Docking_project: direct link, hf CLI and curl.
- Browser
- Download file 8.1 kB
-
https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/pipeline/run_benchmark.py
- Command line
-
hf download hf://datasets/QPromaQ/Docking_project/pipeline/run_benchmark.py
-
curl -L -o run_benchmark.py https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/pipeline/run_benchmark.py
8.1 kB
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| import tempfile | |
| from pathlib import Path | |
| from typing import Any, Dict, List | |
| import yaml | |
| ROOT_DIR = Path(__file__).resolve().parents[1] | |
| if str(ROOT_DIR) not in sys.path: | |
| sys.path.insert(0, str(ROOT_DIR)) | |
| from libs.benchmark.cleanup import execute_results_cleanup, plan_results_cleanup | |
| from libs.benchmark.runtime import AUTO_MINUS_FOUR | |
| from libs.utils.config import load_config | |
| from pipeline.run_large_benchmark import run_large_benchmark | |
| from pipeline.run_fixed_pocket_repair import run_fixed_pocket_repair | |
| from pipeline.run_policy_repair_benchmark import run_policy_repair_benchmark | |
| from pipeline.run_ppi_sanity_check import run_ppi_sanity_check | |
| SUPPORTED_BENCHMARK_TYPES = { | |
| "small_molecule", | |
| "peptide_like", | |
| "policy_repair", | |
| "fixed_pocket_repair", | |
| } | |
| def _parse_bool(text: str) -> bool: | |
| v = str(text).strip().lower() | |
| if v in {"1", "true", "t", "yes", "y"}: | |
| return True | |
| if v in {"0", "false", "f", "no", "n"}: | |
| return False | |
| raise ValueError(f"Invalid boolean value: {text}") | |
| def _build_large_config(args: argparse.Namespace) -> Dict[str, Any]: | |
| cfg = load_config(args.config_template) | |
| cfg.setdefault("run", {}) | |
| cfg.setdefault("target", {}) | |
| cfg.setdefault("reference", {}) | |
| cfg.setdefault("benchmark_dataset", {}) | |
| cfg.setdefault("backend", {}) | |
| cfg.setdefault("matrix", {}) | |
| if args.output_dir: | |
| cfg["run"]["output_dir"] = args.output_dir | |
| if args.pdb_id: | |
| cfg["target"]["docking_reference_pdb"] = str(args.pdb_id) | |
| cfg["reference"]["pdb_id"] = str(args.pdb_id) | |
| if args.ligand_id: | |
| cfg["reference"]["ligand_comp_id"] = str(args.ligand_id) | |
| if args.reference_id: | |
| cfg["reference"]["reference_id"] = str(args.reference_id) | |
| if args.n_ligands is not None: | |
| cfg["benchmark_dataset"]["target_size"] = int(args.n_ligands) | |
| cfg["run"]["adaptive_budget"] = int(args.n_ligands) | |
| cfg["run"]["baseline_budget"] = int(args.n_ligands) | |
| cfg["run"]["max_batches"] = max(1, int(args.n_ligands) // max(1, int(cfg["run"].get("batch_size", 32))) + 10) | |
| mode_map = { | |
| "docking-only": ["docking_only"], | |
| "full-feature": ["full_feature"], | |
| "both": ["docking_only", "full_feature"], | |
| } | |
| cfg["matrix"]["modes"] = mode_map[args.mode] | |
| strategies = {s.strip().lower() for s in args.strategies} | |
| cfg["matrix"]["include_adaptive"] = "adaptive" in strategies | |
| cfg["matrix"]["include_naive_random"] = "naive" in strategies | |
| cfg["matrix"]["include_cluster_naive"] = "cluster-naive" in strategies | |
| cfg["matrix"]["naive_random_seeds"] = [11 + i * 11 for i in range(max(0, int(args.naive_runs)))] | |
| cfg["matrix"]["cluster_naive_seeds"] = [101 + i * 101 for i in range(max(0, int(args.cluster_runs)))] | |
| if "docking_only" not in cfg["matrix"]["modes"]: | |
| cfg["matrix"]["include_adaptive_top1_variant"] = False | |
| cfg["backend"]["type"] = args.backend | |
| cfg["backend"]["require_real_backend"] = bool(args.require_real_backend) | |
| cfg["backend"]["parallel_jobs"] = args.threads | |
| cfg["backend"]["pocket_mode"] = str(args.pocket_mode) | |
| if args.pocket_center: | |
| cfg["backend"]["pocket_center"] = str(args.pocket_center) | |
| if args.pocket_box_size: | |
| cfg["backend"]["pocket_box_size"] = str(args.pocket_box_size) | |
| if args.pocket_radius is not None: | |
| cfg["backend"]["pocket_radius"] = float(args.pocket_radius) | |
| if args.pocket_reference_ligand_id: | |
| cfg["backend"]["pocket_reference_ligand_id"] = str(args.pocket_reference_ligand_id) | |
| if args.pocket_relaxation_margin is not None: | |
| cfg["backend"]["pocket_relaxation_margin"] = float(args.pocket_relaxation_margin) | |
| cfg["run"]["enable_adaptive_early_stop"] = bool(args.enable_early_stop) | |
| cfg["run"]["allow_resume"] = bool(args.allow_resume) | |
| return cfg | |
| def _validate_runner_args(args: argparse.Namespace) -> None: | |
| btype = str(args.benchmark_type).strip().lower() | |
| if btype not in SUPPORTED_BENCHMARK_TYPES: | |
| raise ValueError(f"Unsupported benchmark_type `{args.benchmark_type}`") | |
| if btype == "peptide_like": | |
| if args.backend != "rdock": | |
| raise ValueError("peptide_like mode does not accept --backend overrides; use default architecture-level proxy path") | |
| if args.mode != "full-feature": | |
| raise ValueError("peptide_like mode does not use docking mode matrix; keep --mode full-feature") | |
| if args.strategies != ["adaptive", "naive", "cluster-naive"]: | |
| raise ValueError("peptide_like mode does not use small-molecule strategy matrix arguments") | |
| def main() -> int: | |
| parser = argparse.ArgumentParser(description="Unified production benchmark runner") | |
| parser.add_argument("--benchmark-type", default="small_molecule", choices=sorted(SUPPORTED_BENCHMARK_TYPES)) | |
| parser.add_argument("--config-template", default="configs/large_benchmark.yaml") | |
| parser.add_argument("--pdb-id", default="") | |
| parser.add_argument("--ligand-id", default="") | |
| parser.add_argument("--reference-id", default="") | |
| parser.add_argument("--n-ligands", type=int, default=None) | |
| parser.add_argument("--strategies", nargs="+", default=["adaptive", "naive", "cluster-naive"]) | |
| parser.add_argument("--naive-runs", type=int, default=5) | |
| parser.add_argument("--cluster-runs", type=int, default=5) | |
| parser.add_argument("--mode", choices=["docking-only", "full-feature", "both"], default="full-feature") | |
| parser.add_argument("--backend", choices=["rdock"], default="rdock") | |
| parser.add_argument( | |
| "--pocket-mode", | |
| choices=["user_fixed_pocket", "reference_complex_pocket", "reference_complex_pocket_relaxed"], | |
| default="reference_complex_pocket", | |
| ) | |
| parser.add_argument("--pocket-center", default="") | |
| parser.add_argument("--pocket-box-size", default="") | |
| parser.add_argument("--pocket-radius", type=float, default=None) | |
| parser.add_argument("--pocket-reference-ligand-id", default="") | |
| parser.add_argument("--pocket-relaxation-margin", type=float, default=0.0) | |
| parser.add_argument("--require-real-backend", type=_parse_bool, default=True) | |
| parser.add_argument("--threads", default=AUTO_MINUS_FOUR) | |
| parser.add_argument("--enable-early-stop", type=_parse_bool, default=True) | |
| parser.add_argument("--allow-resume", type=_parse_bool, default=True) | |
| parser.add_argument("--output-dir", default="") | |
| parser.add_argument("--ppi-config", default="configs/ppi_sanity_check.yaml") | |
| parser.add_argument("--cleanup-legacy-results", type=_parse_bool, default=False) | |
| parser.add_argument("--policy-repair-config", default="configs/policy_repair_benchmark.yaml") | |
| args = parser.parse_args() | |
| _validate_runner_args(args) | |
| outputs: Dict[str, Any] = {} | |
| if args.cleanup_legacy_results: | |
| plan = plan_results_cleanup(ROOT_DIR / "results") | |
| archive_dir = execute_results_cleanup(ROOT_DIR / "results", plan) | |
| outputs["cleanup"] = { | |
| "items": [str(x.path) for x in plan], | |
| "archive_dir": str(archive_dir), | |
| } | |
| if args.benchmark_type == "small_molecule": | |
| large_cfg = _build_large_config(args) | |
| with tempfile.TemporaryDirectory() as tmp: | |
| cfg_path = Path(tmp) / "run_benchmark.generated.yaml" | |
| cfg_path.write_text(yaml.safe_dump(large_cfg, sort_keys=False), encoding="utf-8") | |
| outputs["small_molecule"] = run_large_benchmark(cfg_path) | |
| elif args.benchmark_type == "policy_repair": | |
| outputs["policy_repair"] = run_policy_repair_benchmark(args.policy_repair_config) | |
| elif args.benchmark_type == "fixed_pocket_repair": | |
| outputs["fixed_pocket_repair"] = run_fixed_pocket_repair() | |
| elif args.benchmark_type == "peptide_like": | |
| outputs["ppi_sanity"] = run_ppi_sanity_check(args.ppi_config) | |
| else: | |
| raise NotImplementedError("Unreachable benchmark type state") | |
| print(json.dumps(outputs, indent=2)) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |