Skip to content

Incorrect MAGMOM Handling in MPStaticSet When Using add_spin_by_site() #4335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
KylinGuo opened this issue Mar 28, 2025 · 0 comments
Open
Labels

Comments

@KylinGuo
Copy link

KylinGuo commented Mar 28, 2025

Python version

Python 3.13.2

Pymatgen version

2024.10.3

Operating system version

Ubuntu 24.04

Current behavior

When adding magnetic moments to a structure, MPStaticSet produces different MAGMOM values in the INCAR depending on whether add_site_property() or add_spin_by_site() is used. The latter method appears to flip the signs of the magnetic moments.

  • Using add_site_property() produces correct MAGMOM values in INCAR
  • Using add_spin_by_site() flips the signs of magnetic moments in the resulting INCAR

Expected Behavior

Both methods should produce identical MAGMOM values in the INCAR file when given identical spin configurations.

Minimal example

from numpy.testing import assert_allclose
from pymatgen.core import Structure
from pymatgen.io.vasp.sets import MPStaticSet

EXPECTED_MAGMOM = [5.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]


def demo_add_magmom_and_write_incar():
    structure = Structure.from_file(filename='POSCAR')
    spins = [+5, -5, 0, 0, 0, 0, 0, 0, 0, 0]
    structure.add_site_property("magmom", spins)
    mp_static_set = MPStaticSet(structure=structure)
    incar_dict = mp_static_set.incar.as_dict()
    assert_allclose(incar_dict.get('MAGMOM'), EXPECTED_MAGMOM)  # Passes


def demo_add_spin_and_write_incar():
    structure = Structure.from_file(filename='POSCAR')
    spins = [+5, -5, 0, 0, 0, 0, 0, 0, 0, 0]
    structure.add_spin_by_site(spins)
    mp_static_set = MPStaticSet(structure=structure)
    incar_dict = mp_static_set.incar.as_dict()
    assert_allclose(incar_dict.get('MAGMOM'), EXPECTED_MAGMOM)  # Fails (signs flipped)


if __name__ == "__main__":
    demo_add_magmom_and_write_incar()
    demo_add_spin_and_write_incar()

Relevant files to reproduce this bug

POSCAR file:

MnPSe3
   6.40804163940561
     0.8660254037844390   -0.5000000000000000    0.0000000000000000
     0.8660254037844390    0.5000000000000000    0.0000000000000000
     0.0000000000000000    0.0000000000000000    3.7182201236084644
   Mn   P    Se
     2     2     6
Selective dynamics
Direct
  0.0000000000000000  0.0000000000000000  0.0000000000000000   F   F   F
  0.3333333333333357  0.3333333333333357  0.0000000000000000   F   F   F
  0.6666666666666643  0.6666666666666643  0.0470578253908371   T   T   T
  0.6666666666666643  0.6666666666666643  0.9529421746091629   T   T   T
  0.6666666666666643  0.3356524591118557  0.0732317250636854   T   T   T
  0.9976808742214800  0.6666666666666643  0.0732317250636854   T   T   T
  0.3356524591118557  0.9976808742214800  0.0732317250636854   T   T   T
  0.3356524591118557  0.6666666666666643  0.9267682749363146   T   T   T
  0.9976808742214800  0.3356524591118557  0.9267682749363146   T   T   T
  0.6666666666666643  0.9976808742214800  0.9267682749363146   T   T   T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant