Accessing Primitive Lattice Vectors using MAPI?

The crystal structure data seems to only reference the positions of the atoms through the primitive lattice vectors, but I cannot return the actual primitive lattice vectors themselves. The vector data, defined under some arbitrary x, y, z axis, is visible when accessing the structure data from pymatgen, but I cannot seem to extract it. Could someone enlighten me a bit on how to extract this data through python?


Hello @zhangstephen,
This is more a Pymatgen question than a MP/API question, but here we go:
Once you have the structure within Pymatgen you can access the lattice basis vectors as


and if you set i equals 0, 1, or 2 you get the a, b, or c lattice vector, respectively.
Also, if you only need the atomic coordinates in Cartesian coordinates (rather than relative to the basis vectors) you can directly access them as structure.cart_coords


Just to note, the structure returned via the API is not guaranteed to be the primitive structure. You can use pymatgen’s Structure.get_primitive_structure() for this however, once the structure is returned from the API. After that, @peterschindler’s answer is correct.

@mkhorton That’s a good point! Make sure to query for the lattice setting that you are interested in @zhangstephen. You can query for cifs.primitive or cifs.conventional_standard.
A word of caution: if you use the function get_primitive_structure on a structure that is already primitive to begin with, it can un-physically distort the structure. It happened to me.

That actually looks like a rather serious bug, thanks for bringing it up again … get_primitive() should not distort the structure (change the setting yes, but change the bonding no).

1 Like

Thanks everyone, I appreciate the help!