Coverage for gpaw/test/response/test_bse_magnon.py: 31%
35 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1import pytest
2from gpaw.mpi import world
3from gpaw.utilities import compiled_with_sl
4import numpy as np
5from ase import Atoms
6from gpaw import GPAW, FermiDirac
7from gpaw.test import findpeak
8from gpaw.response.bse import BSE
10pytestmark = pytest.mark.skipif(
11 world.size < 4 or not compiled_with_sl(),
12 reason='world.size < 4 or not compiled_with_sl()')
15@pytest.mark.response
16def test_response_bse_magnon(in_tmp_dir):
17 calc = GPAW(mode='pw',
18 xc='PBE',
19 nbands='nao',
20 occupations=FermiDirac(0.001),
21 convergence={'bands': -5},
22 kpts={'size': (3, 3, 1), 'gamma': True})
24 a = 3.945
25 c = 8.0
26 layer = Atoms(symbols='ScSe2',
27 cell=[a, a, c, 90, 90, 120],
28 pbc=(1, 1, 0),
29 scaled_positions=[(0, 0, 0),
30 (2 / 3, 1 / 3, 0.0),
31 (2 / 3, 1 / 3, 0.0)])
32 layer.positions[1, 2] += 1.466
33 layer.positions[2, 2] -= 1.466
34 layer.center(axis=2)
35 layer.set_initial_magnetic_moments([1.0, 0, 0])
36 layer.calc = calc
37 layer.get_potential_energy()
38 calc.write('ScSe2.gpw', mode='all')
40 eshift = 4.2
41 bse = BSE('ScSe2.gpw',
42 ecut=10,
43 valence_bands=[22],
44 conduction_bands=[23],
45 eshift=eshift,
46 nbands=15,
47 mode='BSE',
48 truncation='2D')
50 w_w = np.linspace(-2, 2, 4001)
51 chi_Gw = bse.get_magnetic_susceptibility(eta=0.1,
52 write_eig='chi+-_0_',
53 w_w=w_w)
55 w, I = findpeak(w_w, -chi_Gw[0].imag)
56 assert np.abs(w + 0.0195) < 0.001
57 assert np.abs(I - 4.676) < 0.01
59 bse = BSE('ScSe2.gpw',
60 ecut=10,
61 q_c=[1 / 3, 1 / 3, 0],
62 valence_bands=[22],
63 conduction_bands=[23],
64 eshift=eshift,
65 nbands=15,
66 mode='BSE',
67 truncation='2D')
69 w_w = np.linspace(-2, 2, 4001)
70 chi_Gw = bse.get_magnetic_susceptibility(eta=0.1,
71 write_eig='chi+-_1_',
72 w_w=w_w)
74 w, I = findpeak(w_w, -chi_Gw[0].imag)
75 assert np.abs(w + 0.0153) < 0.001
76 assert np.abs(I - 7.624) < 0.01