Skip to content

Commit

Permalink
Merge branch 'master' into fix-MatPESStaticSet
Browse files Browse the repository at this point in the history
Signed-off-by: Janosh Riebesell <janosh.riebesell@gmail.com>
  • Loading branch information
janosh authored Sep 1, 2023
2 parents ea420a4 + 6ca0390 commit 30e15be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
32 changes: 22 additions & 10 deletions pymatgen/io/vasp/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,15 +1226,13 @@ def __init__(
self,
structure: Structure,
xc_functional: Literal["R2SCAN", "PBE", "PBE+U"] = "PBE",
user_potcar_functional: Literal["PBE_54", "PBE_52"] = "PBE_54",
prev_incar: Incar | dict | None = None,
**kwargs: Any,
) -> None:
"""
Args:
structure (Structure): Structure for static calculation.
xc_functional ('R2SCAN'|'PBE'): Exchange-correlation functional to use. Defaults to 'PBE'.
potcar_functional: Choice of VASP POTCAR functional and version. Defaults to 'PBE_54'.
prev_incar (Incar | dict): Incar file from previous run. Default settings of MatPESStaticSet
are prioritized over inputs from previous runs. Defaults to None.
**kwargs: Passed to DictSet.
Expand All @@ -1248,18 +1246,16 @@ def __init__(
super().__init__(structure, MatPESStaticSet.CONFIG, **kwargs)

if xc_functional.upper() == "R2SCAN":
self.user_incar_settings["METAGGA"] = "R2SCAN"
self.user_incar_settings.setdefault("ALGO", "ALL") # leave user-defined ALGO if set
self.user_incar_settings.pop("GGA", None)
self._config_dict["INCAR"]["METAGGA"] = "R2SCAN"
self._config_dict["INCAR"].setdefault("ALGO", "ALL") # leave user-defined ALGO if set
self._config_dict["INCAR"].pop("GGA", None)
if xc_functional.upper().endswith("+U"):
self.user_incar_settings["LDAU"] = True
if user_potcar_functional.upper() != "PBE_54":
self._config_dict["INCAR"]["LDAU"] = True
if kwargs.get("user_potcar_functional", "PBE_54").upper() != "PBE_54":
warnings.warn(
f"POTCAR version ({user_potcar_functional}) is inconsistent with the recommended PBE_54.", UserWarning
f"POTCAR ({kwargs['user_potcar_functional']}) is inconsistent with the recommended PBE_54.", UserWarning
)

self.user_potcar_functional = user_potcar_functional

self.kwargs = kwargs
self.xc_functional = xc_functional
self.prev_incar = prev_incar or {}
Expand All @@ -1273,6 +1269,22 @@ def incar(self) -> Incar:
incar[key] = self.prev_incar[key]
return incar

@classmethod
def from_prev_calc(cls, prev_calc_dir, **kwargs):
"""
Generate a set of VASP input files for static calculations from a directory of previous VASP run.
Args:
prev_calc_dir (str): Directory containing the outputs(
vasprun.xml and OUTCAR) of previous vasp run.
**kwargs: All kwargs supported by MatPESStaticSet, other than prev_incar
and prev_structure and prev_kpoints which are determined from
the prev_calc_dir.
"""
vrun = sorted(f for f in os.listdir(prev_calc_dir) if f.startswith("vasprun.xml"))[-1]
v = Vasprun(os.path.join(prev_calc_dir, vrun))
return cls(v.final_structure, prev_incar=v.incar, **kwargs)


class MPScanStaticSet(MPScanRelaxSet):
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/io/vasp/test_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,14 @@ def test_functionals(self):
diff_potcar = MatPESStaticSet(self.struct, user_potcar_functional="PBE")
assert str(diff_potcar.potcar[0]) == str(PotcarSingle.from_symbol_and_functional("Fe_pv", "PBE"))

def test_from_prev_calc(self):
vis = MatPESStaticSet.from_prev_calc(f"{TEST_FILES_DIR}/relaxation")
incar = vis.incar
assert incar["GGA"] == "Pe"
assert incar["ALGO"] == "Normal"
assert vis.potcar_symbols == ["Li_sv"]
assert vis.kpoints is None


class TestMPNonSCFSet(PymatgenTest):
def setUp(self):
Expand Down

0 comments on commit 30e15be

Please sign in to comment.