Skip to content

Commit

Permalink
started tutorial example
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudz committed Jul 11, 2024
1 parent ab030ee commit d3d2f17
Show file tree
Hide file tree
Showing 4 changed files with 36,326 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/nomad_parser_vasp/parsers/xml_parser.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from nomad.datamodel.datamodel import (
EntryArchive,
)
from structlog.stdlib import (
BoundLogger,
)

import numpy as np
from nomad.config import config
from nomad.datamodel.datamodel import EntryArchive
from nomad.parsing import MatchingParser
from nomad_simulations.schema_packages.general import Simulation, Program
from nomad_simulations.schema_packages.model_method import DFT, XCFunctional
from nomad_simulations.schema_packages.model_system import ModelSystem, AtomicCell
from nomad.parsing.file_parser.xml_parser import XMLParser
from nomad_simulations.general import Program, Simulation
from nomad_simulations.model_method import DFT, XCFunctional
from nomad_simulations.model_system import AtomicCell, ModelSystem
from nomad_simulations.outputs import Outputs
from structlog.stdlib import BoundLogger

from nomad_parser_vasp.schema_packages.vasp_schema import (
HartreeDCEnergy,
TotalEnergy,
XCdcEnergy,
)

configuration = config.get_plugin_entry_point(
'nomad_parser_vasp.parsers:xml_entry_point'
Expand Down Expand Up @@ -83,3 +85,16 @@ def xml_get(path: str, slicer=slice(0, 1), fallback=None):
archive.data.model_system.append(
ModelSystem(cell=[AtomicCell(positions=positions)])
)

total_energy = xml_get("i[@name='e_fr_energy']", slice(-2, -1))
hartreedc = xml_get("i[@name='hartreedc']", slice(-2, -1))
xcdc = xml_get("i[@name='XCdc']", slice(-2, -1))

output = Outputs()
archive.simulation.outputs.append(output)
output.total_energy.append(TotalEnergy(value=total_energy * ureg.eV))

output.total_energy[0].contributions.append(
HartreeDCEnergy(value=hartreedc * ureg.eV)
)
output.total_energy[0].contributions.append(XCdcEnergy(value=xcdc * ureg.eV))
51 changes: 51 additions & 0 deletions src/nomad_parser_vasp/schema_packages/vasp_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from nomad.metainfo import MEnum, Quantity
from nomad_simulations.properties.energies import EnergyContribution


class DoubleCountingEnergy(EnergyContribution):
type = Quantity(
type=MEnum('double_counting'),
)

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

if not self.type:
self.type = 'double_counting'


class HartreeDCEnergy(DoubleCountingEnergy):
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)


class XCdcEnergy(DoubleCountingEnergy):
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)


class UnknownEnergy(EnergyContribution):
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)


class TotalEnergy(nomad_simulations.schema_packages.properties.TotalEnergy):
def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

if not self.value:
return
if not self.contributions:
return

value = self.value
unknown_energy_exists = False
for contribution in self.contributions:
if not contribution.value:
continue
if contribution.name == 'UnknownEnergy':
unknown_energy_exists = True

value -= contribution.value
if not unknown_energy_exists:
self.contributions.append(UnknownEnergy(value=value))
Loading

0 comments on commit d3d2f17

Please sign in to comment.