molecular_weight_calculator
Compute the molecular weight, average mass, or monoisotopic mass of a chemical formula using NIST atomic weights. Optionally propagate uncertainties and report percent composition by mass.
Instructions
Compute the molecular weight (molar mass) of a chemical formula.
Parses formula into an atom tally, looks up each element's mass in the
bundled NIST Atomic Weights and Isotopic Compositions database, and returns
the total weight in the requested unit. Every call reports all three
distinct mass flavors under masses so callers never conflate them or have
to re-ask:
nominal-- sum of the integer mass numbers of the most abundant isotopes,average-- the standard atomic weight (average molar mass),monoisotopic-- the exact mass of the most abundant isotopes.
The monoisotopic flag selects which of these is mirrored at the top level
(weight / uncertainty / formatted) and named by primary.
Optionally propagates NIST uncertainties (uncertainty) and/or reports
percent composition by mass (composition).
Raises ValueError for an unparseable formula or an unknown element.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| formula | Yes | Chemical formula to weigh. Supports element symbols, integer multipliers, arbitrarily nested parenthetical groups, and isotope labels D (deuterium) and T (tritium). Examples: 'H2O', 'C6H12O6', 'Ca(OH)2', 'Fe2(SO4)3', '((CH3)2CH)2', 'D2O', 'Tc'. | |
| unit | No | Output unit for the reported mass. Defaults to grams per mole. | g/mol |
| uncertainty | No | If true, propagate the per-element NIST standard uncertainties in quadrature and report the result as value ± sigma. | |
| monoisotopic | No | Selects which mass flavor is reported at the top level (weight / uncertainty / formatted): false (default) for the standard atomic weight, true for the monoisotopic mass. All three flavors (nominal, average, monoisotopic) are always returned under 'masses' regardless of this flag. | |
| composition | No | If true, return the per-element percent composition by mass (count, mass subtotal, and percentage) alongside the total weight. |