diff --git a/src/nomad_simulations/schema_packages/properties/band_gap.py b/src/nomad_simulations/schema_packages/properties/band_gap.py index db60333c..33d22de4 100644 --- a/src/nomad_simulations/schema_packages/properties/band_gap.py +++ b/src/nomad_simulations/schema_packages/properties/band_gap.py @@ -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, @@ -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=""" @@ -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)