dualmapref 0.2.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. args_parse.py +593 -0
  2. candidate_corrector.py +161 -0
  3. candidate_scorer.py +359 -0
  4. conformend/__init__.py +36 -0
  5. conformend/refiner.py +25 -0
  6. dataset/__init__.py +1 -0
  7. dataset/drugdataset.py +644 -0
  8. dataset/manifold.py +237 -0
  9. dataset/sharded_drugdataset.py +124 -0
  10. dataset/smiles2graph.py +217 -0
  11. dualmapref/__init__.py +24 -0
  12. dualmapref/refiner.py +16 -0
  13. dualmapref-0.2.8.dist-info/LICENSE +21 -0
  14. dualmapref-0.2.8.dist-info/METADATA +167 -0
  15. dualmapref-0.2.8.dist-info/RECORD +186 -0
  16. dualmapref-0.2.8.dist-info/WHEEL +5 -0
  17. dualmapref-0.2.8.dist-info/entry_points.txt +10 -0
  18. dualmapref-0.2.8.dist-info/top_level.txt +29 -0
  19. exputils.py +289 -0
  20. infer.py +23 -0
  21. infer_base_conformers.py +5589 -0
  22. infer_mean_dispersion_torsion.py +1117 -0
  23. infer_torsion.py +752 -0
  24. infer_torsional_denoiser.py +1021 -0
  25. manimol/__init__.py +30 -0
  26. manimol/__main__.py +6 -0
  27. manimol/cli.py +36 -0
  28. manimol/full_cli.py +41 -0
  29. manimol/legacy_imports.py +43 -0
  30. manimol/manifest.py +56 -0
  31. manimol/postprocess.py +148 -0
  32. manimol/priors.py +60 -0
  33. manimol/protocols.py +119 -0
  34. manimol/refiner.py +645 -0
  35. manimol/runtime.py +194 -0
  36. manimol/selection.py +85 -0
  37. manimol/torsion.py +22 -0
  38. manimol/train_cli.py +14 -0
  39. mixture_flow/src/__init__.py +1 -0
  40. mixture_flow/src/_path.py +7 -0
  41. mixture_flow/src/infer28_mixture_torsion_flow.py +1093 -0
  42. mixture_flow/src/mixture_torsion_flow.py +291 -0
  43. mixture_flow/src/summarize_mixture_debug.py +80 -0
  44. mixture_flow/src/train28_mixture_torsion_flow.py +583 -0
  45. mixture_torsion_flow.py +7 -0
  46. models/ manifold_learning.py +86 -0
  47. models/__init__.py +8 -0
  48. models/dist.py +273 -0
  49. models/dist2coords.py +23 -0
  50. models/egnn.py +107 -0
  51. models/experimental_backbones.py +364 -0
  52. models/gnnconv.py +512 -0
  53. models/kernel_inversion.py +141 -0
  54. models/kernels.py +427 -0
  55. models/losses.py +154 -0
  56. models/mean_dispersion_bridge.py +119 -0
  57. models/mean_dispersion_torsion_context.py +155 -0
  58. models/model.py +73 -0
  59. models/model0.py +2375 -0
  60. models/vis.py +128 -0
  61. pgraph_controls.py +107 -0
  62. scripts/__init__.py +2 -0
  63. scripts/analyze_basin_alignment.py +63 -0
  64. scripts/analyze_hif2a_conformer_aggregation.py +267 -0
  65. scripts/analyze_hif2a_contact_pharmacophore.py +1111 -0
  66. scripts/analyze_hif2a_fixed_budget.py +202 -0
  67. scripts/analyze_hif2a_pharmacophore.py +405 -0
  68. scripts/analyze_hif2a_pharmacophore_match_metric.py +386 -0
  69. scripts/analyze_p_control_candidate_flow.py +154 -0
  70. scripts/analyze_scaffold_basin.py +83 -0
  71. scripts/audit_dispersion_proposals.py +208 -0
  72. scripts/audit_etflow_protocol.py +258 -0
  73. scripts/audit_external_overlap.py +150 -0
  74. scripts/audit_oldbest_fulltrainval_split.py +82 -0
  75. scripts/audit_pdbbind_contact_pharmacophores.py +146 -0
  76. scripts/audit_qm9_geomol_test_split.py +94 -0
  77. scripts/audit_stage1_stage2_cross.py +131 -0
  78. scripts/build_geom_drugs_lowref_diagnostic.py +84 -0
  79. scripts/build_qm9_backfill_manifest.py +99 -0
  80. scripts/check_etflow_runtime.py +56 -0
  81. scripts/compare_prior_sources.py +122 -0
  82. scripts/compose_binding_mode_figure.py +87 -0
  83. scripts/compose_hif2a_contact_pharmacophore_suppfig.py +255 -0
  84. scripts/compose_hif2a_functional_geometry_pipeline.py +266 -0
  85. scripts/compose_manimol_internal_architecture.py +291 -0
  86. scripts/diagnose_flow_basin_intervention.py +54 -0
  87. scripts/diagnose_hif2a_pharmacophore_budget.py +185 -0
  88. scripts/diagnose_route2_p_ranking.py +123 -0
  89. scripts/discover_binding_mode_inputs.py +30 -0
  90. scripts/evaluate_functional_prior_stage1.py +230 -0
  91. scripts/evaluate_geomanimol.py +74 -0
  92. scripts/evaluate_geomanimol_flow.py +23 -0
  93. scripts/evaluate_geomanimol_multiscaffold.py +46 -0
  94. scripts/evaluate_geomanimol_residual.py +45 -0
  95. scripts/evaluate_geomanimol_torsion.py +40 -0
  96. scripts/evaluate_hif2a_bioactive_enrichment.py +91 -0
  97. scripts/evaluate_hif2a_pms_suite.py +440 -0
  98. scripts/evaluate_pdbbind_contact_pms.py +155 -0
  99. scripts/evaluate_platinum_external.py +114 -0
  100. scripts/evaluate_platinum_pool.py +82 -0
  101. scripts/evaluate_route2_calibrated_p.py +104 -0
  102. scripts/evaluate_route2_library_components.py +596 -0
  103. scripts/evaluate_route2_p_basin_budget.py +288 -0
  104. scripts/evaluate_stage1_checkpoint_only.py +30 -0
  105. scripts/export_dispersion_bond_audit.py +136 -0
  106. scripts/export_top20_shards.py +207 -0
  107. scripts/external_validation_metrics.py +152 -0
  108. scripts/fit_topology_prior.py +117 -0
  109. scripts/frozen_dispersion_audit.py +281 -0
  110. scripts/geomanimol_debug.py +50 -0
  111. scripts/geomanimol_smoke.py +37 -0
  112. scripts/infer_etflow_matched.py +524 -0
  113. scripts/inspect_checkpoint.py +12 -0
  114. scripts/inspect_conformer_capacity.py +71 -0
  115. scripts/inspect_pool.py +12 -0
  116. scripts/make_figure3_selection_loss.py +474 -0
  117. scripts/make_figure3_selection_summary.py +275 -0
  118. scripts/make_geom_debug_subset.py +62 -0
  119. scripts/make_low_reference_test_subset.py +70 -0
  120. scripts/merge_stage1_into_stage2.py +82 -0
  121. scripts/place_hif2a_candidates_for_evaluation.py +66 -0
  122. scripts/plot_hif2a_low_budget_efficiency.py +100 -0
  123. scripts/plot_prior_validation.py +48 -0
  124. scripts/precompute_stage2_assignments.py +90 -0
  125. scripts/prepare_bace_activity.py +98 -0
  126. scripts/prepare_bace_etkdg_benchmark.py +90 -0
  127. scripts/prepare_figure5_4x4_cases.py +470 -0
  128. scripts/prepare_geom_drugs_geomol_top20.py +472 -0
  129. scripts/prepare_pdbbind_core_raw.py +90 -0
  130. scripts/prepare_platinum_raw.py +74 -0
  131. scripts/prepare_pubchem_etkdg.py +54 -0
  132. scripts/rebuild_hif2a_final_sdf_and_metrics.py +55 -0
  133. scripts/rebuild_hif2a_fixed_pool_sweep.py +175 -0
  134. scripts/rebuild_hif2a_strict.py +220 -0
  135. scripts/recompute_hif2a_bootstrap.py +63 -0
  136. scripts/reference_free_geometry.py +112 -0
  137. scripts/render_binding_modes.py +413 -0
  138. scripts/render_figure5_4x4.py +330 -0
  139. scripts/render_figure6_pharmacophore_pymol.py +162 -0
  140. scripts/render_hif2a_contact_pharmacophore_pymol.py +414 -0
  141. scripts/render_hif2a_figure11.py +397 -0
  142. scripts/run_bace_2d_baseline.py +73 -0
  143. scripts/run_drugs_validation_matrix.py +225 -0
  144. scripts/run_external_reference_free.py +53 -0
  145. scripts/run_manimol_finalk_sensitivity.py +106 -0
  146. scripts/run_manimol_oversampling_sensitivity.py +109 -0
  147. scripts/run_pdisp_matched_intervention.py +116 -0
  148. scripts/run_stage1_stage2_cross20.py +83 -0
  149. scripts/score_hif2a_candidates_with_pgraph.py +221 -0
  150. scripts/summarize_dispersion_intervention.py +88 -0
  151. scripts/test_mean_dispersion_bridge.py +50 -0
  152. scripts/train_dispersion_head_diagnostic.py +320 -0
  153. scripts/train_dispersion_head_streaming.py +519 -0
  154. scripts/train_geomanimol.py +100 -0
  155. scripts/train_geomanimol_flow.py +26 -0
  156. scripts/train_geomanimol_residual.py +70 -0
  157. scripts/train_geomanimol_torsion.py +50 -0
  158. scripts/train_quantile_representation_diagnostic.py +204 -0
  159. scripts/validate_mean_dispersion_prior.py +173 -0
  160. scripts/validate_packed_shard.py +41 -0
  161. scripts/validate_stage1_prior.py +221 -0
  162. scripts/validate_top20_shards.py +36 -0
  163. scripts/validation/__init__.py +1 -0
  164. scripts/validation/hif2a_downstream_baselines.py +105 -0
  165. scripts/validation/hif2a_pairwise_ranker.py +218 -0
  166. scripts/verify_binding_mode_figure.py +47 -0
  167. torsion_manifold.py +281 -0
  168. train.py +78 -0
  169. train_graph_encoder.py +206 -0
  170. train_local_torsion_corrector.py +511 -0
  171. train_mean_dispersion_torsion_prior.py +329 -0
  172. train_probability_basin.py +235 -0
  173. train_torsion_generator.py +1631 -0
  174. train_torsion_manifold_prior.py +258 -0
  175. train_torsional_denoiser.py +415 -0
  176. trainer.py +1038 -0
  177. utils/__init__.py +7 -0
  178. utils/checkpoint.py +40 -0
  179. utils/device.py +17 -0
  180. utils/helpers.py +98 -0
  181. utils/kabsch.py +29 -0
  182. utils/lookup_table.py +164 -0
  183. utils/metrics.py +50 -0
  184. utils/optuna.py +111 -0
  185. utils/save_mol.py +366 -0
  186. utils/util.py +36 -0
