Using local environment to define A and B species in ABX3 perovskite

Hi everyone

So I have this list of ABX3 perovskites (not only cubic) and I need to make a simple script that tells from the structure only which ion is A and which ion is B.

Example: CaTiO3 -> A = Ca and B = Ti because Ti is at the center of the octahedron(s))

At first, I simply used the coordination number because it will be always 6 for B… But there are some corner cases that A also has a cn = 6 such as this guy here

So I was wondering how I can fully make use of the structural analysis tools from pymatgen for this particular problem…

Is there a module that given a structure and a site outputs the local environment such as ‘octahedral’, ‘tetrahedral’, ‘triangular prism’, etc?

Kind regards,

If anyone is interested…
Had some trouble with the documentation of Chemenv, but this tutorial solves my problem :smile: