Skip to content

Commit

Permalink
add hard-coded parser items
Browse files Browse the repository at this point in the history
  • Loading branch information
alchem0x2A committed Jan 14, 2024
1 parent d747e95 commit 502a734
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion sparc/docparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sparc/sparc_parsers/aimd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 502a734

Please sign in to comment.