Example #1
0
 def test_df_band(self):
     mf = scf.RHF(cell)
     mf.with_df = df.DF(cell)
     mf.with_df.kpts_band = kband[0]
     mf.kernel()
     self.assertAlmostEqual(finger(mf.get_bands(kband[0])[0]),
                            -0.093621142380270361, 9)
Example #2
0
 def test_df_band(self):
     mf = scf.RHF(cell)
     mf.with_df = df.DF(cell).set(auxbasis='weigend')
     mf.with_df.kpts_band = kband[0]
     mf.kernel()
     self.assertAlmostEqual(finger(mf.get_bands(kband[0])[0]),
                            1.9905548831851645, 8)
Example #3
0
 def test_df_band(self):
     mf = scf.RHF(cell)
     mf.with_df = df.DF(cell).set(auxbasis='weigend')
     mf.with_df.exp_to_discard = mf.with_df.eta
     mf.with_df.kpts_band = kband[0]
     mf.kernel()
     self.assertAlmostEqual(finger(mf.get_bands(kband[0])[0]), 1.992205011752425, 7)
Example #4
0
def get_nuc(cell, kpt=np.zeros(3)):
    '''Get the bare periodic nuc-el AO matrix, with G=0 removed.

    See Martin (12.16)-(12.21).
    '''
    from pyscf.pbc import df
    return df.DF(cell).get_nuc(kpt)
Example #5
0
def get_jk(mf, cell, dm, hermi=1, vhfopt=None, kpt=np.zeros(3), kpt_band=None):
    '''Get the Coulomb (J) and exchange (K) AO matrices for the given density matrix.

    Args:
        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
        kpt : (3,) ndarray
            The "inner" dummy k-point at which the DM was evaluated (or
            sampled).
        kpt_band : (3,) ndarray
            The "outer" primary k-point at which J and K are evaluated.

    Returns:
        The function returns one J and one K matrix, corresponding to the input
        density matrix (both order and shape).
    '''
    from pyscf.pbc import df
    return df.DF(cell).get_jk(dm,
                              hermi,
                              kpt,
                              kpt_band,
                              with_j=False,
                              exxdiv=mf.exxdiv)[1]
Example #6
0
 def test_df_bands(self):
     mf = scf.KRHF(cell)
     mf.with_df = df.DF(cell)
     mf.with_df.kpts_band = kband
     mf.kpts = cell.make_kpts([2]*3)
     mf.kernel()
     self.assertAlmostEqual(finger(mf.get_bands(kband[0])[0]), -0.32200476157045782, 9)
     self.assertAlmostEqual(finger(mf.get_bands(kband)[0]), -0.64216552168395347, 9)
Example #7
0
 def test_df_bands(self):
     mf = scf.KRHF(cell)
     mf.with_df = df.DF(cell).set(auxbasis='weigend')
     mf.with_df.kpts_band = kband
     mf.with_df.exp_to_discard = mf.with_df.eta
     mf.kpts = cell.make_kpts([2,1,1])
     mf.kernel()
     self.assertAlmostEqual(finger(mf.get_bands(kband[0])[0]), 1.9648945030342437, 8)
     self.assertAlmostEqual(finger(mf.get_bands(kband)[0]), 1.0455025876245683, 7)
Example #8
0
 def test_df_bands(self):
     mf = scf.KRHF(cell)
     mf.with_df = df.DF(cell).set(auxbasis='weigend')
     mf.with_df.kpts_band = kband
     mf.kpts = cell.make_kpts([2, 1, 1])
     mf.kernel()
     self.assertAlmostEqual(finger(mf.get_bands(kband[0])[0]),
                            1.9630519740658308, 8)
     self.assertAlmostEqual(finger(mf.get_bands(kband)[0]),
                            1.04461751922109, 8)
Example #9
0
    def __init__(self, cell, kpt=np.zeros(3), exxdiv='ewald'):
        from pyscf.pbc import df
        self.cell = cell
        pyscf.scf.uhf.UHF.__init__(self, cell)

        self.with_df = df.DF(cell)
        self.exxdiv = exxdiv
        self.kpt = kpt
        self.direct_scf = False

        self._keys = self._keys.union(['cell', 'exxdiv', 'with_df'])
Example #10
0
def get_ao_pairs_G(cell, kpts=None):
    '''Calculate forward (G|ij) and "inverse" (ij|G) FFT of all AO pairs.

    Args:
        cell : instance of :class:`Cell`

    Returns:
        ao_pairs_G, ao_pairs_invG : (ngs, nao*(nao+1)/2) ndarray
            The FFTs of the real-space AO pairs.

    '''
    return df.DF(cell).get_ao_pairs(kpts)
Example #11
0
    def __init__(self, cell, kpt=np.zeros(3), exxdiv='ewald'):
        from pyscf.pbc import df
        if not cell._built:
            sys.stderr.write('Warning: cell.build() is not called in input\n')
            cell.build()
        self.cell = cell
        pyscf.scf.hf.RHF.__init__(self, cell)

        self.with_df = df.DF(cell)
        self.exxdiv = exxdiv
        self.kpt = kpt
        self.direct_scf = False

        self._keys = self._keys.union(['cell', 'exxdiv', 'with_df'])
