De novo molecular structure elucidation from mass spectra via flow matching

Ghaith Mqawass, Tuan Le, Fabian Theis, Djork-Arné Clevert

TL;DR

Researchers have developed MSFlow, a novel two-stage deep learning model that uses flow matching to translate mass spectrometry (MS) data into molecular structures. This approach significantly improves the accuracy of identifying unknown molecules from their spectral fingerprints, achieving up to a 14-fold improvement over existing methods.

What Problem Does This Paper Address?

Mass spectrometry (MS) is a powerful technique for analyzing molecules, but a major challenge is the "inverse problem": reconstructing a molecule's complete structure from its mass spectrum. This is difficult because a single spectrum can correspond to multiple molecules, and many detected molecules remain unidentified in large databases. Solving this problem is crucial for advancing fields like metabolomics, drug discovery, and chemical research by enabling the identification of unknown compounds and the discovery of new ones.

Methods

MSFlow tackles this challenge with a two-stage encoder-decoder architecture:

  • Stage 1: Spectrum Encoding: An encoder, based on the MIST architecture, takes mass spectra as input and converts them into a continuous, chemically informative embedding space called Continuous Data-Driven Descriptors (CDDDs). This stage uses a transformer model and incorporates predicted molecular formulas to create a rich representation of the spectrum.
  • Stage 2: Structure Generation: A novel discrete flow matching decoder, inspired by BERT, uses the CDDD embeddings from Stage 1 as a condition to generate molecular structures. This decoder is trained using a flow matching objective, which learns to transform a simple prior distribution into the target distribution of molecular representations. The use of SAFE (Sequential Attachment-based Fragment Embedding) as the molecular representation is key, as it's permutation-invariant and preserves structural information better than traditional methods like SMILES.

Datasets

The study utilizes two public datasets for training and evaluation:

  • NPLIB1 (CANOPUS): Contains MS/MS spectra paired with molecular structures and compound class annotations. It's described as an "in-distribution" evaluation scenario.
  • MassSpecGym: A more challenging benchmark designed for evaluating generalization to structurally novel molecules. It uses a structure-aware splitting strategy to ensure molecules in the test set are significantly different from those in the training set, making it an "out-of-distribution" scenario.

Additionally, a large corpus of approximately 2.8 million molecules was curated from public chemical databases (DSSTox, HMDB, COCONUT, MOSES) for decoder training.

Key Insights and Ideas

  • CDDDs are more informative than fingerprints: Using continuous molecular descriptors (CDDDs) for encoding mass spectra leads to significantly better structure generation performance compared to traditional molecular fingerprints (like ECFPs). This highlights the importance of richer, more expressive representations.
  • Discrete flow matching for molecular generation: The paper introduces a discrete flow matching decoder that effectively generates molecular structures in a sequential format (SAFE strings). This approach offers advantages in computational efficiency and flexibility compared to autoregressive models.
  • The spectrum-to-descriptor encoding is the bottleneck: An "oracle experiment" where ground truth CDDD descriptors were used showed a substantial performance gap compared to using descriptors predicted by the encoder. This indicates that while the decoder is powerful, the initial step of converting spectra into embeddings is where most information is lost.
  • Robustness to molecular flexibility: MSFlow demonstrates consistent performance across molecules with varying degrees of flexibility, suggesting its ability to handle the inherent complexity of fragmentation patterns.

Key Results

  • State-of-the-art performance: MSFlow achieved state-of-the-art results on both NPLIB1 and MassSpecGym datasets.
  • Significant accuracy improvements: On NPLIB1, MSFlow reached 44.70% Top-1 accuracy, a substantial improvement over DiffMS (8.34%). On MassSpecGym, it achieved 32.00% Top-1 accuracy, a ~13.9x improvement over DiffMS.
  • Improved structural similarity: MSFlow also showed improvements in structural similarity metrics like Tanimoto similarity and MCES distance.
  • Functional group prediction: The model demonstrated good performance in predicting existing functional groups, with an average precision of 0.868 and recall of 0.863.

Limitations and Future Work

  • Performance degradation with larger molecules: The paper acknowledges that MSFlow's performance degrades with increasingly larger molecules.
  • Information loss in encoding: The significant gap between oracle performance and MIST-based predictions highlights that the spectrum-to-CDDD encoding stage is the primary limitation.
  • Future Directions: The authors suggest future research should focus on developing more expressive spectrum representation techniques to mitigate information loss during the encoding process.

Summary updated

Abstract

Mass spectrometry is a powerful and widely used tool for identifying molecular structures due to its sensitivity and ability to profile complex samples. However, translating spectra into full molecular structures is a difficult, under-defined inverse problem. Overcoming this problem is crucial for enabling biological insight, discovering new metabolites, and advancing chemical research across multiple fields. To this end, we develop MSFlow, a two-stage encoder-decoder flow-matching generative model that achieves state-of-the-art performance on the structure elucidation task for small molecules. In the first stage, we adopt a formula-restricted transformer model for encoding mass spectra into a continuous and chemically informative embedding space, while in the second stage, we train a decoder flow matching model to reconstruct molecules from latent embeddings of mass spectra. We present ablation studies demonstrating the importance of using information-preserving molecular descriptors for encoding mass spectra and motivate the use of our discrete flow-based decoder. Our rigorous evaluation demonstrates that MSFlow can accurately translate up to 45 percent of molecular mass spectra into their corresponding molecular representations - an improvement of up to fourteen-fold over the current state-of-the-art. A trained version of MSFlow is made publicly available on GitHub for non-commercial users.
BibTeX
@misc{mqawass2026de,
  author = {Ghaith Mqawass and Tuan Le and Fabian Theis and Djork-Arné Clevert},
  title = {{De novo molecular structure elucidation from mass spectra via flow matching}},
  year = {2026},
  eprint = {2602.19912},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.19912},
}
Figure