Skip to main content

UltraMS

Pretrained models for tandem mass spectra. Turn MS/MS spectra into embeddings, compare spectra, or fine-tune the encoder for a measured property.

python -m pip install ultrams
I want to… Start here
Embed one spectrum Python example
Embed an MGF or mzML file File command
Train on my labelled spectra PyTorch example · complete MGF example
Compare spectra Search example
Learn in a notebook UltraMS tutorials
Inspect or run pretraining Training code

Embed a spectrum

from ultrams import UltraMS

model = UltraMS.from_pretrained("unsupervised")
embedding = model.encode(
    mz=[100.1, 121.1, 150.0],
    intensity=[20, 100, 35],
    precursor_mz=301.2,
).embedding
print(embedding.shape)  # (1024,)

The first call downloads the selected checkpoint from Hugging Face. Use device="cuda" or device="mps" with from_pretrained to run on an available accelerator.

The three checkpoints are collected on Hugging Face.

Embed a spectrum file

ultrams-embed spectra.mgf embeddings.npz --model unsupervised

The output has aligned ids and embeddings arrays. To use mzML, first run python -m pip install 'ultrams[io]'; the base installation reads MGF and .mgf.gz without an extra file-format package. The checked-in example includes five real MS/MS spectra and a complete Python batch workflow.

Fine-tune with PyTorch

UltraMS is a torch.nn.Module. Each dataset item contains peak mz, peak intensity, precursor_mz, and a measured numeric target. The two rows below are runnable example data; substitute your measured spectra and targets for research.

import torch
from torch.utils.data import DataLoader
from ultrams import UltraMS

dataset = [
    {"mz": [100.1, 121.1, 150.0], "intensity": [20, 100, 35], "precursor_mz": 301.2, "target": 0.5},
    {"mz": [102.1, 135.2, 167.3], "intensity": [40, 100, 25], "precursor_mz": 315.3, "target": 0.7},
]
device = "cuda" if torch.cuda.is_available() else "cpu"
model = UltraMS.from_pretrained("unsupervised", device=device).train()
head = torch.nn.Linear(model.embedding_dim, 1).to(device)
loader = DataLoader(dataset, batch_size=2, collate_fn=model.batch_converter())
optimizer = torch.optim.AdamW([*model.parameters(), *head.parameters()], lr=1e-5)

for batch in loader:
    batch = {name: value.to(device) for name, value in batch.items()}
    prediction = head(model(batch["peaks"], batch["attention_mask"], batch["precursor_mz"]))
    loss = torch.nn.functional.mse_loss(prediction.squeeze(-1), batch["target"])
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    print(f"loss: {loss.item():.4f}")

The complete fine-tuning example reads an MGF file and saves training history. For a shorter route, use model.finetune(labelled_spectra, task="regression") with a label field; it saves weights, configuration, and losses. See spectrum input for the input format.

For measured molecular labels, the MassSpecGym contrastive tutorial downloads the dataset, keeps its train/validation/test folds, fine-tunes the encoder, and reloads the selected checkpoint.

Choose a model

Model name Representation Dimension Spectral peak limit Weights
unsupervised Encoder spectrum embedding 1024 150 Unsupervised
mona MoNA contrastive projection 1024 100 MoNA contrastive
search UltraAtlas search projection 512 150 Search

Load any of them with UltraMS.from_pretrained("name"), or load a downloaded model.pt with UltraMS.from_checkpoint(path). Model selection explains the training purpose and output of each checkpoint. The Search checkpoint is the UltraAtlas application best.pt.

Pretraining

The UltraMSdata pretraining package contains the current model architecture, training entry points, configuration and history outputs. It installs separately from the inference package.

Cite

Citation metadata for this software is in CITATION.cff.

Metadata

Release files for ultrams 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ultrams 0.3.0
File Size Uploaded
ultrams-0.3.0.tar.gz 39.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ultrams 0.3.0
File Interpreter ABI Platform
ultrams-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 60.1 kB

Release files / ultrams-0.3.0.tar.gz

Download URL ultrams-0.3.0.tar.gz
Size 39.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8b363e0af44af3841c86346eadecab79be26d0deb4ebcedaf3a8dae7ffdf7ad0
BLAKE2b-256 checksum
How to use checksums
a6ee8f5c88f38f10677fcb4bd275f9e49ed97a26ee7e58b989efabe39a96dfb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / ultrams-0.3.0-py3-none-any.whl

Download URL ultrams-0.3.0-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb836f9f556e4857c8e61c033d2887abd133cc90024fea0ca1545541c571b2df
BLAKE2b-256 checksum
How to use checksums
6a5031dd37e1319dc5afc406335abd0aad3190213c6a832e1e8e8276f51a695e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page