chemreac.chemistry

This module collects classes useful for describing substances, reactions and reaction systems. The classes have methods to help with consistent low-level conversion to numerical parameters of the model.

class chemreac.chemistry.Reaction(active_reac, products, inactv_reac=None, k=None, T=None, Ea=None, A=None, ref=None, name=None)[source]

Reaction with kinetics governed by the law of mass-action. Example:

A + R –> A + P; r = k*A*R

Also supports

5*C1 + C2 –> B; r = k*C1*C2

by specifying active reactants C1, C2 and inactive reaktants 4*C1.

reactants and products are dictionaries with substance names as keys and positive integers giving their stoichiometric coeffecients as values

rate constant i either given as k (T optional as validity info) or as Ea and A for use in the Arrhenius equation

and ref contains optional information on origin of data.

along the same lines name is possible to use if the reaction is known under a certain name, e.g. “H2O2 auto-decomposition”

Parameters:

active_reac: dict

dictionary mapping substance name (string) to stoichiometric coefficient (integer) of reactant, these affect rate expression.

products: dict

dictionary mapping substance name (string) to stoichiometric coefficient (integer)

inactv_reac: dict (optional)

Same as active_reac but does not affect rate expression.

k: float

rate coefficient

T: float

absolute temperature

Ea: float

activation energy

A: float

preexponential prefactor (Arrhenius type eq.)

ref: string (optional)

Reference key

name: string (optional)

Descriptive name of reaction

class chemreac.chemistry.ReactionSystem(rxns=None, name=None, substances=None)[source]

Collection of reactions forming a system (model).

Parameters:

rxns: sequence

sequence of Reaction instances

name: string (optional)

Name of ReactionSystem (e.g. model name / citation key)

substances: sequence (optional)

Sequence of Substance instances, will be used in doing a sanity check and as default in method to_ReactionDiffusion()

Attributes

k List of rate constants
ns Number of species
nr Number of reactions
rxns sequence of Reaction instances
species_names names of occurring species
k[source]

List of rate constants

nr[source]

Number of reactions

ns[source]

Number of species

to_ReactionDiffusion(substances=None, ordered_names=None, **kwargs)[source]

Creates a ReactionDiffusion instance from self.

Parameters:

substances: sequence of Substance instances

pass to override self.substances (optional)

ordered_names: sequence of names

pass to override self.ordered_names()

**kwargs:

Keyword arguments passed on to ReactionDiffusion

class chemreac.chemistry.Substance(name, charge=None, mass=None, formula=None, tex_name=None, multiplicity=None, D=0.0, **kwargs)[source]

Substance class to represent a chemical speices.

Parameters:

name: string

unique string representation e.g. “H2O”, “CNO-”, “OCN-“

charge: integer

charge of substance

mass: float

molar mass (default None)

formula: e.g. periodictable.formulas.Formula instance

optional, if formula instance provides mass attribute it is used as mass in the case mass=None

tex_name: string

optional, TeX formated string, e.g. ‘$mathrm{OH^{-}}$’

multiplicity: integer

optional, 1 for singlet, 2 for doublet...

D: float (optional)

diffusion coefficent, for now: isothermal, isotropic and only for one medium. default: 0.0

**kwargs:

additional freely chosen attributes

Examples

>>> Substance(name='H2O', charge=0, tex_name=r'$\mathrm{H_{2}O}$', pKa=14)
<Substance 'H2O'>
>>> Substance.all_substances['H2O']
<Substance 'H2O'>
>>> 'H2O' in Substance.all_substances
True

Attributes

all_substances dictionary (name, insatnce) of all Substance instances.
get_mobility(Temp, **kwargs)[source]

See chemreac.util.physchem.electrical_mobility_from_D

chemreac.chemistry.mk_sn_dict_from_names(names, **kwargs)[source]

Convenience function to generate a OrderedDict of Substance instances from a sequence of names and corresponding sequences of kwargs to Substance class.

Parameters:

names: sequence of strings

names of substances

**kwargs:

sequences of corresponding keyword arguments

Examples

>>> mk_sn_dict_from_names(
...     'ABCD', D=[0.1, 0.2, 0.3, 0.4]) 
OrderedDict([('A', <Substance 'A'>), ('B', <Substance 'B'>),
('C', <Substance 'C'>), ('D', <Substance 'D'>)])