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,48 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Plot held-out mean/dispersion-prior validation from the summary CSV."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import matplotlib.pyplot as plt
|
|
9
|
+
import pandas as pd
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
p = argparse.ArgumentParser()
|
|
14
|
+
p.add_argument("--summary", required=True)
|
|
15
|
+
p.add_argument("--output", required=True)
|
|
16
|
+
args = p.parse_args()
|
|
17
|
+
frame = pd.read_csv(args.summary)
|
|
18
|
+
frame = frame[(frame.stratum != "all") & frame.metric.isin(["mae", "spearman"])]
|
|
19
|
+
strata = ["low_0_5", "medium_6_8", "high_ge_9"]
|
|
20
|
+
labels = ["Low\n0–5", "Medium\n6–8", "High\n≥9"]
|
|
21
|
+
fig, axes = plt.subplots(1, 2, figsize=(7.0, 3.0), sharex=True)
|
|
22
|
+
colors = {"mean": "#2F6FA3", "dispersion": "#D97925"}
|
|
23
|
+
titles = {"mae": "Absolute error (↓)", "spearman": "Spearman correlation (↑)"}
|
|
24
|
+
for ax, metric in zip(axes, ["mae", "spearman"]):
|
|
25
|
+
for head in ["mean", "dispersion"]:
|
|
26
|
+
sub = frame[(frame["metric"] == metric) & (frame["head"] == head)].set_index("stratum").reindex(strata)
|
|
27
|
+
y = sub["mean"].to_numpy(float)
|
|
28
|
+
low = y - sub["ci95_low"].to_numpy(float)
|
|
29
|
+
high = sub["ci95_high"].to_numpy(float) - y
|
|
30
|
+
ax.errorbar(range(3), y, yerr=[low, high], color=colors[head], marker="o",
|
|
31
|
+
linewidth=1.8, markersize=4.5, capsize=2.5, label="Mean prior" if head == "mean" else "Dispersion prior")
|
|
32
|
+
ax.set_title(titles[metric], fontsize=9)
|
|
33
|
+
ax.set_xticks(range(3), labels, fontsize=8)
|
|
34
|
+
ax.grid(axis="y", color="#D9DEE5", linewidth=0.6)
|
|
35
|
+
ax.spines[["top", "right"]].set_visible(False)
|
|
36
|
+
ax.tick_params(labelsize=8)
|
|
37
|
+
axes[0].set_ylabel("Held-out molecule mean", fontsize=8.5)
|
|
38
|
+
axes[1].legend(frameon=False, fontsize=7.5, loc="best")
|
|
39
|
+
fig.tight_layout(pad=0.6)
|
|
40
|
+
output = Path(args.output)
|
|
41
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
42
|
+
fig.savefig(output, dpi=600, transparent=True)
|
|
43
|
+
fig.savefig(output.with_suffix(".svg"), transparent=True)
|
|
44
|
+
plt.close(fig)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
main()
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Precompute fixed heavy-atom RMSD cluster assignments for Stage-II."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import math
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
import torch
|
|
12
|
+
from tqdm import tqdm
|
|
13
|
+
|
|
14
|
+
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
15
|
+
if PROJECT_ROOT not in sys.path:
|
|
16
|
+
sys.path.insert(0, PROJECT_ROOT)
|
|
17
|
+
|
|
18
|
+
from dataset.sharded_drugdataset import ShardedDrugDataset
|
|
19
|
+
from train_torsion_generator import pairwise_heavy_kabsch_rmsd_matrix
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def cluster_labels(positions, atom_x, num_modes, device):
|
|
23
|
+
refs = torch.stack(positions, dim=0).to(device)
|
|
24
|
+
atom_x = atom_x.to(device) if atom_x is not None else None
|
|
25
|
+
count = max(1, min(int(num_modes), refs.size(0)))
|
|
26
|
+
if count == 1:
|
|
27
|
+
return torch.zeros(refs.size(0), dtype=torch.long), count
|
|
28
|
+
with torch.no_grad():
|
|
29
|
+
distances = pairwise_heavy_kabsch_rmsd_matrix(refs, refs, atom_x)
|
|
30
|
+
distances = 0.5 * (distances + distances.transpose(0, 1))
|
|
31
|
+
distances.fill_diagonal_(0.0)
|
|
32
|
+
anchors = [int(torch.argmax(distances.mean(dim=1)).item())]
|
|
33
|
+
while len(anchors) < count:
|
|
34
|
+
nearest = distances[:, anchors].min(dim=1).values
|
|
35
|
+
nearest[torch.tensor(anchors, device=device)] = -1.0
|
|
36
|
+
anchors.append(int(torch.argmax(nearest).item()))
|
|
37
|
+
labels = torch.argmin(distances[:, anchors], dim=1).cpu()
|
|
38
|
+
return labels, count
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def main():
|
|
42
|
+
parser = argparse.ArgumentParser()
|
|
43
|
+
parser.add_argument("--sharded-root", required=True)
|
|
44
|
+
parser.add_argument("--output-root", required=True)
|
|
45
|
+
parser.add_argument("--splits", default="train")
|
|
46
|
+
parser.add_argument("--num-modes", type=int, default=10)
|
|
47
|
+
parser.add_argument("--max-molecules", type=int, default=0)
|
|
48
|
+
parser.add_argument("--device", default="cuda:0")
|
|
49
|
+
args = parser.parse_args()
|
|
50
|
+
os.makedirs(args.output_root, exist_ok=True)
|
|
51
|
+
with open(os.path.join(args.sharded_root, "manifest.json")) as handle:
|
|
52
|
+
manifest = json.load(handle)
|
|
53
|
+
identity = manifest.get("identity", {}).get("sha256", "")
|
|
54
|
+
device = torch.device(args.device if torch.cuda.is_available() else "cpu")
|
|
55
|
+
|
|
56
|
+
for split in [value.strip() for value in args.splits.split(",") if value.strip()]:
|
|
57
|
+
dataset = ShardedDrugDataset(args.sharded_root, split, cache_size=1)
|
|
58
|
+
assignments = {}
|
|
59
|
+
groups = [group for block in dataset.molecule_groups_by_shard for group in block]
|
|
60
|
+
if args.max_molecules > 0:
|
|
61
|
+
groups = groups[: args.max_molecules]
|
|
62
|
+
for group in tqdm(groups, desc="Assignments[%s]" % split):
|
|
63
|
+
items = [dataset[index] for index in group]
|
|
64
|
+
first = items[0]
|
|
65
|
+
mol_id = int(first.mol_id.item())
|
|
66
|
+
labels, cluster_count = cluster_labels(
|
|
67
|
+
[item.pos for item in items], getattr(first, "x", None),
|
|
68
|
+
args.num_modes, device,
|
|
69
|
+
)
|
|
70
|
+
assignments[mol_id] = {
|
|
71
|
+
"conf_id": torch.stack([item.conf_id.reshape(()) for item in items]),
|
|
72
|
+
"cluster_id": labels,
|
|
73
|
+
"cluster_count": int(cluster_count),
|
|
74
|
+
}
|
|
75
|
+
payload = {
|
|
76
|
+
"format": "manimol-stage2-assignments-v1",
|
|
77
|
+
"source_identity": identity,
|
|
78
|
+
"split": split,
|
|
79
|
+
"num_modes": int(args.num_modes),
|
|
80
|
+
"molecules": assignments,
|
|
81
|
+
}
|
|
82
|
+
path = os.path.join(args.output_root, "%s.pt" % split)
|
|
83
|
+
temporary = path + ".tmp"
|
|
84
|
+
torch.save(payload, temporary)
|
|
85
|
+
os.replace(temporary, path)
|
|
86
|
+
print("Saved %s (%d molecules)" % (path, len(assignments)), flush=True)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if __name__ == "__main__":
|
|
90
|
+
main()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Validate and prepare the public MoleculeNet BACE activity labels."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import json
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import pandas as pd
|
|
11
|
+
from rdkit import Chem
|
|
12
|
+
from rdkit.Chem.Scaffolds import MurckoScaffold
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def canonical_smiles(value: object) -> str:
|
|
16
|
+
mol = Chem.MolFromSmiles(str(value))
|
|
17
|
+
if mol is None:
|
|
18
|
+
raise ValueError(f"Invalid SMILES: {value}")
|
|
19
|
+
return Chem.MolToSmiles(mol, canonical=True)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def scaffold_key(smiles: str) -> str:
|
|
23
|
+
mol = Chem.MolFromSmiles(smiles)
|
|
24
|
+
return MurckoScaffold.MurckoScaffoldSmiles(mol=mol, includeChirality=False)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def scaffold_split(df: pd.DataFrame) -> pd.Series:
|
|
28
|
+
"""Deterministic scaffold split with approximate class balance."""
|
|
29
|
+
groups: dict[str, list[int]] = {}
|
|
30
|
+
for idx, scaffold in enumerate(df["canonical_smiles"].map(scaffold_key)):
|
|
31
|
+
groups.setdefault(scaffold, []).append(idx)
|
|
32
|
+
records = []
|
|
33
|
+
for ids in groups.values():
|
|
34
|
+
positives = int(df.iloc[ids]["Class"].sum())
|
|
35
|
+
records.append((ids, positives))
|
|
36
|
+
ordered = sorted(records, key=lambda item: (-len(item[0]), item[0][0]))
|
|
37
|
+
target_n = {"train": 0.8 * len(df), "valid": 0.1 * len(df), "test": 0.1 * len(df)}
|
|
38
|
+
target_p = {name: target_n[name] * float(df["Class"].mean()) for name in target_n}
|
|
39
|
+
counts = {name: [0, 0] for name in target_n}
|
|
40
|
+
labels = ["test"] * len(df)
|
|
41
|
+
for ids, positives in ordered:
|
|
42
|
+
candidates = []
|
|
43
|
+
for split in ("train", "valid", "test"):
|
|
44
|
+
n_after = counts[split][0] + len(ids)
|
|
45
|
+
p_after = counts[split][1] + positives
|
|
46
|
+
# Normalize both molecule-count and positive-count deviations.
|
|
47
|
+
score = ((n_after - target_n[split]) / max(1.0, target_n[split])) ** 2
|
|
48
|
+
score += ((p_after - target_p[split]) / max(1.0, target_p[split])) ** 2
|
|
49
|
+
candidates.append((score, split))
|
|
50
|
+
split = min(candidates)[1]
|
|
51
|
+
for idx in ids:
|
|
52
|
+
labels[idx] = split
|
|
53
|
+
counts[split][0] += len(ids)
|
|
54
|
+
counts[split][1] += positives
|
|
55
|
+
return pd.Series(labels, index=df.index)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def main() -> None:
|
|
59
|
+
parser = argparse.ArgumentParser()
|
|
60
|
+
parser.add_argument("--input", default="data/downstream_activity/bace/bace.csv")
|
|
61
|
+
parser.add_argument("--output_dir", default="data/downstream_activity/bace")
|
|
62
|
+
args = parser.parse_args()
|
|
63
|
+
|
|
64
|
+
out_dir = Path(args.output_dir)
|
|
65
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
66
|
+
raw = pd.read_csv(args.input)
|
|
67
|
+
required = {"mol", "CID", "Class", "Model", "pIC50"}
|
|
68
|
+
missing = required.difference(raw.columns)
|
|
69
|
+
if missing:
|
|
70
|
+
raise ValueError(f"Missing required columns: {sorted(missing)}")
|
|
71
|
+
|
|
72
|
+
df = raw[["mol", "CID", "Class", "Model", "pIC50"]].copy()
|
|
73
|
+
df["canonical_smiles"] = df["mol"].map(canonical_smiles)
|
|
74
|
+
if df["canonical_smiles"].duplicated().any():
|
|
75
|
+
raise ValueError("Canonical SMILES duplicates detected")
|
|
76
|
+
df["official_split"] = df["Model"].str.lower().replace({"test": "test", "valid": "valid", "train": "train"})
|
|
77
|
+
df["scaffold_split"] = scaffold_split(df)
|
|
78
|
+
df = df.rename(columns={"mol": "smiles", "Class": "activity_label", "pIC50": "pic50"})
|
|
79
|
+
df = df[["CID", "smiles", "canonical_smiles", "activity_label", "pic50", "official_split", "scaffold_split"]]
|
|
80
|
+
output_csv = out_dir / "bace_activity_clean.csv"
|
|
81
|
+
df.to_csv(output_csv, index=False)
|
|
82
|
+
|
|
83
|
+
summary = {
|
|
84
|
+
"n_molecules": int(len(df)),
|
|
85
|
+
"n_unique_canonical_smiles": int(df["canonical_smiles"].nunique()),
|
|
86
|
+
"class_counts": {str(k): int(v) for k, v in df["activity_label"].value_counts().sort_index().items()},
|
|
87
|
+
"official_split_counts": {str(k): int(v) for k, v in df["official_split"].value_counts().sort_index().items()},
|
|
88
|
+
"scaffold_split_counts": {str(k): int(v) for k, v in df["scaffold_split"].value_counts().sort_index().items()},
|
|
89
|
+
"pic50_range": [float(df["pic50"].min()), float(df["pic50"].max())],
|
|
90
|
+
"source": "https://deepchemdata.s3-us-west-1.amazonaws.com/datasets/bace.csv",
|
|
91
|
+
}
|
|
92
|
+
(out_dir / "bace_activity_summary.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8")
|
|
93
|
+
print(json.dumps(summary, indent=2))
|
|
94
|
+
print(f"Saved: {output_csv}")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
main()
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Prepare a small, leakage-free ETKDG conformer benchmark for BACE."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import hashlib
|
|
8
|
+
import json
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
import pandas as pd
|
|
12
|
+
import torch
|
|
13
|
+
from rdkit import Chem, RDLogger
|
|
14
|
+
from rdkit.Chem import AllChem
|
|
15
|
+
from tqdm import tqdm
|
|
16
|
+
|
|
17
|
+
RDLogger.DisableLog("rdApp.*")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def make_conformers(smiles: str, count: int, seed: int):
|
|
21
|
+
mol = Chem.MolFromSmiles(smiles)
|
|
22
|
+
if mol is None:
|
|
23
|
+
return None
|
|
24
|
+
mol = Chem.AddHs(mol)
|
|
25
|
+
params = AllChem.ETKDGv3()
|
|
26
|
+
params.randomSeed = int(seed % 2147483647)
|
|
27
|
+
params.useRandomCoords = True
|
|
28
|
+
params.pruneRmsThresh = 0.15
|
|
29
|
+
ids = list(AllChem.EmbedMultipleConfs(mol, numConfs=count, params=params))
|
|
30
|
+
if not ids:
|
|
31
|
+
return None
|
|
32
|
+
keep = [atom.GetIdx() for atom in mol.GetAtoms() if atom.GetAtomicNum() != 1]
|
|
33
|
+
coords = []
|
|
34
|
+
for cid in ids[:count]:
|
|
35
|
+
conf = mol.GetConformer(cid)
|
|
36
|
+
coords.append([[float(conf.GetAtomPosition(i).x),
|
|
37
|
+
float(conf.GetAtomPosition(i).y),
|
|
38
|
+
float(conf.GetAtomPosition(i).z)]
|
|
39
|
+
for i in keep])
|
|
40
|
+
return torch.tensor(coords, dtype=torch.float32), Chem.RemoveHs(mol)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main() -> None:
|
|
44
|
+
p = argparse.ArgumentParser()
|
|
45
|
+
p.add_argument("--input", default="data/downstream_activity/bace/bace_activity_clean.csv")
|
|
46
|
+
p.add_argument("--output", default="data/downstream_activity/bace/benchmark_test50_etkdg.pt")
|
|
47
|
+
p.add_argument("--molecules", type=int, default=50)
|
|
48
|
+
p.add_argument("--seed", type=int, default=20260826)
|
|
49
|
+
p.add_argument("--budgets", default="1,5,10,20")
|
|
50
|
+
args = p.parse_args()
|
|
51
|
+
|
|
52
|
+
df = pd.read_csv(args.input)
|
|
53
|
+
test = df[df["scaffold_split"].eq("test")].sort_values("CID").head(args.molecules)
|
|
54
|
+
budgets = [int(x) for x in args.budgets.split(",")]
|
|
55
|
+
records = []
|
|
56
|
+
skipped = []
|
|
57
|
+
for row in tqdm(test.itertuples(index=False), total=len(test), desc="BACE ETKDG", unit="mol"):
|
|
58
|
+
cid_seed = int.from_bytes(hashlib.sha256(str(row.CID).encode()).digest()[:4], "big")
|
|
59
|
+
conformers = {}
|
|
60
|
+
mol = None
|
|
61
|
+
for k in budgets:
|
|
62
|
+
result = make_conformers(str(row.smiles), k, args.seed + cid_seed + k * 100003)
|
|
63
|
+
if result is None:
|
|
64
|
+
skipped.append(int(row.CID))
|
|
65
|
+
break
|
|
66
|
+
coords, mol = result
|
|
67
|
+
conformers[k] = coords
|
|
68
|
+
if len(conformers) != len(budgets):
|
|
69
|
+
continue
|
|
70
|
+
records.append({
|
|
71
|
+
"CID": str(row.CID),
|
|
72
|
+
"smiles": str(row.smiles),
|
|
73
|
+
"canonical_smiles": str(row.canonical_smiles),
|
|
74
|
+
"activity_label": int(row.activity_label),
|
|
75
|
+
"pic50": float(row.pic50),
|
|
76
|
+
"conformers": conformers,
|
|
77
|
+
"mol": mol,
|
|
78
|
+
})
|
|
79
|
+
out = Path(args.output)
|
|
80
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
81
|
+
torch.save({"format": "bace-etkdg-benchmark-v1", "budgets": budgets,
|
|
82
|
+
"split": "scaffold_test", "records": records}, out)
|
|
83
|
+
summary = {"requested": int(len(test)), "prepared": len(records),
|
|
84
|
+
"skipped_cids": skipped, "budgets": budgets, "output": str(out)}
|
|
85
|
+
out.with_suffix(".json").write_text(json.dumps(summary, indent=2) + "\n")
|
|
86
|
+
print(json.dumps(summary, indent=2))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if __name__ == "__main__":
|
|
90
|
+
main()
|