Skip to content

Commit

Permalink
Support for nested folders (e.g., NEB runs) in VaspDir class.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Oct 23, 2024
1 parent 3ee17e2 commit 6025d44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5765,6 +5765,7 @@ class VaspDir(collections.abc.Mapping):
"POSCAR": Poscar,
"CONTCAR": Poscar,
"KPOINTS": Kpoints,
"IBZKPT": Kpoints,
"POTCAR": Potcar,
"vasprun": Vasprun,
"OUTCAR": Outcar,
Expand All @@ -5786,16 +5787,16 @@ def __init__(self, dirname: str | Path):
Args:
dirname: The directory containing the VASP calculation as a string or Path.
"""
self.path = Path(dirname)
self.files = [f.name for f in self.path.iterdir() if f.is_file()]
self.path = Path(dirname).absolute()
self.files = [Path(d) / f for d, subd, fnames in os.walk(self.path) for f in fnames]
self._parsed_files: dict[str, Any] = {}

def reset(self):
"""
Reset all loaded files and recheck the directory for files. Use this when the contents of the directory has
changed.
"""
self.files = [f for f in self.path.iterdir() if f.is_file()]
self.files = [Path(d) / f for d, subd, fnames in os.walk(self.path) for f in fnames]
self._parsed_files = {}

def __len__(self):
Expand Down
12 changes: 9 additions & 3 deletions tests/io/vasp/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,12 @@ def test_getitem(self):
with pytest.raises(ValueError, match="hello not found"):
d["hello"]

d = VaspDir(f"{TEST_FILES_DIR}/io/vasp/outputs")
with pytest.warns(UserWarning, match=r"No parser defined for IBZKPT.*"):
assert isinstance(d["IBZKPT.lobster"], str)
d = VaspDir(f"{TEST_FILES_DIR}/io/pwscf")
with pytest.warns(UserWarning, match=r"No parser defined for Si.pwscf.out"):
assert isinstance(d["Si.pwscf.out"], str)

# Test NEB directories.
d = VaspDir(f"{TEST_FILES_DIR}/io/vasp/fixtures/neb_analysis/neb1/neb")
assert len(d) == 10

assert isinstance(d["00/POSCAR"], Poscar)

0 comments on commit 6025d44

Please sign in to comment.