From ee6476f8fab0d012f3a6a0ea6bc45f4aa77a0187 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Tue, 10 Oct 2023 19:54:03 -0700 Subject: [PATCH] mirror atomate2 fix and improve test_kspacing edge case coverage --- pymatgen/io/vasp/sets.py | 4 ++-- tests/io/vasp/test_sets.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pymatgen/io/vasp/sets.py b/pymatgen/io/vasp/sets.py index 4ce08af2639..4645064e58c 100644 --- a/pymatgen/io/vasp/sets.py +++ b/pymatgen/io/vasp/sets.py @@ -977,10 +977,10 @@ def __init__( if self.bandgap < 1e-4: updates.update(KSPACING=0.22, SIGMA=0.2, ISMEAR=2) else: - rmin = 25.22 - 2.87 * bandgap # Eq. 25 + rmin = max(1.5, 25.22 - 2.87 * bandgap) # Eq. 25 kspacing = 2 * np.pi * 1.0265 / (rmin - 1.0183) # Eq. 29 # cap the KSPACING at a max of 0.44, per internal benchmarking - updates.update(KSPACING=kspacing if 0.22 < kspacing < 0.44 else 0.44, SIGMA=0.05, ISMEAR=-5) + updates.update(KSPACING=np.clip(kspacing, 0.22, 0.44), SIGMA=0.05, ISMEAR=-5) # Don't overwrite things the user has supplied for key in self.user_incar_settings: diff --git a/tests/io/vasp/test_sets.py b/tests/io/vasp/test_sets.py index d8cb02315f1..e091cd4ad60 100644 --- a/tests/io/vasp/test_sets.py +++ b/tests/io/vasp/test_sets.py @@ -1555,11 +1555,11 @@ def test_kspacing(self): # Test that KSPACING is capped at 0.44 for insulators file_path = f"{TEST_FILES_DIR}/POSCAR.O2" struct = Poscar.from_file(file_path, check_for_POTCAR=False).structure - for bandgap, expected in ((10, 0.44), (3, 0.4136617), (1.1, 0.3064757)): + for bandgap, expected in ((10, 0.44), (3, 0.4136617), (1.1, 0.3064757), (0.5, 0.2832948), (0, 0.22)): incar = MPScanRelaxSet(struct, bandgap=bandgap).incar assert incar["KSPACING"] == approx(expected, abs=1e-5) - assert incar["ISMEAR"] == -5 - assert incar["SIGMA"] == 0.05 + assert incar["ISMEAR"] == -5 if bandgap > 1e-4 else 2 + assert incar["SIGMA"] == 0.05 if bandgap > 1e-4 else 0.2 def test_incar_overrides(self): # use 'user_incar_settings' to override the KSPACING, ISMEAR, and SIGMA