Skip to content

Commit

Permalink
Fixed KLinePath and KMesh points refs
Browse files Browse the repository at this point in the history
Fixed bulk condition in resolve_reciprocal_lattice_vectors
  • Loading branch information
JosePizarro3 committed May 27, 2024
1 parent a31b1f1 commit 0b83221
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 79 deletions.
4 changes: 0 additions & 4 deletions src/nomad_simulations/numerical_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,10 +806,6 @@ def resolve_reciprocal_lattice_vectors(
# General checks to proceed with normalization
if is_not_representative(model_system, logger):
continue
# TODO extend this for other dimensions (@ndaelman-hu)
if model_system.type != 'bulk':
logger.warning('`ModelSystem.type` is not describing a bulk system.')
continue

atomic_cell = model_system.cell
if atomic_cell is None:
Expand Down
40 changes: 6 additions & 34 deletions src/nomad_simulations/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Variables(ArchiveSection):
""",
)

# points_error = Quantity()
# ? Do we need to add `points_error`?

def get_n_points(self, logger: BoundLogger) -> Optional[int]:
"""
Expand Down Expand Up @@ -160,21 +160,13 @@ def normalize(self, archive, logger) -> None:
class KMesh(Variables):
"""
K-point mesh over which the physical property is calculated. This is used to define `ElectronicEigenvalues(PhysicalProperty)` and
other k-space properties. The `points` are obtained from a refernece to the `NumericalSettings` section, `KMesh(NumericalSettings)`.
other k-space properties. The `points` are obtained from a reference to the `NumericalSettings` section, `KMesh(NumericalSettings)`.
"""

k_mesh_settings_ref = Quantity(
type=KMeshSettings,
description="""
Reference to the `KMesh(NumericalSettings)` section in the `ModelMethod` section. This reference is useful
to extract `points` and, then, obtain the shape of `value` of the `PhysicalProperty`.
""",
)

points = Quantity(
type=KMeshSettings.points,
type=KMeshSettings.points, # ! fix this (it is not working in parsers!)
description="""
Reference to the `KMesh.points` over which the physical property is calculated. These are 3D arrays stored in fractional coordinates.
Reference to the `KMeshSettings.points` over which the physical property is calculated. These are 3D arrays stored in fractional coordinates.
""",
)

Expand All @@ -185,30 +177,16 @@ def __init__(
self.name = self.m_def.name

def normalize(self, archive, logger) -> None:
# Extracting `points` from the `k_mesh_settings_ref` BEFORE doing `super().normalize()`
if self.k_mesh_settings_ref is None:
logger.error('`k_mesh_settings_ref` is not defined.')
return
self.points = self.k_mesh_settings_ref # ref to `points`

super().normalize(archive, logger)


class KLinePath(Variables):
""" """

k_line_path_settings_ref = Quantity(
type=KLinePathSettings,
description="""
Reference to the `KLinePath(NumericalSettings)` section in the `ModelMethod.KMesh` section. This reference is useful
to extract `points` and, then, obtain the shape of `value` of the `PhysicalProperty`.
""",
)

points = Quantity(
type=KLinePathSettings.points,
type=KLinePathSettings.points, # ! fix this (it is not working in parsers!)
description="""
Reference to the `KLinePath.points` in which the physical property is calculated. These are 3D arrays stored in fractional coordinates.
Reference to the `KLinePathSettings.points` in which the physical property is calculated. These are 3D arrays stored in fractional coordinates.
""",
)

Expand All @@ -219,10 +197,4 @@ def __init__(
self.name = self.m_def.name

def normalize(self, archive, logger) -> None:
# Extracting `points` from the `k_line_path_settings_ref` BEFORE doing `super().normalize()`
if self.k_line_path_settings_ref is None:
logger.error('`k_line_path_settings_ref` is not defined.')
return
self.points = self.k_line_path_settings_ref # ref to `points`

super().normalize(archive, logger)
42 changes: 1 addition & 41 deletions tests/test_numerical_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# limitations under the License.
#

import pytest
import numpy as np
<<<<<<< HEAD
from typing import Optional, List

from nomad.units import ureg
Expand Down Expand Up @@ -277,22 +277,13 @@ def test_resolve_k_line_density(
)
else:
assert k_line_density == result_k_line_density
=======

from nomad.units import ureg

from nomad_simulations.numerical_settings import KLinePath
>>>>>>> bfb33bc (Deprecated KLineSegments for KLinePath)

from . import logger


class TestKLinePath:
"""
Test the `KLinePath` class defined in `numerical_settings.py`.
"""

<<<<<<< HEAD
@pytest.mark.parametrize(
'high_symmetry_path_names, high_symmetry_path_values, result',
[
Expand Down Expand Up @@ -367,48 +358,17 @@ def test_get_high_symmetry_path_norm(self, k_line_path: KLinePath):
hs_points = [0, 0.5, 0.5 + 1 / np.sqrt(2), 1 + 1 / np.sqrt(2)]
for i, val in enumerate(hs_points):
assert np.isclose(high_symmetry_path_norms[i].magnitude, val)
=======
def test_get_high_symmetry_points_norm(self, k_line_path: KLinePath):
"""
Test the `get_high_symmetry_points_norm` method.
"""
rlv = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) * ureg('1/meter')
high_symmetry_points_norms = k_line_path.get_high_symmetry_points_norm(
reciprocal_lattice_vectors=rlv
)
hs_points = {
'Gamma1': 0,
'X': 0.5,
'Y': 0.5 + 1 / np.sqrt(2),
'Gamma2': 1 + 1 / np.sqrt(2),
}
for key, val in hs_points.items():
assert np.isclose(high_symmetry_points_norms[key].magnitude, val)
>>>>>>> bfb33bc (Deprecated KLineSegments for KLinePath)

def test_resolve_points(self, k_line_path: KLinePath):
"""
Test the `resolve_points` method.
"""
rlv = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) * ureg('1/meter')
<<<<<<< HEAD
hs_points = [0, 0.5, 0.5 + 1 / np.sqrt(2), 1 + 1 / np.sqrt(2)]
# Define paths
gamma_x = np.linspace(hs_points[0], hs_points[1], num=5)
x_y = np.linspace(hs_points[1], hs_points[2], num=5)
y_gamma = np.linspace(hs_points[2], hs_points[3], num=5)
=======
hs_points = {
'Gamma1': 0,
'X': 0.5,
'Y': 0.5 + 1 / np.sqrt(2),
'Gamma2': 1 + 1 / np.sqrt(2),
}
# Define paths
gamma_x = np.linspace(hs_points['Gamma1'], hs_points['X'], num=5)
x_y = np.linspace(hs_points['X'], hs_points['Y'], num=5)
y_gamma = np.linspace(hs_points['Y'], hs_points['Gamma2'], num=5)
>>>>>>> bfb33bc (Deprecated KLineSegments for KLinePath)
points_norm = np.concatenate((gamma_x, x_y, y_gamma))
k_line_path.resolve_points(
points_norm=points_norm, reciprocal_lattice_vectors=rlv, logger=logger
Expand Down

0 comments on commit 0b83221

Please sign in to comment.