-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the plugin setup #2
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,123 +1,55 @@ | ||
from typing import ( | ||
TYPE_CHECKING, | ||
from nomad.datamodel.datamodel import ( | ||
EntryArchive, | ||
) | ||
from structlog.stdlib import ( | ||
BoundLogger, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from nomad.datamodel.datamodel import ( | ||
EntryArchive, | ||
) | ||
from structlog.stdlib import ( | ||
BoundLogger, | ||
) | ||
|
||
from nomad.config import config | ||
from nomad.parsing import MatchingParser | ||
from nomad.parsing.file_parser.mapping_parser import ( | ||
MappingAnnotationModel, | ||
MetainfoParser, | ||
XMLParser, | ||
) | ||
from nomad_simulations_plugin.numerical_settings import KMesh | ||
from nomad_simulations.schema_packages.general import Simulation, Program | ||
from nomad_simulations.schema_packages.model_system import ( | ||
ModelSystem, | ||
AtomicCell, | ||
) | ||
from nomad_simulations.schema_packages.model_method import ( | ||
DFT, | ||
XCFunctional, | ||
) | ||
from nomad_simulations.schema_packages.outputs import ElectronicEigenvalues | ||
from nomad_simulations.schema_packages.numerical_settings import KMesh | ||
|
||
configuration = config.get_plugin_entry_point('nomad_parser_vasp.parsers:myparser') | ||
configuration = config.get_plugin_entry_point( | ||
'nomad_parser_vasp.parsers:xml_entry_point' | ||
) | ||
|
||
# TODO move to schema parser and prepare all relevant annotations for every file format | ||
|
||
|
||
# ! vasprun.xml has many meta fields, explaining field semantics | ||
Simulation.m_annotations = dict(xml=MappingAnnotationModel(path='modeling')) | ||
Simulation.program.name.m_annotations = dict( | ||
xml=MappingAnnotationModel(path='modeling.generator.i[?"@name"="program"]') | ||
) | ||
Simulation.program.version.m_annotations = dict( | ||
xml=MappingAnnotationModel(path='modeling.generator.i[?"@name"="version"]') | ||
) | ||
# ? compilation mode? | ||
Simulation.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.separator[?"@name"="electronic exchange-correlation"]' | ||
# DFT.xc_functionals.m_annotations = dict(xml=MappingAnnotationModel(path=dft_path)) | ||
DFT.exact_exchange_mixing_factor.m_annotations = dict( | ||
xml=MappingAnnotationModel( | ||
operator=( | ||
lambda mix, cond: mix if cond else 0, | ||
[dft_path + '.i[?"@name"="HFALPHA"]', dft_path + '.i[?"@name"="LHFCALC"]'], | ||
) | ||
) # TODO convert vasp bool | ||
) | ||
XCFunctional.libxc_name.m_annotations = dict( | ||
xml=MappingAnnotationModel( | ||
operator=(convert_xc, [dft_path + '.i[?"@name"="GGA"]']) # add LDA & mGGA | ||
) | ||
) | ||
# ? target <structure name="initialpos" > and <structure name="finalpos" > | ||
AtomicCell.positions.m_annotations = dict( | ||
xml=MappingAnnotationModel( | ||
path='calculation.structure.varray[?"@name"="positions"]' | ||
) | ||
) | ||
""" | ||
forces.m_annotations = dict( | ||
xml=MappingAnnotationModel(path='calculation.structure.varray[?"@name"="forces"]') | ||
) | ||
stress.m_annotations = dict( | ||
xml=MappingAnnotationModel(path='calculation.structure.varray[?"@name"="stress"]') | ||
) | ||
""" | ||
AtomicCell.lattice_vectors.m_annotations = dict( | ||
xml=MappingAnnotationModel( | ||
path='calculation.structure.crystal.varray[?"@name"="basis"]' | ||
) | ||
) | ||
""" | ||
cell_volume.m_annotations = dict( | ||
xml=MappingAnnotationModel(path='calculation.structure.crystal.i[?"@name"="volume"]') | ||
) | ||
reciprocal_lattice_vectors.m_annotations = dict( | ||
xml=MappingAnnotationModel(path='calculation.structure.crystal.varray[?"@name"="rec_basis"]') | ||
) | ||
total_free_energy.m_annotations = dict( | ||
xml=MappingAnnotationModel(path='calculation.energy.i[?"@name"="e_fr_energy"]') | ||
) | ||
total_internal_energy.m_annotations = dict( | ||
xml=MappingAnnotationModel(path='calculation.energy.i[?"@name"="e_0_energy"]') | ||
) | ||
""" | ||
ElectronicEigenvalues.spin_channel.m_annotations = dict( | ||
xml=MappingAnnotationModel( | ||
path='calculation.eigenvalues.array.set.set[?"@comment"="spin 1"]' | ||
) | ||
) | ||
ElectronicEigenvalues.reciprocal_cell.m_annotations = dict( | ||
xml=MappingAnnotationModel( | ||
path=ElectronicEigenvalues.spin_channel.m_annotations.xml | ||
+ '.set[?"@comment"="kpoint 1"]' | ||
) # TODO not going to work: add conversion to reference | ||
Simulation.m_def.m_annotations['xml'] = MappingAnnotationModel(path='modeling') | ||
|
||
Simulation.program.m_annotations['xml'] = MappingAnnotationModel(path='.generator') | ||
|
||
|
||
Program.name.m_annotations['xml'] = MappingAnnotationModel( | ||
path='.i[?"@name"="program"]' | ||
) | ||
ElectronicEigenvalues.occupation.m_annotations = dict( | ||
xml=MappingAnnotationModel( | ||
path=ElectronicEigenvalues.reciprocal_cell.m_annotations.xml + '.r[0]' | ||
) | ||
|
||
|
||
Program.version.m_annotations['xml'] = MappingAnnotationModel( | ||
path='.i[?"@name"="version"]' | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also here |
||
ElectronicEigenvalues.value.m_annotations = dict( | ||
xml=MappingAnnotationModel( | ||
path=ElectronicEigenvalues.reciprocal_cell.m_annotations.xml + '.r[1]' | ||
) | ||
|
||
# ? compilation mode | ||
Program.compilation_host.m_annotations['xml'] = MappingAnnotationModel( | ||
path='.i[?"@name"="platform"]' | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alao here |
||
# ? partial bands | ||
|
||
|
||
class VasprunXMLParser(MatchingParser): | ||
|
@@ -128,19 +60,7 @@ def parse( | |
logger: BoundLogger, | ||
child_archives: dict[str, EntryArchive] = None, | ||
) -> None: | ||
logger.info( | ||
self.__class__.__repr__() + '.parse', parameter=configuration.parameter | ||
) # give feedback to Ahmed | ||
archive_parser = MetainfoParser( | ||
annotation_key='xml', | ||
data_object=[ | ||
Simulation( | ||
model_system=[ModelSystem(cell=AtomicCell)], | ||
model_method=[DFT, KMesh], | ||
output=[ElectronicEigenvalues], | ||
), | ||
], | ||
) | ||
xml_parser = XMLParser(filepath='vasprun.xml') # TODO apply match | ||
xml_parser.convert(archive_parser) | ||
archive.data = archive_parser.data_object | ||
logger.info('VasprunXMLParser.parse', parameter=configuration.parameter) | ||
data_parser = MetainfoParser(annotation_key='xml', data_object=Simulation()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is a matching parsee you would meed to.add parsee specs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean like the filename to match? I already added it to |
||
XMLParser(filepath=mainfile).convert(data_parser) | ||
archive.data = data_parser.data_object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls try to use simgle quotes inside somerimes jnespath is crazy and it should be ==