Molecular weight¶
Functions to calculate molecular weight of an element, compound, or gas mixture. Note that mole fractions must sum to one otherwise an error is raised.

chemics.molecular_weight.
mw
(formula)[source]¶ Tokenize a molecular formula to determine total molecular weight. Calculation is based on atomic weight values from IUPAC 1.
 Parameters
formula (str) – Molecular formula or element.
 Returns
mw (float) – Molecular weight of the formula or element [g/mol]
Examples
>>> mw('C') 12.011
>>> mw('CH4') 16.04
>>> mw('(NH4)2SO4') 132.13
References
 1
IUPAC Periodic Table of the Elements. International Union of Pure and Applied Chemistry, 2016. https://iupac.org/whatwedo/periodictableofelements/.

chemics.molecular_weight.
mw_mix
(mws, xs)[source]¶ Molecular weight of a gas mixture calculated as a weighted mean.
 Parameters
mws (list, tuple, or array) – Molecular weight of each gas component [g/mol]
xs (list, tuple, or array) – Mole fraction of each gas component []
 Returns
mw_mix (float) – Molecular weight of a gas mixture [g/mol]
 Raises
ValueError – If sum of mole fractions does not equal 1.0
Examples
>>> mw_h2 = cm.mw('H2') ... mw_n2 = cm.mw('N2') ... mw_mix([mw_h2, mw_n2], [0.8, 0.2]) 7.2156
>>> mw_h2 = cm.mw('H2') ... mw_n2 = cm.mw('N2') ... mw_ch4 = cm.mw('CH4') ... mw_mix([mw_h2, mw_n2, mw_ch4], [0.4, 0.1, 0.5]) 11.6293