Coverage for gpaw/test/hubbard/test_hubbard_U.py: 100%
22 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
1from math import sqrt
3from ase import Atoms
4from ase.dft.bandgap import bandgap
6from gpaw import GPAW, FermiDirac
7import pytest
10def test_Hubbard_U(in_tmp_dir):
11 """Setup up bulk NiO in an antiferromagnetic configuration."""
12 # Lattice constant:
13 a = 4.19
14 b = a / sqrt(2)
16 m = 2
17 k = 2 # number of k-points
19 atoms = Atoms(
20 symbols='Ni2O2',
21 pbc=True,
22 cell=(b, b, a),
23 positions=[(0, 0, 0),
24 (b / 2, b / 2, a / 2),
25 (0, 0, a / 2),
26 (b / 2, b / 2, 0)],
27 magmoms=(m, -m, 0, 0))
29 name = 'ni2o2'
30 for setup in ['10', '10:d,6.0']:
31 calc = GPAW(
32 mode='pw',
33 occupations=FermiDirac(width=0.05),
34 setups={'Ni': setup},
35 convergence={'eigenstates': 8e-4,
36 'density': 1.0e-2,
37 'energy': 0.1},
38 txt=name + '.txt',
39 kpts=(k, k, k),
40 xc='oldPBE')
41 atoms.calc = calc
42 atoms.get_potential_energy()
43 gap, _, _ = bandgap(calc)
44 print(name, gap)
45 if name == 'ni2o2':
46 assert gap == pytest.approx(0.8, abs=0.1)
47 else:
48 assert gap == pytest.approx(4.7, abs=0.2)
49 name += '+U'