Skip to content

Commit

Permalink
Apply explanation Markus
Browse files Browse the repository at this point in the history
  • Loading branch information
ndaelman committed Dec 11, 2024
1 parent de7b75d commit b98615c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 52 deletions.
21 changes: 2 additions & 19 deletions src/nomad_simulations/schema_packages/properties/band_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from nomad.metainfo import MEnum, Quantity
from nomad.metainfo.physical_properties import MaterialProperty, Energy
from ..variables import (
MaterialPropertyAttributes,
fetch_instance,
SpinChannel,
MomentumTransfer,
)
Expand All @@ -21,7 +19,7 @@ class ElectronicBandGap(ArchiveSection): # ! TODO: add optical band gap
values = MaterialProperty(
name='BandGap',
fields=[Energy],
variables=[SpinChannel, MomentumTransfer], # target index
variables=[SpinChannel, MomentumTransfer], # presence checked via annotations
iri='http://fairmat-nfdi.eu/taxonomy/ElectronicBandGap',
description="""Energy difference between the highest occupied electronic state and the lowest unoccupied electronic state.""", # ? necessity
)
Expand All @@ -41,20 +39,7 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
if np.any(self.values.fields < 0): # ? check for Energy
logger.warning(f'Negative band gap detected: {self.values.fields} J')

if np.any(
fetch_instance(
self, SpinChannel, attribute=MaterialPropertyAttributes.variables
)
):
logger.warning(
f'Band gap without specifying any spin channel: {self.values.variables}'
)

if not np.any(
fetch_instance(
self, MomentumTransfer, attribute=MaterialPropertyAttributes.variables
)
):
if not self.variables[1]: # ! replace with native getter
if self.type == 'direct':
self.variables.append(
MomentumTransfer(data=[2 * [3 * [0.0]]] * ureg.angstrom**-1)
Expand All @@ -63,5 +48,3 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
logger.warning(
f'Indirect band gap without specifying any momentum transfer: {self.variables}'
)

# ? how to enforce a fixed ordering
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ElectronicEigenstates(ArchiveSection):
) # ? remove

highest_occupied = Quantity(
type=np.float64,
type=np.float64, # ! energy, k-point
unit='joule',
description="""
Highest occupied electronic eigenvalue. Together with `lowest_unoccupied`, it defines the
Expand All @@ -97,7 +97,7 @@ class ElectronicEigenstates(ArchiveSection):
)

lowest_unoccupied = Quantity(
type=np.float64,
type=np.float64, # ! energy, k-point
unit='joule',
description="""
Lowest unoccupied electronic eigenvalue. Together with `highest_occupied`, it defines the
Expand Down
31 changes: 0 additions & 31 deletions src/nomad_simulations/schema_packages/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,6 @@
)


class MaterialPropertyAttributes(Enum):
fields = 'fields'
variables = 'variables'


def fetch_instance(
prop: MaterialProperty,
target: PhysicalProperty,
attribute: MaterialPropertyAttributes = MaterialPropertyAttributes.fields,
) -> np.ndarray[PhysicalProperty]:
"""
Fetches instances of a specified physical property from a material property based on a given attribute.
Args:
prop (MaterialProperty): The material property from which to fetch instances.
target (PhysicalProperty): The type of physical property to fetch.
attribute (MaterialPropertyAttributes): The attribute of the material property to check.
Returns:
np.ndarray[PhysicalProperty]: An array of instances of the specified physical property.
Raises:
ValueError: If the provided attribute is not a valid MaterialProperty attribute.
"""
if not isinstance(attribute, MaterialPropertyAttributes):
raise ValueError(
f'Attribute {attribute} is not a valid MaterialProperty attribute.'
)
return np.where(lambda x: isinstance(x, target), getattr(prop, attribute), [])


SpinChannel = PhysicalProperty(
name='SpinChannel',
type=MEnum('alpha', 'beta', 'both'),
Expand Down

0 comments on commit b98615c

Please sign in to comment.