def test_get_jk(self): df = fft.DF(cell) dm = mf0.get_init_guess() vj0, vk0 = get_jk(mf0, cell, dm, kpt=kpts[0]) vj1, vk1 = df.get_jk(dm, kpts=kpts[0], exxdiv=None) self.assertTrue(vj1.dtype == numpy.complex128) self.assertTrue(vk1.dtype == numpy.complex128) self.assertTrue(np.allclose(vj0, vj1, atol=1e-9, rtol=1e-9)) self.assertTrue(np.allclose(vk0, vk1, atol=1e-9, rtol=1e-9)) ej1 = numpy.einsum('ij,ji->', vj1, dm) ek1 = numpy.einsum('ij,ji->', vk1, dm) self.assertAlmostEqual(ej1, 2.2642719646779832, 9) self.assertAlmostEqual(ek1, 3.2581479552187513, 9) dm = mf0.get_init_guess() vj0, vk0 = get_jk(mf0, cell, dm) vj1, vk1 = df.get_jk(dm, exxdiv=None) self.assertTrue(vj1.dtype == numpy.float64) self.assertTrue(vk1.dtype == numpy.float64) self.assertTrue(np.allclose(vj0, vj1, atol=1e-9, rtol=1e-9)) self.assertTrue(np.allclose(vk0, vk1, atol=1e-9, rtol=1e-9)) ej1 = numpy.einsum('ij,ji->', vj1, dm) ek1 = numpy.einsum('ij,ji->', vk1, dm) self.assertAlmostEqual(ej1, 2.4216815457582102, 9) self.assertAlmostEqual(ek1, 3.6061858403253977, 9)
def test_pwdf_get_nuc(self): v0 = fft.DF(cell).get_nuc(kpts[0]) df = pwdf.PWDF(cell) v1 = df.get_nuc(kpts[0]) self.assertTrue(np.allclose(v0, v1, atol=1e-4, rtol=1e-4)) self.assertAlmostEqual(finger(v1), (-5.7646030917912663 + 0.19126291999423831j), 8)
def test_get_eri_0123(self): odf = pwdf.PWDF(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.DF(cell1).get_mo_eri([numpy.eye(cell1.nao_nr())] * 4, kpts) self.assertTrue(np.allclose(eri1111, ref, atol=1e-8, rtol=1e-8))
def test_get_jk_kpts(self): df = fft.DF(cell) dm = mf0.get_init_guess() dms = [dm] * len(kpts) vj0, vk0 = get_jk_kpts(mf0, cell, dms, kpts=kpts) vj1, vk1 = df.get_jk(dms, kpts=kpts, exxdiv=None) self.assertTrue(vj1.dtype == numpy.complex128) self.assertTrue(vk1.dtype == numpy.complex128) self.assertTrue(np.allclose(vj0, vj1, atol=1e-9, rtol=1e-9)) self.assertTrue(np.allclose(vk0, vk1, atol=1e-9, rtol=1e-9)) ej1 = numpy.einsum('xij,xji->', vj1, dms) / len(kpts) ek1 = numpy.einsum('xij,xji->', vk1, dms) / len(kpts) self.assertAlmostEqual(ej1, 2.2785994326264971, 9) self.assertAlmostEqual(ek1, 7.5122832961825941, 9)
def test_get_pp(self): v0 = pgto.pseudo.get_pp(cell, kpts[0]) v1 = fft.DF(cell).get_pp(kpts) self.assertTrue(np.allclose(v0, v1[0], atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(v1[0]), (-5.6240249083785869 + 0.22094834302524968j), 8) v0 = pgto.pseudo.get_pp(cell, kpts[1]) self.assertTrue(np.allclose(v0, v1[1], atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(v1[1]), (-5.5387702576467603 + 1.0439333717227581j), 8) self.assertAlmostEqual(finger(v1[2]), (-6.0530899866313366 + 0.2817289667029651j), 8) self.assertAlmostEqual(finger(v1[3]), (-5.6011543542444446 + 0.27597306418805201j), 8)
def test_get_nuc(self): v0 = get_nuc(cell, kpts[0]) v1 = fft.DF(cell).get_nuc(kpts) self.assertTrue(np.allclose(v0, v1[0], atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(v1[0]), (-5.7646608099493841 + 0.19126294430138713j), 8) v0 = get_nuc(cell, kpts[1]) self.assertTrue(np.allclose(v0, v1[1], atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(v1[1]), (-5.6567258309199193 + 0.86813371243952175j), 8) self.assertAlmostEqual(finger(v1[2]), (-6.1528952645454895 + 0.09517054428060109j), 8) self.assertAlmostEqual(finger(v1[3]), (-5.7445962879770942 + 0.24611951427601772j), 8)
def test_get_ao_eri(self): df = fft.DF(cell) eri0 = get_ao_eri(cell) eri1 = df.get_ao_eri(compact=True) self.assertTrue(np.allclose(eri0, eri1, atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(eri1), 0.80425358275734926, 8) eri0 = get_ao_eri(cell, kpts[0]) eri1 = df.get_ao_eri(kpts[0]) self.assertTrue(np.allclose(eri0, eri1, atol=1e-9, rtol=1e-9)) self.assertAlmostEqual(finger(eri1), (2.9346374584901898 - 0.20479054936744959j), 8) eri4 = df.get_ao_eri(kpts) self.assertAlmostEqual(finger(eri4), (0.33709288394542991 - 0.94185725001175313j), 8)
def test_get_eri_0011(self): odf = pwdf.PWDF(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.DF(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_pwdf_get_ao_eri(self): df0 = fft.DF(cell) df = pwdf.PWDF(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_get_eri_gamma(self): odf = pwdf.PWDF(cell1) ref = odf.get_eri(compact=True) df = fft.DF(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_eri_0110(self): odf = pwdf.PWDF(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.DF(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_get_mo_eri(self): df = fft.DF(cell) nao = cell.nao_nr() numpy.random.seed(5) mo = (numpy.random.random((nao, nao)) + numpy.random.random( (nao, nao)) * 1j) eri_mo0 = get_mo_eri(cell, (mo, ) * 4, kpts) eri_mo1 = df.get_mo_eri((mo, ) * 4, kpts) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-9, rtol=1e-9)) kpts_t = (kpts[2], kpts[3], kpts[0], kpts[1]) eri_mo2 = get_mo_eri(cell, (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-9, rtol=1e-9)) eri_mo0 = get_mo_eri(cell, (mo, ) * 4, (kpts[0], ) * 4) eri_mo1 = df.get_mo_eri((mo, ) * 4, (kpts[0], ) * 4) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-9, rtol=1e-9)) eri_mo0 = get_mo_eri(cell, (mo, ) * 4, ( kpts[0], kpts[1], kpts[1], kpts[0], )) eri_mo1 = df.get_mo_eri((mo, ) * 4, ( kpts[0], kpts[1], kpts[1], kpts[0], )) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-9, rtol=1e-9)) eri_mo0 = get_mo_eri(cell, (mo, ) * 4, ( kpt0, kpt0, kpts[0], kpts[0], )) eri_mo1 = df.get_mo_eri((mo, ) * 4, ( kpt0, kpt0, kpts[0], kpts[0], )) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-9, rtol=1e-9)) eri_mo0 = get_mo_eri(cell, (mo, ) * 4, ( kpts[0], kpts[0], kpt0, kpt0, )) eri_mo1 = df.get_mo_eri((mo, ) * 4, ( kpts[0], kpts[0], kpt0, kpt0, )) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-9, rtol=1e-9)) mo1 = mo[:, :nao // 2 + 1] eri_mo0 = get_mo_eri(cell, (mo1, mo, mo, mo1), (kpts[0], ) * 4) eri_mo1 = df.get_mo_eri((mo1, mo, mo, mo1), (kpts[0], ) * 4) self.assertTrue(np.allclose(eri_mo1, eri_mo0, atol=1e-9, rtol=1e-9)) eri_mo0 = get_mo_eri(cell, (mo1, mo, mo1, mo), ( kpts[0], kpts[1], kpts[1], kpts[0], )) eri_mo1 = df.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-9, rtol=1e-9))