Skip to content

Commit

Permalink
finished example
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudz committed Jul 12, 2024
1 parent b38dfeb commit 40a54a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/nomad_parser_vasp/parsers/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nomad.datamodel.datamodel import EntryArchive
from nomad.parsing import MatchingParser
from nomad.parsing.file_parser.xml_parser import XMLParser
from nomad.units import ureg
from nomad_simulations.general import Program, Simulation
from nomad_simulations.model_method import DFT, XCFunctional
from nomad_simulations.model_system import AtomicCell, ModelSystem
Expand All @@ -12,6 +13,7 @@
from nomad_parser_vasp.schema_packages.vasp_schema import (
HartreeDCEnergy,
TotalEnergy,
UnknownEnergy,
XCdcEnergy,
)

Expand Down Expand Up @@ -87,14 +89,19 @@ def xml_get(path: str, slicer=slice(0, 1), fallback=None):
)

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

output = Outputs()
archive.simulation.outputs.append(output)
archive.data.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))

output.total_energy[0].contributions.append(UnknownEnergy(value=None))
32 changes: 26 additions & 6 deletions src/nomad_parser_vasp/schema_packages/vasp_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,34 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:


class HartreeDCEnergy(DoubleCountingEnergy):
def __init__(
self, m_def: 'Section' = None, m_context: 'Context' = None, **kwargs
) -> None:
super().__init__(m_def, m_context, **kwargs)
self.name = self.m_def.name

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


class XCdcEnergy(DoubleCountingEnergy):
def __init__(
self, m_def: 'Section' = None, m_context: 'Context' = None, **kwargs
) -> None:
super().__init__(m_def, m_context, **kwargs)
self.name = self.m_def.name

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


class UnknownEnergy(EnergyContribution):
def __init__(
self, m_def: 'Section' = None, m_context: 'Context' = None, **kwargs
) -> None:
super().__init__(m_def, m_context, **kwargs)
self.name = self.m_def.name

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

Expand All @@ -40,13 +58,15 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
return

value = self.value
unknown_energy_exists = False
for contribution in self.contributions:
i_unknown = None
for i_cont, contribution in enumerate(self.contributions):
if contribution.name == 'UnknownEnergy':
i_unknown = i_cont

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))

if i_unknown:
self.contributions[i_unknown].value = value

0 comments on commit 40a54a3

Please sign in to comment.