from pymatgen.core.composition import Composition # create a Composition object with a formula water = Composition("H2O") # access the number of atoms of an element print(water["H"]) # prints 2 # add two compositions together co2 = Composition("CO2") total = water + co2 print(total) # prints H2O1C1O3 # get the weight fraction of an element print(water.weight_fraction("O")) # prints 0.88971In the first example, we create a Composition object for water by passing in its formula ("H2O"). Then we access the number of hydrogen atoms using the dictionary notation and print the result. The second example shows how to add two compositions together by using the "+" operator. The resulting Composition object represents the total composition of water and carbon dioxide. Finally, the last example shows how to calculate the weight fraction of oxygen in water. We use the `weight_fraction()` method to get the fraction of the total weight that comes from oxygen. The package library for pymatgen.core.composition Composition is PyMatGen.