PourPy.parser

Classes

Reactant

Reactant class that defines an ion, compound or electron including all required thermodynamic and molecular parameters.

State

Create a collection of name/value pairs.

Parser

Helper class that provides a standard way to create an ABC using

DefaultParser

Helper class that provides a standard way to create an ABC using

Module Contents

class PourPy.parser.Reactant(formula, state, dGf, dHf, Sm, elements)

Reactant class that defines an ion, compound or electron including all required thermodynamic and molecular parameters.

__str__()

Return str(self).

initialize()

Initialize additional properties of the Reactant.

Returns:

None

Return type:

None

_get_formula(formula)

Validate and returns user-input chemical formula of the reactant.

Parameters:

formula – The chemical formula to validate.

Returns:

Validated chemical formula.

_get_state(state)

Validates and returns the user-input physical state of the reactant.

Parameters:

state – The physical state to validate.

Returns:

Validated physical state.

_get_charge()

Validates and returns the user-input charge of the reactant.

Returns:

The charge of the reactant, 0 if not present.

_get_atoms(elements)

Retrieves a dictionary of atoms in the reactant.

Returns:

A dictionary containing atom symbols as keys and their counts as values.

_get_molecular_weight(elements)

Calculates the molecular weight of the reactant.

Returns:

The molecular weight of the reactant in grams per mole.

_get_super_string(x)

Converts numeric characters in the formula of the reactant to Unicode superscript characters.

Parameters:

x – The input string to convert.

Returns:

The input string with numeric characters replaced by super-script characters.

_get_sub_string(x)

Converts numeric characters in the formula of the reactant to Unicode subscript characters.

Parameters:

x – The input string to convert.

Returns:

The input string with numeric characters replaced by sub-script characters.

_get_reactant_string()

Creates a formatted string representing the reactant formula.

Returns:

Formatted string representation of the reactant, including subscripts for number of atoms and superscripts for charge.

class PourPy.parser.State(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

aqueous = 'aq'
solid = 's'
gaseous = 'g'
liquid = 'l'
electron = 'e'
class PourPy.parser.Parser

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

abstract parse_reactions()
abstract parse_species()
abstract parse_elements()
class PourPy.parser.DefaultParser

Bases: Parser

Helper class that provides a standard way to create an ABC using inheritance.

static parse_reactions(reactions: tuple)

Parses several reactions given as tuple

Parameters:

reactions (tuple) – reactions to be parsed, each entry of a tuple is a reaction string

:return : reactions as list, each entry is a dict containing reactants :rtype : list

static parse_reaction(reaction: str)

Parse a reaction from its string representation

Parameters:

reaction (str) – reaction to be parsed

:return : reactants as dict :rtype : dict

static parse_species(species: tuple, elements: dict)
static parse_specie(specie: str)

Parse a specie and its chemical props from its string representation

Parameters:

specie (str) – specie_name,state,dGf,dHf,Sm as string

:return : name of the specie, properties as dictionary :rtype : tuple

static parse_elements()