Coverage for gpaw/test/fdtd/test_ed.py: 100%
27 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
1import pytest
2from gpaw import GPAW
3from gpaw.tddft import TDDFT, DipoleMomentWriter
6@pytest.mark.old_gpaw_only
7def test_fdtd_ed(in_tmp_dir, gpw_files):
8 # Accuracy
9 energy_eps = 0.0005
11 # load gpw file
12 gs_calc = GPAW(gpw_files['na2_isolated'])
13 energy = gs_calc.get_potential_energy()
15 # Test ground state
16 assert energy == pytest.approx(
17 -0.631881, abs=energy_eps * gs_calc.get_number_of_electrons())
19 # Test floating point arithmetic errors
20 assert gs_calc.hamiltonian.poisson.shift_indices_1 == pytest.approx(
21 [4, 4, 10], abs=0)
22 assert gs_calc.hamiltonian.poisson.shift_indices_2 == pytest.approx(
23 [8, 8, 16], abs=0)
25 # Initialize TDDFT and FDTD
26 kick = [0.0, 0.0, 1.0e-3]
27 time_step = 10.0
28 max_time = 100 # 0.1 fs
30 td_calc = TDDFT(gpw_files['na2_isolated'])
31 DipoleMomentWriter(td_calc, 'dm.dat')
32 td_calc.absorption_kick(kick_strength=kick)
34 # Propagate TDDFT and FDTD
35 td_calc.propagate(time_step, max_time / time_step / 2)
36 td_calc.write('td.gpw', 'all')
38 td_calc2 = TDDFT('td.gpw')
39 DipoleMomentWriter(td_calc2, 'dm.dat')
40 td_calc2.propagate(time_step, max_time / time_step / 2)
42 # Test
43 ref_cl_dipole_moment = [5.25374117e-14, 5.75811267e-14, 3.08349334e-02]
44 ref_qm_dipole_moment = [1.78620337e-11, -1.57782578e-11, 5.21368300e-01]
46 tol = 1e-4
47 assert td_calc2.hamiltonian.poisson.get_classical_dipole_moment() == (
48 pytest.approx(ref_cl_dipole_moment, abs=tol))
49 assert td_calc2.hamiltonian.poisson.get_quantum_dipole_moment() == (
50 pytest.approx(ref_qm_dipole_moment, abs=tol))