automol.form#

some words

molecular formula

automol.form.add_element(fml, symb, num=1)#

Add or subtract (if num < 0) this element from the molecular formula.

Parameters:
  • fml (dict[str, int]) – Stochiometric chemical formula

  • symb (str) – Atomic symbol of element to be added

  • num (int) – Number of the element to add to the formula

Return type:

dict[str, int]

Returns:

Formula with added element

automol.form.argsort_symbols(seq, symbs_first=('C', 'H'), symbs_last=(), idx=None)#

Determine the sort order for a sequence of atomic symbols.

Parameters:
  • seq (Sequence) – Formula or sequence of atomic symbols

  • symbs_first (Sequence[str]) – Atomic symbols to place first

  • symbs_last (Sequence[str]) – Atomic symbols to place last

  • idx (Optional[int]) – Index of symbol for sorting

Return type:

tuple[str, ...]

Returns:

Sorted syymboles

automol.form.atom_count(fml)#

Count the number of atoms in this molecular formula.

Parameters:

fml (dict[str, int]) – Stochiometric chemical formula

Return type:

int

Returns:

Number of atoms.

automol.form.electron_count(fml)#

Count the number of electrons for the atoms in a molecular formula.

Parameters:

fml (dict[str, int]) – Stochiometric chemical formula

Return type:

int

Returns:

Number of electrons.

automol.form.element_count(fml, symb)#

Count the number of a given element in this molecular formula.

Parameters:
  • fml (dict[str, int]) – Stochiometric chemical formula

  • symb (str) – Atomic symbol of element to be counted

Return type:

int

Returns:

Number of a certain element in the formula

automol.form.equal(fml1, fml2)#

Determine whether two formulas are equal.

Parameters:
Return type:

bool

Returns:

True if they are, False if the are not

automol.form.from_string(fml_str)#

Convert formula string to formula dictionary.

Wildcard values can be specified as, for example, ‘O2H*’, which will be interpreted as {‘O’: 2, ‘H’: -1} where the -1 indicates a wildcard stoichiometry.

Parameters:

fml_str (str) – stochiometric chemical formula string

Return type:

dict[str, int]

Returns:

The formula

automol.form.heavy_atom_count(fml)#

Count the number of heavy atoms in this molecular formula.

Parameters:

fml (dict[str, int]) – Stochiometric chemical formula

Return type:

int

Returns:

Number of heavy atoms

automol.form.join(fml1, fml2)#

Join two formulas together.

Parameters:
  • fml1 (dict[str, int]) – Stochiometric chemical formula 1

  • fml2 (dict[str, int]) – Stochiometric chemical formula 2

Return type:

int

Returns:

Formula with the sum of both formulas

automol.form.join_sequence(fmls)#

Join a sequence of formulas together.

Parameters:

fml – Stochiometric chemical formula

Return type:

int

Returns:

Sum of the formulas

automol.form.match(fml1, fml2)#

Check for a match between two formulas, allowing wildcard values.

A stoichiometry of -1 indicates a wildcard value

Parameters:
Return type:

bool

Returns:

True if so, False if not

automol.form.sort_vector(fml, symbs=None)#

Generate a sort vector for sorting various formulas against each other.

Parameters:
  • fml (dict[str, int]) – stochiometric chemical formula string

  • symbs (Optional[Sequence[str]]) – atomic symbols in the desired sort order (optional)

Return type:

tuple[int, ...]

Returns:

Sorted vector

automol.form.sorted_sequence(fmls)#

Sort a sequence of formulas based on Hill-sorting.

Parameters:

fmls (Sequence[dict[str, int] | str]) – A sequence of formulas

Return type:

list[dict[str, int]]

Returns:

The sorted formulas in the sequence

automol.form.sorted_symbols(seq, symbs_first=('C', 'H'), symbs_last=())#

Produce a sorted list of atomic symbols; some elements given priority. By default, C placed first, then H, then others in alphabetical order.

Parameters:
  • seq (Sequence) – Formula or sequence of atomic symbols

  • symbs_first (Sequence[str]) – Atomic symbols to place first

  • symbs_last (Sequence[str]) – Atomic symbols to place last

Return type:

tuple[str, ...]

Returns:

Sorted list

automol.form.sorted_symbols_in_sequence(fmls)#

Sort a sequence of formulas based on Hill-sorting.

Parameters:

fmls (Sequence[dict[str, int]]) – A sequence of formulas

Return type:

tuple[str, ...]

Returns:

The sorted symbols in the sequence

automol.form.string(fml, hyd=True)#

Convert formula dictionary to formula string in the Hill convention. Resultant string is identical to InChI formula string.

Parameters:
  • fml (dict[str, int]) – stochiometric chemical formula

  • hyd (bool) – include hydrogens?

Return type:

str

Returns:

True if formula includes hydrogen, False if no hydrogen

automol.form.string2(fml)#

Convert formula dictionary to formula string that includes 1s in when there is only one atom.

Parameters:

fml (dict[str, int]) – stochiometric chemical formula

Return type:

str

Returns:

Formula which includes 1s when there is only one atom

automol.form.unique(fmls)#

Get the unique formulas in a list.

Parameters:

fmls (Sequence[dict[str, int]]) – A sequence of formulas

Return type:

list[dict[str, int]]

Returns:

The unique formulas in the sequence

automol.form.without(fml, symbs=())#

Return a formula without hydrogen.

Parameters:

fml (dict[str, int]) – A chemical formula

Symbs:

Chemical symbols

Return type:

dict[str, int]

Returns:

Dictionary with new formula, without hydrogen

automol.form.reac#

some words

reaction formulae.

automol.form.reac.argsort_hydrogen_abstraction(rct_fmls, prd_fmls)#

Generate the indices which allows the reactants and products of a hydrogen abstraction reaction can be sorted as RH + Q => R + QH.

Parameters:
Return type:

tuple[tuple[int, int], tuple[int, int]] | None

Returns:

Indices to sort reaction to R + QH

automol.form.reac.is_valid_reaction(rct_fmls, prd_fmls)#

Use the formula to see if a reaction preserves stoichiometry.

Parameters:
Return type:

bool

Returns:

True if the reaction is valid, False if not