@@ -180,6 +180,7 @@ def from_dict(cls, d: dict[str, Any], validate_value_boundaries=True) -> JDFTXIn
180180 instance .validate_boundaries ()
181181 return instance
182182
183+ # TODO: This can be cleaned up by generalizing kwargs that are passed to from_str
183184 @classmethod
184185 def from_file (
185186 cls ,
@@ -309,6 +310,7 @@ def from_str(
309310 sort_tags : bool = True ,
310311 path_parent : Path | None = None ,
311312 validate_value_boundaries : bool = True ,
313+ skip_invalid_tags : bool = False ,
312314 ) -> JDFTXInfile :
313315 """Read a JDFTXInfile object from a string.
314316
@@ -329,9 +331,17 @@ def from_str(
329331 params : dict [str , Any ] = {}
330332 # process all tag value lines using specified tag formats in MASTER_TAG_LIST
331333 for line in lines :
332- tag_object , tag , value = cls ._preprocess_line (line )
333- processed_value = tag_object .read (tag , value )
334- params = cls ._store_value (params , tag_object , tag , processed_value ) # this will change with tag categories
334+ try :
335+ tag_object , tag , value = cls ._preprocess_line (line )
336+ processed_value = tag_object .read (tag , value )
337+ params = cls ._store_value (
338+ params , tag_object , tag , processed_value
339+ ) # this will change with tag categories
340+ except ValueError as e :
341+ if skip_invalid_tags :
342+ warnings .warn (f"Skipping invalid tag line: '{ line } '. Error: { e } " , stacklevel = 2 )
343+ continue
344+ raise
335345 pop_idcs = []
336346 if "include" in params :
337347 for i , filename in enumerate (params ["include" ]):
0 commit comments