Skip to content

Species ​

Species is a composite type (introduced by the keyword struct) and is defined by a human-readable name, a chemical symbol/notation, an underlying Formula object holding composition, charge, and string representations, a physical state aggregate_state, a species class, as well as an extensible map of custom properties (molar mass, thermodynamic data, etc.)

julia
struct Species{T<:Number} <: AbstractSpecies
    name::String
    symbol::String
    formula::Formula{T}
    aggregate_state::AggregateState
    class::Class
    properties::OrderedDict{Symbol,PropertyType}
end

Advanced description

  • aggregate_state denotes the state of the species (solid, liquid, gas) for which the possible keywords are AS_AQUEOUS, AS_CRYSTAL, AS_GAS, AS_LIQUID and AS_UNDEF

  • class defines the role played by the species in the solution. The possible keywords are SC_AQSOLVENT, SC_AQSOLUTE, SC_COMPONENT, SC_GASFLUID and SC_UNDEF

  • properties refers to the set of properties intrinsic to the species. These properties are detailed below.

Species construction ​

Species can be created from:

  • a Formula
julia
using ChemistryLab
fH2O = Formula("H2O")
H2O = Species(fH2O, aggregate_state=AS_AQUEOUS, class=SC_AQSOLVENT)
Species{Int64}
           name: H2O
         symbol: H2O
        formula: H2O ◆ H₂O
          atoms: H => 2, O => 1
         charge: 0
aggregate_state: AS_AQUEOUS
          class: SC_AQSOLVENT
     properties: M = 0.0180149999937744 kg mol⁻¹
  • a string
julia
using ChemistryLab
HSO4⁻ = Species("HSO₄⁻", aggregate_state=AS_AQUEOUS, class=SC_COMPONENT)
Species{Int64}
           name: HSO₄⁻
         symbol: HSO₄⁻
        formula: HSO₄⁻ ◆ HSO4-
          atoms: H => 1, S => 1, O => 4
         charge: -1
aggregate_state: AS_AQUEOUS
          class: SC_COMPONENT
     properties: M = 0.09706399996645676 kg mol⁻¹
  • a dictionary
julia
using ChemistryLab
CO2 = Species(Dict(:C => 1, :O => 2), aggregate_state=AS_GAS, class=SC_GASFLUID)
Species{Int64}
           name: CO₂
         symbol: CO₂
        formula: CO2 ◆ CO₂
          atoms: O => 2, C => 1
         charge: 0
aggregate_state: AS_GAS
          class: SC_GASFLUID
     properties: M = 0.04400899998479143 kg mol⁻¹

Adding charge

To add a charge when creating species with a dictionary, you must add, after the dictionary, the value of the charge (charge is considered an argument of the composite type).

julia
using ChemistryLab
SiO₃²⁻ = Species(Dict(:Si => 1, :O => 3), -2, aggregate_state=AS_AQUEOUS, class=SC_COMPONENT)
Species{Int64}
           name: SiO₃-2
         symbol: SiO₃-2
        formula: SiO3-2 ◆ SiO₃-2
          atoms: Si => 1, O => 3
         charge: -2
aggregate_state: AS_AQUEOUS
          class: SC_COMPONENT
     properties: M = 0.0760819999737077 kg mol⁻¹

Keyword arguments such as name, symbol, aggregate_state, class can be added during construction.

julia
using ChemistryLab
fH₂O = Formula("H2O")
H₂O = Species(fH₂O; name="Water", symbol="H₂O@", aggregate_state=AS_AQUEOUS, class=SC_AQSOLVENT)
Species{Int64}
           name: Water
         symbol: H₂O@
        formula: H2O ◆ H₂O
          atoms: H => 2, O => 1
         charge: 0
aggregate_state: AS_AQUEOUS
          class: SC_AQSOLVENT
     properties: M = 0.0180149999937744 kg mol⁻¹

And symbol accept unicode characters.

julia
using ChemistryLab
CO₂ = Species(Dict(:C=>1, :O=>2); name="Carbon dioxide", symbol="CO₂⤴", aggregate_state=AS_GAS, class=SC_GASFLUID)
Species{Int64}
           name: Carbon dioxide
         symbol: CO₂⤴
        formula: CO2 ◆ CO₂
          atoms: O => 2, C => 1
         charge: 0
