From 502a734794efca4acca4cc3025a4455d5ed8355b Mon Sep 17 00:00:00 2001 From: "T.Tian" Date: Sun, 14 Jan 2024 16:56:42 +0800 Subject: [PATCH] add hard-coded parser items --- sparc/docparser.py | 19 ++++++++++++++++++- sparc/sparc_parsers/aimd.py | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/sparc/docparser.py b/sparc/docparser.py index ff1e1de8..d8df8c5b 100644 --- a/sparc/docparser.py +++ b/sparc/docparser.py @@ -16,6 +16,15 @@ import numpy as np +# Some fields in master SPARC doc may cause auto type detection +# to fail, need hard-coded post-processing for now +postprocess_items = { + "RELAX_FLAG": {"allow_bool_input": False}, + "NPT_SCALE_CONSTRAINTS": {"type": "string"}, + "NPT_SCALE_VECS": {"type": "integer array"}, + "TOL_POISSON": {"type": "double"}, +} + class SPARCDocParser(object): """Use regex to parse LaTeX doc to python API""" @@ -55,6 +64,7 @@ def __init__( self.params_from_intro = params_from_intro self.parse_version(parse_version) self.parse_parameters() + self.postprocess() def find_main_file(self, main_file_pattern): """Find the matching name for the main-file, e.g. Manual.tex or Manual_cyclix.tex""" @@ -251,6 +261,13 @@ def parse_parameters(self): return + def postprocess(self): + """Use the hardcoded parameter correction dict to fix some issues""" + for param, fix in postprocess_items.items(): + if param in self.parameters: + self.parameters[param].update(**fix) + return + def to_dict(self): """Output a json string from current document parser @@ -264,7 +281,7 @@ def to_dict(self): doc["other_parameters"] = { k: v for k, v in sorted(self.other_parameters.items()) } - doc["data_types"] = list(set([p["type"] for p in self.parameters.values()])) + doc["data_types"] = sorted(set([p["type"] for p in self.parameters.values()])) # json_string = json.dumps(doc, indent=indent) return doc diff --git a/sparc/sparc_parsers/aimd.py b/sparc/sparc_parsers/aimd.py index 78529ca6..d604320f 100644 --- a/sparc/sparc_parsers/aimd.py +++ b/sparc/sparc_parsers/aimd.py @@ -137,7 +137,7 @@ def _read_aimd_step(raw_aimd_text): value = raw_value * GPa elif dim == 2: name = "stress_2d" - value = raw_value * Hartree / Bohr ** 2 + value = raw_value * Hartree / Bohr**2 elif dim == 1: name = "stress_1d" value = raw_value * Hartree / Bohr