Skip to content

Commit

Permalink
Changed points in KMesh and KLinePath variables to be references inst…
Browse files Browse the repository at this point in the history
…ead of copy the information
  • Loading branch information
JosePizarro3 committed May 27, 2024
1 parent 53c934e commit 21426fe
Showing 1 changed file with 12 additions and 36 deletions.
48 changes: 12 additions & 36 deletions src/nomad_simulations/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,9 @@ class KMesh(Variables):
)

points = Quantity(
type=np.float64,
shape=['n_points', 'dimensionality'],
type=KMeshSettings.points,
description="""
K-point mesh over which the physical property is calculated. These are 3D arrays stored in fractional coordinates.
Reference to the `KMesh.points` over which the physical property is calculated. These are 3D arrays stored in fractional coordinates.
""",
)

Expand All @@ -185,25 +184,13 @@ def __init__(
super().__init__(m_def, m_context, **kwargs)
self.name = self.m_def.name

def extract_points(self, logger: BoundLogger) -> Optional[list]:
"""
Extract the `points` list from the `k_mesh_settings_ref` pointing to the `KMesh` section.
Args:
logger (BoundLogger): The logger to log messages.
Returns:
(Optional[list]): The `points` list.
"""
if self.k_mesh_settings_ref is not None:
if self.k_mesh_settings_ref.points is not None:
return self.k_mesh_settings_ref.points
points, _ = self.k_mesh_settings_ref.resolve_points_and_offset(logger)
return points
logger.error('`k_mesh_settings_ref` is not defined.')
return None

def normalize(self, archive, logger) -> None:
# Extracting `points` from the `k_mesh_settings_ref` BEFORE doing `super().normalize()`
self.points = self.extract_points(logger)
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)

Expand All @@ -220,10 +207,9 @@ class KLinePath(Variables):
)

points = Quantity(
type=np.float64,
shape=['n_points', 3],
type=KLinePathSettings.points,
description="""
Points along the k-line path in which the physical property is calculated. These are 3D arrays stored in fractional coordinates.
Reference to the `KLinePath.points` in which the physical property is calculated. These are 3D arrays stored in fractional coordinates.
""",
)

Expand All @@ -233,21 +219,11 @@ def __init__(
super().__init__(m_def, m_context, **kwargs)
self.name = self.m_def.name

def extract_points(self, logger: BoundLogger) -> Optional[list]:
"""
Extract the `points` list from the `k_line_path_settings_ref` pointing to the `KLinePath` section.
Args:
logger (BoundLogger): The logger to log messages.
Returns:
(Optional[list]): The `points` list.
"""
if self.k_line_path_settings_ref is not None:
return self.k_line_path_settings_ref.points
logger.error('`k_line_path_settings_ref` is not defined.')
return None

def normalize(self, archive, logger) -> None:
# Extracting `points` from the `k_line_path_settings_ref` BEFORE doing `super().normalize()`
self.points = self.extract_points(logger)
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)

0 comments on commit 21426fe

Please sign in to comment.