コード例 #1
0
ファイル: test_numint.py プロジェクト: mattwelborn/pyscf
    def test_eval_ao_kpts(self):
        cell = pbcgto.Cell()
        cell.verbose = 5
        cell.output = '/dev/null'
        cell.a = np.eye(3) * 2.5
        cell.gs = [10] * 3
        cell.atom = [
            ['He', (1., .8, 1.9)],
            ['He', (.1, .2, .3)],
        ]
        cell.basis = 'ccpvdz'
        cell.build(False, False)
        grids = gen_grid.UniformGrids(cell)
        grids.build()

        np.random.seed(1)
        kpts = np.random.random((4, 3))
        ni = numint._KNumInt(kpts)
        ao1 = ni.eval_ao(cell, grids.coords, kpts)
        self.assertAlmostEqual(finger(ao1[0]),
                               (-2.4066959390326477 - 0.98044994099240701j), 8)
        self.assertAlmostEqual(finger(ao1[1]),
                               (-0.30643153325360639 + 0.1571658820483913j), 8)
        self.assertAlmostEqual(finger(ao1[2]),
                               (-1.1937974302337684 - 0.39039259235266233j), 8)
        self.assertAlmostEqual(finger(ao1[3]),
                               (0.17701966968272009 - 0.20232879692603079j), 8)
コード例 #2
0
def get_j_kpts(mf, cell, dm_kpts, kpts, kpts_band=None):
    coords = gen_grid.gen_uniform_grids(cell)
    nkpts = len(kpts)
    ngs = len(coords)
    dm_kpts = np.asarray(dm_kpts)
    nao = dm_kpts.shape[-1]

    ni = numint._KNumInt(kpts)
    aoR_kpts = ni.eval_ao(cell, coords, kpts)
    if kpts_band is not None:
        aoR_kband = numint.eval_ao(cell, coords, kpts_band)

    dms = dm_kpts.reshape(-1, nkpts, nao, nao)
    nset = dms.shape[0]

    vjR = [get_vjR(cell, dms[i], aoR_kpts) for i in range(nset)]
    if kpts_band is not None:
        vj_kpts = [
            cell.vol / ngs * lib.dot(aoR_kband.T.conj() * vjR[i], aoR_kband)
            for i in range(nset)
        ]
        if dm_kpts.ndim == 3:  # One set of dm_kpts for KRHF
            vj_kpts = vj_kpts[0]
        return lib.asarray(vj_kpts)
    else:
        vj_kpts = []
        for i in range(nset):
            vj = [
                cell.vol / ngs * lib.dot(aoR_k.T.conj() * vjR[i], aoR_k)
                for aoR_k in aoR_kpts
            ]
            vj_kpts.append(lib.asarray(vj))
        return lib.asarray(vj_kpts).reshape(dm_kpts.shape)
コード例 #3
0
ファイル: test_fft.py プロジェクト: berquist/pyscf
def get_j_kpts(mf, cell, dm_kpts, kpts, kpt_band=None):
    coords = gen_grid.gen_uniform_grids(cell)
    nkpts = len(kpts)
    ngs = len(coords)
    dm_kpts = np.asarray(dm_kpts)
    nao = dm_kpts.shape[-1]

    ni = numint._KNumInt(kpts)
    aoR_kpts = ni.eval_ao(cell, coords, kpts)
    if kpt_band is not None:
        aoR_kband = numint.eval_ao(cell, coords, kpt_band)

    dms = dm_kpts.reshape(-1,nkpts,nao,nao)
    nset = dms.shape[0]

    vjR = [get_vjR(cell, dms[i], aoR_kpts) for i in range(nset)]
    if kpt_band is not None:
        vj_kpts = [cell.vol/ngs * lib.dot(aoR_kband.T.conj()*vjR[i], aoR_kband)
                   for i in range(nset)]
        if dm_kpts.ndim == 3:  # One set of dm_kpts for KRHF
            vj_kpts = vj_kpts[0]
        return lib.asarray(vj_kpts)
    else:
        vj_kpts = []
        for i in range(nset):
            vj = [cell.vol/ngs * lib.dot(aoR_k.T.conj()*vjR[i], aoR_k)
                  for aoR_k in aoR_kpts]
            vj_kpts.append(lib.asarray(vj))
        return lib.asarray(vj_kpts).reshape(dm_kpts.shape)
