diff --git a/src/nomad_parser_vasp/parsers/xml_parser.py b/src/nomad_parser_vasp/parsers/xml_parser.py index 2905376..1b6aa49 100644 --- a/src/nomad_parser_vasp/parsers/xml_parser.py +++ b/src/nomad_parser_vasp/parsers/xml_parser.py @@ -13,7 +13,6 @@ from nomad_parser_vasp.schema_packages.vasp_schema import ( HartreeDCEnergy, TotalEnergy, - UnknownEnergy, XCdcEnergy, ) @@ -44,6 +43,9 @@ def xml_get(path: str, slicer=slice(0, 1), fallback=None): except KeyError: return fallback + #################################################### + # Parse the basic program, method, and system data # + #################################################### archive.data = Simulation( program=Program( name='VASP', @@ -88,20 +90,44 @@ def xml_get(path: str, slicer=slice(0, 1), fallback=None): ModelSystem(cell=[AtomicCell(positions=positions)]) ) + ##################################################### + # Get the energy data from the raw simulation files # + ##################################################### total_energy = xml_get("i[@name='e_fr_energy']", slice(-2, -1)) - total_energy = total_energy[0] if total_energy else None + total_energy = total_energy[0] * ureg.eV if total_energy else None hartreedc = xml_get("i[@name='hartreedc']", slice(-2, -1)) - hartreedc = hartreedc[0] if hartreedc else None + hartreedc = hartreedc[0] * ureg.eV if hartreedc else None xcdc = xml_get("i[@name='XCdc']", slice(-2, -1)) - xcdc = xcdc[0] if xcdc else None + xcdc = xcdc[0] * ureg.eV if xcdc else None + #################################################### + # Create the outputs section, populate it with the # + # parsed energies, and add it to the archive # + #################################################### output = Outputs() archive.data.outputs.append(output) - output.total_energy.append(TotalEnergy(value=total_energy * ureg.eV)) + output.total_energy.append(TotalEnergy(value=total_energy)) + output.total_energy[0].contributions.append(HartreeDCEnergy(value=hartreedc)) + output.total_energy[0].contributions.append(XCdcEnergy(value=xcdc)) + + ############################################################## + # Add a new contribution to the total energy that quantifies # + # its unknown contributions (3 ways, choose 1) # + ############################################################## + + # Case 1: Add UnknownEnergy to contribution list in the parser with a value + from nomad_parser_vasp.schema_packages.vasp_schema import UnknownEnergy output.total_energy[0].contributions.append( - HartreeDCEnergy(value=hartreedc * ureg.eV) + UnknownEnergy(value=(total_energy - hartreedc - xcdc)) ) - output.total_energy[0].contributions.append(XCdcEnergy(value=xcdc * ureg.eV)) + # Expected Results: normalizer does not change the value of UnknownEnergy + + # Case 2: Add UnknownEnergy to contribution list in the parser but without a value + # from nomad_parser_vasp.schema_packages.vasp_schema import UnknownEnergy + + # output.total_energy[0].contributions.append(UnknownEnergy(value=None)) + # Expected Results: UnknownEnergy value is calculated by the normalizer and placed into this section - output.total_energy[0].contributions.append(UnknownEnergy(value=None)) + # Case 3: Don't include UnknownEnergy in parsing + # Expected Results: UnknownEnergy is added to contribution list by the normalizer diff --git a/src/nomad_parser_vasp/schema_packages/vasp_schema.py b/src/nomad_parser_vasp/schema_packages/vasp_schema.py index 9ddd497..339e35b 100644 --- a/src/nomad_parser_vasp/schema_packages/vasp_schema.py +++ b/src/nomad_parser_vasp/schema_packages/vasp_schema.py @@ -58,15 +58,23 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: return value = self.value + unknown_exists = False + unknown_has_value = False i_unknown = None for i_cont, contribution in enumerate(self.contributions): if contribution.name == 'UnknownEnergy': + unknown_exists = True i_unknown = i_cont + unknown_has_value = True if contribution.value else False if not contribution.value: continue value -= contribution.value - if i_unknown: - self.contributions[i_unknown].value = value + if unknown_exists: + if not unknown_has_value: + self.contributions[i_unknown].value = value + else: + self.contributions.append(UnknownEnergy(value=value)) + self.contributions[-1].normalize(archive, logger)