DiffMS: Diffusion Generation of Molecules Conditioned on Mass Spectra

Montgomery Bohde, Mrunali Manjrekar, Runzhong Wang, Shuiwang Ji, Connor W. Coley

Abstract

Identifying unknown metabolites, often referred to as the "dark matter" of metabolomics, remains a significant challenge in analytical chemistry. Traditional methods rely on library matching, which fails for novel compounds. We present DiffMS, a generative model that addresses the inverse problem of mass spectrometry (MS) by mapping fragmentation spectra directly to molecular graphs using discrete diffusion. By incorporating chemical formula constraints and leveraging large-scale pretraining on molecular fingerprints, DiffMS achieves state-of-the-art performance in de novo structure elucidation, nearly doubling the accuracy of previous methods on rigorous benchmarks.

Introduction

Mass spectrometry (MS) is the primary tool for identifying small molecules in complex biological samples. The process involves ionizing molecules and breaking them into fragments, resulting in a "fragmentation spectrum" that serves as a structural fingerprint. However, translating this spectrum back into a precise molecular structure is a formidable task.

Two primary hurdles complicate this inverse problem. First, the "Dark Matter" problem: a vast majority of naturally occurring metabolites are not present in any reference database, necessitating de novo generation rather than simple search-and-match. Second, structural ambiguity: different isomers can produce nearly identical spectra, making it difficult to distinguish between closely related structures. While existing machine learning approaches have attempted to solve this using SMILES (string) generation, these models often struggle with chemical validity and the inherent graph-like nature of molecules.

Methodology

DiffMS introduces an encoder-decoder framework specifically designed to bridge the gap between spectral data and molecular graphs through a process of discrete diffusion.

Spectral Encoding

The model employs a Transformer-based encoder (adapted from the MIST architecture) to process the mass spectrum. The spectrum is treated as a set of peaks, where the encoder models "neutral losses"—the mass differences between fragments. These losses are critical as they provide direct evidence of specific functional groups or structural motifs within the molecule.

Discrete Graph Diffusion

Unlike standard diffusion models that operate on continuous pixel data, the DiffMS decoder operates on the adjacency matrix of a molecular graph. The generation process begins with a "noisy" state of random bonds and iteratively refines them into a valid chemical structure. This approach ensures permutation invariance, avoiding the ordering issues common in SMILES-based language models.

Formula-Restricted Generation

A key innovation of DiffMS is the enforcement of chemical formula constraints. In many experimental settings, the heavy-atom composition (e.g., $C_6H_5NO$) can be determined independently with high confidence. DiffMS uses this formula as a hard constraint during the diffusion process, ensuring the model only explores the relevant chemical subspace and never generates physically impossible candidates.

Pretraining via Fingerprint Bridging

High-quality spectrum-structure pairs are scarce, with only tens of thousands available for training. To overcome this data bottleneck, the authors utilized a pretraining strategy involving 2.8 million molecules. Since realistic spectra cannot be easily simulated for all these molecules, the model was pretrained to map molecular fingerprints to graphs. This allowed the decoder to learn the fundamental "grammar" of molecular structures before being fine-tuned on actual mass spectrometry data.

Experimental Results

DiffMS was evaluated against several benchmarks, including NPLIB1 (CANOPUS) and the more challenging MassSpecGym, which focuses on out-of-distribution performance.

  • State-of-the-Art Accuracy: On the NPLIB1 dataset, DiffMS achieved a Top-1 accuracy of 8.34%, a significant improvement over the previous state-of-the-art of 5.40%.
  • MassSpecGym Performance: In the rigorous MassSpecGym benchmark, DiffMS reached 2.30% Top-1 accuracy, nearly doubling the performance of the next-best model, MADGEN (1.31%).
  • Structural Similarity: Beyond exact matches, DiffMS demonstrated superior structural retrieval. Even when the exact molecule was not identified, the predicted structures showed significantly higher Tanimoto similarity to the ground truth compared to baseline models.
  • Scaling Laws: The research highlighted a clear correlation between pretraining data volume and model performance. As the pretraining set grew, the model's ability to generalize to real-world spectral tasks improved consistently.

Discussion and Limitations

While DiffMS represents a major leap in de novo structure elucidation, several challenges remain. The model currently treats hydrogens implicitly, which can occasionally lead to minor formula discrepancies. Furthermore, the current architecture does not account for stereochemistry (chirality), which is essential for biological activity. Finally, the model's performance is tied to the accuracy of the initial chemical formula prediction; errors in formula determination will propagate through the generative process.

Conclusion

DiffMS demonstrates the power of combining discrete graph diffusion with domain-specific constraints to solve complex inverse problems in chemistry. By effectively utilizing large-scale pretraining and hard physical priors, it provides a robust framework for identifying the "dark matter" of the metabolome, offering a significant tool for researchers in drug discovery and environmental science.

Summary updated

BibTeX
@inproceedings{bohde2025diffms,
  author = {Montgomery Bohde and Mrunali Manjrekar and Runzhong Wang and Shuiwang Ji and Connor W. Coley},
  title = {{DiffMS: Diffusion Generation of Molecules Conditioned on Mass Spectra}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=EvILcv2v8L},
}
Figure