Skip to content

Commit

Permalink
Introduce Templates from Markus
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Daelman committed Dec 17, 2024
1 parent b98615c commit 6f8a7ea
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/nomad_simulations/schema_packages/properties/band_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from nomad.units import ureg
from nomad.datamodel.data import ArchiveSection
from nomad.metainfo import MEnum, Quantity
from nomad.metainfo.physical_properties import MaterialProperty, Energy
from nomad.metainfo.physical_properties import DatasetTemplate, Energy
from ..variables import (
SpinChannel,
MomentumTransfer,
Expand All @@ -15,15 +15,29 @@
from structlog.stdlib import BoundLogger


class ElectronicBandGap(ArchiveSection): # ! TODO: add optical band gap
values = MaterialProperty(
name='BandGap',
fields=[Energy],
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
class HomoLumoGap(ArchiveSection): # ? class description
values = DatasetTemplate(
name='HomoLumoGap',
mandatory_fields=[Energy],
mandatory_variables=[SpinChannel], # presence checked via annotations
iri='http://fairmat-nfdi.eu/taxonomy/HomoLumoGap',
description="""
The energy difference between the highest occupied spin state
and the lowest unoccupied spin state.
""",
)

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
self.m_all_validate() # ensure constraints
if np.any(self.values.fields < 0):
logger.warning(f'Negative band gap detected: {self.values.fields} J')


class ElectronicBandGap(HomoLumoGap): # ! TODO: add optical band gap
values = HomoLumoGap.values.m_copy() # ? `m_copy` supported
values.mandatory_variables.append(MomentumTransfer)
values.iri = 'http://fairmat-nfdi.eu/taxonomy/ElectronicBandGap'

type = Quantity(
type=MEnum('direct', 'indirect'),
description="""
Expand All @@ -36,10 +50,7 @@ class ElectronicBandGap(ArchiveSection): # ! TODO: add optical band gap
)

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 not self.variables[1]: # ! replace with native getter
if not self.get_variable(MomentumTransfer).get_values(): # getter
if self.type == 'direct':
self.variables.append(
MomentumTransfer(data=[2 * [3 * [0.0]]] * ureg.angstrom**-1)
Expand Down

0 comments on commit 6f8a7ea

Please sign in to comment.