Coverage for gpaw/test/tddft/test_td_na2.py: 100%

40 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-20 00:19 +0000

1import pytest 

2 

3from gpaw import GPAW 

4from gpaw.tddft import TDDFT, DipoleMomentWriter, photoabsorption_spectrum 

5from gpaw.tddft.abc import PML, LinearAbsorbingBoundary, P4AbsorbingBoundary 

6 

7 

8def test_tddft_td_na2(in_tmp_dir, gpw_files): 

9 """Sodium dimer, Na2.""" 

10 atoms = GPAW(gpw_files['na2_fd']).atoms 

11 # 16 fs run with 8.0 attosec time step 

12 time_step = 8.0 # 8.0 as (1 as = 0.041341 autime)5D 

13 iters = 10 # 2000 x 8 as => 16 fs 

14 # Weak delta kick to z-direction 

15 kick = [0, 0, 1e-3] 

16 

17 # TDDFT calculator 

18 td_calc = TDDFT(gpw_files['na2_fd']) 

19 DipoleMomentWriter(td_calc, 'na2_dmz.dat') 

20 # Kick 

21 td_calc.absorption_kick(kick) 

22 # Propagate 

23 td_calc.propagate(time_step, iters) 

24 td_calc.write('na2_td.gpw', mode='all') 

25 # Linear absorption spectrum 

26 photoabsorption_spectrum('na2_dmz.dat', 'na2_spectrum_z.dat', width=0.3) 

27 

28 iters = 3 

29 

30 # test restart 

31 td_rest = TDDFT('na2_td.gpw') 

32 DipoleMomentWriter(td_rest, 'na2_dmz.dat') 

33 td_rest.propagate(time_step, iters) 

34 

35 # test restart 

36 td_rest = TDDFT('na2_td.gpw', solver='BiCGStab') 

37 DipoleMomentWriter(td_rest, 'na2_dmz3.dat', force_new_file=True) 

38 td_rest.propagate(time_step, iters) 

39 

40 # test absorbing boundary conditions 

41 

42 # linear imaginary potential 

43 td_ipabs = TDDFT(gpw_files['na2_fd']) 

44 ip_abc = LinearAbsorbingBoundary(5.0, 0.01, atoms.positions) 

45 td_ipabs.set_absorbing_boundary(ip_abc) 

46 DipoleMomentWriter(td_ipabs, 'na2_dmz4.dat') 

47 td_ipabs.propagate(time_step, iters) 

48 

49 # 4th order polynomial (1-(x^2-1)^2) imaginary potential 

50 td_ip4abs = TDDFT(gpw_files['na2_fd']) 

51 ip4_abc = P4AbsorbingBoundary(5.0, 0.03, atoms.positions, 3.0) 

52 td_ip4abs.set_absorbing_boundary(ip4_abc) 

53 DipoleMomentWriter(td_ip4abs, 'na2_dmz5.dat') 

54 td_ip4abs.propagate(time_step, iters) 

55 

56 # perfectly matched layers 

57 td_pmlabs = TDDFT(gpw_files['na2_fd'], solver='BiCGStab') 

58 pml_abc = PML(100.0, 0.1) 

59 td_pmlabs.set_absorbing_boundary(pml_abc) 

60 DipoleMomentWriter(td_pmlabs, 'na2_dmz6.dat') 

61 td_pmlabs.propagate(time_step, iters) 

62 

63 

64def test_tddft_fail_with_symmetry(in_tmp_dir, gpw_files): 

65 

66 # Time-propagation calculation 

67 # should not be allowed with symmetries 

68 with pytest.raises(ValueError): 

69 TDDFT(gpw_files['na2_fd_with_sym'])