In this tutorial, we provide clarification of the functionality of the class ChemicalEditor that is used to conveniently create chemical and reaction systems.
Using Reaktoro in Python requires an import of the python package reaktoro
:
from reaktoro import *
The default thermodynamic databases embedded into Reaktoro is SUPCRT92, so you do not have to initialize the
database db = Database('supcrt98.xml')
, unless an alternative database must be used.
Class ChemicalEditor provides convenient operations to initialize ChemicalSystem and ReactionSystem instances. To define the editor of the chemical system from the default database SUPCRT92, we use:
editor = ChemicalEditor()
Alternatively, the editor can be initialized by the database instance:
# Initialize a thermodynamic database with supcrt98.xml
db = Database("supcrt98.xml")
# Define the editor of the chemical system
editor = ChemicalEditor(db)
Before the definition of chemical system, aqueous, gaseous, and mineral phases must be added. It can be done in various ways. Let us consider, first, the definition of aqueous species:
https://reaktoro.org/cpp/classReaktoro_1_1ChemicalEditor.html#a68cdc98877671b61490d0752b3060d91), the AqueousPhase can be created by specifying the names of the species one by one. These species names must conform to those used in the database that was specified during the initialization of the ChemicalEditor object, otherwise, an exception will be thrown.
editor.addAqueousPhase(
["H2O(l)", "H+", "OH-", "Na+", "Cl-", "HCO3-", "CO3--", "CO2(aq)"]
)
species names in the database, we can use method ChemicalEditor::addAqueousPhaseWithElements. It permits the AqueousPhase object to be constructed by using a list of chemical element names. The database will be searched for all species that could be formed out of those elements. These species will then be used to construct AqueousPhase object.
editor.addAqueousPhaseWithElements("H O C Ca Cl Mg")
object can be also constructed by using a list of compounds or substance names that might not necessarily represent names of species in the database. The list of compounds will be broken into a list of element names, and the database will be similarly searched for all species that could be formed out of those elements.
editor.addAqueousPhaseWithElementsOf("H2O NaCl CO2")
Note: The call of
ChemicalEditor::addAqueousPhaseWithElements will result in larger chemical system than
call of ChemicalEditor::addAqueousPhase, where the specific aqueous species are provided. In more demanding applications (e.g., as a chemical solver in a reactive transport simulator), you might want to manually specify the chemical species of each phase in your chemical system.
To add gaseous phase, similar methods can be used:
editor.addGaseousPhase(["H2O(g)", "CO2(g)", "H2(g)", "O2(g)", "CH4(g)"])
editor.addGaseousPhaseWithElements(["H", "O", "C"])
editor.addGaseousPhaseWithElementsOf(["H2O", "CO2"])
The MineralPhase object is created by specifying the names of the species one by one. These species names must conform to those used in the database that was specified during the initialization of the ChemicalEditor object, otherwise, an exception will be thrown. The example below describes the usage of this method for the creation of two pure mineral phases and one solid solution with two mineral species.
editor.addMineralPhase("Calcite")
editor.addMineralPhase("Dolomite")
editor.addMineralPhase(["Dolomite", "Calcite"])
There are two more alternatives to add MinerialPhase, i.e.,
editor.addMineralPhaseWithElements(["Ca", "C", "O"])
editor.addMineralPhaseWithElementsOf(["CaCO3", "MgCO3"])
Besides phases, one could also set temperatures and pressures of considered chemical system for constructing interpolation tables of thermodynamic properties., e.g.,
editor.setTemperatures([60, 80, 100, 120, 140, 160], "celsius")
editor.setPressures([1, 10, 100], "bar")
Finally, the definition of the chemical system is done by calling
system = ChemicalSystem(editor)