Example #1
0
 def test_direct_bindm1(self):
     numpy.random.seed(1)
     nao = mol.nao_nr(cart=True)
     dm = numpy.random.random((nao,nao))
     vhfopt = _vhf.VHFOpt(mol, 'int2e_cart', 'CVHFnrs8_prescreen',
                          'CVHFsetnr_direct_scf',
                          'CVHFsetnr_direct_scf_dm')
     vj0, vk0 = _vhf.direct(dm, mol._atm, mol._bas, mol._env,
                            vhfopt=vhfopt, hermi=0, cart=True)
     vj = _vhf.direct_bindm('int2e_cart', 's1', 'kl->s1ij', dm, 1,
                            mol._atm, mol._bas, mol._env, vhfopt)
     self.assertTrue(numpy.allclose(vj0,vj))
Example #2
0
    def get_jk(self,
               dm,
               hermi=1,
               vhfopt=None,
               with_j=True,
               with_k=True,
               direct_scf_tol=getattr(__config__, 'scf_hf_SCF_direct_scf_tol',
                                      1e-13),
               omega=None):
        if omega is not None:
            # A temporary treatment for RSH integrals
            key = '%.6f' % omega
            if key in self._rsh_df:
                rsh_df = self._rsh_df[key]
            else:
                rsh_df = copy.copy(self)
                rsh_df._rsh_df = None  # to avoid circular reference
                # Not all attributes need to be reset. Resetting _vjopt
                # because it is used by get_j method of regular DF object.
                rsh_df._vjopt = None
                self._rsh_df[key] = rsh_df
                logger.info(self, 'Create RSH-SGX object %s for omega=%s',
                            rsh_df, omega)

            with rsh_df.mol.with_range_coulomb(omega):
                return rsh_df.get_jk(dm, hermi, with_j, with_k, direct_scf_tol)

        if with_j and self.dfj:
            vj = df_jk.get_j(self, dm, hermi, direct_scf_tol)
            if with_k:
                vk = sgx_jk.get_jk(self, dm, hermi, False, with_k,
                                   direct_scf_tol)[1]
            else:
                vk = None
        elif with_j and self.direct_j:
            vj, _ = _vhf.direct(dm, self.mol._atm, self.mol._bas,
                                self.mol._env, vhfopt, hermi, self.mol.cart,
                                True, False)
            if with_k:
                vk = sgx_jk.get_jk(self, dm, hermi, False, with_k,
                                   direct_scf_tol)[1]
            else:
                vk = None
        else:
            vj, vk = sgx_jk.get_jk(self, dm, hermi, with_j, with_k,
                                   direct_scf_tol)
        return vj, vk
Example #3
0
File: hf.py Project: pulkin/pyscf
def get_jk(mol, dm, hermi=1, vhfopt=None):
    '''Compute J, K matrices for the given density matrix

    Args:
        mol : an instance of :class:`Mole`

        dm : ndarray or list of ndarrays
            A density matrix or a list of density matrices

    Kwargs:
        hermi : int
            Whether J, K matrix is hermitian

            | 0 : no hermitian or symmetric
            | 1 : hermitian
            | 2 : anti-hermitian

        vhfopt :
            A class which holds precomputed quantities to optimize the
            computation of J, K matrices

    Returns:
        Depending on the given dm, the function returns one J and one K matrix,
        or a list of J matrices and a list of K matrices, corresponding to the
        input density matrices.

    Examples:

    >>> from pyscf import gto, scf
    >>> from pyscf.scf import _vhf
    >>> mol = gto.M(atom='H 0 0 0; H 0 0 1.1')
    >>> dms = numpy.random.random((3,mol.nao_nr(),mol.nao_nr()))
    >>> j, k = scf.hf.get_jk(mol, dms, hermi=0)
    >>> print(j.shape)
    (3, 2, 2)
    '''
    dm = numpy.asarray(dm, order='C')
    nao = dm.shape[-1]
    vj, vk = _vhf.direct(dm.reshape(-1, nao, nao),
                         mol._atm,
                         mol._bas,
                         mol._env,
                         vhfopt=vhfopt,
                         hermi=hermi,
                         cart=mol.cart)
    return vj.reshape(dm.shape), vk.reshape(dm.shape)
Example #4
0
File: hf.py Project: berquist/pyscf
def get_jk(mol, dm, hermi=1, vhfopt=None):
    '''Compute J, K matrices for the given density matrix

    Args:
        mol : an instance of :class:`Mole`

        dm : ndarray or list of ndarrays
            A density matrix or a list of density matrices

    Kwargs:
        hermi : int
            Whether J, K matrix is hermitian

            | 0 : no hermitian or symmetric
            | 1 : hermitian
            | 2 : anti-hermitian

        vhfopt :
            A class which holds precomputed quantities to optimize the
            computation of J, K matrices

    Returns:
        Depending on the given dm, the function returns one J and one K matrix,
        or a list of J matrices and a list of K matrices, corresponding to the
        input density matrices.

    Examples:

    >>> from pyscf import gto, scf
    >>> from pyscf.scf import _vhf
    >>> mol = gto.M(atom='H 0 0 0; H 0 0 1.1')
    >>> dms = numpy.random.random((3,mol.nao_nr(),mol.nao_nr()))
    >>> j, k = scf.hf.get_jk(mol, dms, hermi=0)
    >>> print(j.shape)
    (3, 2, 2)
    '''
    dm = numpy.asarray(dm, order='C')
    nao = dm.shape[-1]
    vj, vk = _vhf.direct(dm.reshape(-1,nao,nao), mol._atm, mol._bas, mol._env,
                         vhfopt=vhfopt, hermi=hermi)
    return vj.reshape(dm.shape), vk.reshape(dm.shape)