Efficiently predicting high resolution mass spectra with graph neural networks

Michael Murphy, Stefanie Jegelka, Ernest Fraenkel, Tobias Kind, David Healey, Thomas Butler

Introduction

Identifying unknown small molecules—such as metabolites, drugs, and environmental toxins—is a cornerstone of modern biology and chemistry. The gold standard tool for this task is tandem mass spectrometry (MS/MS), which breaks a molecule into fragments and measures their mass-to-charge ratio (m/z). Researchers identify a molecule by matching its experimental "fingerprint" (spectrum) against a library of known spectra.

However, while millions of molecular structures are known, experimental spectra exist for only a few thousand. This discrepancy creates a massive "dark matter" problem in computational metabolomics. To bridge this gap, researchers rely on computational spectrum prediction, but existing methods face a frustrating tradeoff:

  1. Bond-breaking methods: These simulate every possible way a molecule can fragment. They are highly accurate but computationally explosive and slow.
  2. Mass-binning methods: These discretize the spectrum into a blurry histogram. They are fast but lose the high-resolution precision necessary to distinguish between molecules with nearly identical masses.

The GRAFF-MS Approach

To resolve this tradeoff, the authors introduce GRAFF-MS (Graph neural network for Approximation via Fixed Formulas of Mass Spectra). The key innovation of GRAFF-MS is shifting the prediction perspective from "where do the peaks land?" to "which chemical formulas are present?"

The Fixed Vocabulary

By analyzing a massive corpus of spectra, the authors discovered a "power law" of molecular fragmentation. Most molecules break into a small set of common pieces (product ions) or lose common groups (neutral losses). They curated a fixed vocabulary of the top 10,000 most frequent formulas. Remarkably, this vocabulary—constituting only 2% of all observed formulas—is sufficient to explain 98% of the spectral signal in the NIST-20 test set. This "chemical shorthand" enables the model to be both exceptionally fast and highly accurate.

Architecture and Training

GRAFF-MS employs a Graph Isomorphism Network (GIN) that takes a 2D molecular graph as input, incorporating node features (atoms), edge features (bonds), and Laplacian eigenvectors to capture structural geometry. Instead of regressing a continuous vector, the model predicts a probability distribution over the fixed vocabulary.

Because mass spectrometers have limited resolution, a single peak might correspond to multiple plausible formulas. To address this, the authors developed a custom Peak-Marginal Cross Entropy loss function that marginalizes over these ambiguities during training. Furthermore, the model utilizes a "Product + Loss" strategy, predicting both what the fragments are and what was lost from the original molecule, which significantly boosts performance compared to using either approach in isolation.

Experimental Setup

The study evaluates GRAFF-MS across several key benchmarks:

  • NIST-20: A massive, high-quality commercial library of approximately 300,000 spectra, used as the primary training set.
  • CASMI-16: An independent "blind" challenge dataset used to test generalization to novel molecules not seen during training.
  • GNPS: A community-contributed, uncurated dataset used to assess performance on noisy, real-world experimental data.
  • ChEMBL: Used to generate 200,000 "decoy" structures for large-scale retrieval simulations.

Key Results

GRAFF-MS demonstrates state-of-the-art performance across multiple dimensions:

  • Superior Accuracy: The model achieved a mean cosine similarity (a measure of spectral overlap) of 0.71 on the NIST-20 test set, significantly outperforming the previous state-of-the-art method, CFM-ID (0.53).
  • Massive Speedup: Unlike traditional simulators that slow down exponentially as molecules grow, GRAFF-MS scales linearly with molecular weight. For larger molecules (>500 Da), it is 16x faster than bond-breaking methods on a CPU. On a GPU, it processes spectra in roughly 2.8ms per molecule, making it feasible to predict spectra for millions of compounds in minutes.
  • Better Retrieval: In a rigorous "needle in a haystack" test—finding one correct structure among 1.2 million candidates—GRAFF-MS improved Top-1 retrieval accuracy by 10% over existing baselines.

Limitations and Future Directions

While GRAFF-MS represents a major leap forward, the authors note a few limitations:

  • The "Fixed" Vocabulary: Although 10,000 formulas cover the vast majority of cases, rare or highly complex natural products might produce fragments outside this vocabulary. Dynamic vocabulary generation—learning to "spell" new formulas on the fly—is a promising next step.
  • Long-Range Dependencies: The GNN occasionally struggles to capture dependencies between atoms that are far apart in the 2D graph but interact during 3D fragmentation (e.g., missing a specific peak in phthalates).
  • Complex Rearrangements: While GRAFF-MS handles complex chemical rearrangements better than bond-breaking methods, further improvements are needed to fully capture the physics of gas-phase chemistry.

Summary updated

BibTeX
@inproceedings{murphy2023efficiently,
  author = {Michael Murphy and Stefanie Jegelka and Ernest Fraenkel and Tobias Kind and David Healey and Thomas Butler},
  title = {{Efficiently predicting high resolution mass spectra with graph neural networks}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=81RIPI742h},
}
Figure