Commits (1)
...@@ -18,13 +18,15 @@ import gzip ...@@ -18,13 +18,15 @@ import gzip
import bz2 import bz2
import lzma import lzma
from nomad.datamodel import EntryArchive
from .metainfo import m_env from .metainfo import m_env
from vaspparser.parser_vasprun import VasprunContext, XmlParser, parser_info from vaspparser.parser_vasprun import VasprunContext, XmlParser, parser_info
from nomad.parsing.parser import MatchingParser from nomad.parsing.parser import FairdiParser
from vaspparser.parser_outcar import VaspOutcarParser from vaspparser.parser_outcar import VaspOutcarParser
class VASPParser(MatchingParser): class VASPParser(FairdiParser):
def __init__(self): def __init__(self):
super().__init__( super().__init__(
name='parsers/vasp', code_name='VASP', code_homepage='https://www.vasp.at/', name='parsers/vasp', code_name='VASP', code_homepage='https://www.vasp.at/',
...@@ -38,7 +40,7 @@ class VASPParser(MatchingParser): ...@@ -38,7 +40,7 @@ class VASPParser(MatchingParser):
supported_compressions=['gz', 'bz2', 'xz'] supported_compressions=['gz', 'bz2', 'xz']
) )
def run(self, filepath, logger=None): def parse(self, filepath, archive, logger=None):
self._metainfo_env = m_env self._metainfo_env = m_env
super_context = VasprunContext(logger=logger) super_context = VasprunContext(logger=logger)
...@@ -53,5 +55,4 @@ class VASPParser(MatchingParser): ...@@ -53,5 +55,4 @@ class VASPParser(MatchingParser):
elif filepath.endswith('.xz'): elif filepath.endswith('.xz'):
open_file = lzma.open open_file = lzma.open
parser.parse(os.path.abspath(filepath), open_file(filepath, 'rt')) parser.parse(os.path.abspath(filepath), open_file(filepath, 'rt'), archive)
return parser.root_section
# Copyright 2016-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.
import sys
import json
from vaspparser import VASPParser
if __name__ == "__main__":
archive = VASPParser.main(sys.argv[1])
json.dump(archive.m_to_dict(), sys.stdout, indent=2)
\ No newline at end of file
...@@ -954,13 +954,13 @@ class XmlParser(object): ...@@ -954,13 +954,13 @@ class XmlParser(object):
self.tagSections = {} self.tagSections = {}
self.metainfo_env = metainfo_env self.metainfo_env = metainfo_env
def parse(self, main_file_uri, f_in): def parse(self, main_file_uri, f_in, archive):
if self.path: if self.path:
raise Exception( raise Exception(
"Parse of %s called with non empty path, parse already in progress?" % main_file_uri) "Parse of %s called with non empty path, parse already in progress?" % main_file_uri)
self.main_file_uri = main_file_uri self.main_file_uri = main_file_uri
self.f_in = f_in self.f_in = f_in
self.root_section = msection_run() self.root_section = archive.m_create(msection_run)
self.super_context.parser = self self.super_context.parser = self
# there are invalid characters like esc in the files, we do not want to crash on them # there are invalid characters like esc in the files, we do not want to crash on them
xml_parser = MyXMLParser() xml_parser = MyXMLParser()
......