arXiv:2611.01352cs.LGOct 2026

Manuscript Offprint

arXiv:2611.01352

FACET: Feasibility-Automaton Complete Enumeration and Truncation-Free Scoring of Molecular Formulas from MS/MS

Xujun Che, Depeng Xu, Xiuxia Du

Abstract

Determining the neutral molecular formula of a precursor ion from its tandem mass (MS/MS) spectrum is the first step in identifying an unknown small molecule. Existing methods trade recall, whether the correct formula is among the candidates, against the cost of examining each candidate. Methods that examine each candidate in depth must first shorten the list, by limiting element counts or truncating it, and that is where the correct formula is lost. End-to-end regressors are fast but guarantee neither validity nor recall. We present FACET, which separates deciding which formulas to consider from deciding which one to choose. A feasibility automaton builds a formula one element count at a time and admits exactly the formulas that fit the precursor mass and satisfy the ring-and-double-bond and valence constraints. Run as an exhaustive search, it enumerates the complete feasible set, so every candidate is valid and recall is fixed by the chemical constraints rather than by a trained model. A small neural scoring head then ranks every feasible formula from one pass of a pretrained spectrum encoder, so no candidate is discarded. On the NPLIB1 benchmark FACET reaches top-1 accuracies of 0.859 with the adduct known and 0.729 with it unknown, compared with 0.766 and 0.660 for the strongest established method, and its recall is the highest. On the external CASMI 2022 set its recall is 1.000, and with the adduct unknown it is the most accurate of the methods compared.

1 Introduction

Untargeted metabolomics and natural-product discovery routinely produce millions of tandem mass spectra of unknown small molecules1−3^{1-3}, and only a small fraction of them can be annotated by matching against reference spectral libraries4−6^{4-6}. For the remainder, identification has to begin from the spectrum itself, and the first question to answer is the molecule's neutral molecular formula, for example C20H30O4C_{20}H_{30}O_{4}, inferred from the mass-to-charge ratio (m/zm/z) of the precursor ion and from the fragment peaks it produces7,8^{7,8}. An unequivocal formula is itself a reported level of identification confidence9^{9}, and it is the starting point of almost every later step. Structure databases are queried with the formula10,11^{10,11}, compound classes are predicted from fragmentation trees computed for it12^{12}, and de novo structure generators13,14^{13,14} are almost always given the formula and build the molecule on the atom set it fixes, so that a wrong formula becomes a wrong atom set15^{15}. The way a formula identifier fails therefore matters as much as how often it succeeds, and its failure modes are best excluded by construction.

Three properties make the problem hard. The first is validity. A candidate formula is chemically possible only if its mass, corrected for the ion's adduct, matches the precursor within the instrument's mass accuracy; if its ring-and-double-bond equivalent (RDBE), the number of rings and double bonds the formula implies, is not negative 16^{16}; and if its atoms carry enough valences to be joined into a single connected molecule 17^{17}. The adduct is the species added to or removed from the neutral molecule M when it is ionized, such as a proton in [M+H]+[M+H]^{+}, a sodium ion in [M+Na]+[M+Na]^{+}, or a proton together with the loss of a water molecule in [M−H2O+H]+[M-H_{2}O+H]^{+}. Plausibility criteria of this kind are standard filters in formula annotation 18^{18}. The second property is recall. Many formulas fit a given mass, even at sub-ppm accuracy 19^{19}, and the correct one has to be among the candidates that are considered before any scoring can choose it. A precursor at m/z 335.222 observed as [M+H]+[M+H]^{+} and measured to within 30 ppm, for instance, admits 145 distinct formulas inside its ±10\pm10 mDa window, and heavier precursors admit far more. Across the test spectra of the NPLIB1 benchmark, 72% have more than 256 feasible formulas, and above 800 Da the median feasible set holds about 360,000. The third property is near-isobaric ambiguity. The strongest competitors differ from the correct formula by an exchange of atoms of almost the same mass, so that mass alone cannot tell them apart and only the fragment spectrum can. In the example, C20H30O4C_{20}H_{30}O_{4} and C21H26N4C_{21}H_{26}N_{4} lie 1.34 mDa apart. In practice the most frequent of these exchanges are compound ones. Exchanging C3NC_{3}N for O3H2O_{3}H_{2} changes the mass by only 2.68 mDa, and exchanging C2OH2C_{2}OH_{2} for N3N_{3} by 1.34 mDa, whereas the textbook exchange of N for CH2CH_{2} changes it by 12.6 mDa. Some pairs are closer still: C3OC_{3}O and NClH3NClH_{3} differ by 0.49 mDa.

Existing methods handle these properties in different ways, and they share a weakness that we call the recall-cost tension: the more information a method extracts from the spectrum for each candidate, the more each candidate costs to score, and the fewer candidates the method can afford to consider. Combinatorial tools score candidates with expert-designed models of fragmentation, from heuristic rules combined with isotope-pattern matching 20^{20} to hydrogen-rearrangement rules for annotating fragments 21^{21}. SIRIUS 22^{22}, the most widely used of them, decomposes the precursor mass into every formula that fits, using the Round-Robin algorithm for the money-changing problem 23,24^{23,24}. It ranks the candidates by isotope-pattern analysis 25^{25} and by fragmentation trees 26−28^{26-28}, which explain each fragment peak as a subformula of the candidate and must be computed separately for every candidate. ZODIAC then re-ranks the candidates jointly across all spectra of a data set 29^{29}. BUDDY 30^{30} works bottom-up instead, assembling precursor formulas from the formulas that explain individual fragments and neutral losses and ranking them with machine-learned features and a false-discovery-rate estimate, and current versions of SIRIUS combine this bottom-up generation with decomposition. In all of these tools the candidate list is kept manageable by tight mass tolerances and by heuristic limits on element counts of the kind codified by Kind and Fiehn 18^{18}.

