1from ase import Atoms
2
3from gpaw import GPAW
4from gpaw.tddft import TDDFT, DipoleMomentWriter, photoabsorption_spectrum
5from gpaw.tddft.abc import LinearAbsorbingBoundary, P4AbsorbingBoundary, PML
6
7
8def test_tddft_td_na2(in_tmp_dir):
9    """Sodium dimer, Na2."""
10    d = 1.5
11    atoms = Atoms(symbols='Na2',
12                  positions=[(0, 0, d),
13                             (0, 0, -d)],
14                  pbc=False)
15
16    # Calculate ground state for TDDFT
17
18    # Larger box
19    atoms.center(vacuum=6.0)
20    # Larger grid spacing, LDA is ok
21    gs_calc = GPAW(nbands=1, h=0.35, xc='LDA', setups={'Na': '1'})
22    atoms.calc = gs_calc
23    atoms.get_potential_energy()
24    gs_calc.write('na2_gs.gpw', 'all')
25
26    # 16 fs run with 8.0 attosec time step
27    time_step = 8.0  # 8.0 as (1 as = 0.041341 autime)5D
28    iters = 10     # 2000 x 8 as => 16 fs
29    # Weak delta kick to z-direction
30    kick = [0, 0, 1e-3]
31
32    # TDDFT calculator
33    td_calc = TDDFT('na2_gs.gpw')
34    DipoleMomentWriter(td_calc, 'na2_dmz.dat')
35    # Kick
36    td_calc.absorption_kick(kick)
37    # Propagate
38    td_calc.propagate(time_step, iters)
39    td_calc.write('na2_td.gpw', mode='all')
40    # Linear absorption spectrum
41    photoabsorption_spectrum('na2_dmz.dat', 'na2_spectrum_z.dat', width=0.3)
42
43    iters = 3
44
45    # test restart
46    td_rest = TDDFT('na2_td.gpw')
47    DipoleMomentWriter(td_rest, 'na2_dmz.dat')
48    td_rest.propagate(time_step, iters)
49
50    # test restart
51    td_rest = TDDFT('na2_td.gpw', solver='BiCGStab')
52    DipoleMomentWriter(td_rest, 'na2_dmz3.dat', force_new_file=True)
53    td_rest.propagate(time_step, iters)
54
55    # test absorbing boundary conditions
56
57    # linear imaginary potential
58    td_ipabs = TDDFT('na2_gs.gpw')
59    ip_abc = LinearAbsorbingBoundary(5.0, 0.01, atoms.positions)
60    td_ipabs.set_absorbing_boundary(ip_abc)
61    DipoleMomentWriter(td_ipabs, 'na2_dmz4.dat')
62    td_ipabs.propagate(time_step, iters)
63
64    # 4th order polynomial (1-(x^2-1)^2) imaginary potential
65    td_ip4abs = TDDFT('na2_gs.gpw')
66    ip4_abc = P4AbsorbingBoundary(5.0, 0.03, atoms.positions, 3.0)
67    td_ip4abs.set_absorbing_boundary(ip4_abc)
68    DipoleMomentWriter(td_ip4abs, 'na2_dmz5.dat')
69    td_ip4abs.propagate(time_step, iters)
70
71    # perfectly matched layers
72    td_pmlabs = TDDFT('na2_gs.gpw', solver='BiCGStab')
73    pml_abc = PML(100.0, 0.1)
74    td_pmlabs.set_absorbing_boundary(pml_abc)
75    DipoleMomentWriter(td_pmlabs, 'na2_dmz6.dat')
76    td_pmlabs.propagate(time_step, iters)
77