Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bastonero committed Dec 9, 2023
1 parent 1c83dde commit 665c475
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/aiida_vibroscopy/calculations/spectra_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def compute_raman_susceptibility_tensors(
:param phonopy_instance: Phonopy instance with non-analytical constants included
:param nac_direction: non-analytical direction in unit cell space coordinates
:param raman_tensors: dChi/du in Cartesian coordinates (in 1/Angstrom)
:param raman_tensors: dChi/du in Cartesian coordinates (in 4pi/Angstrom)
:param nlo_susceptibility: non linear optical susceptibility
in Cartesian coordinates (in pm/V)
:param use_irreps: whether to use irreducible representations
Expand Down
54 changes: 21 additions & 33 deletions tests/calculations/test_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,18 @@ def generate_third_rank_tensors():

def _generate_third_rank_tensors():
"""Return AlAs Phonopy instance."""
chi2 = np.array([[[-1.42547451e-50, -4.81482486e-35, 1.36568821e-14],
[-4.81482486e-35, 0.00000000e+00, 4.24621905e+01],
[1.36568821e-14, 4.24621905e+01, 5.20011857e-15]],
[[-3.20988324e-35, 0.00000000e+00, 4.24621905e+01],
[0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[4.24621905e+01, 0.00000000e+00, 5.20011857e-15]],
[[1.36568821e-14, 4.24621905e+01, 5.20011857e-15],
[4.24621905e+01, -2.40741243e-35, 5.20011857e-15],
[5.20011857e-15, 5.20011857e-15, 9.55246283e-31]]])

raman = np.array([[[[7.82438427e-38, -1.38120586e-37, -1.13220290e-17],
[-1.37630797e-37, -5.64237288e-37, -3.52026291e-02],
[-1.13220290e-17, -3.52026291e-02, -4.31107870e-18]],
[[-4.23177966e-37, -7.99336159e-37, -3.52026291e-02],
[-5.48564030e-37, -4.99585099e-38, 1.47328625e-36],
[-3.52026291e-02, 1.77891478e-36, -4.31107870e-18]],
[[-1.13220290e-17, -3.52026291e-02, -4.31107870e-18],
[-3.52026291e-02, -2.66445386e-37, -4.31107870e-18],
[-4.31107870e-18, -4.31107870e-18, -7.91497448e-34]]],
[[[-1.01998624e-37, -1.60357021e-36, 1.13220290e-17],
[-1.45026616e-36, 2.31964219e-36, 3.52026291e-02],
[1.13220290e-17, 3.52026291e-02, 4.31107870e-18]],
[[7.67989643e-37, -7.36643127e-37, 3.52026291e-02],
[-4.23177966e-37, -1.59671316e-37, -7.20969869e-37],
[3.52026291e-02, -5.09380885e-37, 4.31107870e-18]],
[[1.13220290e-17, 3.52026291e-02, 4.31107870e-18],
[3.52026291e-02, -2.66445386e-37, 4.31107870e-18],
[4.31107870e-18, 4.31107870e-18, 7.91868953e-34]]]])
c = 42.4621905 # pm/V
chi2 = np.array([[[0, 0, 0], [0, 0, c], [0, 0, 0]], [[0, 0, c], [0, 0, 0], [0, 0, 0]],
[[0, c, 0], [c, 0, 0], [0, 0, 0]]])

a = 3.52026291e-02 # 1/Ang
raman = np.array([[[[0, 0, 0], [0, 0, -a], [0, -a, 0]], [[0, 0, -a], [0, 0, 0], [-a, 0, 0]],
[[0, -a, 0], [-a, 0, 0], [0, 0, 0]]],
[
[[0, 0, 0], [0, 0, a], [0, a, 0]],
[[0, 0, a], [0, 0, 0], [a, 0, 0]],
[[0, a, 0], [a, 0, 0], [0, 0, 0]],
]])
return raman, chi2

return _generate_third_rank_tensors
Expand All @@ -88,6 +72,7 @@ def test_compute_raman_susceptibility_tensors(generate_phonopy_instance, generat
from aiida_vibroscopy.common.constants import DEFAULT

ph = generate_phonopy_instance()
ph.symmetrize_force_constants()
vol = ph.unitcell.volume
raman, chi2 = generate_third_rank_tensors()

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

alpha_comp = prefactor * alpha[0, 0, 1]
alpha_theo = vol * raman[0, 0, 1, 2]
if DEBUG:
print('\n', '================================', '\n')
print((prefactor * alpha).round(3))
print('\t', 'DEBUG')
print(prefactor * alpha[1, 1, 2], vol * raman[1, 0, 1, 2])
print(alpha_comp, alpha_theo)
print('\n', '================================', '\n')

assert np.abs(prefactor * alpha[1, 1, 2] + vol * raman[1, 0, 1, 2]) < 1e-5
assert np.abs(alpha_comp - alpha_theo) < 5e-4

alpha, _, _ = compute_raman_susceptibility_tensors(
phonopy_instance=ph,
Expand All @@ -126,12 +114,12 @@ def test_compute_raman_susceptibility_tensors(generate_phonopy_instance, generat
if DEBUG:
print('\n', '================================', '\n')
print('\t', 'DEBUG')
print((prefactor * alpha).round(3))
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(dchivol, alpha_comp)
print(alpha)
print('\n', '================================', '\n')

assert np.abs(alpha_comp - dchivol) < 1e-4
assert np.abs(alpha_comp + dchivol) < 5e-4

0 comments on commit 665c475

Please sign in to comment.