__init__.py 9.01 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Copyright 2018 Markus Scheidgen
#
# 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.

"""
16
The *parsing* module is an interface for the existing NOMAD-coe parsers.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
The parser code is used via :mod:`nomad.dependencies`. This module redefines
some of the old NOMAD-coe python-common functionality to create a more coherent
interface to the parsers.

Assumption about parsers
------------------------
For now, we make a few assumption about parsers
- they always work on the same *meta-info* version
- they have no conflicting python requirments
- they can be loaded at the same time and can be used within the same python process
- they are uniquely identified by a GIT URL and publicly accessible
- their version is uniquly identified by a GIT commit SHA

Each parser is defined via an instance of :class:`Parser`.

.. autoclass:: nomad.parsing.Parser
    :members:

Markus Scheidgen's avatar
Markus Scheidgen committed
35
36
37
38
The implementation :class:`LegacyParser` is used for most NOMAD-coe parsers.

.. autoclass:: nomad.parsing.LegacyParser

39
40
41
42
43
The parser definitions are available via the following two variables.

.. autodata:: nomad.parsing.parsers
.. autodata:: nomad.parsing.parser_dict

Markus Scheidgen's avatar
Markus Scheidgen committed
44
45
46
47
48
49
50
Parsers are reused for multiple caclulations.

Parsers in NOMAD-coe use a *backend* to create output. There are different NOMAD-coe
basends. In nomad@FAIR, we only currently only use a single backed. A version of
NOMAD-coe's *LocalBackend*. It stores all parser results in memory. The following
classes provide a interface definition for *backends* as an ABC and a concrete implementation
based on NOMAD-coe's *python-common* module.
51
52
53
54
55

.. autoclass:: nomad.parsing.AbstractParserBackend
    :members:
.. autoclass:: nomad.parsing.LocalBackend
    :members:
Markus Scheidgen's avatar
Markus Scheidgen committed
56

57
58
59
"""

from nomad.parsing.backend import AbstractParserBackend, LocalBackend, LegacyLocalBackend, JSONStreamWriter, BadContextURI, WrongContextState
60
from nomad.parsing.parser import Parser, LegacyParser, VaspOutcarParser
61
from nomad.parsing.artificial import TemplateParser, GenerateRandomParser, ChaosParser
62
63
from nomad.dependencies import dependencies_dict as dependencies

64

