Sorting atoms in pymatgen.core.structure.Structure in ascending z direction and setting MAGMOM for Magnetism

Hello everyone,

I would like some help with sorting atom in Structure.
I want to perform magnetism for Fe2O3 and Cr2O3 (ferromagnetic and antiferromagnetic)
I have some trouble assign MAGMOM for antiferromagnetic (+±-, ±±,and ±-+). I think I need to sort atom (Fe) in ascending in z-direction so that I can assign + and - sign.

I tried get_sorted_structure() and sort() but I still receive the same structure. I checked the document and I think they sort it base on electronegativity.
Does anyone have any idea how to sort Fe specie in Structure?

In addition, any suggestion for using from pymatgen.analysis.magnetism.analyzer
For example MagneticStructureEnumerator?

Thank you for everyone time!



I think you make this more difficult for yourself than it has to be. I am not sure what exact structure of Fe2O3 and Cr2O3 you want to investigate, but the ones with the lowest energy in the MaterialsProject database ( mp-19770 and mp-19399) are both AFM. So just download the structures from there and the magnetic moments are already set correctly in the AFM configuration.

If you then want to switch to FM, you can set all moments to their absolute values easily. Lets say you have Fe2O3 in AFM as afm_struct. Do something like:

fm_struct = afm_struct.copy()
new_mag = [abs(m) for m in fm_struct.site_properties['magmom']]
fm_struct.add_site_property('magmom', new_mag)

If you have a different magnetic order in mind, then I think the easiest way is to just look at the atomic positions and set the magmom list yourself by hand. No reordering of the positions required… Since there are often many different AFM possibilities for the same crystal structure, often with different unit cells, this is a quite hard problem to generalize.

1 Like

Thanks @mwo, I think that’s the ideal answer.

That said, MagneticStructureEnumerator (with the help of enumlib) does indeed enumerate possible magnetic orderings for a given input structure, and can be very helpful (this procedure is documented in this paper). However, this is best applied to materials where the magnetic ordering is unknown, if the material (or a similar material) is well-known experimentally it is often easier to set the magnetic moments by hand to match these known orderings.

Hope this helps!


1 Like

Hi mwo,
Thank you for the response!
The structure I want to investigate is corundum Fe2O3 and Cr2O3. I have been manually assign the magmom in INCAR for VASP simulation. The bulk structure has 30 sites so it was ok assigning it manually. But I need to investigate the 2x2 cell now.

Let’s say I want to verify the structure from MP database is AFM and info that relate to spin (magnetism), is there packages I could use to check?

there are 2 Fe2O3 structures with 30 atoms in the MaterialsProject database, but both have FM ordering. On this page you can check the available structures, but magnetic infos is restricted to the type of ordering on the website I think. Check out the MPRester, to download structures and other infos. The documentation has Fe2O3 as an example by chance.
If your structure of interest is among the ones provided in the database, you will have to use the MagneticStructureEnumerator @mkhorton suggested to get various AFM options and select the appropriate one or maybe run calculations for a number of options.
However, since you have defined the moments already, you probably only have to transfer them from the INCAR to the pymatgen Structure object using the site properties.

Now you can easily construct supercells with the same magnetic ordering using the make_supercell() method of the Structure object.

If you have no pymatgen Structure, and it is not in the database, you can of course easily read it from the POSCAR that you have and then add the magmoms as a list:

from pymatgen.core.structure import Structure
struct = Structure.from_file('POSCAR')
struct.add_site_property('magmom': [2.5, 2.5, -2.5, -2.5, 0.0, ...])
1 Like

Thank you a lot! I will give it a try