Skip to content

Commit

Permalink
added xml parsering
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernadette-Mohr committed Jul 9, 2024
1 parent 44f4b92 commit 3d94cb5
Showing 1 changed file with 79 additions and 130 deletions.
209 changes: 79 additions & 130 deletions src/nomad_parser_vasp/schema_packages/vasp_package_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,165 +3,114 @@
)

if TYPE_CHECKING:
pass

from nomad.metainfo import SchemaPackage
from nomad.parsing.file_parser.mapping_parser import MappingAnnotationModel
from nomad_simulations.schema_packages.general import Program, Simulation
from nomad_simulations.schema_packages.model_method import (
DFT,
XCFunctional,
)
from nomad_simulations.schema_packages.model_system import (
AtomicCell,
)
from nomad_simulations.schema_packages.numerical_settings import KMesh

m_package = SchemaPackage()

# note: vasprun.xml has many meta fields, explaining field semantics
Simulation.m_def.m_annotations['xml'] = MappingAnnotationModel(path='modeling')

Simulation.program.m_annotations['xml'] = MappingAnnotationModel(path='.generator')

Simulation.model_method.m_annotations['xml'] = MappingAnnotationModel(
path='.parameters'
)

Simulation.model_system.m_annotations['xml'] = MappingAnnotationModel(
path='.calculation'
)

Simulation.model_system.cell.m_annotations['xml'] = MappingAnnotationModel(
path='.structure'
)

Simulation.outputs.m_annotations['xml'] = MappingAnnotationModel(path='.calculation')

Program.name.m_annotations['xml'] = MappingAnnotationModel(
path='.i[?"@name"="program"]'
)
from nomad.datamodel.datamodel import (
EntryArchive,
)
from structlog.stdlib import (
BoundLogger,
)

Program.version.m_annotations['xml'] = MappingAnnotationModel(
path='.i[?"@name"="version"]'
import numpy as np
from nomad.config import config
from nomad.metainfo import (
MEnum,
Quantity,
SchemaPackage,
)
from nomad_simulations.schema_packages.properties import TotalEnergy
from nomad_simulations.schema_packages.properties.energies import BaseEnergy

# ? compilation mode
Program.compilation_host.m_annotations['xml'] = MappingAnnotationModel(
path='.i[?"@name"="platform"]'
configuration = config.get_plugin_entry_point(
'nomad_parser_vasp.schema_packages:mypackage'
)

DFT.numerical_settings.m_annotations['xml'] = MappingAnnotationModel(
path='modeling.kpoints'
)
m_package = SchemaPackage()

dft_path = '.separator[?"@name"="electronic exchange-correlation"]'
DFT.xc_functionals.m_annotations['xml'] = MappingAnnotationModel(
path=dft_path
) # start from Simulation.model_method 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(
path=dft_path + '.i[?"@name"="GGA"]' # TODO add LDA & mGGA, convert_xc
)
)
# class DoubleCountingCorrection(BaseEnergy): # no extra class, label via type
# value = Quantity(
# type=np.dtype(np.float64),
# unit='eV',
# )
# type # from physical property (like Chema BandGap direct/indirect label)
#
# # Needed?
# def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
# super().normalize(archive, logger)
#
# logger.info('MySchema.normalize', parameter=configuration.parameter)
# self.message = f'Hello {self.name}!'

KMesh.grid.m_annotations['xml'] = MappingAnnotationModel(
path='.generation.v[?"@name"="divisions"]'
) # start from DFT.numerical_settings

KMesh.offset.m_annotations['xml'] = MappingAnnotationModel(
path='.generation.v[?"@name"="shift"]'
) # start from DFT.numerical_settings
# class HartreeDCEnergy(DoubleCountingCorrection):
# value = DoubleCountingCorrection.value

KMesh.offset.m_annotations['xml'] = MappingAnnotationModel(
path='.generation.v[?"@name"="shift"]'
) # start from DFT.numerical_settings

KMesh.points.m_annotations['xml'] = MappingAnnotationModel(
path='.varray[?"@name"="kpointlist"].v'
) # start from DFT.numerical_settings
# class XCdcEnergy(DoubleCountingCorrection):
# value = DoubleCountingCorrection.value

