Determining the molar mass of a substance is done countless times in mass and energy balance models and other process models. It usually requires you to create your own little database or list that you look up the values from. Once you have that, you can perform the required calculations. The auxi.tools.chemistry.stoichiometry
module provides the molar_mass() function for this purpose.
The normal way of getting the molar mass of one or more compounds is as follows:
In [1]:
from auxi.tools.chemistry import stoichiometry
molarmass_FeO = stoichiometry.molar_mass("FeO")
molarmass_CO2 = stoichiometry.molar_mass("CO2")
molarmass_FeCr2O4 = stoichiometry.molar_mass("FeCr2O4")
An example is shown below with its output:
In [2]:
print("Molar mass of FeO :", molarmass_FeO, "kg/kmol")
print("Molar mass of CO2 :", molarmass_CO2, "kg/kmol")
print("Molar mass of FeCr2O4:", molarmass_FeCr2O4, "kg/kmol")
One of Python's strengths is its ability to make code very compact. You may not always want to use a lengthy "stoichiometry.molar_mass" reference to the function. Rather than importing the auxi.tools.chemistry.stoichiometry
module, we can import the auxi.tools.chemistry.stoichiometry.molar_mass
function directly, and give it another name. Here is how you can make it short and sweet:
In [3]:
from auxi.tools.chemistry.stoichiometry import molar_mass as mm
molarmass_FeO = mm("FeO")
print("Molar mass of FeO :", molarmass_FeO, "kg/kmol")
print("Molar mass of CO2 :", mm("CO2"), "kg/kmol")
print("Molar mass of FeCr2O4:", mm("FeCr2O4"), "kg/kmol")
In [4]:
from auxi.tools.chemistry.stoichiometry import molar_mass as mm
def print_molar_mass(compound):
print("Molar mass of", compound, "is", mm(compound), "kg/kmol.")
print_molar_mass("FeO1.5")
print_molar_mass("Fe2O3")
print_molar_mass("FeOTiO2")
print_molar_mass("FeTiO3")
print_molar_mass("Fe2(CO3)3")
print_molar_mass("Fe2C3O9")
print_molar_mass("H2O")
print_molar_mass("H")
print_molar_mass("He")
print_molar_mass("Au")
Sometimes you need to convert the mass of a compound (kg) to the equivalent amount (kmol). The auxi.tools.chemistry.stoichiometry
module provides the auxi.tools.chemistry.stoichiometry.amount
function to do this.
The amount is calculated as follows:
$$n_{\text{compound}} = \frac{m_{\text{compound}}}{mm_{\text{compound}}}$$where
$n_{\text{compound}}$ is the compound amount in kmol. $m_{\text{compound}}$ is the compound mass in kg. $mm_{\text{compound}}$ is the compound molar mass in kg/kmol.
The normal way of calculating the amount of a compound is as follows:
In [5]:
from auxi.tools.chemistry import stoichiometry
m_FeO = 10.0
n_FeO = stoichiometry.amount("FeO", m_FeO)
print("There is", n_FeO, "kmol of FeO in", m_FeO , "kg of the compound.")
m_CO2 = 12.3
n_CO2 = stoichiometry.amount("CO2", m_CO2)
print("There is", n_CO2, "kmol of CO2 in", m_CO2 , "kg of the compound.")
m_FeCr2O4 = 453.0
n_FeCr2O4 = stoichiometry.amount("FeCr2O4", m_FeCr2O4)
print("There is", n_FeCr2O4, "kmol of FeCr2O4 in",
m_FeCr2O4 , "kg of the compound.")
In [6]:
from auxi.tools.chemistry.stoichiometry import amount
m_FeO = 10.0
n_FeO = amount("FeO", m_FeO)
print("There is", n_FeO, "kmol of FeO in", m_FeO , "kg of the compound.")
m_CO2 = 12.3
n_CO2 = amount("CO2", m_CO2)
print("There is", n_CO2, "kmol of CO2 in", m_CO2 , "kg of the compound.")
m_FeCr2O4 = 453.0
n_FeCr2O4 = amount("FeCr2O4", m_FeCr2O4)
print("There is", n_FeCr2O4, "kmol of FeCr2O4 in",
m_FeCr2O4 , "kg of the compound.")
You often have the amount (kmol) of a compound and then need to calculate its mass. The auxi.tools.chemistry.stoichiometry
module provides the auxi.tools.chemistry.stoichiometry.mass
function for this. The mass is calculate with this formula:
where
$m_{\text{compound}}$ is the compound mass in kg. $n_{\text{compound}}$ is the compound amount in kmol. $mm_{\text{compound}}$ is the compound molar mass in kg/kmol. From this point forward the standard and compact approaches are not both demonstrated. Only the standard method, which imports the module, is used below since it is more explicit:
In [7]:
from auxi.tools.chemistry import stoichiometry
n_FeO = 10.0
m_FeO = stoichiometry.mass("FeO", n_FeO)
print("There is", m_FeO, "kg of FeO in", n_FeO , "kmol of the compound.")
m_CO2 = 12.3
n_CO2 = stoichiometry.mass("CO2", m_CO2)
print("There is", m_CO2, "kg of CO2 in", n_CO2 , "kmol of the compound.")
m_FeCr2O4 = 453.0
n_FeCr2O4 = stoichiometry.mass("FeCr2O4", m_FeCr2O4)
print("There is", m_FeCr2O4, "kg of FeCr2O4 in",
n_FeCr2O4 , "kmol of the compound.")
The list of elements present in one or more compounds can be used when calculating element balances. Determining this list is often done manually. auxi.tools.chemistry.stoichiometry
has the auxi.tools.chemistry.stoichiometry.elements
function to automate this task. This is how you use it:
In [8]:
from auxi.tools.chemistry import stoichiometry
elements_Fe2O3 = stoichiometry.elements(["Fe2O3"])
print("Fe2O3 contains these elements:", elements_Fe2O3)
elements_CO2 = stoichiometry.elements(["CO2"])
print("CO2 contains these elements:", elements_CO2)
elements_Fe2Cr2O4 = stoichiometry.elements(["Fe2Cr2O4"])
print("Fe2Cr2O4 contains these elements:", elements_Fe2Cr2O4)
elements_Al2S3O12 = stoichiometry.elements(["Al2(SO4)3"])
print("Al2(SO4)3 contains these elements:", elements_Al2S3O12)
elements_all = stoichiometry.elements(["Fe2O3", "CO2", "Fe2Cr2O4", "Al2(SO4)3"])
print("Fe2O3, CO2, Fe2Cr2O4 and Al2(SO4)3 contain these elements:",
elements_all)
The auxi.tools.chemistry.stoichiometry.stoichiometry_coefficient
and auxi.tools.chemistry.stoichiometry.stoichiometry_coefficients
functions in auxi.tools.chemistry.stoichiometry
determine the stoichiometry coefficients of elements in chemical compounds automatically. If we are only interested in the coefficient for a single element, we use auxi.tools.chemistry.stoichiometry.stoichiometry_coefficient
like this:
In [9]:
from auxi.tools.chemistry import stoichiometry
coeff_Fe2O3_Fe = stoichiometry.stoichiometry_coefficient("Fe2O3", "Fe")
print("Stoichiometry coefficient of Fe in Fe2O3:", coeff_Fe2O3_Fe)
coeff_Fe2O3_O = stoichiometry.stoichiometry_coefficient("Fe2O3", "O")
print("Stoichiometry coefficient of O in Fe2O3:", coeff_Fe2O3_O)
coeff_Fe2O3_C = stoichiometry.stoichiometry_coefficient("Fe2O3", "C")
print("Stoichiometry coefficient of C in Fe2O3:", coeff_Fe2O3_C)
We can determine the coefficients for a list of elements using the auxi.tools.chemistry.stoichiometry.stoichiometry_coefficients
function:
In [10]:
from auxi.tools.chemistry import stoichiometry
elements = ["Fe", "O", "C", "Ar"]
st_Fe2O3 = stoichiometry.stoichiometry_coefficients("Fe2O3", elements)
print("Stoichiometry coefficient of", elements, "in Fe2O3:",
st_Fe2O3)
elements = ["Al", "Ca", "Fe", "Si", "O", "C", "H"]
st_Lawsonite = stoichiometry.stoichiometry_coefficients("CaAl2Si2O7O2H2H2O",
elements)
print("Stoichiometry coefficient of", elements,
"in Lawsonite (CaAl2(Si2O7)(OH)2·H2O):", st_Lawsonite)
Another two useful tools in the calculation of element balances are the auxi.tools.chemistry.stoichiometry.element_mass_fraction
and auxi.tools.chemistry.stoichiometry.element_mass_fractions
functions in auxi.tools.chemistry.stoichiometry
. They are similar to the stoichiometry coefficient functions, but calculate the mass fraction of an element or list of elements in a chemical compound. The calculations are done with the following equation:
where
$y_{\text{compound,element}}$ is the mass fraction of the specified element in the compound.
$n_{\text{compound,element}}$ is the stoichiometry coefficient of the specified element in the compound.
$mm_{\text{element}}$ is the element's molar mass in kg/kmol.
$mm_{\text{compound}}$ is the compound's molar mass in kg/kmol.
For determining the mass fraction of a single element we can use auxi.tools.chemistry.stoichiometry.element_mass_fraction
as follows:
In [11]:
from auxi.tools.chemistry import stoichiometry
y_Fe2O3_Fe = stoichiometry.element_mass_fraction("Fe2O3", "Fe")
print("Mass fraction of Fe in Fe2O3:", y_Fe2O3_Fe)
y_Fe2O3_O = stoichiometry.element_mass_fraction("Fe2O3", "O")
print("Mass fraction of O in Fe2O3:", y_Fe2O3_O)
y_Fe2O3_C = stoichiometry.element_mass_fraction("Fe2O3", "C")
print("Mass fraction of C in Fe2O3:", y_Fe2O3_C)
In [12]:
from auxi.tools.chemistry import stoichiometry
elements = ["Fe", "O", "C", "Ar"]
y_Fe2O3 = stoichiometry.element_mass_fractions("Fe2O3", elements)
print("Mass fractions of", elements, "in Fe2O3:", y_Fe2O3)
elements = ["Al", "Ca", "Fe", "Si", "O", "C", "H"]
y_Lawsonite = stoichiometry.element_mass_fractions("CaAl2Si2O7O2H2H2O", elements)
print("Mass fractions of", elements,
"in Lawsonite (CaAl2(Si2O7)(OH)2·H2O):",
y_Lawsonite)
Sometimes it is needed to convert the mass of one compound to an equivalent mass of another compound. For example, how much Fe will I get when I reduce a certain mass of Fe2O3? auxi.tools.chemistry.stoichiometry
has the auxi.tools.chemistry.stoichiometry.convert_compound
function to help out. The function calculates the result as follows:
where
$m_{\text{target}}$ is the target compound mass in kg.
$m_{\text{source}}$ is the source compound mass in kg.
$y_{\text{target,element}}$ is the mass fraction of the specified base element in the target compound.
$y_{\text{source,element}}$ is the mass fraction of the specified base element in the source compound.
Here are some simple examples of how to use auxi.tools.chemistry.stoichiometry.convert_compound
:
In [13]:
from auxi.tools.chemistry import stoichiometry
m_Fe2O3 = 10.0
m_Fe = stoichiometry.convert_compound(m_Fe2O3, "Fe2O3", "Fe", "Fe")
print("From", m_Fe2O3, "kg of Fe2O3,", m_Fe ,
"kg of Fe can be produced.")
m_Fe = 10.0
m_Fe2O3 = stoichiometry.convert_compound(m_Fe, "Fe", "Fe2O3", "Fe")
print("When", m_Fe, "kg of Fe is oxidised completely,", m_Fe2O3 ,
"kg of Fe2O3 will be produced.")