__init__.py 19.1 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
This module redefines some of the old NOMAD-coe python-common functionality to create a
more coherent interface to the parsers.
19
20
21
22
23

Assumption about parsers
------------------------
For now, we make a few assumption about parsers
- they always work on the same *meta-info* version
Markus Scheidgen's avatar
Markus Scheidgen committed
24
- they have no conflicting python requirements
25
26
- 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
27
- their version is uniquely identified by a GIT commit SHA
28

Markus Scheidgen's avatar
Markus Scheidgen committed
29
Each parser is defined via an instance of :class:`Parser`. The implementation :class:`LegacyParser` is used for most NOMAD-coe parsers.
30
31
32
33

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

Markus Scheidgen's avatar
Markus Scheidgen committed
34
35
36
37
38
39
40
41
42
43
44
45
The are sub-classes for parsers with special purposes.

.. autoclass:: nomad.parsing.Parser
.. autoclass:: nomad.parsing.MatchingParser
.. autoclass:: nomad.parsing.MissingParser
.. autoclass:: nomad.parsing.BrokenParser
.. autoclass:: nomad.parsing.TemplateParser
.. autoclass:: nomad.parsing.GenerateRandomParser
.. autoclass:: nomad.parsing.ChaosParser
.. autoclass:: nomad.parsing.EmptyParser


Markus Scheidgen's avatar
Markus Scheidgen committed
46
47
48
49
The implementation :class:`LegacyParser` is used for most NOMAD-coe parsers.

.. autoclass:: nomad.parsing.LegacyParser

Markus Scheidgen's avatar
Markus Scheidgen committed
50

51
52
53
54
55
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
56
Parsers are reused for multiple calculations.
Markus Scheidgen's avatar
Markus Scheidgen committed
57

58
59
Parsers and calculation files are matched via regular expressions.

Markus Scheidgen's avatar
Markus Scheidgen committed
60
.. autofunction:: nomad.parsing.match_parser
61

Markus Scheidgen's avatar
Markus Scheidgen committed
62
Parsers in NOMAD-coe use a *backend* to create output. There are different NOMAD-coe
Markus Scheidgen's avatar
Markus Scheidgen committed
63
basends. In nomad@FAIRDI, we only currently only use a single backed. A version of
Markus Scheidgen's avatar
Markus Scheidgen committed
64
65
66
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.
67
68
69
70
71
72

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

Alvin Noe Ladines's avatar
Alvin Noe Ladines committed
74
from typing import Callable, IO, Union, Dict
75
import magic
76
77
import gzip
import bz2
Alvin Noe Ladines's avatar
Alvin Noe Ladines committed
78
import lzma
79
import os.path
80

81
from nomad import files, config
82
83

from nomad.parsing.backend import AbstractParserBackend, LocalBackend, LegacyLocalBackend, JSONStreamWriter, BadContextURI, WrongContextState
84
from nomad.parsing.metainfo import MetainfoBackend
85
from nomad.parsing.parser import Parser, LegacyParser, VaspOutcarParser, BrokenParser, MissingParser, MatchingParser
86
from nomad.parsing.artificial import TemplateParser, GenerateRandomParser, ChaosParser, EmptyParser
87

88

89
90
_compressions = {
    b'\x1f\x8b\x08': ('gz', gzip.open),
Alvin Noe Ladines's avatar
Alvin Noe Ladines committed
91
92
    b'\x42\x5a\x68': ('bz2', bz2.open),
    b'\xfd\x37\x7a': ('xz', lzma.open)
93
94
95
}


96
def match_parser(mainfile: str, upload_files: Union[str, files.StagingUploadFiles], strict=True) -> 'Parser':
97
98
99
100
101
102
103
104
105
106
    """
    Performs parser matching. This means it take the given mainfile and potentially
    opens it with the given callback and tries to identify a parser that can parse
    the file.

    This is determined by filename (e.g. *.out), mime type (e.g. text/*, application/xml),
    and beginning file contents.

    Arguments:
        mainfile: The upload relative path to the mainfile
107
108
        upload_files: Either a :class:`files.StagingUploadFiles` object or a directory name.
            Directory name + mainfile needs to point to the file.
109
        strict: Only match strict parsers, e.g. no artificial parsers for missing or empty entries.
110
111
112

    Returns: The parser, or None if no parser could be matched.
    """
