How to compute molecular weight in Python using UliEngineering
You can easily compute the molecular weight (molar mass) of a compound using the UliEngineering Python library:
from UliEngineering.Chemistry import molecular_weight
from UliEngineering.EngineerIO import *
# Compute molecular weight of water (H2O)
mw = molecular_weight("H2O")
print(f"Molecular weight of H2O: {format_value(mw, 'g/mol')}")
# Compute molecular weight of carbon dioxide (CO2)
mw = molecular_weight("CO2")
print(f"Molecular weight of CO2: {format_value(mw, 'g/mol')}")
# Compute molecular weight of glucose (C6H12O6)
mw = molecular_weight("C6H12O6")
print(f"Molecular weight of C6H12O6: {format_value(mw, 'g/mol')}")Example output
Molecular weight of H2O: 18.0 g/mol
Molecular weight of CO2: 44.0 g/mol
Molecular weight of C6H12O6: 180 g/molThe molecular weight (also called molar mass) is the mass of one mole of a substance, typically expressed in grams per mole (g/mol). It is calculated by summing the atomic weights of all atoms in the chemical formula. This fundamental property is essential for stoichiometry calculations, converting between mass and moles, and determining concentrations.
The molecular weight is computed using the formula: $M = \sum_{i} n_i \times A_i$, where $M$ is the molecular weight, $n_i$ is the number of atoms of element $i$ in the formula, and $A_i$ is the atomic weight of element $i$. The atomic weights are based on standard atomic masses from the periodic table.
Related posts
- How to convert moles to grams in Python using UliEngineering
- How to convert grams to moles in Python using UliEngineering
- How to compute molarity from moles and volume in Python using UliEngineering