Coverage for gpaw/test/gllb/test_spin.py: 100%
29 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
1import pytest
2from ase.build import bulk
4from gpaw import GPAW, FermiDirac
7@pytest.mark.gllb
8@pytest.mark.libxc
9def test_gllb_spin():
10 for spin in [False, True]:
11 a = 3.56
12 atoms = bulk('C', 'diamond', a=a)
13 calc = GPAW(mode='fd',
14 kpts=(3, 3, 3),
15 xc='GLLBSC',
16 spinpol=spin,
17 nbands=8,
18 convergence={'bands': 6, 'density': 1e-6},
19 occupations=FermiDirac(width=0.005))
20 atoms.calc = calc
21 atoms.get_potential_energy()
22 resp = calc.hamiltonian.xc.response
23 # Eks is the Kohn-Sham gap and Dxc is the derivative discontinuity
24 if spin:
25 homoa, lumoa = calc.get_homo_lumo(spin=0)
26 homob, lumob = calc.get_homo_lumo(spin=1)
27 dxc_pot = resp.calculate_discontinuity_potential((homoa, homob),
28 (lumoa, lumob))
29 Eksa, Dxca = resp.calculate_discontinuity(dxc_pot, spin=0)
30 Eksb, Dxcb = resp.calculate_discontinuity(dxc_pot, spin=1)
31 Gapa = Eksa + Dxca
32 Gapb = Eksb + Dxcb
33 print("GAP", spin, Gapa, Gapb)
34 else:
35 homo, lumo = calc.get_homo_lumo()
36 dxc_pot = resp.calculate_discontinuity_potential(homo, lumo)
37 Eks, Dxc = resp.calculate_discontinuity(dxc_pot)
38 Gap = Eks + Dxc
39 print("GAP", spin, Gap)
41 assert Gapa == pytest.approx(Gapb, abs=1e-4)
42 assert Gapa == pytest.approx(Gap, abs=1e-4)