113
114
115
116
117
118
    if isinstance(upload_files, str):
        mainfile_path = os.path.join(upload_files, mainfile)
    else:
        mainfile_path = upload_files.raw_file_object(mainfile).os_path

    with open(mainfile_path, 'rb') as f:
119
        compression, open_compressed = _compressions.get(f.read(3), (None, open))
120

Alvin Noe Ladines's avatar
Alvin Noe Ladines committed
121
    with open_compressed(mainfile_path, 'rb') as cf:  # type: ignore
122
        buffer = cf.read(config.parser_matching_size)
123
124
125

    mime_type = magic.from_buffer(buffer, mime=True)
    for parser in parsers:
126
127
128
129
130
131
132
133
134
        if strict and (isinstance(parser, MissingParser) or isinstance(parser, EmptyParser)):
            continue

        if parser.domain != config.domain:
            continue

        if parser.is_mainfile(mainfile_path, mime_type, buffer, compression):
            # TODO: deal with multiple possible parser specs
            return parser
135
136
137
138

    return None


139
parsers = [
140
    GenerateRandomParser(),
141
    TemplateParser(),
142
    ChaosParser(),
Daniel Speckhard's avatar
Daniel Speckhard committed
143
    LegacyParser(
144
        name='parsers/phonopy', code_name='Phonopy',
Daniel Speckhard's avatar
Daniel Speckhard committed
145
        parser_class_name='phonopyparser.PhonopyParserWrapper',
Daniel Speckhard's avatar
Daniel Speckhard committed
146
        # mainfile_contents_re=r'',  # Empty regex since this code calls other DFT codes.
Daniel Speckhard's avatar
Daniel Speckhard committed
147
148
        mainfile_name_re=(r'.*/phonopy-FHI-aims-displacement-0*1/control.in$')
    ),
149
    LegacyParser(
150
        name='parsers/vasp', code_name='VASP',
151
        parser_class_name='vaspparser.VASPRunParserInterface',
Alvin Noe Ladines's avatar
Alvin Noe Ladines committed
152
        mainfile_mime_re=r'(application/.*)|(text/.*)',
153
        mainfile_contents_re=(
154
155
156
157
            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>'
158
            r'?'),
Alvin Noe Ladines's avatar
Alvin Noe Ladines committed
159
        supported_compressions=['gz', 'bz2', 'xz']
160
    ),
161
    VaspOutcarParser(
162
        name='parsers/vasp-outcar', code_name='VASP',
163
        parser_class_name='vaspparser.VaspOutcarParser',
164
165
        mainfile_name_re=r'(.*/)?OUTCAR(\.[^\.]*)?',
        mainfile_contents_re=(r'^\svasp\.')
166
    ),
167
    LegacyParser(
168
        name='parsers/exciting', code_name='exciting',
169
        parser_class_name='excitingparser.ExcitingParser',
170
171
        mainfile_name_re=r'^.*.OUT?',
        mainfile_contents_re=(r'EXCITING.*started')
172
173
    ),
    LegacyParser(
174
        name='parsers/fhi-aims', code_name='FHI-aims',
175
        parser_class_name='fhiaimsparser.FHIaimsParser',
176
        mainfile_contents_re=(
177
178
            r'^(.*\n)*'
            r'?\s*Invoking FHI-aims \.\.\.'
Markus Scheidgen's avatar
Markus Scheidgen committed
179
180
            # r'?\s*Version'
        )
181
182
    ),
    LegacyParser(
183
        name='parsers/cp2k', code_name='CP2K',
184
        parser_class_name='cp2kparser.CP2KParser',
185
        mainfile_contents_re=(
186
187
188
189
            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
190
191
            r'  \*\*\*\* \*\*  \*\*\*\*\*\*\*  \*\*  PROGRAM STARTED IN .*\n'
        )
192
    ),
193
    LegacyParser(
194
        name='parsers/crystal', code_name='Crystal',
195
        parser_class_name='crystalparser.CrystalParser',
196
        mainfile_contents_re=(
197
            r'(CRYSTAL\s*\n0 0 0)|('
speckhard's avatar
speckhard committed
198
            r'\s*\*\s{10,}CRYSTAL(?P<majorVersion>[\d]+)\s{10,}\*'
199
            r'\s*\*\s{10,}public \: (?P<minorVersion>[\d\.]+) \- .*\*)'
speckhard's avatar
speckhard committed
200
        )
201
    ),
202
203
204
    # The main contents regex of CPMD was causing a catostrophic backtracking issue
    # when searching through the first 500 bytes of main files. We decided
    # to use only a portion of the regex to avoid that issue.
205
    LegacyParser(
206
        name='parsers/cpmd', code_name='CPMD',
207
        parser_class_name='cpmdparser.CPMDParser',
208
        mainfile_contents_re=(
209
210
211
212
213
214
215
216
            # r'\s+\*\*\*\*\*\*  \*\*\*\*\*\*    \*\*\*\*  \*\*\*\*  \*\*\*\*\*\*\s*'
            # r'\s+\*\*\*\*\*\*\*  \*\*\*\*\*\*\*   \*\*\*\*\*\*\*\*\*\*  \*\*\*\*\*\*\*\s+'
            r'\*\*\*       \*\*   \*\*\*  \*\* \*\*\*\* \*\*  \*\*   \*\*\*'
            # r'\s+\*\*        \*\*   \*\*\*  \*\*  \*\*  \*\*  \*\*    \*\*\s+'
            # r'\s+\*\*        \*\*\*\*\*\*\*   \*\*      \*\*  \*\*    \*\*\s+'
            # r'\s+\*\*\*       \*\*\*\*\*\*    \*\*      \*\*  \*\*   \*\*\*\s+'
            # r'\s+\*\*\*\*\*\*\*  \*\*        \*\*      \*\*  \*\*\*\*\*\*\*\s+'
            # r'\s+\*\*\*\*\*\*  \*\*        \*\*      \*\*  \*\*\*\*\*\*\s+'
speckhard's avatar
speckhard committed
217
        )
218
    ),
speckhard's avatar
speckhard committed
219
    LegacyParser(
220
        name='parsers/nwchem', code_name='NWChem',
speckhard's avatar
speckhard committed
221
        parser_class_name='nwchemparser.NWChemParser',
222
        mainfile_contents_re=(
223
            r'Northwest Computational Chemistry Package \(NWChem\) (\d+\.)+\d+'
speckhard's avatar
speckhard committed
224
225
226
        )
    ),
    LegacyParser(
227
        name='parsers/bigdft', code_name='BigDFT',
speckhard's avatar
speckhard committed
228
        parser_class_name='bigdftparser.BigDFTParser',
229
        mainfile_contents_re=(
Markus Scheidgen's avatar
Markus Scheidgen committed
230
231
232
233
234
235
            # 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*'
speckhard's avatar
speckhard committed
236
            r'\|_____\|__:__\|__:__\|_____\|_____\|___ BBBBB          i     g         g\s*'
Markus Scheidgen's avatar
Markus Scheidgen committed
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
            # 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
255
        )
256
257
    ),
    LegacyParser(
258
        name='parsers/wien2k', code_name='WIEN2k',
259
        parser_class_name='wien2kparser.Wien2kParser',
260
        mainfile_contents_re=r':LABEL\d+: using WIEN2k_\d+\.\d+'
Markus Scheidgen's avatar
Markus Scheidgen committed
261
262
    ),
    LegacyParser(
Markus Scheidgen's avatar
Markus Scheidgen committed
263
        name='parsers/band', code_name='BAND',
264
        parser_class_name='bandparser.BANDParser',
Markus Scheidgen's avatar
Markus Scheidgen committed
265
        mainfile_contents_re=r' +\* +Amsterdam Density Functional +\(ADF\)'),
Daniel Speckhard's avatar
Daniel Speckhard committed
266
    LegacyParser(
267
        name='parsers/gaussian', code_name='Gaussian',
Daniel Speckhard's avatar
Daniel Speckhard committed
268
        parser_class_name='gaussianparser.GaussianParser',
269
270
        mainfile_contents_re=(
            r'\s*Cite this work as:'
271
272
            r'\s*Gaussian [0-9]+, Revision [A-Za-z0-9\.]*,')
    ),
273
    LegacyParser(
274
        name='parsers/quantumespresso', code_name='Quantum Espresso',
275
        parser_class_name='quantumespressoparser.QuantumEspressoParserPWSCF',
276
        mainfile_contents_re=r'Program PWSCF.*starts'
277
278
279
280
        #    r'^(.*\n)*'
        #    r'\s*Program (\S+)\s+v\.(\S+)(?:\s+\(svn\s+rev\.\s+'
        #    r'(\d+)\s*\))?\s+starts[^\n]+'
        #    r'(?:\s*\n?)*This program is part of the open-source Quantum')
Daniel Speckhard's avatar
Daniel Speckhard committed
281
282
    ),
    LegacyParser(
283
        name='parsers/abinit', code_name='ABINIT',
Daniel Speckhard's avatar
Daniel Speckhard committed
284
        parser_class_name='abinitparser.AbinitParser',
285
        mainfile_contents_re=(r'^\n*\.Version\s*[0-9.]*\s*of ABINIT\s*')
Daniel Speckhard's avatar
Daniel Speckhard committed
286
287
    ),
    LegacyParser(
288
        name='parsers/orca', code_name='ORCA',
Daniel Speckhard's avatar
Daniel Speckhard committed
289
290
291
292
293
294
295
        parser_class_name='orcaparser.OrcaParser',
        mainfile_contents_re=(
            r'\s+\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**\s*'
            r'\s+\* O   R   C   A \*\s*'
            r'\s+\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**\s*'
            r'\s*'
            r'\s*--- An Ab Initio, DFT and Semiempirical electronic structure package ---\s*')
296
297
    ),
    LegacyParser(
298
        name='parsers/castep', code_name='CASTEP',
299
300
        parser_class_name='castepparser.CastepParser',
        mainfile_contents_re=(r'\s\|\s*CCC\s*AA\s*SSS\s*TTTTT\s*EEEEE\s*PPPP\s*\|\s*')
Daniel Speckhard's avatar
Daniel Speckhard committed
301
302
    ),
    LegacyParser(
303
        name='parsers/dl-poly', code_name='DL_POLY',
Daniel Speckhard's avatar
Daniel Speckhard committed
304
305
        parser_class_name='dlpolyparser.DlPolyParserWrapper',
        mainfile_contents_re=(r'\*\* DL_POLY \*\*')
Daniel Speckhard's avatar
Daniel Speckhard committed
306
307
    ),
    LegacyParser(
308
        name='parsers/lib-atoms', code_name='libAtoms',
Daniel Speckhard's avatar
Daniel Speckhard committed
309
310
        parser_class_name='libatomsparser.LibAtomsParserWrapper',
        mainfile_contents_re=(r'\s*<GAP_params\s')
Daniel Speckhard's avatar
Daniel Speckhard committed
311
312
    ),
    LegacyParser(
313
        name='parsers/octopus', code_name='Octopus',
Daniel Speckhard's avatar
Daniel Speckhard committed
314
        parser_class_name='octopusparser.OctopusParserWrapper',
Daniel Speckhard's avatar
Daniel Speckhard committed
315
316
317
        mainfile_contents_re=(r'\|0\) ~ \(0\) \|')
        # We decided to use the octopus eyes instead of
        # r'\*{32} Grid \*{32}Simulation Box:' since it was so far down in the file.
Daniel Speckhard's avatar
Daniel Speckhard committed
318
    ),
319
320
321
322
323
324
325
326
    # match gpaw2 first, other .gpw files are then considered to be "gpaw1"
    LegacyParser(
        name='parsers/gpaw2', code_name='GPAW',
        parser_class_name='gpawparser.GPAWParser2Wrapper',
        mainfile_binary_header=b'GPAW',
        mainfile_name_re=(r'^.*\.(gpw2|gpw)$'),
        mainfile_mime_re=r'application/(x-tar|octet-stream)'
    ),
Daniel Speckhard's avatar
Daniel Speckhard committed
327
    LegacyParser(
328
        name='parsers/gpaw', code_name='GPAW',
Daniel Speckhard's avatar
Daniel Speckhard committed
329
330
        parser_class_name='gpawparser.GPAWParserWrapper',
        mainfile_name_re=(r'^.*\.gpw$'),
331
        mainfile_mime_re=r'application/(x-tar|octet-stream)'
Daniel Speckhard's avatar
Daniel Speckhard committed
332
333
    ),
    LegacyParser(
334
        name='parsers/atk', code_name='ATK',
Daniel Speckhard's avatar
Daniel Speckhard committed
335
336
337
338
339
        parser_class_name='atkparser.ATKParserWrapper',
        # mainfile_contents_re=r'',  # We can't read .gpw as txt - of UlmGPAW|AFFormatGPAW'
        mainfile_name_re=r'^.*\.nc',
        # The previously used mime type r'application/x-netcdf' wasn't found by magic library.
        mainfile_mime_re=r'application/octet-stream'
Daniel Speckhard's avatar
Daniel Speckhard committed
340
341
    ),
    LegacyParser(
342
        name='parsers/gulp', code_name='gulp',
Daniel Speckhard's avatar
Daniel Speckhard committed
343
344
345
346
347
348
349
        parser_class_name='gulpparser.GULPParser',
        mainfile_contents_re=(
            r'\s*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*'
            r'\*\*\*\*\*\*\*\*\*\*\*\*\*\s*'
            r'\s*\*\s*GENERAL UTILITY LATTICE PROGRAM\s*\*\s*')
    ),
    LegacyParser(
350
        name='parsers/siesta', code_name='Siesta',
Daniel Speckhard's avatar
Daniel Speckhard committed
351
352
353
354
355
        parser_class_name='siestaparser.SiestaParser',
        mainfile_contents_re=(
            r'(Siesta Version: siesta-|SIESTA [0-9]\.[0-9]\.[0-9])')
    ),
    LegacyParser(
356
        name='parsers/elk', code_name='elk',
Daniel Speckhard's avatar
Daniel Speckhard committed
357
        parser_class_name='elkparser.ElkParser',
358
        mainfile_contents_re=r'\| Elk version [0-9.a-zA-Z]+ started \|'
Daniel Speckhard's avatar
Daniel Speckhard committed
359
360
    ),
    LegacyParser(
361
        name='parsers/elastic', code_name='elastic',
Daniel Speckhard's avatar
Daniel Speckhard committed
362
363
        parser_class_name='elasticparser.ElasticParser',
        mainfile_contents_re=r'\s*Order of elastic constants\s*=\s*[0-9]+\s*'
Daniel Speckhard's avatar
Daniel Speckhard committed
364
365
    ),
    LegacyParser(
366
        name='parsers/gamess', code_name='GAMESS',
Daniel Speckhard's avatar
Daniel Speckhard committed
367
368
369
370
371
        parser_class_name='gamessparser.GamessParser',
        mainfile_contents_re=(
            r'\s*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**\s*'
            r'\s*\*\s*GAMESS VERSION =\s*(.*)\*\s*'
            r'\s*\*\s*FROM IOWA STATE UNIVERSITY\s*\*\s*')
372
373
    ),
    LegacyParser(
374
        name='parsers/turbomole', code_name='turbomole',
375
376
        parser_class_name='turbomoleparser.TurbomoleParser',
        mainfile_contents_re=(
377
            r'Copyright \(C\) [0-9]+ TURBOMOLE GmbH, Karlsruhe')
378
379
380
381
382
383
    ),
    LegacyParser(
        name='parsers/skeleton', code_name='skeleton', domain='EMS',
        parser_class_name='skeletonparser.SkeletonParserInterface',
        mainfile_mime_re=r'(application/json)|(text/.*)',
        mainfile_contents_re=(r'skeleton experimental metadata format')
Markus Scheidgen's avatar
Markus Scheidgen committed
384
385
386
387
388
    ),
    LegacyParser(
        name='parsers/mpes', code_name='mpes', domain='EMS',
        parser_class_name='mpesparser.MPESParserInterface',
        mainfile_mime_re=r'(application/json)|(text/.*)',
389
        mainfile_name_re=(r'.*.meta'),
390
        mainfile_contents_re=(r'"data_repository_name": "zenodo.org"')
391
392
393
394
395
396
    ),
    LegacyParser(
        name='parsers/aptfim', code_name='mpes', domain='EMS',
        parser_class_name='aptfimparser.APTFIMParserInterface',
        mainfile_mime_re=r'(application/json)|(text/.*)',
        mainfile_name_re=(r'.*.aptfim')
397
    ),
398
    LegacyParser(
399
        name='parsers/qbox', code_name='qbox', domain='DFT',
400
401
        parser_class_name='qboxparser.QboxParser',
        mainfile_mime_re=r'(application/xml)|(text/.*)',
402
        mainfile_contents_re=(r'http://qboxcode.org')
403
    ),
404
    LegacyParser(
405
        name='parsers/dmol', code_name='DMol3', domain='DFT',
406
407
408
        parser_class_name='dmol3parser.Dmol3Parser',
        mainfile_name_re=r'.*\.outmol',
        mainfile_contents_re=r'Materials Studio DMol\^3'
409
    ),
410
    LegacyParser(
411
        name='parser/fleur', code_name='fleur', domain='DFT',
412
        parser_class_name='fleurparser.FleurParser',
413
414
        mainfile_contents_re=r'This output is generated by fleur.'
    ),
415
    LegacyParser(
416
        name='parser/molcas', code_name='MOLCAS', domain='DFT',
417
        parser_class_name='molcasparser.MolcasParser',
418
419
        mainfile_contents_re=r'M O L C A S'
    ),
420
    LegacyParser(
Markus Scheidgen's avatar
Markus Scheidgen committed
421
        name='parser/onetep', code_name='ONETEP', domain='DFT',
422
        parser_class_name='onetepparser.OnetepParser',
423
424
        mainfile_contents_re=r'####### #     # ####### ####### ####### ######'
    ),
425
426
427
428
429
430
431
432
433
    # There are some entries with PIDs that have mainfiles which do not match what
    # the actual parsers expect. We use the EmptyParser to produce placeholder entries
    # to keep the PIDs. These parsers will not match for new, non migrated data.
    EmptyParser(
        name='missing/octopus', code_name='Octopus', domain='DFT',
        mainfile_name_re=r'(inp)|(.*/inp)'
    ),
    EmptyParser(
        name='missing/crystal', code_name='Crystal',
434
        mainfile_name_re=r'.*\.cryst\.out'
435
    ),
436
437
    EmptyParser(
        name='missing/wien2k', code_name='WIEN2k',
438
        mainfile_name_re=r'.*\.scf'
439
    ),
440
441
    EmptyParser(
        name='missing/fhi-aims', code_name='FHI-aims', domain='DFT',
442
        mainfile_name_re=r'.*\.fhiaims'
443
444
    ),
    BrokenParser()
445
]
446

447
""" Instantiation and constructor based config of all parsers. """
448

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