Commit 6e59c52e authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Parsed bit of SCF information.

parent 8d5e7384
"""
When this package is run on a folder with python -m cp2kparser, the current
directory is searched for calculation data and the contents are parsed.
"""
import os
from cp2kparser.implementation.autoparser import parse_path
import argparse
import json
parser = argparse.ArgumentParser(description='Parse a CP2K calculation from folder.')
parser.add_argument('--metaInfoToKeep', type=str, help='A json list containing the names of the metainfos to keep during parsing.')
parser.add_argument('-dump', action='store_true')
args = parser.parse_args()
# Try to decode the metaInfoTokeep
metaInfoToKeep = []
if args.metaInfoToKeep:
try:
metaInfoToKeep = json.loads(args.metaInfoToKeep)
except:
raise Exception("Could not decode the 'metaInfoToKeep' argument as a json list. You might need to surround the string with single quotes if it contains double quotes.")
dump = args.dump
path = os.getcwd()
parse_path(path, metaInfoToKeep, dump)
...@@ -10,12 +10,12 @@ class CP2KOutputParser(FileParser): ...@@ -10,12 +10,12 @@ class CP2KOutputParser(FileParser):
"""The object that goes through the CP2K output file and parses everything """The object that goes through the CP2K output file and parses everything
it can using the SimpleParser architecture. it can using the SimpleParser architecture.
""" """
def __init__(self, files, parser_context): def __init__(self, files, parser_context):
"""Initialize an output parser. """Initialize an output parser.
""" """
FileParser.__init__(self, files, parser_context) FileParser.__init__(self, files, parser_context)
self.f_regex = "-?\d+\.\d+(?:E+|-\d+)?" # Regex for a floating point value self.f_regex = "-?\d+\.\d+(?:E(?:\+|-)\d+)?" # Regex for a floating point value
self.i_regex = "-?\d+" # Regex for an integer
# Define the output parsing tree for this version # Define the output parsing tree for this version
self.root_matcher = SM( self.root_matcher = SM(
...@@ -80,10 +80,21 @@ class CP2KOutputParser(FileParser): ...@@ -80,10 +80,21 @@ class CP2KOutputParser(FileParser):
] ]
), ),
SM( SM(
# sections=["cp2k_section_quickstep_atom_information"],
startReStr=" MODULE QUICKSTEP: ATOMIC COORDINATES IN angstrom", startReStr=" MODULE QUICKSTEP: ATOMIC COORDINATES IN angstrom",
adHoc=self.adHoc_cp2k_section_quickstep_atom_information(), adHoc=self.adHoc_cp2k_section_quickstep_atom_information(),
), ),
# SCF
SM(
sections=["section_single_configuration_calculation"],
startReStr=" SCF WAVEFUNCTION OPTIMIZATION",
subMatchers=[
SM(
sections=["section_scf_iteration"],
startReStr=r"\s+\d+\s+\S+\s+{f}\s+{f}\s+{f}\s+(?P<energy_total_scf_iteration>{f})\s+{f}".format(f=self.f_regex),
repeats=True,
),
]
),
SM( SM(
sections=["cp2k_section_md"], sections=["cp2k_section_md"],
startReStr=" MD| Molecular Dynamics Protocol", startReStr=" MD| Molecular Dynamics Protocol",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment