diff --git a/src/atomate2/vasp/sets/base.py b/src/atomate2/vasp/sets/base.py index 31740dc8e3..5dd52353d0 100644 --- a/src/atomate2/vasp/sets/base.py +++ b/src/atomate2/vasp/sets/base.py @@ -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 @@ -1112,7 +1113,8 @@ 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 @@ -1120,6 +1122,7 @@ def _set_kspacing( # 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"] diff --git a/tests/vasp/test_sets.py b/tests/vasp/test_sets.py index d8b5a22768..f07e2b5a8c 100644 --- a/tests/vasp/test_sets.py +++ b/tests/vasp/test_sets.py @@ -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() @@ -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,