__init__.py 2.83 KB
Newer Older
1
# Copyright 2016-2018 Fawzi Mohamed, Lauri Himanen, Danio Brambila, Ankit Kariryaa, Henning Glawe
Markus Scheidgen's avatar
Markus Scheidgen committed
2
#
3
4
5
#   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
Markus Scheidgen's avatar
Markus Scheidgen committed
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
Markus Scheidgen's avatar
Markus Scheidgen committed
8
#
9
10
11
12
13
14
#   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.

15
16
import os
import logging
Markus Scheidgen's avatar
Markus Scheidgen committed
17

18
from nomadcore.baseclasses import ParserInterface
Markus Scheidgen's avatar
Markus Scheidgen committed
19
import nomadcore.baseclasses
Markus Scheidgen's avatar
Markus Scheidgen committed
20

Markus Scheidgen's avatar
Markus Scheidgen committed
21
from vaspparser.parser_vasprun import parserInfo
Markus Scheidgen's avatar
Markus Scheidgen committed
22
from vaspparser.parser_vasprun import VasprunContext, XmlParser, parserInfo
23
from vaspparser.parser_outcar import VaspOutcarParser
Markus Scheidgen's avatar
Markus Scheidgen committed
24

25

Markus Scheidgen's avatar
Markus Scheidgen committed
26
27
28
29
30
31
32
33
34
class VASPRunParser:
    """
    The main parser class that is called for all run types. Parses the VASP
    .out output files.
    """
    def __init__(self, parser_context):
        self.parser_context = parser_context

    def parse(self, filepath):
Markus Scheidgen's avatar
Markus Scheidgen committed
35
36
        # the nomadcore.baseclasses.logger is set for each parsing run
        superContext = VasprunContext(logger=nomadcore.baseclasses.logger)
Markus Scheidgen's avatar
Markus Scheidgen committed
37
38
39
40
41
42
43
44
        parser = XmlParser(parserInfo, superContext)
        backend = self.parser_context.super_backend
        parser.parse(os.path.abspath(filepath), open(filepath), backend)


class VASPRunParserInterface(ParserInterface):
    """
    This class handles the initial setup before any parsing can happen. It
45
46
47
48
49
50
    determines which version of BigDFT was used to generate the output and then
    sets up a correct main parser.

    After the implementation has been setup, you can parse the files with
    parse().
    """
Markus Scheidgen's avatar
Markus Scheidgen committed
51
52
53
54
55
56
57
    def __init__(
            self,
            metainfo_to_keep=None, backend=None, default_units=None,
            metainfo_units=None, debug=True, log_level=logging.ERROR, store=True):

        super(VASPRunParserInterface, self).__init__(
            metainfo_to_keep, backend, default_units, metainfo_units, debug, log_level, store)
58
59

    def setup_version(self):
Markus Scheidgen's avatar
Markus Scheidgen committed
60
61
        """
        Setups the version by looking at the output file and the version
62
63
64
65
66
67
68
        specified in it.
        """
        # Setup the root folder to the fileservice that is used to access files
        dirpath, filename = os.path.split(self.parser_context.main_file)
        dirpath = os.path.abspath(dirpath)
        self.parser_context.file_service.setup_root_folder(dirpath)
        self.parser_context.file_service.set_file_id(filename, "output")
Markus Scheidgen's avatar
Markus Scheidgen committed
69
        self.main_parser = VASPRunParser(self.parser_context)
70
71
72
73
74
75

    def get_metainfo_filename(self):
        return "vasp.nomadmetainfo.json"

    def get_parser_info(self):
        return parserInfo