Skip to content

Commit c0090e9

Browse files
authored
Merge pull request #121 from benrich37/loose-infile-parsing
Ignorable infile errors
2 parents 32bd35c + 4210f2e commit c0090e9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/pymatgen/io/jdftx/inputs.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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"]):

src/pymatgen/io/jdftx/jdftxoutfileslice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def _set_internal_infile(self, text: list[str]) -> None:
428428
if end_line_idx is None:
429429
raise ValueError("Calculation did not begin for this out file slice.")
430430
self.infile = JDFTXInfile.from_str(
431-
"\n".join(text[start_line_idx:end_line_idx]), validate_value_boundaries=False
431+
"\n".join(text[start_line_idx:end_line_idx]), validate_value_boundaries=False, skip_invalid_tags=True
432432
)
433433
self.constant_lattice = True
434434
if "lattice-minimize" in self.infile:

0 commit comments

Comments
 (0)