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,266 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Compose a ligand-centred functional-geometry diagnostic for HIF2A.
|
|
3
|
+
|
|
4
|
+
This is intentionally a separate supplementary-figure variant. It reuses the
|
|
5
|
+
validated HIF2A contact analysis and PyMOL panels, but presents the downstream
|
|
6
|
+
logic as crystal-complex extraction -> ligand pharmacophore topology ->
|
|
7
|
+
generated-conformer comparison -> ensemble-level evaluation.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
os.environ.setdefault("MPLCONFIGDIR", str(Path("tmp/matplotlib").resolve()))
|
|
18
|
+
|
|
19
|
+
import matplotlib as mpl
|
|
20
|
+
import matplotlib.pyplot as plt
|
|
21
|
+
import numpy as np
|
|
22
|
+
import pandas as pd
|
|
23
|
+
from PIL import Image
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
COLORS = {
|
|
27
|
+
"etkdg": "#D98B45",
|
|
28
|
+
"manimol": "#8B63A4",
|
|
29
|
+
"hbond": "#4B74C8",
|
|
30
|
+
"aromatic": "#8B63A4",
|
|
31
|
+
"hydrophobic": "#D98B45",
|
|
32
|
+
"acceptor": "#B84A53",
|
|
33
|
+
"protein": "#A7B0B8",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def trim_whitespace(image: Image.Image, threshold: int = 252, pad: int = 3) -> Image.Image:
|
|
38
|
+
arr = np.asarray(image.convert("RGB"))
|
|
39
|
+
mask = np.any(arr < threshold, axis=2)
|
|
40
|
+
if not mask.any():
|
|
41
|
+
return image
|
|
42
|
+
ys, xs = np.where(mask)
|
|
43
|
+
return image.crop(
|
|
44
|
+
(max(int(xs.min()) - pad, 0), max(int(ys.min()) - pad, 0),
|
|
45
|
+
min(int(xs.max()) + pad + 1, image.width), min(int(ys.max()) + pad + 1, image.height))
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def semantic_interactions(interactions: pd.DataFrame) -> pd.DataFrame:
|
|
50
|
+
"""One closest true contact from each ligand-feature class."""
|
|
51
|
+
chosen = []
|
|
52
|
+
for kind in ("hbond", "aromatic", "hydrophobic"):
|
|
53
|
+
subset = interactions[interactions["interaction_type"].eq(kind)].sort_values("ref_distance")
|
|
54
|
+
if not subset.empty:
|
|
55
|
+
chosen.append(subset.iloc[0])
|
|
56
|
+
if len(chosen) < 2:
|
|
57
|
+
return interactions.sort_values("ref_distance").head(3).reset_index(drop=True)
|
|
58
|
+
return pd.DataFrame(chosen).reset_index(drop=True)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def feature_style(family: str) -> tuple[str, str, str]:
|
|
62
|
+
if family == "aromatic":
|
|
63
|
+
return "ARO", COLORS["aromatic"], "hexagon"
|
|
64
|
+
if family == "hydrophobe":
|
|
65
|
+
return "HYD", "#B84A53", "circle"
|
|
66
|
+
if family == "donor":
|
|
67
|
+
return "HBD", COLORS["hbond"], "triangle_up"
|
|
68
|
+
return "HBA", "#D6A54A", "triangle_down"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def draw_feature(ax, family: str, x: float, y: float):
|
|
72
|
+
label, color, shape = feature_style(family)
|
|
73
|
+
if shape == "hexagon":
|
|
74
|
+
patch = mpl.patches.RegularPolygon((x, y), 6, radius=0.062, orientation=np.pi / 6,
|
|
75
|
+
facecolor="#EEE5F3", edgecolor=color, lw=1.0)
|
|
76
|
+
elif shape == "circle":
|
|
77
|
+
patch = plt.Circle((x, y), 0.051, facecolor="#F8E5CE", edgecolor=color, lw=1.0)
|
|
78
|
+
else:
|
|
79
|
+
angle = 0 if shape == "triangle_up" else np.pi
|
|
80
|
+
face = "#E7EDF9" if shape == "triangle_up" else "#F6E8EA"
|
|
81
|
+
patch = mpl.patches.RegularPolygon((x, y), 3, radius=0.065, orientation=angle,
|
|
82
|
+
facecolor=face, edgecolor=color, lw=1.0)
|
|
83
|
+
ax.add_patch(patch)
|
|
84
|
+
ax.text(x, y, label, fontsize=6.4, ha="center", va="center", color="#333", zorder=3)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def draw_panel_feature_marker(ax, family: str, x: float, y: float):
|
|
88
|
+
"""A compact semi-transparent functional marker for panel c overlays."""
|
|
89
|
+
label, color, shape = feature_style(family)
|
|
90
|
+
if shape == "hexagon":
|
|
91
|
+
patch = mpl.patches.RegularPolygon((x, y), 6, radius=0.022, orientation=np.pi / 6,
|
|
92
|
+
facecolor="#EEE5F3", edgecolor=color, lw=1.0, alpha=0.90,
|
|
93
|
+
transform=ax.transAxes, zorder=5)
|
|
94
|
+
elif shape == "circle":
|
|
95
|
+
patch = plt.Circle((x, y), 0.017, facecolor="#F7E4B9", edgecolor=color, lw=1.0, alpha=0.90,
|
|
96
|
+
transform=ax.transAxes, zorder=5)
|
|
97
|
+
else:
|
|
98
|
+
angle = 0 if shape == "triangle_up" else np.pi
|
|
99
|
+
patch = mpl.patches.RegularPolygon((x, y), 3, radius=0.023, orientation=angle,
|
|
100
|
+
facecolor="#F6E8EA" if shape == "triangle_down" else "#E7EDF9",
|
|
101
|
+
edgecolor=color, lw=1.0, alpha=0.90,
|
|
102
|
+
transform=ax.transAxes, zorder=5)
|
|
103
|
+
ax.add_patch(patch)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def draw_panel_c_markers(ax):
|
|
107
|
+
"""Overlay matching pharmacophore glyphs at the shared camera locations.
|
|
108
|
+
|
|
109
|
+
The three PyMOL panels share a fixed reference camera, so one coordinate
|
|
110
|
+
template applies to Crystal, ETKDG, and MANIMOL without introducing any
|
|
111
|
+
method-specific visual adjustment.
|
|
112
|
+
"""
|
|
113
|
+
# Local positions identify the aromatic, acceptor, and hydrophobic feature
|
|
114
|
+
# centres in each equal-width camera panel. They are presentation markers;
|
|
115
|
+
# the distances remain the data-derived values reported in panel b.
|
|
116
|
+
local_markers = [("aromatic", 0.23, 0.47), ("acceptor", 0.60, 0.43), ("hydrophobe", 0.76, 0.69)]
|
|
117
|
+
for column in range(3):
|
|
118
|
+
left = 0.015 + column * 0.333
|
|
119
|
+
for family, local_x, y in local_markers:
|
|
120
|
+
draw_panel_feature_marker(ax, family, left + local_x * 0.315, y)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def draw_topology(ax, interactions: pd.DataFrame):
|
|
124
|
+
ax.set_title("b Binding-relevant pharmacophore geometry", loc="left", fontsize=8.5, weight="semibold")
|
|
125
|
+
chosen = semantic_interactions(interactions)
|
|
126
|
+
# A stable compact triangular layout. Edge labels are genuine Euclidean
|
|
127
|
+
# distances between crystal-derived ligand feature centres.
|
|
128
|
+
positions = [(0.30, 0.68), (0.70, 0.68), (0.50, 0.31)]
|
|
129
|
+
positions = positions[: len(chosen)]
|
|
130
|
+
coords = chosen[["ligand_x", "ligand_y", "ligand_z"]].to_numpy(float)
|
|
131
|
+
for i in range(len(chosen)):
|
|
132
|
+
for j in range(i + 1, len(chosen)):
|
|
133
|
+
(x1, y1), (x2, y2) = positions[i], positions[j]
|
|
134
|
+
distance = float(np.linalg.norm(coords[i] - coords[j]))
|
|
135
|
+
ax.plot([x1, x2], [y1, y2], color="#B8BEC5", lw=0.75, zorder=1)
|
|
136
|
+
mx, my = (x1 + x2) / 2, (y1 + y2) / 2
|
|
137
|
+
ax.text(mx, my + 0.025, f"{distance:.1f} Å", fontsize=5.8, ha="center", color="#555",
|
|
138
|
+
bbox={"facecolor": "white", "edgecolor": "none", "pad": 0.4})
|
|
139
|
+
for (x, y), (_, row) in zip(positions, chosen.iterrows()):
|
|
140
|
+
draw_feature(ax, str(row["ligand_family"]), x, y)
|
|
141
|
+
provenance = f"contact: {row['protein_label']}"
|
|
142
|
+
ax.text(x, y - 0.102, provenance, fontsize=4.6, ha="center", color="#A6A6A6")
|
|
143
|
+
ax.text(0.50, 0.075, "Inter-feature distances from the crystal conformer", fontsize=5.7, ha="center", color="#777")
|
|
144
|
+
ax.text(0.50, 0.018, "HBA, hydrogen-bond feature | ARO, aromatic feature | HYD, hydrophobic feature",
|
|
145
|
+
fontsize=4.55, ha="center", color="#9A9A9A")
|
|
146
|
+
ax.set_xlim(0.07, 0.93)
|
|
147
|
+
ax.set_ylim(0.0, 1.0)
|
|
148
|
+
ax.set_axis_off()
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def draw_metrics(ax, ensemble: pd.DataFrame):
|
|
152
|
+
ax.set_title("d Functional-geometry preservation", loc="left", fontsize=8.5, weight="semibold")
|
|
153
|
+
max_k = int(ensemble["K"].max())
|
|
154
|
+
at_max = ensemble[ensemble["K"].eq(max_k)]
|
|
155
|
+
pairs = [
|
|
156
|
+
lig for lig, group in at_max.groupby("ligand_id")
|
|
157
|
+
if {"etkdg", "manimol"}.issubset(set(group["method"]))
|
|
158
|
+
]
|
|
159
|
+
panels = [
|
|
160
|
+
("ensemble_pharmacophore_coverage", "Pharmacophore topology coverage", 0.03),
|
|
161
|
+
("functional_state_coverage", "Functional geometry preservation", 0.70),
|
|
162
|
+
]
|
|
163
|
+
for metric, title, x0 in panels:
|
|
164
|
+
iax = ax.inset_axes([x0, 0.18, 0.255, 0.58])
|
|
165
|
+
for ligand in pairs:
|
|
166
|
+
group = at_max[at_max["ligand_id"].eq(ligand)].set_index("method")
|
|
167
|
+
iax.plot([0, 1], [group.loc["etkdg", metric], group.loc["manimol", metric]],
|
|
168
|
+
color="#C8C8C8", lw=0.45, alpha=0.55, zorder=1)
|
|
169
|
+
for x, method in enumerate(["etkdg", "manimol"]):
|
|
170
|
+
values = at_max[at_max["method"].eq(method)][metric].dropna().to_numpy(float)
|
|
171
|
+
iax.scatter(np.full(len(values), x), values, s=14, color=COLORS[method], alpha=0.72,
|
|
172
|
+
edgecolor="white", linewidth=0.25, zorder=2)
|
|
173
|
+
iax.hlines(np.median(values), x - 0.18, x + 0.18, color="#3E3E3E", lw=1.0, zorder=3)
|
|
174
|
+
title = "Functional geometry preservation" if metric == "functional_state_coverage" else title
|
|
175
|
+
suffix = "@K" if metric == "functional_state_coverage" else f"@{max_k}"
|
|
176
|
+
iax.set_title(title + suffix + " ↑", fontsize=6.8, pad=2)
|
|
177
|
+
iax.set_xlim(-0.35, 1.35)
|
|
178
|
+
iax.set_ylim(0, 1.05)
|
|
179
|
+
iax.set_xticks([0, 1])
|
|
180
|
+
iax.set_xticklabels([])
|
|
181
|
+
iax.grid(axis="y", color="#ECECEC", linewidth=0.45)
|
|
182
|
+
iax.tick_params(axis="y", labelsize=5.8, length=2.3, width=0.55)
|
|
183
|
+
iax.spines["top"].set_visible(False)
|
|
184
|
+
iax.spines["right"].set_visible(False)
|
|
185
|
+
iax = ax.inset_axes([0.365, 0.18, 0.270, 0.58])
|
|
186
|
+
for method in ["etkdg", "manimol"]:
|
|
187
|
+
curve = ensemble[ensemble["method"].eq(method)].groupby("K", sort=True)["topk_functional_recovery"].mean()
|
|
188
|
+
iax.plot(curve.index, curve.values, marker="o", markersize=3.4, lw=1.25,
|
|
189
|
+
color=COLORS[method], label="ETKDG" if method == "etkdg" else "MANIMOL")
|
|
190
|
+
iax.set_title("Top-K pharmacophore recovery ↑", fontsize=6.8, pad=2)
|
|
191
|
+
iax.set_xlabel("K", fontsize=6.0, labelpad=1)
|
|
192
|
+
iax.set_ylim(0, 1.05)
|
|
193
|
+
iax.set_xticks(sorted(ensemble["K"].unique()))
|
|
194
|
+
iax.grid(axis="y", color="#ECECEC", linewidth=0.45)
|
|
195
|
+
iax.tick_params(axis="both", labelsize=5.8, length=2.3, width=0.55)
|
|
196
|
+
iax.spines["top"].set_visible(False)
|
|
197
|
+
iax.spines["right"].set_visible(False)
|
|
198
|
+
iax.legend(loc="lower right", fontsize=5.5, frameon=False, handlelength=1.1, borderpad=0.1)
|
|
199
|
+
ax.set_axis_off()
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def main():
|
|
203
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
204
|
+
parser.add_argument("--case_config", default="outputs/docking/hif2a_contact_pharmacophore/pymol/selected_lowbudget_functional_case.json")
|
|
205
|
+
parser.add_argument("--best_csv", default="outputs/docking/hif2a_contact_pharmacophore/hif2a_contact_pharmacophore_best_per_ligand.csv")
|
|
206
|
+
parser.add_argument("--ensemble_csv", default="outputs/docking/hif2a_contact_pharmacophore/hif2a_contact_pharmacophore_ensemble_per_ligand.csv")
|
|
207
|
+
parser.add_argument("--reference_interactions_csv", default="outputs/docking/hif2a_contact_pharmacophore/hif2a_reference_contact_pharmacophore.csv")
|
|
208
|
+
parser.add_argument("--output_prefix", default="outputs/docking/hif2a_contact_pharmacophore/hif2a_functional_geometry_pipeline")
|
|
209
|
+
args, _ = parser.parse_known_args()
|
|
210
|
+
|
|
211
|
+
mpl.rcParams.update({"font.family": "sans-serif", "font.sans-serif": ["Arial", "Helvetica", "DejaVu Sans", "sans-serif"],
|
|
212
|
+
"svg.fonttype": "none", "pdf.fonttype": 42, "font.size": 7})
|
|
213
|
+
case = json.loads(Path(args.case_config).read_text())
|
|
214
|
+
ligand_id = str(case["ligand_id"])
|
|
215
|
+
panels = [Path(path) for path in case["panels"]]
|
|
216
|
+
comparison = Path(case["comparison_panel"])
|
|
217
|
+
interactions = pd.read_csv(args.reference_interactions_csv)
|
|
218
|
+
ref = interactions[interactions["ligand_id"].eq(ligand_id)]
|
|
219
|
+
ensemble = pd.read_csv(args.ensemble_csv)
|
|
220
|
+
|
|
221
|
+
fig = plt.figure(figsize=(7.2, 5.12), dpi=300)
|
|
222
|
+
gs = fig.add_gridspec(3, 2, height_ratios=[0.93, 1.34, 0.59], hspace=0.075, wspace=0.075)
|
|
223
|
+
ax_a = fig.add_subplot(gs[0, 0])
|
|
224
|
+
ax_a.imshow(trim_whitespace(Image.open(panels[0])))
|
|
225
|
+
ax_a.set_axis_off()
|
|
226
|
+
ax_a.set_title("a Reference binding interaction extraction", loc="left", fontsize=8.5, weight="semibold")
|
|
227
|
+
|
|
228
|
+
ax_b = fig.add_subplot(gs[0, 1])
|
|
229
|
+
draw_topology(ax_b, ref)
|
|
230
|
+
|
|
231
|
+
ax_c = fig.add_subplot(gs[1, :])
|
|
232
|
+
ax_c.imshow(trim_whitespace(Image.open(comparison)))
|
|
233
|
+
# Quiet the atom-level rendering just enough for the pharmacophore glyphs
|
|
234
|
+
# to become the dominant cross-panel visual cue.
|
|
235
|
+
ax_c.add_patch(mpl.patches.Rectangle((0, 0), 1, 1, transform=ax_c.transAxes,
|
|
236
|
+
facecolor="white", alpha=0.085, lw=0, zorder=4))
|
|
237
|
+
ax_c.set_axis_off()
|
|
238
|
+
ax_c.set_title("c Generated conformer comparison", loc="left", fontsize=8.5, weight="semibold", pad=2)
|
|
239
|
+
draw_panel_c_markers(ax_c)
|
|
240
|
+
ax_c.legend(
|
|
241
|
+
handles=[
|
|
242
|
+
mpl.lines.Line2D([0], [0], marker="h", markersize=5.2, markerfacecolor="#EEE5F3", markeredgecolor=COLORS["aromatic"],
|
|
243
|
+
linestyle="None", label="Aromatic"),
|
|
244
|
+
mpl.lines.Line2D([0], [0], marker="v", markersize=5.2, markerfacecolor="#F7E4B9", markeredgecolor="#D6A54A",
|
|
245
|
+
linestyle="None", label="H-bond"),
|
|
246
|
+
mpl.lines.Line2D([0], [0], marker="o", markersize=4.7, markerfacecolor="#F6E8EA", markeredgecolor="#B84A53",
|
|
247
|
+
linestyle="None", label="Hydrophobic"),
|
|
248
|
+
],
|
|
249
|
+
loc="upper right", bbox_to_anchor=(0.995, 0.985), fontsize=4.8, frameon=False,
|
|
250
|
+
handletextpad=0.35, labelspacing=0.28, borderpad=0.05,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
ax_d = fig.add_subplot(gs[2, :])
|
|
254
|
+
draw_metrics(ax_d, ensemble)
|
|
255
|
+
fig.subplots_adjust(left=0.012, right=0.994, top=0.980, bottom=0.025)
|
|
256
|
+
out = Path(args.output_prefix)
|
|
257
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
258
|
+
for suffix, kwargs in [(".png", {"dpi": 600}), (".pdf", {}), (".svg", {})]:
|
|
259
|
+
fig.savefig(out.with_suffix(suffix), bbox_inches="tight", **kwargs)
|
|
260
|
+
print(f"Saved: {out.with_suffix('.png')}")
|
|
261
|
+
print(f"Saved: {out.with_suffix('.pdf')}")
|
|
262
|
+
print(f"Saved: {out.with_suffix('.svg')}")
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
if __name__ == "__main__":
|
|
266
|
+
main()
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Render a faithful internal-architecture preview for MANIMOL.
|
|
3
|
+
|
|
4
|
+
This deliberately complements the workflow schematic in Figure 1: it shows
|
|
5
|
+
the trainable representations and decoder blocks rather than dataset flow or
|
|
6
|
+
evaluation. Labels reflect the current geometry-only MANIMOL implementation.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
import matplotlib as mpl
|
|
15
|
+
import matplotlib.pyplot as plt
|
|
16
|
+
from matplotlib.patches import FancyArrowPatch, FancyBboxPatch, Rectangle
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
PALETTE = {
|
|
21
|
+
"ink": "#313A46",
|
|
22
|
+
"muted": "#66717D",
|
|
23
|
+
"line": "#9DA8B5",
|
|
24
|
+
"light": "#F4F6F8",
|
|
25
|
+
"encoder": "#2E5EAA",
|
|
26
|
+
"encoder_light": "#E7EFFA",
|
|
27
|
+
"prior": "#7658A6",
|
|
28
|
+
"prior_light": "#F0EBF7",
|
|
29
|
+
"decoder": "#3F8175",
|
|
30
|
+
"decoder_light": "#E7F2F0",
|
|
31
|
+
"loss": "#F6F1E7",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def rounded_box(ax, xy, width, height, title, subtitle="", *, face, edge, title_size=8.0, sub_size=6.5,
|
|
36
|
+
lw=0.9, radius=0.018, title_color=None, title_ratio=None, sub_ratio=None):
|
|
37
|
+
patch = FancyBboxPatch(
|
|
38
|
+
xy,
|
|
39
|
+
width,
|
|
40
|
+
height,
|
|
41
|
+
boxstyle=f"round,pad=0.007,rounding_size={radius}",
|
|
42
|
+
linewidth=lw,
|
|
43
|
+
edgecolor=edge,
|
|
44
|
+
facecolor=face,
|
|
45
|
+
transform=ax.transAxes,
|
|
46
|
+
clip_on=False,
|
|
47
|
+
)
|
|
48
|
+
ax.add_patch(patch)
|
|
49
|
+
x, y = xy
|
|
50
|
+
title = title.replace(r"\n", "\n")
|
|
51
|
+
subtitle = subtitle.replace(r"\n", "\n")
|
|
52
|
+
if title_ratio is None:
|
|
53
|
+
title_ratio = 0.62 if subtitle else 0.50
|
|
54
|
+
if sub_ratio is None:
|
|
55
|
+
sub_ratio = 0.30
|
|
56
|
+
ax.text(
|
|
57
|
+
x + width / 2,
|
|
58
|
+
y + height * title_ratio,
|
|
59
|
+
title,
|
|
60
|
+
transform=ax.transAxes,
|
|
61
|
+
ha="center",
|
|
62
|
+
va="center",
|
|
63
|
+
fontsize=title_size,
|
|
64
|
+
fontweight="semibold",
|
|
65
|
+
color=title_color or PALETTE["ink"],
|
|
66
|
+
linespacing=1.15,
|
|
67
|
+
)
|
|
68
|
+
if subtitle:
|
|
69
|
+
ax.text(
|
|
70
|
+
x + width / 2,
|
|
71
|
+
y + height * sub_ratio,
|
|
72
|
+
subtitle,
|
|
73
|
+
transform=ax.transAxes,
|
|
74
|
+
ha="center",
|
|
75
|
+
va="center",
|
|
76
|
+
fontsize=sub_size,
|
|
77
|
+
color=PALETTE["muted"],
|
|
78
|
+
linespacing=1.18,
|
|
79
|
+
)
|
|
80
|
+
return patch
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def arrow(ax, start, end, *, color=None, lw=0.9, style="-|>", dashed=False, rad=0.0):
|
|
84
|
+
patch = FancyArrowPatch(
|
|
85
|
+
start,
|
|
86
|
+
end,
|
|
87
|
+
transform=ax.transAxes,
|
|
88
|
+
arrowstyle=style,
|
|
89
|
+
mutation_scale=8.5,
|
|
90
|
+
linewidth=lw,
|
|
91
|
+
linestyle="--" if dashed else "-",
|
|
92
|
+
color=color or PALETTE["line"],
|
|
93
|
+
connectionstyle=f"arc3,rad={rad}",
|
|
94
|
+
shrinkA=0,
|
|
95
|
+
shrinkB=0,
|
|
96
|
+
)
|
|
97
|
+
ax.add_patch(patch)
|
|
98
|
+
return patch
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def section_label(ax, x, text, color, width=0.28):
|
|
102
|
+
ax.text(x, 0.966, text, transform=ax.transAxes, ha="left", va="center", fontsize=9.2,
|
|
103
|
+
fontweight="bold", color=color)
|
|
104
|
+
ax.plot([x, x + width], [0.947, 0.947], transform=ax.transAxes, color=color, lw=1.6,
|
|
105
|
+
solid_capstyle="round")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def heatmap(ax, x, y, size, cmap="Purples"):
|
|
109
|
+
matrix = np.array(
|
|
110
|
+
[[0.00, 0.52, 0.16, 0.71, 0.24],
|
|
111
|
+
[0.52, 0.00, 0.66, 0.18, 0.48],
|
|
112
|
+
[0.16, 0.66, 0.00, 0.36, 0.81],
|
|
113
|
+
[0.71, 0.18, 0.36, 0.00, 0.57],
|
|
114
|
+
[0.24, 0.48, 0.81, 0.57, 0.00]])
|
|
115
|
+
ax.imshow(matrix, cmap=cmap, vmin=0, vmax=1, interpolation="nearest",
|
|
116
|
+
extent=(x, x + size, y, y + size), transform=ax.transAxes, zorder=5)
|
|
117
|
+
ax.add_patch(Rectangle((x, y), size, size, transform=ax.transAxes, fill=False,
|
|
118
|
+
linewidth=0.55, edgecolor=PALETTE["muted"], zorder=6))
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def draw_mode_tokens(ax, x, y, width, height):
|
|
122
|
+
labels = [r"$B_1$", r"$B_2$", r"$\cdots$", r"$B_M$"]
|
|
123
|
+
gap = 0.012
|
|
124
|
+
token_w = (width - gap * 3) / 4
|
|
125
|
+
for idx, label in enumerate(labels):
|
|
126
|
+
left = x + idx * (token_w + gap)
|
|
127
|
+
rounded_box(ax, (left, y), token_w, height, label, face="#FFFFFF", edge=PALETTE["prior"],
|
|
128
|
+
title_size=5.9, lw=0.75, radius=0.010, title_color=PALETTE["prior"])
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def draw_architecture(output: Path):
|
|
132
|
+
mpl.rcParams.update({
|
|
133
|
+
"font.family": "sans-serif",
|
|
134
|
+
"font.sans-serif": ["Arial", "Helvetica", "DejaVu Sans", "sans-serif"],
|
|
135
|
+
"font.size": 7,
|
|
136
|
+
"mathtext.fontset": "dejavusans",
|
|
137
|
+
"svg.fonttype": "none",
|
|
138
|
+
"pdf.fonttype": 42,
|
|
139
|
+
"axes.linewidth": 0.6,
|
|
140
|
+
})
|
|
141
|
+
# 183 mm double-column width, with the same compact aspect ratio in every
|
|
142
|
+
# export so the preview reflects journal-scale readability.
|
|
143
|
+
fig = plt.figure(figsize=(7.20, 3.30), facecolor="white")
|
|
144
|
+
ax = fig.add_axes([0.015, 0.025, 0.97, 0.95])
|
|
145
|
+
ax.set_axis_off()
|
|
146
|
+
ax.set_xlim(0, 1)
|
|
147
|
+
ax.set_ylim(0, 1)
|
|
148
|
+
|
|
149
|
+
# Figure contract: a neural architecture schematic with P_theta(G) as the
|
|
150
|
+
# hero, backed by the encoder and the probability-conditioned decoder.
|
|
151
|
+
section_label(ax, 0.035, "Molecular representation encoder", PALETTE["encoder"], 0.275)
|
|
152
|
+
section_label(ax, 0.370, "Probability graph encoder", PALETTE["prior"], 0.250)
|
|
153
|
+
section_label(ax, 0.704, "P-conditioned conformer decoder", PALETTE["decoder"], 0.245)
|
|
154
|
+
|
|
155
|
+
# Left: exact Stage-I 2D graph features and GIN encoder.
|
|
156
|
+
rounded_box(
|
|
157
|
+
ax, (0.035, 0.760), 0.255, 0.115,
|
|
158
|
+
r"Input 2D molecular graph $G=(V,E)$",
|
|
159
|
+
r"node features: $h_i$ bond features: $e_{ij}$\n"
|
|
160
|
+
r"topological pair features: $g_{ij}$",
|
|
161
|
+
face=PALETTE["light"], edge=PALETTE["line"], title_size=7.5, sub_size=5.5,
|
|
162
|
+
)
|
|
163
|
+
arrow(ax, (0.162, 0.755), (0.162, 0.692), color=PALETTE["encoder"])
|
|
164
|
+
rounded_box(
|
|
165
|
+
ax, (0.035, 0.525), 0.255, 0.158,
|
|
166
|
+
r"Graph message-passing encoder $\times 4$",
|
|
167
|
+
r"GIN layers: message $\rightarrow$ aggregate $\rightarrow$ update\n"
|
|
168
|
+
r"$\{h_i,e_{ij}\}\;\mapsto\;\{h_i^{\prime}\}$",
|
|
169
|
+
face=PALETTE["encoder_light"], edge=PALETTE["encoder"], title_size=7.4, sub_size=5.5,
|
|
170
|
+
title_color=PALETTE["encoder"],
|
|
171
|
+
)
|
|
172
|
+
arrow(ax, (0.162, 0.520), (0.162, 0.458), color=PALETTE["encoder"])
|
|
173
|
+
rounded_box(
|
|
174
|
+
ax, (0.035, 0.362), 0.255, 0.085,
|
|
175
|
+
r"Atom embeddings $\{h_i\}_{i=1}^{N}$",
|
|
176
|
+
r"graph embedding $h_G=\mathrm{MeanPool}(\{h_i\})$",
|
|
177
|
+
face="#FFFFFF", edge=PALETTE["encoder"], title_size=7.0, sub_size=5.4,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
# Middle: P_theta as hero, with exact pair construction.
|
|
181
|
+
arrow(ax, (0.295, 0.405), (0.365, 0.780), color=PALETTE["prior"], lw=1.1, rad=0.08)
|
|
182
|
+
rounded_box(
|
|
183
|
+
ax, (0.370, 0.705), 0.270, 0.150,
|
|
184
|
+
r"Invariant pair construction",
|
|
185
|
+
r"$z_{ij}=[h_i,h_j,|h_i-h_j|,h_i\odot h_j,g_{ij}]$\n"
|
|
186
|
+
r"all atom pairs $(i,j)$",
|
|
187
|
+
face=PALETTE["prior_light"], edge=PALETTE["prior"], title_size=7.3, sub_size=5.4,
|
|
188
|
+
title_color=PALETTE["prior"],
|
|
189
|
+
)
|
|
190
|
+
arrow(ax, (0.505, 0.700), (0.505, 0.636), color=PALETTE["prior"])
|
|
191
|
+
rounded_box(
|
|
192
|
+
ax, (0.370, 0.545), 0.270, 0.080,
|
|
193
|
+
r"Pairwise MLP + sigmoid",
|
|
194
|
+
r"$z_{ij}\mapsto p_{ij}\in(0,1)$",
|
|
195
|
+
face="#FFFFFF", edge=PALETTE["prior"], title_size=7.1, sub_size=5.5,
|
|
196
|
+
title_color=PALETTE["prior"],
|
|
197
|
+
)
|
|
198
|
+
arrow(ax, (0.505, 0.540), (0.505, 0.476), color=PALETTE["prior"])
|
|
199
|
+
rounded_box(
|
|
200
|
+
ax, (0.370, 0.326), 0.270, 0.138,
|
|
201
|
+
r"Learned probability graph $P_\theta(G)$",
|
|
202
|
+
r"symmetric $N\times N$ atom-pair proximity prior\n"
|
|
203
|
+
r"supervision: $\mathcal{L}_{\mathrm{prob}}=\mathrm{BCE}(P_\theta,Q)$",
|
|
204
|
+
face=PALETTE["prior_light"], edge=PALETTE["prior"], title_size=7.1, sub_size=5.2,
|
|
205
|
+
title_color=PALETTE["prior"],
|
|
206
|
+
)
|
|
207
|
+
heatmap(ax, 0.570, 0.347, 0.048, cmap="Purples")
|
|
208
|
+
arrow(ax, (0.505, 0.321), (0.505, 0.259), color=PALETTE["prior"])
|
|
209
|
+
rounded_box(
|
|
210
|
+
ax, (0.370, 0.137), 0.270, 0.105,
|
|
211
|
+
r"P-guided torsion context",
|
|
212
|
+
r"cross-fragment statistics $\rightarrow$ mode conditions",
|
|
213
|
+
face="#FFFFFF", edge=PALETTE["prior"], title_size=6.9, sub_size=5.0,
|
|
214
|
+
title_color=PALETTE["prior"], title_ratio=0.78, sub_ratio=0.54,
|
|
215
|
+
)
|
|
216
|
+
draw_mode_tokens(ax, 0.391, 0.145, 0.229, 0.030)
|
|
217
|
+
|
|
218
|
+
# Right: actual P-basin-conditioned coordinate/torsion blocks.
|
|
219
|
+
arrow(ax, (0.645, 0.430), (0.700, 0.790), color=PALETTE["prior"], lw=1.0, rad=-0.12)
|
|
220
|
+
rounded_box(
|
|
221
|
+
ax, (0.705, 0.740), 0.255, 0.105,
|
|
222
|
+
r"Mode-specific probability map $P_m$",
|
|
223
|
+
r"$P_\theta(G)$ + mode residual $\Delta P(z_m,z_{ij})$",
|
|
224
|
+
face=PALETTE["decoder_light"], edge=PALETTE["decoder"], title_size=7.0, sub_size=5.2,
|
|
225
|
+
title_color=PALETTE["decoder"],
|
|
226
|
+
)
|
|
227
|
+
arrow(ax, (0.832, 0.735), (0.832, 0.671), color=PALETTE["decoder"])
|
|
228
|
+
rounded_box(
|
|
229
|
+
ax, (0.705, 0.550), 0.255, 0.110,
|
|
230
|
+
r"P-conditioned coordinate block $\times 2$",
|
|
231
|
+
r"$h_i,\;P_m,\;z_m,\;e_{ij}\;\mapsto\;Y^{(0)}$\n"
|
|
232
|
+
r"mode-pair attention (Q/K/V) + bond bias",
|
|
233
|
+
face="#FFFFFF", edge=PALETTE["decoder"], title_size=6.9, sub_size=5.1,
|
|
234
|
+
title_color=PALETTE["decoder"],
|
|
235
|
+
)
|
|
236
|
+
arrow(ax, (0.832, 0.545), (0.832, 0.481), color=PALETTE["decoder"])
|
|
237
|
+
rounded_box(
|
|
238
|
+
ax, (0.705, 0.355), 0.255, 0.115,
|
|
239
|
+
r"Torsion residual head",
|
|
240
|
+
r"local torsion neighborhoods $\mapsto\;\Delta\theta_1,\ldots,\Delta\theta_R$\n"
|
|
241
|
+
r"$Y^{(t+1)}=\mathrm{Rotate}(Y^{(t)},\Delta\theta)$",
|
|
242
|
+
face=PALETTE["decoder_light"], edge=PALETTE["decoder"], title_size=7.0, sub_size=5.05,
|
|
243
|
+
title_color=PALETTE["decoder"],
|
|
244
|
+
)
|
|
245
|
+
arrow(ax, (0.832, 0.350), (0.832, 0.286), color=PALETTE["decoder"])
|
|
246
|
+
rounded_box(
|
|
247
|
+
ax, (0.705, 0.155), 0.255, 0.120,
|
|
248
|
+
r"Iterative geometry refinement $\times T$",
|
|
249
|
+
r"probability-weighted EGNN updates\n"
|
|
250
|
+
r"generated candidates $\{Y_m\}_{m=1}^{M}$",
|
|
251
|
+
face="#FFFFFF", edge=PALETTE["decoder"], title_size=7.0, sub_size=5.1,
|
|
252
|
+
title_color=PALETTE["decoder"],
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
# Bottom training-only objective. Dashed connections avoid turning this
|
|
256
|
+
# into a second pipeline figure.
|
|
257
|
+
rounded_box(
|
|
258
|
+
ax, (0.105, 0.026), 0.780, 0.070,
|
|
259
|
+
r"Training loss: $\mathcal{L}=\lambda_P\mathcal{L}_{\mathrm{prob}}+\mathcal{L}_{\mathrm{torsion}}+\mathcal{L}_{\mathrm{refine}}+\mathcal{L}_{\mathrm{chem}}$",
|
|
260
|
+
r"Dashed links: training supervision only.",
|
|
261
|
+
face=PALETTE["loss"], edge="#C5B696", title_size=6.9, sub_size=5.0, lw=0.8,
|
|
262
|
+
)
|
|
263
|
+
arrow(ax, (0.505, 0.133), (0.505, 0.100), color="#B9A77B", dashed=True, lw=0.8)
|
|
264
|
+
arrow(ax, (0.830, 0.150), (0.830, 0.100), color="#B9A77B", dashed=True, lw=0.8)
|
|
265
|
+
|
|
266
|
+
# Architecture-specific clarification, kept concise and inside the source
|
|
267
|
+
# so the preview does not imply coordinates are Stage-I inputs.
|
|
268
|
+
ax.text(0.035, 0.113, "Stage I uses 2D topology; 3D coordinates enter only in the decoder.",
|
|
269
|
+
transform=ax.transAxes, fontsize=5.2, color=PALETTE["muted"], ha="left", va="center")
|
|
270
|
+
|
|
271
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
272
|
+
fig.savefig(output.with_suffix(".png"), dpi=600, facecolor="white")
|
|
273
|
+
fig.savefig(output.with_suffix(".pdf"), facecolor="white")
|
|
274
|
+
fig.savefig(output.with_suffix(".svg"), facecolor="white")
|
|
275
|
+
fig.savefig(output.with_suffix(".tiff"), dpi=600, facecolor="white")
|
|
276
|
+
plt.close(fig)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def main():
|
|
280
|
+
parser = argparse.ArgumentParser(description="Render MANIMOL internal architecture preview.")
|
|
281
|
+
parser.add_argument(
|
|
282
|
+
"--output",
|
|
283
|
+
default="outputs/architecture_preview/manimol_internal_architecture_preview",
|
|
284
|
+
help="Output stem without extension.",
|
|
285
|
+
)
|
|
286
|
+
args = parser.parse_args()
|
|
287
|
+
draw_architecture(Path(args.output))
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
if __name__ == "__main__":
|
|
291
|
+
main()
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""Measure whether different basin conditions change the flow endpoint."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
import argparse, json, sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import torch
|
|
7
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
8
|
+
from geomanimol.data import load_molecule_groups
|
|
9
|
+
from geomanimol.residual import etkdg_scaffold
|
|
10
|
+
from geomanimol.torsion_flow import TorsionFlowGeoManimol
|
|
11
|
+
from geomanimol.torsion_residual import torsion_defs, torsions_from_coords, wrap_angle
|
|
12
|
+
|
|
13
|
+
def main():
|
|
14
|
+
p = argparse.ArgumentParser()
|
|
15
|
+
p.add_argument('--test', default='data/geom_drugs_geomol_top20/geom_drugs_geomol_top20_debug_val.pt')
|
|
16
|
+
p.add_argument('--checkpoint', default='outputs/geomanimol/flow_expert_debug_checkpoint.pt')
|
|
17
|
+
p.add_argument('--molecules', type=int, default=20)
|
|
18
|
+
p.add_argument('--steps', type=int, default=20)
|
|
19
|
+
p.add_argument('--output', default='outputs/geomanimol/flow_basin_intervention.json')
|
|
20
|
+
a = p.parse_args()
|
|
21
|
+
groups = load_molecule_groups(a.test, a.molecules)
|
|
22
|
+
ck = torch.load(a.checkpoint, map_location='cpu', weights_only=False)
|
|
23
|
+
cfg = ck['args']
|
|
24
|
+
model = TorsionFlowGeoManimol(cfg['node_dim'], cfg['n_basins'], cfg['manifold_dim'], cfg.get('assignment_weight', .5), cfg.get('basin_weight', .2))
|
|
25
|
+
model.load_state_dict(ck['model']); model.eval()
|
|
26
|
+
rows = []
|
|
27
|
+
for mol in groups:
|
|
28
|
+
defs = torsion_defs(mol['mol'])
|
|
29
|
+
if not defs:
|
|
30
|
+
continue
|
|
31
|
+
scaffold = etkdg_scaffold(mol['mol'], 41000 + mol['mol_id'])
|
|
32
|
+
_, _, _, z, _, _ = model._condition(mol, scaffold, defs)
|
|
33
|
+
outputs = []
|
|
34
|
+
for k in range(len(z)):
|
|
35
|
+
# Use one sample with an explicit basin condition by replacing the
|
|
36
|
+
# model's sampled mode through a temporary condition intervention.
|
|
37
|
+
source = torsions_from_coords(mol['mol'], scaffold, defs) / torch.pi
|
|
38
|
+
_, hg, _, _, _, pairs = model._condition(mol, scaffold, defs)
|
|
39
|
+
x = source.clone(); dt = 1.0 / max(1, a.steps)
|
|
40
|
+
for step in range(a.steps):
|
|
41
|
+
t = torch.tensor(step * dt)
|
|
42
|
+
x = (x + dt * model.flow_fields[k](x, t, pairs, hg, z[k])).clamp(-1, 1)
|
|
43
|
+
outputs.append(x)
|
|
44
|
+
pairwise = []
|
|
45
|
+
for i in range(len(outputs)):
|
|
46
|
+
for j in range(i + 1, len(outputs)):
|
|
47
|
+
pairwise.append(float(torch.mean(torch.abs(wrap_angle((outputs[i] - outputs[j]) * torch.pi)))))
|
|
48
|
+
rows.append({'mol_id': int(mol['mol_id']), 'mean_pairwise_torsion_distance_rad': sum(pairwise) / max(1, len(pairwise))})
|
|
49
|
+
result = {'molecules': len(rows), 'basins': int(cfg['n_basins']), 'steps': a.steps, 'rows': rows,
|
|
50
|
+
'mean_pairwise_torsion_distance_rad': sum(r['mean_pairwise_torsion_distance_rad'] for r in rows) / max(1, len(rows))}
|
|
51
|
+
Path(a.output).parent.mkdir(parents=True, exist_ok=True)
|
|
52
|
+
Path(a.output).write_text(json.dumps(result, indent=2), encoding='utf-8')
|
|
53
|
+
print(result)
|
|
54
|
+
if __name__ == '__main__': main()
|