Skip to content

kyal102/elementgate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ElementGate

ElementGate

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

What it checks

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 UNBALANCEDO +1 (lhs-rhs)
Xy2 INVALID_FORMULA — unknown element Xy

One command (pure Python stdlib)

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

Real output

$ 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

Features

  • Formula parsing — nested groups Ca(OH)2 / Fe2(SO4)3 / K4[Fe(CN)6], hydrates CuSO4·5H2O, ions SO4^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.

In Python

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"

What this is — and isn't

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.

Tests

python -m unittest discover -s tests -q     # 41 tests

Part of the ClaimGate ecosystem

A 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

License

MIT — see LICENSE.

About

Deterministic chemistry validator — formula parsing, molar mass, reaction balance (atoms + charge). Pure Python stdlib.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages