示例#1
0
 def get_veff(self, mol=None, dm=None, dm_last=0, vhf_last=0, hermi=1):
     '''Unrestricted Hartree-Fock potential matrix of alpha and beta spins,
     for the given density matrix.  See :func:`scf.uhf.get_veff`.
     '''
     if mol is None: mol = self.mol
     if dm is None: dm = self.make_rdm1()
     if isinstance(dm, numpy.ndarray) and dm.ndim == 2:
         dm = numpy.array((dm*.5, dm*.5))
     nset = len(dm) // 2
     if (self._eri is not None or not self.direct_scf or
         mol.incore_anyway or self._is_mem_enough()):
         dm = numpy.array(dm, copy=False)
         dm = numpy.vstack((dm[nset:], dm[:nset]-dm[nset:]))
         vj, vk = self.get_jk(mol, dm, hermi)
         vj = numpy.vstack((vj[:nset]+vj[nset:], vj[:nset]))
         vk = numpy.vstack((vk[:nset]+vk[nset:], vk[:nset]))
         vhf = uhf._makevhf(vj, vk, nset)
     else:
         ddm = numpy.asarray(dm) - numpy.asarray(dm_last)
         ddm = numpy.vstack((ddm[nset:],             # closed shell
                             ddm[:nset]-ddm[nset:])) # open shell
         vj, vk = self.get_jk(mol, ddm, hermi)
         vj = numpy.vstack((vj[:nset]+vj[nset:], vj[:nset]))
         vk = numpy.vstack((vk[:nset]+vk[nset:], vk[:nset]))
         vhf = uhf._makevhf(vj, vk, nset) \
             + numpy.array(vhf_last, copy=False)
     return vhf
示例#2
0
 def get_veff(self, mol=None, dm=None, dm_last=0, vhf_last=0, hermi=1):
     if mol is None: mol = self.mol
     if dm is None: dm = self.make_rdm1()
     if isinstance(dm, numpy.ndarray) and dm.ndim == 2:
         dm = numpy.array((dm * .5, dm * .5))
     nset = len(dm) // 2
     if (self._eri is not None or not self.direct_scf or mol.incore_anyway
             or self._is_mem_enough()):
         dm = numpy.array(dm, copy=False)
         dm = numpy.vstack((dm[nset:], dm[:nset] - dm[nset:]))
         vj, vk = self.get_jk(mol, dm, hermi)
         vj = numpy.vstack((vj[:nset] + vj[nset:], vj[:nset]))
         vk = numpy.vstack((vk[:nset] + vk[nset:], vk[:nset]))
         vhf = uhf._makevhf(vj, vk, nset)
     else:
         ddm = numpy.asarray(dm) - numpy.asarray(dm_last)
         ddm = numpy.vstack((
             ddm[nset:],  # closed shell
             ddm[:nset] - ddm[nset:]))  # open shell
         vj, vk = self.get_jk(mol, ddm, hermi)
         vj = numpy.vstack((vj[:nset] + vj[nset:], vj[:nset]))
         vk = numpy.vstack((vk[:nset] + vk[nset:], vk[:nset]))
         vhf = uhf._makevhf(vj, vk, nset) \
             + numpy.array(vhf_last, copy=False)
     return vhf
示例#3
0
 def get_veff(self, mol=None, dm=None, dm_last=0, vhf_last=0, hermi=1):
     if mol is None: mol = self.mol
     if dm is None: dm = self.make_rdm1()
     if isinstance(dm, numpy.ndarray) and dm.ndim == 2:
         dm = numpy.array((dm * .5, dm * .5))
     if (self._eri is not None or not self.direct_scf or mol.incore_anyway
             or self._is_mem_enough()):
         vj, vk = self.get_jk(mol, dm, hermi)
         vhf = uhf._makevhf(vj, vk)
     else:
         ddm = dm - numpy.asarray(dm_last)
         vj, vk = self.get_jk(mol, ddm, hermi)
         vhf = uhf._makevhf(vj, vk) + numpy.asarray(vhf_last)
     return vhf
