Skip to main content
Back

Imperial College's NMIRacle Decodes Unknown Molecules From Raw Spectra With 48% Accuracy

A two-stage generative model turns raw IR and NMR spectra into molecular structures, beating prior baselines on unseen molecules with up to 35 heavy atoms.

Pro

  • NMIRacle generates molecular structures directly from raw IR, 1H-NMR, and 13C-NMR spectra with minimal preprocessing.
  • Two-stage training: fragment-to-molecule pre-training then spectra-conditioned fine-tuning on ~790k molecules.
  • Count-aware fragment vocabulary of 991 SMARTS patterns beats binary indicators used in prior work.
  • Top-1 accuracy of 0.48 and Top-15 of 0.66 with all three spectra, outperforming NMR2Struct and Spec2Mol.
  • Robust across molecules up to 35 heavy atoms and 9 distinct chemical elements.
  • Code available on GitHub; paper on arXiv.

Figuring out the structure of an unknown compound from its spectra has always been a chemist's puzzle: match peaks to functional groups, cross-reference libraries, and guess at connectivity. A new framework from Imperial College London called NMIRacle proposes to do this end-to-end, generating a full molecular structure directly from raw IR, 1H-NMR, and 13C-NMR intensity arrays with almost no chemistry-specific preprocessing.

The model consistently beats prior spectra-to-molecule baselines and holds up as molecules get bigger and messier. Code is on GitHub.

Why raw spectra are hard

Structure elucidation is combinatorially brutal. Even for molecules with fewer than 36 heavy atoms, the size of drug-like chemical space could exceed roughly 10^33 possibilities, and each spectral technique gives only partial evidence. IR captures bond vibrations, 1H-NMR probes hydrogen environments, and 13C-NMR maps the carbon backbone.

Most existing deep learning approaches sidestep the difficulty by making strong assumptions. Current spectra-to-molecule generative methods typically rely on a single spectral modality, depend on heavy pre-processing like peak extraction and multiplet assignment, assume prior information such as chemical formula or scaffold, or are benchmarked only on molecules with C, N, O atoms and fewer than 20 heavy atoms. None of that reflects how a working spectroscopist actually gets data off an instrument.

The count-aware fragment trick

NMIRacle trains in two stages. Stage 1 pre-trains a fragment-conditioned generator that reconstructs a SMILES string from a fragment composition vector. Stage 2 introduces a multi-spectra encoder that maps raw IR, 1H-NMR, and 13C-NMR spectra into a latent embedding that conditions the pre-trained generator for direct spectra-to-molecule generation.

The key twist is in how molecules are represented during pre-training. Prior work like NMR2Struct uses binary fragment indicators, one bit per substructure. NMIRacle instead uses a count-aware representation where each entry denotes the number of occurrences of that fragment in the molecule, giving a more faithful description of composition and letting the model capture structural regularities that depend on fragment repetition such as ring patterns and chain extensions. The vocabulary contains 991 SMARTS patterns covering a broad range of common organic motifs.

Each fragment identity and its count are embedded separately, summed, and passed through an MLP with GELU activation. The resulting tokens go into a transformer encoder-decoder that learns to autoregressively spit out SMILES.

Fusing three spectra with attention

In Stage 2, the fragment tokens get replaced by a learned spectral embedding. Each modality has its own encoder: 1D convolutional layers capture local peak patterns for IR and 1H-NMR, compressing the signal into feature maps. For 13C-NMR, peaks are detected using SciPy's find_peaks with a 10 percent threshold, then mapped to chemical shift values across 0 to 220 ppm and discretized into 80 equal-width bins.

The spectra then go through two rounds of attention:

  • Intra-modal: A transformer encoder models dependencies among peaks within a single spectrum.
  • Inter-modal: The three modality-specific representations are concatenated and passed through a second transformer, letting the model learn associations like IR absorption bands linking to 1H shifts of the same functional group.

A separate fragment composition head predicts each fragment's occurrence count as an auxiliary task. The two losses (SMILES cross-entropy and fragment count cross-entropy) are combined with equal weight during fine-tuning.

Data and benchmarks

Pre-training uses roughly 3.1M molecules sampled from GDB-17 combined with about 140k entries from SpectraBase, augmented with around 670k molecules from a recent multimodal spectroscopic dataset, pushing chemical diversity up to 9 distinct elements and molecular size up to 35 heavy atoms.

The spectra-to-molecule benchmark is Alberts et al.'s multimodal spectroscopic dataset, containing over 790k molecules paired with simulated IR, 1H-NMR, and 13C-NMR spectra. The authors guarantee no molecules from pre-training or training data appear in the test set, so evaluation measures the model's ability to predict entirely unseen molecules from spectral evidence.

The numbers

With all three spectral modalities available, NMIRacle achieves a Top-1 accuracy of 0.48 and Top-15 accuracy of 0.66 under an enantiomer-aware evaluation protocol. Compared against three baselines:

ModelTop-1Top-15Morgan Tanimoto
NMIRacle0.480.660.88
NMR2Struct0.410.580.84
SMILES Transformer0.280.420.76
Spec2Mol0.000.010.35

Spec2Mol underperforms in the spectra-to-molecule task despite its strong pre-training results, highlighting a limitation of SMILES autoencoding as a pre-training strategy for multi-spectra conditional generation: aligning spectral representations with a continuous SMILES latent space proves significantly more difficult than conditioning generation on an intermediate, chemically-grounded fragment representation.

The count-aware pre-training itself is measurably better than binary indicators. On fragment-to-molecule reconstruction, Top-1 accuracy increased from 0.63 to 0.70 and Top-10 accuracy from 0.76 to 0.81 while maintaining near-perfect chemical validity.

Where it breaks

A failure-mode analysis groups errors into three buckets: stereochemistry mistakes, connectivity errors, and fragment mispredictions. The dominant source of failure arises from misprediction of fragment compositions, suggesting the model struggles to infer the correct functional group from ambiguous or overlapping spectral evidence.

Rare fragments are the weak point. While micro-averaged F1 reaches 0.87 with all three modalities, macro-averaged F1 drops to 0.43, reflecting the difficulty of predicting rare fragments under severe class imbalance. Practically, the model is strongest on chemically common motifs. Stereochemistry is another blind spot, which is expected because IR and NMR are largely agnostic to absolute configuration.

Other current limitations worth flagging:

  • All experiments use simulated spectra, not lab measurements. Real spectra bring solvent effects, baseline drift, and instrument artifacts that would require domain adaptation.
  • The model outputs 2D connectivity only, not 3D conformations.
  • Pre-training corpus (~3.7M molecules) is small compared to PubChem's ~100M.

Why it matters

The broader point is that fragment-level intermediates work well as a bridge between continuous spectral signals and discrete molecular graphs. Rather than aligning spectra directly to a SMILES latent space, learning a prior over chemically meaningful substructures first, then attaching a spectral encoder, gives the model a grounded target to hit. Count-aware fragments add just enough quantitative signal to disambiguate structures that binary fingerprints cannot. For anyone working on cheminformatics pipelines or automated structure elucidation, the recipe is transferable, and the code is open.