File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -5672,15 +5672,20 @@ def __iter__(self):
5672
5672
def __getitem__ (self , item ):
5673
5673
if item in self ._parsed_files :
5674
5674
return self ._parsed_files [item ]
5675
+ fpath = self .path / item
5676
+
5677
+ if not (self .path / item ).exists ():
5678
+ raise ValueError (f"{ item } not found in { self .path } . List of files are { self .files } ." )
5679
+
5675
5680
for k , cls_ in VaspDir .FILE_MAPPINGS .items ():
5676
5681
if k in item :
5677
5682
try :
5678
- self ._parsed_files [item ] = cls_ .from_file (self . path / item )
5683
+ self ._parsed_files [item ] = cls_ .from_file (fpath )
5679
5684
except AttributeError :
5680
- self ._parsed_files [item ] = cls_ (self . path / item )
5685
+ self ._parsed_files [item ] = cls_ (fpath )
5681
5686
5682
5687
return self ._parsed_files [item ]
5683
- if (self .path / item ).exists ():
5684
- raise RuntimeError (f"Unable to parse { item } . Supported files are { list (VaspDir .FILE_MAPPINGS .keys ())} ." )
5685
5688
5686
- raise ValueError (f"{ item } not found in { self .path } . List of files are { self .files } ." )
5689
+ warnings .warn (f"No parser defined for { item } . Full text of file is returned as a string." , UserWarning )
5690
+ with zopen (fpath , "rt" ) as f :
5691
+ return f .read ()
Original file line number Diff line number Diff line change @@ -2110,12 +2110,14 @@ def test_getitem(self):
2110
2110
d = VaspDir (f"{ TEST_FILES_DIR } /io/vasp/fixtures/relaxation" )
2111
2111
assert len (d ) == 5
2112
2112
assert d ["OUTCAR" ].run_stats ["cores" ] == 8
2113
- d = VaspDir (f"{ TEST_FILES_DIR } /io/vasp/outputs" )
2114
- with pytest .raises (RuntimeError , match = r"Unable to parse IBZKPT.*" ):
2115
- d ["IBZKPT.lobster" ]
2113
+
2116
2114
d = VaspDir (f"{ TEST_FILES_DIR } /io/vasp/fixtures/scan_relaxation" )
2117
2115
assert len (d ) == 2
2118
2116
assert d ["vasprun.xml.gz" ].incar ["METAGGA" ] == "R2scan"
2119
2117
2120
2118
with pytest .raises (ValueError , match = "hello not found" ):
2121
2119
d ["hello" ]
2120
+
2121
+ d = VaspDir (f"{ TEST_FILES_DIR } /io/vasp/outputs" )
2122
+ with pytest .warns (UserWarning , match = r"No parser defined for IBZKPT.*" ):
2123
+ assert isinstance (d ["IBZKPT.lobster" ], str )
You can’t perform that action at this time.
0 commit comments