示例#4
0
def get_veff(ks, cell=None, dm=None, dm_last=0, vhf_last=0, hermi=1,
             kpts=None, kpts_band=None):
    '''Coulomb + XC functional for UKS.  See pyscf/pbc/dft/uks.py
    :func:`get_veff` fore more details.
    '''
    if cell is None: cell = ks.cell
    if dm is None: dm = ks.make_rdm1()
    if kpts is None: kpts = ks.kpts
    t0 = (time.clock(), time.time())
    if ks.grids.coords is None:
        ks.grids.build(with_non0tab=True)
        small_rho_cutoff = ks.small_rho_cutoff
        t0 = logger.timer(ks, 'setting up grids', *t0)
    else:
        small_rho_cutoff = 0

    if hermi == 2:  # because rho = 0
        n, ks._exc, vx = (0,0), 0, 0
    else:
        n, ks._exc, vx = ks._numint.nr_uks(cell, ks.grids, ks.xc, dm, 0,
                                           kpts, kpts_band)
        logger.debug(ks, 'nelec by numeric integration = %s', n)
        t0 = logger.timer(ks, 'vxc', *t0)

    # ndim = 4 : dm.shape = ([alpha,beta], nkpts, nao, nao)
    ground_state = (dm.ndim == 4 and dm.shape[0] == 2 and kpts_band is None)
    nkpts = len(kpts)

    hyb = ks._numint.hybrid_coeff(ks.xc, spin=cell.spin)
    if abs(hyb) < 1e-10:
        vj = ks.get_j(cell, dm, hermi, kpts, kpts_band)
        vhf = lib.asarray([vj[0]+vj[1]] * 2)
    else:
        vj, vk = ks.get_jk(cell, dm, hermi, kpts, kpts_band)
        vhf=moluhf._makevhf(vj,vk*hyb)

        if ground_state:
            ks._exc -= (np.einsum('Kij,Kji', dm[0], vk[0]) +
                        np.einsum('Kij,Kji', dm[1], vk[1])).real * .5 * hyb * (1./nkpts)

    if ground_state:
        ks._ecoul = np.einsum('Kij,Kji', dm[0]+dm[1], vj[0]+vj[1]).real * .5 * (1./nkpts)

    nelec = cell.nelec
    if (small_rho_cutoff > 1e-20 and ground_state and
        abs(n[0]-nelec[0]) < 0.01*n[0] and abs(n[1]-nelec[1]) < 0.01*n[1]):
        # Filter grids the first time setup grids
        idx = ks._numint.large_rho_indices(cell, dm, ks.grids,
                                           small_rho_cutoff, kpts)
        logger.debug(ks, 'Drop grids %d',
                     ks.grids.weights.size - np.count_nonzero(idx))
        ks.grids.coords  = np.asarray(ks.grids.coords [idx], order='C')
        ks.grids.weights = np.asarray(ks.grids.weights[idx], order='C')
        ks.grids.non0tab = ks.grids.make_mask(cell, ks.grids.coords)
    return vhf + vx
示例#5
0
文件: kuhf.py 项目: armunoz/pyscf
 def get_veff(self,
              cell=None,
              dm_kpts=None,
              dm_last=0,
              vhf_last=0,
              hermi=1,
              kpts=None,
              kpts_band=None):
     vj, vk = self.get_jk(cell, dm_kpts, hermi, kpts, kpts_band)
     vhf = uhf._makevhf(vj, vk)
     return vhf
