Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions express/properties/non_scalar/formation_energy_references.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Any

from express.properties.non_scalar import NonScalarProperty


class FormationEnergyReferencesFromContext(NonScalarProperty):
def __init__(self, name, parser, value: Any, *args, **kwargs):
super().__init__(name, parser, *args, **kwargs)
self.value = value

def _serialize(self):
return {
"name": self.name,
"value": self.value,
}
4 changes: 4 additions & 0 deletions express/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"reference": "express.properties.scalar.thermal_correction_to_enthalpy.ThermalCorrectionToEnthalpy"
},
"surface_energy": {"reference": "express.properties.scalar.scalar_property_context.ScalarPropertyFromContext"},
"formation_energy": {"reference": "express.properties.scalar.scalar_property_context.ScalarPropertyFromContext"},
"reaction_energy_barrier": {"reference": "express.properties.scalar.reaction_energy_barrier.ReactionEnergyBarrier"},
"valence_band_offset": {"reference": "express.properties.scalar.scalar_property_context.ScalarPropertyFromContext"},
}
Expand Down Expand Up @@ -60,6 +61,9 @@
"reference": "express.properties.non_scalar.two_dimensional_plot.average_potential_profile.AveragePotentialProfile" # noqa: E501
},
"dielectric_tensor": {"reference": "express.properties.non_scalar.dielectric_tensor.DielectricTensor"},
"formation_energy_references": {
"reference": "express.properties.non_scalar.formation_energy_references.FormationEnergyReferencesFromContext"
},
"hubbard_u": {"reference": "express.properties.non_scalar.hubbard_u.HubbardU"},
"hubbard_v": {"reference": "express.properties.non_scalar.hubbard_v.HubbardV"},
"hubbard_v_nn": {"reference": "express.properties.non_scalar.hubbard_v_nn.HubbardV_NN"},
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
dependencies = [
"pymatgen>=2023.8.10",
"ase>=3.17.0",
"mat3ra-esse>=2026.3.25.post0",
"mat3ra-esse @ git+https://github.com/Exabyte-io/esse.git@9d9ab4b9e3b62c44270dc390bc339052d973696e",
"jarvis-tools>=2023.12.12",
# To avoid module 'numpy.linalg._umath_linalg' has no attribute '_ilp64' in Colab
"numpy>=1.24.4,<2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from tests.unit import UnitTestBase
from express.properties.non_scalar.formation_energy_references import FormationEnergyReferencesFromContext

COMPOUND_TOTAL_ENERGY = -522.232
COMPOUND_N_ATOMS = 4
ROWS = [
{
"label": "SiC",
"total_energy": COMPOUND_TOTAL_ENERGY,
"n_atoms": COMPOUND_N_ATOMS,
"total_energy_per_atom": COMPOUND_TOTAL_ENERGY / COMPOUND_N_ATOMS,
"precision_value": 10,
"precision_metric": "KPPRA",
}
]
EXPECTED = {
"name": "formation_energy_references",
"value": {"rows": ROWS},
}


class FormationEnergyReferencesTest(UnitTestBase):
def test_formation_energy_references(self):
property_ = FormationEnergyReferencesFromContext(
"formation_energy_references",
None,
value={"rows": ROWS},
)
self.assertDeepAlmostEqual(property_.serialize_and_validate(), EXPECTED)
27 changes: 27 additions & 0 deletions tests/unit/properties/scalar/test_formation_energy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest

from mat3ra.esse import ESSE

from tests.unit import UnitTestBase
from express.properties.scalar.scalar_property_context import ScalarPropertyFromContext

FORMATION_ENERGY = {"units": "eV/atom", "name": "formation_energy", "value": -0.123}
FORMATION_ENERGY_VALUE = -0.123
FORMATION_ENERGY_MANIFEST = ESSE().get_property_manifest("formation_energy")


@unittest.skipUnless(
FORMATION_ENERGY_MANIFEST.get("defaults", {}).get("units"),
"formation_energy manifest defaults require a newer mat3ra-esse release",
)
class FormationEnergyTest(UnitTestBase):
def setUp(self):
super().setUp()

def tearDown(self):
super().tearDown()

def test_formation_energy(self):
parser = self.get_mocked_parser("formation_energy", FORMATION_ENERGY_VALUE) # noqa : F841
property_ = ScalarPropertyFromContext("formation_energy", None, value=FORMATION_ENERGY_VALUE)
self.assertDeepAlmostEqual(property_.serialize_and_validate(), FORMATION_ENERGY)
Loading