Skip to content

Commit

Permalink
Added axis to AbsorptionSpectrum
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed May 22, 2024
1 parent 70c03e9 commit 7d248b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/nomad_simulations/properties/permittivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
super().__init__(m_def, m_context, **kwargs)
self.rank = [3, 3]
self.name = self.m_def.name
self._axes_map = ['xx', 'yy', 'zz']

def resolve_type(self) -> str:
frequencies = get_variables(self.variables, Frequency)
Expand Down Expand Up @@ -97,8 +98,11 @@ def extract_absorption_spectra(
spectra = []
for i in range(3):
val = self.value[:, i, i].imag
absorption_spectrum = AbsorptionSpectrum(variables=frequencies)
absorption_spectrum = AbsorptionSpectrum(
axis=self._axes_map[i], variables=frequencies
)
absorption_spectrum.value = val
absorption_spectrum.physical_property_ref = self
spectra.append(absorption_spectrum)
return spectra

Expand Down
10 changes: 9 additions & 1 deletion src/nomad_simulations/properties/spectral_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import pint

from nomad import config
from nomad.metainfo import Quantity, SubSection, Section, Context
from nomad.metainfo import Quantity, SubSection, Section, Context, MEnum

from ..utils import get_sibling_section, get_variables
from ..physical_property import PhysicalProperty
Expand Down Expand Up @@ -525,6 +525,14 @@ class AbsorptionSpectrum(SpectralProfile):

# ! implement `iri` and `rank` as part of `m_def = Section()`

axis = Quantity(
type=MEnum('xx', 'yy', 'zz'),
description="""
Axis of the absorption spectrum. This is related with the polarization direction, and can be seen as the
principal term in the tensor `Permittivity.value` (see permittivity.py module).
""",
)

def __init__(
self, m_def: Section = None, m_context: Context = None, **kwargs
) -> None:
Expand Down
8 changes: 5 additions & 3 deletions tests/test_permittivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ def test_extract_absorption_spectra(
absorption_spectra = permittivity.extract_absorption_spectra(logger)
if absorption_spectra is not None:
assert len(absorption_spectra) == 3
assert absorption_spectra[0].rank == []
assert len(absorption_spectra[0].value) == len(variables[0].points)
assert np.allclose(absorption_spectra[0].value, result)
spectrum = absorption_spectra[1]
assert spectrum.rank == []
assert spectrum.axis == 'yy'
assert len(spectrum.value) == len(variables[0].points)
assert np.allclose(spectrum.value, result)
else:
assert absorption_spectra == result

0 comments on commit 7d248b4

Please sign in to comment.