Skip to content

Commit

Permalink
Fix testing for KMesh and KLinePath
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed May 27, 2024
1 parent b271a92 commit 53c934e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/nomad_simulations/numerical_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ def resolve_high_symmetry_path_values(

# Appending into a list which is stored in the `high_symmetry_path_values`. There is a check in the `normalize()`
# function to ensure that the length of the `high_symmetry_path_names` and `high_symmetry_path_values` coincide.
if self.high_symmetry_path_names is None:
return []
high_symmetry_path_values = [
high_symmetry_points[name]
for name in self.high_symmetry_path_names
Expand Down
54 changes: 19 additions & 35 deletions tests/test_numerical_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,20 @@ def test_resolve_points_and_offset(
assert offset == result_offset

@pytest.mark.parametrize(
'system_type, is_representative, grid, reciprocal_lattice_vectors, result_check, result_get_k_line_density, result_k_line_density',
'system_type, is_representative, grid, reciprocal_lattice_vectors, result_get_k_line_density, result_k_line_density',
[
# No `grid` and `reciprocal_lattice_vectors`
('bulk', False, None, None, False, None, None),
('bulk', False, None, None, None, None),
# No `reciprocal_lattice_vectors`
('bulk', False, [6, 6, 6], None, False, None, None),
('bulk', False, [6, 6, 6], None, None, None),
# No `grid`
('bulk', False, None, [[1, 0, 0], [0, 1, 0], [0, 0, 1]], False, None, None),
('bulk', False, None, [[1, 0, 0], [0, 1, 0], [0, 0, 1]], None, None),
# `is_representative` set to False
(
'bulk',
False,
[6, 6, 6],
[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
True,
0.954929658,
None,
),
Expand All @@ -217,7 +216,6 @@ def test_resolve_points_and_offset(
True,
[6, 6, 6],
[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
True,
0.954929658,
None,
),
Expand All @@ -227,7 +225,6 @@ def test_resolve_points_and_offset(
True,
[6, 6, 6],
[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
True,
0.954929658,
0.954929658,
),
Expand All @@ -239,13 +236,11 @@ def test_resolve_k_line_density(
is_representative: bool,
grid: Optional[List[int]],
reciprocal_lattice_vectors: Optional[List[List[float]]],
result_check: bool,
result_get_k_line_density: Optional[float],
result_k_line_density: Optional[float],
):
"""
Test the `resolve_k_line_density` and `get_k_line_density` methods, as well as the `_check_reciprocal_lattice_vectors`
private method.
Test the `resolve_k_line_density` and `get_k_line_density` methods
"""
simulation = generate_k_space_simulation(
system_type=system_type,
Expand All @@ -257,13 +252,7 @@ def test_resolve_k_line_density(
reciprocal_lattice_vectors = k_space.reciprocal_lattice_vectors
k_mesh = k_space.k_mesh[0]
model_systems = simulation.model_system
# Checking the reciprocal lattice vectors
assert (
k_mesh._check_reciprocal_lattice_vectors(
reciprocal_lattice_vectors=reciprocal_lattice_vectors, logger=logger
)
== result_check
)

# Applying method `get_k_line_density`
get_k_line_density_value = k_mesh.get_k_line_density(
reciprocal_lattice_vectors=reciprocal_lattice_vectors, logger=logger
Expand All @@ -275,6 +264,7 @@ def test_resolve_k_line_density(
)
else:
assert get_k_line_density_value == result_get_k_line_density

# Applying method `resolve_k_line_density`
k_line_density = k_mesh.resolve_k_line_density(
model_systems=model_systems,
Expand Down Expand Up @@ -320,48 +310,42 @@ def test_check_high_symmetry_path(
assert k_line_path._check_high_symmetry_path(logger) == result

@pytest.mark.parametrize(
'high_symmetry_path_names, result',
'reciprocal_lattice_vectors, high_symmetry_path_names, result',
[
(['Gamma', 'X', 'R'], [[0, 0, 0], [0, 0.5, 0], [0.5, 0.5, 0.5]]),
(None, None, []),
([[1, 0, 0], [0, 1, 0], [0, 0, 1]], None, []),
(
[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
['Gamma', 'X', 'R'],
[[0, 0, 0], [0, 0.5, 0], [0.5, 0.5, 0.5]],
),
],
)
def test_resolve_high_symmetry_path_values(
self,
reciprocal_lattice_vectors: Optional[List[List[float]]],
high_symmetry_path_names: List[str],
result: bool,
result: List[float],
):
"""
Test the `resolve_high_symmetry_path_values` method. Only testing the valid situation in which the `ModelSystem` normalization worked.
"""
# `ModelSystem.normalize()` need to extract `bulk` as a type.
simulation = generate_k_space_simulation(
pbc=[True, True, True],
reciprocal_lattice_vectors=reciprocal_lattice_vectors,
high_symmetry_path_names=high_symmetry_path_names,
high_symmetry_path_values=None,
)
model_system = simulation.model_system[0]
model_system.normalize(EntryArchive(), logger) # normalize to extract symmetry
# getting `reciprocal_lattice_vectors`
reciprocal_lattice_vectors = (
simulation.model_method[0].numerical_settings[0].reciprocal_lattice_vectors
)

# `KLinePath` can be understood as a `KMeshBase` section
k_line_path = simulation.model_method[0].numerical_settings[0].k_line_path
k_line_path.normalize(EntryArchive(), logger)
high_symmetry_points_values = k_line_path.resolve_high_symmetry_path_values(
simulation.model_system, reciprocal_lattice_vectors, logger
)
# high_symmetry_points = k_mesh_base.resolve_high_symmetry_points(
# simulation.model_system, logger
# )
# assert len(high_symmetry_points) == 4
# assert high_symmetry_points == {
# 'Gamma': [0, 0, 0],
# 'M': [0.5, 0.5, 0],
# 'R': [0.5, 0.5, 0.5],
# 'X': [0, 0.5, 0],
# }
assert high_symmetry_points_values == result

def test_get_high_symmetry_path_norm(self, k_line_path: KLinePath):
"""
Expand Down

0 comments on commit 53c934e

Please sign in to comment.