aggregate_state: AS_GAS
          class: SC_GASFLUID
     properties: M = 0.04400899998479143 kg mol⁻¹

Comparison between species

Comparison between species (or cemspecies) are done by comparing atoms, aggregate_state and class. In the example below, vapor is not equal to H₂O since aggregate_state and class are different despite atoms are identical.

julia
vapour = Species("H2O"; name="Vapour", symbol="H₂O⤴", aggregate_state=AS_GAS, class=SC_GASFLUID)
vapour == H₂O

Remark

You will also have noticed that a calculation of the molar mass of the species is systematically carried out.


When are two species the same species? ​

Two species are equal when their formula, aggregate state and class agree, and when their symbol agrees on top of that — but only insofar as the symbol says something the formula does not.

The symbol is in the contract because the first three do not separate polymorphs, and a polymorph is a different substance. Calcite and aragonite are both CaCO3, both AS_CRYSTAL, both SC_COMPONENT, and in CEMDATA18 (Lothenbach et al., 2019) their standard Gibbs energies differ by 821 J/mol — at 298 K, 0.33 in ln K, which is the whole difference in solubility between them.

julia
using ChemistryLab

calcite   = Species("CaCO3"; symbol = "Cal", aggregate_state = AS_CRYSTAL)
aragonite = Species("CaCO3"; symbol = "Arg", aggregate_state = AS_CRYSTAL)

(calcite == aragonite, length(unique([calcite, aragonite])))
(false, 2)

At the same time, a symbol that merely spells the species' own formula adds nothing, and is ignored. So the same substance typed two ways is one species, with one hash — which is what a Dict or a Set needs:

julia
a, b = Species("Ca+2"), Species("Ca⁺²")

(a == b, hash(a) == hash(b), Dict(a => 1)[b])
(true, true, 1)

The symbol is also a lookup key, and stays what you typed

ChemicalSystem indexes its species by symbol — cs["H2O"] — so the stored symbol is never rewritten. The canonicalization above happens inside the comparison only. In particular it does not replace a derived symbol by a canonical spelling, because unicode is not constant on formulas that compare equal: Formula("e") and Formula("e-") are equal yet spell themselves "e" and "e⁻", and Formula("Ca+2") and Formula("Ca⁺²") are equal yet spell themselves "Ca²⁺" and "Ca⁺²". A derived symbol therefore contributes nothing at all rather than a canonical form.

julia
cs = ChemicalSystem([Species("H2O"; aggregate_state = AS_AQUEOUS)])

symbol.(cs.species), cs["H2O"] == Species("H2O"; aggregate_state = AS_AQUEOUS)
(["H2O"], true)

Species read from a database always carry an explicit symbol — "Cal", "Arg", "H2O@" — so every identity question about them is decided by that symbol, as it should be.

Species properties ​

The molar mass is automatically calculated and stored in the species properties dict under the key :M. Beyond that, the properties dict is open: any value of type Number, AbstractVector{<:Number}, Function, or AbstractString can be added at any time.

Predefined property:

KeyTypeDescription
:MQuantity (g/mol)Molar mass, computed automatically from the formula

Common user-added thermodynamic properties (loaded from databases or set manually):

KeyTypeDescription
:Cp⁰SymbolicFunc(T)Standard heat capacity (J mol⁻¹ K⁻¹)
:ΔₐH⁰SymbolicFunc(T) or NumericFunc(T, P)Standard enthalpy of formation (J mol⁻¹)
:S⁰SymbolicFunc(T)Standard entropy (J mol⁻¹ K⁻¹)
:ΔₐG⁰SymbolicFunc(T) or NumericFunc(T, P)Standard Gibbs free energy of formation (J mol⁻¹)
:V⁰Quantity or FunctionMolar volume (m³ mol⁻¹)

A database record that declares a constant molar volume has the pressure term V⁰ (P − P°) in its ΔₐH⁰ and ΔₐG⁰, which are then functions of T and P; an aqueous solute of the HKF model (Helgeson et al., 1981) depends on both as well. A gas's V⁰ is RT/P, and one built without a V⁰ is given that volume.

Properties are accessed and mutated via []:

