stoiCreate: Stoichiometry Matrix from Reaction Equations

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/plainMethods_stoiBuild_stoiCheck.r

Description

Creates a stoichiometry matrix from a set of reaction equations.

Usage

1
2
3
4
5
6
7
stoiCreate(
  reactions,
  eval = FALSE,
  env = globalenv(),
  toRight = "_forward",
  toLeft = "_backward"
)

Arguments

reactions

A named vector of character strings, each representing a (chemical) reaction. See syntax details below.

eval

Logical. If FALSE (default), the returned matrix is of type character and any mathematical expressions are returned as text. If TRUE, an attempt is made to return a numeric matrix by evaluating the expression making use env.

env

Only relevant if eval is TRUE. Must be an environment or list supplying constants, functions, and operators needed to evaluate expressions in the generated matrix.

toRight

Only relevant for reversible reactions. The passed character string is appended to the name of the respective element of reactions to create a unique name for the forward reaction.

toLeft

Like toRight, but this is the suffix for the backward reaction.

Value

A matrix with the following properties:

Note

The syntax rules for reaction equations are as follows (see examples):

Author(s)

David Kneis david.kneis@tu-dresden.de

See Also

Use stoiCheck to validate the mass balance of the generated matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# EXAMPLE 1: From https://en.wikipedia.org/wiki/Petersen_matrix (July 2016)
#
reactions <- c(
  formS=  "A + 2 * B -> S",
  equiES= "E + S <-> ES",
  decoES= "ES -> E + P"
)
stoi <- stoiCreate(reactions, eval=TRUE, toRight="_f", toLeft="_b")
print(stoi)

# EXAMPLE 2: Decomposition of organic matter (selected equations only)
#
# Eq. 1 and 2 are from Soetaert et al. (1996), Geochimica et Cosmochimica
# Acta, 60 (6), 1019-1040. 'OM' is organic matter. Constants 'nc' and 'pc'
# represent the nitrogen/carbon and phosphorus/carbon ratio, respectively.
reactions <- c(
  oxicDegrad= "OM + O2 -> CO2 + nc * NH3 + pc * H3PO4 + H2O",
  denitrific= "OM + 0.8*HNO3 -> CO2 + nc*NH3 + 0.4*N2 + pc*H3PO4 + 1.4*H2O",
  dissPhosp1= "H3PO4 <-> H + H2PO4",
  dissPhosp2= "H2PO4 <-> H + HPO4"
)
# Non-evaluated matrix
stoi <- stoiCreate(reactions, toRight="_f", toLeft="_b")
print(stoi)
# Evaluated matrix ('nc' and 'pc' according to Redfield ratio)
pars <- list(nc=16/106, pc=1/106)
stoi <- stoiCreate(reactions, eval=TRUE, env=pars, toRight="_f", toLeft="_b")
print(stoi)

Example output

          A  B  S  E ES P
formS    -1 -2  1  0  0 0
equiES_f  0  0 -1 -1  1 0
equiES_b  0  0  1  1 -1 0
decoES    0  0  0  1 -1 1
             OM   O2   CO2 NH3  H3PO4 H2O   HNO3   N2    H    H2PO4 HPO4
oxicDegrad   "-1" "-1" "1" "nc" "pc"  "1"   "0"    "0"   "0"  "0"   "0" 
denitrific   "-1" "0"  "1" "nc" "pc"  "1.4" "-0.8" "0.4" "0"  "0"   "0" 
dissPhosp1_f "0"  "0"  "0" "0"  "-1"  "0"   "0"    "0"   "1"  "1"   "0" 
dissPhosp1_b "0"  "0"  "0" "0"  "1"   "0"   "0"    "0"   "-1" "-1"  "0" 
dissPhosp2_f "0"  "0"  "0" "0"  "0"   "0"   "0"    "0"   "1"  "-1"  "1" 
dissPhosp2_b "0"  "0"  "0" "0"  "0"   "0"   "0"    "0"   "-1" "1"   "-1"
             OM O2 CO2       NH3        H3PO4 H2O HNO3  N2  H H2PO4 HPO4
oxicDegrad   -1 -1   1 0.1509434  0.009433962 1.0  0.0 0.0  0     0    0
denitrific   -1  0   1 0.1509434  0.009433962 1.4 -0.8 0.4  0     0    0
dissPhosp1_f  0  0   0 0.0000000 -1.000000000 0.0  0.0 0.0  1     1    0
dissPhosp1_b  0  0   0 0.0000000  1.000000000 0.0  0.0 0.0 -1    -1    0
dissPhosp2_f  0  0   0 0.0000000  0.000000000 0.0  0.0 0.0  1    -1    1
dissPhosp2_b  0  0   0 0.0000000  0.000000000 0.0  0.0 0.0 -1     1   -1

rodeo documentation built on March 28, 2021, 1:09 a.m.