Coverage for gpaw/test/lcao/test_pair_and_coulomb.py: 100%
36 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
1import pytest
2import numpy as np
3import pickle
5from gpaw.lcao.tools import makeU, makeV
6from gpaw import restart
7from gpaw.lcao.pwf2 import LCAOwrap
8from gpaw.mpi import world, rank, serial_comm
10pytestmark = pytest.mark.skipif(world.size > 1,
11 reason='world.size > 1')
14@pytest.mark.legacy
15def test_lcao_pair_and_coulomb(gpw_files, in_tmp_dir):
16 if rank == 0:
17 atoms, calc = restart(gpw_files['h2_lcao_pair'],
18 txt=None, communicator=serial_comm)
19 lcao = LCAOwrap(calc)
20 H = lcao.get_hamiltonian()
21 S = lcao.get_overlap()
22 with open('lcao_pair_hs.pckl', 'wb') as fd:
23 pickle.dump((H, S), fd, 2)
24 # indices = get_bfi2(symbols, basis, scat)
25 indices = range(2)
26 lcao.get_xc(indices=indices).dump('lcao_pair_xc.pckl')
27 lcao.get_Fcore(indices=indices).dump('lcao_pair_Fcore.pckl')
28 w_wG = lcao.get_orbitals(indices=indices)
29 P_awi = lcao.get_projections(indices=indices)
30 with open('lcao_pair_w_wG__P_awi.pckl', 'wb') as fd:
31 pickle.dump((w_wG, P_awi), fd, 2)
33 world.barrier()
34 makeU(gpw_files['h2_lcao_pair'],
35 'lcao_pair_w_wG__P_awi.pckl',
36 'lcao_pair_eps_q__U_pq.pckl',
37 1.0e-5,
38 dppname='lcao_pair_D_pp.pckl')
40 world.barrier()
41 makeV(gpw_files['h2_lcao_pair'],
42 'lcao_pair_w_wG__P_awi.pckl',
43 'lcao_pair_eps_q__U_pq.pckl',
44 'lcao_pair_V_qq.pckl',
45 'lcao_pair_V_qq.log',
46 False)
48 world.barrier()
49 V_qq = np.load('lcao_pair_V_qq.pckl', allow_pickle=True)
50 eps_q, U_pq = np.load('lcao_pair_eps_q__U_pq.pckl', allow_pickle=True)
51 assert U_pq.flags.contiguous
52 Usq_pq = U_pq * np.sqrt(eps_q)
53 V_pp = np.dot(np.dot(Usq_pq, V_qq), Usq_pq.T.conj())
54 V_pp_ref = np.array(
55 [[15.34450177, 11.12669608, 11.12669608, 12.82934563],
56 [11.12669608, 8.82280293, 8.82280293, 11.12669608],
57 [11.12669608, 8.82280293, 8.82280293, 11.12669608],
58 [12.82934563, 11.12669608, 11.12669608, 15.34450178]])
59 assert abs(V_pp_ref - V_pp).max() == pytest.approx(0.0, abs=1.0e-5)