File size: 7,271 Bytes
d1988f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4e317f
d1988f5
 
 
 
 
 
c4e317f
d1988f5
c4e317f
 
d1988f5
 
 
c4e317f
 
 
 
 
 
 
68d3a65
c4e317f
68d3a65
 
c4e317f
 
 
68d3a65
 
 
c4e317f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1988f5
 
 
c4e317f
d1988f5
 
c4e317f
d1988f5
 
 
 
 
 
 
 
 
c4e317f
 
 
 
d1988f5
 
 
 
 
 
 
c4e317f
 
 
 
d1988f5
 
c4e317f
 
 
d1988f5
 
 
c4e317f
d1988f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""Upload code, caches, results and figures to a Hugging Face dataset repo."""

from __future__ import annotations

import argparse
import os
import shutil
import tempfile
from pathlib import Path

from huggingface_hub import HfApi, create_repo

DEFAULT_REPO = "eduzrh/LNPBench"

CARD = """---
license: mit
task_categories:
  - graph-ml
  - tabular-regression
language:
  - en
tags:
  - lipid-nanoparticle
  - LNP
  - mRNA-delivery
  - drug-delivery
  - molecular-property-prediction
  - benchmark
pretty_name: LNPBench - physics-informed LNP structure-function benchmark
---

# LNPBench

Reproducible benchmark and physics-informed models for **lipid nanoparticle
(LNP) structure-function prediction** on the public
[LNPDB](https://lnpdb.molcube.com) database (Nature Communications 2026).

## Contents

| Path | Description |
|---|---|
| `code/` | Full source tree (`src/lnpbench`, `scripts/`) |
| `cache/` | Derived feature cache (fingerprints, descriptors, cCPP, tasks) |
| `results/` | Result tables, statistical tests, per-sample predictions (`results/predictions/`) |
| `figures/` | Publication figures (PNG + PDF) |

## Headline results (external generalisation, Spearman rho)

Full runs: four fully held-out studies x the five published 80/20 folds = 20
external tasks, three seeds for every neural model. `seed_avg` averages the
rank-normalised predictions over seeds before scoring.

| Model | LM_2019 | BL_2023 | SL_2020 | ZC_2023 | seed_avg | seeds |
|---|---|---|---|---|---|---|
| Random forest | 0.194 | 0.156 | 0.656 | 0.420 | 0.357 | 1 |
| PhysSet-LNP (ours) | 0.142 | 0.103 | 0.750 | 0.430 | 0.356 | 3 |
| Extra trees | 0.179 | 0.049 | 0.713 | 0.445 | 0.346 | 1 |
| AGILE (re-trained, full pool) | 0.166 | 0.018 | 0.721 | 0.414 | 0.330 | 3 |
| LiON (from scratch) | 0.206 | 0.137 | 0.620 | 0.337 | 0.325 | 3 |
| Identity-free flat probe (ours) | 0.184 | -0.071 | 0.732 | 0.401 | 0.312 | 1 |
| XGBoost | 0.117 | 0.085 | 0.669 | 0.329 | 0.300 | 1 |
| PhyCausal-LNP (ours) | 0.089 | 0.050 | 0.701 | 0.329 | 0.292 | 1 |
| SeqCausal-LNP (ours) | -0.103 | 0.086 | 0.612 | 0.225 | 0.205 | 1 |
| Morgan FP + MLP | -0.063 | 0.007 | 0.490 | 0.344 | 0.194 | 1 |
| **LNPBench-Stack (ours)** | **0.199** | **0.132** | **0.741** | **0.466** | **0.385** | -- |

`LNPBench-Stack` is the equal-weight rank average of PhysSet-LNP, random forest
and extra trees (member list fixed a priori, no fitted weights). It beats every
single model with p < 0.05 in a paired Wilcoxon test over the 20 tasks.

## The central empirical finding

**Study identity is a shortcut.** Replacing the identity-free physical node
features of PhysSet-LNP with Morgan fingerprints raises validation Spearman but
collapses external Spearman from 0.368 to 0.189: the model learns to recognise
which study a formulation came from instead of chemistry that transfers. The
same pattern appears in the set-encoder ladder (flat probe 0.088 -> +set -0.021
-> +physics bias -0.044). Removing the shortcut, not adding capacity, is what
produces a model that transfers.

Cross-validation on the same data reaches 0.61 Spearman versus 0.30-0.36
externally: within-database CV overstates generalisation by 2-3x.

## Benchmark protocols

1. **External generalisation** - four studies held out entirely
   (`LM_2019`, `BL_2023`, `SL_2020`, `ZC_2023`), five published 80/20 folds on
   the remaining database.
2. **Amine-disjoint 70/15/15** - the split used by the LNPDB evaluation.
3. **Study-stratified 5-fold CV** over all 18,858 formulations.

Primary metric: Spearman rank correlation between predicted and measured
delivery efficiency.

## Models

* Baselines: LiON (D-MPNN), AGILE (GIN + descriptors), XGBoost / RF / ExtraTrees,
  Morgan-fingerprint MLP, mean predictor.
* Proposed: **PhysSet-LNP** (GINE over the intact lipid + descriptor MLP +
  ten-node formulation set with physics-biased attention, identity-free nodes),
  **PhyCausal-LNP** (same set encoder with condition cross-attention and a
  within-study ranking loss), **SeqCausal-LNP** (GINE + Bi-Mamba + GroupDRO).

## Reproduction

```bash
git clone https://github.com/evancollins1/LNPDB.git data/LNPDB
pip install -r code/requirements.txt && pip install -e code
python -m lnpbench.prepare --stage all --workers 32
python scripts/run_benchmark.py --models physset_phys --protocols external \
    --seeds 0 1 2 --device cuda --epochs 30 --batch-size 256 --save-preds
python scripts/ensemble.py --pred-dirs results/predictions --out results/ensemble.csv
python scripts/report.py --results results
```

Every table and figure can be rebuilt from `results/predictions/` and
`results/*.csv` without retraining.

## License

Code: MIT. Derived features follow the LNPDB terms of use; raw LNPDB data are
not redistributed here - download them from https://lnpdb.molcube.com.
"""


def main() -> None:
    ap = argparse.ArgumentParser()
    ap.add_argument("--repo", default=DEFAULT_REPO)
    ap.add_argument("--root", default=str(Path(__file__).resolve().parents[1]))
    ap.add_argument("--token", default=os.environ.get("HF_TOKEN"))
    ap.add_argument("--private", action="store_true")
    ap.add_argument("--skip-code", action="store_true")
    args = ap.parse_args()
    assert args.token, "set HF_TOKEN"

    root = Path(args.root)
    api = HfApi(token=args.token)
    create_repo(args.repo, repo_type="dataset", token=args.token, exist_ok=True, private=args.private)
    print("repo:", args.repo)

    with tempfile.TemporaryDirectory() as tmp:
        stage = Path(tmp)
        (stage / "README.md").write_text(CARD)

        if not args.skip_code:
            shutil.copytree(
                root / "src", stage / "code" / "src",
                ignore=shutil.ignore_patterns("__pycache__", "*.pyc"),
            )
            shutil.copytree(root / "scripts", stage / "code" / "scripts",
                            ignore=shutil.ignore_patterns("__pycache__", "*.pyc"))
            for name in ("README.md", "requirements.txt", "pyproject.toml"):
                if (root / name).exists():
                    shutil.copy2(root / name, stage / "code" / name)

        for sub in ("results", "figures", "manuscript"):
            src = root / sub
            if src.exists():
                shutil.copytree(src, stage / sub, dirs_exist_ok=True,
                                ignore=shutil.ignore_patterns("__pycache__", "*.pyc"))

        cache = root / "cache"
        keep = [
            "il_fp.npy", "il_desc.npy", "il_cpp.npy", "il_vocab.json",
            "il_desc_names.json", "il_tokens.npz", "token_vocab.json",
            "sample_features.npz", "tasks.pkl", "md_labels.npz",
            "samples.parquet", "unified_phys.npz", "il_fp_prot.npy",
        ]
        (stage / "cache").mkdir(exist_ok=True)
        for name in keep:
            if (cache / name).exists():
                shutil.copy2(cache / name, stage / "cache" / name)
        for f in cache.glob("frag_*.npz"):
            shutil.copy2(f, stage / "cache" / f.name)

        api.upload_folder(
            folder_path=stage, repo_id=args.repo, repo_type="dataset",
            commit_message="LNPBench: code, caches, results and figures",
        )
    print(f"done -> https://huggingface.co/datasets/{args.repo}")


if __name__ == "__main__":
    main()