diff --git a/src/nomad_parser_vasp/parsers/xml_parser.py b/src/nomad_parser_vasp/parsers/xml_parser.py index 110305e..adca311 100644 --- a/src/nomad_parser_vasp/parsers/xml_parser.py +++ b/src/nomad_parser_vasp/parsers/xml_parser.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Dict, List, Any +from typing import TYPE_CHECKING, Dict, List, Any, Union import numpy as np @@ -13,7 +13,7 @@ from nomad.config import config from nomad.parsing.file_parser.mapping_parser import MetainfoParser, XMLParser, Path -from nomad_parser_vasp.schema_packages.vasp_package import Simulation +from nomad_parser_vasp.schema_packages.vasp_package import Simulation, SinglePoint configuration = config.get_plugin_entry_point( 'nomad_parser_vasp.parsers:vasp_parser_entry_point' @@ -46,6 +46,21 @@ def get_data(self, source: Dict[str, Any], **kwargs) -> float: parser = Path(path=path) return parser.get_data(source) + def get_workflow(self, source: Dict[str, Any]) -> Dict[str, Any]: + calculation = source.get('calculation', {}) + data = {} + if not calculation: + return data + + if isinstance(calculation, list): + # multiple calculations maybe geometry opt or md + pass + elif isinstance(calculation, dict): + scf_steps = calculation.get('scstep', []) + scf_steps = scf_steps if isinstance(scf_steps, list) else [scf_steps] + data.setdefault('n_scf_steps', len(scf_steps)) + + return data class VASPXMLParser: def parse( @@ -73,6 +88,24 @@ def parse( archive.data = data + workflow = None + if len(data.outputs) == 1: + workflow = SinglePoint() + else: + # TODO add other workflow types + pass + if workflow is not None: + workflow_parser = MetainfoParser() + workflow_parser.annotation_key = 'xml' + workflow_parser.data_object = workflow + + xml_parser.convert(workflow_parser) + archive.workflow2 = workflow + + self.workflow_parser = workflow_parser + # self.workflow_parser.close() + + # TODO important! close, debug only to acccess parsers # close file objects # data_parser.close() # xml_parser.close() diff --git a/src/nomad_parser_vasp/schema_packages/vasp_package.py b/src/nomad_parser_vasp/schema_packages/vasp_package.py index f48e326..804031c 100644 --- a/src/nomad_parser_vasp/schema_packages/vasp_package.py +++ b/src/nomad_parser_vasp/schema_packages/vasp_package.py @@ -12,6 +12,7 @@ numerical_settings, outputs, properties, + workflow, ) m_package = SchemaPackage() @@ -285,6 +286,13 @@ class Simulation(general.Simulation): ) +class SinglePoint(workflow.SinglePoint): + + workflow.SinglePoint.n_scf_steps.m_annotations[XML_ANNOTATION_KEY] = MappingAnnotationModel(mapper='.n_scf_steps') + + +SinglePoint.m_def.m_annotations[XML_ANNOTATION_KEY] = MappingAnnotationModel(mapper=('get_workflow', ['modeling'])) + """ # ? target and