Skip to content

Commit

Permalink
fix test_set_kspacing_and_auto_ismear
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 18, 2023
1 parent b7f9e1c commit a9389d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/atomate2/vasp/sets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ def _get_incar(
elif isinstance(self.auto_kspacing, float):
# interpret auto_kspacing as bandgap and set KSPACING based on user input
bandgap = self.auto_kspacing

_set_kspacing(incar, incar_settings, self.user_incar_settings, bandgap, kpoints)

# apply updates from auto options, careful not to override user_incar_settings
Expand Down Expand Up @@ -1112,14 +1113,16 @@ def _set_kspacing(

elif "KSPACING" in user_incar_settings:
incar["KSPACING"] = user_incar_settings["KSPACING"]
elif incar_settings.get("KSPACING") and isinstance(bandgap, float):

elif incar_settings.get("KSPACING") and isinstance(bandgap, (int, float)):
# will always default to 0.22 in first run as one
# cannot be sure if one treats a metal or
# semiconductor/insulator
incar["KSPACING"] = _get_kspacing(bandgap)
# This should default to ISMEAR=0 if band gap is not known (first computation)
# if not from_prev:
# # be careful to not override user_incar_settings

elif incar_settings.get("KSPACING"):
incar["KSPACING"] = incar_settings["KSPACING"]

Expand Down
24 changes: 9 additions & 15 deletions tests/vasp/test_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,7 @@ def test_incar_magmoms_precedence(structure, user_incar_settings, request) -> No
]


@pytest.mark.parametrize(
"structure",
[
"struct_no_magmoms",
"struct_no_u_params",
],
)
@pytest.mark.parametrize("structure", ["struct_no_magmoms", "struct_no_u_params"])
def test_set_u_params(structure, request) -> None:
structure = request.getfixturevalue(structure)
input_gen = StaticSetGenerator()
Expand Down Expand Up @@ -171,17 +165,17 @@ def test_set_u_params(structure, request) -> None:
"bandgap, expected_params",
[
(0, {"KSPACING": 0.22, "ISMEAR": 2, "SIGMA": 0.2}),
(0.1, {"KSPACING": 0.269695615, "ISMEAR": 0, "SIGMA": 0.05}),
(1, {"KSPACING": 0.302352354, "ISMEAR": 0, "SIGMA": 0.05}),
(2, {"KSPACING": 0.349355136, "ISMEAR": 0, "SIGMA": 0.05}),
(5, {"KSPACING": 0.44, "ISMEAR": 0, "SIGMA": 0.05}),
(10, {"KSPACING": 0.44, "ISMEAR": 0, "SIGMA": 0.05}),
(0.1, {"KSPACING": 0.269695615, "ISMEAR": -5, "SIGMA": 0.05}),
(1, {"KSPACING": 0.302352354, "ISMEAR": -5, "SIGMA": 0.05}),
(2, {"KSPACING": 0.349355136, "ISMEAR": -5, "SIGMA": 0.05}),
(5, {"KSPACING": 0.44, "ISMEAR": -5, "SIGMA": 0.05}),
(10, {"KSPACING": 0.44, "ISMEAR": -5, "SIGMA": 0.05}),
],
)
def test_set_kspacing(struct_no_magmoms, bandgap, expected_params):
static_set = StaticSetGenerator(auto_ismear=False)
def test_set_kspacing_and_auto_ismear(struct_no_magmoms, bandgap, expected_params):
static_set = StaticSetGenerator(auto_ismear=True, auto_kspacing=True)
# need to indicate to atomate2 to use KSPACING instead of KPOINTS
static_set.config_dict["INCAR"]["KSPACING"] = 0.1
static_set.config_dict["INCAR"]["KSPACING"] = 42 # dummy value

incar = static_set._get_incar(
structure=struct_no_magmoms,
Expand Down

0 comments on commit a9389d3

Please sign in to comment.