Reactions

ChemistryLab.ReactionType
struct Reaction{SR<:AbstractSpecies,TR<:Number,SP<:AbstractSpecies,TP<:Number}

Representation of a chemical reaction with reactants and products.

Fields

  • equation::String: Unicode equation string.
  • colored::String: colored terminal representation.
  • reactants::OrderedDict{SR,TR}: species => coefficient for reactants.
  • products::OrderedDict{SP,TP}: species => coefficient for products.
  • charge::IC: charge difference between products and reactants.
  • equal_sign::Char: equality operator character.
  • properties::OrderedDict{Symbol,PropertyType}: thermodynamic and other properties.

Examples

julia> length(Reaction("2H2 + O2 = 2H2O"))
3

julia> length(products(Reaction("2H2 + O2 = 2H2O")))
1
julia> Reaction("2H2 + O2 = 2H2O")
  equation: 2H2 + O2 = 2H2O
 reactants: H₂ => 2, O₂ => 1
  products: H₂O => 2
    charge: 0
julia> Reaction("2H2 + O2 = 2H2O").products
OrderedDict{Species{Int64}, Int64} with 1 entry:
  H2O {H2O} [H2O ◆ H₂O] => 2
source
ChemistryLab.CemReactionFunction
CemReaction(equation::AbstractString, args...; kwargs...) -> Reaction

Construct a Reaction using CemSpecies from an equation string. Convenience constructor equivalent to Reaction(equation, CemSpecies, args...; kwargs...).

Examples

julia> CemReaction("C + H = CH")
  equation: C + H = CH
 reactants: C => 1, H => 1
  products: CH => 1
    charge: 0
source
ChemistryLab.reactantsFunction
reactants(r::Reaction) -> OrderedDict

Return the reactants dictionary (species => coefficient).

Examples

julia> reactants(Reaction("CaCO3 = CO3-2 + Ca+2")) == Dict(Species("CaCO3") => 1)
true
source
ChemistryLab.productsFunction
products(r::Reaction) -> OrderedDict

Return the products dictionary (species => coefficient).

Examples

julia> products(Reaction("CaCO3 = CO3-2 + Ca+2")) == Dict(Species("CO3-2") => 1, Species("Ca+2") => 1)
true
source
ChemistryLab.chargeFunction
charge(f::Formula) -> Int8

Return the formal integer charge of the formula.

Examples

julia> charge(Formula("Ca(HSiO3)+"))
1
source
charge(s::AbstractSpecies) -> Int8

Return the formal charge of the species.

Examples

julia> s1 = Species("Ca(HSiO3)+");

julia> charge(s1) == 1
true
source
charge(r::Reaction)

Return the charge difference between products and reactants.

Examples

julia> charge(Reaction("Fe + 2H2O = FeO2- + 4H+"))
3
source
ChemistryLab.simplify_reactionFunction
simplify_reaction(r::Reaction) -> Reaction

Simplify a reaction by canceling common species from both sides.

Examples

julia> simplify_reaction(Reaction("2H2 + O2 + H2O = 3H2O"))
  equation: 2H₂ + O₂ = 2H₂O
 reactants: H₂ => 2, O₂ => 1
  products: H₂O => 2
    charge: 0
source
ChemistryLab.coloredMethod
colored(r::Reaction) -> String

Return the colored terminal representation of the reaction.

Examples

julia> r = Reaction("CaSO4 = Ca²⁺ + SO4²⁻");

julia> print(colored(r))  # Returns string with ANSI color codes
source