aim2dat.utils.chem_formula
¶
Module to parse representations of chemical formulas into each other.
Module Contents¶
Functions¶
|
Check if two chemical formulas are identical. |
|
Try to find a reduced formula only having natural numbers as quantities |
|
Create a string from a formula dictionary, fractional quantities are rounded. |
|
Create a string from a formula dictionary, fractional quantities are rounded. |
|
Convert a list of elements to a dictionary. |
|
Convert a list of elements to a dictionary. |
|
Create a dictionary from a formula string. The function supports round, squared and curly |
-
aim2dat.utils.chem_formula.compare_formulas(chem_formula1, chem_formula2, reduce_formulas=
False
)[source]¶ Check if two chemical formulas are identical.
- Parameters:¶
chem_formula1 (dict) – Chemical formula as dictionary, e.g.
{'Fe' : 4.0, 'O' : 6.0}
or{'H' : 2.0, 'O' : 1.0}
.chem_formula2 (dict) – Chemical formula as dictionary, e.g.
{'Fe' : 4.0, 'O' : 6.0}
or{'H' : 2.0, 'O' : 1.0}
.reduce_formulas (bool) – Whether to reduce the formulas before comparison.
- Returns:¶
match (bool) –
True
if the two forumals are identical
-
aim2dat.utils.chem_formula.reduce_formula(formula_dict, tolerance=
0.0001
)[source]¶ Try to find a reduced formula only having natural numbers as quantities
- Parameters:¶
formula_dict (dict) – Chemical formula as dictionary, e.g.
{'Fe' : 4.0, 'O' : 6.0}
or{'H' : 2.0, 'O' : 1.0}
tolerance (float) – Tolerance to determine fractions, e.g.,
0.33333
is intepreted as 1/3 for a tolerance of1.0e-4
.
- Returns:¶
formula_red (dict) – Chemical formula as dictionary, e.g.
{'Fe' : 2, 'O' : 3}
or{'H' : 2, 'O' : 1}
- aim2dat.utils.chem_formula.transform_dict_to_latexstr(formula_dict)[source]¶
Create a string from a formula dictionary, fractional quantities are rounded.
-
aim2dat.utils.chem_formula.transform_dict_to_str(formula_dict, output_type=
None
)[source]¶ Create a string from a formula dictionary, fractional quantities are rounded.
- Parameters:¶
formula_dict (dict) – Chemical formula as dictionary, e.g.
{'Fe' : 2.0, 'O' : 3.0}
or{'H' : 2.0, 'O' : 1.0}
output_type (None or str) – If set to
'alphabetic'
the output formula will be alphabetically ordered.
- Returns:¶
formula_str (str) – Chemical formula as string, e.g.
Fe2O3`, ``H2O
- aim2dat.utils.chem_formula.transform_list_to_dict(formula_list)[source]¶
Convert a list of elements to a dictionary.
- aim2dat.utils.chem_formula.transform_list_to_str(formula_list)[source]¶
Convert a list of elements to a dictionary.
- aim2dat.utils.chem_formula.transform_str_to_dict(formula_str)[source]¶
Create a dictionary from a formula string. The function supports round, squared and curly brackets as well as recurring elements.
Examples
>>> transform_str_to_dict('HOH') {'H': 2.0, 'O': 1.0}
>>> transform_str_to_dict("H.5(CO)CH3{OH[CH]4}3.5") {'C': 16.0, 'O': 4.5, 'H': 21.0}