Example #1
0
 def test_rcut_vs_ke_cut(self):
     xc = 'lda,'
     with lib.temporary_env(multigrid, TASKS_TYPE='rcut'):
         mg_df = multigrid.MultiGridFFTDF(cell_orth)
         n1, exc1, v1 = multigrid.nr_rks(mg_df, xc, dm1, kpts=kpts)
         self.assertEqual(len(mg_df.tasks), 3)
     with lib.temporary_env(multigrid, TASKS_TYPE='ke_cut'):
         mg_df = multigrid.MultiGridFFTDF(cell_orth)
         n2, exc2, v2 = multigrid.nr_rks(mg_df, xc, dm1, kpts=kpts)
         self.assertEqual(len(mg_df.tasks), 6)
     self.assertAlmostEqual(n1, n2, 8)
     self.assertAlmostEqual(exc1, exc2, 8)
     self.assertAlmostEqual(abs(v1 - v2).max(), 0, 8)
Example #2
0
    def test_nr_uks_fxc(self):
        numpy.random.seed(9)
        dm1 = numpy.random.random(dm_he.shape)
        dm1 = dm1 + dm1.transpose(0, 2, 1)
        mydf = df.FFTDF(cell_he)
        ni = dft.numint.KNumInt()
        mg_df = multigrid.MultiGridFFTDF(cell_he)

        xc = 'lda,'
        ref = dft.numint.nr_uks_fxc(ni,
                                    cell_he,
                                    mydf.grids,
                                    xc, (dm_he, dm_he), (dm1, dm1),
                                    kpts=kpts)
        v = multigrid.nr_uks_fxc(mg_df,
                                 xc, (dm_he, dm_he), (dm1, dm1),
                                 kpts=kpts)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 9)

        xc = 'b88,'
        ref = dft.numint.nr_uks_fxc(ni,
                                    cell_he,
                                    mydf.grids,
                                    xc, (dm_he, dm_he), (dm1, dm1),
                                    kpts=kpts)
        v = multigrid.nr_uks_fxc(mg_df,
                                 xc, (dm_he, dm_he), (dm1, dm1),
                                 kpts=kpts)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 8)
Example #3
0
    def test_nr_rks_fxc_hermi0(self):
        numpy.random.seed(9)
        dm1 = numpy.random.random(
            dm_he.shape) + numpy.random.random(dm_he.shape) * 1j
        mydf = df.FFTDF(cell_he)
        ni = dft.numint.NumInt()
        mg_df = multigrid.MultiGridFFTDF(cell_he)

        xc = 'lda,'
        ref = dft.numint.nr_rks_fxc(ni,
                                    cell_he,
                                    mydf.grids,
                                    xc,
                                    dm_he[0],
                                    dm1,
                                    hermi=0)
        v = multigrid.nr_rks_fxc(mg_df, xc, dm_he[0], dm1, hermi=0)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 9)

        xc = 'b88,'
        ref = dft.numint.nr_rks_fxc(ni,
                                    cell_he,
                                    mydf.grids,
                                    xc,
                                    dm_he,
                                    dm1,
                                    hermi=0)
        v = multigrid.nr_rks_fxc(mg_df, xc, dm_he, dm1, hermi=0)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 6)
Example #4
0
    def test_gen_uhf_response(self):
        numpy.random.seed(9)
        dm1 = numpy.random.random(dm_he.shape)
        dm1 = dm1 + dm1.transpose(0, 2, 1)
        mydf = df.FFTDF(cell_he)
        ni = dft.numint.NumInt()

        mf = dft.UKS(cell_he)
        mf.with_df = multigrid.MultiGridFFTDF(cell_he)

        mf.xc = 'lda,'
        ref = dft.numint.nr_uks_fxc(ni, cell_he, mydf.grids, mf.xc, dm_he, dm1)
        vj = mydf.get_jk(dm1, with_k=False)[0]
        ref += vj[0] + vj[1]
        v = multigrid._gen_uhf_response(mf, dm_he, with_j=True)(dm1)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 9)

        mf.xc = 'b88,'
        ref = dft.numint.nr_uks_fxc(ni, cell_he, mydf.grids, mf.xc, dm_he, dm1)
        ref += vj[0] + vj[1]
        v = multigrid._gen_uhf_response(mf, dm_he, with_j=True)(dm1)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 7)