示例#6
0
文件: rohf.py 项目: berquist/pyscf
 def get_veff(self, mol=None, dm=None, dm_last=0, vhf_last=0, hermi=1):
     if mol is None: mol = self.mol
     if dm is None: dm = self.make_rdm1()
     dm = numpy.asarray(dm)
     nao = dm.shape[-1]
     if dm.ndim == 2:
         dm = numpy.array((dm*.5, dm*.5))
     if (self._eri is not None or not self.direct_scf or
         mol.incore_anyway or self._is_mem_enough()):
         vj, vk = self.get_jk(mol, (dm[1], dm[0]-dm[1]), hermi)
         vj = numpy.asarray((vj[0]+vj[1], vj[0]))
         vk = numpy.asarray((vk[0]+vk[1], vk[0]))
         vhf = uhf._makevhf(vj, vk)
     else:
         ddm = dm - numpy.asarray(dm_last)
         ddm = numpy.asarray((ddm[1],                # closed shell
                              ddm[0]-ddm[1]))        # open shell
         vj, vk = self.get_jk(mol, ddm, hermi)
         vj = numpy.asarray((vj[0]+vj[1], vj[0]))
         vk = numpy.asarray((vk[0]+vk[1], vk[0]))
         vhf = uhf._makevhf(vj, vk) + numpy.asarray(vhf_last)
     return vhf
示例#7
0
文件: rohf.py 项目: armunoz/pyscf
 def get_veff(self, mol=None, dm=None, dm_last=0, vhf_last=0, hermi=1):
     if mol is None: mol = self.mol
     if dm is None: dm = self.make_rdm1()
     dm = numpy.asarray(dm)
     nao = dm.shape[-1]
     if dm.ndim == 2:
         dm = numpy.array((dm*.5, dm*.5))
     if (self._eri is not None or not self.direct_scf or
         mol.incore_anyway or self._is_mem_enough()):
         vj, vk = self.get_jk(mol, (dm[1], dm[0]-dm[1]), hermi)
         vj = numpy.asarray((vj[0]+vj[1], vj[0]))
         vk = numpy.asarray((vk[0]+vk[1], vk[0]))
         vhf = uhf._makevhf(vj, vk)
     else:
         ddm = dm - numpy.asarray(dm_last)
         ddm = numpy.asarray((ddm[1],                # closed shell
                              ddm[0]-ddm[1]))        # open shell
         vj, vk = self.get_jk(mol, ddm, hermi)
         vj = numpy.asarray((vj[0]+vj[1], vj[0]))
         vk = numpy.asarray((vk[0]+vk[1], vk[0]))
         vhf = uhf._makevhf(vj, vk) + numpy.asarray(vhf_last)
     return vhf
示例#8
0
文件: rohf.py 项目: pengdl/pyscf
 def get_veff(self, mol=None, dm=None, dm_last=0, vhf_last=0, hermi=1):
     if mol is None: mol = self.mol
     if dm is None: dm = self.make_rdm1()
     if isinstance(dm, numpy.ndarray) and dm.ndim == 2:
         dm = numpy.array((dm*.5, dm*.5))
     nset = len(dm) // 2
     if (self._eri is not None or not self.direct_scf or
         mol.incore_anyway or self._is_mem_enough()):
         dm = numpy.array(dm, copy=False)
         dm = numpy.vstack((dm[nset:], dm[:nset]-dm[nset:]))
         vj, vk = self.get_jk(mol, dm, hermi)
         vj = numpy.vstack((vj[:nset]+vj[nset:], vj[:nset]))
         vk = numpy.vstack((vk[:nset]+vk[nset:], vk[:nset]))
         vhf = uhf._makevhf(vj, vk, nset)
     else:
         ddm = numpy.asarray(dm) - numpy.asarray(dm_last)
         ddm = numpy.vstack((ddm[nset:],             # closed shell
                             ddm[:nset]-ddm[nset:])) # open shell
         vj, vk = self.get_jk(mol, ddm, hermi)
         vj = numpy.vstack((vj[:nset]+vj[nset:], vj[:nset]))
         vk = numpy.vstack((vk[:nset]+vk[nset:], vk[:nset]))
         vhf = uhf._makevhf(vj, vk, nset) \
             + numpy.array(vhf_last, copy=False)
     return vhf
