Skip to content

Commit

Permalink
Added testing
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Aug 26, 2024
1 parent f6dc836 commit 2ac054c
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from nomad.metainfo import Context, Section
from structlog.stdlib import BoundLogger

from nomad_simulations.schema_packages.variables import Variables

from nomad_simulations.schema_packages.atoms_state import AtomsState, OrbitalsState
from nomad_simulations.schema_packages.physical_property import PhysicalProperty
Expand Down Expand Up @@ -157,7 +156,7 @@ def resolve_space_id(self) -> str:
'iw': MatsubaraFrequency,
}

def find_space_id(space_map: dict[str, 'Variables']) -> str:
def find_space_id(space_map: dict) -> str:
"""
Finds the id string for a given map.
Expand All @@ -169,7 +168,7 @@ def find_space_id(space_map: dict[str, 'Variables']) -> str:
"""
for space_id, variable_cls in space_map.items():
space_variable = get_variables(variables=self.variables, variable_cls=variable_cls)
if len(space_variable) >= 0:
if len(space_variable) > 0:
return space_id
return ''

Expand Down Expand Up @@ -341,12 +340,13 @@ def __init__(

def is_valid_quasiparticle_weight(self) -> bool:
"""
Check if the quasiparticle weight values are valid, i.e., if all `value` are defined positive.
Check if the quasiparticle weight values are valid, i.e., if all `value` are defined between
0 and 1.
Returns:
(bool): True if the quasiparticle weight is valid, False otherwise.
"""
if (self.value < 0.0).any():
if (self.value < 0.0).any() or (self.value > 1.0).any():
return False
return True

Expand All @@ -363,7 +363,7 @@ def resolve_system_correlation_strengths(self) -> str:
return 'strongly-correlated metal'
elif np.any(self.value == 0) and np.any(self.value > 0):
return 'OSMI'
elif np.all(self.value == 0):
elif np.all(self.value < 1e-2):
return 'Mott insulator'
return ''

Expand Down
115 changes: 115 additions & 0 deletions tests/test_greens_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#
# 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 typing import Optional, Union

import pytest

from nomad_simulations.schema_packages.properties import (
ElectronicGreensFunction,
ElectronicSelfEnergy,
HybridizationFunction,
QuasiparticleWeight,
)
from nomad_simulations.schema_packages.properties.greens_function import (
BaseGreensFunction,
)
from nomad_simulations.schema_packages.variables import (
Frequency,
ImaginaryTime,
KMesh,
MatsubaraFrequency,
Time,
WignerSeitz,
)


class TestBaseGreensFunction:
"""
Test the `BaseGreensFunction` class defined in `properties/greens_function.py`.aa
"""

@pytest.mark.parametrize(
'variables, result',
[
([], ''),
([WignerSeitz()], 'r'),
([KMesh()], 'k'),
([Time()], 't'),
([ImaginaryTime()], 'it'),
([Frequency()], 'w'),
([MatsubaraFrequency()], 'iw'),
([WignerSeitz(), Time()], 'rt'),
([WignerSeitz(), ImaginaryTime()], 'rit'),
([WignerSeitz(), Frequency()], 'rw'),
([WignerSeitz(), MatsubaraFrequency()], 'riw'),
([KMesh(), Time()], 'kt'),
([KMesh(), ImaginaryTime()], 'kit'),
([KMesh(), Frequency()], 'kw'),
([KMesh(), MatsubaraFrequency()], 'kiw'),
],
)
def test_resolve_space_id(self, variables: list[Union[WignerSeitz, KMesh, Time, ImaginaryTime, Frequency, MatsubaraFrequency]], result: str):
"""
Test the `resolve_space_id` method of the `BaseGreensFunction` class.
"""
gfs = BaseGreensFunction(n_atoms=1, n_correlated_orbitals=1)
gfs.variables = variables
assert gfs.resolve_space_id() == result



class TestQuasiparticleWeight:
"""
Test the `QuasiparticleWeight` class defined in `properties/greens_function.py`.
"""

@pytest.mark.parametrize(
'value, result',
[
([[1, 0.5, -2]], False),
([[1, 0.5, 8]], False),
([[1, 0.5, 0.8]], True),
],
)
def test_is_valid_quasiparticle_weight(self, value: list[float], result: bool):
"""
Test the `is_valid_quasiparticle_weight` method of the `QuasiparticleWeight` class.
"""
quasiparticle_weight = QuasiparticleWeight(n_atoms=1, n_correlated_orbitals=3)
quasiparticle_weight.value = value
assert quasiparticle_weight.is_valid_quasiparticle_weight() == result


@pytest.mark.parametrize(
'value, result',
[
([[1, 0.9, 0.8]], 'non-correlated metal'),
([[0.2, 0.3, 0.1]], 'strongly-correlated metal'),
([[0, 0.3, 0.1]], 'OSMI'),
([[0, 0, 0]], 'Mott insulator'),
([[1.0, 0.8, 0.2]], ''),
],
)
def test_resolve_system_correlation_strengths(self, value: list[float], result: str):
"""
Test the `resolve_system_correlation_strengths` method of the `QuasiparticleWeight` class.
"""
quasiparticle_weight = QuasiparticleWeight(n_atoms=1, n_correlated_orbitals=3)
quasiparticle_weight.value = value
assert quasiparticle_weight.resolve_system_correlation_strengths() == result

1 comment on commit 2ac054c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py14286%53–55
   atoms_state.py1902189%31–33, 219–222, 246, 301–302, 370–371, 373, 555, 567–568, 629–633, 648–652, 659
   general.py75791%29–30, 98, 162, 272–273, 283
   model_method.py2657771%28–30, 189–192, 195–202, 294–295, 315, 336–355, 371–397, 400–417, 771, 782, 824–831, 869, 888, 968, 1025, 1100, 1214
   model_system.py2612292%43–45, 512–515, 562–569, 743–744, 965–969, 975–976, 984–985, 990, 1013
   numerical_settings.py2636575%30–32, 164, 234, 236–237, 240–243, 247–248, 255–258, 267–270, 274–277, 279–282, 287–290, 296–299, 470–497, 572, 607–610, 634, 637, 682, 684–687, 691, 695, 742, 746–767, 822–823, 890, 899–901, 904
   outputs.py1191092%27–28, 267–270, 310–313, 338, 340, 377, 396
   physical_property.py102793%38–40, 220, 349–351
   variables.py861286%26–28, 116, 139, 163, 185, 207, 229, 251, 274, 294
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%26–28, 153–154
   band_structure.py1112280%27–29, 249–282, 295, 302, 338–339, 342
   energies.py42979%25–27, 54, 75, 100, 121, 137, 152
   fermi_surface.py17476%25–27, 58
   forces.py22673%26–28, 55, 75, 98
   greens_function.py952178%25–27, 179–182, 203–204, 207, 228–229, 232, 253–254, 257, 371–380
   hopping_matrix.py29583%25–27, 76, 112
   permittivity.py48883%25–27, 115–123
   spectral_profile.py26012851%27–29, 75–78, 113–116, 217–318, 374–386, 411–414, 434, 439–442, 484–520, 544, 591–594, 610–611, 616–622
   thermodynamics.py752764%25–27, 53, 74, 90, 99, 108, 119, 128, 155, 165, 175, 190–192, 195, 211, 231–233, 236, 252, 272–274, 277
src/nomad_simulations/schema_packages/utils
   utils.py681479%26–29, 79–88, 97–98, 103, 106
TOTAL221947679% 

Tests Skipped Failures Errors Time
320 0 💤 0 ❌ 0 🔥 2.470s ⏱️

Please sign in to comment.