Example #12
0
def get_mo_pairs_G(cell, mo_coeffs, kpts=None):
    '''Calculate forward (G|ij) FFT of all MO pairs.

    TODO: - Implement simplifications for real orbitals.

    Args:
        mo_coeff: length-2 list of (nao,nmo) ndarrays
            The two sets of MO coefficients to use in calculating the
            product |ij).

    Returns:
        mo_pairs_G : (ngs, nmoi*nmoj) ndarray
            The FFT of the real-space MO pairs.
    '''
    return df.DF(cell).get_mo_pairs(mo_coeffs, kpts)
Example #13
0
def get_j(mf, cell, dm_kpts, kpts, kpt_band=None):
    '''Get the Coulomb (J) AO matrix at sampled k-points.

    Args:
        dm_kpts : (nkpts, nao, nao) ndarray or a list of (nkpts,nao,nao) ndarray
            Density matrix at each k-point.  If a list of k-point DMs, eg,
            UHF alpha and beta DM, the alpha and beta DMs are contracted
            separately.
        kpts : (nkpts, 3) ndarray

    Kwargs:
        kpt_band : (3,) ndarray
            An arbitrary "band" k-point at which to evalute the matrix.

    Returns:
        vj : (nkpts, nao, nao) ndarray
        or list of vj if the input dm_kpts is a list of DMs
    '''
    from pyscf.pbc import df
    return df.DF(cell).get_jk(dm_kpts, kpts, kpt_band, with_k=False)[0]
Example #14
0
def get_jk(mf, cell, dm_kpts, kpts, kpt_band=None):
    '''Get the Coulomb (J) and exchange (K) AO matrices at sampled k-points.

    Args:
        dm_kpts : (nkpts, nao, nao) ndarray
            Density matrix at each k-point
        kpts : (nkpts, 3) ndarray

    Kwargs:
        kpt_band : (3,) ndarray
            An arbitrary "band" k-point at which to evalute the matrix.

    Returns:
        vj : (nkpts, nao, nao) ndarray
        vk : (nkpts, nao, nao) ndarray
        or list of vj and vk if the input dm_kpts is a list of DMs
    '''
    from pyscf.pbc import df
    return df.DF(cell).get_jk(dm_kpts,
                              kpts,
                              kpt_band,
                              with_j=False,
                              exxdiv=mf.exxdiv)[0]
Example #15
0
def get_mo_pairs_invG(cell, mo_coeffs, kpts=None):
    '''Calculate "inverse" (ij|G) FFT of all MO pairs.

    TODO: - Implement simplifications for real orbitals.

    Args:
        mo_coeff: length-2 list of (nao,nmo) ndarrays
            The two sets of MO coefficients to use in calculating the
            product |ij).

    Returns:
        mo_pairs_invG : (ngs, nmoi*nmoj) ndarray
            The inverse FFTs of the real-space MO pairs.
    '''
    if kpts is None: kpts = numpy.zeros((2, 3))
    mo_pairs_G = df.DF(cell).get_mo_pairs((mo_coeffs[1], mo_coeffs[0]),
                                          (kpts[1], kpts[0]))
    nmo0 = mo_coeffs[0].shape[1]
    nmo1 = mo_coeffs[1].shape[1]
    mo_pairs_invG = mo_pairs_G.T.reshape(nmo1, nmo0, -1).transpose(1, 0,
                                                                   2).conj()
    mo_pairs_invG = mo_pairs_invG.reshape(nmo0 * nmo1, -1).T
    return mo_pairs_invG
Example #16
0
    #verbose = 4,
)

Jtime=time.time()
nk = [1,1,2]  # 4 k-poins for each axis, 4^3=64 kpts in total
kpts = cell.make_kpts(nk)
kmf = scf.KRHF(cell, kpts)
kmf.with_df.occ = True
kmf.verbose = 4
#kmf.max_cycle = 0
kmf.kernel()
print "Took this long for total: ", time.time()-Jtime

exit()

kmf.with_df = df.DF(cell, kpts)
print(kmf.scf())


mf = scf.RHF(cell)
ehf = mf.kernel()
print("HF energy (per unit cell) = %.17g" % ehf)


kmf = dft.KRKS(cell, kpts)
# Turn to the atomic grids if you like
kmf.grids = dft.gen_grid.BeckeGrids(cell)
kmf.xc = 'm06,m06'
kmf.kernel()

Example #17
0
def get_ao_eri(cell, kpts=None):
    '''Convenience function to return AO 2-el integrals.'''
    if kpts is not None:
        assert len(kpts) == 4
    return df.DF(cell).get_eri(kpts)
Example #18
0
    verbose=4,
)

#
# 1-electron (periodic) integrals can be obtained with pbc_intor function.
# Note .intor function computes integrals without PBC
#
overlap = cell.pbc_intor('cint1e_ovlp_sph')
kinetic = cell.pbc_intor('cint1e_kin_sph')

