{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Inspecting thermodynamic databases\n", "\n", "
Written by Allan Leal (ETH Zurich) on Jan 4th, 2022
\n", "\n", "```{attention}\n", "Always make sure you are using the [latest version of Reaktoro](https://anaconda.org/conda-forge/reaktoro). Otherwise, some new features documented on this website will not work on your machine and you may receive unintuitive errors. Follow these [update instructions](updating_reaktoro_via_conda) to get the latest version of Reaktoro!\n", "```\n", "\n", "This tutorial demonstrates how a thermodynamic database can be inspected programmatically using Reaktoro's Python API. For this, we will consider the [cemdata18](https://www.empa.ch/web/s308/cemdata) database supported in [ThermoFun](https://thermohub.org/thermofun/thermofun/). \n", "\n", "So, let's get started by creating an object of class {{ThermoFunDatabase}}:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from reaktoro import *\n", "\n", "db = ThermoFunDatabase(\"cemdata18\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We'll use this `db` object throughout this tutorial to demonstrate all inspection capabilities available in class {{Database}} (yes, {{ThermoFunDatabase}} is a derived class from {{Database}})!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Inspecting the species in the database\n", "\n", "Let's loop through all species in this database object and print its name, chemical formula, and molar mass:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [ "scroll-output" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Species Formula Molar Mass (kg/mol) \n", "5CA (CaO)1.25(SiO2)1(Al2O3)0.125(H2O)1.625 0.172201 \n", "5CNA (CaO)1.25(SiO2)1(Al2O3)0.125(Na2O)0.25(H2O)1.375 0.183192 \n", "Al(SO4)+ Al(SO4)+ 0.123046 \n", "Al(SO4)2- Al(SO4)2- 0.219111 \n", "Al+3 Al+3 0.026980 \n", "AlO+ AlO+ 0.042980 \n", "AlO2- AlO2- 0.058981 \n", "AlO2H@ AlO2H@ 0.059988 \n", "AlOH+2 Al(OH)+2 0.043988 \n", "AlOHam Al(OH)3 0.078004 \n", "AlOHmic Al(OH)3 0.078004 \n", "AlSiO5-3 AlSiO5-3 0.135066 \n", "Amor-Sl SiO2 0.060084 \n", "Anh CaSO4 0.136143 \n", "Arg CaCO3 0.100087 \n", "Brc Mg(OH)2 0.058320 \n", "C12A7 (CaO)12(Al2O3)7 1.386658 \n", "C2AClH5 Ca2AlCl(OH)6(H2O)2 0.280665 \n", "C2AH65 Ca2Al(OH)7(H2O)3 0.280235 \n", "C2AH7.5 Ca2Al2(OH)10(H2O)2.5 0.349231 \n", "C2S (CaO)2SiO2 0.172239 \n", "C3A (CaO)3Al2O3 0.270193 \n", "C3AFS0.84H4.32 (AlFe|3|O3)[Ca3O3(SiO2)0.84(H2O)4.32] 0.427354 \n", "C3AH6 Ca3Al2O6(H2O)6 0.378285 \n", "C3AS0.41H5.18 Ca3Al2O6(SiO2)0.41(H2O)5.18 0.388147 \n", "C3AS0.84H4.32 (AlAlO3)[Ca3O3(SiO2)0.84(H2O)4.32] 0.398490 \n", "C3FH6 Ca3Fe|3|2O6(H2O)6 0.436012 \n", "C3FS0.84H4.32 (Fe|3|Fe|3|O3)[Ca3O3(SiO2)0.84(H2O)4.32] 0.456217 \n", "C3FS1.34H3.32 Ca3Fe|3|2O6(SiO2)1.34(H2O)3.32 0.468244 \n", "C3S (CaO)3SiO2 0.228316 \n", "C4AClH10 Ca4Al2Cl2(OH)12(H2O)4 0.561330 \n", "C4AF (CaO)4(Al2O3)(Fe|3|2O3) 0.485959 \n", "C4AH11 Ca4Al2(OH)14(H2O)4 0.524439 \n", "C4AH13 Ca4Al2(OH)14(H2O)6 0.560470 \n", "C4AH19 Ca4Al2(OH)14(H2O)12 0.668562 \n", "C4AsClH12 Ca4Al2Cl(SO4)0.5(OH)12(H2O)6 0.609940 \n", "C4FH13 Ca4Fe|3|2(OH)14(H2O)6 0.618197 \n", "CA CaOAl2O3 0.158039 \n", "CA2 CaO(Al2O3)2 0.260000 \n", "CAH10 CaOAl2O3(H2O)10 0.338192 \n", "CH4 C|-4|H4 0.016043 \n", "CH4@ C|-4|H4@ 0.016043 \n", "CO2 CO2 0.044010 \n", "CO2@ CO2@ 0.044010 \n", "CO3-2 CO3-2 0.060010 \n", "CSH3T-T2C ((CaO)0.75(SiO2)0.5(H2O)1.25)2 0.189239 \n", "CSH3T-T5C ((CaO)1(SiO2)1(H2O)2)1.25 0.190240 \n", "CSH3T-TobH (CaO)1(SiO2)1.5(H2O)2.5 0.191242 \n", "CSHQ-JenD (CaO)1.5(SiO2)0.6667(H2O)2.5 0.169213 \n", "CSHQ-JenH (CaO)1.3333(SiO2)1(H2O)2.1667 0.173886 \n", "CSHQ-TobD ((CaO)1.25(SiO2)1(H2O)2.75)0.6667 0.119821 \n", "CSHQ-TobH (CaO)0.6667(SiO2)1(H2O)1.5 0.124494 \n", "Ca(CO3)@ CaCO3@ 0.100087 \n", "Ca(HCO3)+ Ca(HCO3)+ 0.101094 \n", "Ca(HSiO3)+ Ca(HSiO3)+ 0.117169 \n", "Ca(SO4)@ CaSO4@ 0.136143 \n", "Ca+2 Ca+2 0.040077 \n", "CaOH+ Ca(OH)+ 0.057085 \n", "CaSiO3@ CaSiO3@ 0.116162 \n", "Cal CaCO3 0.100087 \n", "Cl- Cl- 0.035454 \n", "ClO4- Cl|7|O4- 0.099451 \n", "Cls SrSO4 0.183685 \n", "Dis-Dol CaMg(CO3)2 0.184401 \n", "ECSH1-KSH ((KOH)2.5SiO2H2O)0.2 0.043673 \n", "ECSH1-NaSH ((NaOH)2.5SiO2H2O)0.2 0.035618 \n", "ECSH1-SH (SiO2H2O)1 0.078100 \n", "ECSH1-SrSH ((Sr(OH)2)1SiO2H2O)1 0.199734 \n", "ECSH1-TobCa ((Ca(OH)2)0.8333SiO2H2O)1 0.139841 \n", "ECSH2-JenCa ((Ca(OH)2)1.6667SiO2H2O)0.6 0.120954 \n", "ECSH2-KSH ((KOH)2.5SiO2H2O)0.2 0.043673 \n", "ECSH2-NaSH ((NaOH)2.5SiO2H2O)0.2 0.035618 \n", "ECSH2-SrSH ((Sr(OH)2)1SiO2H2O)1 0.199734 \n", "ECSH2-SrSH(ACW) ((Sr(OH)2)1SiO2H2O)1 0.199734 \n", "ECSH2-TobCa ((Ca(OH)2)0.8333SiO2H2O)1 0.139841 \n", "Ettringite13_des Ca6Al2(SO4)3(OH)12(H2O)7 0.912820 \n", "Ettringite9_des Ca6Al2(SO4)3(OH)12(H2O)3 0.840759 \n", "Fe Fe|0| 0.055845 \n", "Fe(CO3)@ FeCO3@ 0.115854 \n", "Fe(HCO3)+ FeHCO3+ 0.116861 \n", "Fe(HSO4)+ FeHSO4+ 0.152917 \n", "Fe(HSO4)+2 Fe|3|HSO4+2 0.152916 \n", "Fe(SO4)+ Fe|3|(SO4)+ 0.151909 \n", "Fe(SO4)2- Fe|3|(SO4)2- 0.247975 \n", "Fe(SO4)@ Fe(SO4)@ 0.151910 \n", "Fe+2 Fe+2 0.055844 \n", "Fe+3 Fe|3|+3 0.055843 \n", "Fe-ettringite Ca6Fe|3|2(SO4)3(OH)12(H2O)26 1.312838 \n", "Fe-ettringite05 Ca3Fe|3|(SO4)1.5(OH)6(H2O)13 0.656419 \n", "Fe-hemicarbonate Ca3O3Fe|3|2O3(CaCO3)0.5(CaO2H2)0.5(H2O)9.5 0.586156 \n", "Fe-monosulph05 Ca2Fe|3|S0.5O5(H2O)6 0.340123 \n", "Fe-monosulphate Ca4Fe|3|2SO10(H2O)12 0.680247 \n", "FeCl+ FeCl+ 0.091297 \n", "FeCl+2 Fe|3|Cl+2 0.091297 \n", "FeCl2+ Fe|3|Cl2+ 0.126750 \n", "FeCl3@ Fe|3|Cl3@ 0.162204 \n", "FeO+ Fe|3|O+ 0.071844 \n", "FeO2- Fe|3|O2- 0.087844 \n", "FeO2H@ Fe|3|O2H@ 0.088852 \n", "FeOH+ FeOH+ 0.072852 \n", "FeOH+2 Fe|3|(OH)+2 0.072851 \n", "FeOOHmic Fe|3|OOH 0.088852 \n", "Femonocarbonate Ca4O4Fe|3|2O3CO2(H2O)12 0.644191 \n", "Gbs Al(OH)3 0.078004 \n", "Gp CaSO4(H2O)2 0.172173 \n", "Gr C|0| 0.012011 \n", "Gt Fe|3|O(OH) 0.088852 \n", "H+ H+ 0.001007 \n", "H2 H|0|2 0.002016 \n", "H2@ H|0|2@ 0.002016 \n", "H2O H2O 0.018015 \n", "H2O@ H2O@ 0.018015 \n", "H2S H2S|-2| 0.034083 \n", "H2S@ H2S|-2|@ 0.034083 \n", "HCN@ HC|-1|N|0|@ 0.027025 \n", "HCO3- HCO3- 0.061017 \n", "HS- HS|-2|- 0.033075 \n", "HSO3- HS|4|O3- 0.081074 \n", "HSO4- HS|6|O4- 0.097073 \n", "HSiO3- HSiO3- 0.077092 \n", "Hem Fe|3|2O3 0.159688 \n", "INFCA (CaO)1(SiO2)1.1875(Al2O3)0.15625(H2O)1.65625 0.173197 \n", "INFCN (CaO)1(SiO2)1.5(Na2O)0.3125(H2O)1.1875 0.186965 \n", "INFCNA (CaO)1(SiO2)1.1875(Al2O3)0.15625(Na2O)0.34375(H2O)1.3125 0.188309 \n", "Jennite (SiO2)1(CaO)1.666667(H2O)2.1 0.191379 \n", "K(SO4)- KSO4- 0.135163 \n", "K+ K+ 0.039098 \n", "K2O K2O 0.094196 \n", "K2SO4 K2SO4 0.174261 \n", "KOH@ KOH@ 0.056106 \n", "KSiOH ((KOH)2.5SiO2H2O)0.2 0.043673 \n", "Kln Al2Si2O5(OH)4 0.258160 \n", "Lim CaO 0.056077 \n", "M075SH Mg1.5Si2O5.5(H2O)2.5 0.225663 \n", "M15SH Mg1.5SiO3.5(H2O)2.5 0.165579 \n", "M4A-OH-LDH Mg4Al2(OH)14(H2O)3 0.443332 \n", "M6A-OH-LDH Mg6Al2(OH)18(H2O)3 0.559971 \n", "M8A-OH-LDH Mg8Al2(OH)22(H2O)3 0.676611 \n", "Mag FeFe|3|2O4 0.231533 \n", "Melanterite FeSO4(H2O)7 0.278017 \n", "Mg(CO3)@ Mg(CO3)@ 0.084314 \n", "Mg(HCO3)+ Mg(HCO3)+ 0.085321 \n", "Mg(HSiO3)+ Mg(HSiO3)+ 0.101396 \n", "Mg+2 Mg+2 0.024304 \n", "Mg2AlC0.5OH Mg2Al(OH)6(CO3)0.5(H2O)2 0.243671 \n", "Mg2FeC0.5OH Mg2Fe|3|(OH)6(CO3)0.5(H2O)2 0.272534 \n", "Mg3AlC0.5OH Mg3Al(OH)8(CO3)0.5(H2O)2.5 0.310998 \n", "Mg3FeC0.5OH Mg3Fe|3|(OH)8(CO3)0.5(H2O)2.5 0.339862 \n", "MgOH+ Mg(OH)+ 0.041312 \n", "MgSO4@ Mg(SO4)@ 0.120370 \n", "Mgs MgCO3 0.084314 \n", "N2 N|0|2 0.028013 \n", "N2@ N|0|2@ 0.028013 \n", "NH3@ N|-3|H3@ 0.017031 \n", "NH4+ N|-3|H4+ 0.018038 \n", "NO3- NO3- 0.062005 \n", "Na(CO3)- NaCO3- 0.082999 \n", "Na(HCO3)@ NaHCO3@ 0.084007 \n", "Na(SO4)- Na(SO4)- 0.119055 \n", "Na+ Na+ 0.022989 \n", "Na2O Na2O 0.061979 \n", "Na2SO4 Na2SO4 0.142044 \n", "NaOH@ NaOH@ 0.039997 \n", "NaSiOH ((NaOH)2.5SiO2H2O)0.2 0.035618 \n", "O2 O|0|2 0.031999 \n", "O2@ O|0|2@ 0.031999 \n", "OH- OH- 0.017008 \n", "Ord-Dol CaMg(CO3)2 0.184401 \n", "Portlandite Ca(OH)2 0.074093 \n", "Py FeS|0|S|-2| 0.119979 \n", "Qtz SiO2 0.060084 \n", "S2O3-2 S|2|2O3-2 0.112133 \n", "SCN- S|0|C|0|N|-1|- 0.058085 \n", "SO3-2 S|4|O3-2 0.080066 \n", "SO4-2 S|6|O4-2 0.096066 \n", "Sd FeCO3 0.115854 \n", "Si4O10-4 Si4O10-4 0.272338 \n", "SiO2@ SiO2@ 0.060084 \n", "SiO3-2 SiO3-2 0.076085 \n", "Sr(CO3)@ Sr(CO3)@ 0.147629 \n", "Sr(HCO3)+ SrHCO3+ 0.148636 \n", "Sr(SO4)@ Sr(SO4)@ 0.183685 \n", "Sr+2 Sr+2 0.087619 \n", "SrOH+ Sr(OH)+ 0.104627 \n", "SrSiO3@ SrSiO3@ 0.163704 \n", "Str SrCO3 0.147629 \n", "Sulfur S|0| 0.032067 \n", "T2C-CNASHss (CaO)1.5(SiO2)1(H2O)2.5 0.189239 \n", "T5C-CNASHss (CaO)1.25(SiO2)1.25(H2O)2.5 0.190240 \n", "Tob-I (SiO2)2.4(CaO)2(H2O)3.2 0.314006 \n", "Tob-II (SiO2)1(CaO)0.833333(H2O)1.333333 0.130836 \n", "TobH-CNASHss (CaO)1(SiO2)1.5(H2O)2.5 0.191242 \n", "Tro Fe|2|S|-2| 0.087912 \n", "chabazite Ca(Al2Si4)O12(H2O)6 0.506468 \n", "ettringite ((H2O)2)Ca6Al2(SO4)3(OH)12(H2O)24 1.255111 \n", "ettringite03_ss (SO4)Ca2Al0.6666667(OH)4(H2O)8.6666667 0.418370 \n", "ettringite05 Ca3Al(SO4)1.5(OH)6(H2O)13 0.627555 \n", "ettringite13 Ca6Al2(SO4)3(OH)12(H2O)7 0.912820 \n", "ettringite30 Ca6Al2(SO4)3(OH)12(H2O)24 1.219080 \n", "ettringite9 Ca6Al2(SO4)3(OH)12(H2O)3 0.840759 \n", "ettringite_ss {SO4}3:Ca6Al2(OH)12(H2O)26 1.255111 \n", "hemicarbonat10.5 (CaO)3Al2O3(CaCO3)0.5(CaO2H2)0.5(H2O)10 0.537436 \n", "hemicarbonate (CaO)3Al2O3(CaCO3)0.5(CaO2H2)0.5(H2O)11.5 0.564459 \n", "hemicarbonate9 (CaO)3Al2O3(CaCO3)0.5(CaO2H2)0.5(H2O)8.5 0.510413 \n", "hemihydrate CaSO4(H2O)0.5 0.145150 \n", "hydrotalcite Mg4Al2O7(H2O)10 0.443332 \n", "monocarbonate Ca4Al2CO9(H2O)11 0.568449 \n", "monocarbonate05 Ca2AlC0.5O4.5(H2O)5.5 0.284224 \n", "monocarbonate9 Ca4Al2CO9(H2O)9 0.532418 \n", "mononitrate Ca4Al2(OH)12N|5|2O6(H2O)4 0.614434 \n", "mononitrite Ca4Al2(OH)12N|3|2O4(H2O)4 0.582435 \n", "monosulphate10.5 Ca4Al2SO10(H2O)10.5 0.595497 \n", "monosulphate12 Ca4Al2SO10(H2O)12 0.622520 \n", "monosulphate1205 Ca2AlS0.5O5(H2O)6 0.311260 \n", "monosulphate14 Ca4Al2SO10(H2O)14 0.658550 \n", "monosulphate16 Ca4Al2SO10(H2O)16 0.694581 \n", "monosulphate9 Ca4Al2SO10(H2O)9 0.568474 \n", "natrolite Na2(Al2Si3)O10(H2O)2 0.380224 \n", "straetlingite Ca2Al2SiO7(H2O)8 0.418323 \n", "straetlingite5.5 Ca2Al2SiO7(H2O)5.5 0.373285 \n", "straetlingite7 Ca2Al2SiO7(H2O)7 0.400307 \n", "syngenite K2Ca(SO4)2H2O 0.328419 \n", "thaumasite (CaSiO3)(CaSO4)(CaCO3)(H2O)15 0.622621 \n", "tricarboalu {CO3}3:Ca6Al2(OH)12(H2O)26 1.146944 \n", "tricarboalu03 (CO3)Ca2Al0.6666667(OH)4(H2O)8.6666667 0.382315 \n", "zeoliteP_Ca Ca(Al2Si2)O8(H2O)4.5 0.359276 \n", "zeoliteX Na2(Al2Si2.5)O9(H2O)6.2 0.425846 \n", "zeoliteY Na2(Al2Si4)O12(H2O)8 0.548400 \n" ] } ], "source": [ "print(f\"{'Species':<20}{'Formula':<60}{'Molar Mass (kg/mol)':<20}\")\n", "for species in db.species():\n", " print(f\"{species.name():<20}{species.formula().str():<60}{species.molarMass():<20.6f}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Inspecting the species in the database with given chemical elements\n", "\n", "Often, we are not interested in all species in a database, but only in those that contain some chemical elements. We show below how the species that can be formed from the elements H, O, C, and Ca can be collected and printed:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Arg\n", "CH4\n", "CH4@\n", "CO2\n", "CO2@\n", "CO3-2\n", "Ca(CO3)@\n", "Ca(HCO3)+\n", "Ca+2\n", "CaOH+\n", "Cal\n", "Gr\n", "H+\n", "H2\n", "H2@\n", "H2O\n", "H2O@\n", "HCO3-\n", "Lim\n", "O2\n", "O2@\n", "OH-\n", "Portlandite\n" ] } ], "source": [ "for species in db.species().withElements(\"H O C Ca\"):\n", " print(species.name())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Inspecting the species in the database with given aggregate state\n", "\n", "What if we want to collect only gaseous species from a database? Check next:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CH4\n", "CO2\n", "H2\n", "H2O\n", "H2S\n", "N2\n", "O2\n" ] } ], "source": [ "for species in db.speciesWithAggregateState(AggregateState.Gas):\n", " print(species.name())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And what if only gases with C, H, O elements?" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CH4\n", "CO2\n", "H2\n", "H2O\n", "O2\n" ] } ], "source": [ "for species in db.speciesWithAggregateState(AggregateState.Gas).withElements(\"C H O\"):\n", " print(species.name())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Inspecting the elements in the database\n", "\n", "We can also check all the chemical elements available in the database:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Symbol Molar Mass (kg/mol)\n", "Al 0.026982 \n", "Ca 0.040078 \n", "H 0.001008 \n", "O 0.015999 \n", "Si 0.028086 \n", "Na 0.022990 \n", "S 0.032067 \n", "C 0.012011 \n", "Mg 0.024305 \n", "Cl 0.035453 \n", "Fe 0.055845 \n", "Sr 0.087620 \n", "K 0.039098 \n", "N 0.014007 \n" ] } ], "source": [ "print(f\"{'Symbol':<10}{'Molar Mass (kg/mol)':<10}\")\n", "for element in db.elements():\n", " print(f\"{element.symbol():<10}{element.molarMass():<10.6f}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "That's it. You should now be able to load and inspect databases in Reaktoro the way you want! \n", "\n", "```{tip}\n", "You might want to check the API documentation of all Reaktoro components (classes and their methods) used in this tutorial:\n", "\n", "* {{Database}}\n", "* {{Element}}\n", "* {{Species}}\n", "* {{SpeciesList}}\n", "* {{ElementList}}\n", "* {{ChemicalFormula}}\n", "* {{AggregateState}}\n", "```" ] } ], "metadata": { "interpreter": { "hash": "e4e8b2f3ae27709963f14fd23a6560d362beea55eaec742263828e04d814e23c" }, "kernelspec": { "display_name": "Python 3.9.7 64-bit ('reaktoro-jupyter-book': conda)", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }