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.
- args_parse.py +593 -0
- candidate_corrector.py +161 -0
- candidate_scorer.py +359 -0
- conformend/__init__.py +36 -0
- conformend/refiner.py +25 -0
- dataset/__init__.py +1 -0
- dataset/drugdataset.py +644 -0
- dataset/manifold.py +237 -0
- dataset/sharded_drugdataset.py +124 -0
- dataset/smiles2graph.py +217 -0
- dualmapref/__init__.py +24 -0
- dualmapref/refiner.py +16 -0
- dualmapref-0.2.8.dist-info/LICENSE +21 -0
- dualmapref-0.2.8.dist-info/METADATA +167 -0
- dualmapref-0.2.8.dist-info/RECORD +186 -0
- dualmapref-0.2.8.dist-info/WHEEL +5 -0
- dualmapref-0.2.8.dist-info/entry_points.txt +10 -0
- dualmapref-0.2.8.dist-info/top_level.txt +29 -0
- exputils.py +289 -0
- infer.py +23 -0
- infer_base_conformers.py +5589 -0
- infer_mean_dispersion_torsion.py +1117 -0
- infer_torsion.py +752 -0
- infer_torsional_denoiser.py +1021 -0
- manimol/__init__.py +30 -0
- manimol/__main__.py +6 -0
- manimol/cli.py +36 -0
- manimol/full_cli.py +41 -0
- manimol/legacy_imports.py +43 -0
- manimol/manifest.py +56 -0
- manimol/postprocess.py +148 -0
- manimol/priors.py +60 -0
- manimol/protocols.py +119 -0
- manimol/refiner.py +645 -0
- manimol/runtime.py +194 -0
- manimol/selection.py +85 -0
- manimol/torsion.py +22 -0
- manimol/train_cli.py +14 -0
- mixture_flow/src/__init__.py +1 -0
- mixture_flow/src/_path.py +7 -0
- mixture_flow/src/infer28_mixture_torsion_flow.py +1093 -0
- mixture_flow/src/mixture_torsion_flow.py +291 -0
- mixture_flow/src/summarize_mixture_debug.py +80 -0
- mixture_flow/src/train28_mixture_torsion_flow.py +583 -0
- mixture_torsion_flow.py +7 -0
- models/ manifold_learning.py +86 -0
- models/__init__.py +8 -0
- models/dist.py +273 -0
- models/dist2coords.py +23 -0
- models/egnn.py +107 -0
- models/experimental_backbones.py +364 -0
- models/gnnconv.py +512 -0
- models/kernel_inversion.py +141 -0
- models/kernels.py +427 -0
- models/losses.py +154 -0
- models/mean_dispersion_bridge.py +119 -0
- models/mean_dispersion_torsion_context.py +155 -0
- models/model.py +73 -0
- models/model0.py +2375 -0
- models/vis.py +128 -0
- pgraph_controls.py +107 -0
- scripts/__init__.py +2 -0
- scripts/analyze_basin_alignment.py +63 -0
- scripts/analyze_hif2a_conformer_aggregation.py +267 -0
- scripts/analyze_hif2a_contact_pharmacophore.py +1111 -0
- scripts/analyze_hif2a_fixed_budget.py +202 -0
- scripts/analyze_hif2a_pharmacophore.py +405 -0
- scripts/analyze_hif2a_pharmacophore_match_metric.py +386 -0
- scripts/analyze_p_control_candidate_flow.py +154 -0
- scripts/analyze_scaffold_basin.py +83 -0
- scripts/audit_dispersion_proposals.py +208 -0
- scripts/audit_etflow_protocol.py +258 -0
- scripts/audit_external_overlap.py +150 -0
- scripts/audit_oldbest_fulltrainval_split.py +82 -0
- scripts/audit_pdbbind_contact_pharmacophores.py +146 -0
- scripts/audit_qm9_geomol_test_split.py +94 -0
- scripts/audit_stage1_stage2_cross.py +131 -0
- scripts/build_geom_drugs_lowref_diagnostic.py +84 -0
- scripts/build_qm9_backfill_manifest.py +99 -0
- scripts/check_etflow_runtime.py +56 -0
- scripts/compare_prior_sources.py +122 -0
- scripts/compose_binding_mode_figure.py +87 -0
- scripts/compose_hif2a_contact_pharmacophore_suppfig.py +255 -0
- scripts/compose_hif2a_functional_geometry_pipeline.py +266 -0
- scripts/compose_manimol_internal_architecture.py +291 -0
- scripts/diagnose_flow_basin_intervention.py +54 -0
- scripts/diagnose_hif2a_pharmacophore_budget.py +185 -0
- scripts/diagnose_route2_p_ranking.py +123 -0
- scripts/discover_binding_mode_inputs.py +30 -0
- scripts/evaluate_functional_prior_stage1.py +230 -0
- scripts/evaluate_geomanimol.py +74 -0
- scripts/evaluate_geomanimol_flow.py +23 -0
- scripts/evaluate_geomanimol_multiscaffold.py +46 -0
- scripts/evaluate_geomanimol_residual.py +45 -0
- scripts/evaluate_geomanimol_torsion.py +40 -0
- scripts/evaluate_hif2a_bioactive_enrichment.py +91 -0
- scripts/evaluate_hif2a_pms_suite.py +440 -0
- scripts/evaluate_pdbbind_contact_pms.py +155 -0
- scripts/evaluate_platinum_external.py +114 -0
- scripts/evaluate_platinum_pool.py +82 -0
- scripts/evaluate_route2_calibrated_p.py +104 -0
- scripts/evaluate_route2_library_components.py +596 -0
- scripts/evaluate_route2_p_basin_budget.py +288 -0
- scripts/evaluate_stage1_checkpoint_only.py +30 -0
- scripts/export_dispersion_bond_audit.py +136 -0
- scripts/export_top20_shards.py +207 -0
- scripts/external_validation_metrics.py +152 -0
- scripts/fit_topology_prior.py +117 -0
- scripts/frozen_dispersion_audit.py +281 -0
- scripts/geomanimol_debug.py +50 -0
- scripts/geomanimol_smoke.py +37 -0
- scripts/infer_etflow_matched.py +524 -0
- scripts/inspect_checkpoint.py +12 -0
- scripts/inspect_conformer_capacity.py +71 -0
- scripts/inspect_pool.py +12 -0
- scripts/make_figure3_selection_loss.py +474 -0
- scripts/make_figure3_selection_summary.py +275 -0
- scripts/make_geom_debug_subset.py +62 -0
- scripts/make_low_reference_test_subset.py +70 -0
- scripts/merge_stage1_into_stage2.py +82 -0
- scripts/place_hif2a_candidates_for_evaluation.py +66 -0
- scripts/plot_hif2a_low_budget_efficiency.py +100 -0
- scripts/plot_prior_validation.py +48 -0
- scripts/precompute_stage2_assignments.py +90 -0
- scripts/prepare_bace_activity.py +98 -0
- scripts/prepare_bace_etkdg_benchmark.py +90 -0
- scripts/prepare_figure5_4x4_cases.py +470 -0
- scripts/prepare_geom_drugs_geomol_top20.py +472 -0
- scripts/prepare_pdbbind_core_raw.py +90 -0
- scripts/prepare_platinum_raw.py +74 -0
- scripts/prepare_pubchem_etkdg.py +54 -0
- scripts/rebuild_hif2a_final_sdf_and_metrics.py +55 -0
- scripts/rebuild_hif2a_fixed_pool_sweep.py +175 -0
- scripts/rebuild_hif2a_strict.py +220 -0
- scripts/recompute_hif2a_bootstrap.py +63 -0
- scripts/reference_free_geometry.py +112 -0
- scripts/render_binding_modes.py +413 -0
- scripts/render_figure5_4x4.py +330 -0
- scripts/render_figure6_pharmacophore_pymol.py +162 -0
- scripts/render_hif2a_contact_pharmacophore_pymol.py +414 -0
- scripts/render_hif2a_figure11.py +397 -0
- scripts/run_bace_2d_baseline.py +73 -0
- scripts/run_drugs_validation_matrix.py +225 -0
- scripts/run_external_reference_free.py +53 -0
- scripts/run_manimol_finalk_sensitivity.py +106 -0
- scripts/run_manimol_oversampling_sensitivity.py +109 -0
- scripts/run_pdisp_matched_intervention.py +116 -0
- scripts/run_stage1_stage2_cross20.py +83 -0
- scripts/score_hif2a_candidates_with_pgraph.py +221 -0
- scripts/summarize_dispersion_intervention.py +88 -0
- scripts/test_mean_dispersion_bridge.py +50 -0
- scripts/train_dispersion_head_diagnostic.py +320 -0
- scripts/train_dispersion_head_streaming.py +519 -0
- scripts/train_geomanimol.py +100 -0
- scripts/train_geomanimol_flow.py +26 -0
- scripts/train_geomanimol_residual.py +70 -0
- scripts/train_geomanimol_torsion.py +50 -0
- scripts/train_quantile_representation_diagnostic.py +204 -0
- scripts/validate_mean_dispersion_prior.py +173 -0
- scripts/validate_packed_shard.py +41 -0
- scripts/validate_stage1_prior.py +221 -0
- scripts/validate_top20_shards.py +36 -0
- scripts/validation/__init__.py +1 -0
- scripts/validation/hif2a_downstream_baselines.py +105 -0
- scripts/validation/hif2a_pairwise_ranker.py +218 -0
- scripts/verify_binding_mode_figure.py +47 -0
- torsion_manifold.py +281 -0
- train.py +78 -0
- train_graph_encoder.py +206 -0
- train_local_torsion_corrector.py +511 -0
- train_mean_dispersion_torsion_prior.py +329 -0
- train_probability_basin.py +235 -0
- train_torsion_generator.py +1631 -0
- train_torsion_manifold_prior.py +258 -0
- train_torsional_denoiser.py +415 -0
- trainer.py +1038 -0
- utils/__init__.py +7 -0
- utils/checkpoint.py +40 -0
- utils/device.py +17 -0
- utils/helpers.py +98 -0
- utils/kabsch.py +29 -0
- utils/lookup_table.py +164 -0
- utils/metrics.py +50 -0
- utils/optuna.py +111 -0
- utils/save_mol.py +366 -0
- utils/util.py +36 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Render the Figure 5 4x4 conformer-recovery case study from prepared pair SDFs."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import csv
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import shutil
|
|
11
|
+
import tempfile
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Dict, List, Tuple
|
|
14
|
+
|
|
15
|
+
import matplotlib as mpl
|
|
16
|
+
import matplotlib.pyplot as plt
|
|
17
|
+
from PIL import Image
|
|
18
|
+
from rdkit import Chem
|
|
19
|
+
from rdkit.Chem import Draw
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
DEFAULT_METHODS = ["Molecule", "Reference", "ETKDG", "ET-Flow", "MANIMOL"]
|
|
23
|
+
METHOD_COLORS = {
|
|
24
|
+
"ETKDG": "orange",
|
|
25
|
+
"ET-Flow": "teal",
|
|
26
|
+
"MANIMOL": "blue",
|
|
27
|
+
}
|
|
28
|
+
DISPLAY_COLORS = {
|
|
29
|
+
"ETKDG": "#C9793D",
|
|
30
|
+
"ET-Flow": "#2A8C8C",
|
|
31
|
+
"MANIMOL": "#2E5EAA",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def parse_args() -> argparse.Namespace:
|
|
36
|
+
parser = argparse.ArgumentParser(description="Render Figure 5 4x4 from prepared SDF pairs.")
|
|
37
|
+
parser.add_argument("--input_dir", default="outputs/figure5_4x4")
|
|
38
|
+
parser.add_argument("--output_prefix", default="NCS_ManiMol/FIG/figure5_4x4")
|
|
39
|
+
parser.add_argument("--panel_width", type=int, default=960)
|
|
40
|
+
parser.add_argument("--panel_height", type=int, default=760)
|
|
41
|
+
parser.add_argument("--dpi", type=int, default=450)
|
|
42
|
+
parser.add_argument("--keep_tmp", action="store_true")
|
|
43
|
+
return parser.parse_args()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def safe_name(text: str) -> str:
|
|
47
|
+
return "".join(ch if ch.isalnum() or ch in "._-" else "_" for ch in str(text))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def load_selected_cases(path: Path) -> List[dict]:
|
|
51
|
+
with path.open(newline="", encoding="utf-8") as handle:
|
|
52
|
+
return list(csv.DictReader(handle))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def first_mol(path: Path) -> Chem.Mol:
|
|
56
|
+
mols = [m for m in Chem.SDMolSupplier(str(path), removeHs=False) if m is not None]
|
|
57
|
+
if not mols:
|
|
58
|
+
raise ValueError(f"empty SDF: {path}")
|
|
59
|
+
return mols[0]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def draw_reference_2d(smiles: str, out_png: Path) -> None:
|
|
63
|
+
mol = Chem.MolFromSmiles(smiles)
|
|
64
|
+
if mol is None:
|
|
65
|
+
raise ValueError(f"invalid SMILES: {smiles}")
|
|
66
|
+
Draw.rdDepictor.Compute2DCoords(mol)
|
|
67
|
+
drawer = Draw.MolDraw2DCairo(900, 650)
|
|
68
|
+
opts = drawer.drawOptions()
|
|
69
|
+
opts.padding = 0.08
|
|
70
|
+
opts.bondLineWidth = 2
|
|
71
|
+
opts.minFontSize = 16
|
|
72
|
+
opts.maxFontSize = 26
|
|
73
|
+
drawer.DrawMolecule(mol)
|
|
74
|
+
drawer.FinishDrawing()
|
|
75
|
+
out_png.write_bytes(drawer.GetDrawingText())
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def render_panel_with_pymol(pair_sdf: Path, method: str, out_png: Path, width: int, height: int) -> None:
|
|
79
|
+
import pymol
|
|
80
|
+
from pymol import cmd
|
|
81
|
+
|
|
82
|
+
generated_color = METHOD_COLORS.get(method, "blue")
|
|
83
|
+
cmd.reinitialize()
|
|
84
|
+
cmd.set("ray_opaque_background", 0)
|
|
85
|
+
cmd.set("bg_rgb", "white")
|
|
86
|
+
cmd.set("antialias", 2)
|
|
87
|
+
cmd.set("ray_trace_mode", 1)
|
|
88
|
+
cmd.set("ambient", 0.55)
|
|
89
|
+
cmd.set("direct", 0.55)
|
|
90
|
+
cmd.set("specular", 0.12)
|
|
91
|
+
cmd.set("shininess", 12)
|
|
92
|
+
cmd.set("depth_cue", 0)
|
|
93
|
+
cmd.set("orthoscopic", 1)
|
|
94
|
+
cmd.load(str(pair_sdf), "pair")
|
|
95
|
+
cmd.split_states("pair", prefix="state")
|
|
96
|
+
cmd.delete("pair")
|
|
97
|
+
states = sorted(cmd.get_object_list())
|
|
98
|
+
if len(states) < 2:
|
|
99
|
+
raise RuntimeError(f"{pair_sdf} should contain reference and generated conformers")
|
|
100
|
+
ref_obj, gen_obj = states[0], states[1]
|
|
101
|
+
cmd.remove("elem H")
|
|
102
|
+
cmd.hide("everything")
|
|
103
|
+
cmd.show("sticks", ref_obj)
|
|
104
|
+
cmd.show("sticks", gen_obj)
|
|
105
|
+
cmd.color("gray60", f"{ref_obj} and elem C")
|
|
106
|
+
cmd.color(generated_color, f"{gen_obj} and elem C")
|
|
107
|
+
for obj in [ref_obj, gen_obj]:
|
|
108
|
+
cmd.color("red", f"{obj} and elem O")
|
|
109
|
+
cmd.color("blue", f"{obj} and elem N")
|
|
110
|
+
cmd.color("yelloworange", f"{obj} and elem S")
|
|
111
|
+
cmd.color("orange", f"{obj} and elem P")
|
|
112
|
+
cmd.color("forest", f"{obj} and elem F+Cl")
|
|
113
|
+
cmd.color("brown", f"{obj} and elem Br")
|
|
114
|
+
cmd.set("stick_radius", 0.15, ref_obj)
|
|
115
|
+
cmd.set("stick_radius", 0.18 if method == "MANIMOL" else 0.17, gen_obj)
|
|
116
|
+
cmd.set("stick_transparency", 0.22, ref_obj)
|
|
117
|
+
cmd.orient(ref_obj)
|
|
118
|
+
cmd.zoom("all", 1.06)
|
|
119
|
+
cmd.ray(int(width), int(height))
|
|
120
|
+
cmd.png(str(out_png), dpi=300)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def render_reference_with_pymol(ref_sdf: Path, out_png: Path, width: int, height: int) -> None:
|
|
124
|
+
import pymol
|
|
125
|
+
from pymol import cmd
|
|
126
|
+
|
|
127
|
+
cmd.reinitialize()
|
|
128
|
+
cmd.set("ray_opaque_background", 0)
|
|
129
|
+
cmd.set("bg_rgb", "white")
|
|
130
|
+
cmd.set("antialias", 2)
|
|
131
|
+
cmd.set("ray_trace_mode", 1)
|
|
132
|
+
cmd.set("ambient", 0.55)
|
|
133
|
+
cmd.set("direct", 0.55)
|
|
134
|
+
cmd.set("specular", 0.12)
|
|
135
|
+
cmd.set("shininess", 12)
|
|
136
|
+
cmd.set("depth_cue", 0)
|
|
137
|
+
cmd.set("orthoscopic", 1)
|
|
138
|
+
cmd.load(str(ref_sdf), "reference")
|
|
139
|
+
cmd.remove("elem H")
|
|
140
|
+
cmd.hide("everything")
|
|
141
|
+
cmd.show("sticks", "reference")
|
|
142
|
+
cmd.color("gray45", "reference and elem C")
|
|
143
|
+
cmd.color("red", "reference and elem O")
|
|
144
|
+
cmd.color("blue", "reference and elem N")
|
|
145
|
+
cmd.color("yelloworange", "reference and elem S")
|
|
146
|
+
cmd.color("orange", "reference and elem P")
|
|
147
|
+
cmd.color("forest", "reference and elem F+Cl")
|
|
148
|
+
cmd.color("brown", "reference and elem Br")
|
|
149
|
+
cmd.set("stick_radius", 0.18, "reference")
|
|
150
|
+
cmd.orient("reference")
|
|
151
|
+
cmd.zoom("reference", 1.06)
|
|
152
|
+
cmd.ray(int(width), int(height))
|
|
153
|
+
cmd.png(str(out_png), dpi=300)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def read_rmsd_from_pair(path: Path) -> float:
|
|
157
|
+
mols = [m for m in Chem.SDMolSupplier(str(path), removeHs=False) if m is not None]
|
|
158
|
+
if len(mols) < 2 or not mols[1].HasProp("rmsd_to_reference"):
|
|
159
|
+
return float("nan")
|
|
160
|
+
return float(mols[1].GetProp("rmsd_to_reference"))
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def ensure_pymol_launched() -> None:
|
|
164
|
+
import pymol
|
|
165
|
+
|
|
166
|
+
if not pymol.invocation.options.show_splash:
|
|
167
|
+
return
|
|
168
|
+
pymol.finish_launching(["pymol", "-qc"])
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def active_methods(cases: List[dict]) -> List[str]:
|
|
172
|
+
has_etflow = any(str(case.get("ETFlow_RMSD", "")).strip() for case in cases)
|
|
173
|
+
return ["Molecule", "Reference", "ETKDG", "ET-Flow", "MANIMOL"] if has_etflow else ["Molecule", "Reference", "ETKDG", "MANIMOL"]
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def rmsd_for_method(case: dict, method: str) -> float:
|
|
177
|
+
if method == "ET-Flow":
|
|
178
|
+
return float(case["ETFlow_RMSD"])
|
|
179
|
+
return float(case[f"{method}_RMSD"])
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def compact_case_label(molecule_id: str) -> str:
|
|
183
|
+
parts = molecule_id.split("_")
|
|
184
|
+
if len(parts) >= 2 and parts[0] and parts[1]:
|
|
185
|
+
pdb_id = parts[0].upper()
|
|
186
|
+
ligand_id = parts[1].split("-")[0]
|
|
187
|
+
return f"PDB {pdb_id} | {ligand_id}"
|
|
188
|
+
return molecule_id
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def compose(cases: List[dict], methods: List[str], rendered: Dict[Tuple[str, str], Path], ref2d: Dict[str, Path], out_prefix: Path, dpi: int) -> None:
|
|
192
|
+
mpl.rcParams.update(
|
|
193
|
+
{
|
|
194
|
+
"font.family": "sans-serif",
|
|
195
|
+
"font.sans-serif": ["Arial", "Helvetica", "DejaVu Sans", "sans-serif"],
|
|
196
|
+
"svg.fonttype": "none",
|
|
197
|
+
"pdf.fonttype": 42,
|
|
198
|
+
"font.size": 8.5,
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
ncols = len(methods)
|
|
202
|
+
fig_width = 7.25 if ncols == 4 else 8.65
|
|
203
|
+
fig_height = 5.75 if len(cases) >= 4 else 1.50 * len(cases)
|
|
204
|
+
fig, axes = plt.subplots(len(cases), ncols, figsize=(fig_width, fig_height))
|
|
205
|
+
if len(cases) == 1:
|
|
206
|
+
axes = axes[None, :]
|
|
207
|
+
for ax in axes.ravel():
|
|
208
|
+
ax.set_axis_off()
|
|
209
|
+
|
|
210
|
+
for col, method in enumerate(methods):
|
|
211
|
+
axes[0, col].set_title(method, fontsize=10.5, fontweight="semibold", pad=8, color=DISPLAY_COLORS.get(method, "#222222"))
|
|
212
|
+
|
|
213
|
+
for row_idx, case in enumerate(cases):
|
|
214
|
+
mol_id = case["molecule_id"]
|
|
215
|
+
row_label = f"({chr(97 + row_idx)})"
|
|
216
|
+
axes[row_idx, 0].imshow(Image.open(ref2d[mol_id]))
|
|
217
|
+
axes[row_idx, 0].text(
|
|
218
|
+
0.018,
|
|
219
|
+
0.982,
|
|
220
|
+
row_label,
|
|
221
|
+
transform=axes[row_idx, 0].transAxes,
|
|
222
|
+
ha="left",
|
|
223
|
+
va="top",
|
|
224
|
+
fontsize=9.5,
|
|
225
|
+
fontweight="semibold",
|
|
226
|
+
color="#222222",
|
|
227
|
+
bbox=dict(facecolor="white", edgecolor="none", alpha=0.82, pad=0.7),
|
|
228
|
+
)
|
|
229
|
+
axes[row_idx, 0].text(
|
|
230
|
+
0.5,
|
|
231
|
+
0.02,
|
|
232
|
+
compact_case_label(mol_id),
|
|
233
|
+
transform=axes[row_idx, 0].transAxes,
|
|
234
|
+
ha="center",
|
|
235
|
+
va="bottom",
|
|
236
|
+
fontsize=7.5,
|
|
237
|
+
color="#444444",
|
|
238
|
+
)
|
|
239
|
+
for col, method in enumerate(methods[1:], start=1):
|
|
240
|
+
img = Image.open(rendered[(mol_id, method)])
|
|
241
|
+
axes[row_idx, col].imshow(img)
|
|
242
|
+
if method == "Reference":
|
|
243
|
+
axes[row_idx, col].text(
|
|
244
|
+
0.5,
|
|
245
|
+
0.02,
|
|
246
|
+
"Reference 3D",
|
|
247
|
+
transform=axes[row_idx, col].transAxes,
|
|
248
|
+
ha="center",
|
|
249
|
+
va="bottom",
|
|
250
|
+
fontsize=8.0,
|
|
251
|
+
color="#333333",
|
|
252
|
+
)
|
|
253
|
+
continue
|
|
254
|
+
rmsd = rmsd_for_method(case, method)
|
|
255
|
+
axes[row_idx, col].text(
|
|
256
|
+
0.5,
|
|
257
|
+
0.02,
|
|
258
|
+
f"RMSD = {rmsd:.2f} Å",
|
|
259
|
+
transform=axes[row_idx, col].transAxes,
|
|
260
|
+
ha="center",
|
|
261
|
+
va="bottom",
|
|
262
|
+
fontsize=8.2,
|
|
263
|
+
color="#1B355F" if method == "MANIMOL" else "#333333",
|
|
264
|
+
fontweight="semibold" if method == "MANIMOL" else "normal",
|
|
265
|
+
)
|
|
266
|
+
if method == "MANIMOL":
|
|
267
|
+
for spine in axes[row_idx, col].spines.values():
|
|
268
|
+
spine.set_visible(True)
|
|
269
|
+
spine.set_linewidth(0.55)
|
|
270
|
+
spine.set_edgecolor("#D7E6F8")
|
|
271
|
+
|
|
272
|
+
fig.subplots_adjust(left=0.012, right=0.997, top=0.965, bottom=0.015, wspace=0.030, hspace=-0.080)
|
|
273
|
+
out_prefix.parent.mkdir(parents=True, exist_ok=True)
|
|
274
|
+
fig.savefig(str(out_prefix) + ".png", dpi=dpi, bbox_inches="tight", pad_inches=0.02)
|
|
275
|
+
fig.savefig(str(out_prefix) + ".pdf", bbox_inches="tight", pad_inches=0.02)
|
|
276
|
+
fig.savefig(str(out_prefix) + ".svg", bbox_inches="tight", pad_inches=0.02)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def main() -> int:
|
|
280
|
+
args = parse_args()
|
|
281
|
+
in_dir = Path(args.input_dir)
|
|
282
|
+
cases_path = in_dir / "figure5_selected_cases.csv"
|
|
283
|
+
if not cases_path.exists():
|
|
284
|
+
raise FileNotFoundError(cases_path)
|
|
285
|
+
cases = load_selected_cases(cases_path)
|
|
286
|
+
if not cases:
|
|
287
|
+
raise RuntimeError("No selected cases available for rendering.")
|
|
288
|
+
tmp_root = Path(tempfile.mkdtemp(prefix="figure5_4x4_render_"))
|
|
289
|
+
rendered: Dict[Tuple[str, str], Path] = {}
|
|
290
|
+
ref2d: Dict[str, Path] = {}
|
|
291
|
+
methods = active_methods(cases)
|
|
292
|
+
try:
|
|
293
|
+
ensure_pymol_launched()
|
|
294
|
+
for case in cases:
|
|
295
|
+
mol_id = case["molecule_id"]
|
|
296
|
+
case_dir = in_dir / "pairs" / safe_name(mol_id)
|
|
297
|
+
ref_png = tmp_root / f"{safe_name(mol_id)}_ref2d.png"
|
|
298
|
+
draw_reference_2d(case["SMILES"], ref_png)
|
|
299
|
+
ref2d[mol_id] = ref_png
|
|
300
|
+
for method in methods[1:]:
|
|
301
|
+
if method == "Reference":
|
|
302
|
+
ref_sdf = case_dir / "Reference.sdf"
|
|
303
|
+
if not ref_sdf.exists():
|
|
304
|
+
raise FileNotFoundError(ref_sdf)
|
|
305
|
+
out_png = tmp_root / f"{safe_name(mol_id)}_reference3d.png"
|
|
306
|
+
render_reference_with_pymol(ref_sdf, out_png, int(args.panel_width), int(args.panel_height))
|
|
307
|
+
rendered[(mol_id, method)] = out_png
|
|
308
|
+
continue
|
|
309
|
+
pair_sdf = case_dir / f"{safe_name(method)}.sdf"
|
|
310
|
+
if not pair_sdf.exists():
|
|
311
|
+
raise FileNotFoundError(pair_sdf)
|
|
312
|
+
out_png = tmp_root / f"{safe_name(mol_id)}_{safe_name(method)}.png"
|
|
313
|
+
render_panel_with_pymol(pair_sdf, method, out_png, int(args.panel_width), int(args.panel_height))
|
|
314
|
+
rendered[(mol_id, method)] = out_png
|
|
315
|
+
expected = float(case["ETFlow_RMSD"] if method == "ET-Flow" else case[f"{method}_RMSD"])
|
|
316
|
+
actual = read_rmsd_from_pair(pair_sdf)
|
|
317
|
+
if abs(expected - actual) > 1e-5:
|
|
318
|
+
raise RuntimeError(f"RMSD mismatch for {mol_id}/{method}: CSV={expected} SDF={actual}")
|
|
319
|
+
compose(cases, methods, rendered, ref2d, Path(args.output_prefix), int(args.dpi))
|
|
320
|
+
print(f"Saved: {args.output_prefix}.png/.pdf/.svg")
|
|
321
|
+
finally:
|
|
322
|
+
if args.keep_tmp:
|
|
323
|
+
print(f"Temporary files kept at: {tmp_root}")
|
|
324
|
+
else:
|
|
325
|
+
shutil.rmtree(tmp_root, ignore_errors=True)
|
|
326
|
+
return 0
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
if __name__ == "__main__":
|
|
330
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Render Figure 6 panel (b) from the PMS evaluator's feature records."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import numpy as np
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
FEATURE_COLORS = {
|
|
11
|
+
"donor": [0.20, 0.72, 0.82],
|
|
12
|
+
"acceptor": [0.88, 0.12, 0.12],
|
|
13
|
+
"aromatic": [0.52, 0.28, 0.75],
|
|
14
|
+
"hydrophobe": [0.35, 0.70, 0.25],
|
|
15
|
+
"positive": [0.16, 0.32, 0.85],
|
|
16
|
+
"negative": [0.95, 0.45, 0.10],
|
|
17
|
+
}
|
|
18
|
+
METHOD_COLORS = {"reference": [0.36, 0.36, 0.36], "etkdg": [0.85, 0.47, 0.20], "manimol": [0.52, 0.34, 0.62]}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def launch():
|
|
22
|
+
import pymol
|
|
23
|
+
pymol.finish_launching(["pymol", "-cq"])
|
|
24
|
+
from pymol import cmd
|
|
25
|
+
return cmd
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def cgo_sphere(color, center, radius, alpha, name):
|
|
29
|
+
from pymol.cgo import ALPHA, COLOR, SPHERE
|
|
30
|
+
return [COLOR, *color, ALPHA, alpha, SPHERE, *[float(v) for v in center], float(radius)]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def cgo_cylinder(color, start, end, radius, alpha):
|
|
34
|
+
from pymol.cgo import ALPHA, COLOR, CYLINDER
|
|
35
|
+
return [COLOR, *color, ALPHA, alpha, CYLINDER, *[float(v) for v in start], *[float(v) for v in end], float(radius), *color, *color]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def cgo_dashed_connector(color, start, end, radius, alpha, n_segments=7):
|
|
39
|
+
start = np.asarray(start, dtype=float)
|
|
40
|
+
end = np.asarray(end, dtype=float)
|
|
41
|
+
out = []
|
|
42
|
+
for i in range(n_segments):
|
|
43
|
+
if i % 2:
|
|
44
|
+
continue
|
|
45
|
+
a = start + (end - start) * (i / n_segments)
|
|
46
|
+
b = start + (end - start) * ((i + 0.72) / n_segments)
|
|
47
|
+
out += cgo_cylinder(color, a, b, radius, alpha)
|
|
48
|
+
return out
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def cgo_ring(color, center, normal, radius, tube_radius, alpha):
|
|
52
|
+
"""Draw a graphical aromatic ring in the plane inferred from crystal atoms."""
|
|
53
|
+
from pymol.cgo import ALPHA, COLOR, CYLINDER
|
|
54
|
+
normal = np.asarray(normal, dtype=float)
|
|
55
|
+
normal /= max(np.linalg.norm(normal), 1e-8)
|
|
56
|
+
seed = np.array([1.0, 0.0, 0.0])
|
|
57
|
+
if abs(np.dot(seed, normal)) > 0.85:
|
|
58
|
+
seed = np.array([0.0, 1.0, 0.0])
|
|
59
|
+
basis_a = seed - np.dot(seed, normal) * normal
|
|
60
|
+
basis_a /= max(np.linalg.norm(basis_a), 1e-8)
|
|
61
|
+
basis_b = np.cross(normal, basis_a)
|
|
62
|
+
points = [np.asarray(center) + radius * (np.cos(t) * basis_a + np.sin(t) * basis_b)
|
|
63
|
+
for t in np.linspace(0, 2 * np.pi, 17)[:-1]]
|
|
64
|
+
out = []
|
|
65
|
+
for a, b in zip(points, points[1:] + points[:1]):
|
|
66
|
+
out += [COLOR, *color, ALPHA, alpha, CYLINDER, *a, *b, tube_radius, *color, *color]
|
|
67
|
+
return out
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def crystal_coords(cmd):
|
|
71
|
+
model = cmd.get_model("crystal")
|
|
72
|
+
return np.asarray([atom.coord for atom in model.atom], dtype=float)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def aromatic_normal(coords, atom_ids):
|
|
76
|
+
points = coords[np.asarray(atom_ids, dtype=int)]
|
|
77
|
+
centered = points - points.mean(axis=0, keepdims=True)
|
|
78
|
+
if len(points) >= 3:
|
|
79
|
+
_, _, vh = np.linalg.svd(centered, full_matrices=False)
|
|
80
|
+
return vh[-1]
|
|
81
|
+
return np.array([0.0, 0.0, 1.0])
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def setup(cmd, ref_path, generated_path, method, features, master_view=None):
|
|
85
|
+
cmd.reinitialize()
|
|
86
|
+
cmd.bg_color("white")
|
|
87
|
+
cmd.set("orthoscopic", 1)
|
|
88
|
+
cmd.set("ray_opaque_background", 0)
|
|
89
|
+
cmd.set("antialias", 2)
|
|
90
|
+
cmd.set("depth_cue", 0)
|
|
91
|
+
cmd.set("specular", 0.15)
|
|
92
|
+
cmd.set("ambient", 0.65)
|
|
93
|
+
cmd.set("stick_radius", 0.095)
|
|
94
|
+
cmd.load(str(ref_path), "crystal")
|
|
95
|
+
if generated_path:
|
|
96
|
+
cmd.load(str(generated_path), method)
|
|
97
|
+
cmd.hide("everything")
|
|
98
|
+
cmd.show("sticks", "crystal")
|
|
99
|
+
cmd.color("gray35", "crystal and elem C")
|
|
100
|
+
if generated_path:
|
|
101
|
+
cmd.show("sticks", method)
|
|
102
|
+
cmd.color("orange" if method == "etkdg" else "purple", f"{method} and elem C")
|
|
103
|
+
cmd.set("stick_radius", 0.125, method)
|
|
104
|
+
cmd.set("stick_transparency", 18, method)
|
|
105
|
+
cmd.color("red", "(crystal or " + method + ") and elem O" if generated_path else "crystal and elem O")
|
|
106
|
+
cmd.color("blue", "(crystal or " + method + ") and elem N" if generated_path else "crystal and elem N")
|
|
107
|
+
cmd.color("yellow", "(crystal or " + method + ") and elem S" if generated_path else "crystal and elem S")
|
|
108
|
+
cmd.color("cyan", "(crystal or " + method + ") and elem F" if generated_path else "crystal and elem F")
|
|
109
|
+
|
|
110
|
+
coords = crystal_coords(cmd)
|
|
111
|
+
cgo = []
|
|
112
|
+
for item in features:
|
|
113
|
+
family = item["feature_type"]
|
|
114
|
+
color = FEATURE_COLORS.get(family, [0.5, 0.5, 0.5])
|
|
115
|
+
target = item["crystal_center_xyz"]
|
|
116
|
+
# Radii/alpha are graphical only; PMS does not define feature spheres.
|
|
117
|
+
target_radius = {"hydrophobe": 0.24, "aromatic": 0.30}.get(family, 0.32)
|
|
118
|
+
target_alpha = {"hydrophobe": 0.11, "aromatic": 0.20}.get(family, 0.20 if generated_path else 0.26)
|
|
119
|
+
if family == "aromatic":
|
|
120
|
+
normal = aromatic_normal(coords, item["atom_ids"])
|
|
121
|
+
cgo += cgo_ring(color, target, normal, target_radius, 0.045, min(0.38, target_alpha + 0.10))
|
|
122
|
+
cgo += cgo_sphere(color, target, 0.065, 0.78, f"target_center_{item['feature_id']}")
|
|
123
|
+
else:
|
|
124
|
+
cgo += cgo_sphere(color, target, target_radius, target_alpha, f"target_{item['feature_id']}")
|
|
125
|
+
if generated_path and item.get(f"{method}_matched"):
|
|
126
|
+
generated = item[f"{method}_center_xyz"]
|
|
127
|
+
generated_radius = 0.085 if family == "hydrophobe" else (0.105 if family == "aromatic" else 0.12)
|
|
128
|
+
cgo += cgo_sphere(color, generated, generated_radius, 0.94, f"generated_{item['feature_id']}")
|
|
129
|
+
if np.linalg.norm(np.asarray(generated) - np.asarray(target)) > 0.08:
|
|
130
|
+
cgo += cgo_dashed_connector([0.42, 0.42, 0.42], target, generated, 0.010, 0.52)
|
|
131
|
+
cmd.load_cgo(cgo, "pharmacophore_features")
|
|
132
|
+
if master_view is None:
|
|
133
|
+
cmd.zoom("crystal or " + method if generated_path else "crystal", buffer=1.25)
|
|
134
|
+
cmd.orient("crystal or " + method if generated_path else "crystal")
|
|
135
|
+
else:
|
|
136
|
+
cmd.set_view(master_view)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def main():
|
|
140
|
+
p = argparse.ArgumentParser()
|
|
141
|
+
p.add_argument("--features", required=True)
|
|
142
|
+
p.add_argument("--reference", required=True)
|
|
143
|
+
p.add_argument("--etkdg", required=True)
|
|
144
|
+
p.add_argument("--manimol", required=True)
|
|
145
|
+
p.add_argument("--output-dir", required=True)
|
|
146
|
+
args = p.parse_args()
|
|
147
|
+
cmd = launch()
|
|
148
|
+
features = json.loads(Path(args.features).read_text())["features"]
|
|
149
|
+
out = Path(args.output_dir); out.mkdir(parents=True, exist_ok=True)
|
|
150
|
+
setup(cmd, args.reference, None, "reference", features)
|
|
151
|
+
master_view = cmd.get_view()
|
|
152
|
+
cmd.png(str(out / "pharmacophore_reference.png"), width=1400, height=900, dpi=300, ray=1)
|
|
153
|
+
setup(cmd, args.reference, args.etkdg, "etkdg", features, master_view)
|
|
154
|
+
cmd.png(str(out / "pharmacophore_etkdg.png"), width=1400, height=900, dpi=300, ray=1)
|
|
155
|
+
setup(cmd, args.reference, args.manimol, "manimol", features, master_view)
|
|
156
|
+
cmd.png(str(out / "pharmacophore_manimol.png"), width=1400, height=900, dpi=300, ray=1)
|
|
157
|
+
(out / "render_metadata.json").write_text(json.dumps({"feature_count": len(features), "master_view_reused": True}, indent=2) + "\n")
|
|
158
|
+
print(out)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
if __name__ == "__main__":
|
|
162
|
+
main()
|