示例#9
0
文件: uks.py 项目: pulkin/pyscf
def get_veff(ks, mol=None, dm=None, dm_last=0, vhf_last=0, hermi=1):
    '''Coulomb + XC functional for UKS.  See pyscf/dft/rks.py
    :func:`get_veff` fore more details.
    '''
    if mol is None: mol = self.mol
    if dm is None: dm = ks.make_rdm1()
    t0 = (time.clock(), time.time())
    if ks.grids.coords is None:
        ks.grids.build(with_non0tab=True)
        small_rho_cutoff = ks.small_rho_cutoff
        t0 = logger.timer(ks, 'setting up grids', *t0)
    else:
        # Filter grids only for the first time setting up grids
        small_rho_cutoff = 0

    if not isinstance(dm, numpy.ndarray):
        dm = numpy.asarray(dm)
    if dm.ndim == 2:  # RHF DM
        dm = numpy.asarray((dm * .5, dm * .5))

    if hermi == 2:  # because rho = 0
        n, ks._exc, vx = (0, 0), 0, 0
    else:
        n, ks._exc, vx = ks._numint.nr_uks(mol, ks.grids, ks.xc, dm)
        logger.debug(ks, 'nelec by numeric integration = %s', n)
        t0 = logger.timer(ks, 'vxc', *t0)

    ground_state = (dm.ndim == 3 and dm.shape[0] == 2)

    hyb = ks._numint.hybrid_coeff(ks.xc, spin=mol.spin)
    if abs(hyb) < 1e-10:
        if (ks._eri is not None or not ks.direct_scf
                or not hasattr(ks, '_dm_last')
                or not isinstance(vhf_last, numpy.ndarray)):
            vj = ks.get_j(mol, dm, hermi)
        else:
            ddm = dm - numpy.asarray(ks._dm_last)
            vj = ks.get_j(mol, ddm, hermi)
            vj += ks._vj_last
            ks._dm_last = dm
            ks._vj_last = vj
        vhf = vj[0] + vj[1]
        vhf = numpy.asarray((vhf, vhf))
    else:
        if (ks._eri is not None or not ks.direct_scf
                or not hasattr(ks, '_dm_last')
                or not isinstance(vhf_last, numpy.ndarray)):
            vj, vk = ks.get_jk(mol, dm, hermi)
        else:
            ddm = dm - numpy.asarray(ks._dm_last)
            vj, vk = ks.get_jk(mol, ddm, hermi)
            vj += ks._vj_last
            vk += ks._vk_last
            ks._dm_last = dm
            ks._vj_last, ks._vk_last = vj, vk
        vhf = uhf._makevhf(vj, vk * hyb)

        if ground_state:
            ks._exc -= (numpy.einsum('ij,ji', dm[0], vk[0]) +
                        numpy.einsum('ij,ji', dm[1], vk[1])) * .5 * hyb
    if ground_state:
        ks._ecoul = numpy.einsum('ij,ji', dm[0] + dm[1], vj[0] + vj[1]) * .5

    nelec = mol.nelec
    if (small_rho_cutoff > 1e-20 and ground_state
            and abs(n[0] - nelec[0]) < 0.01 * n[0]
            and abs(n[1] - nelec[1]) < 0.01 * n[1]):
        idx = ks._numint.large_rho_indices(mol, dm[0] + dm[1], ks.grids,
                                           small_rho_cutoff)
        logger.debug(ks, 'Drop grids %d',
                     ks.grids.weights.size - numpy.count_nonzero(idx))
        ks.grids.coords = numpy.asarray(ks.grids.coords[idx], order='C')
        ks.grids.weights = numpy.asarray(ks.grids.weights[idx], order='C')
        ks.grids.non0tab = ks.grids.make_mask(mol, ks.grids.coords)
    return vhf + vx
示例#10
0
文件: kuhf.py 项目: berquist/pyscf
 def get_veff(self, cell=None, dm_kpts=None, dm_last=0, vhf_last=0, hermi=1, kpts=None, kpt_band=None):
     vj, vk = self.get_jk(cell, dm_kpts, hermi, kpts, kpt_band)
     vhf = uhf._makevhf(vj, vk)
     return vhf