Metainfo update: Energy, Stress, Forces

Here are a few comments:

  1. Having a list of repeatable sections (energies, forces, stress) where the contribution type is identified by a metainfo value has some drawbacks: In order to find a specific value, you have to loop over the entire list. I think a better solution from the perspective of finding information would be to have something like this.

    class Energy(MSection):
        m_def = Section(
            validate=False,
            description="""
            Section describing a type of energy or a contribution to the total energy.
            """
        )
    
        reference = Quantity(
            type=np.dtype(np.float64),
            shape=[],
            unit='joule',
            description='''
            Value of the reference energy to be subtracted from value to obtain a
            code-independent value of the energy.
            ''')
    
        value = Quantity(
            type=np.dtype(np.float64),
            shape=[],
            unit='joule',
            description='''
            Value of the energy identified by energy_kind.
            ''')
    
        value_per_atom = Quantity(
            type=np.dtype(np.float64),
            shape=[],
            unit='joule',
            description='''
            Value of the energy normalized by the total number of atoms in the simulation cell.
            ''')
    
        values_per_atom = Quantity(
            type=np.dtype(np.float64),
            shape=['number_of_atoms'],
            unit='joule',
            description='''
            Value of the atom-resolved energies identified by energy_kind.
            ''')
    
    class EnergyTotal(Energy):
        m_def = Section(
            validate=False,
            description="""
            Contains values for the total energy.
            """
        )
    
    class EnergyKinetic(Energy):
        m_def = Section(
            validate=False,
            description="""
            Contains values for the kinetic energy.
            """
        )
    
    energy_total = SubSection(sub_section=EnergyTotal.m_def)
    energy_kinetic = SubSection(sub_section=EnergyKinetic.m_def)
    ...

    Comparing the process of finding information (in Python, but the same logic applied to Javascript used in GUI):

    1. energy_kinetic = next((x.energy_value for x in energies if x.energy_kind == "kinetic"), None)
    2. energy_kinetic = energy_kinetic.value

    This does not, however, allow easily adding new energy types, which was maybe your original purpose. But I think we should try to optimize the process of information lookups, even if we have to make storing the information a bit harder (=you just need to explicitly create metainfo sections).

  2. I'm not sure if we need the atom_-prefix used at least in atom_forces and atom_charges. It would be nice if all force-related values would start with forces_-, the same applies for charges, stresses, and energies. But this is a minor thing.

Assignee Loading
Time tracking Loading