Chemical reactions
In CementChermistry it is possible to build chemical reactions and manipulate them. A reaction is constructed as a structure, "a composite data type that allows you to store multiple values in a single object". The struct
is organized as follows:
struct Reaction{SR<:AbstractSpecies, TR<:Number, SP<:AbstractSpecies, TP<:Number}
equation::String
colored::String
reactants::OrderedDict{SR, TR}
products::OrderedDict{SP, TP}
equal_sign::Char
properties::OrderedDict{Symbol,PropertyType}
end
Parsing reactions
Reaction
is a composite type struct
which can be build from:
- a string containing species
equation = "13H⁺ + NO₃⁻ + CO₃²⁻ + 10e⁻ = 6H₂O@ + HCN@"
reac, prod, equal_sign = parse_equation(equation)
- a string containing cement species
eqC3S = "C₃S + 5.3H = 1.3CH + C₁.₇SH₄"
rC3S = CemReaction(eqC3S)
- an operation on species
using ChemistryLab
C3S = CemSpecies("C3S")
H = CemSpecies("H")
CH = CemSpecies("CH")
CSH = CemSpecies("C1.7SH4")
r = C3S + 5.3H ↔ 1.3CH + CSH
typeof(r)
Reaction{CemSpecies, Real, CemSpecies, Real}
- a balance calculation
using ChemistryLab
C3S = CemSpecies("C3S")
H = CemSpecies("H")
CH = CemSpecies("CH")
CSH = CemSpecies("C1.7SH4")
r = Reaction([C3S, H, CH, CSH]; equal_sign='→')
C₃S + 5.3H → 1.3CH + C₁.₇SH₄
reactants: C₃S => 1, H => 5.3
products: CH => 1.3, C₁.₇SH₄ => 1
- a balance calculation with symbolic numbers
using ChemistryLab
using SymPy
â, b̂, ĝ = symbols("â b̂ ĝ", real=true)
CSH = CemSpecies(Dict(:C => â, :S => one(Sym), :H => ĝ))
C3S = CemSpecies("C3S")
H = CemSpecies("H")
CH = CemSpecies("CH")
r = Reaction([CSH, C3S, H, CH]; equal_sign='→')
CâSHĝ → (-â+ĝ+3)H + C₃S + (â-3)CH
reactants: CâSHĝ => 1
products: H => -â + ĝ + 3, C₃S => 1, CH => â - 3
using ChemistryLab
C3S = CemSpecies("C3S")
H = CemSpecies("H")
CH = CemSpecies("CH")
CSH = CemSpecies("C1.7SH4")
r = map(simplify, Reaction([C3S, H], [CH, CSH]; equal_sign='→'))
A, _, _ = stoich_matrix([C3S], [CSH, H, CH]; involve_all_atoms=true) ;