Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: add the cp2k-output-tools parser #133

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
dev-zero marked this conversation as resolved.
Show resolved Hide resolved
],
"pre-commit":[
"pre-commit==1.18.3",
Expand Down