diff --git a/src/nomad_parser_vasp/parsers/xml_parser.py b/src/nomad_parser_vasp/parsers/xml_parser.py index 8d48092..2905376 100644 --- a/src/nomad_parser_vasp/parsers/xml_parser.py +++ b/src/nomad_parser_vasp/parsers/xml_parser.py @@ -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 @@ -12,6 +13,7 @@ from nomad_parser_vasp.schema_packages.vasp_schema import ( HartreeDCEnergy, TotalEnergy, + UnknownEnergy, XCdcEnergy, ) @@ -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)) diff --git a/src/nomad_parser_vasp/schema_packages/vasp_schema.py b/src/nomad_parser_vasp/schema_packages/vasp_schema.py index 8ad8609..9ddd497 100644 --- a/src/nomad_parser_vasp/schema_packages/vasp_schema.py +++ b/src/nomad_parser_vasp/schema_packages/vasp_schema.py @@ -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) @@ -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