A deterministic chemistry validator. Paste a chemical formula or a reaction — ElementGate parses it, computes the molar mass, and tells you whether the reaction conserves atoms and charge. No model, no network, no dependencies.
python -m elementgate --demo| Input | ElementGate answers |
|---|---|
Ca(OH)2 |
well-formed? atoms {Ca:1, O:2, H:2}, 74.092 g/mol |
CuSO4·5H2O |
hydrate parsed, 249.677 g/mol |
Fe^3+ + 3 OH- -> Fe(OH)3 |
BALANCED (atoms + charge conserved) |
H2 + O2 -> H2O |
UNBALANCED — O +1 (lhs-rhs) |
Xy2 |
INVALID_FORMULA — unknown element Xy |
python -m elementgate formula "K4[Fe(CN)6]"
python -m elementgate mass "C6H12O6"
python -m elementgate reaction "C3H8 + 5 O2 -> 3 CO2 + 4 H2O"
python -m elementgate reaction "N2 + 3 H2 = 2 NH3" --json$ python -m elementgate reaction "2 H2 + O2 -> 2 H2O"
reaction : 2 H2 + O2 -> 2 H2O
status : BALANCED
lhs atoms: {'H': 4, 'O': 2}
rhs atoms: {'H': 4, 'O': 2}
reason : atoms and charge are conserved
- Formula parsing — nested groups
Ca(OH)2/Fe2(SO4)3/K4[Fe(CN)6], hydratesCuSO4·5H2O, ionsSO4^2-/NH4+. - Molar mass — all 118 elements, IUPAC conventional standard atomic weights, with a per-element breakdown.
- Reaction balancing check — verifies conservation of every element and net charge, and reports the exact imbalance when a reaction doesn't balance.
- Deterministic — same input, same answer, every time.
from elementgate import check_formula, check_reaction, molar_mass
molar_mass("CuSO4·5H2O")[0] # 249.677
check_reaction("HCl + NaOH -> NaCl + H2O").status # "BALANCED"
check_formula("Qz9").status # "INVALID_FORMULA"ElementGate checks chemical bookkeeping: well-formedness, molar mass, and
conservation of atoms and charge. BALANCED means the equation you wrote
conserves atoms and charge — not that the reaction is real, spontaneous, or
favorable. It does not predict products, thermodynamics, or kinetics, and it
does not replace experiment or a chemistry reference. See
docs/LIMITATIONS.md.
python -m unittest discover -s tests -q # 41 testsA small family of standalone, MIT-licensed verification tools (pure stdlib):
- ElementGate — chemistry formulas & reactions (this repo)
- UnitGate — physics-equation dimensional consistency
- EvidencePack — tamper-evident result receipts
- ReplayGate — replay receipts, detect drift
- ClaimLint — lint README/docs for over-claims
- ClaimGate — extract & route claims to gates
MIT — see LICENSE.
