Coverage for gpaw/test/lrtddft2/test_Al2.py: 90%
51 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-08 00:17 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-08 00:17 +0000
1import pytest
2from gpaw import GPAW, FermiDirac
3from gpaw.mpi import world, size, rank
4from gpaw.lrtddft2 import LrTDDFT2
5from gpaw.lrtddft2.lr_communicators import LrCommunicators
6from ase.atoms import Atoms
9@pytest.mark.lrtddft
10def test_lrtddft2_Al2(in_tmp_dir):
11 debug = False
12 restart_file = 'Al2_gs.gpw'
14 d = 2.563
15 atoms = Atoms('Al2', positions=((0, 0, 0),
16 (0, 0, d)))
17 atoms.center(4.0)
18 calc = GPAW(mode='fd', h=0.24, eigensolver='cg', basis='dzp',
19 occupations=FermiDirac(width=0.01),
20 convergence={'eigenstates': 4.0e-5,
21 'density': 1.0e-2,
22 'bands': 'all'},
23 nbands=20)
24 atoms.calc = calc
25 atoms.get_potential_energy()
26 calc.write(restart_file, mode='all')
28 # Try to run parallel over eh-pairs
29 if size % 2 == 0:
30 eh_size = 2
31 domain_size = size // eh_size
32 else:
33 eh_size = 1
34 domain_size = size
36 lr_comms = LrCommunicators(world, domain_size, eh_size)
38 calc = GPAW(restart_file,
39 communicator=lr_comms.dd_comm)
40 de = 3.0
41 lr = LrTDDFT2('Al2_lri',
42 calc,
43 fxc='PBE',
44 max_energy_diff=de,
45 lr_communicators=lr_comms
46 )
47 w, S, R, Sx, Sy, Sz = lr.get_transitions(max_energy=1e9, units='au')
49 e0_1 = w[0]
50 e1_1 = w[-1]
51 # Continue with larger de
52 de = 4.5
53 lr = LrTDDFT2('Al2_lri',
54 calc,
55 fxc='PBE',
56 max_energy_diff=de,
57 lr_communicators=lr_comms)
58 w, S, R, Sx, Sy, Sz = lr.get_transitions(max_energy=1e9, units='au')
59 e0_2 = w[0]
60 e1_2 = w[-1]
61 # Continue with smaller de
62 de = 2.5
63 lr = LrTDDFT2('Al2_lri',
64 calc,
65 fxc='PBE',
66 max_energy_diff=de,
67 lr_communicators=lr_comms)
68 w, S, R, Sx, Sy, Sz = lr.get_transitions(max_energy=1e9, units='au')
69 e0_3 = w[0]
70 e1_3 = w[-1]
72 if debug and rank == 0:
73 print(e0_1, e1_1)
74 print(e0_2, e1_2)
75 print(e0_3, e1_3)
77 tol = 5.0e-8
78 assert e0_1 == pytest.approx(e0_2, abs=tol)
79 assert e0_1 == pytest.approx(e0_3, abs=tol)
80 tol = 1.0e-3
81 assert e0_1 == pytest.approx(0.00105074187176, abs=tol)
82 assert e1_1 == pytest.approx(0.183188157301, abs=tol)
83 assert e1_2 == pytest.approx(0.194973135812, abs=tol)
84 assert e1_3 == pytest.approx(0.120681529342, abs=tol)