コード例 #4
0
ファイル: test_fft.py プロジェクト: berquist/pyscf
def get_jk_kpts(mf, cell, dm_kpts, kpts, kpt_band=None):
    coords = gen_grid.gen_uniform_grids(cell)
    nkpts = len(kpts)
    ngs = len(coords)
    dm_kpts = np.asarray(dm_kpts)
    nao = dm_kpts.shape[-1]

    dms = dm_kpts.reshape(-1,nkpts,nao,nao)
    nset = dms.shape[0]

    ni = numint._KNumInt(kpts)
    aoR_kpts = ni.eval_ao(cell, coords, kpts)
    if kpt_band is not None:
        aoR_kband = numint.eval_ao(cell, coords, kpt_band)

# J
    vjR = [get_vjR_kpts(cell, dms[i], aoR_kpts) for i in range(nset)]
    if kpt_band is not None:
        vj_kpts = [cell.vol/ngs * lib.dot(aoR_kband.T.conj()*vjR[i], aoR_kband)
                   for i in range(nset)]
    else:
        vj_kpts = []
        for i in range(nset):
            vj = [cell.vol/ngs * lib.dot(aoR_k.T.conj()*vjR[i], aoR_k)
                  for aoR_k in aoR_kpts]
            vj_kpts.append(lib.asarray(vj))
    vj_kpts = lib.asarray(vj_kpts)
    vjR = None

# K
    weight = 1./nkpts * (cell.vol/ngs)
    vk_kpts = np.zeros_like(vj_kpts)
    if kpt_band is not None:
        for k2, kpt2 in enumerate(kpts):
            aoR_dms = [lib.dot(aoR_kpts[k2], dms[i,k2]) for i in range(nset)]
            vkR_k1k2 = get_vkR(mf, cell, aoR_kband, aoR_kpts[k2],
                               kpt_band, kpt2)
            #:vk_kpts = 1./nkpts * (cell.vol/ngs) * np.einsum('rs,Rp,Rqs,Rr->pq',
            #:            dm_kpts[k2], aoR_kband.conj(),
            #:            vkR_k1k2, aoR_kpts[k2])
            for i in range(nset):
                tmp_Rq = np.einsum('Rqs,Rs->Rq', vkR_k1k2, aoR_dms[i])
                vk_kpts[i] += weight * lib.dot(aoR_kband.T.conj(), tmp_Rq)
            vkR_k1k2 = None
        if dm_kpts.ndim == 3:
            vj_kpts = vj_kpts[0]
            vk_kpts = vk_kpts[0]
        return lib.asarray(vj_kpts), lib.asarray(vk_kpts)
    else:
        for k2, kpt2 in enumerate(kpts):
            aoR_dms = [lib.dot(aoR_kpts[k2], dms[i,k2]) for i in range(nset)]
            for k1, kpt1 in enumerate(kpts):
                vkR_k1k2 = get_vkR(mf, cell, aoR_kpts[k1], aoR_kpts[k2],
                                   kpt1, kpt2)
                for i in range(nset):
                    tmp_Rq = np.einsum('Rqs,Rs->Rq', vkR_k1k2, aoR_dms[i])
                    vk_kpts[i,k1] += weight * lib.dot(aoR_kpts[k1].T.conj(), tmp_Rq)
            vkR_k1k2 = None
        return vj_kpts.reshape(dm_kpts.shape), vk_kpts.reshape(dm_kpts.shape)
