def test_rhf_2d_fft(self): L = 4 cell = pbcgto.Cell() cell.build(unit = 'B', a = [[L,0,0],[0,L,0],[0,0,L*5]], mesh = [11,11,20], atom = '''He 2 0 0; He 3 0 0''', dimension = 2, verbose = 0, basis = { 'He': [[0, (0.8, 1.0)], [0, (1.2, 1.0)] ]}) mf = pbchf.RHF(cell, exxdiv='ewald') mf.with_df = pdf.FFTDF(cell) mf.with_df.mesh = cell.mesh e1 = mf.kernel() self.assertAlmostEqual(e1, -3.5797041803667593, 5) mf1 = pbchf.RHF(cell, exxdiv='ewald') mf1.with_df = pdf.FFTDF(cell) mf1.with_df.mesh = cell.mesh mf1.direct_scf = True e1 = mf1.kernel() self.assertAlmostEqual(e1, -3.5797041803667593, 5) mf2 = pbchf.RHF(cell, exxdiv=None) mf2.with_df = pdf.FFTDF(cell) mf2.with_df.mesh = cell.mesh mf2.direct_scf = True e2 = mf2.kernel() self.assertAlmostEqual(e2, -1.629571720365774, 5)
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)
def get_j(cell, dm, hermi=1, vhfopt=None, kpt=np.zeros(3), kpts_band=None): '''Get the Coulomb (J) AO matrix 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). kpts_band : (3,) ndarray or (*,3) ndarray An arbitrary "band" k-point at which J is evaluated. Returns: The function returns one J matrix, corresponding to the input density matrix (both order and shape). ''' return df.FFTDF(cell).get_jk(dm, hermi, kpt, kpts_band, with_k=False)[0]
def get_qij(gw, q, mo_coeff, uniform_grids=False): ''' Compute qij = 1/Omega * |< psi_{ik} | e^{iqr} | psi_{ak-q} >|^2 at q: (nkpts, nocc, nvir) ''' nocc = gw.nocc nmo = gw.nmo nvir = nmo - nocc kpts = gw.kpts nkpts = len(kpts) cell = gw.mol mo_energy = gw._scf.mo_energy if uniform_grids: mydf = df.FFTDF(cell, kpts=kpts) coords = cell.gen_uniform_grids(mydf.mesh) else: coords, weights = dft.gen_grid.get_becke_grids(cell,level=5) ngrid = len(coords) qij = np.zeros((nkpts,nocc,nvir),dtype=np.complex128) for i, kpti in enumerate(kpts): ao_p = dft.numint.eval_ao(cell, coords, kpt=kpti, deriv=1) ao = ao_p[0] ao_grad = ao_p[1:4] if uniform_grids: ao_ao_grad = einsum('mg,xgn->xmn',ao.T.conj(),ao_grad) * cell.vol / ngrid else: ao_ao_grad = einsum('g,mg,xgn->xmn',weights,ao.T.conj(),ao_grad) q_ao_ao_grad = -1j * einsum('x,xmn->mn',q,ao_ao_grad) q_mo_mo_grad = np.dot(np.dot(mo_coeff[i][:,:nocc].T.conj(), q_ao_ao_grad), mo_coeff[i][:,nocc:]) enm = 1./(mo_energy[i][nocc:,None] - mo_energy[i][None,:nocc]) dens = enm.T * q_mo_mo_grad qij[i] = dens / np.sqrt(cell.vol) return qij
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.FFTDF(cell).get_nuc(kpt)
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)
def test_mdf_jk_rsh(self): L = 4. cell = pgto.Cell() cell.verbose = 0 cell.a = numpy.eye(3)*L cell.atom =[['He' , ( L/2+0., L/2+0. , L/2+1.)],] cell.basis = {'He': [[0, (4.0, 1.0)], [0, (1.0, 1.0)]]} cell.build() nao = cell.nao kpts = [[0.2, 0.2, 0.4]] numpy.random.seed(1) dm = numpy.random.random((nao,nao)) + .2j*numpy.random.random((nao,nao)) dm = dm.dot(dm.conj().T).reshape(1,nao,nao) vj0, vk0 = pbcdf.FFTDF(cell, kpts).get_jk(dm, hermi=0, kpts=kpts, omega=0.3, exxdiv='ewald') vj1, vk1 = pbcdf.GDF(cell, kpts).get_jk(dm, hermi=0, kpts=kpts, omega=0.3, exxdiv='ewald') vj2, vk2 = pbcdf.MDF(cell, kpts).get_jk(dm, hermi=0, kpts=kpts, omega=0.3, exxdiv='ewald') vj3, vk3 = pbcdf.AFTDF(cell, kpts).get_jk(dm, hermi=0, kpts=kpts, omega=0.3, exxdiv='ewald') self.assertAlmostEqual(lib.fp(vj0), 0.007500219791944259, 9) self.assertAlmostEqual(lib.fp(vk0), 0.0007724337759304424+0.00018842136513478529j, 9) self.assertAlmostEqual(abs(vj0-vj1).max(), 0, 8) self.assertAlmostEqual(abs(vj0-vj2).max(), 0, 8) self.assertAlmostEqual(abs(vj0-vj3).max(), 0, 8) self.assertAlmostEqual(abs(vk0-vk1).max(), 0, 8) self.assertAlmostEqual(abs(vk0-vk2).max(), 0, 8) self.assertAlmostEqual(abs(vk0-vk3).max(), 0, 8)
def test_get_j(self): mydf = df.FFTDF(cell) ref = fft_jk.get_j_kpts(mydf, dm, kpts=kpts) mydf = fft_multi_grids.MultiGridFFTDF(cell) v = mydf.get_j_kpts(dm, kpts=kpts) self.assertAlmostEqual(abs(ref-v).max(), 0, 8) self.assertAlmostEqual(lib.finger(v), 0.21963596743261393, 8)
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)
def get_jk(mf, cell, dm_kpts, kpts, kpts_band=None, with_j=True, with_k=True, omega=None, **kwargs): '''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. It needs to be Hermitian. Kwargs: kpts_band : (3,) ndarray A list of 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 ''' return df.FFTDF(cell).get_jk(dm_kpts, kpts, kpts_band, with_j, with_k, omega, exxdiv=mf.exxdiv)
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.FFTDF(cell).get_jk(dm, hermi, kpt, kpt_band, exxdiv=mf.exxdiv)
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)
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)
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.FFTDF(cell) self.exxdiv = exxdiv self.kpt = kpt self.direct_scf = False self._keys = self._keys.union(['cell', 'exxdiv', 'with_df'])
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 : (ngrids, nao*(nao+1)/2) ndarray The FFTs of the real-space AO pairs. ''' return df.FFTDF(cell).get_ao_pairs(kpts)
def test_uks_lda_plus_j(self): mydf = df.FFTDF(cell) mydf.grids.build() ref_j = fft_jk.get_j_kpts(mydf, dmab, kpts=kpts) n, exc, ref = mydf._numint.nr_uks(cell, mydf.grids, 'lda,', dmab, 0, kpts) mydf = fft_multi_grids.MultiGridFFTDF(cell) n, exc, vxc, vj = mydf.uks_j_xc(dmab, 'lda,', kpts=kpts, with_j=False, j_in_xc=True) self.assertAlmostEqual(abs(ref_j+ref-vxc).max(), 0, 6) self.assertAlmostEqual(lib.finger(vxc), -0.24822187080855951+0j, 4) self.assertAlmostEqual(exc, 3.3968809873729704, 6) self.assertAlmostEqual(sum(n), 16.77639832814981, 8)
def test_uks_lda(self): mydf = df.FFTDF(cell) mydf.grids.build() ref_j = fft_jk.get_j_kpts(mydf, dmab, kpts=kpts) n, exc, ref = mydf._numint.nr_uks(cell, mydf.grids, 'lda,', dmab, 0, kpts) mydf = fft_multi_grids.MultiGridFFTDF(cell) n, exc, vxc, vj = mydf.uks_j_xc(dmab, 'lda,', kpts=kpts, with_j=True, j_in_xc=False) self.assertAlmostEqual(abs(ref_j-vj).max(), 0, 8) self.assertAlmostEqual(abs(ref-vxc).max(), 0, 6) self.assertAlmostEqual(lib.finger(vxc), 0.56051003830739932, 6) self.assertAlmostEqual(exc, -8.1508688099749218, 8) self.assertAlmostEqual(sum(n), 16.77639832814981, 8)
def test_rks_gga_plus_j(self): mydf = df.FFTDF(cell) mydf.grids.build() ref_j = fft_jk.get_j_kpts(mydf, dm, kpts=kpts) n, exc, ref = mydf._numint.nr_rks(cell, mydf.grids, 'b88,', dm, 0, kpts) mydf = fft_multi_grids.MultiGridFFTDF(cell) n, exc, vxc, vj = mydf.rks_j_xc(dm, 'b88,', kpts=kpts, with_j=False, j_in_xc=True) self.assertAlmostEqual(abs(ref_j+ref-vxc).max(), 0, 4) self.assertAlmostEqual(lib.finger(vxc), 0.056907756241836749+0j, 4) self.assertAlmostEqual(exc, 2.036577374818183, 6) self.assertAlmostEqual(n, 8.0749444279646347, 8)
def test_rks_lda_plus_j(self): mydf = df.FFTDF(cell) mydf.grids.build() ref_j = fft_jk.get_j_kpts(mydf, dm, kpts=kpts) n, exc, ref = mydf._numint.nr_rks(cell, mydf.grids, 'lda,', dm, 0, kpts) mydf = fft_multi_grids.MultiGridFFTDF(cell) n, exc, vxc, vj = mydf.rks_j_xc(dm, 'lda,', kpts=kpts, with_j=False, j_in_xc=True) self.assertAlmostEqual(abs(ref_j+ref-vxc).max(), 0, 6) self.assertAlmostEqual(lib.finger(vxc), 0.11593869767055653+0j, 8) self.assertAlmostEqual(exc, 2.3601737480485134, 8) self.assertAlmostEqual(n, 8.0749444279646347, 8)
def test_rks_mgga(self): mydf = df.FFTDF(cell) mydf.grids.build() n, exc, ref = mydf._numint.nr_rks(cell, mydf.grids, 'tpss,', dm, 0, kpts) mydf = fft_multi_grids.MultiGridFFTDF(cell) n, exc, vxc, vj = mydf.rks_j_xc(dm, 'tpss,', kpts=kpts, with_j=True, j_in_xc=False) self.assertAlmostEqual(abs(ref-vxc).max(), 0, 2) self.assertAlmostEqual(lib.finger(vxc), -0.12904037508240063, 8) self.assertAlmostEqual(lib.finger(vj), 0.21963596743261393, 8) self.assertAlmostEqual(exc, -3.4188140995616179, 8) self.assertAlmostEqual(n, 8.0749444279646347, 8)
def test_uks_gga_plus_j(self): mydf = df.FFTDF(cell) mydf.grids.build() ref_j = fft_jk.get_j_kpts(mydf, dmab, kpts=kpts) n, exc, ref = mydf._numint.nr_uks(cell, mydf.grids, 'b88,', dmab, 0, kpts) mydf = fft_multi_grids.MultiGridFFTDF(cell) n, exc, vxc, vj = mydf.uks_j_xc(dmab, 'b88,', kpts=kpts, with_j=False, j_in_xc=True) self.assertAlmostEqual(abs(ref_j+ref-vxc).max(), 0, 4) self.assertAlmostEqual(lib.finger(vxc), -0.18113908287908242+0j, 8) self.assertAlmostEqual(exc, 2.7336576611968653, 8) self.assertAlmostEqual(sum(n), 16.77639832814981, 8)
def test_rks_lda(self): mydf = df.FFTDF(cell) mydf.grids.build() ref_j = fft_jk.get_j_kpts(mydf, dm, kpts=kpts) n, exc, ref = mydf._numint.nr_rks(cell, mydf.grids, 'lda,', dm, 0, kpts) mydf = fft_multi_grids.MultiGridFFTDF(cell) n, exc, vxc, vj = mydf.rks_j_xc(dm, 'lda,', kpts=kpts, with_j=True, j_in_xc=False) self.assertAlmostEqual(abs(ref_j-vj).max(), 0, 8) self.assertAlmostEqual(abs(ref-vxc).max(), 0, 6) self.assertAlmostEqual(lib.finger(vxc), -0.10369726976205595, 6) self.assertAlmostEqual(exc, -3.0494590778748032, 8) self.assertAlmostEqual(n, 8.0749444279646347, 8)
def __init__(self, cell, kpt=np.zeros(3), exxdiv='ewald'): if not cell._built: sys.stderr.write('Warning: cell.build() is not called in input\n') cell.build() self.cell = cell hf.SCF.__init__(self, cell) self.with_df = df.FFTDF(cell) self.exxdiv = exxdiv self.kpt = kpt self.direct_scf = False self._keys = self._keys.union(['cell', 'exxdiv', 'with_df'])
def __init__(self, cell, kpt=np.zeros(3), exxdiv=getattr(__config__, 'pbc_scf_SCF_exxdiv', 'ewald')): if not cell._built: sys.stderr.write('Warning: cell.build() is not called in input\n') cell.build() self.cell = cell mol_hf.SCF.__init__(self, cell) self.with_df = df.FFTDF(cell) self.exxdiv = exxdiv self.kpt = kpt self._keys = self._keys.union(['cell', 'exxdiv', 'with_df'])
def get_qij(gw, q, mo_coeff, uniform_grids=False): ''' Compute qij = 1/Omega * |< psi_{ik} | e^{iqr} | psi_{ak-q} >|^2 at q: (nkpts, nocc, nvir) through kp perturbtation theory Ref: Phys. Rev. B 83, 245122 (2011) ''' nocca, noccb = gw.nocc nmoa, nmob = gw.nmo nvira = nmoa - nocca nvirb = nmob - noccb kpts = gw.kpts nkpts = len(kpts) cell = gw.mol mo_energy = np.asarray(gw._scf.mo_energy) if uniform_grids: mydf = df.FFTDF(cell, kpts=kpts) coords = cell.gen_uniform_grids(mydf.mesh) else: coords, weights = dft.gen_grid.get_becke_grids(cell, level=4) ngrid = len(coords) qij_a = np.zeros((nkpts, nocca, nvira), dtype=np.complex128) qij_b = np.zeros((nkpts, noccb, nvirb), dtype=np.complex128) for i, kpti in enumerate(kpts): ao_p = dft.numint.eval_ao(cell, coords, kpt=kpti, deriv=1) ao = ao_p[0] ao_grad = ao_p[1:4] if uniform_grids: ao_ao_grad = einsum('mg,xgn->xmn', ao.T.conj(), ao_grad) * cell.vol / ngrid else: ao_ao_grad = einsum('g,mg,xgn->xmn', weights, ao.T.conj(), ao_grad) q_ao_ao_grad = -1j * einsum('x,xmn->mn', q, ao_ao_grad) q_mo_mo_grad_a = np.dot( np.dot(mo_coeff[0, i][:, :nocca].T.conj(), q_ao_ao_grad), mo_coeff[0, i][:, nocca:]) q_mo_mo_grad_b = np.dot( np.dot(mo_coeff[1, i][:, :noccb].T.conj(), q_ao_ao_grad), mo_coeff[1, i][:, noccb:]) enm_a = 1. / (mo_energy[0, i][nocca:, None] - mo_energy[0, i][None, :nocca]) enm_b = 1. / (mo_energy[1, i][noccb:, None] - mo_energy[1, i][None, :noccb]) dens_a = enm_a.T * q_mo_mo_grad_a dens_b = enm_b.T * q_mo_mo_grad_b qij_a[i] = dens_a / np.sqrt(cell.vol) qij_b[i] = dens_b / np.sqrt(cell.vol) return (qij_a, qij_b)
def __init__(self, comm, cell, kpts, maxvecs, nmo_pk, QKToK2, kminus, gtol_chol=1e-5, verbose=True): self.QKToK2 = QKToK2 self.kminus = kminus nmo_max = numpy.max(nmo_pk) nmo_tot = numpy.sum(nmo_pk) if comm.rank == 0 and verbose: print(" # Total number of orbitals: {}".format(nmo_tot)) sys.stdout.flush() assert (nmo_max is not None) nkpts = len(kpts) self.nkpts = nkpts self.kpts = kpts self.cell = cell self.part = Partition(comm, maxvecs, nmo_tot, nmo_max, nkpts, kp_sym=True) maxvecs = maxvecs * nmo_max self.maxvecs = maxvecs self.nmo_max = nmo_max self.gmap, self.Qi, self.ngs = generate_grid_shifts(cell) if comm.rank == 0 and verbose: print(" # Each kpoint is distributed accross {} mpi tasks.".format( self.part.nproc_pk)) sys.stdout.flush() try: self.maxres_buff = numpy.zeros(5 * comm.size, dtype=numpy.float64) except MemoryError: print(" # Problems allocating memory for auxiliary structures for " "Cholesky solver.") sys.exit() self.df = df.FFTDF(cell, kpts) tstart = time.clock() self.nmo_pk = nmo_pk self.gtol_chol = gtol_chol self.verbose = verbose
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)
def __init__(self, cell, kpts=np.zeros((1, 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 hf.RHF.__init__(self, cell) self.with_df = df.FFTDF(cell) self.exxdiv = exxdiv self.kpts = kpts self.direct_scf = False self.exx_built = False self._keys = self._keys.union( ['cell', 'exx_built', 'exxdiv', 'with_df'])
def setUpModule(): global cell_orth, cell_nonorth, cell_he, mydf global kpts, nao, dm, dm1, vj_uks_orth, he_nao, dm_he numpy.random.seed(2) cell_orth = gto.M( verbose=7, output='/dev/null', a=numpy.eye(3) * 3.5668, atom='''C 0. 0. 0. C 1.8 1.8 1.8 ''', basis='gth-dzv', pseudo='gth-pade', precision=1e-9, mesh=[48] * 3, ) cell_nonorth = gto.M( a=numpy.eye(3) * 3.5668 + numpy.random.random((3, 3)), atom='''C 0. 0. 0. C 0.8917 0.8917 0.8917''', basis='gth-dzv', pseudo='gth-pade', precision=1e-9, mesh=[44, 43, 42], ) cell_he = gto.M(atom='He 0 0 0', basis=[[0, (1, 1, .1), (.5, .1, 1)], [1, (.8, 1)]], unit='B', precision=1e-9, mesh=[18] * 3, a=numpy.eye(3) * 5) kptsa = numpy.random.random((2, 3)) kpts = kptsa.copy() kpts[1] = -kpts[0] nao = cell_orth.nao_nr() dm = numpy.random.random((len(kpts), nao, nao)) * .2 dm1 = dm + numpy.eye(nao) dm = dm1 + dm1.transpose(0, 2, 1) mydf = df.FFTDF(cell_orth) vj_uks_orth = mydf.get_jk(dm1, with_k=False)[0] he_nao = cell_he.nao dm_he = numpy.random.random((len(kpts), he_nao, he_nao)) dm_he = dm_he + dm_he.transpose(0, 2, 1) dm_he = dm_he * .2 + numpy.eye(he_nao)
def get_j(mf, cell, dm_kpts, kpts, kpts_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. It needs to be Hermitian. Kwargs: kpts_band : (k,3) ndarray A list of arbitrary "band" k-points 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 ''' return df.FFTDF(cell).get_jk(dm_kpts, kpts, kpts_band, with_k=False)[0]