scalainterface.py 1.68 KB
Newer Older
1
2
3
4
5
"""
This is the access point to the parser for the scala layer in the nomad project.
"""
import os
from cp2kparser import CP2KParser
6
from cp2kparser.parsing.versions.cp2k262.outputparser import CP2KOutputParser
7
8
9
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.simple_parser import mainFunction

Lauri Himanen's avatar
Lauri Himanen committed
10
# This is what should be called by the scala layer to run the parser. Currently
11
12
13
14
# only the outputparser is used because the scala layer doesn't support
# auxiliary files. Also the version identification is skipped and the structure
# used in CP2K 2.6.2 is assumed.
if __name__ == "__main__":
15

16
17
18
    cp2kparser = CP2KParser()

    # Get the outputparser class
19
    outputparser = CP2KOutputParser(None, None)
20
21

    # Setup the metainfos
Lauri Himanen's avatar
Lauri Himanen committed
22
    metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../../nomad-meta-info/meta_info/nomad_meta_info/{}".format(cp2kparser.get_metainfo_filename())))
23
24
25
26
27
28
    metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath, dependencyLoader=None, extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS, uri=None)

    # Parser info
    parserInfo = {'name': 'cp2k-parser', 'version': '1.0'}

    # Adjust caching of metadata
29
    cachingLevelForMetaName = outputparser.caching_level_for_metaname
30
31
32
33
34
35

    # Supercontext is where the objet where the callback functions for
    # section closing are found
    superContext = outputparser

    # Main file description is the SimpleParser tree
36
    mainFileDescription = outputparser.root_matcher
37
38
39

    # Use the main function from nomadcore
    mainFunction(mainFileDescription, metaInfoEnv, parserInfo, superContext=superContext, cachingLevelForMetaName=cachingLevelForMetaName, onClose={})