コード例 #5
0
 def __init__(self, cell, kpts=np.zeros((1, 3))):
     kuhf.KUHF.__init__(self, cell, kpts)
     self.xc = 'LDA,VWN'
     self.grids = gen_grid.UniformGrids(cell)
     self.small_rho_cutoff = 1e-7  # Use rho to filter grids
     ##################################################
     # don't modify the following attributes, they are not input options
     # Note Do not refer to .with_df._numint because gs/coords may be different
     self._numint = numint._KNumInt(kpts)
     self._keys = self._keys.union(['xc', 'grids', 'small_rho_cutoff'])
コード例 #6
0
ファイル: kuks.py プロジェクト: berquist/pyscf
    def __init__(self, cell, kpts):
        kuhf.KUHF.__init__(self, cell, kpts)
        self.xc = 'LDA,VWN'
        self.grids = gen_grid.UniformGrids(cell)
        self.small_rho_cutoff = 1e-7  # Use rho to filter grids
##################################################
# don't modify the following attributes, they are not input options
        self._ecoul = 0
        self._exc = 0
        # Note Do not refer to .with_df._numint because gs/coords may be different
        self._numint = numint._KNumInt(kpts)
        self._keys = self._keys.union(['xc', 'grids', 'small_rho_cutoff'])
コード例 #7
0
ファイル: fft.py プロジェクト: sunchong137/pyscf_2017
    def __init__(self, cell, kpts=numpy.zeros((1, 3))):
        self.cell = cell
        self.stdout = cell.stdout
        self.verbose = cell.verbose
        self.max_memory = cell.max_memory

        self.kpts = kpts
        self.gs = cell.gs

        # Not input options
        self.exxdiv = None  # to mimic KRHF/KUHF object in function get_coulG
        self._numint = numint._KNumInt()
        self._keys = set(self.__dict__.keys())
コード例 #8
0
ファイル: fft.py プロジェクト: berquist/pyscf
    def __init__(self, cell, kpts=numpy.zeros((1,3))):
        self.cell = cell
        self.stdout = cell.stdout
        self.verbose = cell.verbose
        self.max_memory = cell.max_memory

        self.kpts = kpts
        self.gs = cell.gs

# Not input options
        self.exxdiv = None  # to mimic KRHF/KUHF object in function get_coulG
        self._numint = numint._KNumInt()
        self._keys = set(self.__dict__.keys())
コード例 #9
0
    def __init__(self, cell, kpts=numpy.zeros((1, 3))):
        from pyscf.pbc.dft import numint
        self.cell = cell
        self.stdout = cell.stdout
        self.verbose = cell.verbose
        self.max_memory = cell.max_memory

        self.kpts = kpts
        self.gs = cell.gs

        self.blockdim = 240  # to mimic molecular DF object
        self.non0tab = None

        # Not input options
        self.exxdiv = None  # to mimic KRHF/KUHF object in function get_coulG
        self._numint = numint._KNumInt()
        self._keys = set(self.__dict__.keys())
コード例 #10
0
ファイル: test_numint.py プロジェクト: mattwelborn/pyscf
    def test_nr_rks(self):
        cell = pbcgto.Cell()
        cell.verbose = 5
        cell.output = '/dev/null'
        cell.a = np.eye(3) * 2.5
        cell.gs = [10] * 3
        cell.atom = [
            ['He', (1., .8, 1.9)],
            ['He', (.1, .2, .3)],
        ]
        cell.basis = 'ccpvdz'
        cell.build(False, False)
        grids = gen_grid.UniformGrids(cell)
        grids.build()
        nao = cell.nao_nr()

        np.random.seed(1)
        kpts = np.random.random((2, 3))
        dms = np.random.random((2, nao, nao))
        dms = (dms + dms.transpose(0, 2, 1)) * .5
        ni = numint._NumInt()
        ne, exc, vmat = ni.nr_rks(cell, grids, 'blyp', dms[0], 0, kpts[0])
        self.assertAlmostEqual(ne, 5.0499199224525153, 8)
        self.assertAlmostEqual(exc, -3.8870579114663886, 8)
        self.assertAlmostEqual(finger(vmat),
                               0.42538491159934377 + 0.14139753327162483j, 8)

        ni = numint._KNumInt()
        ne, exc, vmat = ni.nr_rks(cell, grids, 'blyp', dms, 0, kpts)
        self.assertAlmostEqual(ne, 6.0923292346269742, 8)
        self.assertAlmostEqual(exc, -3.9899423803106466, 8)
        self.assertAlmostEqual(finger(vmat[0]),
                               -2348.9577179701278 - 60.733087913116719j, 7)
        self.assertAlmostEqual(finger(vmat[1]),
                               -2353.0350086740673 - 117.74811536967495j, 7)

        ne, exc, vmat = ni.nr_rks(cell, grids, 'blyp', [dms, dms], 0, kpts)
        self.assertAlmostEqual(ne[1], 6.0923292346269742, 8)
        self.assertAlmostEqual(exc[1], -3.9899423803106466, 8)
        self.assertAlmostEqual(finger(vmat[1][0]),
                               -2348.9577179701278 - 60.733087913116719j, 7)
        self.assertAlmostEqual(finger(vmat[1][1]),
                               -2353.0350086740673 - 117.74811536967495j, 7)
