scalainterface.py 1.62 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
This is the access point to the parser for the scala layer in the nomad project.
"""
import os
from cp2kparser import CP2KParser
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.simple_parser import mainFunction

# This is what gets run when the scala layer calls for this parser. Currently
# 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__":
    cp2kparser = CP2KParser()

    # Get the outputparser class
    outputparser = globals()["CP2KOutputParser{}".format("262")](None, None)

    # Setup the metainfos
    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())))
    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
    cachingLevelForMetaName = outputparser.cachingLevelForMetaName

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

    # Main file description is the SimpleParser tree
    mainFileDescription = outputparser.outputstructure

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