@@ -0,0 +1,225 @@
1
+ #!/usr/bin/env python3
2
+ """Run the locked three-way GEOM-Drugs generator validation matrix.
3
+
4
+ This is an orchestration layer only. It leaves legacy inference code intact
5
+ and changes one generation component at a time under a shared evaluation
6
+ protocol.
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import json
12
+ import shlex
13
+ import subprocess
14
+ from dataclasses import asdict, dataclass
15
+ from datetime import datetime, timezone
16
+ from pathlib import Path
17
+
18
+
19
+ VARIANTS = ("stage2_only", "denoiser_fixed", "denoiser_dispersion")
20
+
21
+
22
+ @dataclass(frozen=True)
23
+ class MatrixConfig:
24
+ python: str
25
+ data_root: Path
26
+ base_checkpoint: Path
27
+ stage2_checkpoint: Path
28
+ stage2_base_checkpoint: Path | None
29
+ denoiser_checkpoint: Path
30
+ output_dir: Path
31
+ max_molecules: int = 50
32
+ seed: int = 20260913
33
+ test_raw_filename: str = "geom_drugs_geomol_top20_test1000.pt"
34
+ max_confs: int = 0
35
+ sample_multiplier: float = 2.0
36
+ oversample_factor: int = 15
37
+ denoise_steps: int = 10
38
+ device: str = "cpu"
39
+
40
+
41
+ def _output_args(config: MatrixConfig, variant: str) -> list[str]:
42
+ prefix = config.output_dir / variant
43
+ return [
44
+ "--method_name", f"MANIMOL-{variant}",
45
+ "--save_per_molecule_csv",
46
+ "--per_molecule_csv", str(prefix.with_name(prefix.name + "_per_molecule.csv")),
47
+ "--revisited_metrics_csv", str(prefix.with_name(prefix.name + "_chemistry.csv")),
48
+ "--threshold_curve_csv", str(prefix.with_name(prefix.name + "_curve.csv")),
49
+ "--save_raw_pool_pt", str(prefix.with_name(prefix.name + "_raw_pool.pt")),
50
+ ]
51
+
52
+
53
+ def build_variant_command(config: MatrixConfig, variant: str) -> list[str]:
54
+ if variant not in VARIANTS:
55
+ raise ValueError(f"Unknown variant {variant!r}; choose from {VARIANTS}")
56
+
57
+ denoiser = "" if variant == "stage2_only" else str(config.denoiser_checkpoint)
58
+ base_checkpoint = (
59
+ config.stage2_base_checkpoint or config.stage2_checkpoint
60
+ if variant == "stage2_only"
61
+ else config.base_checkpoint
62
+ )
63
+ command = [
64
+ config.python, "-u", "infer_mean_dispersion_torsion.py",
65
+ "--base_checkpoint", str(base_checkpoint),
66
+ "--denoiser_checkpoint", denoiser,
67
+ "--checkpoint", str(base_checkpoint),
68
+ "--data_root", str(config.data_root),
69
+ "--dataset", "Drugs",
70
+ "--raw_prefix", "geom_drugs_geomol_top20",
71
+ "--train_raw_filename", "geom_drugs_geomol_top20_debug_train.pt",
72
+ "--val_raw_filename", "geom_drugs_geomol_top20_debug_val.pt",
73
+ "--test_raw_filename", config.test_raw_filename,
74
+ "--split", "test",
75
+ "--inference_only_data",
76
+ "--test_process_limit", str(config.max_molecules),
77
+ "--device", config.device,
78
+ "--max_confs", str(config.max_confs),
79
+ "--cov_thresholds", "0.5,0.75,1.0,1.5,2.0",
80
+ "--sample_multiplier", str(config.sample_multiplier),
81
+ "--max_output_confs", "0",
82
+ "--num_modes", "10",
83
+ "--deterministic_modes",
84
+ "--denoise_steps", str(config.denoise_steps),
85
+ "--denoise_sigma_max", "0.75",
86
+ "--denoise_sigma_min", "0.05",
87
+ "--denoise_step_scale", "1.0",
88
+ "--denoise_initial_noise", "0.75",
89
+ "--torsion_mode_max", "64",
90
+ "--torsion_base_method", "etkdg",
91
+ "--no_etkdg_candidate_pool",
92
+ "--oversample_factor", str(config.oversample_factor),
93
+ "--select_candidates", "precision2r",
94
+ "--precision2r_density_k", "20",
95
+ "--precision2r_prefilter_quantile", "0.45",
96
+ "--precision2r_density_weight", "1.0",
97
+ "--precision2r_centrality_weight", "0.45",
98
+ "--precision2r_duplicate_radius", "0.04",
99
+ "--output_dedup_radius", "0.04",
100
+ "--precision_refine_steps", "0",
101
+ "--metric_recall_pool", "final",
102
+ "--rmsd_backend", "rdkit_best",
103
+ "--rdkit_rmsd_max_matches", "1000000",
104
+ "--no_egnn_refine",
105
+ "--no_mmff",
106
+ "--no_torsion_refine",
107
+ "--limit_molecules", str(config.max_molecules),
108
+ "--inference_seed", str(config.seed),
109
+ ]
110
+
111
+ if variant == "stage2_only":
112
+ command += [
113
+ "--pbasin_checkpoint", str(config.stage2_checkpoint),
114
+ "--pbasin_fraction", "1.0",
115
+ "--pbasin_only",
116
+ "--pbasin_iterative_torsion_steps", "3",
117
+ "--pbasin_iterative_torsion_delta_scale", "0.8",
118
+ ]
119
+ if variant == "denoiser_dispersion":
120
+ command.append("--use_dispersion_proposal")
121
+
122
+ command += _output_args(config, variant)
123
+ return command
124
+
125
+
126
+ def _validate_inputs(config: MatrixConfig, variants: list[str]) -> None:
127
+ required = [config.data_root, config.base_checkpoint]
128
+ if "stage2_only" in variants:
129
+ required.extend([config.stage2_checkpoint, config.stage2_base_checkpoint or config.stage2_checkpoint])
130
+ if any(name != "stage2_only" for name in variants):
131
+ required.append(config.denoiser_checkpoint)
132
+ missing = [str(path) for path in required if not path.exists()]
133
+ raw_test = config.data_root / config.test_raw_filename
134
+ if not raw_test.exists():
135
+ missing.append(str(raw_test))
136
+ if missing:
137
+ raise FileNotFoundError("Missing validation inputs:\n " + "\n ".join(missing))
138
+
139
+
140
+ def run_logged(command: list[str], log_path: Path) -> None:
141
+ """Run a command while mirroring merged output to terminal and a log."""
142
+ with log_path.open("w") as log:
143
+ process = subprocess.Popen(
144
+ command,
145
+ stdout=subprocess.PIPE,
146
+ stderr=subprocess.STDOUT,
147
+ text=True,
148
+ bufsize=1,
149
+ )
150
+ assert process.stdout is not None
151
+ for line in process.stdout:
152
+ print(line, end="", flush=True)
153
+ log.write(line)
154
+ log.flush()
155
+ process.stdout.close()
156
+ return_code = process.wait()
157
+ if return_code:
158
+ raise subprocess.CalledProcessError(return_code, command)
159
+
160
+
161
+ def main() -> None:
162
+ parser = argparse.ArgumentParser(description=__doc__)
163
+ parser.add_argument("--python", default="/opt/anaconda3/envs/deeplearning/bin/python")
164
+ parser.add_argument("--data-root", type=Path, default=Path("data/geom_drugs_geomol_top20"))
165
+ parser.add_argument("--base-checkpoint", type=Path, required=True)
166
+ parser.add_argument("--stage2-checkpoint", type=Path, required=True)
167
+ parser.add_argument(
168
+ "--stage2-base-checkpoint",
169
+ type=Path,
170
+ default=None,
171
+ help="Base used only by stage2_only; defaults to --stage2-checkpoint.",
172
+ )
173
+ parser.add_argument("--denoiser-checkpoint", type=Path, required=True)
174
+ parser.add_argument("--output-dir", type=Path, default=Path("results/drugs_validation_matrix"))
175
+ parser.add_argument("--max-molecules", type=int, default=50)
176
+ parser.add_argument("--seed", type=int, default=20260913)
177
+ parser.add_argument("--max-confs", type=int, default=0, help="0 resolves capacity from each base checkpoint.")
178
+ parser.add_argument("--oversample-factor", type=int, default=15)
179
+ parser.add_argument("--denoise-steps", type=int, default=10)
180
+ parser.add_argument("--device", default="cpu")
181
+ parser.add_argument("--variants", nargs="+", choices=VARIANTS, default=list(VARIANTS))
182
+ parser.add_argument("--dry-run", action="store_true")
183
+ args = parser.parse_args()
184
+
185
+ config = MatrixConfig(
186
+ python=args.python,
187
+ data_root=args.data_root,
188
+ base_checkpoint=args.base_checkpoint,
189
+ stage2_checkpoint=args.stage2_checkpoint,
190
+ stage2_base_checkpoint=args.stage2_base_checkpoint,
191
+ denoiser_checkpoint=args.denoiser_checkpoint,
192
+ output_dir=args.output_dir,
193
+ max_molecules=args.max_molecules,
194
+ seed=args.seed,
195
+ max_confs=args.max_confs,
196
+ oversample_factor=args.oversample_factor,
197
+ denoise_steps=args.denoise_steps,
198
+ device=args.device,
199
+ )
200
+ variants = list(args.variants)
201
+ _validate_inputs(config, variants)
202
+ config.output_dir.mkdir(parents=True, exist_ok=True)
203
+ commands = {name: build_variant_command(config, name) for name in variants}
204
+ manifest = {
205
+ "created_utc": datetime.now(timezone.utc).isoformat(),
206
+ "purpose": "locked three-way GEOM-Drugs validation",
207
+ "config": {key: str(value) if isinstance(value, Path) else value for key, value in asdict(config).items()},
208
+ "variants": variants,
209
+ "strict_shared_base_checkpoint": (
210
+ str(config.stage2_base_checkpoint or config.stage2_checkpoint) == str(config.base_checkpoint)
211
+ ),
212
+ "commands": commands,
213
+ }
214
+ (config.output_dir / "protocol_manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
215
+
216
+ for name, command in commands.items():
217
+ print(f"\n===== {name} =====", flush=True)
218
+ print(shlex.join(command), flush=True)
219
+ if not args.dry_run:
220
+ log_path = config.output_dir / f"{name}.log"
221
+ run_logged(command, log_path)
222
+
223
+
224
+ if __name__ == "__main__":
225
+ main()
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env python3
2
+ """Run the existing MANIMOL CLI with reference-free geometry preparation.
3
+
4
+ This launcher intentionally leaves ``infer_base_conformers.py`` unchanged. It replaces only
5
+ the two preparation helpers that otherwise retain a conformer stored on the
6
+ RDKit template molecule. The crystallographic conformer remains available to
7
+ the evaluator but cannot be returned by MMFF or torsion preparation.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import sys
13
+ from datetime import datetime, timezone
14
+ from pathlib import Path
15
+
16
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
17
+
18
+ import infer_base_conformers
19
+
20
+ from scripts.reference_free_geometry import patch_inference_geometry
21
+
22
+
23
+ def _write_provenance():
24
+ for index, value in enumerate(sys.argv[1:]):
25
+ if value == "--save_raw_pool_pt" and index + 2 < len(sys.argv):
26
+ pool_path = Path(sys.argv[index + 2])
27
+ audit_path = pool_path.with_name(pool_path.stem + "_provenance.json")
28
+ audit_path.parent.mkdir(parents=True, exist_ok=True)
29
+ audit_path.write_text(
30
+ json.dumps(
31
+ {
32
+ "created_utc": datetime.now(timezone.utc).isoformat(),
33
+ "launcher": "scripts/run_external_reference_free.py",
34
+ "template_conformers_removed_before_preparation": True,
35
+ "preparation_ignores_template_conformers": True,
36
+ "generation_input_audit_required": True,
37
+ "argv": sys.argv[1:],
38
+ },
39
+ indent=2,
40
+ )
41
+ + "\n"
42
+ )
43
+ return
44
+
45
+
46
+ def main():
47
+ patch_inference_geometry(infer_base_conformers)
48
+ _write_provenance()
49
+ infer_base_conformers.main()
50
+
51
+
52
+ if __name__ == "__main__":
53
+ main()
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env python3
2
+ """Run MANIMOL final-output-budget sensitivity from an existing YAML task.
3
+
4
+ The script intentionally reuses the paper protocol task and only changes the
5
+ final output cap, optional GFN2-xTB relaxation cap, and output file names.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import shlex
12
+ import subprocess
13
+ import sys
14
+ from copy import deepcopy
15
+ from pathlib import Path
16
+
17
+ import yaml
18
+
19
+ ROOT = Path(__file__).resolve().parents[1]
20
+ if str(ROOT) not in sys.path:
21
+ sys.path.insert(0, str(ROOT))
22
+
23
+ import run_from_yaml
24
+
25
+
26
+ def parse_args():
27
+ parser = argparse.ArgumentParser(description="Run final-K sensitivity for MANIMOL.")
28
+ parser.add_argument("--config", default="configs/drugs_torsion_limit.yaml")
29
+ parser.add_argument(
30
+ "--base_task",
31
+ default="infer_manimol_component_probability_xtb_os30_limit_curve",
32
+ help="Existing run_from_yaml task to clone.",
33
+ )
34
+ parser.add_argument("--ks", default="32,64,128", help="Comma-separated final output caps.")
35
+ parser.add_argument("--no_xtb", action="store_true", help="Use the non-xTB matched task instead.")
36
+ parser.add_argument("--python", default=None, help="Python executable for the cloned commands.")
37
+ parser.add_argument("--dry_run", action="store_true")
38
+ args, _ = parser.parse_known_args()
39
+ return args
40
+
41
+
42
+ def parse_ks(text: str) -> list[int]:
43
+ out = []
44
+ for item in text.split(","):
45
+ item = item.strip()
46
+ if item:
47
+ out.append(int(item))
48
+ if not out:
49
+ raise ValueError("--ks must contain at least one integer")
50
+ return out
51
+
52
+
53
+ def make_task(config: dict, base_task: str, k: int, use_xtb: bool) -> dict:
54
+ tasks = config["tasks"]
55
+ if base_task not in tasks:
56
+ raise KeyError(f"Unknown base_task={base_task}")
57
+ task = deepcopy(tasks[base_task])
58
+ args = task.setdefault("args", {})
59
+
60
+ tag = f"manimol_finalk{k}_os30"
61
+ if use_xtb:
62
+ tag += "_xtb"
63
+ tag += "_limit"
64
+
65
+ args["max_output_confs"] = k
66
+ args["method_name"] = f"MANIMOL final-K sensitivity K={k}" + (" with GFN2-xTB" if use_xtb else "")
67
+ args["per_molecule_csv"] = f"outputs/visualization/{tag}_per_molecule.csv"
68
+ args["revisited_metrics_csv"] = f"outputs/visualization/{tag}_chemistry_metrics.csv"
69
+ args["threshold_curve_csv"] = f"outputs/visualization/{tag}_curve.csv"
70
+
71
+ if use_xtb:
72
+ args["xtb_relax"] = True
73
+ args["xtb_command"] = args.get("xtb_command", "xtb")
74
+ args["xtb_max_confs"] = k
75
+ else:
76
+ args.pop("xtb_relax", None)
77
+ args.pop("xtb_command", None)
78
+ args.pop("xtb_max_confs", None)
79
+
80
+ return task
81
+
82
+
83
+ def main():
84
+ args = parse_args()
85
+ config_path = Path(args.config)
86
+ with config_path.open("r", encoding="utf-8") as f:
87
+ config = yaml.safe_load(f)
88
+
89
+ use_xtb = not args.no_xtb
90
+ base_task = args.base_task
91
+ if args.no_xtb and base_task == "infer_manimol_component_probability_xtb_os30_limit_curve":
92
+ base_task = "infer_manimol_component_probability_os30_limit_curve"
93
+
94
+ for k in parse_ks(args.ks):
95
+ run_config = deepcopy(config)
96
+ task_name = f"__finalk_{k}"
97
+ run_config["tasks"][task_name] = make_task(config, base_task, k, use_xtb)
98
+ cmd = run_from_yaml.build_command(run_config, task_name, python_override=args.python)
99
+ print("Command:")
100
+ print(" ".join(shlex.quote(part) for part in cmd))
101
+ if not args.dry_run:
102
+ subprocess.run(cmd, cwd=Path.cwd(), check=True)
103
+
104
+
105
+ if __name__ == "__main__":
106
+ main()
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env python3
2
+ """Run MANIMOL oversampling-factor sensitivity from an existing YAML task.
3
+
4
+ The script clones a paper-protocol inference task and changes only
5
+ `oversample_factor` plus output file names. This keeps checkpoint, selector,
6
+ GFN2-xTB, final cap, and all other inference choices fixed.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import argparse
12
+ import shlex
13
+ import subprocess
14
+ import sys
15
+ from copy import deepcopy
16
+ from pathlib import Path
17
+
18
+ import yaml
19
+
20
+ ROOT = Path(__file__).resolve().parents[1]
21
+ if str(ROOT) not in sys.path:
22
+ sys.path.insert(0, str(ROOT))
23
+
24
+ import run_from_yaml
25
+
26
+
27
+ def parse_args():
28
+ parser = argparse.ArgumentParser(description=__doc__)
29
+ parser.add_argument("--config", default="configs/manimol.yaml")
30
+ parser.add_argument("--base_task", default="infer_drugs_best_xtb")
31
+ parser.add_argument("--oversampling", default="10,20,30", help="Comma-separated oversample factors.")
32
+ parser.add_argument(
33
+ "--limit_molecules",
34
+ type=int,
35
+ default=0,
36
+ help="Optional test-subset limit propagated to each cloned inference task; 0 keeps the base task setting.",
37
+ )
38
+ parser.add_argument("--python", default=None)
39
+ parser.add_argument("--dry_run", action="store_true")
40
+ args, _ = parser.parse_known_args()
41
+ return args
42
+
43
+
44
+ def parse_factors(text: str) -> list[float]:
45
+ out = []
46
+ for item in str(text).split(","):
47
+ item = item.strip()
48
+ if item:
49
+ value = float(item)
50
+ out.append(int(value) if value.is_integer() else value)
51
+ if not out:
52
+ raise ValueError("--oversampling must contain at least one value")
53
+ return out
54
+
55
+
56
+ def tag_value(value: float | int) -> str:
57
+ text = f"{value:g}" if isinstance(value, float) else str(value)
58
+ return text.replace(".", "p")
59
+
60
+
61
+ def make_task(
62
+ config: dict,
63
+ base_task: str,
64
+ oversample_factor: float | int,
65
+ limit_molecules: int = 0,
66
+ ) -> dict:
67
+ tasks = config["tasks"]
68
+ if base_task not in tasks:
69
+ raise KeyError(f"Unknown base_task={base_task}")
70
+ task = deepcopy(tasks[base_task])
71
+ args = task.setdefault("args", {})
72
+
73
+ tag = f"manimol_drugs_oversampling_os{tag_value(oversample_factor)}_xtb"
74
+ if int(limit_molecules) > 0:
75
+ tag += f"_limit{int(limit_molecules)}"
76
+ args["oversample_factor"] = oversample_factor
77
+ if int(limit_molecules) > 0:
78
+ args["limit_molecules"] = int(limit_molecules)
79
+ args["method_name"] = f"MANIMOL oversampling x{oversample_factor:g} with GFN2-xTB"
80
+ args["per_molecule_csv"] = f"outputs/visualization/{tag}_per_molecule.csv"
81
+ args["revisited_metrics_csv"] = f"outputs/visualization/{tag}_chemistry_metrics.csv"
82
+ args["threshold_curve_csv"] = f"outputs/visualization/{tag}_curve.csv"
83
+ return task
84
+
85
+
86
+ def main():
87
+ args = parse_args()
88
+ config_path = Path(args.config)
89
+ with config_path.open("r", encoding="utf-8") as f:
90
+ config = yaml.safe_load(f)
91
+
92
+ for factor in parse_factors(args.oversampling):
93
+ run_config = deepcopy(config)
94
+ task_name = f"__oversampling_{tag_value(factor)}"
95
+ run_config["tasks"][task_name] = make_task(
96
+ config,
97
+ args.base_task,
98
+ factor,
99
+ limit_molecules=args.limit_molecules,
100
+ )
101
+ cmd = run_from_yaml.build_command(run_config, task_name, python_override=args.python)
102
+ print("Command:")
103
+ print(" ".join(shlex.quote(part) for part in cmd))
104
+ if not args.dry_run:
105
+ subprocess.run(cmd, cwd=Path.cwd(), check=True)
106
+
107
+
108
+ if __name__ == "__main__":
109
+ main()
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env python3
2
+ """Run a matched intervention on the dispersion-to-width pathway.
3
+
4
+ The three arms differ only in the dispersion signal used to form torsion
5
+ proposal widths:
6
+
7
+ * normal: the learned pairwise dispersion map;
8
+ * shuffle: the same upper-triangular values after a within-molecule
9
+ permutation, reconstructed symmetrically;
10
+ * constant: a molecule-wise matched off-diagonal mean, which preserves the
11
+ overall dispersion scale while removing pair-specific structure.
12
+
13
+ All candidate-generation, proposal, selection, budget, RMSD, and random-seed
14
+ arguments are shared. The script intentionally does not summarize results;
15
+ the inference program remains the single source of truth for metric
16
+ calculation, and its per-molecule CSV files are the auditable outputs.
17
+ """
18
+ from __future__ import annotations
19
+
20
+ import argparse
21
+ import json
22
+ import shlex
23
+ import subprocess
24
+ from datetime import datetime, timezone
25
+ from pathlib import Path
26
+
27
+
28
+ CONTROLS = ("normal", "constant", "shuffle", "random")
29
+
30
+
31
+ def parse_args() -> argparse.Namespace:
32
+ parser = argparse.ArgumentParser(description=__doc__)
33
+ parser.add_argument("--python", default="python")
34
+ parser.add_argument("--output-dir", type=Path, required=True)
35
+ parser.add_argument("--dry-run", action="store_true")
36
+ parser.add_argument("--controls", nargs="+", choices=CONTROLS, default=["normal", "constant", "shuffle"])
37
+ parser.add_argument("--inference-script", default="infer_mean_dispersion_torsion.py")
38
+ parser.add_argument("--seed", type=int, default=20260921)
39
+ parser.add_argument(
40
+ "inference_args",
41
+ nargs=argparse.REMAINDER,
42
+ help="Arguments forwarded to infer_mean_dispersion_torsion.py.",
43
+ )
44
+ return parser.parse_args()
45
+
46
+
47
+ def build_command(args: argparse.Namespace, control: str) -> list[str]:
48
+ forwarded = list(args.inference_args)
49
+ if forwarded and forwarded[0] == "--":
50
+ forwarded = forwarded[1:]
51
+ # Remove output paths supplied by a copied command so every arm gets a
52
+ # distinct, auditable output without changing any scientific setting.
53
+ command = [args.python, "-u", args.inference_script, *forwarded]
54
+ command += [
55
+ "--dispersion_control", control,
56
+ "--dispersion_seed", str(args.seed),
57
+ "--inference_seed", str(args.seed),
58
+ "--method_name", f"Pdisp-intervention-{control}",
59
+ "--output_dir", str(args.output_dir / control),
60
+ "--per_molecule_csv", str(args.output_dir / f"{control}_per_molecule.csv"),
61
+ "--revisited_metrics_csv", str(args.output_dir / f"{control}_chemistry.csv"),
62
+ "--threshold_curve_csv", str(args.output_dir / f"{control}_curve.csv"),
63
+ "--save_raw_pool_pt", str(args.output_dir / control / "raw_pool.pt"),
64
+ ]
65
+ return command
66
+
67
+
68
+ def main() -> None:
69
+ args = parse_args()
70
+ args.output_dir.mkdir(parents=True, exist_ok=True)
71
+ commands = {control: build_command(args, control) for control in args.controls}
72
+ manifest = {
73
+ "created_utc": datetime.now(timezone.utc).isoformat(),
74
+ "purpose": "matched intervention for the learned P_disp contribution",
75
+ "controls": list(args.controls),
76
+ "seed": int(args.seed),
77
+ "commands": {key: value for key, value in commands.items()},
78
+ "protocol": {
79
+ "shared_checkpoint": True,
80
+ "shared_candidate_budget": True,
81
+ "shared_selector": True,
82
+ "shared_final_budget": True,
83
+ "shared_rmsd_backend": True,
84
+ "only_intervention": "dispersion signal used to form torsion proposal widths",
85
+ },
86
+ }
87
+ (args.output_dir / "protocol_manifest.json").write_text(
88
+ json.dumps(manifest, indent=2) + "\n", encoding="utf-8"
89
+ )
90
+
91
+ for control, command in commands.items():
92
+ print(f"\n===== {control} =====")
93
+ print(shlex.join(command), flush=True)
94
+ if args.dry_run:
95
+ continue
96
+ log_path = args.output_dir / f"{control}.log"
97
+ with log_path.open("w", encoding="utf-8") as log:
98
+ process = subprocess.Popen(
99
+ command,
100
+ stdout=subprocess.PIPE,
101
+ stderr=subprocess.STDOUT,
102
+ text=True,
103
+ bufsize=1,
104
+ )
105
+ assert process.stdout is not None
106
+ for line in process.stdout:
107
+ print(line, end="", flush=True)
108
+ log.write(line)
109
+ log.flush()
110
+ return_code = process.wait()
111
+ if return_code:
112
+ raise subprocess.CalledProcessError(return_code, command)
113
+
114
+
115
+ if __name__ == "__main__":
116
+ main()