wien2k_parser_in0.py 5.49 KB
Newer Older
1
2
3
4
5
from builtins import object
import setup_paths
from nomadcore.simple_parser import mainFunction, CachingLevel
from nomadcore.simple_parser import SimpleMatcher as SM
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
Daria Tomecka's avatar
Daria Tomecka committed
6
import os, sys, json, logging
7

Daria Tomecka's avatar
Daria Tomecka committed
8
9
10
11
12
13


################################################################
# This is the subparser for the WIEN2k input file (.in0)
################################################################

Daria M. Tomecka's avatar
Daria M. Tomecka committed
14
# Copyright 2016-2018 Daria M. Tomecka, Fawzi Mohamed
Daria M. Tomecka's avatar
Daria M. Tomecka committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__author__ = "Daria M. Tomecka"
__maintainer__ = "Daria M. Tomecka"
__email__ = "tomeckadm@gmail.com;"
__date__ = "15/05/2017"
Daria Tomecka's avatar
Daria Tomecka committed
32

33
class Wien2kIn0Context(object):
34
    """context for wien2k In0 parser"""
35
36
37
38
39
40
41
42
43
44
45
46
47
48

    def __init__(self):
        self.parser = None

    def initialize_values(self):
        """allows to reset values if the same superContext is used to parse different files"""
        pass

    def startedParsing(self, path, parser):
        """called when parsing starts"""
        self.parser = parser
        # allows to reset values if the same superContext is used to parse different files
        self.initialize_values()

49
    def onClose_x_wien2k_section_xc(self, backend, gIndex, section):
50
        xc_index = section["x_wien2k_indxc"]   #[0]
Daria Tomecka's avatar
Daria Tomecka committed
51
        #logging.error("winsectxc: %s -> %s", section, xc_index)
52
        if not xc_index:
Daria Tomecka's avatar
Daria Tomecka committed
53
54
55
56
57
58
59
60
61
            xc_index = ["XC_PBE"]
        xc_map_legend = {

            '5': ['LDA_C_PW_RPA'],
            'XC_LDA': ['LDA_X_2D'],

            '13': ['GGA_X_PBE', 'GGA_C_PBE'],
            'XC_PBE':['GGA_X_PBE', 'GGA_C_PBE'],

Daria Tomecka's avatar
Daria Tomecka committed
62
63
            '19': ['GGA_X_PBE_SOL', 'GGA_C_PBE_SOL'],
            'XC_PBESOL': ['GGA_X_PBE_SOL', 'GGA_C_PBE_SOL'],
Daria Tomecka's avatar
Daria Tomecka committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

            '11': ['GGA_X_WC'],
            'XC_WC': ['GGA_X_WC'],

            '17': ['GGA_X_PW91'],
            'EC_PW91': ['GGA_X_PW91'],
            'VC_PW91': ['GGA_X_PW91'],

            '28': ['MGGA_X_TB09'],
            'XC_MBJ': ['MGGA_X_TB09'],

            '29': ['MGGA_C_REVTPSS, GGA_C_REGTPSS'],
            'XC_REVTPSS': ['MGGA_C_REVTPSS, GGA_C_REGTPSS'],

            '24': ['GGA_X_B88', 'GGA_C_LYP'],
            'EX_B88': ['GGA_X_B88'],
            'VX_B88': ['GGA_X_B88'],
            'EC_LYP': ['GGA_C_LYP'],
            'VC_LYP': ['GGA_C_LYP'],

            '18': ['HYB_GGA_XC_B3PW91'],
            'XC_B3PW91': ['HYB_GGA_XC_B3PW91'],

            '27': ['MGGA_X_TPSS','MGGA_C_TPSS'],
            'XC_TPSS': ['MGGA_X_TPSS','MGGA_C_TPSS'],

            '46':['GGA_X_HTBS'],
            'XC_HTBS': ['GGA_X_HTBS'], 

            '47': ['HYB_GGA_XC_B3LYP'],
            'XC_B3LYP': ['HYB_GGA_XC_B3LYP'],


            #        51: ['-'],
            #        EX_SLDA:
            #        VX_SLDA:

            #        52: ['-'],
            #        EX_SPBE: 
            #        VX_SPBE:

            #        53: ['-'],
            #        EX_SWC: 
            #        VX_SWC:

            #        54: ['-'],
            #        EX_SPBESOL: 
            #        VX_SPBESOL:

            #        55: ['-'],
            #        EX_SB88:
            #        VX_SB88:

            '6': ['HF_X'],
            'EX_LDA': ['HF_X'],
            'VX_LDA': ['HF_X']
        }

        # Push the functional string into the backend
        xc_map_legend = xc_map_legend.get(xc_index[0])
        if not xc_map_legend:
            raise Exception("Unhandled xc functional %s found" % xc_index)


        for xc_name in xc_map_legend:
            #  for xc_name in xc_map_legend[xc_index]:
130
131
132
            s = backend.openSection("section_xc_functionals")
            backend.addValue("xc_functional_name", xc_name)
            backend.closeSection("section_xc_functionals", s)
133
134
135
136

# description of the input
def buildIn0Matchers():
    return SM(
137
138
139
        name = 'root',
        weak = True,
        startReStr = "",
Daria Tomecka's avatar
Daria Tomecka committed
140
        sections = ["section_run", "section_method"],
141
142
        subMatchers = [
            #        SM(name = 'systemName',
143
144
            #          startReStr = r"(?P<x_wien2k_system_namein>.*)"),
            SM(r"(?P<x_wien2k_switch>\w*)\s*(?P<x_wien2k_indxc>\w*)\s*.*",sections = ['x_wien2k_section_xc']),
145
146
            SM(r"\s*(?P<x_wien2k_ifft_x>[0-9]+)\s*(?P<x_wien2k_ifft_y>[0-9]+)\s*(?P<x_wien2k_ifft_z>[0-9]+)\s*(?P<x_wien2k_ifft_factor>[0-9.]+)\s*(?P<x_wien2k_iprint>[0-9]+).*")
        ])
147

Daria Tomecka's avatar
Daria Tomecka committed
148
149


150
151
def get_cachingLevelForMetaName(metaInfoEnv, CachingLvl):
    """Sets the caching level for the metadata.
152
    
153
    Args:
154
155
156
    metaInfoEnv: metadata which is an object of the class InfoKindEnv in nomadcore.local_meta_info.py.
    CachingLvl: Sets the CachingLevel for the sections k_band, run, and single_configuration_calculation.
    This allows to run the parser without opening new sections.
157
158

    Returns:
159
    Dictionary with metaname as key and caching level as value.
160
161
162
    """
    # manually adjust caching of metadata
    cachingLevelForMetaName = {
163
164
165
        'section_run': CachingLvl,
        'section_method': CachingLvl
    }
166
167
168
    return cachingLevelForMetaName

# loading metadata from nomad-meta-info/meta_info/nomad_meta_info/fhi_aims.nomadmetainfo.json