3DMolMS
3D Molecular Network for Mass Spectra Prediction (3DMolMS) is a deep neural network model to predict the MS/MS spectra of compounds from their 3D conformations. This model's molecular representation, learned through MS/MS prediction tasks, can be further applied to enhance performance in other molecular-related tasks, such as predicting retention times (RT) and collision cross sections (CCS).
Paper | Document | Workflow on Koina | PyPI package
Latest release
3DMolMS v1.3.2 is now available on PyPI!
This release makes the 3D molecular encoder correctly E(3)-invariant (to rotation, reflection, and translation) — the previous encoder's output depended on a molecule's absolute position in space. All checkpoints (MS/MS for QTOF and Orbitrap, RT, and CCS) have been retrained with the corrected encoder. This release also adds batched MS/MS inference, in-memory input, per-user checkpoint caching, and optional self-supervised pretraining.
The full change log is at CHANGE_LOG.md.
Installation
3DMolMS is available on PyPI:
pip install molnetpack
PyTorch must be installed separately. Choose the build that matches your system (see the official PyTorch site for other options):
# CUDA 11.6
pip install torch==1.13.0+cu116 torchvision==0.14.0+cu116 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu116
# CUDA 11.7
pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu117
# CPU only
pip install torch==1.13.0+cpu torchvision==0.14.0+cpu torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cpu
Or install from source:
git clone https://github.com/JosieHong/3DMolMS.git
cd 3DMolMS
pip install .
Prefer no installation? Use the Koina web service for inference with API support.
Usage
Predict MS/MS spectra:
import torch
from molnetpack import MolNet, plot_msms
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
molnet_engine = MolNet(device, seed=42)
# Supports CSV, MGF, and PKL input
molnet_engine.load_data("./examples/input_msms.csv")
# Predict and save to MGF (checkpoints are downloaded automatically)
pred_df = molnet_engine.pred_msms(
path_to_results="./output_msms.mgf",
instrument="qtof", # or "orbitrap"
)
# Plot the predicted spectra alongside their 3D conformations
plot_msms(pred_df, dir_to_img="./img/")
Predict retention time (RT) and CCS:
molnet_engine.load_data("./examples/input_ccs.csv")
rt_df = molnet_engine.pred_rt(path_to_results="./output_rt.csv")
ccs_df = molnet_engine.pred_ccs(path_to_results="./output_ccs.csv")
Save molecular embeddings:
molnet_engine.load_data("./examples/input_savefeat.csv")
ids, features = molnet_engine.save_features()
print("Feature shape:", features.shape)
Train your own model:
# Fine-tune from a pretrained checkpoint
molnet_engine.train(
task="msms", # or "rt" / "ccs"
train_data="./data/qtof_etkdgv3_train.pkl",
valid_data="./data/qtof_etkdgv3_test.pkl",
checkpoint_path="./check_point/molnet_qtof_tl.pt",
resume_path="./check_point/molnet_pre_etkdgv3.pt", # pretrained encoder
transfer=True,
)
# The trained model is immediately ready — no reload needed
molnet_engine.load_data("./data/qtof_etkdgv3_test.pkl")
pred_df = molnet_engine.pred_msms(instrument="qtof")
# Evaluate against ground truth
results_df = molnet_engine.evaluate(
test_pkl="./data/qtof_etkdgv3_test.pkl",
pred_mgf="./output_msms.mgf",
result_path="./eval_results.csv",
plot_path="./eval_similarity_hist.png",
)
Sample input files are in examples/. For CCS-only input you may assign an arbitrary value to the Collision_Energy field. Unsupported formats are automatically excluded during loading. Supported inputs:
| Item | Supported input |
|---|---|
| Atom number | ≤ 300 |
| Atom types | C, O, N, H, P, S, F, Cl, B, Br, I |
| Precursor types | [M+H]+, [M-H]-, [M+H-H2O]+, [M+Na]+, [M+2H]2+ |
| Collision energy | any number |
See the full documentation for dataset preparation, preprocessing, and advanced usage, and the source-code docs for script-based workflows.
Citation
If you use 3DMolMS in your research, please cite:
- Hong, Y., Li, S., Welch, C.J., Tichy, S., Ye, Y. and Tang, H., 2023. 3DMolMS: prediction of tandem mass spectra from 3D molecular conformations. Bioinformatics, 39(6), p.btad354.
- Hong, Y., Welch, C.J., Piras, P. and Tang, H., 2024. Enhanced structure-based prediction of chiral stationary phases for chromatographic enantioseparation from 3D molecular conformations. Analytical Chemistry, 96(6), pp.2351-2359.
License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file molnetpack-1.3.2.tar.gz.
File metadata
- Download URL: molnetpack-1.3.2.tar.gz
- Upload date:
- Size: 41.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b793a791504e1bf4b6c54235230951bd5b4008641fcf3bf8d974709fb7574df4
|
|
| MD5 |
3fee5568ce5b9ff2f0502e14fe436f0e
|
|
| BLAKE2b-256 |
53916cd089b4100eb3619f44c71bca19e9fba32eeadecfa86aa53a259bfad721
|
Provenance
The following attestation bundles were made for molnetpack-1.3.2.tar.gz:
Publisher:
publish.yml on josiehong/3DMolMS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
molnetpack-1.3.2.tar.gz -
Subject digest:
b793a791504e1bf4b6c54235230951bd5b4008641fcf3bf8d974709fb7574df4 - Sigstore transparency entry: 2223347586
- Sigstore integration time:
-
Permalink:
josiehong/3DMolMS@5df919eff5907905038177b5fdaec8ffb781ab89 -
Branch / Tag:
refs/tags/v1.3.2 - Owner: https://github.com/josiehong
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5df919eff5907905038177b5fdaec8ffb781ab89 -
Trigger Event:
push
-
Statement type:
File details
Details for the file molnetpack-1.3.2-py3-none-any.whl.
File metadata
- Download URL: molnetpack-1.3.2-py3-none-any.whl
- Upload date:
- Size: 48.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e520f40cf762e1ec7658b80ff0bc9132caaedcc2e1f9219f77b018c38d174db
|
|
| MD5 |
894d645e9459986272e4cbd3982e6b80
|
|
| BLAKE2b-256 |
c6fc332deb4e7605b9ae131783dac96120bd8299ba7abbebe85abbfa30543db2
|
Provenance
The following attestation bundles were made for molnetpack-1.3.2-py3-none-any.whl:
Publisher:
publish.yml on josiehong/3DMolMS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
molnetpack-1.3.2-py3-none-any.whl -
Subject digest:
6e520f40cf762e1ec7658b80ff0bc9132caaedcc2e1f9219f77b018c38d174db - Sigstore transparency entry: 2223348181
- Sigstore integration time:
-
Permalink:
josiehong/3DMolMS@5df919eff5907905038177b5fdaec8ffb781ab89 -
Branch / Tag:
refs/tags/v1.3.2 - Owner: https://github.com/josiehong
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5df919eff5907905038177b5fdaec8ffb781ab89 -
Trigger Event:
push
-
Statement type: