Skip to content

Commit

Permalink
added force contributions, fixed energies, import changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudz committed Jun 17, 2024
1 parent 454cd9f commit 569ef02
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 68 deletions.
10 changes: 8 additions & 2 deletions src/nomad_simulations/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
AbsorptionSpectrum,
XASSpectrum,
Permittivity,
TotalEnergy
TotalEnergy,
TotalForce,
)


Expand Down Expand Up @@ -112,7 +113,9 @@ class Outputs(ArchiveSection):

xas_spectra = SubSection(sub_section=XASSpectrum.m_def, repeats=True)

total_energy = SubSection(SubSection=TotalEnergy.m_def, repeats=True)
total_energy = SubSection(sub_section=TotalEnergy.m_def, repeats=True)

total_force = SubSection(sub_section=TotalForce.m_def, repeats=True)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down Expand Up @@ -296,6 +299,7 @@ def normalize(self, archive, logger) -> None:
logger=logger,
)


class WorkflowOutputs(Outputs):
"""
This section contains output properties that depend on a single system, but were
Expand All @@ -320,6 +324,7 @@ class WorkflowOutputs(Outputs):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class TrajectoryOutputs(WorkflowOutputs):
"""
This section contains output properties that depend on a single system, but were
Expand All @@ -328,6 +333,7 @@ class TrajectoryOutputs(WorkflowOutputs):

time = Quantity(
type=np.float64,
unit='ps',
description="""
The elapsed simulated physical time since the start of the trajectory.
""",
Expand Down
2 changes: 1 addition & 1 deletion src/nomad_simulations/physical_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,4 @@ def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)

