Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ requires-python = '>=3.8'
dependencies = [
"aiida-core~=2.3",
"aiida-quantumespresso~=4.10",
"aiida-phonopy~=1.1",
"spglib~=2.2.0",
"phonopy~=2.19,<=2.25.0",
"aiida-phonopy~=1.3",
"spglib~=2.6",
"phonopy~=2.39",
]

[project.urls]
Expand Down
10 changes: 4 additions & 6 deletions src/aiida_vibroscopy/calculations/spectra_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def compute_active_modes(

bands_indices = irreps.band_indices
characters = irreps.characters.real
labels = irreps._get_ir_labels() #pylint: disable=protected-access
labels = irreps._ir_labels #pylint: disable=protected-access

mode_index = 0

Expand Down Expand Up @@ -216,6 +216,7 @@ def compute_raman_susceptibility_tensors(
# rcell = np.linalg.inv(phonopy_instance.unitcell.cell) # as columns
# q_cartesian = np.dot(rcell, nac_direction) # in Cartesian coordinates
q_cartesian = np.zeros((3)) if nac_direction is None else np.array(nac_direction)
nac_direction_ = nac_direction if nac_direction is None else np.array(nac_direction)

selection_rule = 'raman' if use_irreps else None

Expand All @@ -225,7 +226,7 @@ def compute_raman_susceptibility_tensors(

freqs, neigvs, labels = compute_active_modes(
phonopy_instance=phonopy_instance,
nac_direction=q_cartesian,
nac_direction=nac_direction_,
degeneracy_tolerance=degeneracy_tolerance,
selection_rule=selection_rule
)
Expand Down Expand Up @@ -366,10 +367,7 @@ def compute_complex_dielectric(
:return: (3, 3, num steps) shape :class:`numpy.ndarray`, `num steps` refers to the
number of frequency steps where the complex dielectric function is evaluated
"""
from phonopy import units
from qe_tools import CONSTANTS

prefactor = 4 * np.pi * units.VaspToCm**2 * 2. * CONSTANTS.ry_to_ev * CONSTANTS.bohr_to_ang
prefactor = UNITS.complex_dielectric_factor

polarizations, frequencies, _ = compute_polarization_vectors(
phonopy_instance=phonopy_instance,
Expand Down
2 changes: 1 addition & 1 deletion src/aiida_vibroscopy/calculations/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def transform_trajectory(
lattice = cell.cell
positions = cell.scaled_positions
r_cart = similarity_transformation(lattice.T, rotation)
num_atoms = cell.get_number_of_atoms()
num_atoms = len(cell)

forces_ = np.zeros_like(forces)
pola_ = np.dot(r_cart, polarisation)
Expand Down
8 changes: 6 additions & 2 deletions src/aiida_vibroscopy/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
from types import SimpleNamespace

import numpy as np
from phonopy import units
from phonopy.physical_units import get_physical_units
from qe_tools import CONSTANTS

__all__ = ('DEFAULT',)

units = get_physical_units()

# We here refer to SI to the general convention in material science of:
# * Length ==> in Angstrom
# * Energy ==> in eV
Expand All @@ -34,7 +36,7 @@
# The exrta 'e' comes from the Ang/V = e * (Ang/eV) of Chi(2).
nlo_conversion=0.02 *
(2.0 * CONSTANTS.ry_to_ev * CONSTANTS.bohr_to_ang), # we remove 4pi and put it back in the cross sections
cm_to_kelvin=units.CmToEv / units.Kb,
cm_to_kelvin=units.CmToEv / units.KB,
thz_to_cm=units.THzToCm, # THz to cm^-1
debey_ang=1.0 / 0.2081943, # 1 Debey = 0.2081943 e * Angstrom ==> e = (1/0.2081943) D/A
# The absolute theoretical Raman cross-section per unit volume is obtained with the
Expand All @@ -49,6 +51,8 @@
elementary_charge_si=1.602176634e-19, # elementary charge in Coulomb
electron_mass_si=units.Me, # electron mass in kg
atomic_mass_si=units.AMU, # atomic mass unit in kg
complex_dielectric_factor=4 * np.pi * (units.DefaultToTHz * units.THzToCm)**2 * 2. * CONSTANTS.ry_to_ev *
CONSTANTS.bohr_to_ang,
# to be defined:
# * kelvin to eV
# * nm to eV
Expand Down
6 changes: 5 additions & 1 deletion src/aiida_vibroscopy/utils/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def boson_factor(frequency: float, temperature: float = 300) -> float:
:param temperature: temperature in Kelvin
:return: boson occupation factor (adimensional)
"""
from phonopy.units import CmToEv, Kb
from phonopy.physical_units import get_physical_units

units = get_physical_units()
CmToEv = units.CmToEv
Kb = units.KB

return 1.0 / (1.0 - np.exp(-CmToEv * frequency / (temperature * Kb)))

Expand Down
28 changes: 19 additions & 9 deletions tests/calculations/test_numerical_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,31 @@ def _generate_trajectory(scale=1, index=2):
from aiida.orm import TrajectoryData
import numpy as np

# yapf: disable
node = TrajectoryData()
if index == 2:
polarization = scale * np.array([[-4.88263729e-09, 6.84208048e-09, 1.67517339e-01]])
forces = scale * np.array([[
[-0.00000000e+00, -0.00000000e+00, 1.95259855e-02], [-0.00000000e+00, 0.00000000e+00, 1.95247000e-02],
[-0.00000000e+00, -0.00000000e+00, 1.95247000e-02], [-0.00000000e+00, 0.00000000e+00, 1.95262427e-02],
[-1.25984053e-05, -1.25984053e-05, -1.95383268e-02], [-1.31126259e-05, 1.31126259e-05, -1.95126158e-02],
[1.28555156e-05, 1.25984053e-05, -1.95383268e-02], [1.31126259e-05, -1.31126259e-05, -1.95126158e-02]
[-0.00000000e+00, -0.00000000e+00, 1.95259855e-02],
[-0.00000000e+00, 0.00000000e+00, 1.95247000e-02],
[-0.00000000e+00, -0.00000000e+00, 1.95247000e-02],
[-0.00000000e+00, 0.00000000e+00, 1.95262427e-02],
[-1.25984053e-05, -1.25984053e-05, -1.95383268e-02],
[-1.31126259e-05, 1.31126259e-05, -1.95126158e-02],
[1.28555156e-05, 1.25984053e-05, -1.95383268e-02],
[1.31126259e-05, -1.31126259e-05, -1.95126158e-02]
]])
if index == 3:
polarization = scale * np.array([[9.55699034e-05, 1.18453183e-01, 1.18453160e-01]])
forces = scale * np.array([
[[-1.82548322e-05, 1.38068238e-02, 1.38068238e-02], [-1.82548322e-05, 1.38060524e-02, 1.38060524e-02],
[-1.82548322e-05, 1.38070809e-02, 1.38060524e-02], [-1.82548322e-05, 1.38060524e-02, 1.38070809e-02],
[5.39931655e-06, -1.38194222e-02, -1.38194222e-02], [5.14220624e-06, -1.37937111e-02, -1.37937111e-02],
[3.11103478e-05, -1.37937111e-02, -1.38194222e-02], [3.11103478e-05, -1.38194222e-02, -1.37937111e-02]]
[[-1.82548322e-05, 1.38068238e-02, 1.38068238e-02],
[-1.82548322e-05, 1.38060524e-02, 1.38060524e-02],
[-1.82548322e-05, 1.38070809e-02, 1.38060524e-02],
[-1.82548322e-05, 1.38060524e-02, 1.38070809e-02],
[5.39931655e-06, -1.38194222e-02, -1.38194222e-02],
[5.14220624e-06, -1.37937111e-02, -1.37937111e-02],
[3.11103478e-05, -1.37937111e-02, -1.38194222e-02],
[3.11103478e-05, -1.38194222e-02, -1.37937111e-02]]
])

node.set_array('forces', forces)
Expand All @@ -82,6 +91,7 @@ def _generate_trajectory(scale=1, index=2):
[4.21853809,4.21853809,1.40621634],
[4.21853809,1.40621634,4.21853809],
]])
# yapf: enable
symbols = ['Al', 'Al', 'Al', 'Al', 'As', 'As', 'As', 'As']
node.set_trajectory(stepids=stepids, cells=cells, symbols=symbols, positions=positions, times=times)

Expand Down Expand Up @@ -178,7 +188,7 @@ def test_compute_tensors(generate_phonopy_instance, generate_trajectory):
)
)
def test_get_central_derivatives_coefficients(inputs, result):
"""Test the numerical derivatives coefficients.
"""Test the generation of numerical derivatives coefficients.