julia
using ChemistryLab
using DynamicQuantities

H2O = Species("H2O"; aggregate_state = AS_AQUEOUS, class = SC_AQSOLVENT)

# Molar mass is always available
H2O[:M]
0.0180149999937744 kg mol⁻¹
julia
# Add a scalar property: the molar volume of liquid water at 25 °C, from its
# molar mass and the density of the package's equation of state for water
ρ = water_thermo_props(298.15, 1.0e5).D * u"kg/m^3"
H2O[:V⁰] = H2O[:M] / ρ
H2O[:V⁰]
1.8068095510560707e-5 m³ mol⁻¹
julia
# Add a string annotation
H2O[:source] = "M / ρ, ρ from the HGK equation of state at 25 °C"
H2O[:source]
"M / ρ, ρ from the HGK equation of state at 25 °C"

Attaching temperature-dependent thermodynamic functions ​

The standard workflow uses build_thermo_functions to construct callable SymbolicFunc objects from reference data and Cp polynomial coefficients, then assigns them to the species:

julia
using ChemistryLab
using DynamicQuantities

calcite = Species("CaCO3"; name = "Calcite", aggregate_state = AS_CRYSTAL, class = SC_COMPONENT)

# Reference data at 298.15 K: Thermoddem's values, as transcribed in
# data/literature/Blanc2012.json
ref = literature_row("Blanc2012", "individual_properties", "Calcite")
mk  = literature_row("Blanc2012", "maier_kelley", "Calcite")
params_Cp_calcite = Dict(
    :S⁰   => ref.S,
    :ΔₐH⁰ => ref.dfH,
    :ΔₐG⁰ => ref.dfG,
    :a₀   => mk.a,       # Maier-Kelley: a₀ + a₁T + a₂/T², the other terms zero
    :a₁   => mk.b,
    :a₂   => mk.c,
    :a₃   => 0.0u"J/(mol*K^0.5)",
    :T    => 298.15u"K",             # reference temperature
)

dtf_calcite = build_thermo_functions(:cp_ft_equation, params_Cp_calcite)
OrderedCollections.OrderedDict{Symbol, SymbolicFunc{1, @NamedTuple{T::Quantity{Float64, Dimensions{FRInt32}}}, Float64, Dimensions{FRInt32}}} with 4 entries:
  :Cp⁰  => 99.72 + 0.02692T + -2.158e6 / (T^2) [m² kg s⁻² K⁻¹ mol⁻¹] ◆ vars=(T) ◆ T=298.15 K
  :ΔₐH⁰ => -1.24577e6 + 99.72T + 2.158e6 / T + 0.01346(T^2) [m² kg s⁻² mol⁻¹] ◆ vars=(T) ◆ T=298.15 K
  :S⁰   => -496.549 + 0.02692T + 99.72log(T) + 1.079e6 / (T^2) [m² kg s⁻² K⁻¹ mol⁻¹] ◆ vars=(T) ◆ T=298.15 K
  :ΔₐG⁰ => -1.13991e6 + 596.269T + 1.079e6 / T - 0.01346(T^2) - 99.72T*log(T) [m² kg s⁻² mol⁻¹] ◆ vars=(T) ◆ T=298.15 K
Data read above: Blanc2012Blanc, Ph. et al. (2012)2 tables

Blanc, Ph., Lassin, A., Piantone, P., Azaroual, M., Jacquemet, N., Fabbri, A., Gaucher, E. C. (2012). Thermoddem: A geochemical database focused on low temperature water/rock interactions and waste materials. Applied Geochemistry 27(10), 2107-2116. doi:10.1016/j.apgeochem.2012.06.002

Read in the Thermoddem database, thermoddem.brgm.fr, individual properties at 298.15 K checked against the source

Transcribed from the pages of the Thermoddem website for calcite, portlandite, Ca+2 and CO3-2 (thermoddem.brgm.fr/species/calcite, portlandite, ca2, co3-2), read on 2026-09-25; calcite and the two ions are also captured in docs/src/assets/calcite_properties_thermoddem.png, ca_properties_thermoddem.png and co3_properties_thermoddem.png

