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,1117 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Independent u/v-aware inference; the legacy entry point is untouched."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import sys
|
|
7
|
+
from argparse import ArgumentParser
|
|
8
|
+
|
|
9
|
+
import torch
|
|
10
|
+
|
|
11
|
+
import infer_base_conformers
|
|
12
|
+
import infer_torsion
|
|
13
|
+
from pgraph_controls import controlled_pglobal
|
|
14
|
+
from models.model0 import GNNEncoder, _torsion_rows, apply_torsion_residuals, torsion_angles
|
|
15
|
+
from train_torsional_denoiser import NoiseTorsionDenoiser, load_base_model, noised_conformer
|
|
16
|
+
from models.mean_dispersion_torsion_context import controlled_dispersion_for_width
|
|
17
|
+
from models.mean_dispersion_torsion_context import mean_dispersion_torsion_context
|
|
18
|
+
from models.mean_dispersion_torsion_context import dispersion_torsion_widths
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class DenoiseWrapper:
|
|
22
|
+
def __init__(self, base_model, denoiser, post_denoiser=None, pbasin_model=None, torsion_manifold_prior=None):
|
|
23
|
+
self.base_model = base_model
|
|
24
|
+
self.denoiser = denoiser
|
|
25
|
+
self.post_denoiser = post_denoiser
|
|
26
|
+
self.pbasin_model = pbasin_model
|
|
27
|
+
self.torsion_manifold_prior = torsion_manifold_prior
|
|
28
|
+
self.num_modes = 10
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def parse_denoise_args():
|
|
32
|
+
parser = ArgumentParser(add_help=False)
|
|
33
|
+
parser.add_argument("--base_checkpoint", type=str, required=True)
|
|
34
|
+
parser.add_argument(
|
|
35
|
+
"--denoiser_checkpoint",
|
|
36
|
+
type=str,
|
|
37
|
+
default="",
|
|
38
|
+
help="Optional denoiser checkpoint; omit only with --pbasin_only for Stage-II-only inference.",
|
|
39
|
+
)
|
|
40
|
+
parser.add_argument("--denoise_steps", type=int, default=10)
|
|
41
|
+
parser.add_argument("--denoise_sigma_max", type=float, default=0.75)
|
|
42
|
+
parser.add_argument("--denoise_sigma_min", type=float, default=0.05)
|
|
43
|
+
parser.add_argument("--denoise_step_scale", type=float, default=1.0)
|
|
44
|
+
parser.add_argument("--denoise_initial_noise", type=float, default=0.75)
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"--pbasin_only",
|
|
47
|
+
action="store_true",
|
|
48
|
+
help="Generate every learned candidate with the Stage-II/P-basin branch, disabling denoiser sampling.",
|
|
49
|
+
)
|
|
50
|
+
parser.add_argument(
|
|
51
|
+
"--denoise_polish_steps",
|
|
52
|
+
type=int,
|
|
53
|
+
default=0,
|
|
54
|
+
help="Extra low-noise denoising steps after the normal schedule.",
|
|
55
|
+
)
|
|
56
|
+
parser.add_argument("--denoise_polish_sigma", type=float, default=0.03)
|
|
57
|
+
parser.add_argument("--denoise_polish_step_scale", type=float, default=0.35)
|
|
58
|
+
parser.add_argument(
|
|
59
|
+
"--denoise_precision_fraction",
|
|
60
|
+
type=float,
|
|
61
|
+
default=0.0,
|
|
62
|
+
help=(
|
|
63
|
+
"Fraction of candidates sampled with a lower-noise precision schedule. "
|
|
64
|
+
"This keeps the candidate budget unchanged while mixing coverage and accuracy hypotheses."
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
parser.add_argument("--denoise_precision_steps", type=int, default=0)
|
|
68
|
+
parser.add_argument("--denoise_precision_sigma_max", type=float, default=0.45)
|
|
69
|
+
parser.add_argument("--denoise_precision_sigma_min", type=float, default=0.02)
|
|
70
|
+
parser.add_argument("--denoise_precision_step_scale", type=float, default=0.65)
|
|
71
|
+
parser.add_argument("--denoise_precision_initial_noise", type=float, default=0.45)
|
|
72
|
+
parser.add_argument(
|
|
73
|
+
"--post_denoiser_checkpoint",
|
|
74
|
+
type=str,
|
|
75
|
+
default="",
|
|
76
|
+
help="Optional candidate-level denoiser used only as a post-generation local corrector.",
|
|
77
|
+
)
|
|
78
|
+
parser.add_argument("--post_denoise_steps", type=int, default=0)
|
|
79
|
+
parser.add_argument("--post_denoise_sigma", type=float, default=0.02)
|
|
80
|
+
parser.add_argument("--post_denoise_step_scale", type=float, default=0.35)
|
|
81
|
+
parser.add_argument(
|
|
82
|
+
"--final_snap_steps",
|
|
83
|
+
type=int,
|
|
84
|
+
default=0,
|
|
85
|
+
help="Add low-noise torsion-snap variants to the generated candidate pool before final selection.",
|
|
86
|
+
)
|
|
87
|
+
parser.add_argument("--final_snap_sigma", type=float, default=0.012)
|
|
88
|
+
parser.add_argument("--final_snap_step_scale", type=float, default=0.18)
|
|
89
|
+
parser.add_argument("--final_snap_max_candidates", type=int, default=0)
|
|
90
|
+
parser.add_argument("--final_snap_use_post_denoiser", action="store_true")
|
|
91
|
+
parser.add_argument("--final_snap_keep_original", action="store_true")
|
|
92
|
+
parser.add_argument("--torsion_mode_max", type=int, default=64)
|
|
93
|
+
parser.add_argument(
|
|
94
|
+
"--use_dispersion_proposal",
|
|
95
|
+
action="store_true",
|
|
96
|
+
help="Use Stage-I P_disp to modulate torsion-noise and residual widths.",
|
|
97
|
+
)
|
|
98
|
+
parser.add_argument("--dispersion_width_scale", type=float, default=0.35)
|
|
99
|
+
parser.add_argument("--dispersion_width_min", type=float, default=0.5)
|
|
100
|
+
parser.add_argument("--dispersion_width_max", type=float, default=2.0)
|
|
101
|
+
parser.add_argument("--dispersion_control", type=str, default="normal", choices=["normal", "shuffle", "constant", "random"])
|
|
102
|
+
parser.add_argument("--dispersion_seed", type=int, default=20260913)
|
|
103
|
+
parser.add_argument(
|
|
104
|
+
"--torsion_manifold_prior_path",
|
|
105
|
+
type=str,
|
|
106
|
+
default="",
|
|
107
|
+
help="Optional graph-conditioned torsion-mixture prior used for proposal and/or compact-set selection.",
|
|
108
|
+
)
|
|
109
|
+
parser.add_argument(
|
|
110
|
+
"--torsion_manifold_proposal_fraction",
|
|
111
|
+
type=float,
|
|
112
|
+
default=0.0,
|
|
113
|
+
help="Fraction of the denoise branch initialized from torsion-manifold mixture prototypes.",
|
|
114
|
+
)
|
|
115
|
+
parser.add_argument(
|
|
116
|
+
"--torsion_manifold_proposal_strength",
|
|
117
|
+
type=float,
|
|
118
|
+
default=0.55,
|
|
119
|
+
help="Circular interpolation strength from an ETKDG seed toward a mixture torsion prototype.",
|
|
120
|
+
)
|
|
121
|
+
parser.add_argument(
|
|
122
|
+
"--torsion_manifold_proposal_noise",
|
|
123
|
+
type=float,
|
|
124
|
+
default=0.18,
|
|
125
|
+
help="Per-torsion Gaussian perturbation (radians) around a mixture prototype.",
|
|
126
|
+
)
|
|
127
|
+
parser.add_argument(
|
|
128
|
+
"--torsion_manifold_proposal_denoise_noise_scale",
|
|
129
|
+
type=float,
|
|
130
|
+
default=0.50,
|
|
131
|
+
help="Multiplier for initial torsion noise on mixture-initialized candidates.",
|
|
132
|
+
)
|
|
133
|
+
parser.add_argument(
|
|
134
|
+
"--torsion_manifold_p_context_control",
|
|
135
|
+
type=str,
|
|
136
|
+
default="normal",
|
|
137
|
+
choices=["normal", "zero", "shuffle"],
|
|
138
|
+
help="Control only the Stage-1 P-to-torsion bridge; it does not alter denoiser conditioning.",
|
|
139
|
+
)
|
|
140
|
+
parser.add_argument(
|
|
141
|
+
"--manifold_use_mode_p",
|
|
142
|
+
action="store_true",
|
|
143
|
+
help="Use the P-basin checkpoint's learned mode-specific probability graph during torsion decoding.",
|
|
144
|
+
)
|
|
145
|
+
parser.add_argument("--torsion_base_method", type=str, default="etkdg", choices=["etkdg", "rdkit_dg", "random3d"])
|
|
146
|
+
parser.add_argument("--torsion_base_confs", type=int, default=0)
|
|
147
|
+
parser.add_argument(
|
|
148
|
+
"--pbasin_checkpoint",
|
|
149
|
+
type=str,
|
|
150
|
+
default="",
|
|
151
|
+
help="Optional P-basin Stage-2 checkpoint mixed into the denoise candidate pool.",
|
|
152
|
+
)
|
|
153
|
+
parser.add_argument(
|
|
154
|
+
"--pbasin_fraction",
|
|
155
|
+
type=float,
|
|
156
|
+
default=0.0,
|
|
157
|
+
help="Fraction of the model candidate budget allocated to P-basin torsion candidates.",
|
|
158
|
+
)
|
|
159
|
+
parser.add_argument(
|
|
160
|
+
"--pbudget_adaptive",
|
|
161
|
+
action="store_true",
|
|
162
|
+
help=(
|
|
163
|
+
"Let the Stage-1 probability graph decide the denoise/P-basin candidate split. "
|
|
164
|
+
"This is useful for low-budget ablations where P should control mode allocation."
|
|
165
|
+
),
|
|
166
|
+
)
|
|
167
|
+
parser.add_argument("--pbudget_min_fraction", type=float, default=0.15)
|
|
168
|
+
parser.add_argument("--pbudget_max_fraction", type=float, default=0.75)
|
|
169
|
+
parser.add_argument(
|
|
170
|
+
"--pbudget_confidence_scale",
|
|
171
|
+
type=float,
|
|
172
|
+
default=3.0,
|
|
173
|
+
help="Scale applied to the P-graph contrast before mapping it to a P-basin budget.",
|
|
174
|
+
)
|
|
175
|
+
parser.add_argument("--pbasin_iterative_torsion_steps", type=int, default=3)
|
|
176
|
+
parser.add_argument("--pbasin_iterative_torsion_delta_scale", type=float, default=0.8)
|
|
177
|
+
parser.add_argument("--pbasin_torsion_base_confs", type=int, default=0)
|
|
178
|
+
parser.add_argument(
|
|
179
|
+
"--pbasin_anchor_gate",
|
|
180
|
+
action="store_true",
|
|
181
|
+
help=(
|
|
182
|
+
"Use P-basin candidates as reference-free manifold anchors and keep only denoise "
|
|
183
|
+
"candidates close to those anchors in internal pair-distance space."
|
|
184
|
+
),
|
|
185
|
+
)
|
|
186
|
+
parser.add_argument("--pbasin_anchor_gate_keep_fraction", type=float, default=1.0)
|
|
187
|
+
parser.add_argument("--pbasin_anchor_gate_threshold", type=float, default=-1.0)
|
|
188
|
+
parser.add_argument("--pbasin_anchor_gate_min_keep_fraction", type=float, default=0.35)
|
|
189
|
+
parser.add_argument("--pbasin_anchor_gate_max_anchors", type=int, default=256)
|
|
190
|
+
parser.add_argument(
|
|
191
|
+
"--disable_stage1_pglobal",
|
|
192
|
+
action="store_true",
|
|
193
|
+
help="Ablation: replace the Stage-1 probability map P_global with zeros during denoising.",
|
|
194
|
+
)
|
|
195
|
+
parser.add_argument(
|
|
196
|
+
"--disable_probability_guidance",
|
|
197
|
+
action="store_true",
|
|
198
|
+
help=(
|
|
199
|
+
"Strict inference-only ablation. Disable every probability-guided path: "
|
|
200
|
+
"the P-basin branch, adaptive P-budget allocation, P-conditioned torsion "
|
|
201
|
+
"updates, P-aware manifold proposals, and P terms in final-pool refinement. "
|
|
202
|
+
"Candidate count and all non-probabilistic post-processing remain unchanged."
|
|
203
|
+
),
|
|
204
|
+
)
|
|
205
|
+
parser.add_argument(
|
|
206
|
+
"--pglobal_control",
|
|
207
|
+
type=str,
|
|
208
|
+
default="normal",
|
|
209
|
+
choices=["normal", "zero", "constant", "topology", "random", "shuffle", "noisy"],
|
|
210
|
+
help=(
|
|
211
|
+
"Control ablation for the Stage-1 probability map. "
|
|
212
|
+
"'shuffle' preserves the map values but destroys atom-pair alignment; "
|
|
213
|
+
"'random' preserves only a symmetric random control; 'noisy' perturbs P."
|
|
214
|
+
),
|
|
215
|
+
)
|
|
216
|
+
parser.add_argument("--pglobal_noise_std", type=float, default=0.15)
|
|
217
|
+
parser.add_argument("--pglobal_seed", type=int, default=20260715)
|
|
218
|
+
parser.add_argument("--pglobal_topology_scale", type=float, default=1.5)
|
|
219
|
+
parser.add_argument("--pglobal_topology_mapping", type=str, default="")
|
|
220
|
+
parser.add_argument(
|
|
221
|
+
"--inference_seed",
|
|
222
|
+
type=int,
|
|
223
|
+
default=-1,
|
|
224
|
+
help="Per-molecule deterministic seed for controlled P experiments; negative keeps legacy RNG behavior.",
|
|
225
|
+
)
|
|
226
|
+
parser.add_argument(
|
|
227
|
+
"--stage1_kernel",
|
|
228
|
+
type=str,
|
|
229
|
+
default="umap",
|
|
230
|
+
choices=[
|
|
231
|
+
"umap",
|
|
232
|
+
"gaussian",
|
|
233
|
+
"laplacian",
|
|
234
|
+
"student",
|
|
235
|
+
"cauchy",
|
|
236
|
+
"rational_quadratic",
|
|
237
|
+
"inverse_multiquadric",
|
|
238
|
+
"matern32",
|
|
239
|
+
"matern52",
|
|
240
|
+
"triweight",
|
|
241
|
+
"logistic",
|
|
242
|
+
],
|
|
243
|
+
help="Probability-graph kernel forwarded to P-conditioned projection/refinement ablations.",
|
|
244
|
+
)
|
|
245
|
+
exp_args, remaining = parser.parse_known_args()
|
|
246
|
+
return exp_args, remaining
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _pgraph_budget_fraction(P, args):
|
|
250
|
+
min_fraction = max(0.0, min(0.95, float(getattr(args, "pbudget_min_fraction", 0.15))))
|
|
251
|
+
max_fraction = max(min_fraction, min(0.95, float(getattr(args, "pbudget_max_fraction", 0.75))))
|
|
252
|
+
if P is None or P.numel() == 0:
|
|
253
|
+
return min_fraction
|
|
254
|
+
mask = torch.triu(torch.ones_like(P, dtype=torch.bool), diagonal=1)
|
|
255
|
+
vals = P[mask]
|
|
256
|
+
vals = vals[torch.isfinite(vals)]
|
|
257
|
+
if vals.numel() < 4:
|
|
258
|
+
return min_fraction
|
|
259
|
+
vals = vals.detach().float()
|
|
260
|
+
contrast = torch.quantile(vals, 0.90) - torch.quantile(vals, 0.10)
|
|
261
|
+
contrast = torch.clamp(contrast, min=0.0)
|
|
262
|
+
scale = max(0.0, float(getattr(args, "pbudget_confidence_scale", 3.0)))
|
|
263
|
+
confidence = 1.0 - torch.exp(-scale * contrast)
|
|
264
|
+
confidence = float(torch.clamp(confidence, 0.0, 1.0).item())
|
|
265
|
+
return min_fraction + (max_fraction - min_fraction) * confidence
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _symmetrize_pglobal(P):
|
|
269
|
+
P = 0.5 * (P + P.t())
|
|
270
|
+
if P.numel() > 0:
|
|
271
|
+
P = P.clone()
|
|
272
|
+
P.fill_diagonal_(0.0)
|
|
273
|
+
return P
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _controlled_pglobal(P, args):
|
|
277
|
+
if P is None:
|
|
278
|
+
return None
|
|
279
|
+
if bool(getattr(args, "disable_stage1_pglobal", False)):
|
|
280
|
+
return torch.zeros_like(P)
|
|
281
|
+
|
|
282
|
+
mode = str(getattr(args, "pglobal_control", "normal") or "normal").lower()
|
|
283
|
+
if mode == "normal":
|
|
284
|
+
return P
|
|
285
|
+
if mode == "zero":
|
|
286
|
+
return torch.zeros_like(P)
|
|
287
|
+
|
|
288
|
+
seed = int(getattr(args, "pglobal_seed", 20260715))
|
|
289
|
+
seed = (seed + int(P.numel()) * 1009 + int(P.shape[0]) * 9173) % (2**31 - 1)
|
|
290
|
+
gen = torch.Generator(device=P.device)
|
|
291
|
+
gen.manual_seed(seed)
|
|
292
|
+
|
|
293
|
+
if mode == "shuffle":
|
|
294
|
+
perm = torch.randperm(P.shape[0], generator=gen, device=P.device)
|
|
295
|
+
return _symmetrize_pglobal(P[perm][:, perm])
|
|
296
|
+
|
|
297
|
+
if mode == "random":
|
|
298
|
+
R = torch.rand(P.shape, generator=gen, device=P.device, dtype=P.dtype)
|
|
299
|
+
mask = torch.triu(torch.ones_like(P, dtype=torch.bool), diagonal=1)
|
|
300
|
+
vals = P[mask]
|
|
301
|
+
vals = vals[torch.isfinite(vals)]
|
|
302
|
+
if vals.numel() > 1:
|
|
303
|
+
lo = torch.quantile(vals.detach().float(), 0.05).to(P.dtype)
|
|
304
|
+
hi = torch.quantile(vals.detach().float(), 0.95).to(P.dtype)
|
|
305
|
+
R = lo + (hi - lo).clamp_min(1e-6) * R
|
|
306
|
+
return _symmetrize_pglobal(R.clamp(0.0, 1.0))
|
|
307
|
+
|
|
308
|
+
if mode == "noisy":
|
|
309
|
+
std = max(0.0, float(getattr(args, "pglobal_noise_std", 0.15)))
|
|
310
|
+
noise = torch.randn(P.shape, generator=gen, device=P.device, dtype=P.dtype) * std
|
|
311
|
+
return _symmetrize_pglobal((P + noise).clamp(0.0, 1.0))
|
|
312
|
+
|
|
313
|
+
return P
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def _proposal_widths(P_disp, mol, torsion_index, args, max_torsions, device, dtype):
|
|
317
|
+
# Keep the unmodified and intervention-controlled proposal maps
|
|
318
|
+
# separately so a smoke test can audit the bond-level consequence of
|
|
319
|
+
# pairwise dispersion interventions.
|
|
320
|
+
original_widths, original_scores, original_valid = dispersion_torsion_widths(
|
|
321
|
+
P_disp,
|
|
322
|
+
mol,
|
|
323
|
+
torsion_index,
|
|
324
|
+
max_torsions,
|
|
325
|
+
scale=float(getattr(args, "dispersion_width_scale", 0.35)),
|
|
326
|
+
min_width=float(getattr(args, "dispersion_width_min", 0.5)),
|
|
327
|
+
max_width=float(getattr(args, "dispersion_width_max", 2.0)),
|
|
328
|
+
)
|
|
329
|
+
used_P_disp = controlled_dispersion_for_width(P_disp, args)
|
|
330
|
+
widths, scores, valid = dispersion_torsion_widths(
|
|
331
|
+
used_P_disp,
|
|
332
|
+
mol,
|
|
333
|
+
torsion_index,
|
|
334
|
+
max_torsions,
|
|
335
|
+
scale=float(getattr(args, "dispersion_width_scale", 0.35)),
|
|
336
|
+
min_width=float(getattr(args, "dispersion_width_min", 0.5)),
|
|
337
|
+
max_width=float(getattr(args, "dispersion_width_max", 2.0)),
|
|
338
|
+
)
|
|
339
|
+
if not bool(getattr(args, "use_dispersion_proposal", False)):
|
|
340
|
+
widths = torch.ones_like(widths)
|
|
341
|
+
# These attributes are consumed only by the diagnostic cache. The
|
|
342
|
+
# function return signature remains unchanged for legacy callers.
|
|
343
|
+
_proposal_widths.last_original_widths = original_widths
|
|
344
|
+
_proposal_widths.last_original_scores = original_scores
|
|
345
|
+
_proposal_widths.last_original_valid = original_valid
|
|
346
|
+
_proposal_widths.last_used_widths = widths
|
|
347
|
+
_proposal_widths.last_used_scores = scores
|
|
348
|
+
_proposal_widths.last_used_valid = valid
|
|
349
|
+
return widths.to(device=device, dtype=dtype), scores, valid
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def load_denoiser(path, device):
|
|
353
|
+
ckpt = torch.load(path, map_location=device)
|
|
354
|
+
hidden_dim = int(ckpt.get("hidden_dim", 128))
|
|
355
|
+
max_delta = float(ckpt.get("max_delta", 0.8))
|
|
356
|
+
model = NoiseTorsionDenoiser(
|
|
357
|
+
hidden_dim=hidden_dim,
|
|
358
|
+
max_delta=max_delta,
|
|
359
|
+
backbone=str(ckpt.get("denoiser_backbone", "mlp")),
|
|
360
|
+
transformer_layers=int(ckpt.get("transformer_layers", 2)),
|
|
361
|
+
transformer_heads=int(ckpt.get("transformer_heads", 4)),
|
|
362
|
+
dropout=float(ckpt.get("transformer_dropout", 0.0)),
|
|
363
|
+
).to(device)
|
|
364
|
+
model.load_state_dict(ckpt["model_state_dict"], strict=True)
|
|
365
|
+
model.eval()
|
|
366
|
+
return model
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def _pair_distance_features(confs, max_confs=None):
|
|
370
|
+
if not confs:
|
|
371
|
+
return None
|
|
372
|
+
if max_confs is not None and int(max_confs) > 0 and len(confs) > int(max_confs):
|
|
373
|
+
idx = torch.linspace(0, len(confs) - 1, int(max_confs)).round().long().tolist()
|
|
374
|
+
confs = [confs[i] for i in idx]
|
|
375
|
+
stacked = torch.stack([c.detach().cpu().float() for c in confs], dim=0)
|
|
376
|
+
if stacked.dim() != 3 or stacked.size(1) < 2:
|
|
377
|
+
return None
|
|
378
|
+
row, col = torch.triu_indices(stacked.size(1), stacked.size(1), offset=1)
|
|
379
|
+
dists = torch.norm(stacked[:, row] - stacked[:, col], dim=-1)
|
|
380
|
+
return torch.nan_to_num(dists, nan=0.0, posinf=0.0, neginf=0.0)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _anchor_gate_denoise_candidates(denoise_confs, anchor_confs, args):
|
|
384
|
+
if not bool(getattr(args, "pbasin_anchor_gate", False)):
|
|
385
|
+
return denoise_confs
|
|
386
|
+
if not denoise_confs or not anchor_confs:
|
|
387
|
+
return denoise_confs
|
|
388
|
+
|
|
389
|
+
keep_fraction = min(1.0, max(0.0, float(getattr(args, "pbasin_anchor_gate_keep_fraction", 1.0))))
|
|
390
|
+
threshold = float(getattr(args, "pbasin_anchor_gate_threshold", -1.0))
|
|
391
|
+
min_keep_fraction = min(1.0, max(0.0, float(getattr(args, "pbasin_anchor_gate_min_keep_fraction", 0.35))))
|
|
392
|
+
if keep_fraction >= 0.999 and threshold <= 0:
|
|
393
|
+
return denoise_confs
|
|
394
|
+
|
|
395
|
+
denoise_feat = _pair_distance_features(denoise_confs)
|
|
396
|
+
anchor_feat = _pair_distance_features(
|
|
397
|
+
anchor_confs,
|
|
398
|
+
max_confs=max(1, int(getattr(args, "pbasin_anchor_gate_max_anchors", 256))),
|
|
399
|
+
)
|
|
400
|
+
if denoise_feat is None or anchor_feat is None or denoise_feat.size(1) != anchor_feat.size(1):
|
|
401
|
+
return denoise_confs
|
|
402
|
+
|
|
403
|
+
score_chunks = []
|
|
404
|
+
for start in range(0, denoise_feat.size(0), 256):
|
|
405
|
+
block = denoise_feat[start : start + 256]
|
|
406
|
+
diff = block[:, None, :] - anchor_feat[None, :, :]
|
|
407
|
+
score = torch.sqrt(torch.mean(diff * diff, dim=-1).clamp_min(0.0)).min(dim=1).values
|
|
408
|
+
score_chunks.append(score)
|
|
409
|
+
scores = torch.cat(score_chunks, dim=0)
|
|
410
|
+
order = torch.argsort(scores)
|
|
411
|
+
|
|
412
|
+
target_keep = len(denoise_confs)
|
|
413
|
+
if keep_fraction < 0.999:
|
|
414
|
+
target_keep = max(1, int(round(len(denoise_confs) * keep_fraction)))
|
|
415
|
+
min_keep = max(1, int(round(len(denoise_confs) * min_keep_fraction)))
|
|
416
|
+
|
|
417
|
+
if threshold > 0:
|
|
418
|
+
threshold_keep = torch.nonzero(scores <= threshold, as_tuple=False).flatten()
|
|
419
|
+
if int(threshold_keep.numel()) < min_keep:
|
|
420
|
+
selected = order[:min_keep]
|
|
421
|
+
elif int(threshold_keep.numel()) > target_keep:
|
|
422
|
+
selected = order[:target_keep]
|
|
423
|
+
else:
|
|
424
|
+
selected = threshold_keep
|
|
425
|
+
else:
|
|
426
|
+
selected = order[:target_keep]
|
|
427
|
+
|
|
428
|
+
selected = torch.sort(selected).values.tolist()
|
|
429
|
+
return [denoise_confs[i] for i in selected]
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def _augment_final_torsion_snap_candidates(
|
|
433
|
+
confs,
|
|
434
|
+
*,
|
|
435
|
+
denoiser,
|
|
436
|
+
post_denoiser,
|
|
437
|
+
feat_i,
|
|
438
|
+
graph_feat_i,
|
|
439
|
+
P,
|
|
440
|
+
edge_i,
|
|
441
|
+
local_torsion_index,
|
|
442
|
+
args,
|
|
443
|
+
device,
|
|
444
|
+
dispersion_widths=None,
|
|
445
|
+
):
|
|
446
|
+
steps = max(0, int(getattr(args, "final_snap_steps", 0)))
|
|
447
|
+
if steps <= 0 or not confs:
|
|
448
|
+
return confs
|
|
449
|
+
|
|
450
|
+
snap_model = post_denoiser if bool(getattr(args, "final_snap_use_post_denoiser", False)) and post_denoiser is not None else denoiser
|
|
451
|
+
if snap_model is None:
|
|
452
|
+
return confs
|
|
453
|
+
|
|
454
|
+
sigma = float(getattr(args, "final_snap_sigma", 0.012))
|
|
455
|
+
step_scale = float(getattr(args, "final_snap_step_scale", 0.18))
|
|
456
|
+
max_torsions = int(getattr(args, "torsion_mode_max", 64))
|
|
457
|
+
max_candidates = int(getattr(args, "final_snap_max_candidates", 0))
|
|
458
|
+
keep_original = bool(getattr(args, "final_snap_keep_original", False))
|
|
459
|
+
|
|
460
|
+
source_confs = list(confs)
|
|
461
|
+
if max_candidates > 0 and len(source_confs) > max_candidates:
|
|
462
|
+
idx = torch.linspace(0, len(source_confs) - 1, max_candidates).round().long().tolist()
|
|
463
|
+
source_confs = [source_confs[int(i)] for i in idx]
|
|
464
|
+
|
|
465
|
+
snapped = []
|
|
466
|
+
for conf in source_confs:
|
|
467
|
+
y = conf.to(device=device, dtype=feat_i.dtype)
|
|
468
|
+
for _ in range(steps):
|
|
469
|
+
delta = snap_model(
|
|
470
|
+
node_feat=feat_i,
|
|
471
|
+
graph_feat=graph_feat_i,
|
|
472
|
+
coords=y,
|
|
473
|
+
P=P,
|
|
474
|
+
torsion_index=local_torsion_index,
|
|
475
|
+
sigma=float(sigma),
|
|
476
|
+
max_torsions=max_torsions,
|
|
477
|
+
)
|
|
478
|
+
applied_delta = delta * step_scale
|
|
479
|
+
if dispersion_widths is not None:
|
|
480
|
+
applied_delta = applied_delta * dispersion_widths[: applied_delta.size(0)]
|
|
481
|
+
y = apply_torsion_residuals(
|
|
482
|
+
y,
|
|
483
|
+
torsions=local_torsion_index,
|
|
484
|
+
deltas=applied_delta,
|
|
485
|
+
edge_index=edge_i,
|
|
486
|
+
max_torsions=max_torsions,
|
|
487
|
+
)
|
|
488
|
+
if torch.isfinite(y).all():
|
|
489
|
+
snapped.append(y.detach().cpu())
|
|
490
|
+
|
|
491
|
+
if not snapped:
|
|
492
|
+
return confs
|
|
493
|
+
if keep_original:
|
|
494
|
+
return list(confs) + snapped
|
|
495
|
+
return snapped
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def _initialize_from_torsion_manifold(
|
|
499
|
+
coords,
|
|
500
|
+
torsion_index,
|
|
501
|
+
edge_index,
|
|
502
|
+
prototype,
|
|
503
|
+
strength,
|
|
504
|
+
noise_scale,
|
|
505
|
+
max_torsions,
|
|
506
|
+
):
|
|
507
|
+
"""Move an ETKDG seed toward one circular torsion-mixture prototype.
|
|
508
|
+
|
|
509
|
+
The update is deliberately partial: bond geometry and the established
|
|
510
|
+
denoising trajectory remain intact, while the mixture prior supplies a
|
|
511
|
+
state-specific torsion hypothesis rather than a post-hoc score.
|
|
512
|
+
"""
|
|
513
|
+
rows = _torsion_rows(torsion_index)
|
|
514
|
+
if rows is None or rows.numel() == 0:
|
|
515
|
+
return coords
|
|
516
|
+
count = min(int(rows.size(0)), int(prototype.size(0)), int(max_torsions))
|
|
517
|
+
if count <= 0:
|
|
518
|
+
return coords
|
|
519
|
+
current = torsion_angles(coords, rows[:count])
|
|
520
|
+
target = torch.atan2(prototype[:count, 0], prototype[:count, 1]).to(current)
|
|
521
|
+
delta = torch.atan2(torch.sin(target - current), torch.cos(target - current))
|
|
522
|
+
delta = delta * float(strength)
|
|
523
|
+
if float(noise_scale) > 0.0:
|
|
524
|
+
delta = delta + torch.randn_like(delta) * float(noise_scale)
|
|
525
|
+
full_delta = torch.zeros(rows.size(0), dtype=coords.dtype, device=coords.device)
|
|
526
|
+
full_delta[:count] = delta.to(full_delta)
|
|
527
|
+
return apply_torsion_residuals(
|
|
528
|
+
coords,
|
|
529
|
+
torsions=torsion_index,
|
|
530
|
+
deltas=full_delta,
|
|
531
|
+
edge_index=edge_index,
|
|
532
|
+
max_torsions=max_torsions,
|
|
533
|
+
)
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def _manifold_component_schedule(logits, count, uncertainty=None):
|
|
537
|
+
"""Cover likely components once, then allocate residual slots by mass.
|
|
538
|
+
|
|
539
|
+
Mode-covering priors additionally expose torsion uncertainty. A broader
|
|
540
|
+
mode receives a modestly larger residual budget, while every likely mode
|
|
541
|
+
still receives an initial coverage slot.
|
|
542
|
+
"""
|
|
543
|
+
if int(count) <= 0:
|
|
544
|
+
return []
|
|
545
|
+
weights = torch.softmax(logits.detach(), dim=-1)
|
|
546
|
+
allocation = weights
|
|
547
|
+
if uncertainty is not None and torch.is_tensor(uncertainty) and uncertainty.numel() > 0:
|
|
548
|
+
spread = uncertainty.detach().float().mean(dim=-1)
|
|
549
|
+
spread = spread / spread.mean().clamp_min(1e-6)
|
|
550
|
+
allocation = weights * (1.0 + 0.35 * spread)
|
|
551
|
+
allocation = allocation / allocation.sum().clamp_min(1e-8)
|
|
552
|
+
ranked = torch.argsort(allocation, descending=True).detach().cpu().tolist()
|
|
553
|
+
schedule = [int(index) for index in ranked[: min(int(count), len(ranked))]]
|
|
554
|
+
if len(schedule) < int(count):
|
|
555
|
+
draws = torch.multinomial(allocation, int(count) - len(schedule), replacement=True)
|
|
556
|
+
schedule.extend(int(index) for index in draws.detach().cpu().tolist())
|
|
557
|
+
return schedule
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
def _controlled_torsion_manifold_probability(P, args):
|
|
561
|
+
"""Ablate only the probability-graph bridge, not the established denoiser."""
|
|
562
|
+
mode = str(getattr(args, "torsion_manifold_p_context_control", "normal") or "normal").lower()
|
|
563
|
+
if mode == "normal":
|
|
564
|
+
return P
|
|
565
|
+
if mode == "zero":
|
|
566
|
+
return torch.zeros_like(P)
|
|
567
|
+
if mode == "shuffle":
|
|
568
|
+
seed = int(getattr(args, "inference_seed", 20260721)) + int(P.size(0)) * 1009
|
|
569
|
+
generator = torch.Generator(device=P.device)
|
|
570
|
+
generator.manual_seed(seed % (2**31 - 1))
|
|
571
|
+
perm = torch.randperm(P.size(0), generator=generator, device=P.device)
|
|
572
|
+
return P[perm][:, perm]
|
|
573
|
+
raise ValueError(f"Unknown torsion-manifold P context control: {mode}")
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
def patched_load_model_factory(exp_args):
|
|
577
|
+
def load_model(_checkpoint_path, device, args_cli):
|
|
578
|
+
# infer_base_conformers.py still requires --checkpoint; train_torsional_denoiser uses explicit base and denoiser paths.
|
|
579
|
+
base_args = type("Args", (), {})()
|
|
580
|
+
base_args.checkpoint = exp_args.base_checkpoint
|
|
581
|
+
base_args.max_confs = args_cli.max_confs
|
|
582
|
+
base_model = load_base_model(base_args, device)
|
|
583
|
+
denoiser_path = str(getattr(exp_args, "denoiser_checkpoint", "") or "").strip()
|
|
584
|
+
# Stage-II-only / pbasin-only evaluation does not need a denoiser checkpoint.
|
|
585
|
+
denoiser = load_denoiser(denoiser_path, device) if denoiser_path else None
|
|
586
|
+
post_denoiser = None
|
|
587
|
+
post_path = str(getattr(exp_args, "post_denoiser_checkpoint", "") or "").strip()
|
|
588
|
+
if post_path:
|
|
589
|
+
post_denoiser = load_denoiser(post_path, device)
|
|
590
|
+
print(f"Loaded post-generation candidate corrector: {post_path}")
|
|
591
|
+
pbasin_model = None
|
|
592
|
+
pbasin_path = ""
|
|
593
|
+
if not bool(getattr(exp_args, "disable_probability_guidance", False)):
|
|
594
|
+
pbasin_path = str(getattr(exp_args, "pbasin_checkpoint", "") or "").strip()
|
|
595
|
+
if pbasin_path:
|
|
596
|
+
pbasin_args = type("Args", (), {})()
|
|
597
|
+
for key, value in vars(args_cli).items():
|
|
598
|
+
setattr(pbasin_args, key, value)
|
|
599
|
+
pbasin_args.num_modes = int(getattr(args_cli, "num_modes", 10))
|
|
600
|
+
pbasin_args.max_confs = int(getattr(args_cli, "max_confs", 5))
|
|
601
|
+
pbasin_args.torsion_mode_max = int(getattr(exp_args, "torsion_mode_max", 64))
|
|
602
|
+
pbasin_args.torsion_delta_scale = 3.141592653589793
|
|
603
|
+
pbasin_args.iterative_torsion_steps = int(getattr(exp_args, "pbasin_iterative_torsion_steps", 3))
|
|
604
|
+
pbasin_args.iterative_torsion_delta_scale = float(
|
|
605
|
+
getattr(exp_args, "pbasin_iterative_torsion_delta_scale", 0.8)
|
|
606
|
+
)
|
|
607
|
+
pbasin_args.mode_condition_strategy = "z"
|
|
608
|
+
pbasin_args.mode_prototype_dim = 32
|
|
609
|
+
pbasin_args.candidate_corrector_path = ""
|
|
610
|
+
pbasin_args.ensemble_checkpoints = ""
|
|
611
|
+
pbasin_args.ensemble_iterative_torsion_delta_scales = ""
|
|
612
|
+
pbasin_args.disable_stage1_pglobal = bool(getattr(exp_args, "disable_stage1_pglobal", False))
|
|
613
|
+
pbasin_args.pglobal_control = str(getattr(exp_args, "pglobal_control", "normal"))
|
|
614
|
+
pbasin_args.pglobal_noise_std = float(getattr(exp_args, "pglobal_noise_std", 0.15))
|
|
615
|
+
pbasin_args.pglobal_seed = int(getattr(exp_args, "pglobal_seed", 20260715))
|
|
616
|
+
pbasin_args.dispersion_control = str(getattr(exp_args, "dispersion_control", "normal"))
|
|
617
|
+
pbasin_args.dispersion_seed = int(getattr(exp_args, "dispersion_seed", 20260913))
|
|
618
|
+
pbasin_args.stage1_kernel = str(getattr(exp_args, "stage1_kernel", "umap"))
|
|
619
|
+
pbasin_loader = infer_torsion.patched_load_model_factory(pbasin_args)
|
|
620
|
+
pbasin_model = pbasin_loader(pbasin_path, device, pbasin_args)
|
|
621
|
+
print(f"Loaded P-basin hybrid checkpoint: {pbasin_path}")
|
|
622
|
+
torsion_manifold_prior = None
|
|
623
|
+
torsion_manifold_path = ""
|
|
624
|
+
if not bool(getattr(exp_args, "disable_probability_guidance", False)):
|
|
625
|
+
torsion_manifold_path = str(getattr(exp_args, "torsion_manifold_prior_path", "") or "").strip()
|
|
626
|
+
if torsion_manifold_path:
|
|
627
|
+
from torsion_manifold import ProbabilityAlignedTorsionStateMixturePrior, TorsionModeCoveringPrior, TorsionStateMixturePrior
|
|
628
|
+
|
|
629
|
+
state = torch.load(torsion_manifold_path, map_location=device, weights_only=False)
|
|
630
|
+
if str(state.get("model_type", "")) == "mixture_torsion_flow":
|
|
631
|
+
from mixture_torsion_flow import MixtureTorsionFlowModel, MixtureTorsionFlowProposalAdapter
|
|
632
|
+
|
|
633
|
+
flow_model = MixtureTorsionFlowModel(
|
|
634
|
+
graph_dim=int(state.get("graph_dim", 128)),
|
|
635
|
+
pair_dim=int(state.get("pair_dim", 515)),
|
|
636
|
+
components=int(state["components"]),
|
|
637
|
+
mode_dim=int(state["mode_dim"]),
|
|
638
|
+
max_torsions=int(state["max_torsions"]),
|
|
639
|
+
hidden_dim=int(state["hidden_dim"]),
|
|
640
|
+
flow_layers=int(state.get("flow_layers", 3)),
|
|
641
|
+
).to(device)
|
|
642
|
+
flow_model.load_state_dict(state["model_state_dict"])
|
|
643
|
+
flow_model.eval()
|
|
644
|
+
torsion_manifold_prior = MixtureTorsionFlowProposalAdapter(flow_model).to(device)
|
|
645
|
+
prior_kind = "mixture-flow"
|
|
646
|
+
print(f"Loaded {prior_kind} torsion proposal adapter: {torsion_manifold_path}")
|
|
647
|
+
elif str(state.get("prior_type", "")) in {"p_aligned_torsion_mixture", "mean_dispersion_aligned_torsion_mixture"}:
|
|
648
|
+
prior_cls = ProbabilityAlignedTorsionStateMixturePrior
|
|
649
|
+
torsion_manifold_prior = prior_cls(
|
|
650
|
+
int(state.get("graph_dim", 128)),
|
|
651
|
+
int(state["max_torsions"]),
|
|
652
|
+
int(state["components"]),
|
|
653
|
+
int(state["hidden_dim"]),
|
|
654
|
+
).to(device)
|
|
655
|
+
torsion_manifold_prior.load_state_dict(state["model_state_dict"])
|
|
656
|
+
torsion_manifold_prior.eval()
|
|
657
|
+
prior_kind = "P-aligned"
|
|
658
|
+
print(f"Loaded {prior_kind} torsion-manifold proposal prior: {torsion_manifold_path}")
|
|
659
|
+
else:
|
|
660
|
+
prior_cls = TorsionModeCoveringPrior if str(state.get("prior_type", "")) == "torsion_mode_covering" else TorsionStateMixturePrior
|
|
661
|
+
torsion_manifold_prior = prior_cls(
|
|
662
|
+
int(state.get("graph_dim", 128)),
|
|
663
|
+
int(state["max_torsions"]),
|
|
664
|
+
int(state["components"]),
|
|
665
|
+
int(state["hidden_dim"]),
|
|
666
|
+
).to(device)
|
|
667
|
+
torsion_manifold_prior.load_state_dict(state["model_state_dict"])
|
|
668
|
+
torsion_manifold_prior.eval()
|
|
669
|
+
if bool(getattr(torsion_manifold_prior, "uses_budget_allocation", False)):
|
|
670
|
+
prior_kind = "mode-covering"
|
|
671
|
+
else:
|
|
672
|
+
prior_kind = "graph-only"
|
|
673
|
+
print(f"Loaded {prior_kind} torsion-manifold proposal prior: {torsion_manifold_path}")
|
|
674
|
+
wrapper = DenoiseWrapper(
|
|
675
|
+
base_model,
|
|
676
|
+
denoiser,
|
|
677
|
+
post_denoiser=post_denoiser,
|
|
678
|
+
pbasin_model=pbasin_model,
|
|
679
|
+
torsion_manifold_prior=torsion_manifold_prior,
|
|
680
|
+
)
|
|
681
|
+
print(f"Loaded base Manimol checkpoint: {exp_args.base_checkpoint}")
|
|
682
|
+
if denoiser_path:
|
|
683
|
+
print(f"Loaded torsion denoiser: {denoiser_path}")
|
|
684
|
+
return wrapper
|
|
685
|
+
|
|
686
|
+
return load_model
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
@torch.no_grad()
|
|
690
|
+
def sample_denoise_conformers(model, batch, graph_idx, args, model_count=None, etkdg_count=None):
|
|
691
|
+
base_model = model.base_model
|
|
692
|
+
denoiser = model.denoiser
|
|
693
|
+
post_denoiser = getattr(model, "post_denoiser", None)
|
|
694
|
+
pbasin_model = getattr(model, "pbasin_model", None)
|
|
695
|
+
torsion_manifold_prior = getattr(model, "torsion_manifold_prior", None)
|
|
696
|
+
# Stage-II-only / pbasin-only runs may intentionally omit the denoiser.
|
|
697
|
+
device = next(denoiser.parameters()).device if denoiser is not None else next(base_model.parameters()).device
|
|
698
|
+
batch = batch.to(device)
|
|
699
|
+
|
|
700
|
+
node_feat = base_model.gnn(batch)
|
|
701
|
+
graph_feat = base_model.pool(node_feat, batch.batch)
|
|
702
|
+
mask = batch.batch == graph_idx
|
|
703
|
+
feat_i = node_feat[mask]
|
|
704
|
+
if feat_i.size(0) <= 1:
|
|
705
|
+
return None
|
|
706
|
+
edge_i = base_model._get_local_edge_index(batch.edge_index, mask)
|
|
707
|
+
local_torsion_index = base_model._get_local_torsion_index(getattr(batch, "torsion_index", None), mask)
|
|
708
|
+
if local_torsion_index is None or local_torsion_index.numel() == 0:
|
|
709
|
+
return None
|
|
710
|
+
mol_ref = batch.rdmol[graph_idx] if hasattr(batch, "rdmol") else None
|
|
711
|
+
if mol_ref is None:
|
|
712
|
+
return None
|
|
713
|
+
seed = int(getattr(args, "inference_seed", -1))
|
|
714
|
+
if seed >= 0:
|
|
715
|
+
mol_seed = seed + int(batch.mol_id[graph_idx].item()) * 100003
|
|
716
|
+
torch.manual_seed(mol_seed % (2**31 - 1))
|
|
717
|
+
P, P_disp, pair_feat_i = base_model._predict_mean_dispersion(feat_i, edge_i)
|
|
718
|
+
P = controlled_pglobal(P, args, mol=mol_ref)
|
|
719
|
+
dispersion_widths, dispersion_scores, dispersion_valid = _proposal_widths(
|
|
720
|
+
P_disp,
|
|
721
|
+
mol_ref,
|
|
722
|
+
local_torsion_index,
|
|
723
|
+
args,
|
|
724
|
+
int(getattr(args, "torsion_mode_max", 64)),
|
|
725
|
+
device,
|
|
726
|
+
feat_i.dtype,
|
|
727
|
+
)
|
|
728
|
+
model.last_dispersion_torsion_widths = dispersion_widths.detach().cpu()
|
|
729
|
+
model.last_dispersion_torsion_scores = None if dispersion_scores is None else dispersion_scores.detach().cpu()
|
|
730
|
+
model.last_dispersion_torsion_valid = None if dispersion_valid is None else dispersion_valid.detach().cpu()
|
|
731
|
+
model.last_dispersion_torsion_original_widths = _proposal_widths.last_original_widths.detach().cpu()
|
|
732
|
+
model.last_dispersion_torsion_original_scores = _proposal_widths.last_original_scores.detach().cpu()
|
|
733
|
+
model.last_dispersion_torsion_original_valid = _proposal_widths.last_original_valid.detach().cpu()
|
|
734
|
+
# Exposed only for raw-pool diagnostic caching in infer_base_conformers.py.
|
|
735
|
+
model.last_pglobal = P.detach().cpu()
|
|
736
|
+
try:
|
|
737
|
+
a, b = base_model.predict_ab(graph_feat[graph_idx], conf_idx=0)
|
|
738
|
+
model.last_pgraph_kernel = (a.detach().cpu(), b.detach().cpu())
|
|
739
|
+
except Exception:
|
|
740
|
+
model.last_pgraph_kernel = None
|
|
741
|
+
|
|
742
|
+
count = int(model_count if model_count is not None else getattr(args, "num_modes", 10))
|
|
743
|
+
pbasin_only = bool(getattr(args, "pbasin_only", False))
|
|
744
|
+
pbasin_fraction = min(1.0, max(0.0, float(getattr(args, "pbasin_fraction", 0.0))))
|
|
745
|
+
if pbasin_only:
|
|
746
|
+
pbasin_fraction = 1.0
|
|
747
|
+
if bool(getattr(args, "pbudget_adaptive", False)):
|
|
748
|
+
pbasin_fraction = _pgraph_budget_fraction(P, args)
|
|
749
|
+
pbasin_count = 0
|
|
750
|
+
if pbasin_model is not None and count > 0 and pbasin_fraction > 0.0:
|
|
751
|
+
pbasin_count = int(round(count * pbasin_fraction))
|
|
752
|
+
max_pbasin_count = count if pbasin_only else max(1, count - 1)
|
|
753
|
+
pbasin_count = max(1, min(max_pbasin_count, pbasin_count))
|
|
754
|
+
denoise_count = max(0, count - pbasin_count)
|
|
755
|
+
manifold_fraction = min(0.80, max(0.0, float(getattr(args, "torsion_manifold_proposal_fraction", 0.0))))
|
|
756
|
+
manifold_count = 0
|
|
757
|
+
manifold_prototypes = None
|
|
758
|
+
manifold_spread = None
|
|
759
|
+
manifold_schedule = []
|
|
760
|
+
if torsion_manifold_prior is not None and denoise_count > 0 and manifold_fraction > 0.0:
|
|
761
|
+
with torch.no_grad():
|
|
762
|
+
if bool(getattr(torsion_manifold_prior, "uses_pair_p_context", False)):
|
|
763
|
+
manifold_output = torsion_manifold_prior(
|
|
764
|
+
graph_feat[graph_idx],
|
|
765
|
+
pair_feat_i.detach(),
|
|
766
|
+
_controlled_torsion_manifold_probability(P, args),
|
|
767
|
+
)
|
|
768
|
+
if len(manifold_output) == 3:
|
|
769
|
+
manifold_logits, manifold_prototypes, manifold_spread = manifold_output
|
|
770
|
+
else:
|
|
771
|
+
manifold_logits, manifold_prototypes = manifold_output
|
|
772
|
+
elif bool(getattr(torsion_manifold_prior, "uses_p_context", False)):
|
|
773
|
+
p_context, _ = mean_dispersion_torsion_context(
|
|
774
|
+
_controlled_torsion_manifold_probability(P, args),
|
|
775
|
+
P_disp,
|
|
776
|
+
mol_ref,
|
|
777
|
+
local_torsion_index,
|
|
778
|
+
torsion_manifold_prior.max_torsions,
|
|
779
|
+
)
|
|
780
|
+
manifold_logits, manifold_prototypes = torsion_manifold_prior(graph_feat[graph_idx], p_context)
|
|
781
|
+
else:
|
|
782
|
+
manifold_output = torsion_manifold_prior(graph_feat[graph_idx])
|
|
783
|
+
if len(manifold_output) == 3:
|
|
784
|
+
manifold_logits, manifold_prototypes, manifold_spread = manifold_output
|
|
785
|
+
else:
|
|
786
|
+
manifold_logits, manifold_prototypes = manifold_output
|
|
787
|
+
manifold_count = max(1, min(denoise_count, int(round(denoise_count * manifold_fraction))))
|
|
788
|
+
manifold_schedule = _manifold_component_schedule(manifold_logits, manifold_count, uncertainty=manifold_spread)
|
|
789
|
+
base_count = int(getattr(args, "torsion_base_confs", 0))
|
|
790
|
+
if base_count <= 0:
|
|
791
|
+
base_count = max(1, denoise_count)
|
|
792
|
+
base_confs = infer_torsion.generate_base_conformers(
|
|
793
|
+
mol_ref,
|
|
794
|
+
num_confs=max(1, base_count),
|
|
795
|
+
method=getattr(args, "torsion_base_method", "etkdg"),
|
|
796
|
+
)
|
|
797
|
+
if not base_confs:
|
|
798
|
+
return None
|
|
799
|
+
|
|
800
|
+
steps = max(1, int(getattr(args, "denoise_steps", 10)))
|
|
801
|
+
sigma_max = float(getattr(args, "denoise_sigma_max", 0.75))
|
|
802
|
+
sigma_min = float(getattr(args, "denoise_sigma_min", 0.05))
|
|
803
|
+
step_scale = float(getattr(args, "denoise_step_scale", 1.0))
|
|
804
|
+
init_noise = float(getattr(args, "denoise_initial_noise", sigma_max))
|
|
805
|
+
max_torsions = int(getattr(args, "torsion_mode_max", 64))
|
|
806
|
+
polish_steps = max(0, int(getattr(args, "denoise_polish_steps", 0)))
|
|
807
|
+
polish_sigma = float(getattr(args, "denoise_polish_sigma", 0.03))
|
|
808
|
+
polish_scale = float(getattr(args, "denoise_polish_step_scale", 0.35))
|
|
809
|
+
precision_fraction = min(1.0, max(0.0, float(getattr(args, "denoise_precision_fraction", 0.0))))
|
|
810
|
+
precision_steps = int(getattr(args, "denoise_precision_steps", 0))
|
|
811
|
+
if precision_steps <= 0:
|
|
812
|
+
precision_steps = steps
|
|
813
|
+
precision_sigma_max = float(getattr(args, "denoise_precision_sigma_max", 0.45))
|
|
814
|
+
precision_sigma_min = float(getattr(args, "denoise_precision_sigma_min", 0.02))
|
|
815
|
+
precision_step_scale = float(getattr(args, "denoise_precision_step_scale", 0.65))
|
|
816
|
+
precision_init_noise = float(getattr(args, "denoise_precision_initial_noise", precision_sigma_max))
|
|
817
|
+
post_steps = max(0, int(getattr(args, "post_denoise_steps", 0)))
|
|
818
|
+
post_sigma = float(getattr(args, "post_denoise_sigma", 0.02))
|
|
819
|
+
post_step_scale = float(getattr(args, "post_denoise_step_scale", 0.35))
|
|
820
|
+
|
|
821
|
+
denoise_confs = []
|
|
822
|
+
for k in range(denoise_count):
|
|
823
|
+
# Scatter precision candidates across the whole pool instead of taking
|
|
824
|
+
# the first block of ETKDG seeds. ETKDG conformers are ordered, so a
|
|
825
|
+
# prefix split can accidentally turn into a low-energy/low-diversity
|
|
826
|
+
# bias. The multiplicative permutation is deterministic and keeps
|
|
827
|
+
# runs reproducible.
|
|
828
|
+
permuted_rank = ((int(k) * 9973) % max(1, int(count)) + 0.5) / max(1, int(count))
|
|
829
|
+
use_precision = precision_fraction > 0.0 and permuted_rank <= precision_fraction
|
|
830
|
+
if use_precision:
|
|
831
|
+
current_steps = max(1, int(precision_steps))
|
|
832
|
+
current_sigmas = torch.linspace(
|
|
833
|
+
precision_sigma_max,
|
|
834
|
+
precision_sigma_min,
|
|
835
|
+
current_steps,
|
|
836
|
+
device=device,
|
|
837
|
+
).detach().cpu().tolist()
|
|
838
|
+
current_step_scale = precision_step_scale
|
|
839
|
+
current_init_noise = precision_init_noise
|
|
840
|
+
else:
|
|
841
|
+
current_sigmas = torch.linspace(
|
|
842
|
+
sigma_max,
|
|
843
|
+
sigma_min,
|
|
844
|
+
steps,
|
|
845
|
+
device=device,
|
|
846
|
+
).detach().cpu().tolist()
|
|
847
|
+
current_step_scale = step_scale
|
|
848
|
+
current_init_noise = init_noise
|
|
849
|
+
|
|
850
|
+
y = base_confs[k % len(base_confs)]
|
|
851
|
+
if y.shape[0] != feat_i.size(0):
|
|
852
|
+
continue
|
|
853
|
+
y = y.to(device=device, dtype=feat_i.dtype)
|
|
854
|
+
# Spread state-conditioned hypotheses across the denoise branch rather
|
|
855
|
+
# than using an ordered prefix of ETKDG seeds. This preserves the
|
|
856
|
+
# original branch as a recall anchor at the same candidate budget.
|
|
857
|
+
is_manifold = manifold_count > 0 and ((int(k) * 7919) % max(1, denoise_count)) < manifold_count
|
|
858
|
+
if is_manifold and manifold_prototypes is not None and manifold_schedule:
|
|
859
|
+
component = manifold_schedule[len(denoise_confs) % len(manifold_schedule)]
|
|
860
|
+
y = _initialize_from_torsion_manifold(
|
|
861
|
+
y,
|
|
862
|
+
torsion_index=local_torsion_index,
|
|
863
|
+
edge_index=edge_i,
|
|
864
|
+
prototype=manifold_prototypes[int(component)],
|
|
865
|
+
strength=float(getattr(args, "torsion_manifold_proposal_strength", 0.55)),
|
|
866
|
+
noise_scale=float(getattr(args, "torsion_manifold_proposal_noise", 0.18)),
|
|
867
|
+
max_torsions=max_torsions,
|
|
868
|
+
)
|
|
869
|
+
if current_init_noise > 0:
|
|
870
|
+
if is_manifold:
|
|
871
|
+
current_init_noise *= float(getattr(args, "torsion_manifold_proposal_denoise_noise_scale", 0.50))
|
|
872
|
+
y, _ = noised_conformer(
|
|
873
|
+
y,
|
|
874
|
+
local_torsion_index,
|
|
875
|
+
edge_i,
|
|
876
|
+
current_init_noise,
|
|
877
|
+
max_torsions,
|
|
878
|
+
torsion_scales=dispersion_widths,
|
|
879
|
+
)
|
|
880
|
+
for sigma in current_sigmas:
|
|
881
|
+
if denoiser is None:
|
|
882
|
+
break
|
|
883
|
+
delta = denoiser(
|
|
884
|
+
node_feat=feat_i,
|
|
885
|
+
graph_feat=graph_feat[graph_idx],
|
|
886
|
+
coords=y,
|
|
887
|
+
P=P,
|
|
888
|
+
torsion_index=local_torsion_index,
|
|
889
|
+
sigma=float(sigma),
|
|
890
|
+
max_torsions=max_torsions,
|
|
891
|
+
)
|
|
892
|
+
applied_delta = delta * current_step_scale * dispersion_widths[: delta.size(0)]
|
|
893
|
+
y = apply_torsion_residuals(
|
|
894
|
+
y,
|
|
895
|
+
torsions=local_torsion_index,
|
|
896
|
+
deltas=applied_delta,
|
|
897
|
+
edge_index=edge_i,
|
|
898
|
+
max_torsions=max_torsions,
|
|
899
|
+
)
|
|
900
|
+
for _ in range(polish_steps):
|
|
901
|
+
if denoiser is None:
|
|
902
|
+
break
|
|
903
|
+
delta = denoiser(
|
|
904
|
+
node_feat=feat_i,
|
|
905
|
+
graph_feat=graph_feat[graph_idx],
|
|
906
|
+
coords=y,
|
|
907
|
+
P=P,
|
|
908
|
+
torsion_index=local_torsion_index,
|
|
909
|
+
sigma=float(polish_sigma),
|
|
910
|
+
max_torsions=max_torsions,
|
|
911
|
+
)
|
|
912
|
+
applied_delta = delta * polish_scale * dispersion_widths[: delta.size(0)]
|
|
913
|
+
y = apply_torsion_residuals(
|
|
914
|
+
y,
|
|
915
|
+
torsions=local_torsion_index,
|
|
916
|
+
deltas=applied_delta,
|
|
917
|
+
edge_index=edge_i,
|
|
918
|
+
max_torsions=max_torsions,
|
|
919
|
+
)
|
|
920
|
+
if post_denoiser is not None and post_steps > 0:
|
|
921
|
+
for _ in range(post_steps):
|
|
922
|
+
delta = post_denoiser(
|
|
923
|
+
node_feat=feat_i,
|
|
924
|
+
graph_feat=graph_feat[graph_idx],
|
|
925
|
+
coords=y,
|
|
926
|
+
P=P,
|
|
927
|
+
torsion_index=local_torsion_index,
|
|
928
|
+
sigma=float(post_sigma),
|
|
929
|
+
max_torsions=max_torsions,
|
|
930
|
+
)
|
|
931
|
+
applied_delta = delta * post_step_scale * dispersion_widths[: delta.size(0)]
|
|
932
|
+
y = apply_torsion_residuals(
|
|
933
|
+
y,
|
|
934
|
+
torsions=local_torsion_index,
|
|
935
|
+
deltas=applied_delta,
|
|
936
|
+
edge_index=edge_i,
|
|
937
|
+
max_torsions=max_torsions,
|
|
938
|
+
)
|
|
939
|
+
denoise_confs.append(y.detach().cpu())
|
|
940
|
+
|
|
941
|
+
pbasin_normal_count = 0
|
|
942
|
+
pbasin_mirror_count = 0
|
|
943
|
+
pbasin_etkdg_count = 0
|
|
944
|
+
pbasin_confs = []
|
|
945
|
+
if pbasin_model is not None and pbasin_count > 0:
|
|
946
|
+
p_args = type("Args", (), {})()
|
|
947
|
+
for key, value in vars(args).items():
|
|
948
|
+
setattr(p_args, key, value)
|
|
949
|
+
p_args.iterative_torsion_steps = int(getattr(args, "pbasin_iterative_torsion_steps", 3))
|
|
950
|
+
p_args.iterative_torsion_delta_scale = float(getattr(args, "pbasin_iterative_torsion_delta_scale", 0.8))
|
|
951
|
+
p_args.torsion_base_confs = int(getattr(args, "pbasin_torsion_base_confs", 0))
|
|
952
|
+
p_args.torsion_base_method = str(getattr(args, "torsion_base_method", "etkdg"))
|
|
953
|
+
p_args.etkdg_candidate_pool = False
|
|
954
|
+
p_args.use_etkdg = bool(getattr(args, "use_etkdg", True))
|
|
955
|
+
p_args.use_egnn_refine = False
|
|
956
|
+
p_args.use_mmff = False
|
|
957
|
+
p_args.use_torsion_refine = False
|
|
958
|
+
p_args.mirror_ratio = 0.0
|
|
959
|
+
result = infer_torsion._sample_torsion_conformers_single(
|
|
960
|
+
pbasin_model,
|
|
961
|
+
batch,
|
|
962
|
+
graph_idx,
|
|
963
|
+
p_args,
|
|
964
|
+
model_count=pbasin_count,
|
|
965
|
+
etkdg_count=0,
|
|
966
|
+
)
|
|
967
|
+
if result is not None:
|
|
968
|
+
p_confs, pbasin_normal_count, pbasin_mirror_count, pbasin_etkdg_count = result
|
|
969
|
+
for conf in p_confs:
|
|
970
|
+
pbasin_confs.append(conf.detach().cpu())
|
|
971
|
+
|
|
972
|
+
gated_denoise_confs = _anchor_gate_denoise_candidates(denoise_confs, pbasin_confs, args)
|
|
973
|
+
out_confs = list(gated_denoise_confs) + list(pbasin_confs)
|
|
974
|
+
actual_etkdg_count = int(pbasin_etkdg_count)
|
|
975
|
+
all_confs = list(out_confs)
|
|
976
|
+
if args.use_etkdg and args.etkdg_candidate_pool and mol_ref is not None and int(etkdg_count or 0) > 0:
|
|
977
|
+
etkdg_confs = infer_base_conformers.generate_etkdg_conformers(mol_ref, num_confs=int(etkdg_count))
|
|
978
|
+
for conf in etkdg_confs:
|
|
979
|
+
if conf.shape[0] == feat_i.size(0):
|
|
980
|
+
all_confs.append(conf)
|
|
981
|
+
actual_etkdg_count += 1
|
|
982
|
+
all_confs = _augment_final_torsion_snap_candidates(
|
|
983
|
+
all_confs,
|
|
984
|
+
denoiser=denoiser,
|
|
985
|
+
post_denoiser=post_denoiser,
|
|
986
|
+
feat_i=feat_i,
|
|
987
|
+
graph_feat_i=graph_feat[graph_idx],
|
|
988
|
+
P=P,
|
|
989
|
+
edge_i=edge_i,
|
|
990
|
+
local_torsion_index=local_torsion_index,
|
|
991
|
+
args=args,
|
|
992
|
+
device=device,
|
|
993
|
+
dispersion_widths=dispersion_widths,
|
|
994
|
+
)
|
|
995
|
+
if not all_confs:
|
|
996
|
+
return None
|
|
997
|
+
return (
|
|
998
|
+
torch.stack(all_confs, dim=0),
|
|
999
|
+
int(len(gated_denoise_confs)) + int(pbasin_normal_count),
|
|
1000
|
+
int(pbasin_mirror_count),
|
|
1001
|
+
int(actual_etkdg_count),
|
|
1002
|
+
)
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
def main():
|
|
1006
|
+
exp_args, remaining = parse_denoise_args()
|
|
1007
|
+
# The u/v entry point is used for external evaluation as well as internal
|
|
1008
|
+
# probes. Keep reference-free preparation local to this new entry point;
|
|
1009
|
+
# the legacy infer_base_conformers.py path remains unchanged.
|
|
1010
|
+
from scripts.reference_free_geometry import patch_inference_geometry
|
|
1011
|
+
patch_inference_geometry(infer_base_conformers)
|
|
1012
|
+
original_argv = sys.argv
|
|
1013
|
+
original_parse_args = infer_base_conformers.parse_args
|
|
1014
|
+
|
|
1015
|
+
def patched_parse_args():
|
|
1016
|
+
try:
|
|
1017
|
+
sys.argv = [original_argv[0]] + remaining
|
|
1018
|
+
args = original_parse_args()
|
|
1019
|
+
finally:
|
|
1020
|
+
sys.argv = original_argv
|
|
1021
|
+
args.base_checkpoint = str(exp_args.base_checkpoint)
|
|
1022
|
+
args.denoiser_checkpoint = str(exp_args.denoiser_checkpoint)
|
|
1023
|
+
args.denoise_steps = int(exp_args.denoise_steps)
|
|
1024
|
+
args.denoise_sigma_max = float(exp_args.denoise_sigma_max)
|
|
1025
|
+
args.denoise_sigma_min = float(exp_args.denoise_sigma_min)
|
|
1026
|
+
args.denoise_step_scale = float(exp_args.denoise_step_scale)
|
|
1027
|
+
args.denoise_initial_noise = float(exp_args.denoise_initial_noise)
|
|
1028
|
+
args.pbasin_only = bool(exp_args.pbasin_only)
|
|
1029
|
+
args.denoise_polish_steps = int(exp_args.denoise_polish_steps)
|
|
1030
|
+
args.denoise_polish_sigma = float(exp_args.denoise_polish_sigma)
|
|
1031
|
+
args.denoise_polish_step_scale = float(exp_args.denoise_polish_step_scale)
|
|
1032
|
+
args.denoise_precision_fraction = float(exp_args.denoise_precision_fraction)
|
|
1033
|
+
args.denoise_precision_steps = int(exp_args.denoise_precision_steps)
|
|
1034
|
+
args.denoise_precision_sigma_max = float(exp_args.denoise_precision_sigma_max)
|
|
1035
|
+
args.denoise_precision_sigma_min = float(exp_args.denoise_precision_sigma_min)
|
|
1036
|
+
args.denoise_precision_step_scale = float(exp_args.denoise_precision_step_scale)
|
|
1037
|
+
args.denoise_precision_initial_noise = float(exp_args.denoise_precision_initial_noise)
|
|
1038
|
+
args.post_denoiser_checkpoint = str(exp_args.post_denoiser_checkpoint)
|
|
1039
|
+
args.post_denoise_steps = int(exp_args.post_denoise_steps)
|
|
1040
|
+
args.post_denoise_sigma = float(exp_args.post_denoise_sigma)
|
|
1041
|
+
args.post_denoise_step_scale = float(exp_args.post_denoise_step_scale)
|
|
1042
|
+
args.final_snap_steps = int(exp_args.final_snap_steps)
|
|
1043
|
+
args.final_snap_sigma = float(exp_args.final_snap_sigma)
|
|
1044
|
+
args.final_snap_step_scale = float(exp_args.final_snap_step_scale)
|
|
1045
|
+
args.final_snap_max_candidates = int(exp_args.final_snap_max_candidates)
|
|
1046
|
+
args.final_snap_use_post_denoiser = bool(exp_args.final_snap_use_post_denoiser)
|
|
1047
|
+
args.final_snap_keep_original = bool(exp_args.final_snap_keep_original)
|
|
1048
|
+
args.torsion_mode_max = int(exp_args.torsion_mode_max)
|
|
1049
|
+
args.use_dispersion_proposal = bool(exp_args.use_dispersion_proposal)
|
|
1050
|
+
args.dispersion_width_scale = float(exp_args.dispersion_width_scale)
|
|
1051
|
+
args.dispersion_width_min = float(exp_args.dispersion_width_min)
|
|
1052
|
+
args.dispersion_width_max = float(exp_args.dispersion_width_max)
|
|
1053
|
+
args.dispersion_control = str(exp_args.dispersion_control)
|
|
1054
|
+
args.dispersion_seed = int(exp_args.dispersion_seed)
|
|
1055
|
+
args.torsion_manifold_prior_path = str(exp_args.torsion_manifold_prior_path)
|
|
1056
|
+
args.torsion_manifold_proposal_fraction = float(exp_args.torsion_manifold_proposal_fraction)
|
|
1057
|
+
args.torsion_manifold_proposal_strength = float(exp_args.torsion_manifold_proposal_strength)
|
|
1058
|
+
args.torsion_manifold_proposal_noise = float(exp_args.torsion_manifold_proposal_noise)
|
|
1059
|
+
args.torsion_manifold_proposal_denoise_noise_scale = float(
|
|
1060
|
+
exp_args.torsion_manifold_proposal_denoise_noise_scale
|
|
1061
|
+
)
|
|
1062
|
+
args.torsion_manifold_p_context_control = str(exp_args.torsion_manifold_p_context_control)
|
|
1063
|
+
args.manifold_use_mode_p = bool(exp_args.manifold_use_mode_p)
|
|
1064
|
+
args.torsion_base_method = str(exp_args.torsion_base_method)
|
|
1065
|
+
args.torsion_base_confs = int(exp_args.torsion_base_confs)
|
|
1066
|
+
args.pbasin_checkpoint = str(exp_args.pbasin_checkpoint)
|
|
1067
|
+
args.pbasin_fraction = float(exp_args.pbasin_fraction)
|
|
1068
|
+
args.pbudget_adaptive = bool(exp_args.pbudget_adaptive)
|
|
1069
|
+
args.pbudget_min_fraction = float(exp_args.pbudget_min_fraction)
|
|
1070
|
+
args.pbudget_max_fraction = float(exp_args.pbudget_max_fraction)
|
|
1071
|
+
args.pbudget_confidence_scale = float(exp_args.pbudget_confidence_scale)
|
|
1072
|
+
args.pbasin_iterative_torsion_steps = int(exp_args.pbasin_iterative_torsion_steps)
|
|
1073
|
+
args.pbasin_iterative_torsion_delta_scale = float(exp_args.pbasin_iterative_torsion_delta_scale)
|
|
1074
|
+
args.pbasin_torsion_base_confs = int(exp_args.pbasin_torsion_base_confs)
|
|
1075
|
+
args.pbasin_anchor_gate = bool(exp_args.pbasin_anchor_gate)
|
|
1076
|
+
args.pbasin_anchor_gate_keep_fraction = float(exp_args.pbasin_anchor_gate_keep_fraction)
|
|
1077
|
+
args.pbasin_anchor_gate_threshold = float(exp_args.pbasin_anchor_gate_threshold)
|
|
1078
|
+
args.pbasin_anchor_gate_min_keep_fraction = float(exp_args.pbasin_anchor_gate_min_keep_fraction)
|
|
1079
|
+
args.pbasin_anchor_gate_max_anchors = int(exp_args.pbasin_anchor_gate_max_anchors)
|
|
1080
|
+
args.disable_stage1_pglobal = bool(exp_args.disable_stage1_pglobal)
|
|
1081
|
+
args.disable_probability_guidance = bool(exp_args.disable_probability_guidance)
|
|
1082
|
+
args.pglobal_control = str(exp_args.pglobal_control)
|
|
1083
|
+
args.pglobal_noise_std = float(exp_args.pglobal_noise_std)
|
|
1084
|
+
args.pglobal_seed = int(exp_args.pglobal_seed)
|
|
1085
|
+
args.pglobal_topology_scale = float(exp_args.pglobal_topology_scale)
|
|
1086
|
+
args.pglobal_topology_mapping = str(getattr(exp_args, "pglobal_topology_mapping", "") or "")
|
|
1087
|
+
args.inference_seed = int(exp_args.inference_seed)
|
|
1088
|
+
args.stage1_kernel = str(exp_args.stage1_kernel)
|
|
1089
|
+
if args.disable_probability_guidance:
|
|
1090
|
+
# Preserve the sampling budget and non-probabilistic stages while
|
|
1091
|
+
# removing every inference-time route through the learned graph.
|
|
1092
|
+
args.disable_stage1_pglobal = True
|
|
1093
|
+
args.pglobal_control = "zero"
|
|
1094
|
+
args.pbasin_checkpoint = ""
|
|
1095
|
+
args.pbasin_fraction = 0.0
|
|
1096
|
+
args.pbudget_adaptive = False
|
|
1097
|
+
args.pbasin_anchor_gate = False
|
|
1098
|
+
args.torsion_manifold_prior_path = ""
|
|
1099
|
+
args.torsion_manifold_proposal_fraction = 0.0
|
|
1100
|
+
args.manifold_use_mode_p = False
|
|
1101
|
+
args.precision_refine_pgraph_weight = 0.0
|
|
1102
|
+
args.ultra_refine_pgraph_weight = 0.0
|
|
1103
|
+
args.pgraph_reconstruct_steps = 0
|
|
1104
|
+
args.pgraph_direct_candidates = 0
|
|
1105
|
+
args.pgraph_direct_only = False
|
|
1106
|
+
if "--etkdg_candidate_pool" not in remaining:
|
|
1107
|
+
args.etkdg_candidate_pool = False
|
|
1108
|
+
return args
|
|
1109
|
+
|
|
1110
|
+
infer_base_conformers.parse_args = patched_parse_args
|
|
1111
|
+
infer_base_conformers.load_model = patched_load_model_factory(exp_args)
|
|
1112
|
+
infer_base_conformers.sample_conformers = sample_denoise_conformers
|
|
1113
|
+
infer_base_conformers.main()
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
if __name__ == "__main__":
|
|
1117
|
+
main()
|