Skip to content

Commit 6027ae5

Browse files
authored
Merge pull request #648 from JonathanSchmidt1/LDAU
2 parents 5ec73f7 + 0cf5df0 commit 6027ae5

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/atomate2/vasp/sets/base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ class VaspInputGenerator(InputGenerator):
236236
so these keys can be defined in one of two ways, e.g. either
237237
{"LDAUU":{"O":{"Fe":5}}} to set LDAUU for Fe to 5 in an oxide, or
238238
{"LDAUU":{"Fe":5}} to set LDAUU to 5 regardless of the input structure.
239-
To set magmoms, pass a dict mapping element symbols to magnetic moments, e.g.
240-
{"MAGMOM": {"Co": 1}}.
239+
To set magmoms, pass a dict mapping the strings of species to magnetic
240+
moments, e.g. {"MAGMOM": {"Co": 1}} or {"MAGMOM": {"Fe2+,spin=4": 3.7}} in the
241+
case of a site with Species("Fe2+", spin=4).
241242
If None is given, that key is unset. For example, {"ENCUT": None} will remove
242243
ENCUT from the incar settings.
243244
user_kpoints_settings
@@ -655,7 +656,7 @@ def _get_incar(
655656
if k == "MAGMOM":
656657
incar[k] = _get_magmoms(
657658
structure,
658-
magmoms=self.user_incar_settings.get("MAGMOMS", {}),
659+
magmoms=self.user_incar_settings.get("MAGMOM", {}),
659660
config_magmoms=config_magmoms,
660661
)
661662
elif k in ("LDAUU", "LDAUJ", "LDAUL") and incar_settings.get("LDAU", False):
@@ -726,7 +727,9 @@ def _get_incar(
726727

727728
# Finally, re-apply `self.user_incar_settings` to make sure any accidentally
728729
# overwritten settings are changed back to the intended values.
729-
_apply_incar_updates(incar, self.user_incar_settings)
730+
# skip dictionary parameters to avoid dictionaries appearing in the INCAR
731+
skip = ["LDAUU", "LDAUJ", "LDAUL", "MAGMOM"]
732+
_apply_incar_updates(incar, self.user_incar_settings, skip=skip)
730733

731734
return incar
732735

tests/vasp/test_sets.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def test_user_incar_settings():
7474
"NSW": 5_000,
7575
"PREC": 10, # wrong type, should be string.
7676
"SIGMA": 20,
77+
"LDAUU": {"H": 5.0},
78+
"LDAUJ": {"H": 6.0},
79+
"LDAUL": {"H": 3.0},
80+
"LDAUTYPE": 2,
7781
}
7882

7983
static_set_generator = StaticSetGenerator(user_incar_settings=uis)
@@ -82,6 +86,8 @@ def test_user_incar_settings():
8286
for key in uis:
8387
if isinstance(incar[key], str):
8488
assert incar[key].lower() == uis[key].lower()
89+
elif isinstance(uis[key], dict):
90+
assert incar[key] == [uis[key][str(site.specie)] for site in structure]
8591
else:
8692
assert incar[key] == uis[key]
8793

@@ -92,9 +98,9 @@ def test_user_incar_settings():
9298
("struct_no_magmoms", {}),
9399
("struct_with_magmoms", {}),
94100
("struct_with_spin", {}),
95-
("struct_no_magmoms", {"MAGMOM": [3.7, 0.8]}),
96-
("struct_with_magmoms", {"MAGMOM": [3.7, 0.8]}),
97-
("struct_with_spin", {"MAGMOM": [3.7, 0.8]}),
101+
("struct_no_magmoms", {"MAGMOM": {"Fe": 3.7, "O": 0.8}}),
102+
("struct_with_magmoms", {"MAGMOM": {"Fe": 3.7, "O": 0.8}}),
103+
("struct_with_spin", {"MAGMOM": {"Fe2+,spin=4": 3.7, "O2-,spin=0.63": 0.8}}),
98104
],
99105
)
100106
def test_incar_magmoms_precedence(structure, user_incar_settings, request) -> None:
@@ -121,7 +127,9 @@ def test_incar_magmoms_precedence(structure, user_incar_settings, request) -> No
121127
has_struct_spin = getattr(structure.species[0], "spin", None) is not None
122128

123129
if user_incar_settings: # case 1
124-
assert incar_magmom == user_incar_settings["MAGMOM"]
130+
assert incar_magmom == [
131+
user_incar_settings["MAGMOM"][str(site.specie)] for site in structure
132+
]
125133
elif has_struct_magmom: # case 2
126134
assert incar_magmom == structure.site_properties["magmom"]
127135
elif has_struct_spin: # case 3

0 commit comments

Comments
 (0)