def test_efg_kernel(self): cell = gto.Cell() cell.atom = 'H 1 0.8 0; H 0. 1.3 0' cell.a = np.eye(3) * 3 cell.basis = [[0, (2.0, 1.)], [0, (0.5, 1.)]] cell.mesh = [20] * 3 cell.build() np.random.seed(12) kpts = cell.make_kpts([2] * 3) nao = cell.nao dm = np.random.random((len(kpts), nao, nao)) mf = scf.RHF(cell) mf.make_rdm1 = lambda *args, **kwargs: dm vref = EFG(mf) self.assertAlmostEqual(lib.finger(vref), 0.67090557110411564, 9) mf.with_df = df.AFTDF(cell) mf.with_df.eta = 0 v = EFG(mf) self.assertAlmostEqual(abs(v - vref).max(), 0, 2) mf.with_df = df.AFTDF(cell) mf.with_df.mesh = [8] * 3 v = EFG(mf) self.assertAlmostEqual(abs(v - vref).max(), 0, 2)
def test_pnucp(self): cell1 = gto.Cell() cell1.atom = ''' He 1.3 .2 .3 He .1 .1 1.1 ''' cell1.basis = {'He': [[0, [0.8, 1]], [1, [0.6, 1]]]} cell1.mesh = [15] * 3 cell1.a = numpy.array(([2.0, .9, 0.], [0.1, 1.9, 0.4], [0.8, 0, 2.1])) cell1.build() charge = -cell1.atom_charges() Gv = cell1.get_Gv(cell1.mesh) SI = cell1.get_SI(Gv) rhoG = numpy.dot(charge, SI) coulG = tools.get_coulG(cell1, mesh=cell1.mesh, Gv=Gv) vneG = rhoG * coulG vneR = tools.ifft(vneG, cell1.mesh).real coords = cell1.gen_uniform_grids(cell1.mesh) aoR = dft.numint.eval_ao(cell1, coords, deriv=1) ngrids, nao = aoR.shape[1:] vne_ref = numpy.einsum('p,xpi,xpj->ij', vneR, aoR[1:4], aoR[1:4]) mydf = df.AFTDF(cell1) dat = sfx2c1e.get_pnucp(mydf) self.assertAlmostEqual(abs(dat - vne_ref).max(), 0, 7) mydf.eta = 0 dat = sfx2c1e.get_pnucp(mydf) self.assertAlmostEqual(abs(dat - vne_ref).max(), 0, 7)
def test_mdf_jk_0d(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.dimension = 0 cell.mesh = [60]*3 cell.build() nao = cell.nao numpy.random.seed(1) dm = numpy.random.random((nao,nao)) dm = dm.dot(dm.conj().T).reshape(1,nao,nao) vj0, vk0 = scf.hf.get_jk(cell, dm, hermi=0, omega=0.5) self.assertAlmostEqual(lib.fp(vj0), 0.08265798268352553, 9) self.assertAlmostEqual(lib.fp(vk0), 0.2375705823780625 , 9) vj1, vk1 = pbcdf.GDF(cell).get_jk(dm, hermi=0, omega=0.5, exxdiv=None) vj2, vk2 = pbcdf.MDF(cell).get_jk(dm, hermi=0, omega=0.5, exxdiv=None) vj3, vk3 = pbcdf.AFTDF(cell).get_jk(dm, hermi=0, omega=0.5, exxdiv=None) self.assertAlmostEqual(abs(vj0-vj1).max(), 0, 3) self.assertAlmostEqual(abs(vj0-vj2).max(), 0, 3) self.assertAlmostEqual(abs(vj0-vj3).max(), 0, 3) self.assertAlmostEqual(abs(vk0-vk1).max(), 0, 3) self.assertAlmostEqual(abs(vk0-vk2).max(), 0, 3) self.assertAlmostEqual(abs(vk0-vk3).max(), 0, 3)
def test_aft_bands(self): mf = scf.KRHF(cell) mf.with_df = df.AFTDF(cell) mf.kpts = cell.make_kpts([2,1,1]) mf.kernel() self.assertAlmostEqual(finger(mf.get_bands(kband[0])[0]), 1.968506055533682, 8) self.assertAlmostEqual(finger(mf.get_bands(kband)[0]), 1.0538585525613609, 7)
def test_aft_bands(self): mf = scf.KRHF(cell) mf.with_df = df.AFTDF(cell) mf.kpts = cell.make_kpts([2]*3) mf.kernel() self.assertAlmostEqual(finger(mf.get_bands(kband[0])[0]), -0.32214958122356513, 9) self.assertAlmostEqual(finger(mf.get_bands(kband)[0]), -0.64207984898611348, 9)
def test_krhf_2d(self): L = 4 cell = pbcgto.Cell() cell.build( unit='B', a=np.eye(3) * 4, mesh=[10, 10, 20], atom='''He 2 0 0; He 3 0 0''', dimension=2, low_dim_ft_type='inf_vacuum', verbose=0, rcut=7.427535697575829, basis={ 'He': [ [0, (0.8, 1.0)], #[0, (1.0, 1.0)], [0, (1.2, 1.0)] ] }) mf = khf.KRHF(cell) mf.with_df = df.AFTDF(cell) mf.with_df.eta = 0.2 mf.with_df.mesh = cell.mesh mf.kpts = cell.make_kpts([2, 1, 1]) e1 = mf.kernel() self.assertAlmostEqual(e1, -3.5376801775171911, 5)
def test_kghf_1d(self): L = 4 cell = pbcgto.Cell() cell.build( unit='B', a=np.eye(3) * 4, mesh=[8, 20, 20], atom='''He 2 0 0; He 3 0 0''', dimension=1, low_dim_ft_type='inf_vacuum', verbose=0, rcut=7.427535697575829, basis={ 'He': [ [0, (0.8, 1.0)], #[0, (1.0, 1.0)], [0, (1.2, 1.0)] ] }) mf = pscf.KGHF(cell) mf.with_df = df.AFTDF(cell) mf.with_df.eta = 0.2 mf.init_guess = 'hcore' mf.kpts = cell.make_kpts([2, 1, 1]) e1 = mf.kernel() self.assertAlmostEqual(e1, -3.5112358424228809, 4)
def test_rhf_2d(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, low_dim_ft_type='inf_vacuum', verbose=0, rcut=7.427535697575829, basis={ 'He': [ [0, (0.8, 1.0)], #[0, (1.0, 1.0)], [0, (1.2, 1.0)] ] }) mf = pbchf.RHF(cell) mf.with_df = pdf.AFTDF(cell) mf.with_df.eta = 0.3 mf.with_df.mesh = cell.mesh e1 = mf.kernel() self.assertAlmostEqual(e1, -3.2681555164454039, 5)
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_ghf_1d(self): L = 4 cell = pbcgto.Cell() cell.build( unit='B', a=numpy.eye(3) * 4, mesh=[10, 20, 20], atom='''He 2 0 0; He 3 0 0''', dimension=1, low_dim_ft_type='inf_vacuum', verbose=0, basis={ 'He': [ [0, (0.8, 1.0)], #[0, (1.0, 1.0)], [0, (1.2, 1.0)] ] }) mf = pscf.GHF(cell) mf.with_df = pdf.AFTDF(cell) mf.with_df.eta = 0.3 mf.with_df.mesh = cell.mesh mf.init_guess = 'hcore' e1 = mf.kernel() self.assertAlmostEqual(e1, -3.24497234871167, 5)
def test_khf(self): with lib.light_speed(2) as c: mf = scf.KRHF(cell).sfx2c1e() mf.with_df = df.AFTDF(cell) mf.kpts = cell.make_kpts([3,1,1]) dm = mf.get_init_guess() h1 = mf.get_hcore() self.assertAlmostEqual(numpy.einsum('ij,ji', dm[0], h1[0]),-0.47578184212352159+0j, 8) self.assertAlmostEqual(numpy.einsum('ij,ji', dm[1], h1[1]),-0.09637799091491725+0j, 8) self.assertAlmostEqual(numpy.einsum('ij,ji', dm[2], h1[2]),-0.09637799091491725+0j, 8)
def test_hf(self): with lib.light_speed(2) as c: mf = scf.RHF(cell).sfx2c1e() mf.with_df = df.AFTDF(cell) dm = mf.get_init_guess() h1 = mf.get_hcore() self.assertAlmostEqual(numpy.einsum('ij,ji', dm, h1), -0.2458227312351979 + 0j, 8) kpts = cell.make_kpts([3, 1, 1]) h1 = mf.get_hcore(kpt=kpts[1]) self.assertAlmostEqual(numpy.einsum('ij,ji', dm, h1), -0.04113247191600125 + 0j, 8)
def test_khf(self): with lib.light_speed(2) as c: mf = scf.KRHF(cell).sfx2c1e() mf.with_df = df.AFTDF(cell) mf.kpts = cell.make_kpts([3, 1, 1]) dm = mf.get_init_guess() h1 = mf.get_hcore() self.assertAlmostEqual(numpy.einsum('ij,ji', dm[0], h1[0]), -0.31082970748083477 + 0j, 8) self.assertAlmostEqual(numpy.einsum('ij,ji', dm[1], h1[1]), -0.05200981271862468 + 0j, 8) self.assertAlmostEqual(numpy.einsum('ij,ji', dm[2], h1[2]), -0.05200981271862468 + 0j, 8)
def test_hf(self): with lib.light_speed(2) as c: mf = scf.RHF(cell).sfx2c1e() mf.with_df = df.AFTDF(cell) dm = mf.get_init_guess() h1 = mf.get_hcore() self.assertAlmostEqual( numpy.einsum('ij,ji', dm, h1), 2 / 3.7865300454631 * -0.47578184212352159 + 0j, 8) kpts = cell.make_kpts([3, 1, 1]) h1 = mf.get_hcore(kpt=kpts[1]) self.assertAlmostEqual( numpy.einsum('ij,ji', dm, h1), 2 / 3.7865300454631 * -0.09637799091491725 + 0j, 8)
def test_pp_int(self): from pyscf import gto, scf from pyscf.pbc import gto as pbcgto from pyscf.pbc import scf as pbcscf from pyscf.pbc import df cell = pbcgto.Cell() cell.atom = 'He 1. .5 .5; C .1 1.3 2.1' cell.basis = { 'He': [(0, (2.5, 1)), (0, (1., 1))], 'C': 'gth-szv', } cell.pseudo = { 'C': 'gth-pade', 'He': pbcgto.pseudo.parse('''He 2 0.40000000 3 -1.98934751 -0.75604821 0.95604821 2 0.29482550 3 1.23870466 .855 .3 .71 -1.1 .9 0.32235865 2 2.25670239 -0.39677748 0.93894690 ''') } cell.a = numpy.eye(3) cell.dimension = 0 cell.build() mol = cell.to_mol() hcore = scf.RHF(mol).get_hcore() mydf = df.AFTDF(cell) ref = mydf.get_pp() + mol.intor('int1e_kin') self.assertAlmostEqual(abs(hcore - ref).max(), 0, 2) mf = pbcscf.RHF(cell) mf.with_df = mydf mf.run() e_ref = mf.e_tot e_tot = scf.RHF(mol).run().e_tot self.assertAlmostEqual(abs(e_ref - e_tot).max(), 0, 6)
def test_rhf_1d(self): L = 4 cell = pbcgto.Cell() cell.build(unit = 'B', a = [[L,0,0],[0,L*5,0],[0,0,L*5]], mesh = [11,20,20], atom = '''He 2 0 0; He 3 0 0''', dimension = 1, verbose = 0, basis = { 'He': [[0, (0.8, 1.0)], #[0, (1.0, 1.0)], [0, (1.2, 1.0)] ]}) mf = pbchf.RHF(cell) mf.with_df = pdf.AFTDF(cell) mf.with_df.eta = 0.3 mf.with_df.mesh = cell.mesh e1 = mf.kernel() self.assertAlmostEqual(e1, -3.24497234871167, 5)
def test_rhf_2d(self): L = 4 cell = pbcgto.Cell() cell.build( unit='B', a=[[L, 0, 0], [0, L, 0], [0, 0, L * 5]], gs=[5, 5, 10], atom='''He 2 0 0; He 3 0 0''', dimension=2, verbose=0, basis={ 'He': [ [0, (0.8, 1.0)], #[0, (1.0, 1.0)], [0, (1.2, 1.0)] ] }) mf = pbchf.RHF(cell) mf.with_df = pdf.AFTDF(cell) e1 = mf.kernel() self.assertAlmostEqual(e1, -3.2684257145738229, 5)
def test_kuhf_1d(self): L = 4 cell = pbcgto.Cell() cell.build( unit='B', a=np.eye(3) * 4, mesh=[8, 20, 20], atom='''He 2 0 0; He 3 0 0''', dimension=1, verbose=0, basis={ 'He': [ [0, (0.8, 1.0)], #[0, (1.0, 1.0)], [0, (1.2, 1.0)] ] }) mf = kuhf.KUHF(cell) mf.with_df = df.AFTDF(cell) mf.with_df.eta = 0.2 mf.init_guess = 'hcore' mf.kpts = cell.make_kpts([2, 1, 1]) e1 = mf.kernel() self.assertAlmostEqual(e1, -3.5112358424228809, 5)
import numpy as np import time from pyscf.pbc import gto, scf, df import pyscf_cache # Run without caching: cell = gto.Cell() cell.build(atom='He 0 0 1; He 1 0 1', basis='6-31g', a=np.eye(3)*3, mesh=[10,]*3, verbose=0) rhf_old = scf.KRHF(cell) rhf_old.with_df = df.AFTDF(cell) rhf_old.kpts = cell.make_kpts([2,2,1]) t0 = time.time() rhf_old.run() t1 = time.time() # Assign desired cached functions and apply decorators: pyscf_cache.to_cache = { gto.Cell: ['energy_nuc', 'ewald'], scf.KRHF: ['get_hcore'], df.AFTDF: ['ft_loop'], } copy_policy = {}
def test_aft_band(self): mf = scf.RHF(cell) mf.with_df = df.AFTDF(cell) mf.kernel() self.assertAlmostEqual(lib.fp(mf.get_bands(kband[0])[0]), 1.9966027703000777, 7)
# 2D PBC with AFT # ################################################## cell = pbcgto.Cell() cell.build(unit = 'B', a = [[4.6298286730500005, 0.0, 0.0], [-2.3149143365249993, 4.009549246030899, 0.0], [0.0, 0.0, Lz]], atom = 'C 0 0 0; C 0 2.67303283 0', mesh = aft_mesh, dimension=2, pseudo = pseudo, verbose = 7, precision = 1e-6, basis='gth-szv') t0 = time.time() mf = pbchf.KRHF(cell) mf.with_df = pdf.AFTDF(cell) mf.kpts = cell.make_kpts(kpts) mf.conv_tol = 1e-6 e.append(mf.kernel()) t.append(time.time() - t0) ################################################## # # 2D PBC with FFT # ################################################## cell = pbcgto.Cell() cell.build(unit = 'B', a = [[4.6298286730500005, 0.0, 0.0], [-2.3149143365249993, 4.009549246030899, 0.0], [0.0, 0.0, Lz]], atom = 'C 0 0 0; C 0 2.67303283 0', ke_cutoff = fft_ke_cut,
def test_aft_band(self): mf = scf.RHF(cell) mf.with_df = df.AFTDF(cell) mf.kernel() self.assertAlmostEqual(finger(mf.get_bands(kband[0])[0]), -0.093770552709347754, 9)
new = super_cell(cell, nmp) cell = pbcgto.Cell() #cell.unit = 'B' cell.spin = 0 cell.symmetry = 0 cell.charge = 0 cell.verbose = 4 cell.atom = new.atom cell.a = new.a cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.mesh = [10, 10, 10] cell.build() mf = pbchf.RHF(cell) mf.with_df = pbcdf.AFTDF(cell) mf.kernel() nao = cell.nao_nr() dm = mf.make_rdm1() mo = mf.mo_coeff c = numpy.eye(cell.nao_nr()) s = cell.pbc_intor('cint1e_ovlp_sph') pop = einsum('ij,ji->', s, dm) print('Population : %s' % pop) pairs1 = einsum('ij,kl,ij,kl->', dm, dm, s, s) * 0.5 # J pairs2 = einsum('ij,kl,li,kj->', dm, dm, s, s) * 0.25 # XC pairs = (pairs1 - pairs2) print('Coulomb Pairs : %12.6f' % (pairs1))
pqkR = pqkI = None return eriR def get_eri_2c2e(mydf): from pyscf.gto.ft_ao import ft_ao eriR = 0 kptijkl = numpy.zeros((4, 3)) q = numpy.zeros(3) coulG = mydf.weighted_coulG(q, False, mydf.mesh) Gv, Gvbase, kws = cell.get_Gv_weights(mydf.mesh) ao = ft_ao(cell, Gv) return lib.dot(ao.T * coulG, ao.conj()) mydf = df.AFTDF(cell) # Regular ERIs eri0 = get_eri(mydf) eri1 = cell.intor('int2e_sph', aosym='s4') print('int2e', abs(eri0 - eri1).max(), abs(eri0).max()) eri0 = get_eri_ip1(mydf) eri1 = cell.intor('int2e_ip1_sph', aosym='s1', comp=3) eri1 = -eri1 - eri1.transpose(0, 2, 1, 3, 4) print('int2e_ip1', abs(eri0 - eri1).max(), abs(eri0).max()) eri0 = get_eri_laplacian(mydf) eri1_ipip1 = cell.intor('int2e_ipip1_sph', aosym='s1', comp=9).reshape(3, 3, nao, nao, nao, nao) eri1_ipvip1 = cell.intor('int2e_ipvip1_sph', aosym='s1',