diff --git a/src/pymatgen/io/vasp/inputs.py b/src/pymatgen/io/vasp/inputs.py index d8deb7da7e7..e153cd0b1a2 100644 --- a/src/pymatgen/io/vasp/inputs.py +++ b/src/pymatgen/io/vasp/inputs.py @@ -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= 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.") diff --git a/tests/io/vasp/test_inputs.py b/tests/io/vasp/test_inputs.py index b56cab1d3e6..cf4f6ea7940 100644 --- a/tests/io/vasp/test_inputs.py +++ b/tests/io/vasp/test_inputs.py @@ -28,6 +28,7 @@ Incar, Kpoints, KpointsSupportedModes, + PmgVaspPspDirError, Poscar, Potcar, PotcarSingle, @@ -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= 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."), ):