Example #5
0
 def test_orth_rks_lda_kpts(self):
     xc = 'lda,'
     mydf = df.FFTDF(cell_orth)
     ni = dft.numint.KNumInt()
     n, exc0, ref = ni.nr_rks(cell_orth, mydf.grids, xc, dm, 0, kpts=kpts)
     mydf = multigrid.MultiGridFFTDF(cell_orth)
     n, exc1, vxc = multigrid.nr_rks(mydf, xc, dm, kpts=kpts)
     self.assertAlmostEqual(float(abs(ref - vxc).max()), 0, 9)
     self.assertAlmostEqual(abs(exc0 - exc1).max(), 0, 8)
Example #6
0
 def test_orth_uks_gga_hermi0(self):
     xc = 'b88,'
     mydf = df.FFTDF(cell_orth)
     ni = dft.numint.NumInt()
     n, exc0, ref = ni.nr_uks(cell_orth, mydf.grids, xc, dm1, 0)
     ref += vj_uks_orth[0] + vj_uks_orth[1]
     mydf = multigrid.MultiGridFFTDF(cell_orth)
     n, exc1, vxc = multigrid.nr_uks(mydf, xc, dm1, hermi=0, with_j=True)
     self.assertAlmostEqual(float(abs(ref - vxc).max()), 0, 8)
     self.assertAlmostEqual(abs(exc0 - exc1).max(), 0, 8)
Example #7
0
    def test_eval_rhoG_nonorth_gga(self):
        mydf = multigrid.MultiGridFFTDF(cell_nonorth)
        rhoG = multigrid._eval_rhoG(mydf,
                                    dm,
                                    hermi=1,
                                    kpts=kpts,
                                    deriv=1,
                                    rhog_high_order=True)

        mydf = df.FFTDF(cell_nonorth)
        ni = dft.numint.KNumInt()
        ao_kpts = ni.eval_ao(cell_nonorth, mydf.grids.coords, kpts, deriv=1)
        ref = ni.eval_rho(cell_nonorth, ao_kpts, dm, xctype='GGA')
        rhoR = tools.ifft(rhoG[0], cell_nonorth.mesh).real
        rhoR *= numpy.prod(cell_nonorth.mesh) / cell_nonorth.vol
        self.assertAlmostEqual(abs(rhoR - ref).max(), 0, 7)
Example #8
0
    def test_gen_rhf_response(self):
        numpy.random.seed(9)
        dm1 = numpy.random.random(dm_he.shape)
        dm1 = dm1 + dm1.transpose(0, 2, 1)
        dm1[1] = dm1[0]
        mydf = df.FFTDF(cell_he)
        ni = dft.numint.KNumInt()

        mf = dft.KRKS(cell_he)
        mf.with_df = multigrid.MultiGridFFTDF(cell_he)
        mf.kpts = kpts

        mf.xc = 'lda,'
        ref = dft.numint.nr_rks_fxc(ni,
                                    cell_he,
                                    mydf.grids,
                                    mf.xc,
                                    dm_he,
                                    dm1,
                                    hermi=1,
                                    kpts=kpts)
        vj = mydf.get_jk(dm1, with_k=False, kpts=kpts)[0]
        ref += vj
        v = multigrid._gen_rhf_response(mf, dm_he, hermi=1)(dm1)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 9)

        mf.xc = 'b88,'
        ref = dft.numint.nr_rks_fxc(ni,
                                    cell_he,
                                    mydf.grids,
                                    mf.xc,
                                    dm_he,
                                    dm1,
                                    hermi=1,
                                    kpts=kpts)
        ref += vj
        v = multigrid._gen_rhf_response(mf, dm_he, hermi=1)(dm1)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 6)
