Calling specie from a site can result in two different types

Depending on the source of the structure the return value for “Site.specie” is either an specie object or an element object. When I’m working with a database of pymatgen structures this seems to vary depending on the data source. This causes inconsistent behaviour with attempting to access the atomic number with .Z as specie.Z and specie.element.Z can report different values for some structures. Sometimes site.Z can report huge numbers like 9145449639597878252 where as site.element.Z would behave properly for these samples. Handling these different possibilites has proven challenging

Have I missed something or is there a more robust way to extract the atomic number from any structure?

Hi @Michael_Moran,

Sometimes site.Z can report huge numbers like 9145449639597878252 where as site.element.Z would behave properly for these samples.

Can you provide an example of this?

Depending on the source of the structure the return value for “Site.specie” is either an specie object or an element object.

This is true. A site can hold a bare Element, or a Species (element annotated with oxidation state) or even a composition (for disordered structures, where a single site holds multiple species).

However, the .Z property should work on both Element and Species.

Also, in Python, you can use checks such as isinstance(..., Element) or hasattr or getattr to work with objects that might be one of multiple types.

If you can’t get it to work happy to help further.

Best,

Matt