Skip to content

Commit e4792d1

Browse files
author
Shyue Ping Ong
committed
Fix POTCAR functional handling and tests.
1 parent c845074 commit e4792d1

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

pymatgen/io/vasp/sets.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,15 +1249,15 @@ def __init__(
12491249
self,
12501250
structure: Structure,
12511251
xc_functional: Literal["R2SCAN", "PBE", "PBE+U"] = "PBE",
1252-
potcar_functional="PBE_54",
1252+
user_potcar_functional="PBE_54",
12531253
prev_incar=None,
12541254
**kwargs: Any,
12551255
):
12561256
"""
12571257
Args:
12581258
structure (Structure): Structure for static calculation.
12591259
xc_functional ('R2SCAN'|'PBE'): Exchange-correlation functional to use. Defaults to 'PBE'.
1260-
potcar_functional: Choice of VASP POTCAR functional and version. Defaults to 'PBE_54'.
1260+
user_potcar_functional: Choice of VASP POTCAR functional and version. Defaults to 'PBE_54'.
12611261
prev_incar (Incar|str): Incar file from previous run. Default settings of MatPESStaticSet
12621262
are prioritized over inputs from previous runs.
12631263
**kwargs: Passed to DictSet.
@@ -1275,9 +1275,10 @@ def __init__(
12751275
f"{xc_functional} is not supported."
12761276
" The supported exchange-correlation functionals are PBE, PBE+U and R2SCAN."
12771277
)
1278-
if potcar_functional.upper() != "PBE_54":
1279-
raise UserWarning(f"POTCAR version ({potcar_functional}) is inconsistent with the default of PBE_54.")
1280-
self.potcar.functional = potcar_functional.upper()
1278+
if user_potcar_functional.upper() != "PBE_54":
1279+
raise UserWarning(f"POTCAR version ({user_potcar_functional}) is inconsistent with the recommended PBE_54.")
1280+
1281+
self.user_potcar_functional = user_potcar_functional.upper()
12811282

12821283
self.kwargs = kwargs
12831284
self.xc_functional = xc_functional

tests/io/vasp/test_sets.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from pymatgen.core import SETTINGS, Lattice, Species, Structure
2020
from pymatgen.core.surface import SlabGenerator
2121
from pymatgen.core.units import FloatWithUnit
22-
from pymatgen.io.vasp.inputs import Incar, Kpoints, Poscar
22+
from pymatgen.io.vasp.inputs import Incar, Kpoints, Poscar, PotcarSingle
2323
from pymatgen.io.vasp.outputs import Vasprun
2424
from pymatgen.io.vasp.sets import (
2525
BadInputSetWarning,
@@ -766,6 +766,8 @@ def test_default(self):
766766
assert default.potcar.functional == "PBE_54"
767767
assert default.kpoints is None
768768

769+
assert str(default.potcar[0]) == str(PotcarSingle.from_symbol_and_functional("Fe_pv", "PBE_54"))
770+
769771
def test_with_prev_incar(self):
770772
default_prev = MatPESStaticSet(structure=self.struct, prev_incar=self.prev_incar)
771773
incar = default_prev.incar
@@ -838,11 +840,12 @@ def test_functionals(self):
838840
functional = "LDA"
839841
with pytest.raises(ValueError, match=f"{functional} is not supported"):
840842
MatPESStaticSet(self.struct, xc_functional=functional)
841-
with pytest.raises(
843+
with pytest.warns(
842844
UserWarning,
843-
match="inconsistent with the default of PBE_54",
845+
match="inconsistent with the recommended PBE_54",
844846
):
845-
MatPESStaticSet(self.struct, potcar_functional=functional)
847+
diff_potcar = MatPESStaticSet(self.struct, user_potcar_functional="PBE")
848+
assert str(diff_potcar.potcar[0]) == str(PotcarSingle.from_symbol_and_functional("Fe_pv", "PBE"))
846849

847850

848851
class TestMPNonSCFSet(PymatgenTest):

0 commit comments

Comments
 (0)