diff --git a/pymatgen/io/vasp/sets.py b/pymatgen/io/vasp/sets.py index 2ebf055af90..5d425ce45ba 100644 --- a/pymatgen/io/vasp/sets.py +++ b/pymatgen/io/vasp/sets.py @@ -544,22 +544,27 @@ def incar(self) -> Incar: else: incar[k] = v has_u = hubbard_u and sum(incar["LDAUU"]) > 0 - if has_u: - # modify LMAXMIX if LSDA+U and you have d or f electrons - # note that if the user explicitly sets LMAXMIX in settings it will - # override this logic. - if "LMAXMIX" not in settings.keys(): - # contains f-electrons - if any(el.Z > 56 for el in structure.composition): - incar["LMAXMIX"] = 6 - # contains d-electrons - elif any(el.Z > 20 for el in structure.composition): - incar["LMAXMIX"] = 4 - else: + if not has_u: for key in list(incar.keys()): if key.startswith("LDAU"): del incar[key] + # Modify LMAXMIX if you have d or f electrons present. + # Note that if the user explicitly sets LMAXMIX in settings it will + # override this logic. + # Previously, this was only set if Hubbard U was enabled as per the + # VASP manual but following an investigation it was determined that + # this would lead to a significant difference between SCF -> NonSCF + # even without Hubbard U enabled. Thanks to Andrew Rosen for + # investigating and reporting. + if "LMAXMIX" not in settings.keys(): + # contains f-electrons + if any(el.Z > 56 for el in structure.composition): + incar["LMAXMIX"] = 6 + # contains d-electrons + elif any(el.Z > 20 for el in structure.composition): + incar["LMAXMIX"] = 4 + if self.constrain_total_magmom: nupdown = sum([mag if abs(mag) > 0.6 else 0 for mag in incar["MAGMOM"]]) incar["NUPDOWN"] = nupdown diff --git a/pymatgen/io/vasp/tests/test_sets.py b/pymatgen/io/vasp/tests/test_sets.py index 1784910d64d..8d954cc4ceb 100644 --- a/pymatgen/io/vasp/tests/test_sets.py +++ b/pymatgen/io/vasp/tests/test_sets.py @@ -413,6 +413,9 @@ def test_hubbard_off_and_ediff_override(self): p = MPRelaxSet(self.structure, user_incar_settings={"LDAU": False, "EDIFF": 1e-10}) self.assertNotIn("LDAUU", p.incar) self.assertEqual(p.incar["EDIFF"], 1e-10) + # after testing, we have determined LMAXMIX should still be 4 for d-block + # even if U is turned off (thanks Andrew Rosen for reporting) + self.assertEqual(p.incar["LMAXMIX"], 4) def test_write_input(self): self.mitset.write_input(".", make_dir_if_not_present=True)