Code accompanying the paper "CSP5: Large-scale Neural Chemical Shift Prediction from 2.5 Million Experimental NMR Spectra" (J. B. Rowlands, R. J. Lewis, P. Howe and J. M. Goodman, Digital Discovery, 2026).
This repo contains:
- the code for processing the data and training the CSP5 and CSP5q models (
src/,scripts/); - the source of version 0.2.16 of the
csp5Python package, as used in the paper (csp5_package/).
If you just want predictions from the trained models, install the package from PyPI with uv pip install csp5 (or pip install csp5) in a suitable virtual environment. Package page and docs: https://pypi.org/project/csp5/.
- Code (this repo): 10.5281/zenodo.23960955 (all versions; each GitHub release is archived as a version).
- Data, data splits, trained models and DFT outputs: 10.5281/zenodo.23668018.
uv venv .venv --prompt .venv
UV_PROJECT_ENVIRONMENT=.venv uv sync --frozen
source .venv/bin/activate
export PYTHONPATH="$PWD/src:$PYTHONPATH"The accompanying Zenodo record (https://zenodo.org/records/19486117) contains model files and the version of the NMRexp dataset used in this work. To download the data and extract it appropriately, run:
./scripts/download_zenodo_data.shBuild both 13C and 1H ensemble shards directly from the Zenodo parquet:
./scripts/build_zenodo_ensemble_shards.sh --targets 13C,1HThis will do a conformational search for each structure with rdkit to obtain an appropriate conformational ensemble, and set up the data so that it can be used to train the models.
First train a model on the assigned data only (command for 13C shown):
python src/cascade_nmr/NMRexp_PaiNN/train_assigned.py \
--target 13C \
--entries-path zenodo_csp5_upload/data/assigned/Exp22K_13C_entries.pkl \
--splits-path zenodo_csp5_upload/data/splits/CSP5-13C-scaffold-doi_split.json \
--output-dir results/train_assigned_13cThen train a joint model, on both the assigned and unassigned data, initialized from the assigned model:
python src/cascade_nmr/NMRexp_PaiNN/train_joint.py \
--target 13C \
--output-dir results/train_joint_13c \
--ensemble-shards-dir data/cascade_nmrexp_13c_ensembles_scaffold_doi \
--exp22k-entries-path zenodo_csp5_upload/data/assigned/Exp22K_13C_entries.pkl \
--exp22k-splits-path zenodo_csp5_upload/data/splits/CSP5-13C-scaffold-doi_split.json \
--init-from results/train_assigned_13c/best_model.ptFor 1H, set --target 1H, use matching 1H entries/splits/shard paths, and initialize from results/train_assigned_1h/best_model.pt.
The CSP5q models, used for the DP5q structure-verification comparison, predict 99 quantiles (0.01 to 0.99) of each shift instead of a single value. The median quantile is used as the shift prediction. They are trained starting from the CSP5 models above (zenodo_csp5_upload/models/checkpoints/CSP5-13C.pt and CSP5-1H.pt, or your own best_model.pt files).
First train a quantile model from scratch on the assigned data. Only its spread (the distances between its quantiles and its median) is used in the next step:
python src/cascade_nmr/NMRexp_PaiNN/train_assigned.py \
--target 13C \
--entries-path zenodo_csp5_upload/data/assigned/Exp22K_13C_entries.pkl \
--splits-path zenodo_csp5_upload/data/splits/CSP5-13C-scaffold-doi_split.json \
--output-dir results/csp5q_13c_spread \
--loss quantile --quantiles 0.01:0.99:99 \
--quantile-loss ruslankotl-huber --quantile-huber-delta 1e-4 --quantile-order-penalty-weight 1.0 \
--lr 5e-4 --lr-scheduler exponential-step --lr-decay-steps 100000 --lr-decay-rate 0.96 \
--batch-size 8 --epochs 50 --save-initial-modelThen distil a quantile model whose median follows CSP5-13C and whose spread follows the model above, starting from the CSP5-13C weights:
python src/cascade_nmr/NMRexp_PaiNN/train_assigned.py \
--target 13C \
--entries-path zenodo_csp5_upload/data/assigned/Exp22K_13C_entries.pkl \
--splits-path zenodo_csp5_upload/data/splits/CSP5-13C-scaffold-doi_split.json \
--output-dir results/csp5q_13c \
--loss quantile --quantiles 0.01:0.99:99 --quantile-loss pinball \
--supervised-loss-weight 0.0 \
--hybrid-distill-weight 1.0 \
--hybrid-distill-center-checkpoint zenodo_csp5_upload/models/checkpoints/CSP5-13C.pt \
--hybrid-distill-spread-checkpoint results/csp5q_13c_spread/best_model.pt \
--warm-start-checkpoint zenodo_csp5_upload/models/checkpoints/CSP5-13C.pt \
--warm-start-quantile-offset-init val-residual-quantiles \
--quantile-parameterization ordered-gaps --quantile-gap-scale 0.05 \
--checkpoint-metric val_loss \
--lr 1e-5 --reduce-lr-factor 0.5 --reduce-lr-patience 4 --min-lr 1e-7 \
--batch-size 8 --epochs 60 --early-stop-patience 12 --save-initial-modelFine-tune CSP5-1H jointly on the assigned and unassigned data with a quantile (pinball) loss. The single output of CSP5-1H is widened to 99 quantile outputs, each starting at the matching quantile of CSP5-1H's errors on the assigned validation set. Peaks are matched to the median prediction, as in CSP5 training.
python src/cascade_nmr/NMRexp_PaiNN/train_joint.py \
--target 1H \
--output-dir results/csp5q_1h \
--ensemble-shards-dir data/cascade_nmrexp_1h_ensembles_scaffold_doi \
--exp22k-entries-path zenodo_csp5_upload/data/assigned/DFT8K_1H_entries.pkl \
--exp22k-splits-path zenodo_csp5_upload/data/splits/CSP5-1H-scaffold-doi_split.json \
--init-from zenodo_csp5_upload/models/checkpoints/CSP5-1H.pt \
--quantile-regression --quantile-levels 0.01:0.99:99 \
--target-max-train-shards 8 --target-max-val-shards 1 --target-max-test-shards 1 \
--target-max-rows-per-shard 512 --target-eval-max-rows-per-shard 512 \
--normalize --assigned-normalize-targets \
--target-loss-weight 0.9 --assigned-loss-weight 0.1 \
--batch-size 16 --assigned-batch-size 8 \
--lr 1e-5 --reduce-lr-patience 2 --epochs 5Both scripts write a model_metadata.json next to best_model.pt describing the quantile outputs.