KMesh.weights.m_annotations['xml'] = MappingAnnotationModel(
path='.varray[?"@name"="weights"].v'
) # start from DFT.numerical_settings

# class Outputs(Outputs):
# m_def = Section(
# validate=False,
# extends_base_section=True,
# )

# ? target <structure name="initialpos" > and <structure name="finalpos" >
# # add a new section for the custom output
# hartreedc = SubSection(
# sub_section=HartreeDCEnergy.m_def,
# repeats=True,
# )

# xcdc = SubSection(
# sub_section=XCdcEnergy.m_def,
# repeats=True,
# )

AtomicCell.positions.m_annotations = dict(
xml=MappingAnnotationModel(path='.varray[?"@name"="positions"]')
) # start from Simulation.model_system.cell path

"""
...forces.m_annotations['xml'] = MappingAnnotationModel(
path='.varray[?"@name"="forces"]'
) # start from Simulation.model_system.cell path
class DoubleCountingEnergy(BaseEnergy):
value = Quantity(
type=np.dtype(np.float64),
unit='eV',
)

...stress.m_annotations['xml'] = MappingAnnotationModel(
path='.varray[?"@name"="stress"]'
) # start from Simulation.model_system.cell path
"""
type = Quantity(
type=MEnum('double_counting'),
)

AtomicCell.lattice_vectors.m_annotations['xml'] = MappingAnnotationModel(
path='.crystal.varray[?"@name"="basis"]'
) # start from Simulation.model_system.cell path
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

"""
cell_volume.m_annotations['xml'] = MappingAnnotationModel(
path='.crystal.i[?"@name"="volume"]'
) # start from Simulation.model_system.cell path
if not self.type:
self.type = 'double_counting'

reciprocal_lattice_vectors.m_annotations['xml'] = MappingAnnotationModel(
path='.crystal.varray[?"@name"="rec_basis"]'
) # start from Simulation.model_system.cell path

total_free_energy.m_annotations['xml'] = MappingAnnotationModel(
path='calculation.energy.i[?"@name"="e_fr_energy"]'
)
class HartreeDCEnergy(DoubleCountingEnergy):
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

total_internal_energy.m_annotations['xml'] = MappingAnnotationModel(
path='calculation.energy.i[?"@name"="e_0_energy"]'
)

...eigenvalues.m_annotations['xml'] = MappingAnnotationModel(
path='.eigenvalues.array'
)
class XCdcEnergy(DoubleCountingEnergy):
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

ElectronicEigenvalues.spin_channel.m_annotations['xml'] = MappingAnnotationModel(
path='.eigenvalues.set.set[?"@comment"="spin 1"]'
) # start from Simulation.outputs path

ElectronicEigenvalues.reciprocal_cell.m_annotations['xml'] = MappingAnnotationModel(
path=ElectronicEigenvalues.spin_channel.m_annotations.xml
+ '.set[?"@comment"="kpoint 1"]'
) # TODO not going to work: add conversion to reference
class RestEnergy(BaseEnergy):
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

ElectronicEigenvalues.occupation.m_annotations['xml'] = MappingAnnotationModel(
path=ElectronicEigenvalues.reciprocal_cell.m_annotations.xml + '.r[0]'
)

ElectronicEigenvalues.value.m_annotations['xml'] = MappingAnnotationModel(
path=ElectronicEigenvalues.reciprocal_cell.m_annotations.xml + '.r[1]'
)
class TotalEnergy(TotalEnergy):
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

electronic_energy_correction.m_annotations['xml'] = MappingAnnotationModel(
path='calculation.energy.i[?"@name"="hartreedc"]'
)
if self.total_energy:
for total_energy in self.total_energy:
if total_energy.value and total_energy.contributions:
value = total_energy.value
for contribution in total_energy.contributions:
value -= contribution.value
total_energy.rest_energy.append(RestEnergy(value=value))

exchange_correlation_energy_correction.m_annotations['xml'] = MappingAnnotationModel(
path='calculation.energy.i[?"@name"="XCdc"]'
)
"""

m_package.__init_metainfo__()

0 comments on commit 3d94cb5

Please sign in to comment.