def test_jk(self): mf0 = scf.RHF(cell) dm = mf0.get_init_guess() mydf = aft.AFTDF(cell) mydf.mesh = [11] * 3 vj, vk = mydf.get_jk(dm, exxdiv='ewald') ej1 = numpy.einsum('ij,ji->', vj, dm) ek1 = numpy.einsum('ij,ji->', vk, dm) self.assertAlmostEqual(ej1, 3.0455881073561235 * (4. / 3.66768353356587)**2, 9) self.assertAlmostEqual(ek1, 7.7905480251964629 * (4. / 3.66768353356587)**2, 9) numpy.random.seed(12) nao = cell.nao_nr() dm = numpy.random.random((nao, nao)) dm = dm + dm.T vj1, vk1 = mydf.get_jk(dm, hermi=0, exxdiv='ewald') ej1 = numpy.einsum('ij,ji->', vj1, dm) ek1 = numpy.einsum('ij,ji->', vk1, dm) self.assertAlmostEqual(ej1, 12.234106555081793, 9) self.assertAlmostEqual(ek1, 43.988705494650802, 9) numpy.random.seed(1) kpt = numpy.random.random(3) vj, vk = mydf.get_jk(dm, 1, kpt, exxdiv='ewald') ej1 = numpy.einsum('ij,ji->', vj, dm) ek1 = numpy.einsum('ij,ji->', vk, dm) self.assertAlmostEqual(ej1, 12.233546641482697, 9) self.assertAlmostEqual(ek1, 43.946958026023722, 9)
def test_aft_k1_high_cost(self): kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((8, nao, nao)) mydf = aft.AFTDF(cell) mydf.kpts = kpts numpy.random.seed(1) dm = numpy.random.random((8, nao, nao)) dm = dm + dm.transpose(0, 2, 1) vk = aft_jk.get_k_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger(vk[0]), (8.7518173818250702 - 0.11793770445839372j) / 8, 9) self.assertAlmostEqual(finger( vk[1]), (5.7682393685317894 + 0.069482280306391239j) / 8, 9) self.assertAlmostEqual(finger( vk[2]), (7.1890462727492324 - 0.088727079644645671j) / 8, 9) self.assertAlmostEqual(finger(vk[3]), (10.08358152800003 + 0.1278144339422369j) / 8, 9) self.assertAlmostEqual(finger(vk[4]), (8.393281242945573 - 0.099410704957774876j) / 8, 9) self.assertAlmostEqual(finger(vk[5]), (7.9413682328898769 + 0.1015563120870652j) / 8, 9) self.assertAlmostEqual(finger( vk[6]), (7.3743790120272408 - 0.096290683129384574j) / 8, 9) self.assertAlmostEqual(finger(vk[7]), (6.8144379626901443 + 0.08071261392857812j) / 8, 9)
def test_aft_k(self): kpts = cell.get_abs_kpts([[-.25, -.25, -.25], [-.25, -.25, .25], [-.25, .25, -.25], [-.25, .25, .25], [.25, -.25, -.25], [.25, -.25, .25], [.25, .25, -.25], [.25, .25, .25]]) numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((8, nao, nao)) mydf = aft.AFTDF(cell) mydf.kpts = kpts vk = aft_jk.get_k_kpts(mydf, dm, 0, mydf.kpts) self.assertAlmostEqual(finger( vk[0]), (4.3373802352168278 - 0.062977052131451577j) / 8, 9) self.assertAlmostEqual(finger(vk[1]), (2.878809181709983 + 0.028843869853690692j) / 8, 9) self.assertAlmostEqual(finger( vk[2]), (3.7027622609953061 - 0.052034330663180237j) / 8, 9) self.assertAlmostEqual(finger( vk[3]), (5.0939994842559422 + 0.060094478876149444j) / 8, 9) self.assertAlmostEqual(finger( vk[4]), (4.2942087551592651 - 0.061138484763336887j) / 8, 9) self.assertAlmostEqual(finger( vk[5]), (3.9689429688683679 + 0.048471952758750547j) / 8, 9) self.assertAlmostEqual(finger( vk[6]), (3.6342630872923456 - 0.054892635365850449j) / 8, 9) self.assertAlmostEqual(finger( vk[7]), (3.3483735224533548 + 0.040877095049528467j) / 8, 9)
def test_ao2mo_7d(self): L = 3. n = 6 cell = pgto.Cell() cell.a = numpy.diag([L, L, L]) cell.mesh = [n, n, n] cell.atom = '''He 2. 2.2 2. He 1.2 1. 1.''' cell.basis = {'He': [[0, (1.2, 1)], [1, (0.6, 1)]]} cell.verbose = 0 cell.build(0, 0) kpts = cell.make_kpts([1, 3, 1]) nkpts = len(kpts) nao = cell.nao_nr() numpy.random.seed(1) mo = (numpy.random.random((nkpts, nao, nao)) + numpy.random.random( (nkpts, nao, nao)) * 1j) with_df = aft.AFTDF(cell, kpts) out = with_df.ao2mo_7d(mo, kpts) ref = numpy.empty_like(out) kconserv = kpts_helper.get_kconserv(cell, kpts) for ki, kj, kk in kpts_helper.loop_kkk(nkpts): kl = kconserv[ki, kj, kk] tmp = with_df.ao2mo((mo[ki], mo[kj], mo[kk], mo[kl]), kpts[[ki, kj, kk, kl]]) ref[ki, kj, kk] = tmp.reshape([nao] * 4) self.assertAlmostEqual(abs(out - ref).max(), 0, 12)
def test_get_eri_gamma(self): odf0 = mdf.MDF(cell1) odf = aft.AFTDF(cell1) ref = odf0.get_eri() eri0000 = odf.get_eri(compact=True) self.assertTrue(eri0000.dtype == numpy.double) self.assertTrue(np.allclose(eri0000, ref, atol=1e-6, rtol=1e-6)) self.assertAlmostEqual(finger(eri0000), 0.23714016293926865, 9)
def test_get_eri_0123(self): odf = aft.AFTDF(cell1) ref = kdf0.get_eri(kpts) eri1111 = odf.get_eri(kpts) self.assertAlmostEqual(abs(eri1111-ref).max(), 0, 9) self.assertAlmostEqual(finger(eri1111), (1.2917759427391706-0.013340252488069412j), 9) ref = fft.FFTDF(cell1).get_mo_eri([numpy.eye(cell1.nao_nr())]*4, kpts) self.assertAlmostEqual(abs(eri1111-ref).max(), 0, 9)
def test_get_eri_0123(self): odf = aft.AFTDF(cell1) ref = kdf0.get_eri(kpts) eri1111 = odf.get_eri(kpts) self.assertTrue(np.allclose(eri1111, ref, atol=1e-8, rtol=1e-8)) self.assertAlmostEqual(finger(eri1111), (1.2917759427391706-0.013340252488069412j), 9) ref = fft.FFTDF(cell1).get_mo_eri([numpy.eye(cell1.nao_nr())]*4, kpts) self.assertTrue(np.allclose(eri1111, ref, atol=1e-8, rtol=1e-8))
def get_hcore(self, cell=None, kpts=None): if cell is None: cell = self.cell if kpts is None: kpts_lst = numpy.zeros((1, 3)) else: kpts_lst = numpy.reshape(kpts, (-1, 3)) xcell, contr_coeff = self.get_xmol(cell) with_df = aft.AFTDF(xcell) c = lib.param.LIGHT_SPEED assert ('1E' in self.approx.upper()) if 'ATOM' in self.approx.upper(): atom_slices = xcell.offset_nr_by_atom() nao = xcell.nao_nr() x = numpy.zeros((nao, nao)) vloc = numpy.zeros((nao, nao)) wloc = numpy.zeros((nao, nao)) for ia in range(xcell.natm): ish0, ish1, p0, p1 = atom_slices[ia] shls_slice = (ish0, ish1, ish0, ish1) t1 = xcell.intor('int1e_kin', shls_slice=shls_slice) s1 = xcell.intor('int1e_ovlp', shls_slice=shls_slice) with xcell.with_rinv_at_nucleus(ia): z = -xcell.atom_charge(ia) v1 = z * xcell.intor('int1e_rinv', shls_slice=shls_slice) w1 = z * xcell.intor('int1e_prinvp', shls_slice=shls_slice) vloc[p0:p1, p0:p1] = v1 wloc[p0:p1, p0:p1] = w1 x[p0:p1, p0:p1] = x2c._x2c1e_xmatrix(t1, v1, w1, s1, c) else: raise NotImplementedError t = xcell.pbc_intor('int1e_kin', 1, lib.HERMITIAN, kpts_lst) s = xcell.pbc_intor('int1e_ovlp', 1, lib.HERMITIAN, kpts_lst) v = with_df.get_nuc(kpts_lst) #w = get_pnucp(with_df, kpts_lst) if self.basis is not None: s22 = s s21 = pbcgto.intor_cross('int1e_ovlp', xcell, cell, kpts=kpts_lst) h1_kpts = [] for k in range(len(kpts_lst)): # The treatment of pnucp local part has huge effects to hcore #h1 = x2c._get_hcore_fw(t[k], vloc, wloc, s[k], x, c) - vloc + v[k] #h1 = x2c._get_hcore_fw(t[k], v[k], w[k], s[k], x, c) h1 = x2c._get_hcore_fw(t[k], v[k], wloc, s[k], x, c) if self.basis is not None: c = lib.cho_solve(s22[k], s21[k]) h1 = reduce(numpy.dot, (c.T, h1, c)) if self.xuncontract and contr_coeff is not None: h1 = reduce(numpy.dot, (contr_coeff.T, h1, contr_coeff)) h1_kpts.append(h1) if kpts is None or numpy.shape(kpts) == (3, ): h1_kpts = h1_kpts[0] return lib.asarray(h1_kpts)
def test_get_eri_gamma(self): odf = aft.AFTDF(cell1) ref = kdf0.get_eri((kpts[0],kpts[0],kpts[0],kpts[0])) eri1111 = odf.get_eri((kpts[0],kpts[0],kpts[0],kpts[0])) self.assertTrue(np.allclose(eri1111, ref, atol=1e-6, rtol=1e-6)) self.assertAlmostEqual(finger(eri1111), (1.2410388899583582-5.2370501878355006e-06j), 9) eri1111 = odf.get_eri((kpts[0]+1e-8,kpts[0]+1e-8,kpts[0],kpts[0])) self.assertTrue(np.allclose(eri1111, ref, atol=1e-6, rtol=1e-6)) self.assertAlmostEqual(finger(eri1111), (1.2410388899583582-5.2370501878355006e-06j), 9)
def test_get_eri_0011(self): odf = aft.AFTDF(cell1) ref = kdf0.get_eri((kpts[0],kpts[0],kpts[1],kpts[1])) eri0011 = odf.get_eri((kpts[0],kpts[0],kpts[1],kpts[1])) self.assertTrue(np.allclose(eri0011, ref, atol=1e-3, rtol=1e-3)) self.assertAlmostEqual(finger(eri0011), (1.2410162858084512+0.00074485383749912936j), 9) ref = fft.FFTDF(cell1).get_mo_eri([numpy.eye(cell1.nao_nr())]*4, (kpts[0],kpts[0],kpts[1],kpts[1])) eri0011 = odf.get_eri((kpts[0],kpts[0],kpts[1],kpts[1])) self.assertTrue(np.allclose(eri0011, ref, atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(eri0011), (1.2410162860852818+0.00074485383748954838j), 9)
def test_aft_get_pp(self): v0 = pgto.pseudo.get_pp(cell, kpts[0]) v1 = aft.AFTDF(cell).get_pp(kpts) self.assertTrue(np.allclose(v0, v1[0], atol=1e-5, rtol=1e-5)) self.assertAlmostEqual(finger(v1[0]), (-5.6240305085898807+0.22094834207603817j), 8) v0 = pgto.pseudo.get_pp(cell, kpts[1]) self.assertTrue(np.allclose(v0, v1[1], atol=1e-5, rtol=1e-5)) self.assertAlmostEqual(finger(v1[1]), (-5.53877585793+1.043933371359j) ,8) self.assertAlmostEqual(finger(v1[2]), (-6.05309558678+0.281728966073j), 8) self.assertAlmostEqual(finger(v1[3]), (-5.60115995450+0.275973062529j), 8)
def test_init_aft_1d(self): cell = pgto.Cell() cell.atom = 'He 1. .5 .5; He .1 1.3 2.1' cell.basis = {'He': [(0, (2.5, 1)), (0, (1., 1))]} cell.a = np.eye(3) * 2.5 cell.dimension = 1 cell.mesh = [3, 3, 3] cell.build() f = aft.AFTDF(cell) np.random.seed(1) f.kpts = np.random.random((4, 3)) f.check_sanity()
def get_jk(self, dm, hermi=1, kpts=None, kpts_band=None, with_j=True, with_k=True, omega=None, exxdiv=None): if omega is not None: # J/K for RSH functionals cell = self.cell # * AFT is computationally more efficient than GDF if the Coulomb # attenuation tends to the long-range role (i.e. small omega). # * Note: changing to AFT integrator may cause small difference to # the GDF integrator. If a very strict GDF result is desired, # we can disable this trick by setting # LONGRANGE_AFT_TURNOVER_THRESHOLD to 0. # * The sparse mesh is not appropriate for low dimensional systems # with infinity vacuum since the ERI may require large mesh to # sample density in vacuum. if (omega < LONGRANGE_AFT_TURNOVER_THRESHOLD and cell.dimension >= 2 and cell.low_dim_ft_type != 'inf_vacuum'): mydf = aft.AFTDF(cell, self.kpts) mydf.ke_cutoff = aft.estimate_ke_cutoff_for_omega(cell, omega) mydf.mesh = tools.cutoff_to_mesh(cell.lattice_vectors(), mydf.ke_cutoff) else: mydf = self return _sub_df_jk_(mydf, dm, hermi, kpts, kpts_band, with_j, with_k, omega, exxdiv) if kpts is None: if numpy.all(self.kpts == 0): # Gamma-point calculation by default kpts = numpy.zeros(3) else: kpts = self.kpts kpts = numpy.asarray(kpts) if kpts.shape == (3, ): return df_jk.get_jk(self, dm, hermi, kpts, kpts_band, with_j, with_k, exxdiv) vj = vk = None if with_k: vk = df_jk.get_k_kpts(self, dm, hermi, kpts, kpts_band, exxdiv) if with_j: vj = df_jk.get_j_kpts(self, dm, hermi, kpts, kpts_band) return vj, vk
def test_aft_get_ao_eri(self): df0 = fft.FFTDF(cell1) df = aft.AFTDF(cell1) eri0 = df0.get_ao_eri(compact=True) eri1 = df.get_ao_eri(compact=True) self.assertAlmostEqual(abs(eri0 - eri1).max(), 0, 9) eri0 = df0.get_ao_eri(kpts[0]) eri1 = df.get_ao_eri(kpts[0]) self.assertAlmostEqual(abs(eri0 - eri1).max(), 0, 9) eri0 = df0.get_ao_eri(kpts) eri1 = df.get_ao_eri(kpts) self.assertAlmostEqual(abs(eri0 - eri1).max(), 0, 9)
def test_eri1111(self): kpts = numpy.random.random((4, 3)) * .25 kpts[3] = -numpy.einsum('ij->j', kpts[:3]) with_df = aft.AFTDF(cell) with_df.kpts = kpts mo = (numpy.random.random((nao, nao)) + numpy.random.random( (nao, nao)) * 1j) eri = with_df.get_eri(kpts).reshape((nao, ) * 4) eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj()) eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo) eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj()) eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo) eri1 = with_df.ao2mo(mo, kpts) self.assertAlmostEqual( abs(eri1.reshape(eri0.shape) - eri0).sum(), 0, 9)
def test_get_eri_0110(self): odf = aft.AFTDF(cell1) ref = kdf0.get_eri((kpts[0],kpts[1],kpts[1],kpts[0])) eri0110 = odf.get_eri((kpts[0],kpts[1],kpts[1],kpts[0])) self.assertTrue(np.allclose(eri0110, ref, atol=1e-6, rtol=1e-6)) eri0110 = odf.get_eri((kpts[0]+1e-8,kpts[1]+1e-8,kpts[1],kpts[0])) self.assertTrue(np.allclose(eri0110, ref, atol=1e-6, rtol=1e-6)) self.assertAlmostEqual(finger(eri0110), (1.2928399254827956-0.011820590601969154j), 9) ref = fft.FFTDF(cell1).get_mo_eri([numpy.eye(cell1.nao_nr())]*4, (kpts[0],kpts[1],kpts[1],kpts[0])) eri0110 = odf.get_eri((kpts[0],kpts[1],kpts[1],kpts[0])) self.assertTrue(np.allclose(eri0110, ref, atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(eri0110), (1.2928399254827956-0.011820590601969154j), 9) eri0110 = odf.get_eri((kpts[0]+1e-8,kpts[1]+1e-8,kpts[1],kpts[0])) self.assertTrue(np.allclose(eri0110, ref, atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(eri0110), (1.2928399254827956-0.011820590601969154j), 9)
def test_aft_get_ao_eri(self): df0 = fft.FFTDF(cell) df = aft.AFTDF(cell) eri0 = df0.get_ao_eri(compact=True) eri1 = df.get_ao_eri(compact=True) self.assertTrue(np.allclose(eri0, eri1, atol=1e-5, rtol=1e-5)) self.assertAlmostEqual(finger(eri1), 0.80425361966560172, 8) eri0 = df0.get_ao_eri(kpts[0]) eri1 = df.get_ao_eri(kpts[0]) self.assertTrue(np.allclose(eri0, eri1, atol=1e-5, rtol=1e-5)) self.assertAlmostEqual(finger(eri1), (2.9346374476387949-0.20479054936779137j), 8) eri0 = df0.get_ao_eri(kpts) eri1 = df.get_ao_eri(kpts) self.assertTrue(np.allclose(eri0, eri1, atol=1e-5, rtol=1e-5)) self.assertAlmostEqual(finger(eri1), (0.33709287302019619-0.94185725020966538j), 8)
def test_aft_j(self): numpy.random.seed(1) nao = cell.nao_nr() dm = numpy.random.random((4, nao, nao)) dm = dm + dm.transpose(0, 2, 1) mydf = aft.AFTDF(cell) mydf.kpts = numpy.random.random((4, 3)) mydf.mesh = numpy.asarray((11, ) * 3) vj = aft_jk.get_j_kpts(mydf, dm, 1, mydf.kpts) self.assertAlmostEqual(finger( vj[0]), (0.93946193432413905 + 0.00010862804196223034j) / 4, 9) self.assertAlmostEqual(finger( vj[1]), (0.94866073525335626 + 0.005571199307452865j) / 4, 9) self.assertAlmostEqual(finger( vj[2]), (1.1492194255929766 + 0.0093705761598793739j) / 4, 9) self.assertAlmostEqual(finger( vj[3]), (1.1397493412770023 + 0.010731970529096637j) / 4, 9)
def test_get_eri_gamma(self): odf = aft.AFTDF(cell1) ref = odf.get_eri(compact=True) df = fft.FFTDF(cell1) eri0000 = df.get_eri(compact=True) self.assertTrue(eri0000.dtype == numpy.double) self.assertTrue(np.allclose(eri0000, ref, atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(eri0000), 0.23714016293926865, 9) ref = odf.get_eri((kpts[0],kpts[0],kpts[0],kpts[0])) eri1111 = df.get_eri((kpts[0],kpts[0],kpts[0],kpts[0])) self.assertTrue(np.allclose(eri1111, ref, atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(eri1111), (1.2410388899583582-5.2370501878355006e-06j), 9) eri1111 = df.get_eri((kpts[0]+1e-8,kpts[0]+1e-8,kpts[0],kpts[0])) self.assertTrue(np.allclose(eri1111, ref, atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(eri1111), (1.2410388899583582-5.2370501878355006e-06j), 9)
def test_get_mo_eri(self): df0 = fft.FFTDF(cell) odf = aft.AFTDF(cell) nao = cell.nao_nr() numpy.random.seed(5) mo =(numpy.random.random((nao,nao)) + numpy.random.random((nao,nao))*1j) eri_mo0 = df0.get_mo_eri((mo,)*4, kpts) eri_mo1 = odf.get_mo_eri((mo,)*4, kpts) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-7, rtol=1e-7)) kpts_t = (kpts[2],kpts[3],kpts[0],kpts[1]) eri_mo2 = df0.get_mo_eri((mo,)*4, kpts_t) eri_mo2 = eri_mo2.reshape((nao,)*4).transpose(2,3,0,1).reshape(nao**2,-1) self.assertTrue(np.allclose(eri_mo2, eri_mo0, atol=1e-7, rtol=1e-7)) eri_mo0 = df0.get_mo_eri((mo,)*4, (kpts[0],)*4) eri_mo1 = odf.get_mo_eri((mo,)*4, (kpts[0],)*4) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-7, rtol=1e-7)) eri_mo0 = df0.get_mo_eri((mo,)*4, (kpts[0],kpts[1],kpts[1],kpts[0],)) eri_mo1 = odf.get_mo_eri((mo,)*4, (kpts[0],kpts[1],kpts[1],kpts[0],)) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-7, rtol=1e-7)) eri_mo0 = df0.get_mo_eri((mo,)*4, (kpt0,kpt0,kpts[0],kpts[0],)) eri_mo1 = odf.get_mo_eri((mo,)*4, (kpt0,kpt0,kpts[0],kpts[0],)) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-7, rtol=1e-7)) eri_mo0 = df0.get_mo_eri((mo,)*4, (kpts[0],kpts[0],kpt0,kpt0,)) eri_mo1 = odf.get_mo_eri((mo,)*4, (kpts[0],kpts[0],kpt0,kpt0,)) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-7, rtol=1e-7)) mo1 = mo[:,:nao//2+1] eri_mo0 = df0.get_mo_eri((mo1,mo,mo,mo1), (kpts[0],)*4) eri_mo1 = odf.get_mo_eri((mo1,mo,mo,mo1), (kpts[0],)*4) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-7, rtol=1e-7)) eri_mo0 = df0.get_mo_eri((mo1,mo,mo1,mo), (kpts[0],kpts[1],kpts[1],kpts[0],)) eri_mo1 = odf.get_mo_eri((mo1,mo,mo1,mo), (kpts[0],kpts[1],kpts[1],kpts[0],)) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-7, rtol=1e-7))
def test_eri0000(self): with_df = aft.AFTDF(cell) with_df.kpts = numpy.zeros((4, 3)) mo = (numpy.random.random((nao, nao)) + numpy.random.random( (nao, nao)) * 1j) eri = ao2mo.restore(1, with_df.get_eri(with_df.kpts), nao) eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj()) eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo) eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj()) eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo) eri1 = with_df.ao2mo(mo, with_df.kpts) self.assertAlmostEqual( abs(eri1.reshape(eri0.shape) - eri0).sum(), 0, 9) mo = mo.real eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj()) eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo) eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj()) eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo) eri1 = with_df.ao2mo(mo, with_df.kpts, compact=False) self.assertAlmostEqual( abs(eri1.reshape(eri0.shape) - eri0).sum(), 0, 9)
def test_aft_get_nuc(self): df = aft.AFTDF(cell) v1 = df.get_nuc(kpts[0]) self.assertAlmostEqual(finger(v1), (-5.764786312608102 + 0.19126292955145852j), 8)
def test_get_pp_loc_part1_high_cost(self): df = aft.AFTDF(cell) v1 = aft.get_pp_loc_part1(df, kpts[0]) self.assertAlmostEqual(finger(v1), (-6.0893491060887159 + 0.19823828749533859j), 8)
def test_aft_get_nuc(self): df = aft.AFTDF(cell) v1 = df.get_nuc(kpts[0]) self.assertAlmostEqual(finger(v1), (-6.0893491060887159 + 0.19823828749533859j), 8)
wj_kpts = wj_kpts[0] return numpy.asarray(wj_kpts) if __name__ == '__main__': from pyscf.pbc import scf cell = pbcgto.Cell() cell.build(unit='B', a=numpy.eye(3) * 4, mesh=[11] * 3, atom='H 0 0 0; H 0 0 1.8', verbose=4, basis='sto3g') lib.param.LIGHT_SPEED = 2 mf = scf.RHF(cell) mf.with_df = aft.AFTDF(cell) enr = mf.kernel() print('E(NR) = %.12g' % enr) mf = sfx2c1e(mf) esfx2c = mf.kernel() print('E(SFX2C1E) = %.12g' % esfx2c) mf = scf.KRHF(cell) mf.with_df = aft.AFTDF(cell) mf.kpts = cell.make_kpts([2, 2, 1]) enr = mf.kernel() print('E(k-NR) = %.12g' % enr) mf = sfx2c1e(mf) esfx2c = mf.kernel()
if __name__ == '__main__': from pyscf.pbc import gto as pgto from pyscf.pbc import scf as pscf from pyscf.pbc.df import aft L = 5. n = 5 cell = pgto.Cell() cell.a = numpy.diag([L,L,L]) cell.gs = numpy.array([n,n,n]) cell.atom = '''He 3. 2. 3. He 1. 1. 1.''' #cell.basis = {'He': [[0, (1.0, 1.0)]]} #cell.basis = '631g' #cell.basis = {'He': [[0, (2.4, 1)], [1, (1.1, 1)]]} cell.basis = 'ccpvdz' cell.verbose = 0 cell.build(0,0) cell.verbose = 5 df = aft.AFTDF(cell) df.gs = (15,)*3 dm = pscf.RHF(cell).get_init_guess() vj, vk = df.get_jk(dm) print(numpy.einsum('ij,ji->', df.get_nuc(), dm), 'ref=-10.577490961074622') print(numpy.einsum('ij,ji->', vj, dm), 'ref=5.3766911667862516') print(numpy.einsum('ij,ji->', vk, dm), 'ref=8.2255177602309022')
def get_pbc_pvxp(cell, kpts=None): import numpy import copy import time from pyscf import lib from pyscf.lib import logger from pyscf.pbc import tools from pyscf.gto import mole from pyscf.pbc.df import ft_ao from pyscf.pbc.df import aft_jk from pyscf.pbc.df import aft if kpts is None: kpts_lst = numpy.zeros((1,3)) else: kpts_lst = numpy.reshape(kpts, (-1,3)) log = logger.Logger(cell.stdout, cell.verbose) t1 = t0 = (time.clock(), time.time()) mydf = aft.AFTDF(cell, kpts) mydf.eta = 0.2 ke_guess = aft.estimate_ke_cutoff_for_eta(cell, mydf.eta, cell.precision) mydf.mesh = tools.cutoff_to_mesh(cell.lattice_vectors(), ke_guess) log.debug('mydf.mesh %s', mydf.mesh) nkpts = len(kpts_lst) nao = cell.nao_nr() nao_pair = nao * (nao+1) // 2 Gv, Gvbase, kws = cell.get_Gv_weights(mydf.mesh) charge = -cell.atom_charges() # Apply Koseki effective charge? kpt_allow = numpy.zeros(3) coulG = tools.get_coulG(cell, kpt_allow, mesh=mydf.mesh, Gv=Gv) coulG *= kws if mydf.eta == 0: soc_mat = numpy.zeros((nkpts,3,nao*nao), dtype=numpy.complex128) SI = cell.get_SI(Gv) vG = numpy.einsum('i,ix->x', charge, SI) * coulG else: nuccell = copy.copy(cell) half_sph_norm = .5/numpy.sqrt(numpy.pi) norm = half_sph_norm/mole.gaussian_int(2, mydf.eta) chg_env = [mydf.eta, norm] ptr_eta = cell._env.size ptr_norm = ptr_eta + 1 chg_bas = [[ia, 0, 1, 1, 0, ptr_eta, ptr_norm, 0] for ia in range(cell.natm)] nuccell._atm = cell._atm nuccell._bas = numpy.asarray(chg_bas, dtype=numpy.int32) nuccell._env = numpy.hstack((cell._env, chg_env)) soc_mat = mydf._int_nuc_vloc(nuccell, kpts_lst, 'int3c2e_pvxp1_sph', aosym='s1', comp=3) soc_mat = numpy.asarray(soc_mat).reshape(nkpts,3,nao**2) t1 = log.timer_debug1('pnucp pass1: analytic int', *t1) aoaux = ft_ao.ft_ao(nuccell, Gv) vG = numpy.einsum('i,xi->x', charge, aoaux) * coulG max_memory = max(2000, mydf.max_memory-lib.current_memory()[0]) for aoaoks, p0, p1 in mydf.ft_loop(mydf.mesh, kpt_allow, kpts_lst, max_memory=max_memory, aosym='s1', intor='GTO_ft_pxp_sph', comp=3): for k, aoao in enumerate(aoaoks): aoao = aoao.reshape(3,-1,nao**2) if aft_jk.gamma_point(kpts_lst[k]): soc_mat[k] += numpy.einsum('k,ckx->cx', vG[p0:p1].real, aoao.real) soc_mat[k] += numpy.einsum('k,ckx->cx', vG[p0:p1].imag, aoao.imag) else: soc_mat[k] += numpy.einsum('k,ckx->cx', vG[p0:p1].conj(), aoao) t1 = log.timer_debug1('contracting pnucp', *t1) soc_mat_kpts = [] for k, kpt in enumerate(kpts_lst): if aft_jk.gamma_point(kpt): soc_mat_kpts.append(soc_mat[k].real.reshape(3,nao,nao)) else: soc_mat_kpts.append(soc_mat[k].reshape(3,nao,nao)) if kpts is None or numpy.shape(kpts) == (3,): soc_mat_kpts = soc_mat_kpts[0] return numpy.asarray(soc_mat_kpts)