65
parsers = [
66
    GenerateRandomParser(),
67
    TemplateParser(),
68
    ChaosParser(),
69
70
    LegacyParser(
        python_git=dependencies['parsers/vasp'],
71
        parser_class_name='vaspparser.VASPRunParserInterface',
72
73
74
75
76
77
78
79
        main_file_re=r'^.*\.xml(\.[^\.]*)?$',
        main_contents_re=(
            r'^\s*<\?xml version="1\.0" encoding="ISO-8859-1"\?>\s*'
            r'?\s*<modeling>'
            r'?\s*<generator>'
            r'?\s*<i name="program" type="string">\s*vasp\s*</i>'
            r'?')
    ),
80
81
82
83
84
85
    VaspOutcarParser(
        python_git=dependencies['parsers/vasp'],
        parser_class_name='vaspparser.VaspOutcarParser',
        main_file_re=r'^OUTCAR(\.[^\.]*)?$',
        main_contents_re=(r'^\svasp\..*$')
    ),
86
87
    LegacyParser(
        python_git=dependencies['parsers/exciting'],
88
        parser_class_name='excitingparser.ExcitingParser',
89
90
91
92
93
94
95
96
97
98
99
100
101
102
        main_file_re=r'^.*/INFO\.OUT?',
        main_contents_re=(
            r'^\s*=================================================+\s*'
            r'\s*\|\s*EXCITING\s+\S+\s+started\s*='
            r'\s*\|\s*version hash id:\s*\S*\s*=')
    ),
    LegacyParser(
        python_git=dependencies['parsers/fhi-aims'],
        parser_class_name='fhiaimsparser.FHIaimsParser',
        main_file_re=r'^.*\.out$',
        main_contents_re=(
            r'^(.*\n)*'
            r'?\s*Invoking FHI-aims \.\.\.'
            r'?\s*Version')
103
104
105
106
107
108
    ),
    LegacyParser(
        python_git=dependencies['parsers/cp2k'],
        parser_class_name='cp2kparser.CP2KParser',
        main_file_re=r'^.*\.out$',  # This looks for files with .out
        main_contents_re=(
109
110
111
112
            r'\*\*\*\* \*\*\*\* \*\*\*\*\*\*  \*\*  PROGRAM STARTED AT\s.*\n'
            r' \*\*\*\*\* \*\* \*\*\*  \*\*\* \*\*   PROGRAM STARTED ON\s*.*\n'
            r' \*\*    \*\*\*\*   \*\*\*\*\*\*    PROGRAM STARTED BY .*\n'
            r' \*\*\*\*\* \*\*    \*\* \*\* \*\*   PROGRAM PROCESS ID .*\n'
speckhard's avatar
speckhard committed
113
114
            r'  \*\*\*\* \*\*  \*\*\*\*\*\*\*  \*\*  PROGRAM STARTED IN .*\n'
        )
115
    ),
116
117
118
119
    LegacyParser(
        python_git=dependencies['parsers/crystal'],
        parser_class_name='crystalparser.CrystalParser',
        main_file_re=r'^.*\.out$',  # This looks for files with .out
speckhard's avatar
speckhard committed
120
121
122
123
124
125
        main_contents_re=(
            r'\s*[\*]{22,}'  # Looks for '*' 22 times or more in a row.
            r'\s*\*\s{20,}\*'  # Looks for a '*' sandwhiched by whitespace.
            r'\s*\*\s{10,}CRYSTAL(?P<majorVersion>[\d]+)\s{10,}\*'
            r'\s*\*\s{10,}public \: (?P<minorVersion>[\d\.]+) \- .*\*'
        )
126
    ),
127
    LegacyParser(
speckhard's avatar
speckhard committed
128
        python_git=dependencies['parsers/cpmd'],
129
130
        parser_class_name='cpmdparser.CPMDParser',
        main_file_re=r'^.*\.out$',  # This looks for files with .out
speckhard's avatar
speckhard committed
131
132
133
134
135
136
137
138
139
140
        main_contents_re=(
            r'\s*    \*\*\*\*\*\*  \*\*\*\*\*\*    \*\*\*\*  \*\*\*\*  \*\*\*\*\*\*\s*'
            r'\s*   \*\*\*\*\*\*\*  \*\*\*\*\*\*\*   \*\*\*\*\*\*\*\*\*\*  \*\*\*\*\*\*\*\s*'
            r'\s*  \*\*\*       \*\*   \*\*\*  \*\* \*\*\*\* \*\*  \*\*   \*\*\*\s*'
            r'\s*  \*\*        \*\*   \*\*\*  \*\*  \*\*  \*\*  \*\*    \*\*\s*'
            r'\s*  \*\*        \*\*\*\*\*\*\*   \*\*      \*\*  \*\*    \*\*\s*'
            r'\s*  \*\*\*       \*\*\*\*\*\*    \*\*      \*\*  \*\*   \*\*\*\s*'
            r'\s*   \*\*\*\*\*\*\*  \*\*        \*\*      \*\*  \*\*\*\*\*\*\*\s*'
            r'\s*    \*\*\*\*\*\*  \*\*        \*\*      \*\*  \*\*\*\*\*\*\s*'
        )
141
    ),
speckhard's avatar
speckhard committed
142
143
144
145
146
    LegacyParser(
        python_git=dependencies['parsers/nwchem'],
        parser_class_name='nwchemparser.NWChemParser',
        main_file_re=r'^.*\.out$',  # This looks for files with .out
        main_contents_re=(
speckhard's avatar
speckhard committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
            r'              Northwest Computational Chemistry Package \(NWChem\) \d+\.\d+'
            r' ------------------------------------------------------'
            r'      Environmental Molecular Sciences Laboratory'
            r'           Pacific Northwest National Laboratory'
            r'                    Richland, WA 99352'
        )
    ),
    LegacyParser(
        python_git=dependencies['parsers/bigdft'],
        parser_class_name='bigdftparser.BigDFTParser',
        main_file_re=r'^.*\.out$',  # This looks for files with .out
        main_contents_re=(
            r'__________________________________ A fast and precise DFT wavelet code\s*'
            r'\|     \|     \|     \|     \|     \|\s*'
            r'\|     \|     \|     \|     \|     \|      BBBB         i       gggggg\s*'
            r'\|_____\|_____\|_____\|_____\|_____\|     B    B               g\s*'
            r'\|     \|  :  \|  :  \|     \|     \|    B     B        i     g\s*'
            r'\|     \|-0\+--\|-0\+--\|     \|     \|    B    B         i     g        g\s*'
            r'\|_____\|__:__\|__:__\|_____\|_____\|___ BBBBB          i     g         g\s*'
            r'\|  :  \|     \|     \|  :  \|     \|    B    B         i     g         g\s*'
            r'\|--\+0-\|     \|     \|-0\+--\|     \|    B     B     iiii     g         g\s*'
            r'\|__:__\|_____\|_____\|__:__\|_____\|    B     B        i      g        g\s*'
            r'\|     \|  :  \|  :  \|     \|     \|    B BBBB        i        g      g\s*'
            r'\|     \|-0\+--\|-0\+--\|     \|     \|    B        iiiii          gggggg\s*'
            r'\|_____\|__:__\|__:__\|_____\|_____\|__BBBBB\s*'
            r'\|     \|     \|     \|  :  \|     \|                           TTTTTTTTT\s*'
            r'\|     \|     \|     \|--\+0-\|     \|  DDDDDD          FFFFF        T\s*'
            r'\|_____\|_____\|_____\|__:__\|_____\| D      D        F        TTTT T\s*'
            r'\|     \|     \|     \|  :  \|     \|D        D      F        T     T\s*'
            r'\|     \|     \|     \|--\+0-\|     \|D         D     FFFF     T     T\s*'
            r'\|_____\|_____\|_____\|__:__\|_____\|D___      D     F         T    T\s*'
            r'\|     \|     \|  :  \|     \|     \|D         D     F          TTTTT\s*'
            r'\|     \|     \|--\+0-\|     \|     \| D        D     F         T    T\s*'
            r'\|_____\|_____\|__:__\|_____\|_____\|          D     F        T     T\s*'
            r'\|     \|     \|     \|     \|     \|         D               T    T\s*'
            r'\|     \|     \|     \|     \|     \|   DDDDDD       F         TTTT\s*'
            r'\|_____\|_____\|_____\|_____\|_____\|______                    www\.bigdft\.org'
speckhard's avatar
speckhard committed
184
185
        )
    )
186
187
188
]
""" Instanciation and constructor based config of all parsers. """

Markus Scheidgen's avatar
Markus Scheidgen committed
189
parser_dict = {parser.name: parser for parser in parsers}  # type: ignore
190
""" A dict to access parsers by name. Usually 'parsers/<...>', e.g. 'parsers/vasp'. """