# Accessing unit cell formula coefficients // Mean atomic number per unit cell

I am trying to access the coefficients after each atom in the unit cell formula, for example in the following unit cell, {“Li”: 4, “O”: 2}, i need to be able to access the numbers 4 and 2.
What I’m actually trying to do is calculate the mean atomic number per atom in a given unit cell for each of the entries i queried so i can later plot and analyze my data.
My thought process till this point is accessing each coefficient and atom, in each unit cell formula, in each entry, then calculate the mean atomic number and divide by the number of elements in each unit cell.
Is there by any chance a fastest way to achieve this with another (maybe single) command?
Hope i made myself clear enough

-Aris

Hi Aris,

I assume you queried the MP API for either `unit_cell_formula` or `reduced_cell_formula`, right? In that case you already get the unit cell formula information as a Python dictionary which makes it pretty straight-forward to determine the mean atomic number:

``````unit_cell = {"Li": 4, "O": 2}
print(sum(unit_cell.values()) / len(unit_cell.keys()))
``````

Is this what you had in mind?

Best,
Peter

1 Like

Hello Peter and thanks for the reply,

it kinda is yes but what i had in mind, for example in the above scenario with Li and O, was:

mean atomic number = (4 * Z_Li + 2 * Z_O) / ( nsites ).

What i failed to understand at the time was dictionary structures, which i then researched a bit a got the right commands. A `for` loop with `x, y in` the dictionary allowed me to access those coefficients (values) and keys. Then with `element().atomic_number` from the `mendeleev` library i managed to calculate the appropriate the mean atomic number.

-Aris

1 Like