Prescription-Anchored Metabolite Elucidation from Mass Spectra

When a hospital runs untargeted mass spectrometry on a patient's blood or urine, most of the peaks it records cannot be named. Reference libraries cover only about a tenth of what such samples contain (MassSpecGym). A large share of the unnamed peaks are not exotic. They are the patient's own drugs after the liver and kidneys have modified them: a hydroxyl group added here, a methyl group removed there, a sugar acid attached. The patient's prescription and claims record already lists the molecules these products came from. Current models that generate a structure directly from a spectrum ignore that record. They also assume an "oracle" has supplied the exact elemental formula, which is unrealistic in biofluids, where the same compound can show up as several ion forms with different masses.

We propose to treat the medication list as a set of candidate parent molecules and to elucidate an unknown peak as a small, mass-balanced edit of one of them. The edit is accepted only if the parent's mass, plus the mass changes of a few chemical transformations, plus the mass of the ion form, equals the measured mass to within instrument precision. A "none of the parents" option falls back to unconstrained generation. In two sentences: administrative records tell us which molecules a patient's unknown metabolites probably came from, and an exact mass-conservation equation tells us which edits of those molecules are physically possible. Searching that small, physically consistent space should beat both open-ended generation and library lookup on drug-derived metabolites, and it removes the need to know the formula in advance.

Core Claim

The three directions play different roles here. Administrative data supply the hypothesis set: prescribed parents, plus a secondary prior on which transformations are likely given organ-function codes and labs. Spectroscopic elucidation is the task. Physical consistency is the mechanism, enforced as a hard combinatorial constraint rather than a soft penalty.

The constraint is a mass balance. Let $m_{obs}$ be the measured precursor mass. Let $M(p)$ be the exact monoisotopic mass of a candidate parent $p$ from the medication list. Let $\Delta_k$ be the mass shift of transformation type $k$ (for example +O for hydroxylation, −CH₂ for demethylation, +C₆H₈O₆ for glucuronidation), applied $n_k$ times. Let $a$ be the mass shift of the ion form, such as [M+H]⁺ or [M+Na]⁺. A hypothesis $(p, n, a)$ is admissible only if

$$\left| m_{obs} - M(p) - \sum_k n_k \Delta_k - a \right| \le \epsilon \, m_{obs},$$

where $\epsilon$ is the instrument's parts-per-million tolerance. Each admissible hypothesis fixes a formula exactly. So formula inference and ion-form assignment become a small integer search instead of an oracle input. This addresses the gap that FlowMS, FRIGID, CHEFNMR and Stiefel Flow Matching each state explicitly in their limitations.

Generation then edits the parent graph. Atoms outside the edit are conserved exactly, and the formula after the edit must equal the admissible one. A conditional model places each transformation on a specific atom of the parent. We borrow the idea of generating chemistry as conserved electron and bond bookkeeping from FlowER, which uses bond-electron matrices to stop sequence models from creating or destroying atoms. Its baseline Graph2SMILES conserved heavy atoms in as few as 14.3% of steps. FlowER does this for forward reactions from known reactants. We apply the same bookkeeping to an inverse problem in which the "reactant" is drawn from the patient record.

Because the constraint is discrete, it sidesteps the tension in this literature between exact geometric constraints and soft losses. Stiefel Flow Matching achieves zero moment error but breaks on planar molecules and underfits large ones. CHEFNMR's soft Smooth LDDT loss scales to large molecules but permits violations. A mass-balance filter over integer transformation counts has neither singularities nor drift.

What is new is not "add metadata to a spectrum model." The new part is converting an administrative list into a finite set of exactly mass-balanced formula hypotheses, each paired with a conserved scaffold. This is the specific link the research file reports as missing between clinical records and de novo elucidation.

Research Program

The system has four parts.

First, a hypothesis enumerator. It takes the medication list, a vocabulary of roughly fifty common phase I and phase II transformation mass shifts, and common ion forms. It solves the mass-balance inequality with at most three transformations, which yields a ranked set of (parent, formula) pairs, and it always includes a null hypothesis.

Second, a site-placement editor. This is a graph model conditioned on the spectrum embedding and on the parent graph. For each admissible hypothesis it proposes where on the parent each transformation occurs, and it is constrained so that unedited atoms and bonds stay fixed. We train it on parent and product pairs mined from the training folds of MassSpecGym and NPLIB1. A pair is any two molecules whose formulas differ by an admissible transformation combination and whose graphs differ only locally.

Third, a verifier. In the spirit of FRIGID's cycle-consistency loop, it predicts the spectrum of each candidate with a forward fragmentation simulator and scores agreement with the observed spectrum. Each candidate also gets a parent-specificity score: whether fragments diagnostic of the parent scaffold actually appear in the spectrum.

Fourth, an arbiter. It decides between the best anchored candidate and an unanchored de novo candidate from FRIGID, run with an inferred formula. The decision rests on calibrated verifier scores, so a wrong or incomplete medication list degrades the system to the unanchored baseline rather than below it.