Learned scoring reduces the hand-tuning but not the cost per candidate. MIST-CF 31^{31}, the most direct precedent for the present work, extends a spectrum Transformer 32^{32} into an energy-based ranker of (formula, adduct) pairs supplied by an external decomposer. Its authors list this reliance on the decomposition of SIRIUS among the limitations of the method. MIST-CF dispenses with the fragmentation tree but still assigns subformulas to the fragment peaks of every candidate, and this is expensive enough that the candidate list is shortened twice before scoring: the decomposer admits at most one atom of each halogen, and a fast pre-filter keeps only 256 candidates. A formula removed at either step can never be ranked first, however good the scorer is. On NPLIB1, the halogen limit alone excludes the correct formula for 4.0% of the test spectra. End-to-end regressors avoid candidate lists altogether. FIDDLE 33^{33} predicts the formula directly with a network trained on about one million spectra and is fast and accurate at that scale, but nothing constrains its output to be chemically valid, and nothing ensures that the correct formula was ever considered.

Table 1 summarizes where each approach obtains its candidates, what it scores, and what it guarantees. The method we present, FACET, removes the recall-cost tension by separating two decisions that the methods above couple: which formulas to consider, and which of them to choose.

Table 1: How the compared methods generate and score candidate formulas. “Valid” means that every returned formula fits the precursor mass and satisfies an RDBE bound by construction.

MethodCandidatesScoringValidRecall guarantee
SIRIUS 6mass decomposition below m/zm/z 400 and bottom-up assembly from fragment formulas at every massa fragmentation tree for each candidate, of which the best 50 are keptyesno
BUDDYformulas retrieved by mass from a bundled database of 4.19 million, and formulas assembled from fragment and neutral-loss formulasmachine-learned features of each candidate's fragment explanationsyesno
MIST-CFexternal decomposition by SIRIUS, at most one atom of each halogensubformula-annotated peaks for the 256 candidates kept by a learned formula filteryesno
FIDDLEnone, as the formula is regressed directlyrefinement of the predicted formulanono
FACETcomplete enumeration of the feasible set by the feasibility automatonevery feasible formula, scored by a small head on one shared spectrum encodingyesyes

A feasibility automaton makes the first decision. It builds a formula one element count at a time, discards at each step only counts that can no longer be completed into a valid formula, and accepts a finished formula only if it is valid. Because it never accepts an invalid formula and never discards a completable count, running it as an exhaustive search returns the complete set of valid formulas, and the correct formula belongs to that set whenever it is valid. FACET is database-independent: it considers every formula that the constraints admit, whether or not the formula occurs in a known compound. A neural network makes the second decision, and it is kept cheap per candidate: a spectrum encoder reads the spectrum once, and a scoring head about 450 times smaller than the encoder ranks every formula in the set from that single encoding. Scoring the whole set, which for heavy precursors runs to millions of formulas, then becomes affordable, so FACET needs neither tight element limits nor truncation. The encoder is DreaMS³, which was pretrained on spectra alone and never sees a candidate formula, so the correct formula cannot leak into the spectrum representation.

Restricting what a generative model may output by means of a grammar or an automaton is an established technique in natural-language processing³⁴⁻³⁷, and in mass spectrometry a pruning rule on heavy-atom mass that provably never removes the true molecule already steers de novo structure generation toward the precursor mass¹⁵. The feasibility automaton applies the idea to formula identification with a constraint set that is exact, and it is this exactness that turns masking into a guarantee on recall. The contributions of this work are the following.

  • Validity by construction. Every formula FACET emits satisfies the mass, RDBE and valence constraints without any filtering after the fact.

  • A recall guarantee. The same automaton enumerates the entire feasible set, so the correct

formula is a candidate whenever it is feasible, however the candidates are later scored.

  • Truncation-free scoring. All candidates share one encoder pass, and the cost per candidate is that of a small scoring head, so FACET ranks the complete feasible set rather than a shortened list.

  • A self-contained predictor. FACET runs no external decomposition tool during training or inference, and even the negative examples it learns from come from its own enumeration.

On the NPLIB1 benchmark FACET ranks the correct formula first more often than any of four established methods when the adduct is known, and more often than the three that can run without the adduct when it has to be inferred. With the adduct known, its top-1 accuracy is 0.859, compared with 0.766 for the strongest of them. In both settings it also keeps the correct formula among its candidates more often. It keeps this lead for every adduct type and instrument represented by more than a handful of spectra, and its ranking advantage widens above 300 Da, where feasible sets become large. Its decomposer produces 160,000 formulas per CPU second on a single thread, scales across processor cores, and runs inside the model. On the external CASMI 2022 challenge set the recall guarantee carries over unchanged.

References (40)