Skip to content

Commit

Permalink
Parser: add the cp2k-output-tools parser (aiidateam#133).
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-zero authored and Holger-Dietrich Saßnick committed Apr 26, 2021
1 parent beeb59d commit b846f47
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
46 changes: 45 additions & 1 deletion aiida_cp2k/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _parse_stdout(self):

fname = self.node.process_class._DEFAULT_OUTPUT_FILE # pylint: disable=protected-access
if fname not in self.retrieved.list_object_names():
raise OutputParsingError("Cp2k output file not retrieved")
raise OutputParsingError("CP2K output file not retrieved.")

try:
output_string = self.retrieved.get_object_content(fname)
Expand Down Expand Up @@ -151,3 +151,47 @@ def _parse_stdout(self):

self.out("output_parameters", Dict(dict=result_dict))
return None


class Cp2kToolsParser(Cp2kBaseParser):
"""AiiDA parser class for the output of CP2K based on the cp2k-output-tools project."""

def _parse_stdout(self):
"""Very advanced CP2K output file parser."""

from cp2k_output_tools import parse_iter

fname = self.node.process_class._DEFAULT_OUTPUT_FILE # pylint: disable=protected-access
if fname not in self.retrieved.list_object_names():
raise OutputParsingError("CP2K output file not retrieved.")

try:
output_string = self.retrieved.get_object_content(fname)
except IOError:
return self.exit_codes.ERROR_OUTPUT_STDOUT_READ

result_dict = {}

# the CP2K output parser is a block-based parser return blocks of data, each under a block key
# merge them into one dict
for match in parse_iter(output_string, key_mangling=True):
result_dict.update(match)

# nwarnings is the last thing to be printed in the CP2K output file:
# if it is not there, CP2K didn't finish properly most likely
if 'nwarnings' not in result_dict:
raise OutputParsingError("CP2K did not finish properly")

if "aborted" in result_dict:
return self.exit_codes.ERROR_OUTPUT_CONTAINS_ABORT

try:
# the cp2k-output-tools parser is more hierarchical, be compatible with
# the basic parser here and provide the total force eval energy as energy
result_dict["energy"] = result_dict["energies"]["total_force_eval"]
result_dict["energy_units"] = "a.u."
except KeyError:
pass

self.out("output_parameters", Dict(dict=result_dict))
return None
6 changes: 4 additions & 2 deletions setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
],
"aiida.parsers": [
"cp2k_base_parser = aiida_cp2k.parsers:Cp2kBaseParser",
"cp2k_advanced_parser = aiida_cp2k.parsers:Cp2kAdvancedParser"
"cp2k_advanced_parser = aiida_cp2k.parsers:Cp2kAdvancedParser",
"cp2k_tools_parser = aiida_cp2k.parsers:Cp2kToolsParser"
],
"aiida.workflows": [
"cp2k.base = aiida_cp2k.workchains:Cp2kBaseWorkChain"
Expand All @@ -33,7 +34,8 @@
"pytest>=4.4,<5.0.0",
"pytest-cov>=2.6.1,<3.0.0",
"coverage",
"aiida-gaussian-datatypes"
"aiida-gaussian-datatypes",
"cp2k-output-tools"
],
"pre-commit":[
"pre-commit==1.18.3",
Expand Down

0 comments on commit b846f47

Please sign in to comment.