Creating chemical states¶

Written by Allan Leal (ETH Zurich) on Jan 4th, 2022

After learning how to define chemical systems and create a ChemicalSystem object, it is time to create some chemical states. In your applications, you will most often deal with a single ChemicalSystem object and multiple ChemicalState objects in which the system’s temperature, pressure, and species amounts are specified.

Let’s check the following simple example, in which a chemical system is constructed with a gaseous phase only.

from reaktoro import *

gases = GaseousPhase("CO2 O2 H2 H2O CH4 CO")

system = ChemicalSystem(db, gases)


We can now create a ChemicalState object to represent the state of the system:

state = ChemicalState(system)
state.temperature(1000, "celsius")
state.pressure(10, "MPa")
state.set("CO2", 0.1, "mol")
state.set("O2" , 0.2, "mol")
state.set("H2" , 0.3, "mol")
state.set("H2O", 0.4, "mol")
state.set("CH4", 0.5, "mol")
state.set("CO" , 0.6, "mol")


We can print this chemical state to have an idea of what information it contains:

print(state)

+-----------------+---------+------+
| Property        |   Value | Unit |
+-----------------+---------+------+
| Temperature     | 1273.15 |    K |
| Pressure        |   1e+07 |   Pa |
| Charge:         |       0 |  mol |
| Element Amount: |         |      |
| :: H            |     3.4 |  mol |
| :: C            |     1.2 |  mol |
| :: O            |     1.6 |  mol |
| Species Amount: |         |      |
| :: CO2          |     0.1 |  mol |
| :: O2           |     0.2 |  mol |
| :: H2           |     0.3 |  mol |
| :: H2O          |     0.4 |  mol |
| :: CH4          |     0.5 |  mol |
| :: CO           |     0.6 |  mol |
+-----------------+---------+------+


Tip

Access the link ChemicalState to find out all methods available in class ChemicalState!

From the table above we see that ChemicalState objects do not have thermodynamic properties of the system; only temperature, pressure, species amounts, element amounts, and the electric charge. We will learn in the next guide how to evaluate thermodynamic and chemical properties of the system such as Gibbs energy, enthalpy, volume, heat capacities, species activities, etc.

Note

You will often use class ChemicalState for:

• specifying initial conditions for chemical equilibrium and kinetics calculations

• storing computed states from the above computations (e.g., chemical equilibrium states)

We will learn all these use cases in subsequent guides.

Let’s consider now a more complicated chemical system and create a chemical state for it:

db = PhreeqcDatabase("pitzer.dat")

solution = AqueousPhase()
minerals = MineralPhase("Halite Calcite Dolomite Quartz")

system = ChemicalSystem(db, solution, minerals)

state = ChemicalState(system)
state.temperature(50.0, "celsius")
state.pressure(5.0, "atm")
state.set("H2O"     , 1.00, "kg")
state.set("Na+"     , 0.10, "mol")
state.set("Cl-"     , 0.10, "mol")
state.set("Ca+2"    , 0.50, "mmol")
state.set("Mg+2"    , 0.50, "mmol")
state.set("Calcite" , 1.00, "mg")
state.set("Dolomite", 1.00, "ug")
state.set("Quartz"  , 1.00, "kmol")

print(state)

+-----------------+-------------+------+
| Property        |       Value | Unit |
+-----------------+-------------+------+
| Temperature     |      323.15 |    K |
| Pressure        |      506625 |   Pa |
| Charge:         |       0.002 |  mol |
| Element Amount: |             |      |
| :: H            |     111.012 |  mol |
| :: C            | 1.00017e-05 |  mol |
| :: O            |     2055.51 |  mol |
| :: Na           |         0.1 |  mol |
| :: Mg           | 0.000500005 |  mol |
| :: Si           |        1000 |  mol |
| :: Cl           |         0.1 |  mol |
| :: Ca           | 0.000509996 |  mol |
| Species Amount: |             |      |
| :: H+           |       1e-16 |  mol |
| :: H2O          |     55.5062 |  mol |
| :: CO3-2        |       1e-16 |  mol |
| :: CO2          |       1e-16 |  mol |
| :: Ca+2         |      0.0005 |  mol |
| :: Cl-          |         0.1 |  mol |
| :: H4SiO4       |       1e-16 |  mol |
| :: H2SiO4-2     |       1e-16 |  mol |
| :: H3SiO4-      |       1e-16 |  mol |
| :: HCO3-        |       1e-16 |  mol |
| :: Mg+2         |      0.0005 |  mol |
| :: MgCO3        |       1e-16 |  mol |
| :: MgOH+        |       1e-16 |  mol |
| :: Na+          |         0.1 |  mol |
| :: OH-          |       1e-16 |  mol |
| :: Halite       |       1e-16 |  mol |
| :: Calcite      |  9.9909e-06 |  mol |
| :: Dolomite     | 5.42278e-09 |  mol |
| :: Quartz       |        1000 |  mol |
+-----------------+-------------+------+


Tip

By default, a ChemicalState object is initialized with the following conditions:

• 273.15 K (or 25 °C)

• 105 Pa (or 1 bar)

• 10-16 mol as the amounts of every species

Zero is a numerically problematic value for species amounts; that’s why we set it to a very small positive value instead. This should not be an issue for you in most cases, but if for some reason 10-16 is not small enough, you can use the method ChemicalState.setSpeciesAmount(1e-40) to set a common amount value for all species in the system.

Try: Create a ChemicalState object and print it before setting any property.

Continue reading to learn more interesting use cases for ChemicalState, such as computing thermodynamic and chemical properties for the system using class ChemicalProps!