From 0b83221a305b0b624464f23e9aa5f3419da8f323 Mon Sep 17 00:00:00 2001 From: JosePizarro3 Date: Mon, 27 May 2024 15:24:59 +0200 Subject: [PATCH] Fixed KLinePath and KMesh points refs Fixed bulk condition in resolve_reciprocal_lattice_vectors --- src/nomad_simulations/numerical_settings.py | 4 -- src/nomad_simulations/variables.py | 40 +++----------------- tests/test_numerical_settings.py | 42 +-------------------- 3 files changed, 7 insertions(+), 79 deletions(-) diff --git a/src/nomad_simulations/numerical_settings.py b/src/nomad_simulations/numerical_settings.py index ed9410e1..5a1e9d94 100644 --- a/src/nomad_simulations/numerical_settings.py +++ b/src/nomad_simulations/numerical_settings.py @@ -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: diff --git a/src/nomad_simulations/variables.py b/src/nomad_simulations/variables.py index 0fe97d75..3627d1ed 100644 --- a/src/nomad_simulations/variables.py +++ b/src/nomad_simulations/variables.py @@ -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]: """ @@ -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. """, ) @@ -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. """, ) @@ -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) diff --git a/tests/test_numerical_settings.py b/tests/test_numerical_settings.py index 248d229c..3b780da7 100644 --- a/tests/test_numerical_settings.py +++ b/tests/test_numerical_settings.py @@ -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 @@ -277,14 +277,6 @@ 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: @@ -292,7 +284,6 @@ class TestKLinePath: Test the `KLinePath` class defined in `numerical_settings.py`. """ -<<<<<<< HEAD @pytest.mark.parametrize( 'high_symmetry_path_names, high_symmetry_path_values, result', [ @@ -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