#
# In PBC, 2e integrals are all computed with 3-ceter integrals, ie from
# density fitting module.  Without kpts argument, the DF gives gamma point AO
# 2e-integrals.  Permutation symmetry is not considered
#
mydf = df.DF(cell)
mydf.gs = [7] * 3
eri = mydf.get_eri()
print('ERI shape (%d,%d)' % eri.shape)

kpts = numpy.array((
    (-.5, .5, .5),
    (.5, -.5, .5),
    (.5, .5, -.5),
    (.5, .5, .5),
))
#
# Note certain translational symmetry is required:
#       kj-ki+kl-kk = 2n\pi
#
ki, kj, kk = kpts[:3]
Example #19
0
e = []
cell = pbcgto.Cell()
cell.build(unit = 'B',
           a = numpy.eye(3),
           gs = [10]*3,
           atom = '''H 0 0 0; H 0 0 1.8''',
           dimension = 0,
           verbose = 0,
           basis = 'sto3g')
mf = pbchf.RHF(cell)
mf.with_df = pdf.AFTDF(cell)
e.append(mf.kernel())

mf = pbchf.RHF(cell)
mf.with_df = pdf.DF(cell)
mf.with_df.auxbasis = 'weigend'
# The above two lines of initialization can be replaced by density_fit method
# mf = pbchf.RHF(cell).density_fit(auxbasis='weigend')
e.append(mf.kernel())

mf = pbchf.RHF(cell)
mf.with_df = pdf.MDF(cell)
mf.with_df.auxbasis = 'weigend'
# The above two lines of initialization can be replaced by density_fit method
# mf = pbchf.RHF(cell).mix_density_fit(auxbasis='weigend')
e.append(mf.kernel())

mol = cell.to_mol()
mf = scf.RHF(mol)
e.append(mf.kernel())
Example #20
0
mydf = df.MDF(cell)
eri_3d = numpy.vstack([Lpq.copy() for Lpq in mydf.loop()])
# Test 2-e integrals
eri = numpy.dot(eri_3d.T, eri_3d)
print(abs(eri - mydf.get_eri(compact=True)).max())

#
# Using .sr_loop method to access the 3-index tensor of gaussian density
# fitting (GDF) for arbitrary k-points
# The same can be achieved by using range-separated density fitting (RSDF).
# To do so, simply change 'df.DF' to be 'df.RSDF' below.
# see '35-range_separated_density_fit.py' for more details of RSDF.
#
nao = cell.nao_nr()
mydf = df.DF(cell, kpts=kpts)
eri_3d_kpts = []
for i, kpti in enumerate(kpts):
    eri_3d_kpts.append([])
    for j, kptj in enumerate(kpts):
        eri_3d = []
        for LpqR, LpqI, sign in mydf.sr_loop([kpti, kptj], compact=False):
            eri_3d.append(LpqR + LpqI * 1j)
        eri_3d = numpy.vstack(eri_3d).reshape(-1, nao, nao)
        eri_3d_kpts[i].append(eri_3d)
# Test 2-e integrals
# Note, Coulomb integrals are positive definition in this example. The code
# below does not work for 2D pbc system.
eri = numpy.einsum('Lpq,Lrs->pqrs', eri_3d_kpts[0][3], eri_3d_kpts[3][0])
print(
    abs(eri -
Example #21
0
    L = 5.
    n = 5
    cell = pgto.Cell()
    cell.h = numpy.diag([L, L, L])
    cell.gs = numpy.array([n, n, n])

    cell.atom = '''He    3.    2.       3.
                   He    1.    1.       1.'''
    #cell.basis = {'He': [[0, (1.0, 1.0)]]}
    #cell.basis = '631g'
    #cell.basis = {'He': [[0, (2.4, 1)], [1, (1.1, 1)]]}
    cell.basis = 'ccpvdz'
    cell.verbose = 0
    cell.build(0, 0)

    nao = cell.nao_nr()
    numpy.random.seed(1)
    kpts = numpy.random.random((4, 3))
    kpts[3] = -numpy.einsum('ij->j', kpts[:3])
    with_df = df.DF(cell)
    with_df.kpts = kpts
    mo = (numpy.random.random((nao, nao)) + numpy.random.random(
        (nao, nao)) * 1j)
    eri = with_df.get_eri(kpts).reshape((nao, ) * 4)
    eri0 = numpy.einsum('pjkl,pi->ijkl', eri, mo.conj())
    eri0 = numpy.einsum('ipkl,pj->ijkl', eri0, mo)
    eri0 = numpy.einsum('ijpl,pk->ijkl', eri0, mo.conj())
    eri0 = numpy.einsum('ijkp,pl->ijkl', eri0, mo).reshape(nao**2, -1)
    eri1 = with_df.ao2mo(mo, kpts)
    print abs(eri1 - eri0).sum()
Example #22
0
def general(cell, mo_coeffs, kpts=None, compact=False):
    '''pyscf-style wrapper to get MO 2-el integrals.'''
    if kpts is not None:
        assert len(kpts) == 4
    return df.DF(cell).ao2mo(mo_coeffs, kpts, compact)