Skip to content

Commit ebfc7a0

Browse files
committed
improve and test PmgVaspPspDirError msg in PotcarSingle.from_symbol_and_functional
1 parent 60464fd commit ebfc7a0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/pymatgen/io/vasp/inputs.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2277,9 +2277,7 @@ def from_symbol_and_functional(
22772277
functional_subdir = SETTINGS.get("PMG_VASP_PSP_SUB_DIRS", {}).get(functional, cls.functional_dir[functional])
22782278
PMG_VASP_PSP_DIR = SETTINGS.get("PMG_VASP_PSP_DIR")
22792279
if PMG_VASP_PSP_DIR is None:
2280-
raise PmgVaspPspDirError(
2281-
f"No POTCAR for {symbol} with {functional=} found. Please set the PMG_VASP_PSP_DIR in .pmgrc.yaml."
2282-
)
2280+
raise PmgVaspPspDirError("Set PMG_VASP_PSP_DIR=<directory-path> in .pmgrc.yaml (needed to find POTCARs)")
22832281
if not os.path.isdir(PMG_VASP_PSP_DIR):
22842282
raise FileNotFoundError(f"{PMG_VASP_PSP_DIR=} does not exist.")
22852283

tests/io/vasp/test_inputs.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Incar,
2929
Kpoints,
3030
KpointsSupportedModes,
31+
PmgVaspPspDirError,
3132
Poscar,
3233
Potcar,
3334
PotcarSingle,
@@ -1211,7 +1212,16 @@ def test_from_symbol_and_functional_raises(self):
12111212
# test FileNotFoundError on non-existent PMG_VASP_PSP_DIR in SETTINGS
12121213
PMG_VASP_PSP_DIR = "missing-dir"
12131214
symbol, functional = "Fe", "PBE_64"
1214-
with (
1215+
with ( # test PMG_VASP_PSP_DIR not set in SETTINGS
1216+
patch.dict(SETTINGS, PMG_VASP_PSP_DIR=None),
1217+
pytest.raises(
1218+
PmgVaspPspDirError,
1219+
match=re.escape("Set PMG_VASP_PSP_DIR=<directory-path> in .pmgrc.yaml (needed to find POTCARs)"),
1220+
),
1221+
):
1222+
PotcarSingle.from_symbol_and_functional(symbol, functional)
1223+
1224+
with ( # test FileNotFoundError on non-existent PMG_VASP_PSP_DIR in SETTINGS
12151225
patch.dict(SETTINGS, PMG_VASP_PSP_DIR=PMG_VASP_PSP_DIR),
12161226
pytest.raises(FileNotFoundError, match=f"{PMG_VASP_PSP_DIR=} does not exist."),
12171227
):

0 commit comments

Comments
 (0)