Coverage for gpaw/test/lrtddft/test_2.py: 100%
31 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
2from ase import Atoms
3from gpaw import GPAW
4from gpaw.lrtddft import LrTDDFT
5from gpaw.lrtddft.spectrum import spectrum
8@pytest.mark.lrtddft
9def test_lrtddft_2(in_tmp_dir):
10 txt = None
11 xc = 'LDA'
13 R = 0.7 # approx. experimental bond length
14 a = 4.0
15 c = 5.0
16 H2 = Atoms('HH',
17 [(a / 2, a / 2, (c - R) / 2),
18 (a / 2, a / 2, (c + R) / 2)],
19 cell=(a, a, c))
21 calc = GPAW(mode='fd',
22 xc=xc,
23 nbands=2,
24 spinpol=False,
25 eigensolver='rmm-diis',
26 txt=txt)
27 H2.calc = calc
28 H2.get_potential_energy()
29 calc.write('H2saved_wfs.gpw', 'all')
30 calc.write('H2saved.gpw')
32 print('-> starting directly after a gs calculation')
33 lr = LrTDDFT(calc, txt='-')
34 lr.diagonalize()
36 print('-> reading gs with wfs')
37 gs = GPAW('H2saved_wfs.gpw', txt=txt)
39 lr1 = LrTDDFT(gs, xc=xc, txt='-')
40 # check the oscillator strength
41 assert (abs(lr1[0].get_oscillator_strength()[0] /
42 lr[0].get_oscillator_strength()[0] - 1) < 1e-7)
44 print('-> reading gs without wfs')
45 gs = GPAW('H2saved.gpw', txt=None)
47 lr2 = LrTDDFT(gs, txt='-')
48 # check the oscillator strrength
49 d = abs(lr2[0].get_oscillator_strength()[0] /
50 lr[0].get_oscillator_strength()[0] - 1)
51 assert (d < 2e-3), d
53 # write spectrum
54 spectrum(lr, 'spectrum.dat')