Example #9
0
 def test_orth_rks_gga_kpts(self):
     xc = 'b88,'
     mydf = df.FFTDF(cell_orth)
     ni = dft.numint.KNumInt()
     n, exc0, ref = ni.nr_rks(cell_orth,
                              mydf.grids,
                              xc,
                              dm,
                              hermi=1,
                              kpts=kpts)
     ref += mydf.get_jk(dm, hermi=1, with_k=False, kpts=kpts)[0]
     mydf = multigrid.MultiGridFFTDF(cell_orth)
     n, exc1, vxc = multigrid.nr_rks(mydf,
                                     xc,
                                     dm,
                                     hermi=1,
                                     kpts=kpts,
                                     with_j=True)
     self.assertAlmostEqual(float(abs(ref - vxc).max()), 0, 9)
     self.assertAlmostEqual(abs(exc0 - exc1).max(), 0, 8)
Example #10
0
    def test_eval_rhoG_orth_kpts(self):
        numpy.random.seed(9)
        dm = numpy.random.random(
            dm1.shape) + numpy.random.random(dm1.shape) * 1j
        mydf = multigrid.MultiGridFFTDF(cell_orth)
        rhoG = multigrid._eval_rhoG(mydf,
                                    dm,
                                    hermi=0,
                                    kpts=kpts,
                                    deriv=0,
                                    rhog_high_order=True)
        self.assertTrue(rhoG.dtype == numpy.complex128)

        mydf = df.FFTDF(cell_orth)
        ni = dft.numint.KNumInt()
        ao_kpts = ni.eval_ao(cell_orth, mydf.grids.coords, kpts, deriv=0)
        ref = ni.eval_rho(cell_orth, ao_kpts, dm, hermi=0, xctype='LDA')
        rhoR = tools.ifft(rhoG[0], cell_orth.mesh).real
        rhoR *= numpy.prod(cell_orth.mesh) / cell_orth.vol
        self.assertAlmostEqual(abs(rhoR - ref).max(), 0, 8)
Example #11
0
 def test_orth_get_nuc_kpts(self):
     ref = df.FFTDF(cell_orth).get_nuc(kpts)
     out = multigrid.MultiGridFFTDF(cell_orth).get_nuc(kpts)
     self.assertAlmostEqual(abs(ref - out).max(), 0, 8)
Example #12
0
 def test_nonorth_get_pp(self):
     ref = df.FFTDF(cell_nonorth).get_pp()
     out = multigrid.MultiGridFFTDF(cell_nonorth).get_pp()
     self.assertAlmostEqual(abs(ref - out).max(), 0, 9)
Example #13
0
 def test_nonorth_get_j(self):
     ref = df.FFTDF(cell_nonorth).get_jk(dm[0], with_k=False)[0]
     out = multigrid.MultiGridFFTDF(cell_nonorth).get_jk(dm)[0]
     self.assertAlmostEqual(abs(ref - out).max(), 0, 9)
Example #14
0
    def test_nr_rks_fxc_st(self):
        numpy.random.seed(9)
        dm1 = numpy.random.random(
            dm_he.shape) + numpy.random.random(dm_he.shape) * 1j
        dm1[1] = dm1[0]
        mydf = df.FFTDF(cell_he)
        ni = dft.numint.KNumInt()
        mg_df = multigrid.MultiGridFFTDF(cell_he)

        mf = dft.KRKS(cell_he)
        mf.with_df = mg_df
        mf.kpts = kpts

        xc = 'lda,'
        ref = dft.numint.nr_rks_fxc_st(ni,
                                       cell_he,
                                       mydf.grids,
                                       xc,
                                       dm_he,
                                       dm1,
                                       singlet=True,
                                       kpts=kpts)
        v = multigrid.nr_rks_fxc_st(mg_df,
                                    xc,
                                    dm_he,
                                    dm1,
                                    singlet=True,
                                    kpts=kpts)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 4)

        mf.xc = 'b88,'
        ref = dft.numint.nr_rks_fxc_st(ni,
                                       cell_he,
                                       mydf.grids,
                                       mf.xc,
                                       dm_he,
                                       dm1,
                                       singlet=True,
                                       kpts=kpts)
        v = multigrid._gen_rhf_response(mf, dm_he, singlet=True)(dm1)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 5)

        mf.xc = 'lda,'
        ref = dft.numint.nr_rks_fxc_st(ni,
                                       cell_he,
                                       mydf.grids,
                                       mf.xc,
                                       dm_he,
                                       dm1,
                                       singlet=False,
                                       kpts=kpts)
        v = multigrid._gen_rhf_response(mf, dm_he, singlet=False)(dm1)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 4)

        xc = 'b88,'
        ref = dft.numint.nr_rks_fxc_st(ni,
                                       cell_he,
                                       mydf.grids,
                                       xc,
                                       dm_he,
                                       dm1,
                                       singlet=False,
                                       kpts=kpts)
        v = multigrid.nr_rks_fxc_st(mg_df,
                                    xc,
                                    dm_he,
                                    dm1,
                                    singlet=False,
                                    kpts=kpts)
        self.assertEqual(ref.dtype, v.dtype)
        self.assertEqual(ref.shape, v.shape)
        self.assertAlmostEqual(abs(v - ref).max(), 0, 5)
