Skip to content

Commit bc9039a

Browse files
authored
MatPESStaticSet restore GGA tag removal if xc_functional.upper() == "R2SCAN" (#3288)
* use str.split for INHERITED_INCAR_PARAMS * add MatPESStaticSet init type hints * move ValueError Unrecognized {xc_functional=} to top * refactor MatPESStaticSet def incar(self) -> Incar: * leave user-defined ALGO if set, always apply LADU if xc_functional.upper().endswith("+U") and restore removing GGA tag if xc_functional.upper() == "R2SCAN" * fix test_functionals * revert INHERITED_INCAR_PARAMS revert setdefault r2SCAN algo --------- Signed-off-by: Janosh Riebesell <[email protected]>
1 parent 6ca0390 commit bc9039a

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

pymatgen/io/vasp/sets.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,13 +1201,15 @@ def from_prev_calc(cls, prev_calc_dir, **kwargs):
12011201
class MatPESStaticSet(DictSet):
12021202
"""Creates input files for a MatPES static calculation.
12031203
1204-
The goal of MatPES is to generate PES data. This is a distinctly different from the objectives of the MP static
1205-
calculations, which aims to obtain accurate energies and electronic structure (DOS) primarily. For PES data,
1206-
force accuracy (and to some extent, stress accuracy) is of paramount importance.
1207-
1208-
It should be noted that the default POTCAR versions have been updated to PBE_54, rather than the old PBE set used
1209-
in the MPStaticSet. However, **U values** are still based on PBE. The implicit assumption here is that the PBE_54
1210-
and PBE POTCARs are sufficiently similar that the U values fitted to the old PBE functional still applies.
1204+
The goal of MatPES is to generate potential energy surface data. This is a distinctly different
1205+
from the objectives of the MP static calculations, which aims to obtain primarily accurate
1206+
energies and also electronic structure (DOS). For PES data, force accuracy (and to some extent,
1207+
stress accuracy) is of paramount importance.
1208+
1209+
The default POTCAR versions have been updated to PBE_54 from the old PBE set used in the
1210+
MPStaticSet. However, **U values** are still based on PBE. The implicit assumption here is that
1211+
the PBE_54 and PBE POTCARs are sufficiently similar that the U values fitted to the old PBE
1212+
functional still applies.
12111213
"""
12121214

12131215
CONFIG = _load_yaml_config("MatPESStaticSet")
@@ -1242,31 +1244,35 @@ def __init__(
12421244
self,
12431245
structure: Structure,
12441246
xc_functional: Literal["R2SCAN", "PBE", "PBE+U"] = "PBE",
1245-
prev_incar=None,
1247+
prev_incar: Incar | dict | None = None,
12461248
**kwargs: Any,
1247-
):
1249+
) -> None:
12481250
"""
12491251
Args:
12501252
structure (Structure): Structure for static calculation.
12511253
xc_functional ('R2SCAN'|'PBE'): Exchange-correlation functional to use. Defaults to 'PBE'.
1252-
prev_incar (Incar|str): Incar file from previous run. Default settings of MatPESStaticSet
1253-
are prioritized over inputs from previous runs.
1254+
prev_incar (Incar | dict): Incar file from previous run. Default settings of MatPESStaticSet
1255+
are prioritized over inputs from previous runs. Defaults to None.
12541256
**kwargs: Passed to DictSet.
12551257
"""
1258+
valid_xc_functionals = ("R2SCAN", "PBE", "PBE+U")
1259+
if xc_functional.upper() not in valid_xc_functionals:
1260+
raise ValueError(
1261+
f"Unrecognized {xc_functional=}. Supported exchange-correlation functionals are {valid_xc_functionals}"
1262+
)
1263+
12561264
super().__init__(structure, MatPESStaticSet.CONFIG, **kwargs)
12571265

12581266
if xc_functional.upper() == "R2SCAN":
12591267
self._config_dict["INCAR"]["METAGGA"] = "R2SCAN"
12601268
self._config_dict["INCAR"]["ALGO"] = "ALL"
12611269
self._config_dict["INCAR"].pop("GGA", None)
1262-
elif xc_functional.upper() == "PBE+U":
1270+
if xc_functional.upper().endswith("+U"):
12631271
self._config_dict["INCAR"]["LDAU"] = True
1264-
elif xc_functional.upper() != "PBE":
1265-
raise ValueError(f"{xc_functional} is not supported. Supported xc functionals are PBE, PBE+U and R2SCAN.")
1266-
if kwargs.get("user_potcar_functional", "PBE_54") != "PBE_54":
1267-
warnings.warn(
1268-
f"POTCAR ({kwargs['user_potcar_functional']}) is inconsistent with the recommended PBE_54.", UserWarning
1269-
)
1272+
user_potcar_functional = kwargs.get("user_potcar_functional", "PBE_54")
1273+
if user_potcar_functional.upper() != "PBE_54":
1274+
warnings.warn(f"{user_potcar_functional=} is inconsistent with the recommended PBE_54.", UserWarning)
1275+
12701276
self.kwargs = kwargs
12711277
self.xc_functional = xc_functional
12721278
self.prev_incar = prev_incar or {}
@@ -1276,9 +1282,8 @@ def incar(self) -> Incar:
12761282
"""Incar"""
12771283
incar = super().incar
12781284

1279-
for p in MatPESStaticSet.INHERITED_INCAR_PARAMS:
1280-
if p in self.prev_incar:
1281-
incar[p] = self.prev_incar[p]
1285+
for key in set(self.INHERITED_INCAR_PARAMS) & set(self.prev_incar):
1286+
incar[key] = self.prev_incar[key]
12821287
return incar
12831288

12841289
@classmethod

tests/io/vasp/test_sets.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,13 +837,13 @@ def test_default_u(self):
837837
assert default_u.kpoints is None
838838

839839
def test_functionals(self):
840-
functional = "LDA"
841-
with pytest.raises(ValueError, match=f"{functional} is not supported"):
842-
MatPESStaticSet(self.struct, xc_functional=functional)
843-
with pytest.warns(
844-
UserWarning,
845-
match="inconsistent with the recommended PBE_54",
840+
xc_functional = "LDA"
841+
with pytest.raises(
842+
ValueError, match=f"Unrecognized {xc_functional=}. Supported exchange-correlation functionals are "
846843
):
844+
MatPESStaticSet(self.struct, xc_functional=xc_functional)
845+
846+
with pytest.warns(UserWarning, match="inconsistent with the recommended PBE_54"):
847847
diff_potcar = MatPESStaticSet(self.struct, user_potcar_functional="PBE")
848848
assert str(diff_potcar.potcar[0]) == str(PotcarSingle.from_symbol_and_functional("Fe_pv", "PBE"))
849849

0 commit comments

Comments
 (0)