Usage

import the library with your chosen alias, here e

[1]:
import elementMass as e

Calculate the atomic weight of an element or compound by with the function calculate_weight()

[2]:
wt_Si = e.calculate_weight("Si")
wt_SiO2 = e.calculate_weight("SiO2")
wt_Fe15O = e.calculate_weight("Fe1.5O")
print(f"Si: {wt_Si}, SiO2: {wt_SiO2}, Fe1.5O: {wt_Fe15O}")
Si: 28.086, SiO2: 60.084, Fe1.5O: 99.7665

Calculate atomic weights of multiple elements or compounds by supplying a list of names as the argument to compound_weights(). Results are returned as a pandas Series.

[3]:
element_names = ["SiO2", "Na2O", "P2O5"]
print(e.compound_weights(element_names))
SiO2     60.084
Na2O     61.979
P2O5    141.943
Name: weights, dtype: float64

Get cation or oxygen amounts with cation_numbers() and oxygen_numbers() respectively. Results are returned as a pandas Series.

[4]:
e.cation_numbers(["P2O5", "TiO2"])
[4]:
P2O5    2.0
TiO2    1.0
Name: cations, dtype: float64
[5]:
e.oxygen_numbers(["Fe2O3", "K2O"])
[5]:
Fe2O3    3.0
K2O      1.0
Name: oxygen, dtype: float64

Note that cation_numbers() simply returns the amount of the first listed element and therefore only gives reasonable results for simple oxides. It will not work on more complex compounds:

[6]:
e.cation_numbers(["MgFeSiO4"])
[6]:
MgFeSiO4    1.0
Name: cations, dtype: float64