diff --git a/src/pymatgen/io/vasp/outputs.py b/src/pymatgen/io/vasp/outputs.py index 2df543c879a..7439c1a2bf7 100644 --- a/src/pymatgen/io/vasp/outputs.py +++ b/src/pymatgen/io/vasp/outputs.py @@ -5807,7 +5807,10 @@ def reset(self): changed. """ # Note that py3.12 has Path.walk(). But we need to use os.walk to ensure backwards compatibility for now. - self.files = [str(Path(d) / f).lstrip(str(self.path)) for d, _, fnames in os.walk(self.path) for f in fnames] + self.files = [ + str(Path(d) / f)[len(str(self.path)) + 1 :] for d, _, fnames in os.walk(self.path) for f in fnames + ] + self._parsed_files: dict[str, Any] = {} def __contains__(self, item): @@ -5851,3 +5854,6 @@ def get_files_by_name(self, name: str) -> dict[str, Any]: {filename: object from VaspDir[filename]} """ return {f: self[f] for f in self.files if name in f} + + def __repr__(self): + return f"VaspDir({self.path})" diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index 84f8521fa6b..5e26bda532e 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -2194,6 +2194,8 @@ def test_getitem(self): d = VaspDir(f"{TEST_FILES_DIR}/io/vasp/fixtures/scan_relaxation") assert len(d) == 2 + assert "vasprun.xml.gz" in d.files + assert "OUTCAR" in d assert d["vasprun.xml.gz"].incar["METAGGA"] == "R2scan" with pytest.raises(ValueError, match="hello not found"):