Reaktoro  v2.0.0 A unified framework for modeling chemically reactive systems
ChemicalFormula Class Reference

A type used to represent the chemical formula of a chemical species. More...

#include <ChemicalFormula.hpp>

## Public Member Functions

ChemicalFormula ()
Construct a default ChemicalFormula object.

ChemicalFormula (const char *formula)
Construct a ChemicalFormula object with given formula. More...

ChemicalFormula (String formula)
Construct a ChemicalFormula object with given formula. More...

ChemicalFormula (String formula, Pairs< String, double > symbols, double charge)
Construct a ChemicalFormula object with given formula, element symbols, and charge. More...

auto str () const -> const String &
Return the chemical formula of the substance as a string.

auto elements () const -> const Pairs< String, double > &
Return the element symbols and their coefficients in the chemical formula.

auto symbols () const -> Strings
Return the element symbols in the chemical formula.

auto coefficients () const -> Vec< double >
Return the coefficients of the elements in the chemical formula.

auto coefficient (const String &symbol) const -> double
Return the coefficient of an element symbol in the chemical formula.

auto charge () const -> double
Return the electric charge of the chemical formula.

auto equivalent (const ChemicalFormula &other) const -> bool
Return true if another chemical formula is equivalent to this one. More...

operator String () const
Convert this ChemicalFormula object into a string.

operator Pairs< String, double > () const
Convert this ChemicalFormula object into a Pairs<String, double>.

## Static Public Member Functions

static auto equivalent (const ChemicalFormula &f1, const ChemicalFormula &f2) -> bool
Return true if two chemical formulas are equivalent.

## Detailed Description

A type used to represent the chemical formula of a chemical species.

## ◆ ChemicalFormula() [1/3]

 ChemicalFormula ( const char * formula )

Construct a ChemicalFormula object with given formula.

Parameters
 formula The chemical formula of the species (e.g., H2O, CaCO3, CO3--, CO3-2).

## ◆ ChemicalFormula() [2/3]

 ChemicalFormula ( String formula )

Construct a ChemicalFormula object with given formula.

Parameters
 formula The chemical formula of the species (e.g., H2O, CaCO3, CO3--, CO3-2).

## ◆ ChemicalFormula() [3/3]

 ChemicalFormula ( String formula, Pairs< String, double > symbols, double charge )

Construct a ChemicalFormula object with given formula, element symbols, and charge.

Parameters
 formula The chemical formula of the species (e.g., HCO3-). symbols The element symbols and their coefficients (e.g., {{"H", 1}, {"C", 1}, {"O", 3}} for HCO3-). charge The electric charge in the chemical formula (e.g., -1 for HCO3-).

## ◆ equivalent()

 auto equivalent ( const ChemicalFormula & other ) const -> bool

Return true if another chemical formula is equivalent to this one.

Two chemical formulas are equivalent if they have the same elemental composition. Consider Ca++ and Ca+2 for example. These two formulas are equivalent, despite the different convention for indicating charge. Another example is CaCO3 and Ca(CO3). All these formulas have identical symbols and coefficients, and are thus equivalent.

The documentation for this class was generated from the following file: