Skip to content

Commit

Permalink
Introduce MappingParsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Daelman committed Jul 1, 2024
1 parent 653b0cc commit cdad89e
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions src/nomad_parser_vasp/parsers/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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(
Expand All @@ -44,7 +60,7 @@
) # TODO convert vasp bool
)
# ? target <structure name="initialpos" > and <structure name="finalpos" >
Cell.positions.m_annotations = dict(
AtomicCell.positions.m_annotations = dict(
xml=MappingAnnotationModel(path='calculation.structure.varray[@name="positions"]')
)
"""
Expand All @@ -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"]'
)
Expand Down Expand Up @@ -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

0 comments on commit cdad89e

Please sign in to comment.