Reactions
ChemistryLab.ReactionChemistryLab.CemReactionChemistryLab.chargeChemistryLab.coloredChemistryLab.productsChemistryLab.reactantsChemistryLab.simplify_reaction
ChemistryLab.Reaction — Type
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")))
1julia> Reaction("2H2 + O2 = 2H2O")
equation: 2H2 + O2 = 2H2O
reactants: H₂ => 2, O₂ => 1
products: H₂O => 2
charge: 0julia> Reaction("2H2 + O2 = 2H2O").products
OrderedDict{Species{Int64}, Int64} with 1 entry:
H2O {H2O} [H2O ◆ H₂O] => 2ChemistryLab.CemReaction — Function
CemReaction(equation::AbstractString, args...; kwargs...) -> ReactionConstruct 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: 0ChemistryLab.reactants — Function
reactants(r::Reaction) -> OrderedDictReturn the reactants dictionary (species => coefficient).
Examples
julia> reactants(Reaction("CaCO3 = CO3-2 + Ca+2")) == Dict(Species("CaCO3") => 1)
trueChemistryLab.products — Function
products(r::Reaction) -> OrderedDictReturn the products dictionary (species => coefficient).
Examples
julia> products(Reaction("CaCO3 = CO3-2 + Ca+2")) == Dict(Species("CO3-2") => 1, Species("Ca+2") => 1)
trueChemistryLab.charge — Function
charge(f::Formula) -> Int8Return the formal integer charge of the formula.
Examples
julia> charge(Formula("Ca(HSiO3)+"))
1charge(s::AbstractSpecies) -> Int8Return the formal charge of the species.
Examples
julia> s1 = Species("Ca(HSiO3)+");
julia> charge(s1) == 1
truecharge(r::Reaction)Return the charge difference between products and reactants.
Examples
julia> charge(Reaction("Fe + 2H2O = FeO2- + 4H+"))
3ChemistryLab.simplify_reaction — Function
simplify_reaction(r::Reaction) -> ReactionSimplify 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: 0ChemistryLab.colored — Method
colored(r::Reaction) -> StringReturn the colored terminal representation of the reaction.
Examples
julia> r = Reaction("CaSO4 = Ca²⁺ + SO4²⁻");
julia> print(colored(r)) # Returns string with ANSI color codes