Skip to content

Commit

Permalink
mirror atomate2 fix and improve test_kspacing edge case coverage (#3396)
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh authored Oct 11, 2023
1 parent 30d11bb commit c818aa7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pymatgen/io/vasp/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/io/vasp/test_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c818aa7

Please sign in to comment.