コード例 #11
0
ファイル: test_numint.py プロジェクト: berquist/pyscf
    def test_eval_ao_kpts(self):
        cell = pbcgto.Cell()
        cell.verbose = 5
        cell.output = '/dev/null'
        cell.h = np.eye(3) * 2.5
        cell.gs = [10]*3
        cell.atom = [['He', (1., .8, 1.9)],
                     ['He', (.1, .2,  .3)],]
        cell.basis = 'ccpvdz'
        cell.build(False, False)
        grids = gen_grid.UniformGrids(cell)
        grids.build()

        np.random.seed(1)
        kpts = np.random.random((4,3))
        ni = numint._KNumInt(kpts)
        ao1 = ni.eval_ao(cell, grids.coords, kpts)
        self.assertAlmostEqual(finger(ao1[0]), (-2.4066959390326477-0.98044994099240701j), 8)
        self.assertAlmostEqual(finger(ao1[1]), (-0.30643153325360639+0.1571658820483913j), 8)
        self.assertAlmostEqual(finger(ao1[2]), (-1.1937974302337684-0.39039259235266233j), 8)
        self.assertAlmostEqual(finger(ao1[3]), (0.17701966968272009-0.20232879692603079j), 8)
コード例 #12
0
ファイル: test_numint.py プロジェクト: berquist/pyscf
    def test_nr_rks(self):
        cell = pbcgto.Cell()
        cell.verbose = 5
        cell.output = '/dev/null'
        cell.h = np.eye(3) * 2.5
        cell.gs = [10]*3
        cell.atom = [['He', (1., .8, 1.9)],
                     ['He', (.1, .2,  .3)],]
        cell.basis = 'ccpvdz'
        cell.build(False, False)
        grids = gen_grid.UniformGrids(cell)
        grids.build()
        nao = cell.nao_nr()

        np.random.seed(1)
        kpts = np.random.random((2,3))
        dms = np.random.random((2,nao,nao))
        dms = (dms + dms.transpose(0,2,1)) * .5
        ni = numint._NumInt()
        ne, exc, vmat = ni.nr_rks(cell, grids, 'blyp', dms[0], 0, kpts[0])
        self.assertAlmostEqual(ne, 5.0499199224525153, 8)
        self.assertAlmostEqual(exc, -3.8870579114663886, 8)
        self.assertAlmostEqual(finger(vmat), 0.42538491159934377+0.14139753327162483j, 8)

        ni = numint._KNumInt()
        ne, exc, vmat = ni.nr_rks(cell, grids, 'blyp', dms, 0, kpts)
        self.assertAlmostEqual(ne, 6.0923292346269742, 8)
        self.assertAlmostEqual(exc, -3.9899423803106466, 8)
        self.assertAlmostEqual(finger(vmat[0]), -2348.9577179701278-60.733087913116719j, 8)
        self.assertAlmostEqual(finger(vmat[1]), -2353.0350086740673-117.74811536967495j, 8)

        ne, exc, vmat = ni.nr_rks(cell, grids, 'blyp', [dms,dms], 0, kpts)
        self.assertAlmostEqual(ne[1], 6.0923292346269742, 8)
        self.assertAlmostEqual(exc[1], -3.9899423803106466, 8)
        self.assertAlmostEqual(finger(vmat[1][0]), -2348.9577179701278-60.733087913116719j, 8)
        self.assertAlmostEqual(finger(vmat[1][1]), -2353.0350086740673-117.74811536967495j, 8)
