aim2dat.utils.chem_formula

Module to parse representations of chemical formulas into each other.

Module Contents

Functions

compare_formulas(chem_formula1, chem_formula2[, ...])

Check if two chemical formulas are identical.

reduce_formula(formula_dict)

Try to find a reduced formula. Elements with fractional occupation numbers are neglected.

transform_dict_to_latexstr(formula_dict)

Create a string from a formula dictionary, fractional quantities are rounded.

transform_dict_to_str(formula_dict[, output_type])

Create a string from a formula dictionary, fractional quantities are rounded.

transform_list_to_dict(formula_list)

Convert a list of elements to a dictionary.

transform_list_to_str(formula_list)

Convert a list of elements to a dictionary.

transform_str_to_dict(formula_str)

Create a dictionary from a formula string.

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)[source]

Try to find a reduced formula. Elements with fractional occupation numbers are neglected.

Parameters:

formula_dict (dict) – Chemical formula as dictionary, e.g. {'Fe' : 4.0, 'O' : 6.0} or {'H' : 2.0, 'O' : 1.0}

Returns:

formula_red (dict) – Chemical formula as dictionary, e.g. {'Fe' : 2.0, 'O' : 3.0} or {'H' : 2.0, 'O' : 1.0}

aim2dat.utils.chem_formula.transform_dict_to_latexstr(formula_dict)[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}.

Returns:

formula_str (str) – Chemical formula as string with latex formating, e.g. r'$\mathrm{Fe}_{\mathrm{2}}\mathrm{O3}$', r'$\mathrm{H}_{\mathrm{2}}\mathrm{O}$'.

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.

Parameters:

formula_list (list) – Chemical formula as list, e.g. ['Fe', 'Fe', 'O', 'O', 'O'] or ['H', 'O', 'H']

Returns:

formula_dict (dict) – Chemical formula as dictionary, e.g. {'Fe' : 2.0, 'O' : 3.0} or {'H' : 2.0, 'O' : 1.0}

aim2dat.utils.chem_formula.transform_list_to_str(formula_list)[source]

Convert a list of elements to a dictionary.

Parameters:

formula_list (list) – Chemical formula as list, e.g. ['Fe', 'Fe', 'O', 'O', 'O'] or ['H', 'O', 'H']

Returns:

formula_str (str) – Chemical formula as string, e.g. Fe2O3`, ``H2O

aim2dat.utils.chem_formula.transform_str_to_dict(formula_str)[source]

Create a dictionary from a formula string.

Parameters:

formula_str (str) – Chemical formula as string, e.g. Fe2O3`, ``H2O

Returns:

formula_dict (dict) – Chemical formula as dictionary, e.g. {'Fe' : 2.0, 'O' : 3.0} or {'H' : 2.0, 'O' : 1.0}