def _test_cu_metallic_frozen_vir(self, kmf, cell, nk=[1, 1, 1]): assert cell.mesh == [7, 7, 7] ecc3_bench = -0.94610600274627665 max_cycle = 2 # The following calculation at full convergence gives -0.58688462599474 # for a cell.mesh = [25, 25, 25]. It is equivalent to a supercell [1, 1, 2] # calculation with frozen = [0, 3, 35]. mycc = pbcc.KGCCSD(kmf, frozen=[[2, 3, 34, 35], [0, 1]]) mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 eris = mycc.ao2mo() eris.mo_energy = [f.diagonal() for f in eris.fock] ecc3, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ecc3, ecc3_bench, 6) check_gamma = False # Turn me on to run the supercell calculation! if check_gamma: from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) kmf = pbcscf.RHF(supcell, exxdiv=None) ehf = kmf.scf() mycc = pbcc.RCCSD(kmf, frozen=[0, 3, 35]) mycc.max_cycle = max_cycle mycc.iterative_damping = 0.05 ecc, t1, t2 = mycc.kernel() print('Gamma energy =', ecc / np.prod(nk)) print('K-point energy =', ecc3)
def test_rccsd_t_non_hf_against_so_frozen(self): '''Tests rccsd_t with gccsd_t with frozen orbitals.''' n = 15 cell = make_test_cell.test_cell_n3([n]*3) #import sys #cell.stdout = sys.stdout #cell.verbose = 7 nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcscf.KRKS(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KGCCSD(khf, frozen=[[],[0,1]]) eris = mycc.ao2mo() ekgcc, t1, t2 = mycc.kernel(eris=eris) ekgcc_t = mycc.ccsd_t(eris=eris) mycc = pbcc.KRCCSD(khf, frozen=[[],[0]]) eris = mycc.ao2mo() ekrcc, t1, t2 = mycc.kernel(eris=eris) ekrcc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ekrcc_t, -0.0008839412571610861, 6) self.assertAlmostEqual(ekrcc_t, ekgcc_t, 6)
def test_rand_ccsd_frozen1(self): '''Single (eom-)ccsd iteration with random t1/t2 and single frozen occupied orbital.''' kmf = pbcscf.addons.convert_to_ghf(rand_kmf) # Round to make this insensitive to small changes between PySCF versions mat_veff = kmf.get_veff().round(4) mat_hcore = kmf.get_hcore().round(4) kmf.get_veff = lambda *x: mat_veff kmf.get_hcore = lambda *x: mat_hcore frozen = [[ 0, ], [], []] rand_cc = pbcc.KGCCSD(kmf, frozen=frozen) eris = rand_cc.ao2mo(rand_cc.mo_coeff) eris.mo_energy = [ eris.fock[k].diagonal() for k in range(rand_cc.nkpts) ] t1, t2 = rand_t1_t2(kmf, rand_cc) # Manually zero'ing out the frozen elements of the t1/t2 # N.B. the 0'th element frozen means we are freezing the 1'th # element in the current padding scheme t1[0, 1] = 0.0 t2[0, :, :, 1, :] = 0.0 t2[:, 0, :, :, 1] = 0.0 Ht1, Ht2 = rand_cc.update_amps(t1, t2, eris) self.assertAlmostEqual(finger(Ht1), (-15.7950827762 + 31.0483053388j), 6) self.assertAlmostEqual(finger(Ht2), (263.884192539 + 96.7615664563j), 6)
def test_rand_ccsd_frozen3(self): '''Single (eom-)ccsd iteration with random t1/t2 and single frozen virtual orbital.''' kconserv = kpts_helper.get_kconserv(rand_kmf.cell, rand_kmf.kpts) kmf = pbcscf.addons.convert_to_ghf(rand_kmf) # Round to make this insensitive to small changes between PySCF versions mat_veff = kmf.get_veff().round(4) mat_hcore = kmf.get_hcore().round(4) kmf.get_veff = lambda *x: mat_veff kmf.get_hcore = lambda *x: mat_hcore frozen = [[],[],[5]] # freezing one virtual rand_cc = pbcc.KGCCSD(kmf, frozen=frozen) eris = rand_cc.ao2mo(rand_cc.mo_coeff) eris.mo_energy = [eris.fock[k].diagonal() for k in range(rand_cc.nkpts)] t1, t2 = rand_t1_t2(kmf, rand_cc) # Manually zero'ing out the frozen elements of the t1/t2 t1[2, :, 0] = 0.0 for ki in range(rand_cc.nkpts): for kj in range(rand_cc.nkpts): for ka in range(rand_cc.nkpts): kb = kconserv[ki, ka, kj] if ka == 2: t2[ki, kj, ka, :, :, 0] = 0.0 if kb == 2: t2[ki, kj, ka, :, :, :, 0] = 0.0 Ht1, Ht2 = rand_cc.update_amps(t1, t2, eris) self.assertAlmostEqual(finger(Ht1), (-19.6637196882-16.2773841431j), 6) self.assertAlmostEqual(finger(Ht2), (881.655146297+1283.71020059j), 6)
def test_rccsd_t_non_hf_against_so(self): '''Tests restricted ccsd and ccsd_t for non Hartree-Fock references against the general spin-orbital implementation.''' n = 7 cell = make_test_cell.test_cell_n3([n] * 3) #import sys #cell.stdout = sys.stdout #cell.verbose = 7 nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcscf.KRKS(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KGCCSD(khf, frozen=0) eris = mycc.ao2mo() ekgcc, t1, t2 = mycc.kernel(eris=eris) ekgcc_t = mycc.ccsd_t(eris=eris) mycc = pbcc.KRCCSD(khf, frozen=0) eris = mycc.ao2mo() ekrcc, t1, t2 = mycc.kernel(eris=eris) ekrcc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ekrcc_t, -0.0021709465899365336, 6) self.assertAlmostEqual(ekrcc_t, ekgcc_t, 6)
def test_rand_ccsd_frozen2(self): '''Single (eom-)ccsd iteration with random t1/t2 and full occupied frozen at a single k-point.''' kmf = pbcscf.addons.convert_to_ghf(rand_kmf) # Round to make this insensitive to small changes between PySCF versions mat_veff = kmf.get_veff().round(4) mat_hcore = kmf.get_hcore().round(4) kmf.get_veff = lambda *x: mat_veff kmf.get_hcore = lambda *x: mat_hcore frozen = [[],[0,1,2,3],[]] rand_cc = pbcc.KGCCSD(kmf, frozen=frozen) eris = rand_cc.ao2mo(rand_cc.mo_coeff) eris.mo_energy = [eris.fock[k].diagonal() for k in range(rand_cc.nkpts)] t1, t2 = rand_t1_t2(kmf, rand_cc) # Manually zero'ing out the frozen elements of the t1/t2 # N.B. the 0'th element frozen means we are freezing the 1'th # element in the current padding scheme t1[1, [0,1,2,3]] = 0.0 t2[1, :, :, [0,1,2,3], :] = 0.0 t2[:, 1, :, :, [0,1,2,3]] = 0.0 Ht1, Ht2 = rand_cc.update_amps(t1, t2, eris) self.assertAlmostEqual(finger(Ht1), (-19.2772171332-10.5977304455j), 6) self.assertAlmostEqual(finger(Ht2), (227.434582141+298.826965082j), 6)
def test_rccsd_t_vs_gccsd_t(self): '''Test rccsd(t) vs gccsd(t) with k-points.''' from pyscf.pbc.scf.addons import convert_to_ghf kmf = copy.copy(rand_kmf) mat_veff = kmf.get_veff().round(4) mat_hcore = kmf.get_hcore().round(4) kmf.get_veff = lambda *x: mat_veff kmf.get_hcore = lambda *x: mat_hcore rand_cc = pbcc.KRCCSD(kmf) eris = rand_cc.ao2mo(kmf.mo_coeff) eris.mo_energy = [eris.fock[k].diagonal().real for k in range(rand_cc.nkpts)] t1, t2 = rand_t1_t2(kmf, rand_cc) rand_cc.t1, rand_cc.t2, rand_cc.eris = t1, t2, eris energy_t = kccsd_t_rhf.kernel(rand_cc, eris=eris) gkmf = convert_to_ghf(rand_kmf) # Round to make this insensitive to small changes between PySCF versions mat_veff = gkmf.get_veff().round(4) mat_hcore = gkmf.get_hcore().round(4) gkmf.get_veff = lambda *x: mat_veff gkmf.get_hcore = lambda *x: mat_hcore from pyscf.pbc.cc import kccsd_t rand_gcc = pbcc.KGCCSD(gkmf) eris = rand_gcc.ao2mo(rand_gcc.mo_coeff) eris.mo_energy = [eris.fock[k].diagonal().real for k in range(rand_cc.nkpts)] gt1 = rand_gcc.spatial2spin(t1) gt2 = rand_gcc.spatial2spin(t2) rand_gcc.t1, rand_gcc.t2, rand_gcc.eris = gt1, gt2, eris genergy_t = kccsd_t.kernel(rand_gcc, eris=eris) self.assertAlmostEqual(energy_t, -65.5365125645066, 6) self.assertAlmostEqual(energy_t, genergy_t, 8)
def test_rccsd_t_hf_against_so(self): '''Tests restricted ccsd and ccsd_t for Hartree-Fock references against the general spin-orbital implementation.''' n = 15 cell = make_test_cell.test_cell_n3([n]*3) #import sys #cell.stdout = sys.stdout #cell.verbose = 7 nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcscf.KRHF(cell, kpts=kpts) ekks = kks.kernel() self.assertAlmostEqual(ekks, -10.530978858287662, 8) khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KGCCSD(khf, frozen=None) eris = mycc.ao2mo() ekgcc, t1, t2 = mycc.kernel(eris=eris) ekgcc_t = mycc.ccsd_t(eris=eris) mycc = pbcc.KRCCSD(khf, frozen=None) eris = mycc.ao2mo() ekrcc, t1, t2 = mycc.kernel(eris=eris) ekrcc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ekrcc_t, -0.0011112985234012498, 6) self.assertAlmostEqual(ekrcc_t, ekgcc_t, 6)
def test_t3p2_imds_complex_against_so(self): '''Test t3[2] implementation against spin-orbital implmentation.''' from pyscf.pbc.scf.addons import convert_to_ghf kmf = copy.copy(rand_kmf2) # Round to make this insensitive to small changes between PySCF versions mat_veff = kmf.get_veff().round(4) mat_hcore = kmf.get_hcore().round(4) kmf.get_veff = lambda *x: mat_veff kmf.get_hcore = lambda *x: mat_hcore rand_cc = pbcc.kccsd_rhf.RCCSD(kmf) eris = rand_cc.ao2mo(kmf.mo_coeff) eris.mo_energy = [ eris.fock[k].diagonal() for k in range(rand_cc.nkpts) ] t1, t2 = rand_t1_t2(kmf, rand_cc) rand_cc.t1, rand_cc.t2, rand_cc.eris = t1, t2, eris e, pt1, pt2, Wmcik, Wacek = kintermediates_rhf.get_t3p2_imds( rand_cc, t1, t2) self.assertAlmostEqual(lib.finger(e), 3867.812511518491, 6) self.assertAlmostEqual(lib.finger(pt1), (179.0050003787795 + 521.7529255474592j), 6) self.assertAlmostEqual(lib.finger(pt2), (361.4902731606503 + 1079.5387279755082j), 6) self.assertAlmostEqual(lib.finger(Wmcik), (34.9811459194098 - 86.93467379996585j), 6) self.assertAlmostEqual(lib.finger(Wacek), (183.86684834783233 + 179.66583663669644j), 6) gkmf = convert_to_ghf(rand_kmf2) # Round to make this insensitive to small changes between PySCF versions mat_veff = gkmf.get_veff().round(4) mat_hcore = gkmf.get_hcore().round(4) gkmf.get_veff = lambda *x: mat_veff gkmf.get_hcore = lambda *x: mat_hcore rand_gcc = pbcc.KGCCSD(gkmf) eris = rand_gcc.ao2mo(rand_gcc.mo_coeff) eris.mo_energy = [ eris.fock[k].diagonal() for k in range(rand_gcc.nkpts) ] gt1 = rand_gcc.spatial2spin(t1) gt2 = rand_gcc.spatial2spin(t2) rand_gcc.t1, rand_gcc.t2, rand_gcc.eris = gt1, gt2, eris ge, gpt1, gpt2, gWmcik, gWacek = kintermediates.get_t3p2_imds_slow( rand_gcc, gt1, gt2) self.assertAlmostEqual(lib.finger(ge), lib.finger(e), 8) self.assertAlmostEqual(lib.finger(gpt1[:, ::2, ::2]), lib.finger(pt1), 8) self.assertAlmostEqual(lib.finger(gpt2[:, :, :, ::2, 1::2, ::2, 1::2]), lib.finger(pt2), 8) self.assertAlmostEqual( lib.finger(gWmcik[:, :, :, ::2, 1::2, ::2, 1::2]), lib.finger(Wmcik), 8) self.assertAlmostEqual( lib.finger(gWacek[:, :, :, ::2, 1::2, ::2, 1::2]), lib.finger(Wacek), 8)
def test_t3p2_imds_complex_against_so_frozen(self): '''Test t3[2] implementation against spin-orbital implmentation with frozen orbitals.''' from pyscf.pbc.scf.addons import convert_to_ghf kmf = copy.copy(rand_kmf2) # Round to make this insensitive to small changes between PySCF versions mat_veff = kmf.get_veff().round(4) mat_hcore = kmf.get_hcore().round(4) kmf.get_veff = lambda *x: mat_veff kmf.get_hcore = lambda *x: mat_hcore rand_cc = pbcc.kccsd_rhf.RCCSD(kmf, frozen=1) eris = rand_cc.ao2mo(kmf.mo_coeff) eris.mo_energy = [ eris.fock[k].diagonal() for k in range(rand_cc.nkpts) ] t1, t2 = rand_t1_t2(kmf, rand_cc) rand_cc.t1, rand_cc.t2, rand_cc.eris = t1, t2, eris e, pt1, pt2, Wmcik, Wacek = kintermediates_rhf.get_t3p2_imds( rand_cc, t1, t2) self.assertAlmostEqual(lib.finger(e), -328.44609187669454, 6) self.assertAlmostEqual(lib.finger(pt1), (-64.29455737653288 + 94.36604246905883j), 6) self.assertAlmostEqual(lib.finger(pt2), (-24.663592135920723 + 36.00181963359046j), 6) self.assertAlmostEqual(lib.finger(Wmcik), (6.692675632408793 + 6.926864923969868j), 6) self.assertAlmostEqual(lib.finger(Wacek), (24.78958393361647 - 15.627512899715132j), 6) gkmf = convert_to_ghf(rand_kmf2) # Round to make this insensitive to small changes between PySCF versions mat_veff = gkmf.get_veff().round(4) mat_hcore = gkmf.get_hcore().round(4) gkmf.get_veff = lambda *x: mat_veff gkmf.get_hcore = lambda *x: mat_hcore rand_gcc = pbcc.KGCCSD(gkmf, frozen=2) eris = rand_gcc.ao2mo(rand_gcc.mo_coeff) eris.mo_energy = [ eris.fock[k].diagonal() for k in range(rand_gcc.nkpts) ] gt1 = rand_gcc.spatial2spin(t1) gt2 = rand_gcc.spatial2spin(t2) rand_gcc.t1, rand_gcc.t2, rand_gcc.eris = gt1, gt2, eris ge, gpt1, gpt2, gWmcik, gWacek = kintermediates.get_t3p2_imds_slow( rand_gcc, gt1, gt2) self.assertAlmostEqual(lib.finger(ge), lib.finger(e), 8) self.assertAlmostEqual(lib.finger(gpt1[:, ::2, ::2]), lib.finger(pt1), 8) self.assertAlmostEqual(lib.finger(gpt2[:, :, :, ::2, 1::2, ::2, 1::2]), lib.finger(pt2), 8) self.assertAlmostEqual( lib.finger(gWmcik[:, :, :, ::2, 1::2, ::2, 1::2]), lib.finger(Wmcik), 8) self.assertAlmostEqual( lib.finger(gWacek[:, :, :, ::2, 1::2, ::2, 1::2]), lib.finger(Wacek), 8)
def test_dmd_high_cost(self): cell = gto.Cell() cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.685068664391 1.685068664391 1.685068664391 ''' cell.basis = {'C': [[0, (0.8, 1.0)], [1, (1.0, 1.0)]]} 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() nmp = [1, 1, 2] # treating 1*1*2 supercell at gamma point supcell = super_cell(cell, nmp) gmf = scf.GHF(supcell, exxdiv=None) ehf = gmf.kernel() gcc = cc.GCCSD(gmf) gcc.conv_tol = 1e-12 gcc.conv_tol_normt = 1e-10 gcc.max_cycle = 250 ecc, t1, t2 = gcc.kernel() print('GHF energy (supercell) %.7f \n' % (float(ehf) / 2.)) print('GCCSD correlation energy (supercell) %.7f \n' % (float(ecc) / 2.)) eom = eom_gccsd.EOMIP(gcc) e1, v = eom.ipccsd(nroots=2) eom = eom_gccsd.EOMEA(gcc) e2, v = eom.eaccsd(nroots=2, koopmans=True) # Running HF and CCSD with 1x1x2 Monkhorst-Pack k-point mesh kmf = scf.KGHF(cell, kpts=cell.make_kpts(nmp), exxdiv=None) ehf2 = kmf.kernel() mycc = cc.KGCCSD(kmf) mycc.conv_tol = 1e-12 mycc.conv_tol_normt = 1e-10 mycc.max_cycle = 250 ecc2, t1, t2 = mycc.kernel() print('GHF energy %.7f \n' % (float(ehf2))) print('GCCSD correlation energy %.7f \n' % (float(ecc2))) kptlist = cell.make_kpts(nmp) eom = EOMIP(mycc) e1_obt, v = eom.ipccsd(nroots=2, kptlist=[0]) eom = EOMEA(mycc) e2_obt, v = eom.eaccsd(nroots=2, koopmans=True, kptlist=[0]) assert (ehf / 2 - ehf2 < 1e-10) assert (ecc / 2 - ecc2 < 1e-10) assert (e1[0] - (e1_obt[0][0]) < 1e-7) assert (e2[0] - (e2_obt[0][0]) < 1e-7)
def test_n3_diffuse_Ta_against_so(self): ehf_bench = -6.1870676561720721 ecc_bench = -0.06764836939412185 cc = pbcc.kccsd_rhf.RCCSD(kmf) cc.conv_tol = 1e-10 eris = cc.ao2mo() eris.mo_energy = [ eris.fock[ikpt].diagonal() for ikpt in range(cc.nkpts) ] ecc, t1, t2 = cc.kernel(eris=eris) ehf = kmf.e_tot self.assertAlmostEqual(ehf, ehf_bench, 6) self.assertAlmostEqual(ecc, ecc_bench, 6) eom = EOMEA_Ta(cc) eea_rccsd = eom.eaccsd_star(nroots=1, koopmans=True, kptlist=(0, ), eris=eris) eom = EOMIP_Ta(cc) eip_rccsd = eom.ipccsd_star(nroots=1, koopmans=True, kptlist=(0, ), eris=eris) self.assertAlmostEqual(eea_rccsd[0][0], 1.2610123166324307, 6) self.assertAlmostEqual(eip_rccsd[0][0], -1.1435100754903331, 6) from pyscf.pbc.cc import kccsd cc = pbcc.KGCCSD(kmf) cc.conv_tol = 1e-10 eris = cc.ao2mo() eris.mo_energy = [ eris.fock[ikpt].diagonal() for ikpt in range(cc.nkpts) ] ecc, t1, t2 = cc.kernel(eris=eris) ehf = kmf.e_tot self.assertAlmostEqual(ehf, ehf_bench, 6) self.assertAlmostEqual(ecc, ecc_bench, 6) from pyscf.pbc.cc import eom_kccsd_ghf eom = eom_kccsd_ghf.EOMEA_Ta(cc) eea_gccsd = eom.eaccsd_star(nroots=1, koopmans=True, kptlist=(0, ), eris=eris) eom = eom_kccsd_ghf.EOMIP_Ta(cc) eip_gccsd = eom.ipccsd_star(nroots=1, koopmans=True, kptlist=(0, ), eris=eris) self.assertAlmostEqual(eea_gccsd[0][0], 1.2610123166324307, 6) self.assertAlmostEqual(eip_gccsd[0][0], -1.1435100754903331, 6) # Usually slightly higher agreement when comparing directly against one another self.assertAlmostEqual(eea_gccsd[0][0], eea_rccsd[0][0], 9) self.assertAlmostEqual(eip_gccsd[0][0], eip_rccsd[0][0], 9)
def test_rand_ccsd_frozen0(self): '''Single (eom-)ccsd iteration with random t1/t2 and lowest lying orbital at multiple k-points frozen.''' kmf = pbcscf.addons.convert_to_ghf(rand_kmf) # Round to make this insensitive to small changes between PySCF versions mat_veff = kmf.get_veff().round(4) mat_hcore = kmf.get_hcore().round(4) kmf.get_veff = lambda *x: mat_veff kmf.get_hcore = lambda *x: mat_hcore # frozen = 1 rand_cc = pbcc.KGCCSD(kmf, frozen=1) eris = rand_cc.ao2mo(rand_cc.mo_coeff) eris.mo_energy = [ eris.fock[k].diagonal() for k in range(rand_cc.nkpts) ] t1, t2 = rand_t1_t2(kmf, rand_cc) Ht1, Ht2 = rand_cc.update_amps(t1, t2, eris) self.assertAlmostEqual(finger(Ht1), (12.6235870016 - 0.263432509044j), 6) self.assertAlmostEqual(finger(Ht2), (94.8802678168 + 910.369938369j), 6) # frozen = [[0,],[0,],[0,]], should be same as above frozen = [[ 0, ], [ 0, ], [ 0, ]] rand_cc = pbcc.KGCCSD(kmf, frozen=frozen) eris = rand_cc.ao2mo(rand_cc.mo_coeff) eris.mo_energy = [ eris.fock[k].diagonal() for k in range(rand_cc.nkpts) ] t1, t2 = rand_t1_t2(rand_kmf, rand_cc) Ht1, Ht2 = rand_cc.update_amps(t1, t2, eris) self.assertAlmostEqual(finger(Ht1), (12.6235870016 - 0.263432509044j), 6) self.assertAlmostEqual(finger(Ht2), (94.8802678168 + 910.369938369j), 6)
def test_supercell_vs_kpt(self): # Running HF and CCSD with 1x1x2 Monkhorst-Pack k-point mesh kmf = pbcscf.KGHF(cell, kpts=cell.make_kpts(nmp), exxdiv=None) kmf.kernel() mycc = pbcc.KGCCSD(kmf) mycc.conv_tol = 1e-12 mycc.conv_tol_normt = 1e-10 ecc2, t1, t2 = mycc.kernel() ecc_ref = -0.01044680113334205 print(ecc2) self.assertAlmostEqual(abs(ecc_ref - ecc2), 0, 10)
def _test_cu_metallic_nonequal_occ(self, kmf, cell, nk=[1, 1, 1]): assert cell.mesh == [7, 7, 7] ecc1_bench = -1.1633910051553982 max_cycle = 2 # Too expensive to do more! # The following calculation at full convergence gives -0.711071910294612 # for a cell.mesh = [25, 25, 25]. mycc = pbcc.KGCCSD(kmf, frozen=0) mycc.diis_start_cycle = 1 mycc.iterative_damping = 0.04 mycc.max_cycle = max_cycle ecc1, t1, t2 = mycc.kernel() self.assertAlmostEqual(ecc1, ecc1_bench, 6)
def test_ccsd_t_high_cost(self): n = 14 cell = make_test_cell.test_cell_n3([n] * 3) kpts = cell.make_kpts([1, 1, 2]) kpts -= kpts[0] kmf = pbcscf.KRHF(cell, kpts=kpts, exxdiv=None) ehf = kmf.kernel() mycc = pbcc.KGCCSD(kmf) ecc, t1, t2 = mycc.kernel() energy_t = kccsd_t.kernel(mycc) energy_t_bench = -0.00191440345386 self.assertAlmostEqual(energy_t, energy_t_bench, 6)
def _test_cu_metallic_frozen_occ(self, kmf, cell, nk=[1, 1, 1]): assert cell.mesh == [7, 7, 7] ecc2_bench = -1.0430822430909346 max_cycle = 2 # The following calculation at full convergence gives -0.6440448716452378 # for a cell.mesh = [25, 25, 25]. It is equivalent to a supercell [1, 1, 2] # calculation with frozen = [0, 3]. mycc = pbcc.KGCCSD(kmf, frozen=[[2, 3], [0, 1]]) mycc.diis_start_cycle = 1 mycc.iterative_damping = 0.04 mycc.max_cycle = max_cycle ecc2, t1, t2 = mycc.kernel() self.assertAlmostEqual(ecc2, ecc2_bench, 6)
def test_ccsd_t_high_cost(self): n = 14 cell = make_test_cell.test_cell_n3([n] * 3) kpts = cell.make_kpts([1, 1, 2]) kpts -= kpts[0] kmf = pbcscf.KRHF(cell, kpts=kpts, exxdiv=None) ehf = kmf.kernel() mycc = pbcc.KGCCSD(kmf) eris = mycc.ao2mo() ecc, t1, t2 = mycc.kernel(eris=eris) eris.mo_energy = [eris.fock[i].diagonal() for i in range(len(kpts))] energy_t = kccsd_t.kernel(mycc, eris=eris) energy_t_bench = -0.00191440345386 self.assertAlmostEqual(energy_t, energy_t_bench, 6)
def setUpModule(): global cell, kmf, mycc, eris cell = make_test_cell.test_cell_n3_diffuse() kmf = scf.KRHF(cell, kpts=cell.make_kpts([1, 1, 2], with_gamma_point=True), exxdiv=None) kmf.conv_tol = 1e-10 kmf.conv_tol_grad = 1e-6 kmf.scf() mycc = cc.KGCCSD(kmf) mycc.conv_tol = 1e-7 mycc.conv_tol_normt = 1e-7 mycc.run() eris = mycc.ao2mo() eris.mo_energy = [ eris.fock[ikpt].diagonal().real for ikpt in range(mycc.nkpts) ]
def test_n3_diffuse_frozen(self): ehf2 = kmf.e_tot self.assertAlmostEqual(ehf2, -6.1870676561725695, 6) mycc_frozen = cc.KGCCSD(kmf, frozen=[[0, 1], [0, 1, 2, 3]]) mycc_frozen.conv_tol = 1e-7 mycc_frozen.conv_tol_normt = 1e-7 eris = mycc_frozen.ao2mo() eris.mo_energy = [ eris.fock[ikpt].diagonal().real for ikpt in range(mycc_frozen.nkpts) ] ecc2, t1, t2 = mycc_frozen.kernel(eris=eris) self.assertAlmostEqual(ecc2, -0.0442506265840587, 6) eom = EOMIP(mycc_frozen) imds = eom.make_imds(eris=eris) e1_obt, v = eom.ipccsd(nroots=3, koopmans=False, kptlist=[0], imds=imds) self.assertAlmostEqual(e1_obt[0][0], -1.1316152294295743, 6) self.assertAlmostEqual(e1_obt[0][1], -1.1316152294295743, 6) self.assertAlmostEqual(e1_obt[0][2], -1.104163717600433, 6) e1_obt, v = eom.ipccsd(nroots=3, koopmans=True, kptlist=[1], imds=imds) self.assertAlmostEqual(e1_obt[0][0], -0.8983145129187627, 6) self.assertAlmostEqual(e1_obt[0][1], -0.8983145129187627, 6) self.assertAlmostEqual(e1_obt[0][2], -0.8983139520017552, 6) eom = EOMEA(mycc_frozen) imds = eom.make_imds(eris=eris) e2_obt, v = eom.eaccsd(nroots=3, kptlist=[0], imds=imds) self.assertAlmostEqual(e2_obt[0][0], 1.2572812499753756, 6) self.assertAlmostEqual(e2_obt[0][1], 1.2572812532456588, 6) self.assertAlmostEqual(e2_obt[0][2], 1.280747357928012, 6) eom = EOMEA(mycc_frozen) e2_obt, v = eom.eaccsd(nroots=3, koopmans=True, kptlist=[1], imds=imds) self.assertAlmostEqual(e2_obt[0][0], 1.229802629928757, 6) self.assertAlmostEqual(e2_obt[0][1], 1.229802629928764, 6) self.assertAlmostEqual(e2_obt[0][2], 1.384394578043613, 6)
def test_rand_ccsd(self): '''Single (eom-)ccsd iteration with random t1/t2.''' kmf = pbcscf.addons.convert_to_ghf(rand_kmf) # Round to make this insensitive to small changes between PySCF versions mat_veff = kmf.get_veff().round(4) mat_hcore = kmf.get_hcore().round(4) kmf.get_veff = lambda *x: mat_veff kmf.get_hcore = lambda *x: mat_hcore rand_cc = pbcc.KGCCSD(kmf) eris = rand_cc.ao2mo(rand_cc.mo_coeff) eris.mo_energy = [eris.fock[k].diagonal() for k in range(rand_cc.nkpts)] t1, t2 = rand_t1_t2(kmf, rand_cc) Ht1, Ht2 = rand_cc.update_amps(t1, t2, eris) self.assertAlmostEqual(finger(Ht1), (-10.5746290133+4.22371219606j), 6) self.assertAlmostEqual(finger(Ht2), (-250.696532783+706.190346877j), 6) # Excited state results rand_cc.t1, rand_cc.t2, rand_cc.eris = t1, t2, eris
from pyscf.pbc.tools.pbc import super_cell from pyscf.pbc import gto, scf, cc from pyscf.pbc.cc.eom_kccsd_ghf import EOMIP, EOMEA, EOMEE from pyscf.pbc.cc.eom_kccsd_ghf import EOMIP_Ta, EOMEA_Ta from pyscf.cc import eom_gccsd import unittest cell = make_test_cell.test_cell_n3_diffuse() kmf = scf.KRHF(cell, kpts=cell.make_kpts([1, 1, 2], with_gamma_point=True), exxdiv=None) kmf.conv_tol = 1e-10 kmf.conv_tol_grad = 1e-6 kmf.scf() mycc = cc.KGCCSD(kmf) mycc.conv_tol = 1e-7 mycc.conv_tol_normt = 1e-7 mycc.run() eris = mycc.ao2mo() eris.mo_energy = [eris.fock[ikpt].diagonal() for ikpt in range(mycc.nkpts)] def tearDownModule(): global cell, kmf, mycc, eris cell.stdout.close() del cell, kmf, mycc, eris class KnownValues(unittest.TestCase): def test_n3_diffuse(self):
def test_h4_fcc_k2_frozen(self): '''Metallic hydrogen fcc lattice with frozen lowest lying occupied and highest lying virtual orbitals. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1., 0., 0.], [0., 1., 0], [0, 0, 2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [ [0, [1.0, 1]], ] cell.pseudo = 'gth-pade' cell.output = '/dev/null' cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple( np.dot(np.array(cell.atom[i][1]), np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0, 0.0, 0.0]) e = kmf.kernel() #mymp = pbmp.KMP2(kmf) #ekmp2, _ = mymp.kernel() #print("KMP2 corr energy (per unit cell) = ", ekmp2) # By not applying a level-shift, one gets a different initial CCSD answer. # One can check however that the t1/t2 from level-shifting are a solution # of the CCSD equations done without level-shifting. frozen = [[0, 1, 6, 7], []] mycc = pbcc.KGCCSD(kmf, frozen=frozen) ekccsd, t1, t2 = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.04683399814247455, 6) # TODO: fill in as the eom-kgccsd completed... # ## Getting more roots than 1 is difficult #e = mycc.eaccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, 5.060562738181741, 6) #e = mycc.eaccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, 4.188511644938458, 6) #e = mycc.ipccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, -3.477663551987023, 6) #e = mycc.ipccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, -4.23523412155825, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() #mysmp = pbmp.KMP2(mf) #emp2, _ = mysmp.kernel() #print("MP2 corr energy (per unit cell) = ", emp2 / np.prod(nmp)) myscc = pbcc.KGCCSD(mf, frozen=[0, 1, 14, 15]) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.04683401678904569, 6)
def test_h4_fcc_k2(self): '''Metallic hydrogen fcc lattice. Checks versus a corresponding supercell calculation. NOTE: different versions of the davidson may converge to a different solution for the k-point IP/EA eom. If you're getting the wrong root, check to see if it's contained in the supercell set of eigenvalues.''' cell = pbcgto.Cell() cell.atom = [['H', (0.000000000, 0.000000000, 0.000000000)], ['H', (0.000000000, 0.500000000, 0.250000000)], ['H', (0.500000000, 0.500000000, 0.500000000)], ['H', (0.500000000, 0.000000000, 0.750000000)]] cell.unit = 'Bohr' cell.a = [[1., 0., 0.], [0., 1., 0], [0, 0, 2.2]] cell.verbose = 7 cell.spin = 0 cell.charge = 0 cell.basis = [ [0, [1.0, 1]], ] cell.pseudo = 'gth-pade' cell.output = '/dev/null' cell.max_memory = 1000 for i in range(len(cell.atom)): cell.atom[i][1] = tuple( np.dot(np.array(cell.atom[i][1]), np.array(cell.a))) cell.build() nmp = [2, 1, 1] kmf = pbcscf.KRHF(cell) kmf.kpts = cell.make_kpts(nmp, scaled_center=[0.0, 0.0, 0.0]) e = kmf.kernel() #mymp = pbmp.KMP2(kmf) #ekmp2, _ = mymp.kernel() #print("KMP2 corr energy (per unit cell) = ", ekmp2) mycc = pbcc.KGCCSD(kmf) ekccsd, t1, t2 = mycc.kernel() self.assertAlmostEqual(ekccsd, -0.06146759560406628, 6) # TODO: fill in as the eom-kgccsd completed... # ## Getting more roots than 1 is difficult #e = mycc.eaccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, 5.079427283440857, 6) #e = mycc.eaccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, 4.183328878177331, 6) #e = mycc.ipccsd(nroots=1, kptlist=(0,))[0] #self.assertAlmostEqual(e, -3.471710821544506, 6) #e = mycc.ipccsd(nroots=1, kptlist=(1,))[0] #self.assertAlmostEqual(e, -4.272015727359054, 6) # Start of supercell calculations from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nmp) supcell.build() mf = pbcscf.KRHF(supcell) e = mf.kernel() ##mysmp = pbmp.KMP2(mf) ##emp2, _ = mysmp.kernel() ##print("MP2 corr energy (per unit cell) = ", emp2 / np.prod(nmp)) myscc = pbcc.KGCCSD(mf) eccsd, _, _ = myscc.kernel() eccsd /= np.prod(nmp) self.assertAlmostEqual(eccsd, -0.06146759560406628, 6)