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 jk_method(self, J='FFTDF', K=None): ''' Set up the schemes to evaluate Coulomb and exchange matrix FFTDF: planewave density fitting using Fast Fourier Transform AFTDF: planewave density fitting using analytic Fourier Transform GDF: Gaussian density fitting MDF: Gaussian and planewave mix density fitting RS: range-separation JK builder RSDF: range-separation density fitting ''' if K is None: K = J if J != K: raise NotImplementedError('J != K') if 'DF' in J or 'DF' in K: if 'DF' in J and 'DF' in K: assert J == K else: df_method = J if 'DF' in J else K self.with_df = getattr(df, df_method)(self.cell, self.kpts) if 'RS' in J or 'RS' in K: self.rsjk = RangeSeparationJKBuilder(self.cell, self.kpts) self.rsjk.verbose = self.verbose # For nuclear attraction if J == 'RS' and K == 'RS' and not isinstance(self.with_df, df.GDF): self.with_df = df.GDF(self.cell, self.kpts) nuc = self.with_df.__class__.__name__ logger.debug1(self, 'Apply %s for J, %s for K, %s for nuc', J, K, nuc) return self
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_gwcd_high_cost(self): kpts = cell.make_kpts([3,1,1],scaled_center=[0,0,0]) gdf = df.GDF(cell, kpts) gdf._cderi = gdf_fname = os.path.realpath(os.path.join(__file__, '..', 'gdf_ints_311.h5')) if 1: gdf._cderi_to_save = gdf_fname gdf.build() kmf = dft.KRKS(cell, kpts).density_fit(with_df=gdf) kmf.xc = 'pbe' kmf.kernel() gw = krgw_cd.KRGWCD(kmf) gw.linearized = False # without finite size corrections gw.fc = False nocc = gw.nocc gw.kernel(kptlist=[0,1,2],orbs=range(0,nocc+3)) self.assertAlmostEqual(gw.mo_energy[0][nocc-1], 0.62045796, 4) self.assertAlmostEqual(gw.mo_energy[0][nocc], 0.96574426, 4) self.assertAlmostEqual(gw.mo_energy[1][nocc-1], 0.52639129, 4) self.assertAlmostEqual(gw.mo_energy[1][nocc], 1.07442235, 4) # with finite size corrections gw.fc = True gw.kernel(kptlist=[0,1,2],orbs=range(0,nocc+3)) self.assertAlmostEqual(gw.mo_energy[0][nocc-1], 0.5427707 , 4) self.assertAlmostEqual(gw.mo_energy[0][nocc], 0.80148557, 4) self.assertAlmostEqual(gw.mo_energy[1][nocc-1], 0.45073751, 4) self.assertAlmostEqual(gw.mo_energy[1][nocc], 0.92910117, 4)
def make_cell(d, kmesh): a = np.eye(3) a[0,0] = 10 a[1,1] = 10 a[2,2] = 2*d atoms = [['H',[5,5,0.25*a[2,2]+0.5]],['H',[5,5,0.75*a[2,2]-0.5]]] cell = gto.Cell() cell.atom = atoms cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.a = a cell.verbose = 5 cell.build() kpts = cell.make_kpts(kmesh,wrap_around=True) krhf = scf.KRHF(cell, kpts).density_fit() gdf = df.GDF(cell, kpts) gdf._cderi_to_save = 'gdf.h5' gdf.build() krhf.with_df._cderi = 'gdf.h5' krhf.exxdiv = None krhf.run() num_wann =2 keywords = \ ''' begin projections H:s end projections num_iter = 100 ''' w90 = pywannier90.W90(krhf, cell, kmesh, num_wann, other_keywords = keywords) w90.kernel() w90.plot_wf(grid=[20,20,20], supercell=kmesh) return cell, krhf, w90
def test_ao2mo(self): kmf = make_rand_kmf() rand_cc = pbcc.KRCCSD(kmf) # incore eris1 = pbcc.kccsd_rhf._ERIS(rand_cc, rand_kmf.mo_coeff) self.assertAlmostEqual(finger(eris1.oooo), 0.13691900935600992 + 0.026617355192746089j, 12) self.assertAlmostEqual(finger(eris1.ooov), 0.11364240700567171 - 0.041695025273248622j, 12) self.assertAlmostEqual(finger(eris1.oovv), -0.23285827477217841 + 0.019174699732188771j, 12) self.assertAlmostEqual(finger(eris1.ovov), -0.43577673177721338 - 0.25735127894943477j, 12) self.assertAlmostEqual(finger(eris1.voov), -0.38516873139657298 + 0.26042322219884251j, 12) self.assertAlmostEqual(finger(eris1.vovv), -0.12844875724711163 + 0.17587781601517866j, 12) self.assertAlmostEqual(finger(eris1.vvvv), -0.39587103797107615 - 0.001692506310261882j, 12) # outcore eris2 = pbcc.kccsd_rhf._ERIS(rand_cc, rand_kmf.mo_coeff, method='outcore') self.assertAlmostEqual(abs(eris2.oooo - eris1.oooo).max(), 0, 12) self.assertAlmostEqual(abs(eris2.ooov - eris1.ooov).max(), 0, 12) self.assertAlmostEqual(abs(eris2.oovv - eris1.oovv).max(), 0, 12) self.assertAlmostEqual(abs(eris2.ovov - eris1.ovov).max(), 0, 12) self.assertAlmostEqual(abs(eris2.voov - eris1.voov).max(), 0, 12) self.assertAlmostEqual(abs(eris2.vovv - eris1.vovv).max(), 0, 12) self.assertAlmostEqual(abs(eris2.vvvv - eris1.vvvv).max(), 0, 12) # df rand_cc.direct = True rand_cc._scf.with_df = pbc_df.GDF(kmf.cell, kmf.kpts) eris3 = pbcc.kccsd_rhf._ERIS(rand_cc, rand_kmf.mo_coeff, method='outcore') self.assertAlmostEqual(finger(eris3.oooo), 0.13807643618081983 + 0.02706881005926997j, 12) self.assertAlmostEqual(finger(eris3.ooov), 0.11503403213521873 - 0.04088028212967049j, 12) self.assertAlmostEqual(finger(eris3.oovv), -0.23166000424452704 + 0.01922808953198968j, 12) self.assertAlmostEqual(finger(eris3.ovov), -0.4333329222923895 - 0.2542273009739961j, 12) self.assertAlmostEqual(finger(eris3.voov), -0.3851423191571177 + 0.26086853075652333j, 12) self.assertAlmostEqual(finger(eris3.vovv), -0.12653400070346893 + 0.17634730801555784j, 12) self.assertAlmostEqual(finger(np.array(eris3.Lpv.tolist())), -2.2567245766867092 + 0.7648803028093745j, 12)
def scf_run(pmol, method='KROHF', df_method='gdf', use_saved_eri=False, \ eri_fname='./gdf_ints_atom_full_basis.h5'): if method == 'KROHF': pmf = scf.KROHF(pmol) else: raise NotImplementedError pmf.max_cycle = 5000 pmf.conv_tol = 1e-10 if df_method == 'gdf': gdf = df.GDF(pmol, kpts=pmol.make_kpts([1, 1, 1])) else: raise NotImplementedError if not use_saved_eri: gdf._cderi_to_save = eri_fname gdf.build() pmf.with_df = gdf pmf.with_df._cderi = eri_fname pmf.scf() return pmf
def make_cell(): a = np.eye(3) a[0,0] = 10 a[1,1] = 10 a[2,2] = 15 atoms = [['Li',[5,5,1.5]],['H',[5,5,3.5]],['H',[5,5,6.5]],['H',[5,5,8.5]],['H',[5,5,11.5]],['H',[5,5,13.5]]] cell = gto.Cell() cell.atom = atoms cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.a = a cell.verbose = 5 cell.build() kmesh = [1, 1, 1] kpts = cell.make_kpts(kmesh) krhf = scf.KRHF(cell, kpts).density_fit() gdf = df.GDF(cell, kpts) gdf._cderi_to_save = 'gdf_gamma.h5' gdf.build() krhf.with_df._cderi = 'gdf_gamma.h5' krhf.exxdiv = None krhf.run() num_wann =7 keywords = \ ''' begin projections Li:sp H:s end projections num_iter = 100 ''' w90 = pywannier90.W90(krhf, cell, kmesh, num_wann, other_keywords = keywords) w90.kernel() w90.plot_wf(grid=[20,20,20], supercell=kmesh) return cell, krhf, w90
cell = gto.Cell() cell.unit = 'A' cell.a = [[4, 0, 0], [0, 1, 0], [0, 0, 1]] cell.atom = ''' H 0.0000000 0.0000000 0.0000000 H 1.0000000 0.0000000 0.0000000 H 2.0000000 0.0000000 0.0000000 H 3.0000000 0.0000000 0.0000000 ''' cell.basis = 'sto-6g' cell.dimension = 1 cell.verbose = 4 cell.build() gdf = df.GDF(cell) mf = scf.RHF(cell) mf.with_df = gdf mf.with_df.auxbasis = 'cc-pvdz-jkfit' mf.max_cycle = 150 mf.chkfile = name + '.chk' #mf.with_df._cderi_to_save = name+'_eri.h5' #mf.with_df._cderi = name+'_eri.h5' #mf = mole_scf.addons.remove_linear_dep_(mf) #mf.__dict__.update(scf.chkfile.load(name+'.chk', 'scf')) #dm = mf.make_rdm1() ehf = mf.kernel() ncore = 0 nao, nmo = mf.mo_coeff.shape
C 1.7834 0. 1.7834 C 2.6751 0.8917 2.6751 C 0. 1.7834 1.7834 C 0.8917 2.6751 2.6751''' cell.a = np.eye(3) * 3.5668 cell.basis = 'sto-3g' #cell.precision = 1e-10 cell.verbose = 4 cell.build() kmesh = [2, 2, 2] abs_kpts = cell.make_kpts(kmesh) scaled_kpts = cell.get_scaled_kpts(abs_kpts) kmf = pscf.KRHF(cell, abs_kpts).density_fit() gdf = df.GDF(cell, abs_kpts) kmf.with_df = gdf #kmf.checkfile = './ch4.chk' kmf.verbose = 5 #kmf = pscf.KRHF(cell, abs_kpts) #kmf.__dict__.update(scf.chkfile.load('ch4.chk', 'scf')) # test ekpt = kmf.run() print np.asarray(kmf.mo_coeff) kmf_sc = k2gamma(kmf, abs_kpts, kmesh, realize=True, tol_deg=5e-5, real_split=False)
mf = pbchf.KRHF(cell, exxdiv='ewald') #mf = pbchf.KRHF(cell, exxdiv=None) mf.with_df = pdf.FFTDF(cell) mf.kpts = cell.make_kpts(kpts) mf.conv_tol = 1e-6 e.append(mf.kernel()) t.append(time.time() - t0) ################################################## # # 2D PBC with GDF # ################################################## t0 = time.time() mf = pbchf.KRHF(cell) mf.with_df = pdf.GDF(cell) mf.kpts = cell.make_kpts(kpts) mf.conv_tol = 1e-6 e.append(mf.kernel()) t.append(time.time() - t0) ################################################## # # 2D PBC with MDF # ################################################## t0 = time.time() mf = pbchf.KRHF(cell) mf.with_df = pdf.MDF(cell) mf.kpts = cell.make_kpts(kpts) mf.conv_tol = 1e-6
# ''' cell.basis = '321g' cell.a = np.array([[6.00, 0.0, 0.0], [0.0, 20.0, 0.0],[0.0, 0.0, 20.0]]) #cell.mesh = [21, 21, 21 ] cell.precision = 1e-10 cell.verbose = 6 cell.unit='B' cell.build() kmesh = [3, 1, 1] abs_kpts = cell.make_kpts(kmesh) scaled_kpts = cell.get_scaled_kpts(abs_kpts) kmf = pscf.KRHF(cell, abs_kpts).density_fit() gdf = df.GDF(cell, abs_kpts) kmf.with_df = gdf kmf.checkfile = './ch4.chk' kmf.verbose = 5 #kmf = pscf.KRHF(cell, abs_kpts) #kmf.__dict__.update(scf.chkfile.load('ch4.chk', 'scf')) # test ekpt = kmf.run() kmf_sc = k2gamma(kmf, abs_kpts, kmesh, realize = False, tol_deg = 5e-5, real_split = False) c_g_ao = kmf_sc.mo_coeff[0] print "Supercell gamma MO in AO basis from conversion:" print c_g_ao mo_coeff_occ = kmf_sc.mo_coeff[0][:,kmf_sc.mo_occ[0]>0] lo_iao = lo.iao.iao(kmf_sc.cell, mo_coeff_occ)
import inp # Initialize geometry geoms = read(inp.filename, ":") geom = geoms[iconf] symb = geom.get_chemical_symbols() coords = geom.get_positions() cell = geom.get_cell() natoms = len(coords) atoms = [] for i in range(natoms): coord = coords[i] atoms.append([symb[i], (coord[0], coord[1], coord[2])]) # Get PySCF objects for wave-function and density-fitted basis mol = gto.M(atom=atoms, basis=inp.qmbasis, a=cell) gdf = df.GDF(mol) #mol = gto.M(atom=atoms, basis='gth-dzvp', pseudo = 'gth-pade', a=cell) mol.verbose = 4 # Run restricted hartree-fock calculation m = dft.RKS(mol) m.xc = inp.functional m.with_df = gdf # Save density matrix m.kernel() dm = m.make_rdm1() dirpath = os.path.join(inp.path2indata, "density_matrices") if not os.path.exists(dirpath): os.mkdir(dirpath) np.save(inp.path2indata + "density_matrices/dm_conf" + str(iconf + 1) + ".npy",
cell.atom = ''' C 0.00000000 0.00000000 0.00000000 C 1.686580575 1.686580575 1.686580575 ''' cell.basis = 'bfd-vtz' cell.ecp = 'bfd' cell.unit = 'B' cell.drop_exponent = 0.1 cell.verbose = 5 cell.build() kpts = cell.make_kpts(kmesh) kpts -= kpts[0] supcell = cell mydf = df.GDF(supcell, kpts) mydf.auxbasis = 'weigend' mf = scf.KRHF(supcell, kpts).density_fit() mf.exxdiv = 'ewald' mf.with_df = mydf e_scf = mf.kernel() title = "C_Diamond-211" from PyscfToQmcpack import savetoqmcpack savetoqmcpack(supcell, mf, title=title, kpts=kpts, kmesh=kmesh)
e = myscc.ipccsd(nroots=4, koopmans=False, kptlist=(0, ))[0] self.assertAlmostEqual(e[0][0], -4.261818242746091, 6) self.assertAlmostEqual(e[0][1], -4.235233956876479, 6) self.assertAlmostEqual(e[0][2], -3.477663568390151, 6) self.assertAlmostEqual(e[0][3], -3.459133332687474, 6) if __name__ == '__main__': print("Full kpoint_rhf test") #unittest.main() if 1: kmf = make_rand_kmf() rand_cc = pbcc.KRCCSD(kmf) rand_cc.direct = True rand_cc._scf.with_df = pbc_df.GDF(kmf.cell, kmf.kpts) eris3 = pbcc.kccsd_rhf._ERIS(rand_cc, rand_kmf.mo_coeff, method='outcore') print( lib.fp(eris3.oooo) - (0.13807643618081983 + 0.02706881005926997j)) print( lib.fp(eris3.ooov) - (0.11503403213521873 - 0.04088028212967049j)) print( lib.fp(eris3.oovv) - (-0.23166000424452704 + 0.01922808953198968j)) print(lib.fp(eris3.ovov) - (-0.4333329222923895 - 0.2542273009739961j)) print( lib.fp(eris3.voov) - (-0.3851423191571177 + 0.26086853075652333j)) print( lib.fp(eris3.vovv) - (-0.12653400070346893 + 0.17634730801555784j)) print(
cell = gto.Cell() cell.build(unit='B', a=[[0., 6.74027466, 6.74027466], [6.74027466, 0., 6.74027466], [6.74027466, 6.74027466, 0.]], atom='''H 0 0 0 H 1.68506866 1.68506866 1.68506866 H 3.37013733 3.37013733 3.37013733''', basis='gth-dzvp', pseudo='gth-pade', verbose=5, charge=0, spin=1) cell.spin = cell.spin * 3 kpts = cell.make_kpts([3, 1, 1], scaled_center=[0, 0, 0]) gdf = df.GDF(cell, kpts) gdf_fname = 'h3_ints_311.h5' gdf._cderi_to_save = gdf_fname if not os.path.isfile(gdf_fname): gdf.build() chkfname = 'h_311.chk' if os.path.isfile(chkfname): kmf = scf.KUHF(cell, kpts, exxdiv=None) kmf.with_df = gdf kmf.with_df._cderi = gdf_fname data = chkfile.load(chkfname, 'scf') kmf.__dict__.update(data) else: kmf = scf.KUHF(cell, kpts, exxdiv=None) kmf.with_df = gdf
cell.atom=''' H 0.000000000000 0.000000000000 0.000000000000 H 1.685068664391 1.685068664391 1.685068664391 ''' cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.a = ''' 0.000000000, 3.370137329, 3.370137329 3.370137329, 0.000000000, 3.370137329 3.370137329, 3.370137329, 0.000000000''' cell.unit = 'B' cell.verbose = 5 cell.build() kpts = cell.make_kpts([1,1,3]) mydf = GDF(cell, kpts) mydf.mesh = [5,5,5] mydf.build() mydf.dump_to_file('erimpi.int') if rank==0: mf = scf.KRHF(cell, kpts) mf.with_df = mydf # USING ERI FILE from MPIGDF for SCF mf.kernel() mf= scf.KRHF(cell,kpts) mf.with_df = df.GDF(cell,kpts) # USING SERIAL GDF ERI mf.with_df.mesh = [5,5,5] mf.kernel()