# Resolve if the physical property `is_derived` or not from another physical property.
self.is_derived = self._is_derived()
self.is_derived = self._is_derived()
1 change: 1 addition & 0 deletions src/nomad_simulations/properties/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
ClassicalEnergyContributions,
QuantumEnergyContributions,
)
from .forces import TotalForce, ForceContributions
from .band_gap import ElectronicBandGap
from .spectral_profile import (
SpectralProfile,
Expand Down
72 changes: 58 additions & 14 deletions src/nomad_simulations/properties/energies.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import numpy as np

from nomad.metainfo import Quantity, Section, Context, SubSection, MEnum
from nomad.datamodel.data import ArchiveSection

from nomad_simulations.physical_property import PhysicalProperty


class FermiLevel(PhysicalProperty):
"""
Energy required to add or extract a charge from a material at zero temperature. It can be also defined as the chemical potential at zero temperature.
Expand Down Expand Up @@ -82,6 +84,7 @@ def normalize(self, archive, logger) -> None:
# List of classical energy contribuions
####################################################


class PotentialEnergy(PhysicalProperty):
"""
Section containing the potential energy of a (sub)system.
Expand All @@ -98,6 +101,7 @@ class PotentialEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class KineticEnergy(PhysicalProperty):
"""
Section containing the kinetic energy of a (sub)system.
Expand Down Expand Up @@ -152,6 +156,7 @@ class VDWEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class ElectrostaticEnergy(PhysicalProperty):
"""
Section containing all electrostatic contributions to the potential energy of a (sub)system.
Expand All @@ -168,6 +173,7 @@ class ElectrostaticEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class ElectrostaticShortRangeEnergy(PhysicalProperty):
"""
Section containing short-range electrostatic contributions to the potential energy of a (sub)system.
Expand All @@ -184,6 +190,7 @@ class ElectrostaticShortRangeEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class ElectrostaticLongRangeEnergy(PhysicalProperty):
"""
Section containing long-range electrostatic contributions to the potential energy of a (sub)system.
Expand All @@ -200,6 +207,7 @@ class ElectrostaticLongRangeEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class BondedEnergy(PhysicalProperty):
"""
Section containing all bonded (i.e., intramolecular) contributions to the potential energy of a (sub)system.
Expand All @@ -216,6 +224,7 @@ class BondedEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class BondEnergy(PhysicalProperty):
"""
Section containing contributions to the potential energy from bond interactions of a (sub)system.
Expand All @@ -232,6 +241,7 @@ class BondEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class AngleEnergy(PhysicalProperty):
"""
Section containing contributions to the potential energy from angle interactions of a (sub)system.
Expand All @@ -248,6 +258,7 @@ class AngleEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class DihedralEnergy(PhysicalProperty):
"""
Section containing contributions to the potential energy from dihedral interactions of a (sub)system.
Expand All @@ -264,6 +275,7 @@ class DihedralEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class ImproperDihedralEnergy(PhysicalProperty):
"""
Section containing contributions to the potential energy from improper dihedral interactions of a (sub)system.
Expand All @@ -280,6 +292,7 @@ class ImproperDihedralEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class ExternalEnergy(PhysicalProperty):
"""
Section containing contributions to the potential energy from external interactions of a (sub)system.
Expand All @@ -296,6 +309,7 @@ class ExternalEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class ClassicalEnergyContributions(ArchiveSection):
"""
Section containing contributions to the potential energy from a classical force field.
Expand All @@ -309,9 +323,13 @@ class ClassicalEnergyContributions(ArchiveSection):

electrostatic = SubSection(sub_section=ElectrostaticEnergy.m_def, repeats=False)

electrostatic_short_range = SubSection(sub_section=ElectrostaticShortRangeEnergy.m_def, repeats=False)
electrostatic_short_range = SubSection(
sub_section=ElectrostaticShortRangeEnergy.m_def, repeats=False
)

electrostatic_long_range = SubSection(sub_section=ElectrostaticLongRangeEnergy.m_def, repeats=False)
electrostatic_long_range = SubSection(
sub_section=ElectrostaticLongRangeEnergy.m_def, repeats=False
)

bonded = SubSection(sub_section=BondedEnergy.m_def, repeats=False)

Expand All @@ -321,7 +339,9 @@ class ClassicalEnergyContributions(ArchiveSection):

dihedral = SubSection(sub_section=DihedralEnergy.m_def, repeats=False)

improper_dihedral = SubSection(sub_section=ImproperDihedralEnergy.m_def, repeats=False)
improper_dihedral = SubSection(
sub_section=ImproperDihedralEnergy.m_def, repeats=False
)

external = SubSection(sub_section=ExternalEnergy.m_def, repeats=False)

Expand All @@ -330,10 +350,12 @@ def normalize(self, archive, logger) -> None:
# Set the name of the section
self.name = self.m_def.name


######################################
# List of quantum energy contributions
######################################


class ElectronicEnergy(PhysicalProperty):
"""
Section containing the electronic energy of a (sub)system.
Expand All @@ -347,12 +369,11 @@ class ElectronicEnergy(PhysicalProperty):
""",
)

contributions = SubSection(sub_section=EnergyContributions.m_def, repeats=True)

def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)
allowed_contributions = ['PotKin']


class ElectronicKineticEnergy(PhysicalProperty):
"""
Section containing the electronic kinetic energy of a (sub)system.
Expand All @@ -369,11 +390,13 @@ class ElectronicKineticEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class XCEnergy(PhysicalProperty):
"""
Section containing the exchange-correlation (XC) energy of a (sub)system,
calculated using the functional stored in XC_functional.
"""

# ! Someone check this description!
# ? Do we really want to specify the method here? This can't be user-defined?

Expand All @@ -388,6 +411,7 @@ class XCEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class XCPotentialEnergy(PhysicalProperty):
"""
Section containing the potential energy contribution to the exchange-correlation (XC) energy,
Expand All @@ -396,6 +420,7 @@ class XCPotentialEnergy(PhysicalProperty):
of XC that is in the sum of the eigenvalues. Value associated with the
configuration, should be the most converged value. |
"""

# ! Someone check this description!
# ? Do we really want to specify the method here? This can't be user-defined?

Expand All @@ -410,12 +435,14 @@ class XCPotentialEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


# ? XCCorrelationEnergy?
class CorrelationEnergy(PhysicalProperty):
"""
Section containing the correlation energy of a (sub)system,
calculated using the method described in XC_functional.
"""

# ! Someone check this description!
# ? Do we really want to specify the method here? This can't be user-defined?

Expand All @@ -430,12 +457,14 @@ class CorrelationEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


# ? XCExchangeEnergy?
class ExchangeEnergy(PhysicalProperty):
"""
Section containing the exchange energy of a (sub)system,
calculated using the method described in XC_functional.
"""

# ! Someone check this description!
# ? Do we really want to specify the method here? This can't be user-defined?

Expand Down Expand Up @@ -468,11 +497,13 @@ class ZeroTemperatureEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class ZeroPointEnergy(PhysicalProperty):
"""
Section containing the zero-point vibrational energy of a (sub)system,
calculated using the method described in zero_point_method.
"""

# ! Someone check this description!
# ? Do we really want to specify the method here? This can't be user-defined?

Expand All @@ -487,6 +518,7 @@ class ZeroPointEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class ElectrostaticEnergy(PhysicalProperty):
"""
Section containing the electrostatic energy (nuclei + electrons) of a (sub)system.
Expand All @@ -503,6 +535,7 @@ class ElectrostaticEnergy(PhysicalProperty):
def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)


class NuclearRepulsionEnergy(PhysicalProperty):
"""
Section containing the nuclear-nuclear repulsion energy of a (sub)system.
Expand All @@ -524,11 +557,14 @@ class QuantumEnergyContributions(ArchiveSection):
"""
Section containing contributions to the potential energy from a DFT calculation.
"""
...

...

electronic = SubSection(sub_section=ElectronicEnergy.m_def, repeats=False)

electronic_kinetic = SubSection(sub_section=ElectronicKineticEnergy.m_def, repeats=False)
electronic_kinetic = SubSection(
sub_section=ElectronicKineticEnergy.m_def, repeats=False
)

xc = SubSection(sub_section=XCEnergy.m_def, repeats=False)

Expand All @@ -538,18 +574,24 @@ class QuantumEnergyContributions(ArchiveSection):

exchange = SubSection(sub_section=ExchangeEnergy.m_def, repeats=False)

zero_temperature = SubSection(sub_section=ZeroTemperatureEnergy.m_def, repeats=False)
zero_temperature = SubSection(
sub_section=ZeroTemperatureEnergy.m_def, repeats=False
)

zero_point = SubSection(sub_section=ZeroPointEnergy.m_def, repeats=False)

electrostatic = SubSection(sub_section=ElectrostaticEnergy.m_def, repeats=False)

nuclear_repulsion = SubSection(sub_section=NuclearRepulsionEnergy.m_def, repeats=False)
nuclear_repulsion = SubSection(
sub_section=NuclearRepulsionEnergy.m_def, repeats=False
)


##########################
# Other / General energies
##########################


class TotalEnergy(PhysicalProperty):
"""
Section containing the total energy of a (sub)system.
Expand All @@ -564,12 +606,17 @@ class TotalEnergy(PhysicalProperty):
)
# ? Do we need these descriptions under value? It ends up simply duplicating the section info to some extent.

classical_contributions = SubSection(sub_section=ClassicalEnergyContributions.m_def, repeats=False)
classical_contributions = SubSection(
sub_section=ClassicalEnergyContributions.m_def, repeats=False
)

quantum_contributions = SubSection(sub_section=QuantumEnergyContributions.m_def, repeats=False)
quantum_contributions = SubSection(
sub_section=QuantumEnergyContributions.m_def, repeats=False
)

def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)
#? Should we set total energy value as sum of all contributions if not set explicitly?

# madelung = SubSection(
# sub_section=EnergyEntry.m_def,
Expand Down Expand Up @@ -709,7 +756,6 @@ def normalize(self, archive, logger) -> None:
# """,
# )


# # TODO this should be removed and replaced by correction in EnergyEntry
# current = SubSection(
# sub_section=EnergyEntry.m_def,
Expand All @@ -723,8 +769,6 @@ def normalize(self, archive, logger) -> None:
# )




# # ? Do we want to allow this?
# class EnergyCustom(PhysicalProperty):
# """
Expand Down
Loading

0 comments on commit 569ef02

Please sign in to comment.