Skip to content

Commit

Permalink
Handle sp workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ladinesa committed Oct 17, 2024
1 parent d8f1e9a commit fd01e5a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/nomad_parser_vasp/parsers/xml_parser.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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'
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions src/nomad_parser_vasp/schema_packages/vasp_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
numerical_settings,
outputs,
properties,
workflow,
)

m_package = SchemaPackage()
Expand Down Expand Up @@ -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 <structure name="initialpos" > and <structure name="finalpos" >
Expand Down

0 comments on commit fd01e5a

Please sign in to comment.