Functionality for easily fetching a section using a path
Currently it is quite inconvenient to add a single piece of information deep in the metainfo hierarchy, especially if this involves repeating sections.
E.g. if I want to update the band gap value in a normalizer:
if not archive.results:
archive.results = Results()
if not archive.results.properties:
archive.results.properties = Properties()
if not archive.results.properties.electronic:
archive.results.properties.electronic = ElectronicProperties()
if not archive.results.properties.electronic.band_structure:
archive.results.properties.optoelectronic.band_structure.append(BandStructure())
if not archive.results.properties.electronic.band_structure[0].band_gap:
not archive.results.properties.electronic.band_structure[0].band_gap.append(BandGap())
archive.results.properties.electronic.band_structure[0].band_gap[0].value = 5 * ureg.eV
I would propose simplifying such tasks by creating a new function for sections called m_setdefault
(in accordance with the python dict setdefault method) which would help with this. The operation above would be achieved with:
band_gap = archive.m_setdefault('results.properties.electronic.band_structure.band_gap')
band_gap.value = 5 * ureg.eV
This function create any missing sections along the path and will raise an exception if the path cannot be unambiguously resolved (e.g. there are already several repeating sections).