Skip to content

Commit

Permalink
improve and test PmgVaspPspDirError msg in PotcarSingle.from_symbol_a…
Browse files Browse the repository at this point in the history
…nd_functional
  • Loading branch information
janosh committed Sep 15, 2024
1 parent 60464fd commit ebfc7a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2277,9 +2277,7 @@ def from_symbol_and_functional(
functional_subdir = SETTINGS.get("PMG_VASP_PSP_SUB_DIRS", {}).get(functional, cls.functional_dir[functional])
PMG_VASP_PSP_DIR = SETTINGS.get("PMG_VASP_PSP_DIR")
if PMG_VASP_PSP_DIR is None:
raise PmgVaspPspDirError(
f"No POTCAR for {symbol} with {functional=} found. Please set the PMG_VASP_PSP_DIR in .pmgrc.yaml."
)
raise PmgVaspPspDirError("Set PMG_VASP_PSP_DIR=<directory-path> in .pmgrc.yaml (needed to find POTCARs)")
if not os.path.isdir(PMG_VASP_PSP_DIR):
raise FileNotFoundError(f"{PMG_VASP_PSP_DIR=} does not exist.")

Expand Down
12 changes: 11 additions & 1 deletion tests/io/vasp/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Incar,
Kpoints,
KpointsSupportedModes,
PmgVaspPspDirError,
Poscar,
Potcar,
PotcarSingle,
Expand Down Expand Up @@ -1211,7 +1212,16 @@ def test_from_symbol_and_functional_raises(self):
# test FileNotFoundError on non-existent PMG_VASP_PSP_DIR in SETTINGS
PMG_VASP_PSP_DIR = "missing-dir"
symbol, functional = "Fe", "PBE_64"
with (
with ( # test PMG_VASP_PSP_DIR not set in SETTINGS
patch.dict(SETTINGS, PMG_VASP_PSP_DIR=None),
pytest.raises(
PmgVaspPspDirError,
match=re.escape("Set PMG_VASP_PSP_DIR=<directory-path> in .pmgrc.yaml (needed to find POTCARs)"),
),
):
PotcarSingle.from_symbol_and_functional(symbol, functional)

with ( # test FileNotFoundError on non-existent PMG_VASP_PSP_DIR in SETTINGS
patch.dict(SETTINGS, PMG_VASP_PSP_DIR=PMG_VASP_PSP_DIR),
pytest.raises(FileNotFoundError, match=f"{PMG_VASP_PSP_DIR=} does not exist."),
):
Expand Down

0 comments on commit ebfc7a0

Please sign in to comment.