chemhelper.compounds
chemhelper.compounds ¶
Molar mass and composition of chemical compounds.
Formulas are written the usual way, with case-sensitive symbols and optional
counts: 'H2O', 'C6H12O6', 'Ca(OH)2', 'CH3COOH'. Parentheses
and square brackets may be nested.
parse_formula ¶
Count the atoms of each element in a formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chemical
|
str
|
Chemical formula, e.g. |
required |
Returns:
| Type | Description |
|---|---|
OrderedDict
|
Element symbol -> number of atoms, in order of first appearance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the formula contains an unknown element, unbalanced parentheses or characters that are not part of a formula. |
Examples:
Source code in src/chemhelper/compounds.py
mass ¶
Molar mass of a compound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chemical
|
str
|
Chemical formula, e.g. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Molar mass in g/mol, rounded to 2 decimals. |
Examples:
Source code in src/chemhelper/compounds.py
mass_steps ¶
Print a step-by-step molar mass calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chemical
|
str
|
Chemical formula, e.g. |
required |
Examples:
Source code in src/chemhelper/compounds.py
composition ¶
Mass contributed by each element in one mole of a compound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chemical
|
str
|
Chemical formula, e.g. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Grams of each element per mole of compound, plus a |
Examples:
Source code in src/chemhelper/compounds.py
composition_steps ¶
Print the molar mass calculation followed by :func:composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chemical
|
str
|
Chemical formula, e.g. |
required |
Source code in src/chemhelper/compounds.py
percent_composition ¶
Percent by mass of each element in a compound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chemical
|
str
|
Chemical formula, e.g. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Percent of each element, rounded to 3 decimals, plus |
Examples:
Source code in src/chemhelper/compounds.py
percent_composition_steps ¶
Print a step-by-step percent composition calculation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chemical
|
str
|
Chemical formula, e.g. |
required |