From cdad89eabc59e8b68a625f0cb7d6f0a8752a1401 Mon Sep 17 00:00:00 2001 From: Nathan Daelman Date: Mon, 1 Jul 2024 17:23:31 +0200 Subject: [PATCH] Introduce `MappingParser`s --- src/nomad_parser_vasp/parsers/xml_parser.py | 48 +++++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/nomad_parser_vasp/parsers/xml_parser.py b/src/nomad_parser_vasp/parsers/xml_parser.py index 9b54440..5bfc0e6 100644 --- a/src/nomad_parser_vasp/parsers/xml_parser.py +++ b/src/nomad_parser_vasp/parsers/xml_parser.py @@ -11,8 +11,12 @@ ) from nomad.config import config -from nomad.datamodel.results import Material, Results from nomad.parsing.parser import MatchingParser +from nomad.parsing.file_parser.mapping_parser import ( + MappingAnnotationModel, + MetainfoParser, + XMLParser, +) configuration = config.get_plugin_entry_point('nomad_parser_vasp.parsers:myparser') @@ -29,6 +33,18 @@ Program.compilation_host.m_annotations = dict( xml=MappingAnnotationModel(path='modeling.generator.i[@name="platform"]') ) +KMesh.grid.m_annotations = dict( + xml=MappingAnnotationModel(path='modeling.kpoints.generation.v[@name="divisions"]') +) +KMesh.offset.m_annotations = dict( + xml=MappingAnnotationModel(path='modeling.kpoints.generation.v[@name="shift"]') +) +KMesh.high_symmetry_points.m_annotations = dict( + xml=MappingAnnotationModel(path='modeling.kpoints.varray.v[@name="kpointlist"]') +) +KMesh.weights.m_annotations = dict( + xml=MappingAnnotationModel(path='modeling.kpoints.varray.v[@name="weights"]') +) dft_path = 'modeling.calculation[@name="electronic"]' XCFunctional.libxc_name.m_annotations = dict( xml=MappingAnnotationModel( @@ -44,7 +60,7 @@ ) # TODO convert vasp bool ) # ? target and -Cell.positions.m_annotations = dict( +AtomicCell.positions.m_annotations = dict( xml=MappingAnnotationModel(path='calculation.structure.varray[@name="positions"]') ) """ @@ -55,7 +71,7 @@ xml=MappingAnnotationModel(path='calculation.structure.varray[@name="stress"]') ) """ -Cell.lattice_vectors.m_annotations = dict( +AtomicCell.lattice_vectors.m_annotations = dict( xml=MappingAnnotationModel( path='calculation.structure.crystal.varray[@name="basis"]' ) @@ -98,13 +114,27 @@ # ? partial bands -class MyParser(MatchingParser): +class VasprunXMLParser(MatchingParser): def parse( self, mainfile: str, - archive: 'EntryArchive', - logger: 'BoundLogger', - child_archives: dict[str, 'EntryArchive'] = None, + archive: EntryArchive, + logger: BoundLogger, + child_archives: dict[str, EntryArchive] = None, ) -> None: - logger.info('MyParser.parse', parameter=configuration.parameter) - archive.results = Results(material=Material(elements=['H', 'O'])) + logger.info( + self.__class__.__repr__() + '.parse', parameter=configuration.parameter + ) # give feedback to Ahmed + archive_parser = MetainfoParser( + annotation_key='xml', + data_object=[ + Program, + KMesh, + DFT, + AtomicCell, + ElectronicEigenvalues, + ], + ) + xml_parser = XMLParser(filepath='vasprun.xml') # TODO apply match + xml_parser.convert(archive_parser) + archive = archive_parser.data_object