The values of calcite and of the two ions were typed into the from_scratch example before this file existed and agree with the website, all of them. The website credits each value to its own primary source (CODATA, Robie and Hemingway 1995, Shock et al. 1997, Plummer and Busenberg 1982, internal calculations); the database is cited here, through its reference publication. The HKF coefficients of the two ions are not transcribed: the examples take their heat capacities as constant at 25 C.

Tables

individual_properties: 4 rows

individual properties (298.15 K)

speciesM [g/mol]V [cm^3/mol]dfG [J/mol]dfH [J/mol]S [J/(mol*K)]Cp [J/(mol*K)]
Calcite100.08736.934-1129109-120760591.7883.47
Portlandite74.09333.056-896886-98455283.3987.49
Ca+240.078-18.154-552806-543000-56.2-26.38
CO3-260.009-5.275-527900-675230-50.0-276.88
maier_kelley: 2 rows

Cp(T) = a + b T + c T^-2, T in kelvin

speciesa [J/(mol*K)]b [J/(mol*K^2)]c [J*K/mol]
Calcite99.720.02692-2.158e6
Portlandite89.260.03311-1.036e6

Notes

  • The website prints b * 10^3 and c * 10^-5 (26.92 and -21.58 for calcite); the columns hold b and c themselves.
  • The polynomials reproduce the heat capacity the same pages give at 298.15 K: 83.47 for calcite, and 87.48 against 87.49 for portlandite.
  • CO2(g), which the Manual used to build from this source, is not transcribed: its page leaves c blank, and a + b T then gives 41.10 J/(mol K) at 298.15 K where the page gives Cp = 37.14.
julia
# Assign each function to the species
for (k, v) in dtf_calcite
    calcite[k] = v
end

# Evaluate at different temperatures
calcite[:Cp⁰](T = 298.15)    # J/mol/K at 25 °C
83.46993616521688
julia
calcite[:Cp⁰](T = 500.0)     # J/mol/K at 227 °C
104.54799999999999
julia
calcite[:ΔₐG⁰](T = 500.0u"K", unit = true)   # Gibbs energy at 227 °C with units
-1.1528438070232493e6 m² kg s⁻² mol⁻¹

Cp polynomial

The built-in :cp_ft_equation model uses an 11-term polynomial:        Unused coefficients should be set to 0.0 with appropriate units. Only non-zero terms affect the result. See the Thermodynamic Functions tutorial for the full list of models and parameters.

Reference temperature

Always include :T => reference_temperature in the parameter dict. The functions are adjusted so that S°(T_ref), ΔₐH°(T_ref), ΔₐG°(T_ref) match the provided reference values exactly.


Requalifying a species: with_class ​

Species is an immutable struct — none of its fields can be modified after construction. with_class returns a copy of the species with only the class field changed. All other fields — name, symbol, formula, aggregate state, properties and thermodynamic functions — are shared by reference and unchanged.

julia
using ChemistryLab

# A crystal species with the class that databases typically assign
cal = Species("CaCO3"; aggregate_state = AS_CRYSTAL, class = SC_COMPONENT)

println("before: ", class(cal))        # SC_COMPONENT

em = with_class(cal, SC_SSENDMEMBER)

println("after:  ", class(em))         # SC_SSENDMEMBER
println("formula preserved: ", formula(em) == formula(cal))
before: SC_COMPONENT
after:  SC_SSENDMEMBER
formula preserved: true

Solid solutions: no requalification needed

SolidSolutionPhase automatically promotes end-members to SC_SSENDMEMBER at construction time. Database species with SC_COMPONENT can therefore be passed directly — no prior call to with_class is required:

julia
substances = build_species(datapath("cemdata18-thermofun.json"))
dict = Dict(symbol(s) => s for s in substances)

# Pass database species directly — SolidSolutionPhase requalifies internally
cshq = SolidSolutionPhase("CSHQ", [dict["CSHQ-TobD"], dict["CSHQ-TobH"],
                                    dict["CSHQ-JenH"], dict["CSHQ-JenD"]])

with_class is still useful when you need to track the requalified object explicitly (e.g. to inspect its class, or for types other than solid solution end-members).

Where to go next ​

Species combine into reactions in Chemical Reactions, and into the conservation matrix of a system in Stoichiometric Matrix. Species are seldom built by hand in practice: Importing thermodynamic databases reads them from the databases.