From 0c058b32b4f0ea765db035c30bef05e40a08ad00 Mon Sep 17 00:00:00 2001 From: JosePizarro3 Date: Fri, 12 Apr 2024 14:35:23 +0200 Subject: [PATCH] Fixed IRI Added Nathan comments --- src/nomad_simulations/physical_property.py | 15 +++++++++----- src/nomad_simulations/properties/band_gap.py | 21 ++++++++++++-------- tests/test_band_gap.py | 3 ++- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/nomad_simulations/physical_property.py b/src/nomad_simulations/physical_property.py index d7ae223f..07a92f48 100644 --- a/src/nomad_simulations/physical_property.py +++ b/src/nomad_simulations/physical_property.py @@ -28,6 +28,7 @@ Section, Context, MEnum, + URL, ) from nomad.metainfo.metainfo import DirectQuantity, Dimension, _placeholder_quantity from nomad.datamodel.metainfo.basesections import Entity @@ -57,7 +58,7 @@ class PhysicalProperty(ArchiveSection): ) iri = Quantity( - type=str, + type=URL, description=""" Internationalized Resource Identifier (IRI) of the physical property defined in the FAIRmat taxonomy, https://fairmat-nfdi.github.io/fairmat-taxonomy/. @@ -195,9 +196,14 @@ def full_shape(self) -> list: @property def _new_value(self) -> Quantity: - # initialize a `_new_value` quantity copying the main attrs from the `_value` quantity (`type`, `unit`, - # `description`); this will then be used to setattr the `value` quantity to the `_new_value` one with the - # correct `shape=_full_shape` + """ + Initialize a new `Quantity` object for the `value` quantity with the correct `shape` extracted from + the `full_shape` attribute. This copies the main attributes from `value` (`type`, `description`, `unit`). + It is used in the `__setattr__` method. + + Returns: + (Quantity): The new `Quantity` object for setting the `value` quantity. + """ for quant in self.m_def.quantities: if quant.name == 'value': return Quantity( @@ -208,7 +214,6 @@ def _new_value(self) -> Quantity: def __init__(self, m_def: Section = None, m_context: Context = None, **kwargs): super().__init__(m_def, m_context, **kwargs) - # self._new_value = self._new_value def __setattr__(self, name: str, val: Any) -> None: # For the special case of `value`, its `shape` needs to be defined from `_full_shape` diff --git a/src/nomad_simulations/properties/band_gap.py b/src/nomad_simulations/properties/band_gap.py index eb4ecc1e..d30a7c19 100644 --- a/src/nomad_simulations/properties/band_gap.py +++ b/src/nomad_simulations/properties/band_gap.py @@ -21,7 +21,6 @@ import pint from typing import Optional -from nomad.units import ureg from nomad.metainfo import Quantity, MEnum, Section, Context from ..physical_property import PhysicalProperty @@ -32,13 +31,13 @@ class ElectronicBandGap(PhysicalProperty): Energy difference between the highest occupied electronic state and the lowest unoccupied electronic state. """ - iri = 'https://fairmat-nfdi.github.io/fairmat-taxonomy/#/ElectronicBandGap' + iri = 'http://fairmat-nfdi.eu/taxonomy/ElectronicBandGap' # ? can `type` change character depending on the `variables`? type = Quantity( type=MEnum('direct', 'indirect'), description=""" - Type categorization of the `ElectronicBandGap`. This quantity is directly related with `momentum_transfer` as by + Type categorization of the electronic band gap. This quantity is directly related with `momentum_transfer` as by definition, the electronic band gap is `'direct'` for zero momentum transfer (or if `momentum_transfer` is `None`) and `'indirect'` for finite momentum transfer. @@ -50,7 +49,7 @@ class ElectronicBandGap(PhysicalProperty): type=np.float64, shape=[2, 3], description=""" - If the `ElectronicBandGap` is `'indirect'`, the reciprocal momentum transfer for which the band gap is defined + If the electronic band gap is `'indirect'`, the reciprocal momentum transfer for which the band gap is defined in units of the `reciprocal_lattice_vectors`. The initial and final momentum 3D vectors are given in the first and second element. Example, the momentum transfer in bulk Si2 happens between the Γ and the (approximately) X points in the Brillouin zone; thus: @@ -63,15 +62,16 @@ class ElectronicBandGap(PhysicalProperty): spin_channel = Quantity( type=np.int32, description=""" - Spin channel of the corresponding `ElectronicBandGap`. It can take values of 0 or 1. + Spin channel of the corresponding electronic band gap. It can take values of 0 or 1. """, ) value = Quantity( type=np.float64, - unit='joule', + unit='joule', # ! this units need to be fixed when we have dynamical units description=""" - The value of the `ElectronicBandGap`. + The value of the electronic band gap. This value has to be positive, otherwise it will + be set to a 0 by the `normalize()` function. """, ) @@ -89,7 +89,9 @@ def check_negative_values(self, logger: BoundLogger) -> pint.Quantity: """ value = self.value.magnitude if not isinstance(self.value.magnitude, np.ndarray): # for scalars - value = np.array([value]) + value = np.array( + [value] + ) # ! check this when talking with Lauri and Theodore # Set the value to 0 when it is negative if (value < 0).any(): @@ -136,6 +138,9 @@ def normalize(self, archive, logger) -> None: super().normalize(archive, logger) # Checks if the `value` is negative and sets it to 0 if it is. + if self.value is None: + logger.error('The `value` of the electronic band gap is not stored.') + return self.value = self.check_negative_values(logger) # Resolve the `type` of the electronic band gap from `momentum_transfer`, ONLY for scalar `value` diff --git a/tests/test_band_gap.py b/tests/test_band_gap.py index db965ba3..b33beccc 100644 --- a/tests/test_band_gap.py +++ b/tests/test_band_gap.py @@ -40,7 +40,7 @@ def test_default_quantities(self): electronic_band_gap = ElectronicBandGap() assert ( electronic_band_gap.iri - == 'https://fairmat-nfdi.github.io/fairmat-taxonomy/#/ElectronicBandGap' + == 'http://fairmat-nfdi.eu/taxonomy/ElectronicBandGap' ) assert electronic_band_gap.name == 'ElectronicBandGap' assert electronic_band_gap.rank == [] @@ -48,6 +48,7 @@ def test_default_quantities(self): @pytest.mark.parametrize( 'value, result', [ + (0.0, 0.0), (1.0, 1.0), (-1.0, 0.0), ],