Science

vchem

Parses chemical formulas and works out molar mass and gas law arithmetic.

Released v1.0.0 · 2026-09-28
Import
use "stdlib/chem.ven"

Chemical formulas, molar mass, gas laws and pH, in a handful of exact functions.

vchem.ven
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}

molar_mass(formula)

Computes the molar mass of formula in grams per mole.

molar_mass("H2O")
:: 18.015

moles_to_grams(moles, formula)

Converts an amount in moles of formula to a mass in grams.

moles_to_grams(2.0, "H2O")
:: 36.03

grams_to_moles(grams, formula)

Converts a mass in grams of formula to an amount in moles.

grams_to_moles(36.03, "H2O")
:: 2.0

ideal_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.0006228345982142

ph_from_concentration(hydrogen_ion_molarity)

Computes pH from a hydrogen ion concentration.

ph_from_concentration(0.0000001)
:: 7.0

Get notified when vchem changes

Get notified about

New versions and security advisories.

New and updated packages, once a day.

News on the math model built in Venutian.