Formulas

ChemistryLab.AtomGroupType
struct AtomGroup{T}

Simple container pairing an atomic symbol with a numeric coefficient.

Fields

  • coef::T: numeric coefficient.
  • sym::Symbol: atomic symbol.

Examples

julia> AtomGroup(:H, 2)
AtomGroup{Int64}(2, :H)

julia> AtomGroup(:Ca)
AtomGroup{Int64}(1, :Ca)
source
ChemistryLab.AtomGroupMethod
AtomGroup(sym::Symbol) -> AtomGroup
AtomGroup(sym::Symbol, coef::T) where {T<:Number} -> AtomGroup{T}

Constructors for AtomGroup.

Arguments

  • sym: atomic symbol.
  • coef: numeric coefficient (default 1).

Examples

julia> AtomGroup(:C)
AtomGroup{Int64}(1, :C)

julia> AtomGroup(:C, 3)
AtomGroup{Int64}(3, :C)
source
Base.convertMethod
Base.convert(::Type{AtomGroup}, sym::Symbol) -> AtomGroup

Convert a Symbol to a unit AtomGroup (coefficient = 1).

Examples

julia> convert(AtomGroup, :O)
AtomGroup{Int64}(1, :O)
source
ChemistryLab.stoichtypeFunction
stoichtype(f::Formula{T}) where {T} -> Type{T}

Return the numeric stoichiometric coefficient type T for formula f.

Examples

julia> stoichtype(Formula("H2O"))
Int64
source
ChemistryLab.FormulaType
struct Formula{T}

Canonical container for a chemical formula.

Fields

  • expr::String: original input expression.
  • phreeqc::String: PHREEQC-compatible representation.
  • unicode::String: Unicode pretty representation.
  • colored::String: colored terminal representation.
  • composition::OrderedDict{Symbol,T}: mapping element symbol to coefficient.
  • charge::Int8: formal integer charge.

Examples

julia> f = Formula("H2O");

julia> composition(f)[:H]
2
source
ChemistryLab.exprMethod
expr(f::Formula) -> String

Return the original expression string stored in f.

Examples

julia> expr(Formula("H2O"))
"H2O"
source
ChemistryLab.phreeqcMethod
phreeqc(f::Formula) -> String

Return the PHREEQC-compatible representation of f.

Examples

julia> phreeqc(Formula("H2O"))
"H2O"
source
ChemistryLab.unicodeMethod
unicode(f::Formula) -> String

Return the Unicode pretty representation of f.

Examples

julia> phreeqc(Formula("C3A"))
"C3A"
source
ChemistryLab.coloredMethod
colored(f::Formula) -> String

Return the colored terminal representation of f.

Examples

julia> colored(Formula("Ca(HSiO3)+"))
source
ChemistryLab.compositionMethod
composition(f::Formula) -> OrderedDict{Symbol,T}

Return the composition mapping (element symbol => coefficient).

Examples

julia> composition(Formula("Ca(HSiO3)+"))
source
ChemistryLab.chargeMethod
charge(f::Formula) -> Int8

Return the formal integer charge of the formula.

Examples

julia> charge(Formula("Ca(HSiO3)+"))
1
source
ChemistryLab.check_mendeleevMethod
check_mendeleev(f::Formula) -> Bool

Validate that all element symbols in f exist in the package elements registry. Returns true when valid; otherwise throws an informative error.

Examples

julia> check_mendeleev(Formula("NaCl"))
true
source