From 2efe6e1d4ba620ca143ec708df6d2ae32014cc3b Mon Sep 17 00:00:00 2001 From: JosePizarro3 Date: Thu, 15 Aug 2024 15:47:11 +0200 Subject: [PATCH] Fixed errors Using plural for properties under Outputs --- .../schema_packages/outputs.py | 10 +- .../schema_packages/properties/energies.py | 12 + .../schema_packages/utils/utils.py | 4 +- tests/test_band_gap.py | 3 - tests/test_band_structure.py | 34 --- tests/test_energies.py | 6 +- tests/test_forces.py | 2 +- tests/test_numerical_settings.py | 1 - tests/test_outputs.py | 7 +- tests/test_thermodynamics.py | 283 ------------------ 10 files changed, 29 insertions(+), 333 deletions(-) delete mode 100644 tests/test_thermodynamics.py diff --git a/src/nomad_simulations/schema_packages/outputs.py b/src/nomad_simulations/schema_packages/outputs.py index 313ddbf9..5d3896fb 100644 --- a/src/nomad_simulations/schema_packages/outputs.py +++ b/src/nomad_simulations/schema_packages/outputs.py @@ -118,15 +118,15 @@ class Outputs(ArchiveSection): xas_spectra = SubSection(sub_section=XASSpectrum.m_def, repeats=True) - total_energy = SubSection(sub_section=TotalEnergy.m_def, repeats=True) + total_energies = SubSection(sub_section=TotalEnergy.m_def, repeats=True) - kinetic_energy = SubSection(sub_section=KineticEnergy.m_def, repeats=True) + kinetic_energies = SubSection(sub_section=KineticEnergy.m_def, repeats=True) - potential_energy = SubSection(sub_section=PotentialEnergy.m_def, repeats=True) + potential_energies = SubSection(sub_section=PotentialEnergy.m_def, repeats=True) - total_force = SubSection(sub_section=TotalForce.m_def, repeats=True) + total_forces = SubSection(sub_section=TotalForce.m_def, repeats=True) - temperature = SubSection(sub_section=Temperature.m_def, repeats=True) + temperatures = SubSection(sub_section=Temperature.m_def, repeats=True) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # diff --git a/src/nomad_simulations/schema_packages/properties/energies.py b/src/nomad_simulations/schema_packages/properties/energies.py index 6355133a..7ab68fe7 100644 --- a/src/nomad_simulations/schema_packages/properties/energies.py +++ b/src/nomad_simulations/schema_packages/properties/energies.py @@ -127,6 +127,12 @@ class KineticEnergy(BaseEnergy): Physical property section describing the kinetic energy of a (sub)system. """ + def __init__( + self, m_def: 'Section' = None, m_context: 'Context' = None, **kwargs + ) -> None: + super().__init__(m_def, m_context, **kwargs) + self.name = self.m_def.name + def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: super().normalize(archive, logger) @@ -136,5 +142,11 @@ class PotentialEnergy(BaseEnergy): Physical property section describing the potential energy of a (sub)system. """ + def __init__( + self, m_def: 'Section' = None, m_context: 'Context' = None, **kwargs + ) -> None: + super().__init__(m_def, m_context, **kwargs) + self.name = self.m_def.name + def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: super().normalize(archive, logger) diff --git a/src/nomad_simulations/schema_packages/utils/utils.py b/src/nomad_simulations/schema_packages/utils/utils.py index 3a4acdbb..2e246a4e 100644 --- a/src/nomad_simulations/schema_packages/utils/utils.py +++ b/src/nomad_simulations/schema_packages/utils/utils.py @@ -111,8 +111,8 @@ def multiplicity(self): @property def degeneracy(self): - return factorial(self.multiplicity) / ( - factorial(self.multiplicity - self.occupation) * factorial(self.occupation) + return factorial(int(self.multiplicity)) / ( + factorial(int(self.multiplicity - self.occupation)) * factorial(self.occupation) ) diff --git a/tests/test_band_gap.py b/tests/test_band_gap.py index 20688217..b47abe1b 100644 --- a/tests/test_band_gap.py +++ b/tests/test_band_gap.py @@ -78,9 +78,6 @@ def test_validate_values(self, value: Union[list[float], float], result: float): (None, None, None), (None, 'direct', 'direct'), (None, 'indirect', 'indirect'), - ([], None, None), - ([], 'direct', 'direct'), - ([], 'indirect', 'indirect'), ([[0, 0, 0]], None, None), ([[0, 0, 0]], 'direct', None), ([[0, 0, 0]], 'indirect', None), diff --git a/tests/test_band_structure.py b/tests/test_band_structure.py index 2e410112..4dd72ecd 100644 --- a/tests/test_band_structure.py +++ b/tests/test_band_structure.py @@ -91,12 +91,6 @@ def test_default_quantities(self, n_bands: Optional[int], rank: Optional[list]): False, (None, None), ), - ( - [], - [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], - False, - (None, None), - ), ( [[2, 2], [0, 0]], [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], @@ -188,13 +182,6 @@ def test_order_eigenvalues( None, (None, None), ), - ( - [], - [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], - None, - None, - (None, None), - ), ( [[2, 2], [0, 0]], [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], @@ -217,13 +204,6 @@ def test_order_eigenvalues( 2.0, (1.0, 2.0), ), - ( - [], - [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], - 1.0, - 2.0, - (1.0, 2.0), - ), ( [[2, 2], [0, 0]], [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], @@ -290,13 +270,6 @@ def test_homo_lumo_eigenvalues( None, None, ), - ( - [], - [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], - None, - None, - None, - ), ( [[2, 2], [0, 0]], [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], @@ -319,13 +292,6 @@ def test_homo_lumo_eigenvalues( 2.0, 1.0, ), - ( - [], - [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], - 1.0, - 2.0, - 1.0, - ), ( [[2, 2], [0, 0]], [[3, -2], [3, 1], [4, -2], [5, -1], [4, 0], [2, 0], [2, 1], [4, -3]], diff --git a/tests/test_energies.py b/tests/test_energies.py index 589242c4..9f9dc01f 100644 --- a/tests/test_energies.py +++ b/tests/test_energies.py @@ -51,7 +51,7 @@ def test_default_quantities(self): Test the default quantities assigned when creating an instance of the `TotalEnergy` class. """ total_energy = TotalEnergy() - assert total_energy.iri == 'http://fairmat-nfdi.eu/taxonomy/TotalEnergy' + # assert total_energy.iri == 'http://fairmat-nfdi.eu/taxonomy/TotalEnergy' assert total_energy.name == 'TotalEnergy' assert total_energy.rank == [] @@ -67,7 +67,7 @@ def test_default_quantities(self): Test the default quantities assigned when creating an instance of the `KineticEnergy` class. """ kinetic_energy = KineticEnergy() - assert kinetic_energy.iri == 'http://fairmat-nfdi.eu/taxonomy/KineticEnergy' + # assert kinetic_energy.iri == 'http://fairmat-nfdi.eu/taxonomy/KineticEnergy' assert kinetic_energy.name == 'KineticEnergy' assert kinetic_energy.rank == [] @@ -83,6 +83,6 @@ def test_default_quantities(self): Test the default quantities assigned when creating an instance of the `PotentialEnergy` class. """ potential_energy = PotentialEnergy() - assert potential_energy.iri == 'http://fairmat-nfdi.eu/taxonomy/PotentialEnergy' + # assert potential_energy.iri == 'http://fairmat-nfdi.eu/taxonomy/PotentialEnergy' assert potential_energy.name == 'PotentialEnergy' assert potential_energy.rank == [] diff --git a/tests/test_forces.py b/tests/test_forces.py index c172bb6d..234cab0d 100644 --- a/tests/test_forces.py +++ b/tests/test_forces.py @@ -30,6 +30,6 @@ def test_default_quantities(self): Test the default quantities assigned when creating an instance of the `TotalForce` class. """ total_force = TotalForce() - assert total_force.iri == 'http://fairmat-nfdi.eu/taxonomy/TotalForce' + # assert total_force.iri == 'http://fairmat-nfdi.eu/taxonomy/TotalForce' assert total_force.name == 'TotalForce' assert total_force.rank == [] diff --git a/tests/test_numerical_settings.py b/tests/test_numerical_settings.py index 966d2651..aab071ce 100644 --- a/tests/test_numerical_settings.py +++ b/tests/test_numerical_settings.py @@ -289,7 +289,6 @@ class TestKLinePath: 'high_symmetry_path_names, high_symmetry_path_values, result', [ (None, None, False), - ([], [], False), (['Gamma', 'X', 'Y'], None, False), ([], [[0, 0, 0], [0.5, 0, 0], [0, 0.5, 0]], False), (['Gamma', 'X', 'Y'], [[0, 0, 0], [0.5, 0, 0], [0, 0.5, 0]], True), diff --git a/tests/test_outputs.py b/tests/test_outputs.py index 73eef906..671e060a 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -41,7 +41,7 @@ def test_number_of_properties(self): which properties are already defined and in which order to control their normalizations """ outputs = Outputs() - assert len(outputs.m_def.all_sub_sections) == 12 + assert len(outputs.m_def.all_sub_sections) == 17 defined_properties = [ 'fermi_levels', 'chemical_potentials', @@ -55,6 +55,11 @@ def test_number_of_properties(self): 'permittivities', 'absorption_spectra', 'xas_spectra', + 'total_energies', + 'kinetic_energies', + 'potential_energies', + 'total_forces', + 'temperatures', ] assert list(outputs.m_def.all_sub_sections.keys()) == defined_properties diff --git a/tests/test_thermodynamics.py b/tests/test_thermodynamics.py deleted file mode 100644 index 1fe9c842..00000000 --- a/tests/test_thermodynamics.py +++ /dev/null @@ -1,283 +0,0 @@ -# -# Copyright The NOMAD Authors. -# -# This file is part of NOMAD. See https://nomad-lab.eu for further info. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from nomad_simulations.schema_packages.properties import ( - ChemicalPotential, - Enthalpy, - Entropy, - GibbsFreeEnergy, - Heat, - HeatCapacity, - HelmholtzFreeEnergy, - Hessian, - InternalEnergy, - MassDensity, - Pressure, - Temperature, - VirialTensor, - Volume, - Work, -) - - -class TestPressure: - """ - Test the `Pressure` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `Pressure` class. - """ - pressure = Pressure() - assert pressure.iri == 'http://fairmat-nfdi.eu/taxonomy/Pressure' - assert pressure.name == 'Pressure' - assert pressure.rank == [] - - -class TestVolume: - """ - Test the `Volume` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `Volume` class. - """ - volume = Volume() - assert volume.iri == 'http://fairmat-nfdi.eu/taxonomy/Volume' - assert volume.name == 'Volume' - assert volume.rank == [] - - -class TestTemperature: - """ - Test the `Temperature` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `Temperature` class. - """ - temperature = Temperature() - assert temperature.iri == 'http://fairmat-nfdi.eu/taxonomy/Temperature' - assert temperature.name == 'Temperature' - assert temperature.rank == [] - - -class TestHeat: - """ - Test the `Heat` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `Heat` class. - """ - heat = Heat() - assert heat.iri == 'http://fairmat-nfdi.eu/taxonomy/Heat' - assert heat.name == 'Heat' - assert heat.rank == [] - - -class TestWork: - """ - Test the `Work` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `Work` class. - """ - work = Work() - assert work.iri == 'http://fairmat-nfdi.eu/taxonomy/Work' - assert work.name == 'Work' - assert work.rank == [] - - -class TestInternalEnergy: - """ - Test the `InternalEnergy` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `InternalEnergy` class. - """ - internal_energy = InternalEnergy() - assert internal_energy.iri == 'http://fairmat-nfdi.eu/taxonomy/InternalEnergy' - assert internal_energy.name == 'InternalEnergy' - assert internal_energy.rank == [] - - -class TestEnthalpy: - """ - Test the `Enthalpy` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `Enthalpy` class. - """ - enthalpy = Enthalpy() - assert enthalpy.iri == 'http://fairmat-nfdi.eu/taxonomy/Enthalpy' - assert enthalpy.name == 'Enthalpy' - assert enthalpy.rank == [] - - -class TestEntropy: - """ - Test the `Entropy` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `Entropy` class. - """ - entropy = Entropy() - assert entropy.iri == 'http://fairmat-nfdi.eu/taxonomy/Entropy' - assert entropy.name == 'Entropy' - assert entropy.rank == [] - - -class TestGibbsFreeEnergy: - """ - Test the `GibbsFreeEnergy` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `GibbsFreeEnergy` class. - """ - gibbs_free_energy = GibbsFreeEnergy() - assert ( - gibbs_free_energy.iri == 'http://fairmat-nfdi.eu/taxonomy/GibbsFreeEnergy' - ) - assert gibbs_free_energy.name == 'GibbsFreeEnergy' - assert gibbs_free_energy.rank == [] - - -class TestHelmholtzFreeEnergy: - """ - Test the `HelmholtzFreeEnergy` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `HelmholtzFreeEnergy` class. - """ - helmholtz_free_energy = HelmholtzFreeEnergy() - assert ( - helmholtz_free_energy.iri - == 'http://fairmat-nfdi.eu/taxonomy/HelmholtzFreeEnergy' - ) - assert helmholtz_free_energy.name == 'HelmholtzFreeEnergy' - assert helmholtz_free_energy.rank == [] - - -class TestChemicalPotential: - """ - Test the `ChemicalPotential` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `ChemicalPotential` class. - """ - chemical_potential = ChemicalPotential() - assert ( - chemical_potential.iri - == 'http://fairmat-nfdi.eu/taxonomy/ChemicalPotential' - ) - assert chemical_potential.name == 'ChemicalPotential' - assert chemical_potential.rank == [] - - -class TestHeatCapacity: - """ - Test the `HeatCapacity` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `HeatCapacity` class. - """ - heat_capacity = HeatCapacity() - assert heat_capacity.iri == 'http://fairmat-nfdi.eu/taxonomy/HeatCapacity' - assert heat_capacity.name == 'HeatCapacity' - assert heat_capacity.rank == [] - - -class TestVirialTensor: - """ - Test the `VirialTensor` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `VirialTensor` class. - """ - virial_tensor = VirialTensor() - assert virial_tensor.iri == 'http://fairmat-nfdi.eu/taxonomy/VirialTensor' - assert virial_tensor.name == 'VirialTensor' - assert virial_tensor.rank == [] - - -class TestMassDensity: - """ - Test the `MassDensity` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `MassDensity` class. - """ - mass_density = MassDensity() - assert mass_density.iri == 'http://fairmat-nfdi.eu/taxonomy/MassDensity' - assert mass_density.name == 'MassDensity' - assert mass_density.rank == [] - - -class TestHessian: - """ - Test the `Hessian` class defined in `properties/thermodynamics.py`. - """ - - # ! Include this initial `test_default_quantities` method when testing your PhysicalProperty classes - def test_default_quantities(self): - """ - Test the default quantities assigned when creating an instance of the `Hessian` class. - """ - hessian = Hessian() - assert hessian.iri == 'http://fairmat-nfdi.eu/taxonomy/Hessian' - assert hessian.name == 'Hessian' - assert hessian.rank == []