Skip to content

Commit

Permalink
Fixed IRI
Browse files Browse the repository at this point in the history
Added Nathan comments
  • Loading branch information
JosePizarro3 committed Apr 12, 2024
1 parent 7d2818f commit 0c058b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
15 changes: 10 additions & 5 deletions src/nomad_simulations/physical_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Section,
Context,
MEnum,
URL,
)
from nomad.metainfo.metainfo import DirectQuantity, Dimension, _placeholder_quantity
from nomad.datamodel.metainfo.basesections import Entity
Expand Down Expand Up @@ -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/.
Expand Down Expand Up @@ -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(
Expand All @@ -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`
Expand Down
21 changes: 13 additions & 8 deletions src/nomad_simulations/properties/band_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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.
""",
)

Expand All @@ -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():
Expand Down Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion tests/test_band_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ 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 == []

@pytest.mark.parametrize(
'value, result',
[
(0.0, 0.0),
(1.0, 1.0),
(-1.0, 0.0),
],
Expand Down

0 comments on commit 0c058b3

Please sign in to comment.