Skip to content

Commit

Permalink
expanded normalize function for different cases and added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudz committed Jul 12, 2024
1 parent 40a54a3 commit de9744d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
42 changes: 34 additions & 8 deletions src/nomad_parser_vasp/parsers/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from nomad_parser_vasp.schema_packages.vasp_schema import (
HartreeDCEnergy,
TotalEnergy,
UnknownEnergy,
XCdcEnergy,
)

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
12 changes: 10 additions & 2 deletions src/nomad_parser_vasp/schema_packages/vasp_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit de9744d

Please sign in to comment.