chemistry_tools.formulae.unicode

Attention

This module has the following additional requirements:

cawdrey>=0.5.0
mathematical>=0.5.1
pyparsing>=2.4.6
tabulate>=0.8.9

These can be installed as follows:

python -m pip install chemistry-tools[formulae]

Functions and constants for converting formulae to unicode.

Functions:

string_to_unicode(formula[, prefixes, …])

Convert the given formula string to a unicode string representation.

unicode_subscript(val)

Returns the Unicode subscript of the given value.

unicode_superscript(val)

Returns the Unicode superscript of the given value.

string_to_unicode(formula, prefixes=None, infixes=None, suffixes=('(s)', '(l)', '(g)', '(aq)'))[source]

Convert the given formula string to a unicode string representation.

Examples:

>>> string_to_unicode('NH4+')
'NH₄⁺'
>>> string_to_unicode('Fe(CN)6+2')
'Fe(CN)₆²⁺'
>>> string_to_unicode('Fe(CN)6+2(aq)')
'Fe(CN)₆²⁺(aq)'
>>> string_to_unicode('.NHO-(aq)')
'⋅NHO⁻(aq)'
>>> string_to_unicode('alpha-FeOOH(s)')
'α-FeOOH(s)'
Parameters
  • formula (str) – Chemical formula, e.g. 'H2O', 'Fe+3', 'Cl-'

  • prefixes (Optional[Dict[str, str]]) – Mapping of prefixes to their Unicode equivalents. Default greek letters and .

  • infixes (Optional[Dict[str, str]]) – Mapping of infixes to their Unicode equivalents. Default None.

  • suffixes (Sequence[str]) – Suffixes to keep. Default ('(s)', '(l)', '(g)', '(aq)').

Return type

str

Returns

The Unicode representation of the formula.

unicode_subscript(val)[source]

Returns the Unicode subscript of the given value.

Parameters

val (Union[str, float]) – The value to superscript

Return type

str

unicode_superscript(val)[source]

Returns the Unicode superscript of the given value.

Parameters

val (Union[str, float]) – The value to subscript

Return type

str