Skip to content

Commit e1e1a70

Browse files
esoteric-ephemerajanosh
authored andcommitted
add incar, kpoints, poscar, potcar attr to io.vasp.inputs.VaspInput + tests
1 parent d599611 commit e1e1a70

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

pymatgen/io/vasp/inputs.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,8 +2759,8 @@ def __init__(
27592759
**kwargs: Additional keyword arguments to be stored in the VaspInput object.
27602760
"""
27612761
super().__init__(**kwargs)
2762-
potcar_filename = "POTCAR" + (".spec" if potcar_spec else "")
2763-
self.update({"INCAR": incar, "KPOINTS": kpoints, "POSCAR": poscar, potcar_filename: potcar})
2762+
self._potcar_filename = "POTCAR" + (".spec" if potcar_spec else "")
2763+
self.update({"INCAR": incar, "KPOINTS": kpoints, "POSCAR": poscar, self._potcar_filename: potcar})
27642764
if optional_files is not None:
27652765
self.update(optional_files)
27662766

@@ -2889,3 +2889,23 @@ def run_vasp(
28892889
open(err_file, mode="w", encoding="utf-8", buffering=1) as stderr_file,
28902890
):
28912891
subprocess.check_call(vasp_cmd, stdout=stdout_file, stderr=stderr_file)
2892+
2893+
@property
2894+
def incar(self) -> Incar:
2895+
""" INCAR object. """
2896+
return Incar(self["INCAR"]) if isinstance(self["INCAR"],dict) else self["INCAR"]
2897+
2898+
@property
2899+
def kpoints(self) -> Kpoints | None:
2900+
""" KPOINTS object. """
2901+
return self["KPOINTS"]
2902+
2903+
@property
2904+
def poscar(self) -> Poscar:
2905+
""" POSCAR object. """
2906+
return self["POSCAR"]
2907+
2908+
@property
2909+
def potcar(self) -> Potcar | str | None:
2910+
""" POTCAR or POTCAR.spec object. """
2911+
return self[self._potcar_filename]

tests/io/vasp/test_inputs.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,24 @@ def test_from_directory(self):
13641364
vasp_input = VaspInput.from_dict(vi.as_dict())
13651365
assert "CONTCAR_Li2O" in vasp_input
13661366

1367+
def test_input_attr(self):
1368+
assert all(
1369+
v == getattr(self.vasp_input, k.lower()) for k, v in self.vasp_input.items()
1370+
)
1371+
1372+
vis_potcar_spec = VaspInput(
1373+
self.vasp_input.incar,
1374+
self.vasp_input.kpoints,
1375+
self.vasp_input.poscar,
1376+
"\n".join(self.vasp_input.potcar.symbols),
1377+
potcar_spec = True
1378+
)
1379+
assert all(k in vis_potcar_spec for k in ("INCAR","KPOINTS","POSCAR","POTCAR.spec"))
1380+
assert all(
1381+
self.vasp_input[k] == getattr(vis_potcar_spec, k.lower())
1382+
for k in ("INCAR","KPOINTS","POSCAR")
1383+
)
1384+
assert isinstance(vis_potcar_spec.potcar, str)
13671385

13681386
def test_potcar_summary_stats() -> None:
13691387
potcar_summary_stats = loadfn(POTCAR_STATS_PATH)

tests/io/vasp/test_sets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ def test_get_nedos(self):
671671
vis.prev_vasprun = vrun
672672
assert vis._get_nedos(0.1) == pytest.approx(741, abs=1)
673673

674-
675674
class TestMPStaticSet(PymatgenTest):
676675
def setUp(self):
677676
self.set = MPStaticSet

0 commit comments

Comments
 (0)