chemistry_tools.formulae.parser
Attention
This module has the following additional requirements:
cawdrey>=0.5.0 mathematical>=0.5.1 pyparsing>=2.4.6 tabulate>=0.8.9
These can be installed as follows:
python -m pip install chemistry-tools[formulae]
Functions and parsing formulae.
Functions:
|
Calculates molecular mass, in atomic mass units, from atomic weights. |
|
Parse composition of formula representing a chemical formula. |
-
mass_from_composition
(composition, charge=0)[source] Calculates molecular mass, in atomic mass units, from atomic weights.
Note
Atomic number 0 denotes charge or “net electron defficiency”
Example:
>>> f'{mass_from_composition({0: -1, "H": 1, 8: 1}):.2f}' '17.01'
-
string_to_composition
(formula, prefixes=None, suffixes=('(s)', '(l)', '(g)', '(aq)'))[source] Parse composition of formula representing a chemical formula.
Examples:
>>> string_to_composition('NH4+') == {0: 1, "H": 4, "N": 1} True >>> string_to_composition('.NHO-(aq)') == {0: -1, "H": 1, "N": 1, "O": 1} True >>> string_to_composition('Na2CO3.7H2O') == {"Na": 2, "C": 1, "O": 10, "H": 14} True
- Parameters
- Return type
- Returns
The composition, as a dictionary mapping atomic number -> multiplicity. “Atomic number” 0 represents net charge.