vibesketch.chem.formula¶
Chemical formulas of solids that have no molecular graph (#142).
Oxides, salts, catalysts and scales are written as formulas, not drawn as structures: Fe2O3, Pb3(CO3)2(OH)2, CuSO4·5H2O, a variable or doped composition such as Fe3−xCrxO4 or CoAlxOy, a composite such as AlOx–Fe2O3, with an optional polymorph (γ-Al2O3) and state ((s)). This module reads such a formula into its composition, the canonical form that identifies it, and, when every count is a number, its molar mass with the atomic weights RDKit gives the species report.
Grammar, informally: [polymorph-]phase[–phase…][(state)], a phase being
groups and elements each with an optional count, hydrate parts after ·
(or ./*) with a leading multiplier, and a count a number, a variable
(x, y, z or δ), or a number with a variable added or taken away (3−x).
Functions
|
The formula a canvas text writes for a solid, or |
|
Read a formula; raises |
Classes
|
A formula read: its phases' compositions, polymorph and state. |
Exceptions
Text that is not a formula this module reads; the message says where. |
- class vibesketch.chem.formula.Formula(text, phases, polymorph=None, state=None, written=())[source]¶
Bases:
objectA formula read: its phases’ compositions, polymorph and state.
- Parameters:
- property composition: dict[str, float | str][source]¶
The elements of all phases together; a variable count keeps its expression.
- canonical()[source]¶
Each phase in Hill order, phases joined by a dash: what identifies the solid.
A variable count is kept in parentheses, Fe3−xCrxO4 as Cr(x)Fe(3-x)O4.
- Return type:
- molar_mass()[source]¶
g/mol from RDKit’s atomic weights, or
Nonewith a variable count.- Return type:
float | None
- exception vibesketch.chem.formula.FormulaError[source]¶
Bases:
ValueErrorText that is not a formula this module reads; the message says where.
- vibesketch.chem.formula.is_solid_text(text)[source]¶
The formula a canvas text writes for a solid, or
None.Only a whole text that is a formula marked as a solid counts: with the state (s) or a polymorph, so that conditions such as NaOH or H2O at an arrow keep their meaning.
- vibesketch.chem.formula.parse_formula(text)[source]¶
Read a formula; raises
FormulaErrorfor anything else.