Coverage for gpaw/test/lcaotddft/test_rremission.py: 100%
45 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
1import pytest
2import numpy as np
4from gpaw.lcaotddft import LCAOTDDFT
5from gpaw.lcaotddft.dipolemomentwriter import DipoleMomentWriter
6from gpaw.lcaotddft.qed import RRemission
7from gpaw.tddft.spectrum import read_td_file_data
8from gpaw.tddft.units import as_to_au
11@pytest.mark.rttddft
12def test_rremission(gpw_files, in_tmp_dir):
13 dt = 40
14 niter = 20
16 env = {'environment': 'waveguide',
17 'quantization_plane': 0.5,
18 'cavity_polarization': [0, 0, 1]}
19 td_calc = LCAOTDDFT(gpw_files['na2_tddft_dzp'],
20 rremission=RRemission(env),
21 propagator={'name': 'scpc', 'tolerance': 1e-0})
22 DipoleMomentWriter(td_calc, 'dm.dat')
23 td_calc.absorption_kick([0.0, 0.0, 1e-5])
24 td_calc.propagate(dt, niter)
26 times = np.arange(0, dt * (niter + 0.1), dt) * as_to_au
27 times = np.concatenate(([0], times)) # One inital zero before the kick
28 data = np.loadtxt('dm.dat')
30 # Check times in data file
31 np.testing.assert_allclose(data[:, 0], times)
33 # Check norm and x, y components
34 np.testing.assert_allclose(data[:, 1:4], 0, atol=1e-10)
36 # Check z component
37 ref_i = [
38 -3.982847629258e-14,
39 -3.914902027642e-14,
40 3.419488131280e-05,
41 6.328738771521e-05,
42 8.608533242884e-05,
43 1.032870345833e-04,
44 1.156375187581e-04,
45 1.238315688509e-04,
46 1.285064383632e-04,
47 1.302401811969e-04,
48 1.295514557099e-04,
49 1.269006285844e-04,
50 1.226921048004e-04,
51 1.172777277082e-04,
52 1.109610266703e-04,
53 1.040020450314e-04,
54 9.662244521506e-05,
55 8.901056071782e-05,
56 8.132605402745e-05,
57 7.370387298427e-05,
58 6.625729128738e-05,
59 5.907997327753e-05,
60 ]
62 np.testing.assert_allclose(data[:, 4], ref_i, atol=1e-10)
64 """
65 Restart check for rremission. Does restarting change the outcome?
66 """
68 env = {'environment': 'waveguide',
69 'quantization_plane': 0.5,
70 'cavity_polarization': [0, 0, 1]}
71 td_calc = LCAOTDDFT(gpw_files['na2_tddft_dzp'],
72 rremission=RRemission(env),
73 propagator={'name': 'scpc', 'tolerance': 1e-0})
74 DipoleMomentWriter(td_calc, 'dm_rrsplit.dat')
75 td_calc.absorption_kick([0.0, 0.0, 1e-5])
76 td_calc.propagate(40, 10)
77 td_calc.write('td_rrsplit0.gpw', mode='all')
79 td_calc_restart = LCAOTDDFT('td_rrsplit0.gpw')
80 DipoleMomentWriter(td_calc_restart, 'dm_rrsplit.dat')
81 td_calc_restart.propagate(40, 10)
83 dipole_full = read_td_file_data('dm.dat')[1][-10:]
84 dipole_restart = read_td_file_data('dm_rrsplit.dat',)[1][-10:]
85 assert np.allclose(dipole_full, dipole_restart)
88@pytest.mark.ci
89def test_legacy_parameters():
90 quantization_plane = 0.5
91 cavity_polarization = [0, 0, 1]
92 env = {'environment': 'waveguide',
93 'quantization_plane': quantization_plane,
94 'cavity_polarization': cavity_polarization}
96 # The proper way of setting up the RRemission
97 rr = RRemission(env)
99 # The legacy way
100 with pytest.warns(FutureWarning):
101 rr_legacy = RRemission(quantization_plane, cavity_polarization)
103 # The environment should be the same
104 assert rr.environment.todict() == rr_legacy.environment.todict()