Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bastonero committed Feb 12, 2024
1 parent e96b304 commit 0238307
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tests/calculations/test_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ def _generate_third_rank_tensors():


def test_compute_raman_susceptibility_tensors(generate_phonopy_instance, generate_third_rank_tensors):
"""Test the `compute_raman_susceptibility_tensors` function."""
"""Test the `compute_raman_susceptibility_tensors` function.
For cubic semiconductors AB, the Raman susceptibility for phonons polarized along the `l`
direction can be written as sqrt(mu*Omega)*alpha_{12} = Omega dChi_{12}/dtau_{A,3},
where A is the atom located at the origin, and the atom B in (1/4,1/4,1/4).
As a consequence, we can test the implementation when specifying a q-direction (Cartesian).
"""
from aiida_vibroscopy.calculations.spectra_utils import compute_raman_susceptibility_tensors
from aiida_vibroscopy.common.constants import DEFAULT

Expand All @@ -83,10 +90,10 @@ def test_compute_raman_susceptibility_tensors(generate_phonopy_instance, generat
phonopy_instance=ph,
raman_tensors=raman,
nlo_susceptibility=chi2,
nac_direction=[0, 1, 0],
nac_direction=[1, 0, 0],
)

alpha_comp = prefactor * alpha[0, 1, 2]
alpha_comp = prefactor * alpha[2, 1, 2]
alpha_theo = vol * raman[0, 0, 1, 2]
if DEBUG:
print('\n', '================================', '\n')
Expand All @@ -95,7 +102,7 @@ def test_compute_raman_susceptibility_tensors(generate_phonopy_instance, generat
print(alpha_comp, alpha_theo)
print('\n', '================================', '\n')

assert np.abs(alpha_comp - alpha_theo) < 1e-5
assert np.abs(abs(alpha_comp) - abs(alpha_theo)) < 1e-5

alpha, _, _ = compute_raman_susceptibility_tensors(
phonopy_instance=ph,
Expand All @@ -106,8 +113,8 @@ def test_compute_raman_susceptibility_tensors(generate_phonopy_instance, generat
diel = ph.nac_params['dielectric']
borns = ph.nac_params['born']

nlocorr = DEFAULT.nlo_conversion * borns[0, 2, 2] * chi2[0, 1, 2] / diel[2, 2]
alpha_theo = vol * raman[0, 0, 1, 2] - nlocorr
nlocorr = DEFAULT.nlo_conversion * borns[1, 2, 2] * chi2[0, 1, 2] / diel[2, 2]
alpha_theo = vol * raman[1, 0, 1, 2] - nlocorr

# we take the last, cause it is associated to the LO mode
alpha_comp = prefactor * alpha[2, 0, 1]
Expand All @@ -118,8 +125,7 @@ def test_compute_raman_susceptibility_tensors(generate_phonopy_instance, generat
print('NLO corr. expected: ', nlocorr)
print('Born corr. expected: ', -borns[1, 0, 0] / np.sqrt(reduced_mass))
print('Conversion factor nlo: ', DEFAULT.nlo_conversion)
# print(prefactor * alpha)
print(alpha_comp, alpha_theo)
print('\n', '================================', '\n')

assert np.abs(alpha_comp - alpha_theo) < 1e-3
assert np.abs(abs(alpha_comp) - abs(alpha_theo)) < 1e-4

0 comments on commit 0238307

Please sign in to comment.