コード例 #13
0
def get_jk_kpts(mf, cell, dm_kpts, kpts, kpts_band=None):
    coords = gen_grid.gen_uniform_grids(cell)
    nkpts = len(kpts)
    ngs = len(coords)
    dm_kpts = np.asarray(dm_kpts)
    nao = dm_kpts.shape[-1]

    dms = dm_kpts.reshape(-1, nkpts, nao, nao)
    nset = dms.shape[0]

    ni = numint._KNumInt(kpts)
    aoR_kpts = ni.eval_ao(cell, coords, kpts)
    if kpts_band is not None:
        aoR_kband = numint.eval_ao(cell, coords, kpts_band)


# J
    vjR = [get_vjR_kpts(cell, dms[i], aoR_kpts) for i in range(nset)]
    if kpts_band is not None:
        vj_kpts = [
            cell.vol / ngs * lib.dot(aoR_kband.T.conj() * vjR[i], aoR_kband)
            for i in range(nset)
        ]
    else:
        vj_kpts = []
        for i in range(nset):
            vj = [
                cell.vol / ngs * lib.dot(aoR_k.T.conj() * vjR[i], aoR_k)
                for aoR_k in aoR_kpts
            ]
            vj_kpts.append(lib.asarray(vj))
    vj_kpts = lib.asarray(vj_kpts)
    vjR = None

    # K
    weight = 1. / nkpts * (cell.vol / ngs)
    vk_kpts = np.zeros_like(vj_kpts)
    if kpts_band is not None:
        for k2, kpt2 in enumerate(kpts):
            aoR_dms = [lib.dot(aoR_kpts[k2], dms[i, k2]) for i in range(nset)]
            vkR_k1k2 = get_vkR(mf, cell, aoR_kband, aoR_kpts[k2], kpts_band,
                               kpt2)
            #:vk_kpts = 1./nkpts * (cell.vol/ngs) * np.einsum('rs,Rp,Rqs,Rr->pq',
            #:            dm_kpts[k2], aoR_kband.conj(),
            #:            vkR_k1k2, aoR_kpts[k2])
            for i in range(nset):
                tmp_Rq = np.einsum('Rqs,Rs->Rq', vkR_k1k2, aoR_dms[i])
                vk_kpts[i] += weight * lib.dot(aoR_kband.T.conj(), tmp_Rq)
            vkR_k1k2 = None
        if dm_kpts.ndim == 3:
            vj_kpts = vj_kpts[0]
            vk_kpts = vk_kpts[0]
        return lib.asarray(vj_kpts), lib.asarray(vk_kpts)
    else:
        for k2, kpt2 in enumerate(kpts):
            aoR_dms = [lib.dot(aoR_kpts[k2], dms[i, k2]) for i in range(nset)]
            for k1, kpt1 in enumerate(kpts):
                vkR_k1k2 = get_vkR(mf, cell, aoR_kpts[k1], aoR_kpts[k2], kpt1,
                                   kpt2)
                for i in range(nset):
                    tmp_Rq = np.einsum('Rqs,Rs->Rq', vkR_k1k2, aoR_dms[i])
                    vk_kpts[i, k1] += weight * lib.dot(aoR_kpts[k1].T.conj(),
                                                       tmp_Rq)
            vkR_k1k2 = None
        return vj_kpts.reshape(dm_kpts.shape), vk_kpts.reshape(dm_kpts.shape)