Chemical Compounds¶
Making a Compound¶
- class chemlib.chemistry.Compound(*args: Any, **kwargs: Any)¶
Instantiate a chemlib.Compound
object with the formula of the compound.
>>> from chemlib import Compound
>>> water = Compound("H2O")
>>> water.formula
'H₂O₁'
- chemlib.chemistry.Compound.occurences: dict¶
A dictionary containing the frequencies of the constituent elements in the compound.
>>> water.occurences {'H': 2, 'O': 1}
Molar Mass¶
- chemlib.chemistry.Compound.molar_mass(self)¶
- Returns
The molar mass in (g/mol) of the compound
- Return type
float
>>> water.molar_mass()
18.01
Percentage Composition by Mass¶
- chemlib.chemistry.Compound.percentage_by_mass(self, element)¶
Get the percentage composition by mass of a certain element of the compound.
- Parameters
element (str) – The constituent element of which the user wants to get percentage composition.
- Returns
The percentage composition by mass of the element in the compound.
- Return type
float
>>> water.percentage_by_mass('H') #Percent of Hydrogen in Compound
11.183
>>> water.percentage_by_mass('O') #Percent of Oxygen in Compound
88.834
Stoichiometry¶
- chemlib.chemistry.Compound.get_amounts(self, **kwargs)¶
Get stoichiometric amounts of the compound given one measurement.
- Parameters
compound_number (int) – The chosen compound in the reaction by order of appearance.
kwargs – The amount of the chosen compound (grams=, moles=, or molecules=)
- Returns
The gram, mole, and molecule amounts of the compound.
- Return type
dict
- Raises
ValueError – If the kwargs argument isn’t either grams, moles, or molecules
ValueError – if more than one argument is given under kwargs
Get the amount of moles and molecules of water given 2 grams of water.
>>> water.get_amounts(grams = 2)
{'Compound': 'H₂O₁', 'Grams': 2, 'Moles': 0.111, 'Molecules': 6.685e+22}
Get the amount of grams and molecules of water given 2 moles of water.
>>> water.get_amounts(moles = 2)
{'Compound': 'H₂O₁', 'Grams': 36.02, 'Moles': 2, 'Molecules': 1.204e+24}
Get the amount of moles and grams of water given 2e+24 molecules of water.
>>> water.get_amounts(molecules = 2e+24)
{'Compound': 'H₂O₁', 'Grams': 59.834, 'Moles': 3.3223, 'Molecules': 2e+24}