Example #15
0
 def test_orth_get_j_kpts(self):
     ref = df.FFTDF(cell_orth).get_jk(dm, kpts=kpts, with_k=False)[0]
     out = multigrid.MultiGridFFTDF(cell_orth).get_jk(dm, kpts=kpts)[0]
     self.assertAlmostEqual(abs(ref - out).max(), 0, 9)
Example #16
0
H       2.856874      11.297981       7.433660
H       1.492332      11.195517       6.786033
H       7.145820       0.090200       9.749009
H       7.227275       0.077690      11.260665
H       4.662021       9.538430      10.798155
H       5.994537       9.833472      10.142985
H      10.544299       6.595857      10.301445
H      11.281750       5.653082       9.374494
H      12.103020       8.841164      10.006916
H      11.491592       8.576221       8.647557
""",
                basis='gth-tzv2p',
                pseudo='gth-pade',
                max_memory=50000,
                precision=1e-6)

for xc in ('lsda', 'pbe'):
    for images in ([1, 1, 1], [2, 1, 1], [2, 2, 1], [2, 2, 2]):
        cell = pbc.tools.super_cell(cell0, images)
        nao = cell.nao
        log.note('nao = %d', nao)
        dm = np.random.random((nao, nao))
        dm = dm + dm.T

        mf = cell.RKS().set(xc=xc)
        mf.with_df = multigrid.MultiGridFFTDF(cell)

        cpu0 = time.clock(), time.time()
        v = mf.get_veff(cell, dm)
        log.timer('Fock build (xc=%s, nao=%d)' % (xc, nao), *cpu0)
Example #17
0
        dm1 = dm + numpy.eye(nao)
        dm = dm1 + dm1.transpose(0, 2, 1)
        he_nao = cell_he.nao
        dm_he = numpy.random.random(
            (len(kpts), he_nao, he_nao)) + numpy.random.random(
                (len(kpts), he_nao, he_nao)) * 1j
        dm_he = dm_he + dm_he.transpose(0, 2, 1).conj()
        dm_he = dm_he * .2 + numpy.eye(he_nao)

        numpy.random.seed(9)
        dm1 = numpy.random.random(
            dm_he.shape) + numpy.random.random(dm_he.shape) * 1j
        dm1[1] = dm1[0]
        mydf = df.FFTDF(cell_he)
        ni = dft.numint.KNumInt()
        mg_df = multigrid.MultiGridFFTDF(cell_he)

        mf = dft.KRKS(cell_he)
        mf.with_df = mg_df
        mf.kpts = kpts

        numpy.random.seed(9)
        dm1 = numpy.random.random(
            dm_he.shape) + numpy.random.random(dm_he.shape) * 1j
        dm1 = dm1 + dm1.transpose(0, 2, 1)
        mydf = df.FFTDF(cell_he)
        ni = dft.numint.KNumInt()
        mg_df = multigrid.MultiGridFFTDF(cell_he)

        xc = 'lda,'
        ref = dft.numint.nr_uks_fxc(ni,