formula_from_mass
Candidate elemental formulas (C, H, N, O, S, P, F, Cl, Br, I within limits) for a measured monoisotopic neutral mass, or an m/z with its adduct ([M+H]+, [M-H]-, [M+Na]+, [M+2H]2+, [2M+H]+ ...), within a ppm tolerance. Exhaustive search inside the element limits; ring-and-double-bond equivalents RDBE = C - (H+X)/2 + (N+P)/2 + 1, the nitrogen rule and H/C limits as filters; ranked by absolute ppm error. Monoisotopic masses are the single IUPAC/AME values of bench_science::iupac, the electron mass CODATA.
- Field
- Mass spectrometry
- Version
- 0.1.0
- Runs as
- Compiled (Rust)
- Typical run
- 0.05 s
Compiled from source: run sh packs/install.sh once before admitting it.
Known answers it must pass
r0001Glucose C6H12O6 at 180.06339 Da, 5 ppm (spec): listed; mass = 72 + 12 x 1.00782503223 + 6 x 15.99491461957 = 180.06338810418 Da (IUPAC monoisotopic sum, rel 1e-12); RDBE = 6 - 12/2 + 1 = 1; error = (180.06339 - 180.06338810418)/180.06338810418 x 1e6 = 0.0105286256 ppm (exact decimal arithmetic, abs 1e-6 ppm)passed
target.listed= truemisseddifferstarget.mass_Da{"value": 180.06338810418, "rel_tol": 1e-12}target.rdbe{"value": 1.0, "abs_tol": 1e-12}target.error_ppm{"value": 0.0105286256132, "abs_tol": 1e-06}best_formula= C6H12O6C6H12O6lockedexact matchr0002Caffeine [M+H]+ at m/z 195.08765, 5 ppm (spec): best C8H10N4O2; m/z = 194.08037557916 + 1.00782503223 - 0.000548579909 (CODATA m_e) = 195.087652031481 (rel 1e-12); RDBE = 8 - 10/2 + 4/2 + 1 = 6; error -0.0104131706 ppm (exact decimal, abs 1e-6 ppm)passed
best_formula= C8H10N4O2C8H10N4O2lockedexact matchbest_mz195.088 ± 2e-10195.088locked0.015 % of the tolerance usedbest_rdbe6 ± 1e-126lockedunder 0.01 % of the tolerance usedbest_error_ppm-0.0104132 ± 1e-06-0.0104132lockedunder 0.01 % of the tolerance usedr0003Benzene C6H6 at 78.04695 Da, 5 ppm (spec): the only formula; RDBE = 6 - 6/2 + 1 = 4 (three C=C + one ring); mass 78.04695019338 Da (IUPAC sum, rel 1e-12)passed
best_formula= C6H6C6H6lockedexact matchunique= truetruelockedexact matchbest_rdbe4 ± 1e-124lockedunder 0.01 % of the tolerance usedbest_mass_Da78.047 ± 7.8e-1178.047lockedunder 0.01 % of the tolerance usedr0004Tight tolerance 0.1 ppm at 180.06339 Da returns one formula, C6H12O6 (spec; the 5 ppm runner-up C7H16OS2 sits 4.8 ppm away, checked by an independent brute-force enumeration)passed
candidate_count= 11lockedexact matchunique= truetruelockedexact matchbest_formula= C6H12O6C6H12O6lockedexact matchr0005Halogen RDBE: chlorobenzene C6H5Cl at 112.00798 Da, cl_max 2: RDBE = 6 - (5+1)/2 + 1 = 4; mass 72 + 5 x 1.00782503223 + 34.968852682 = 112.00797784315 Da (IUPAC sum, rel 1e-12)passed
target.listed= truemisseddifferstarget.rdbe{"value": 4.0, "abs_tol": 1e-12}target.mass_Da{"value": 112.00797784315, "rel_tol": 1e-12}best_formula= C6H5ClC6H5Cllockedexact matchr0006Nitrogen rule: radical C5H6N (nominal 80, one N, RDBE 5 - 6/2 + 1/2 + 1 = 3.5) at 80.05002 Da is in the 5 ppm window but rejectedpassed
target.nitrogen_rule_ok= falsemisseddifferstarget.listed= falsemisseddifferstarget.nominal_mass= 80misseddifferstarget.rdbe{"value": 3.5, "abs_tol": 1e-12}r0007Negative mode: glucose [M-H]- at m/z 179.0561, 3 ppm: m/z = 180.06338810418 - 1.00782503223 + 0.000548579909 = 179.056111651859 (rel 1e-12; electron added, not removed)passed
best_formula= C6H12O6C6H12O6lockedexact matchbest_mz179.056 ± 1.8e-10179.056lockedunder 0.01 % of the tolerance usedcharge= -1-1lockedexact match
Each line is one reading the kernel checked. The bright band is the tolerance; the needle is the value the instrument actually returned when it was admitted. A needle near the centre line used little of its tolerance.
Inputs
| Name | Unit | Default | Meaning |
|---|---|---|---|
neutral_mass | Da | Measured monoisotopic mass of the neutral molecule. Give this or mz, not both. | |
mz | Da | Measured m/z of the ion (Da per elementary charge, i.e. thomson). Give this or neutral_mass, not both. | |
adduct | [M+H]+ | Ion form when mz is given: [M+H]+, [M-H]-, [M+Na]+, [M+K]+, [M+NH4]+, [M+2H]2+, [2M+H]+, [M+FA-H]-, [M-H2O+H]+, [M]+ ... m/z = (n M + atoms added - atoms lost - z m_e) / |z|. | |
tolerance_ppm | 5 | Half-width of the window, parts per million of the theoretical value on the measured scale. | |
c_max | 1 | 100 | |
h_max | 1 | 200 | |
n_max | 1 | 10 | |
o_max | 1 | 20 | |
s_max | 1 | 4 | |
p_max | 1 | 3 | |
f_max | 1 | 0 | |
cl_max | 1 | 0 | |
br_max | 1 | 0 | |
i_max | 1 | 0 | |
min_atoms | Lower limits per element, e.g. {"Cl": 1} when the isotope pattern shows chlorine. | ||
rdbe_min | 1 | 0 | |
rdbe_max | 1 | 40 | |
h_per_c_min | 1 | 0.2 | |
h_per_c_max | 1 | 3.1 | |
nitrogen_rule | true | Keep only closed-shell neutral formulas: nominal mass and N count both even or both odd (same as a whole-number RDBE for these ten elements). | |
target_formula | Optional expected formula (e.g. C6H12O6): its mass, error, RDBE and why it is or is not listed. | ||
max_candidates | 1 | 25 | Rows in the candidates reading; out/candidates.csv holds them all. |
Readings
| Name | Unit | Meaning |
|---|---|---|
measured | Da | The measured value: neutral mass, or m/z in Da per charge. |
neutral_mass_Da | Da | |
tolerance_ppm | parts per million (no kernel unit for ppm, left undeclared) | |
window_mDa | mDa | Half-width of the neutral-mass window. |
in_window_count | 1 | |
candidate_count | 1 | |
listed_count | 1 | |
unique | true when exactly one formula passes | |
best_formula | Hill formula of the lowest-|error| candidate | |
best_mass_Da | Da | |
best_mz | Da | |
best_error_ppm | (measured - theoretical)/theoretical x 1e6, parts per million | |
best_error_mDa | mDa | |
best_rdbe | 1 | |
best_h_per_c | 1 | |
best_nominal_mass | Da | |
second_error_ppm | parts per million | |
candidates | Best first: formula, mass_Da, mz, error_ppm, error_mDa, rdbe, h_per_c, nominal_mass, nitrogen_rule_ok, atoms | |
target | The expected formula, if named | |
rejected | Formulas inside the window rejected by each rule (one formula may fail several) | |
warnings | ||
search_nodes | 1 | Loop steps taken; out/candidates.csv holds every candidate, best first, with its atom counts. |
Try the call
Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.