There is also a secondary, explicitly riskier hypothesis that tests the "administrative" part beyond the drug list. Organ-function context should shift the prior over transformations: renal-failure codes and elevated creatinine favor accumulated conjugates, and hepatic codes suppress oxidative routes. We know of no paired public data with ground truth for this. We therefore treat it as a prior-reweighting module and evaluate it only in the retrospective clinical stage, without claiming it in advance.

Baselines

The naive reference point is library retrieval. We use the MIST retrieval model, for which MassSpecGym reports Hit@1 of 14.6% on its scaffold-disjoint split. We run it on our evaluation subset with the benchmark's candidate pools. A second naive point is "predict the parent itself," which measures how often the anchor alone is already the right answer.

The strongest existing de novo method is FRIGID. It reports 18.29% Top-1 accuracy on MassSpecGym and 25.03% on NPLIB1, given oracle formulas. We run it two ways on the same subset with the same sampling budget per spectrum: with the oracle formula, as an upper reference, and with a formula from its own preferred inference route. Beating it means exceeding its oracle-formula Top-1 on drug-derived spectra while using no oracle formula. That would show the record substitutes for the oracle.

We also run FlowMS (reported 9.15% Top-1 on NPLIB1) and the test-time-tuned transformer of Test-Time Tuned Language Models (reported 3.16% Top-1 on MassSpecGym and 12.88% on NPLIB1). Both receive the oracle formula. For our specific drug-metabolite subset, no reported result was found on Lacuna for any of these methods, so all numbers there are re-measured by us under matched compute.

Two ablations isolate the key ingredient. The first replaces the hard mass-balance filter with a soft penalty on formula mismatch while keeping the anchor; this tests whether exactness matters. The second keeps everything but feeds the medication list to FRIGID as extra conditioning tokens instead of as a constraint; this tests whether anchoring beats conditioning.

Why not just…?

Why not just enumerate known biotransformation rules on each prescribed drug and rank the products with a spectrum simulator? This is the most serious threat. It may well match us on single-step metabolites, where the site of modification is unambiguous. We include it as a baseline with the same transformation vocabulary and the same verifier. Our claim has to survive it in two regimes. One is multi-step products, where rule trees grow combinatorially. The other is site isomers on aromatic rings, where a 2D simulator, as FRIGID's authors note of ICEBERG, discriminates weakly. If rule enumeration ties us on both, the honest conclusion is that the contribution lies in the mass-balance formula inference and the fallback arbitration, not in the learned editor. We would report it that way.

Why not just paste the medication list into the prompt of a sequence model? Soft conditioning does not prevent atom creation. FlowER documents heavy-atom conservation as low as 14.3% for Graph2SMILES, and CHEFNMR reports chemical language models at 19% top-1 against over 65% for its geometry-aware model on SpectraNP. The conditioning-token ablation tests this directly on our data.

Why not just infer the formula first and then run FRIGID? That pipeline compounds two errors. In biofluids, ion-form and isobaric ambiguity is exactly where formula assignment fails. The FRIGID inferred-formula baseline measures how much accuracy is lost relative to the oracle condition, and the anchored system should recover that loss.

Why administrative data rather than just asking the clinician? Prescription claims are the clinician's list, recorded at scale and retrospectively available. Their known flaws, namely incompleteness, non-adherence and coding differences across sites, as the clinical-data literature stresses (Talman et al.), are the reason the arbiter and the corruption experiments below exist.

Proposed Experiments

The first stage is a semi-synthetic benchmark built from public spectra. From the MCES-disjoint test folds of MassSpecGym and from NPLIB1, we select test molecules that have a plausible parent in the molecule set, meaning one related by at most three vocabulary transformations. We simulate a patient context of $k$ "prescribed" molecules: the true parent plus distractors sampled from drug-like molecules in the benchmark set. We vary $k$ from 5 to 30.

We report Top-1 and Top-10 exact match, Top-1 MCES and Tanimoto (the benchmark's own metrics), formula and ion-form accuracy, and site-placement accuracy. We also report the rate at which outputs violate mass balance, which our method should hold at zero by construction. Before reporting, we audit the split against the evaluation issues raised in MassSpecGym in the Wild, so that parent–product pairs do not leak across folds.

The decisive robustness check corrupts the context. We remove the true parent with probability 0–50% and inject wrong parents. The system passes if its accuracy never falls below unanchored FRIGID with an inferred formula, and if the arbiter's choice of "none of the parents" is calibrated.

The second stage is a retrospective clinical check. We will seek collaborators who hold untargeted LC-HRMS from cohorts like those in the neuroblastoma plasma study or the interstitial cystitis urine study, together with linked prescription records. We report the fraction of previously unannotated features assigned to a prescribed parent with high verifier confidence. A subset of those assignments will be confirmed with authentic standards. Only in this stage do we test the organ-function prior, by comparing transformation-type frequencies between patients with and without renal or hepatic codes.

The core claim fails under any of three outcomes: if anchoring adds nothing over rule enumeration plus the same verifier on multi-step and site-isomer cases, if the soft-penalty ablation matches the hard filter, or if corrupted contexts push accuracy below the unanchored baseline.