Skip to content

Commit

Permalink
Improved ElectronicBandGap property
Browse files Browse the repository at this point in the history
Added iri to quantity in PhysicalProperty
  • Loading branch information
JosePizarro3 committed Apr 11, 2024
1 parent 31c2bb9 commit eeee194
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/nomad_simulations/physical_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ class PhysicalProperty(ArchiveSection):
""",
)

iri = Quantity(
type=str,
description="""
Internationalized Resource Identifier (IRI) of the physical property defined in the FAIRmat
taxonomy, https://fairmat-nfdi.github.io/fairmat-taxonomy/.
""",
)

source = Quantity(
type=MEnum('simulation', 'measurement', 'analysis'),
default='simulation',
Expand Down
81 changes: 75 additions & 6 deletions src/nomad_simulations/properties/band_gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,105 @@

import numpy as np
from structlog.stdlib import BoundLogger
import pint
from typing import Optional

from nomad.units import ureg
from nomad.metainfo import Quantity, MEnum, Section, Context

from ..physical_property import PhysicalProperty


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'

type = Quantity(
type=MEnum('direct', 'indirect'),
description="""
Type categorization of the electronic band gap. The electronic band gap can be `'direct'` or `'indirect'`.
Type categorization of the `ElectronicBandGap`. 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.
""",
)

momentum_transfer = Quantity(
type=np.float64,
shape=[2, 3],
description="""
If the `ElectronicBandGap` 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:
`momentum_transfer = [[0, 0, 0], [0.5, 0.5, 0]]`.
""",
)

spin_channel = Quantity(
type=np.int32,
description="""
Spin channel of the corresponding `ElectronicBandGap`. It can take values of 0 or 1.
""",
)

value = Quantity(
type=np.float64,
unit='joule',
description="""
The value of the electronic band gap.
The value of the `ElectronicBandGap`.
""",
)

# TODO add more functionalities here

def __init__(self, m_def: Section = None, m_context: Context = None, **kwargs):
super().__init__(m_def, m_context, **kwargs)
self.name = self.m_def.name
self.rank = []
self.rank = [] # ? Is this here or in the attrs instantiation better?

def check_negative_values(self, logger: BoundLogger) -> pint.Quantity:
"""
Checks if the electronic band gap is negative and sets it to 0 if it is.
Args:
logger (BoundLogger): The logger to log messages.
"""
if self.value < 0.0:
logger.error(
'The electronic band gap cannot be defined negative. We set it up to 0.'
)
return 0.0 * ureg.eV
return self.value

def resolve_type(self, logger: BoundLogger) -> Optional[str]:
"""
Resolves the `type` of the electronic band gap based on the stored `momentum_transfer` values.
Args:
logger (BoundLogger): The logger to log messages.
Returns:
(Optional[str]): The resolved `type` of the electronic band gap.
"""
if self.momentum_transfer is None and self.type == 'indirect':
logger.warning(
"The `momentum_transfer` is not defined for an `type='indirect'` electronic band gap."
)
return None
if self.momentum_transfer is not None:
momentum_difference = np.diff(self.momentum_transfer, axis=0)
if (momentum_difference == np.zeros(3)).all():
return 'direct'
else:
return 'indirect'
return self.type

def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)

# Checks if the `value` is negative and sets it to 0 if it is.
self.value = self.check_negative_values(logger)

# Resolve the `type` of the electronic band gap.
self.type = self.resolve_type(logger)

0 comments on commit eeee194

Please sign in to comment.