Skip to main content

3DMolMS

CC BY-NC-SA 4.0 (free for academic use)

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:

  1. 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.
  2. 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.

CC BY-NC-SA 4.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

molnetpack-1.3.2.tar.gz (41.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

molnetpack-1.3.2-py3-none-any.whl (48.5 kB view details)

Uploaded Python 3

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

Hashes for molnetpack-1.3.2.tar.gz
Algorithm Hash digest
SHA256 b793a791504e1bf4b6c54235230951bd5b4008641fcf3bf8d974709fb7574df4
MD5 3fee5568ce5b9ff2f0502e14fe436f0e
BLAKE2b-256 53916cd089b4100eb3619f44c71bca19e9fba32eeadecfa86aa53a259bfad721

See more details on using hashes here.

Provenance

The following attestation bundles were made for molnetpack-1.3.2.tar.gz:

Publisher: publish.yml on josiehong/3DMolMS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for molnetpack-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e520f40cf762e1ec7658b80ff0bc9132caaedcc2e1f9219f77b018c38d174db
MD5 894d645e9459986272e4cbd3982e6b80
BLAKE2b-256 c6fc332deb4e7605b9ae131783dac96120bd8299ba7abbebe85abbfa30543db2

See more details on using hashes here.

Provenance

The following attestation bundles were made for molnetpack-1.3.2-py3-none-any.whl:

Publisher: publish.yml on josiehong/3DMolMS

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.4.0

2 files

This release

1.3.2 This release

2 files

1.3.1

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.10.post1

2 files

1.1.10

2 files

1.1.9

2 files

1.1.8

2 files

1.1.7

2 files

1.1.5

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page