singlepointparser.py 2.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.baseclasses import MainHierarchicalParser
from singlepointforceparser import CP2KSinglePointForceParser
from commonmatcher import CommonMatcher
import logging
logger = logging.getLogger("nomad")


#===============================================================================
class CP2KSinglePointParser(MainHierarchicalParser):
    """The main parser class. Used to parse the CP2K calculation with run types:
        -ENERGY
        -ENERGY_FORCE
    """
    def __init__(self, file_path, parser_context):
        """
        """
        super(CP2KSinglePointParser, self).__init__(file_path, parser_context)
19
        self.setup_common_matcher(CommonMatcher(parser_context))
20

21
22
        #=======================================================================
        # SimpleMatchers
23
24
        self.root_matcher = SM("",
            forwardMatch=True,
25
            sections=['section_run', "section_single_configuration_calculation", "section_system", "section_method"],
26
            otherMetaInfo=["atom_forces"],
27
28
            subMatchers=[
                self.cm.header(),
29
30
                self.cm.quickstep(),
                self.cm.scf()
31
32
33
34
            ]
        )

    #===========================================================================
35
    # onClose triggers
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    def onClose_section_single_configuration_calculation(self, backend, gIndex, section):
        """
        """
        # If the force file for a single point calculation is available, and
        # the forces were not parsed fro the output file, parse the separate
        # file
        if section["atom_forces"] is None:
            force_file = self.file_service.get_file_by_id("force_file_single_point")
            if force_file is not None:
                force_parser = CP2KSinglePointForceParser(force_file, self.parser_context)
                force_parser.parse()
            else:
                logger.warning("The file containing the forces printed by ENERGY_FORCE calculation could not be found.")

50
51
52
53
54
55
        # Only in the single configuration calculations the number of scf
        # iterations is given. E.g. in geometry optimization there are multiple
        # scf calculations so this loses it's meaning sort of.
        self.cache_service.push_value("number_of_scf_iterations")
        self.cache_service["number_of_scf_iterations"] = 0

56
    #===========================================================================
57
    # adHoc functions