Science
vchem
Parses chemical formulas and works out molar mass and gas law arithmetic.
Released v1.0.0 · 2026-09-28use "stdlib/chem.ven"
Chemical formulas, molar mass, gas laws and pH, in a handful of exact functions.
print parse_formula("CaCO3")
:: {"Ca": 1, "C": 1, "O": 3}
Reference (6 functions)
API reference
parse_formula(formula)
Parses a flat chemical formula into pairs of element symbol and count.
parse_formula("CaCO3")
:: {"Ca": 1, "C": 1, "O": 3}moles_to_grams(moles, formula)
Converts an amount in moles of formula to a mass in grams.
moles_to_grams(2.0, "H2O")
:: 36.03grams_to_moles(grams, formula)
Converts a mass in grams of formula to an amount in moles.
grams_to_moles(36.03, "H2O")
:: 2.0ideal_gas_pressure(moles, temperature_k, volume_l)
Computes gas pressure from the ideal gas law, PV = nRT.
ideal_gas_pressure(1.0, 273.15, 22.4)
:: 1.0006228345982142ph_from_concentration(hydrogen_ion_molarity)
Computes pH from a hydrogen ion concentration.
ph_from_concentration(0.0000001)
:: 7.0