From 05e5f608178df11fe5563dcb88c3e475d51cd230 Mon Sep 17 00:00:00 2001 From: Markus Scheidgen <markus.scheidgen@gmail.com> Date: Mon, 4 Feb 2019 20:16:07 +0100 Subject: [PATCH] Added minimar OUTCAR parser that can be used in absence of .xml to create repository meta data. --- vaspparser/__init__.py | 1 + vaspparser/parser_outcar.py | 92 +++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 vaspparser/parser_outcar.py diff --git a/vaspparser/__init__.py b/vaspparser/__init__.py index 7380dc0..9b0f6bc 100644 --- a/vaspparser/__init__.py +++ b/vaspparser/__init__.py @@ -20,6 +20,7 @@ import nomadcore.baseclasses from vaspparser.parser_vasprun import parserInfo from vaspparser.parser_vasprun import VasprunContext, XmlParser, parserInfo +from vaspparser.parser_outcar import VaspOutcarParser class VASPRunParser: diff --git a/vaspparser/parser_outcar.py b/vaspparser/parser_outcar.py new file mode 100644 index 0000000..2e3776d --- /dev/null +++ b/vaspparser/parser_outcar.py @@ -0,0 +1,92 @@ +# Copyright 2019-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 numpy as np + +from ase.io import read as ase_read + +from nomadcore.simple_parser import SimpleMatcher +from nomadcore.baseclasses import ParserInterface, MainHierarchicalParser + +from nomad.parsing import LocalBackend + + +""" +A very basic VASP OUTCAR parser. It is only used to get nomad repository +metadata in absence of the VASP .xml file. +""" + + +class VaspOutcarParser(ParserInterface): + + def get_metainfo_filename(self): + return 'vasp.nomadmetainfo.json' + + def get_parser_info(self): + return { + 'name': 'vaspoutcar_parser', + 'version': '1.0.0' + } + + def setup_version(self): + self.setup_main_parser(None) + + def setup_main_parser(self, _): + self.main_parser = MainParser(self.parser_context) + + +class MainParser(MainHierarchicalParser): + def __init__(self, parser_context, *args, **kwargs): + super().__init__(parser_context, *args, **kwargs) + self.lattice_vectors = [] + + self.root_matcher = SimpleMatcher( + name='root', + startReStr=r'vasp.', + weak=True, + sections=['section_run', 'section_system', 'section_method'], + subMatchers=[ + SimpleMatcher(r'\svasp.(?P<program_version>\d+.\d+.\d+)\s.*') + ] + ) + + def parse(self, mainfile, *args, **kwargs): + self.ase = ase_read(mainfile, format='vasp-out') + super().parse(mainfile, *args, **kwargs) + + def add_lattice_vector(self, backend, data): + self.lattice_vectors.append(list(float(x.strip()) for x in data[1].split(','))) + + def onClose_section_method(self, backend, *args, **kwargs): + backend.openNonOverlappingSection('section_XC_functionals') + backend.addValue('XC_functional_name', 'GGA_X_PBE') + backend.closeNonOverlappingSection('section_XC_functionals') + backend.addValue('electronic_structure_method', 'DFT') + + def onClose_section_system(self, backend, *args, **kwargs): + backend.addArrayValues('atom_labels', np.array(self.ase.get_chemical_symbols())) + backend.addArrayValues('atom_positions', self.ase.get_positions()) + backend.addArrayValues('lattice_vectors', self.ase.get_cell()) + backend.addArrayValues('configuration_periodic_dimensions', self.ase.get_pbc()) + + def onClose_section_run(self, backend, *args, **kwargs): + backend.addValue('program_name', 'vasp') + backend.addValue('program_basis_set_type', 'plane waves') + + +if __name__ == "__main__": + parser = VaspOutcarParser(backend=LocalBackend) + parser.parse(sys.argv[1]) + print(parser.parser_context.super_backend) -- GitLab