Coverage for tests/unittests/calculators/test_hotcarriers.py: 100%
21 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-08-01 16:57 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-08-01 16:57 +0000
1from __future__ import annotations
3import numpy as np
4import pytest
6from gpaw.tddft.units import fs_to_au
7from rhodent.calculators.hotcarriers import HotCarriersCalculator
8from rhodent.response import ResponseFromWaveFunctions
9from rhodent.density_matrices.readers.gpaw import KohnShamRhoWfsReader
12@pytest.mark.parametrize('test_system', ['Na8', 'Ag8'])
13def test_hcdist_wave_functions_stride(ksd_fname, wfssnap_fname):
14 # Read the full density matrix directly
15 rho_nn_direct = KohnShamRhoWfsReader(wfs_fname=wfssnap_fname, ksd=ksd_fname,
16 yield_re=True, yield_im=False,
17 filter_times=np.array([30]) * fs_to_au)
18 nM = rho_nn_direct.lcao_rho_reader.C0_sknM.shape[-1]
19 imin, imax, amin, amax = rho_nn_direct.ksd.ialims()
21 for dm_buffer in rho_nn_direct.iread(0, 0, slice(0, nM), slice(0, nM)):
22 ref_rho_n = dm_buffer.real.diagonal()
24 # Set up the calculator
25 response = ResponseFromWaveFunctions(ksd=ksd_fname, wfs_fname=wfssnap_fname, perturbation=None)
27 calc = HotCarriersCalculator(response, None, times=[30e3], energies_occ=[], energies_unocc=[])
29 # Compare diagonals from first order to actual diagonals
30 test_rho_n = np.zeros(amax + 1 - imin)
31 for _, results in calc.icalculate_gather_on_root(yield_total_P=True):
32 test_rho_n[imin:imax+1] -= results['P_i']
33 test_rho_n[amin:amax+1] += results['P_a']
35 np.testing.assert_allclose(ref_rho_n, test_rho_n, atol=1e-10)