Exact values taken from Wikipedia: https://en.wikipedia.org/wiki/Finite_difference_coefficient
"""
Expand Down
52 changes: 2 additions & 50 deletions tests/calculations/test_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_compute_clamped_pockels_tensor(generate_phonopy_instance, generate_thir
'pockels_el': pockels_el,
'pockels_ion': pockels_ion,
}
ndarrays_regression.check(results, default_tolerance=dict(atol=1e-4, rtol=1e-4))
ndarrays_regression.check(results, default_tolerance=dict(atol=1e-1, rtol=1e-2))


def test_compute_methods(generate_phonopy_instance, generate_third_rank_tensors, ndarrays_regression):
Expand Down Expand Up @@ -230,60 +230,12 @@ def test_compute_methods(generate_phonopy_instance, generate_third_rank_tensors,
eps = compute_complex_dielectric(ph, nac_direction=[0,0,1], freq_range=freq_range)
results['complex_dielectric_nac'] = eps

ndarrays_regression.check(results, default_tolerance=dict(atol=1e-4, rtol=1e-4))
ndarrays_regression.check(results, default_tolerance=dict(atol=1e-1, rtol=1e-2))


def test_generate_vibrational_data_from_forces(generate_vibrational_data_from_forces, ndarrays_regression):
"""Test `generate_vibrational_data_from_phonopy`."""
vibro = generate_vibrational_data_from_forces()
assert np.abs(abs(alpha_comp) - abs(alpha_theo)) < 1e-3


def test_compute_methods(generate_phonopy_instance, generate_third_rank_tensors, ndarrays_regression):
"""Test the post-processing methods with data regression techniques."""
from aiida_vibroscopy.calculations.spectra_utils import (
compute_active_modes,
compute_complex_dielectric,
compute_raman_space_average,
compute_raman_susceptibility_tensors,
)

results = {}
ph = generate_phonopy_instance()
ph.symmetrize_force_constants()
raman, chi2 = generate_third_rank_tensors()

freqs, _, _ = compute_active_modes(phonopy_instance=ph)
results['active_modes_freqs'] = freqs
# results['active_modes_eigvecs'] = eigenvectors

freqs, _ , _ = compute_active_modes(phonopy_instance=ph, nac_direction=[0,0,1])
results['active_modes_nac_freqs'] = freqs
# results['active_modes_nac_eigvecs'] = eigenvectors

alpha, _, _ = compute_raman_susceptibility_tensors(ph, raman, chi2)
ints_hh, ints_hv = compute_raman_space_average(alpha)
# results['raman_susceptibility_tensors'] = alpha
results['intensities_hh'] = ints_hh
results['intensities_hv'] = ints_hv

# alpha, _, _ = compute_raman_susceptibility_tensors(ph, raman, chi2, nac_direction=[0,0,1])
# results['raman_susceptibility_tensors_nac'] = alpha

# pols, _, _ = compute_polarization_vectors(ph)
# results['polarization_vectors'] = pols

# pols, _, _ = compute_polarization_vectors(ph, nac_direction=[0,0,1])
# results['polarization_vectors_nac'] = pols

freq_range = np.linspace(10,1000,900)
eps = compute_complex_dielectric(ph, freq_range=freq_range)
results['complex_dielectric'] = eps

eps = compute_complex_dielectric(ph, nac_direction=[0,0,1], freq_range=freq_range)
results['complex_dielectric_nac'] = eps

ndarrays_regression.check(results, default_tolerance=dict(atol=1e-4, rtol=1e-4))


def test_generate_vibrational_data_from_forces(generate_vibrational_data_from_forces, ndarrays_regression):
Expand Down
Binary file not shown.
Binary file modified tests/calculations/test_spectra/test_compute_methods.npz
Binary file not shown.
64 changes: 19 additions & 45 deletions tests/calculations/test_symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,62 +47,36 @@ def _generate_trajectory(scale=1):
from aiida.orm import TrajectoryData
import numpy as np

# yapf: disable
node = TrajectoryData()
polarization = scale * np.array([[-4.88263729e-09, 6.84208048e-09, 1.67517339e-01]])
node.set_array('electronic_dipole_cartesian_axes', polarization)
forces = scale * np.array(
[[[-0.00000000e+00, -0.00000000e+00, 1.95259855e-02], [-0.00000000e+00, 0.00000000e+00, 1.95247000e-02],
[-0.00000000e+00, -0.00000000e+00, 1.95247000e-02], [-0.00000000e+00, 0.00000000e+00, 1.95262427e-02],
[-1.25984053e-05, -1.25984053e-05, -1.95383268e-02], [-1.31126259e-05, 1.31126259e-05, -1.95126158e-02],
[1.28555156e-05, 1.25984053e-05, -1.95383268e-02], [1.31126259e-05, -1.31126259e-05, -1.95126158e-02]]]
)
[[[-0.00000000e+00, -0.00000000e+00, 1.95259855e-02],
[-0.00000000e+00, 0.00000000e+00, 1.95247000e-02],
[-0.00000000e+00, -0.00000000e+00, 1.95247000e-02],
[-0.00000000e+00, 0.00000000e+00, 1.95262427e-02],
[-1.25984053e-05, -1.25984053e-05, -1.95383268e-02],
[-1.31126259e-05, 1.31126259e-05, -1.95126158e-02],
[1.28555156e-05, 1.25984053e-05, -1.95383268e-02],
[1.31126259e-05, -1.31126259e-05, -1.95126158e-02]]
])
node.set_array('forces', forces)

stepids = np.array([1])
times = stepids * 0.0
cells = np.array([5.62475444 * np.eye(3)])
positions = np.array([[
[
0.,
0.,
0.,
],
[
0.,
2.81237722,
2.81237722,
],
[
2.81237722,
0.,
2.81237722,
],
[
2.81237722,
2.81237722,
0.,
],
[
1.40621634,
1.40621634,
1.40621634,
],
[
1.40621634,
4.21853809,
4.21853809,
],
[
4.21853809,
4.21853809,
1.40621634,
],
[
4.21853809,
1.40621634,
4.21853809,
],
[ 0., 0., 0. ],
[ 0., 2.81237722, 2.81237722 ],
[ 2.81237722, 0., 2.81237722 ],
[ 2.81237722, 2.81237722, 0. ],
[ 1.40621634, 1.40621634, 1.40621634 ],
[ 1.40621634, 4.21853809, 4.21853809 ],
[ 4.21853809, 4.21853809, 1.40621634 ],
[ 4.21853809, 1.40621634, 4.21853809 ],
]])
# yapf: enable
symbols = ['Al', 'Al', 'Al', 'Al', 'As', 'As', 'As', 'As']
node.set_trajectory(stepids=stepids, cells=cells, symbols=symbols, positions=positions, times=times)

Expand Down
Loading
Loading