def test_rand_ccsd_frozen0(self): '''Single (eom-)ccsd iteration with random t1/t2 and lowest lying orbital at multiple k-points frozen.''' rand_cc = pbcc.KRCCSD(rand_kmf, frozen=1) eris = rand_cc.ao2mo(rand_kmf.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), (-8.06918006043+8.2779236131j), 6) self.assertAlmostEqual(finger(Ht2), (30.6692903818-14.2701276046j), 6) frozen = [[0,],[0,],[0,]] rand_cc = pbcc.KRCCSD(rand_kmf, frozen=frozen) eris = rand_cc.ao2mo(rand_kmf.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), (-8.06918006043+8.2779236131j), 6) self.assertAlmostEqual(finger(Ht2), (30.6692903818-14.2701276046j), 6) # Excited state results rand_cc.t1, rand_cc.t2, rand_cc.eris = t1, t2, eris kshift = 0 r1, r2 = rand_r1_r2_ip(rand_kmf, rand_cc) Hr1, Hr2 = _run_ip_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(finger(Hr1), (0.289384011655-0.394002590665j), 6) self.assertAlmostEqual(finger(Hr2), (0.056437476036+0.156522915807j), 6) r1, r2 = rand_r1_r2_ea(rand_kmf, rand_cc) Hr1, Hr2 = _run_ea_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(finger(Hr1), (0.298028415374+0.0944020804565j), 6) self.assertAlmostEqual(finger(Hr2), (-0.243561845158+0.869173612894j), 6)
def test_n3_ee(self): n = 15 cell_n3 = make_test_cell.test_cell_n3([n] * 3) kmf_n3 = pbcscf.KRHF(cell_n3, cell_n3.make_kpts([2, 1, 1]), exxdiv=None) kmf_n3.kernel() kmf_n3_ewald = pbcscf.KRHF(cell_n3, cell_n3.make_kpts([2, 1, 1]), exxdiv='ewald') kmf_n3_ewald.kernel() ehf_bench = [-8.651923514149, -10.530905169078] ecc_bench = [-0.155298299344, -0.093617975270] ekrhf = kmf_n3.e_tot self.assertAlmostEqual(ekrhf, ehf_bench[0], 3) ekrhf = kmf_n3_ewald.e_tot self.assertAlmostEqual(ekrhf, ehf_bench[1], 3) mycc = pbcc.KRCCSD(kmf_n3) ekrcc, t1, t2 = mycc.kernel() self.assertAlmostEqual(ekrcc, ecc_bench[0], 3) mycc_ewald = pbcc.KRCCSD(kmf_n3_ewald) mycc_ewald.keep_exxdiv = True ekrcc, t1, t2 = mycc_ewald.kernel() self.assertAlmostEqual(ekrcc, ecc_bench[1], 3) # EOM-EE-KRCCSD singlet from pyscf.pbc.cc import eom_kccsd_rhf as eom_krccsd nroots = 2 # number of roots requested myeomee = eom_krccsd.EOMEESinglet(mycc) myeomee.max_space = nroots * 10 eee, vee = myeomee.kernel(nroots=nroots, kptlist=[0]) self.assertAlmostEqual(eee[0][0], 0.267867075425, 3) self.assertAlmostEqual(eee[0][1], 0.268704338187, 3) eee, vee = myeomee.kernel(nroots=nroots, kptlist=[1]) self.assertAlmostEqual(eee[0][0], 0.389795492091, 3) self.assertAlmostEqual(eee[0][1], 0.407782858154, 3) myeomee = eom_krccsd.EOMEESinglet(mycc_ewald) myeomee.max_space = nroots * 10 eee, vee = myeomee.kernel(nroots=nroots, kptlist=[0]) self.assertAlmostEqual(eee[0][0], 0.707047835495, 3) self.assertAlmostEqual(eee[0][1], 0.707047835495, 3) eee, vee = myeomee.kernel(nroots=nroots, kptlist=[1]) self.assertAlmostEqual(eee[0][0], 0.815872164169, 3) self.assertAlmostEqual(eee[0][1], 0.845417271088, 3)
def test_rand_ccsd_frozen3(self): '''Single (eom-)ccsd iteration with random t1/t2 and single frozen virtual orbital.''' 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 kconserv = kpts_helper.get_kconserv(kmf.cell, kmf.kpts) frozen = [[],[],[3]] # freezing one virtual rand_cc = pbcc.KRCCSD(kmf, frozen=frozen) 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) # 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(lib.fp(Ht1), (5.3320153970710118-7.9402122992688602j), 6) self.assertAlmostEqual(lib.fp(Ht2), (-236.46389414847206-360.1605297160217j), 6) # Excited state results rand_cc.t1, rand_cc.t2, rand_cc.eris = t1, t2, eris kshift = 2 r1, r2 = rand_r1_r2_ip(kmf, rand_cc) r1[0] = 0.0 for ki in range(rand_cc.nkpts): for kj in range(rand_cc.nkpts): ka = kconserv[ki, kshift, kj] if ka == 2: r2[ki, kj, :, :, 0] = 0.0 Hr1, Hr2 = _run_ip_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(lib.fp(Hr1), (0.4067595510145880 + 0.0770280877446436j), 6) self.assertAlmostEqual(lib.fp(Hr2), (0.0926714318228812 + -1.0702702421619084j), 6) r1, r2 = rand_r1_r2_ea(kmf, rand_cc) r1[0] = 0.0 for kj in range(rand_cc.nkpts): for ka in range(rand_cc.nkpts): kb = kconserv[kshift, ka, kj] if ka == 2: r2[kj, ka, :, 0, :] = 0.0 if kb == 2: r2[kj, ka, :, :, 0] = 0.0 Hr1, Hr2 = _run_ea_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(lib.fp(Hr1), (0.0070404498167285 + -0.1646809321907418j), 6) self.assertAlmostEqual(lib.fp(Hr2), (0.4518315588945250 + -0.5508323185152750j), 6)
def test_rand_ccsd(self): '''Single (eom-)ccsd iteration with random t1/t2.''' 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() 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 t1, t2 = rand_cc.t1, rand_cc.t2 Ht1, Ht2 = rand_cc.update_amps(t1, t2, eris) self.assertAlmostEqual(lib.fp(Ht1), (-4.6942326686+9.50185397111j), 6) self.assertAlmostEqual(lib.fp(Ht2), (17.1490394799+110.137726574j), 6) # Excited state results kshift = 0 r1, r2 = rand_r1_r2_ip(kmf, rand_cc) Hr1, Hr2 = _run_ip_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(lib.fp(Hr1), (-0.456418558025-0.0485067398162j), 6) self.assertAlmostEqual(lib.fp(Hr2), (0.616016341219+2.08777776589j), 6) r1, r2 = rand_r1_r2_ea(kmf, rand_cc) Hr1, Hr2 = _run_ea_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(lib.fp(Hr1), (-0.234979092885-0.218401823892j), 6) self.assertAlmostEqual(lib.fp(Hr2), (-3.56244154449+2.12051064183j), 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() 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() 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_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=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.0021709465899365336, 6) self.assertAlmostEqual(ekrcc_t, ekgcc_t, 6)
def test_rccsd_t_non_hf_against_so_frozen(self): '''Tests rccsd_t with gccsd_t with frozen orbitals.''' 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, 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.0018712836246782309, 6) self.assertAlmostEqual(ekrcc_t, ekgcc_t, 6)
def setUpClass(cls): cls.cell = gto.Cell() cls.cell.atom = '''Al 0 0 0''' cls.cell.basis = 'gth-szv' cls.cell.pseudo = 'gth-pade' cls.cell.a = ''' 2.47332919 0 1.42797728 0.82444306 2.33187713 1.42797728 0 0 2.85595455 ''' cls.cell.unit = 'angstrom' cls.cell.build() cls.cell.verbose = 4 cls.cell.incore_anyway = True cls.cell.max_memory = 20e3 cls.mf = scf.KRHF(cls.cell, kpts=cls.cell.make_kpts([2, 2, 2], scaled_center=(.1, .2, .3))) cls.mf.chkfile = 'test_kgf_proper_rhf_al2_chk.dat' if os.path.exists(cls.mf.chkfile): cls.mf.update() else: cls.mf.kernel() cls.ccsd = cc.KRCCSD(cls.mf) cls.ccsd.kernel() # TODO: lambda iterations cls.ccsd.l1 = cls.ccsd.t1 cls.ccsd.l2 = cls.ccsd.t2 cls.eip, cls.ip_vecs = cls.ccsd.ipccsd(nroots=2) cls.eea, cls.ea_vecs = cls.ccsd.eaccsd(nroots=2) cls.energies = numpy.linspace(-1, 1.3, 100) cls.eta = 0.04 cls.title = "Al-2" cls.options = ("td",)
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 test_rand_ccsd_frozen1(self): '''Single (eom-)ccsd iteration with random t1/t2 and single frozen occupied orbital.''' 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 frozen = [[ 0, ], [], []] rand_cc = pbcc.KRCCSD(kmf, frozen=frozen) 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) # 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), (-9.31532552971 + 16.3972283898j), 6) self.assertAlmostEqual(finger(Ht2), (-4.42939435314 + 52.147616355j), 6) # Excited state results rand_cc.t1, rand_cc.t2, rand_cc.eris = t1, t2, eris kshift = 0 r1, r2 = rand_r1_r2_ip(kmf, rand_cc) r1[1] = 0.0 r2[0, :, 1] = 0.0 r2[:, 0, :, 1] = 0.0 Hr1, Hr2 = _run_ip_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(finger(Hr1), (-0.558560718395 - 0.344470539404j), 6) self.assertAlmostEqual(finger(Hr2), (0.882960101238 + 0.0752022769822j), 6) r1, r2 = rand_r1_r2_ea(kmf, rand_cc) r2[0, :, 1] = 0.0 Hr1, Hr2 = _run_ea_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(finger(Hr1), (0.010947007472 - 0.287095461151j), 6) self.assertAlmostEqual(finger(Hr2), (-2.58907863831 + 0.685390702884j), 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 = 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 frozen = [[], [0, 1], []] rand_cc = pbcc.KRCCSD(kmf, frozen=frozen) 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) # 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]] = 0.0 t2[1, :, :, [0, 1], :] = 0.0 t2[:, 1, :, :, [0, 1]] = 0.0 Ht1, Ht2 = rand_cc.update_amps(t1, t2, eris) self.assertAlmostEqual(finger(Ht1), (-0.931278705177 + 2.16347477318j), 6) self.assertAlmostEqual(finger(Ht2), (29.0079567454 - 0.114082762172j), 6) # Excited state results rand_cc.t1, rand_cc.t2, rand_cc.eris = t1, t2, eris kshift = 1 r1, r2 = rand_r1_r2_ip(kmf, rand_cc) r1[[0, 1]] = 0.0 r2[1, :, [0, 1]] = 0.0 r2[:, 1, :, [0, 1]] = 0.0 Hr1, Hr2 = _run_ip_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(finger(Hr1), (0.0 + 0.0j), 6) self.assertAlmostEqual(finger(Hr2), (-0.336011745573 - 0.0454220386975j), 6) r1, r2 = rand_r1_r2_ea(kmf, rand_cc) r2[1, :, [0, 1]] = 0.0 Hr1, Hr2 = _run_ea_matvec(rand_cc, r1, r2, kshift) self.assertAlmostEqual(finger(Hr1), (-0.00152035195068 - 0.502318229581j), 6) self.assertAlmostEqual(finger(Hr2), (-1.59488320866 + 0.838903632811j), 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) ehf = kmf.kernel() rand_cc = pbcc.KRCCSD(kmf) ecc, t1, t2 = rand_cc.kernel() energy_t = kccsd_t_rhf.kernel(rand_cc) energy_t_bench = -0.00191443154358 self.assertAlmostEqual(energy_t, energy_t_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) ehf = kmf.kernel() mycc = pbcc.KRCCSD(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_rhf.kernel(mycc, eris=eris) energy_t_bench = -0.00191443154358 self.assertAlmostEqual(energy_t, energy_t_bench, 6)
def test_ccsd_t_non_hf_frozen(self): '''Tests ccsd and ccsd_t for non-Hartree-Fock references with frozen orbitals using supercell vs k-point calculation.''' n = 14 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 = pbcdft.KRKS(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KRCCSD(khf, frozen=1) eris = mycc.ao2mo() ekcc, t1, t2 = mycc.kernel(eris=eris) ekcc_t = mycc.ccsd_t(eris=eris) # Run supercell from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) rks = pbcdft.RKS(supcell) erks = rks.kernel() rhf = pbcscf.RHF(supcell) rhf.__dict__.update(rks.__dict__) mycc = pbcc.RCCSD(rhf, frozen=2) eris = mycc.ao2mo() ercc, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ercc / np.prod(nk), -0.11467718013872311, 6) self.assertAlmostEqual(ercc / np.prod(nk), ekcc, 6) ercc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ercc_t / np.prod(nk), -0.00066503872045200996, 6) self.assertAlmostEqual(ercc_t / np.prod(nk), ekcc_t, 6)
def test_ccsd_t_non_hf(self): '''Tests ccsd and ccsd_t for non-Hartree-Fock references using supercell vs k-point calculation.''' n = 14 cell = make_test_cell.test_cell_n3([n] * 3) nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcdft.KRKS(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KRCCSD(khf) eris = mycc.ao2mo() ekcc, t1, t2 = mycc.kernel(eris=eris) ekcc_t = mycc.ccsd_t(eris=eris) # Run supercell from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) rks = pbcdft.RKS(supcell) erks = rks.kernel() rhf = pbcscf.RHF(supcell) rhf.__dict__.update(rks.__dict__) mycc = pbcc.RCCSD(rhf) eris = mycc.ao2mo() ercc, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ercc / np.prod(nk), -0.15632445245405927, 6) self.assertAlmostEqual(ercc / np.prod(nk), ekcc, 6) ercc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ercc_t / np.prod(nk), -0.00114619248449, 6) self.assertAlmostEqual(ercc_t / np.prod(nk), ekcc_t, 6)
def test_ccsd_t_hf_frozen(self): '''Tests ccsd and ccsd_t for Hartree-Fock references with frozen orbitals using supercell vs k-point calculation.''' n = 14 cell = make_test_cell.test_cell_n3([n] * 3) nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcscf.KRHF(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KRCCSD(khf, frozen=1) eris = mycc.ao2mo() ekcc, t1, t2 = mycc.kernel(eris=eris) ekcc_t = mycc.ccsd_t(eris=eris) # Run supercell from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) rks = pbcscf.RHF(supcell) erks = rks.kernel() rhf = pbcscf.RHF(supcell) rhf.__dict__.update(rks.__dict__) mycc = pbcc.RCCSD(rhf, frozen=2) eris = mycc.ao2mo() ercc, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ercc / np.prod(nk), -0.1137362020855094, 6) self.assertAlmostEqual(ercc / np.prod(nk), ekcc, 6) ercc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ercc_t / np.prod(nk), -0.0006758642528821, 6) self.assertAlmostEqual(ercc_t / np.prod(nk), ekcc_t, 6)
def test_ccsd_t_hf(self): '''Tests ccsd and ccsd_t for Hartree-Fock references.''' n = 14 cell = make_test_cell.test_cell_n3([n] * 3) nk = [2, 1, 1] kpts = cell.make_kpts(nk) kpts -= kpts[0] kks = pbcscf.KRHF(cell, kpts=kpts) ekks = kks.kernel() khf = pbcscf.KRHF(cell) khf.__dict__.update(kks.__dict__) mycc = pbcc.KRCCSD(khf) eris = mycc.ao2mo() ekcc, t1, t2 = mycc.kernel(eris=eris) ekcc_t = mycc.ccsd_t(eris=eris) # Run supercell from pyscf.pbc.tools.pbc import super_cell supcell = super_cell(cell, nk) rks = pbcscf.RHF(supcell) erks = rks.kernel() rhf = pbcscf.RHF(supcell) rhf.__dict__.update(rks.__dict__) mycc = pbcc.RCCSD(rhf) eris = mycc.ao2mo() ercc, t1, t2 = mycc.kernel(eris=eris) self.assertAlmostEqual(ercc / np.prod(nk), -0.15530756381467772, 6) self.assertAlmostEqual(ercc / np.prod(nk), ekcc, 6) ercc_t = mycc.ccsd_t(eris=eris) self.assertAlmostEqual(ercc_t / np.prod(nk), -0.0011112735513837887, 6) self.assertAlmostEqual(ercc_t / np.prod(nk), ekcc_t, 6)
def setUpClass(cls): cls.cell = gto.Cell() cls.cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.685068664391 1.685068664391 1.685068664391 ''' cls.cell.basis = 'gth-szv' cls.cell.pseudo = 'gth-pade' cls.cell.a = ''' 0.000000000, 3.370137329, 3.370137329 3.370137329, 0.000000000, 3.370137329 3.370137329, 3.370137329, 0.000000000''' cls.cell.unit = 'B' cls.cell.build() cls.cell.verbose = 0 cls.cell.incore_anyway = True cls.cell.max_memory = 20e3 cls.mf = scf.KRHF(cls.cell, kpts=cls.cell.make_kpts([2, 1, 1])) cls.mf.chkfile = 'test_kgf_proper_rhf_chk.dat' if os.path.exists(cls.mf.chkfile): cls.mf.update() else: cls.mf.kernel() cls.ccsd = cc.KRCCSD(cls.mf, frozen=(cls.cell.nelectron - 4) // 2) cls.ccsd.kernel() # TODO: lambda iterations cls.ccsd.l1 = cls.ccsd.t1 cls.ccsd.l2 = cls.ccsd.t2 cls.eip, cls.ip_vecs = cls.ccsd.ipccsd(nroots=2) cls.eea, cls.ea_vecs = cls.ccsd.eaccsd(nroots=2) cls.energies = numpy.linspace(0, 1.3, 50) cls.eta = 0.04 cls.title = "diamond" cls.options = ("iter", "td")
def test_eomea_matvec(self): cell = gto.Cell() cell.atom = ''' He 0.000000000000 0.000000000000 0.000000000000 He 1.685068664391 1.685068664391 1.685068664391 ''' cell.basis = [[0, (1., 1.)], [0, (.5, 1.)]] cell.a = ''' 0.000000000, 3.370137329, 3.370137329 3.370137329, 0.000000000, 3.370137329 3.370137329, 3.370137329, 0.000000000''' cell.unit = 'B' cell.build() np.random.seed(2) # Running HF and CCSD with 1x1x2 Monkhorst-Pack k-point mesh kmf = pbcscf.KRHF(cell, kpts=cell.make_kpts([1, 1, 3]), exxdiv=None) nmo = cell.nao_nr() kmf.mo_occ = np.zeros((3, nmo)) kmf.mo_occ[:, :2] = 2 kmf.mo_energy = np.arange(nmo) + np.random.random((3, nmo)) * .3 kmf.mo_energy[kmf.mo_occ == 0] += 2 kmf.mo_coeff = (np.random.random((3, nmo, nmo)) + np.random.random( (3, nmo, nmo)) * 1j - .5 - .5j) mycc = pbcc.KRCCSD(kmf) t1, t2 = rand_t1_t2(kmf, mycc) mycc.t1 = t1 mycc.t2 = t2 eris = mycc.ao2mo() eom = EOMEA(mycc) imds = eom.make_imds(eris) np.random.seed(9) vector = np.random.random(eom.vector_size()) hc = eom.matvec(vector, 0, imds) self.assertAlmostEqual(lib.finger(hc), (-2.615041322934018 - 0.19907655222705176j), 9) hc = eom.matvec(vector, 1, imds) self.assertAlmostEqual(lib.finger(hc), (-1.9105694363906784 + 0.4623840337230889j), 9) hc = eom.matvec(vector, 2, imds) self.assertAlmostEqual(lib.finger(hc), (-3.5191624937262938 - 0.09803982911194647j), 9) kmf = kmf.density_fit(auxbasis=[[0, (2., 1.)], [0, (1., 1.)], [0, (.5, 1.)]]) mycc._scf = kmf mycc.max_memory = 0 eris = mycc.ao2mo() imds = eom.make_imds(eris) hc = eom.matvec(vector, 0, imds) self.assertAlmostEqual(lib.finger(hc), (-2.6242967982318532 - 0.19622574939883755j), 9) hc = eom.matvec(vector, 1, imds) self.assertAlmostEqual(lib.finger(hc), (-1.9052161075024587 + 0.4635723967077203j), 9) hc = eom.matvec(vector, 2, imds) self.assertAlmostEqual(lib.finger(hc), (-3.5273812229833275 - 0.10165584293391894j), 9) mycc.max_memory = 4000 eris = mycc.ao2mo() imds = eom.make_imds(eris) hc = eom.matvec(vector, 0, imds) self.assertAlmostEqual(lib.finger(hc), (-2.6242967982318532 - 0.19622574939883755j), 9) hc = eom.matvec(vector, 1, imds) self.assertAlmostEqual(lib.finger(hc), (-1.9052161075024587 + 0.4635723967077203j), 9) hc = eom.matvec(vector, 2, imds) self.assertAlmostEqual(lib.finger(hc), (-3.5273812229833275 - 0.10165584293391894j), 9)
def run_krccsd(mf): cc = pbccc.KRCCSD(mf) cc.verbose = 7 cc.ccsd() return cc
self.assertAlmostEqual(e[0][2], 5.060562771978923, 6) self.assertAlmostEqual(e[0][3], 5.077249823137741, 6) 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(
def test_eomea_l_matvec(self): cell = gto.Cell() cell.atom = ''' He 0.000000000000 0.000000000000 0.000000000000 He 1.685068664391 1.685068664391 1.685068664391 ''' cell.basis = [[0, (1., 1.)], [0, (.5, 1.)]] cell.a = ''' 0.000000000, 3.370137329, 3.370137329 3.370137329, 0.000000000, 3.370137329 3.370137329, 3.370137329, 0.000000000''' cell.unit = 'B' cell.build() np.random.seed(2) # Running HF and CCSD with 1x1x2 Monkhorst-Pack k-point mesh kmf = pbcscf.KRHF(cell, kpts=cell.make_kpts([1, 1, 3]), exxdiv=None) nmo = cell.nao_nr() kmf.mo_occ = np.zeros((3, nmo)) kmf.mo_occ[:, :2] = 2 kmf.mo_energy = np.arange(nmo) + np.random.random((3, nmo)) * .3 kmf.mo_energy[kmf.mo_occ == 0] += 2 kmf.mo_coeff = (np.random.random((3, nmo, nmo)) + np.random.random( (3, nmo, nmo)) * 1j - .5 - .5j) mycc = pbcc.KRCCSD(kmf) t1, t2 = rand_t1_t2(kmf, mycc) mycc.t1 = t1 mycc.t2 = t2 eris = mycc.ao2mo() eom = EOMEA(mycc) imds = eom.make_imds(eris) np.random.seed(9) vector = np.random.random(eom.vector_size()) hc = eom.l_matvec(vector, 0, imds) self.assertAlmostEqual(lib.finger(hc), (-0.9490117387531858 - 1.726564412656459j), 9) hc = eom.l_matvec(vector, 1, imds) self.assertAlmostEqual(lib.finger(hc), (-0.4497554439273588 - 5.620765390422395j), 9) hc = eom.l_matvec(vector, 2, imds) self.assertAlmostEqual(lib.finger(hc), (-1.9057184472068758 + 2.7776122802218817j), 9) kmf = kmf.density_fit(auxbasis=[[0, (2., 1.)], [0, (1., 1.)], [0, (.5, 1.)]]) mycc._scf = kmf mycc.max_memory = 0 eris = mycc.ao2mo() imds = eom.make_imds(eris) hc = eom.l_matvec(vector, 0, imds) self.assertAlmostEqual(lib.finger(hc), (-0.9525095721066594 - 1.722602584395692j), 9) hc = eom.l_matvec(vector, 1, imds) self.assertAlmostEqual(lib.finger(hc), (-0.4402079681364959 - 5.610500177034039j), 9) hc = eom.l_matvec(vector, 2, imds) self.assertAlmostEqual(lib.finger(hc), (-1.9053243731138183 + 2.785112360342188j), 9) mycc.max_memory = 4000 eris = mycc.ao2mo() imds = eom.make_imds(eris) hc = eom.l_matvec(vector, 0, imds) self.assertAlmostEqual(lib.finger(hc), (-0.9525095721066594 - 1.722602584395692j), 9) hc = eom.l_matvec(vector, 1, imds) self.assertAlmostEqual(lib.finger(hc), (-0.4402079681364959 - 5.610500177034039j), 9) hc = eom.l_matvec(vector, 2, imds) self.assertAlmostEqual(lib.finger(hc), (-1.9053243731138183 + 2.785112360342188j), 9)
mesh=[24,]*3, atom='''C 0 0 0 C 1.68506866 1.68506866 1.68506866''', basis='gth-szv', pseudo='gth-pade', verbose=4 ) # First we perform our mean-field calculation with a [1,1,2] grid kpts = cell.make_kpts(nmp) kpts -= kpts[0] kmf = pbchf.KRHF(cell, kpts, exxdiv=None)#, conv_tol=1e-10) kpoint_energy = kmf.kernel() # Perform our ground state ccsd calculation mykcc = pbccc.KRCCSD(kmf) eris = mykcc.ao2mo() kccsd_energy = mykcc.ccsd(eris=eris)[0] ekcc = mykcc.ecc # To run an EOM-CCSD(T)*a calculation, you need to use the EOMIP_Ta/ # /EOMEA_Ta classes that will add in the contribution of T3[2] to # T1/T2 as well as any other relevant EOM-CCSD intermediates. myeom = EOMIP_Ta(mykcc) # We then call the ip-ccsd* function that will find both the right # and left eigenvectors of EOM-CCSD (with perturbed intermediates) # and run EOM-CCSD* myeom.ipccsd_star(nroots=2, kptlist=[0], eris=eris) # If we need to run both an IP and EA calculation, the t3[2] intermediates # would need to be created two times. Because creating the t3[2] intermediates
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.mesh = [15, 15, 15] cell.build() kpts = cell.make_kpts([1, 1, 3]) mf = scf.KRHF(cell, kpts, exxdiv=None) if rank == 0: #SCF only needs to run on one process mf.kernel() refcc = cc.KRCCSD(mf) refcc.kernel() comm.barrier() mf.mo_coeff = comm.bcast(mf.mo_coeff, root=0) mf.mo_occ = comm.bcast(mf.mo_occ, root=0) mycc = kccsd_rhf.KRCCSD(mf) mycc.kernel() mycc.ipccsd(nroots=2, kptlist=[0], koopmans=True) if rank == 0: refcc.ipccsd(nroots=2, kptlist=[0], koopmans=True) comm.barrier() mycc.eaccsd(nroots=2, kptlist=[0], koopmans=True) if rank == 0:
print "trace gf ", bal #Run new kpts = cell.make_kpts(nmp) kpts -= kpts[0] #kpts = cell.make_kpts([1,1,1]) kmf = scf.KRHF(cell, kpts, exxdiv=None) kmf.kpts = kpts kmf.diis = None kmf.conv_tol_grad = 1e-8 kmf.conv_tol = 1e-8 ehf = kmf.kernel() kmf.analyze() mycc = cc.KRCCSD(kmf) mycc.frozen = [[0, 1, 2, 5, 6, 7], [0, 2, 3, 4, 5, 7]] mycc.ip_partition = None mycc.ea_partition = None mycc.conv_tol_normt = 1e-10 mycc.conv_tol = 1e-10 mycc.kernel() #p=[4,5,6,7] #q=[4,5,6,7] p = [1] q = [1] #p = range(mycc.nocc) #mos = mycc.nmo #q = range(mos-mycc.nocc) gfunccc = kpts_gf.OneParticleGF(mycc) kpts_gf_ea = gfunccc.kernel(kpts, p, q, omegas)
def setUpClass(cls): k_grid = [2, 1, 1] # Unit cell cls.cell = gto.Cell() cls.cell.atom = ''' C 0.000000000000 0.000000000000 0.000000000000 C 1.685068664391 1.685068664391 1.685068664391 ''' cls.cell.basis = 'gth-szv' cls.cell.pseudo = 'gth-pade' cls.cell.a = ''' 0.000000000, 3.370137329, 3.370137329 3.370137329, 0.000000000, 3.370137329 3.370137329, 3.370137329, 0.000000000 ''' cls.cell.unit = 'B' cls.cell.verbose = 7 cls.cell.mesh = [24] * 3 cls.cell.build() # MF cls.mf = scf.KRHF(cls.cell, kpts=cls.cell.make_kpts(k_grid), exxdiv=None) cls.mf.chkfile = 'test_kgf_proper_rhf_chk.dat' if os.path.exists(cls.mf.chkfile): cls.mf.update() else: cls.mf.kernel() # Supercell cls.cell2 = super_cell(cls.cell, k_grid) cls.mf2 = scf.KRHF(cls.cell2, exxdiv=None) cls.order = numpy.argsort(numpy.hstack(cls.mf.mo_energy)) c1 = cls.mf.mo_coeff[0] c2 = cls.mf.mo_coeff[1] c1, c2 = numpy.concatenate((c1, c1), axis=0) / 2.**.5, numpy.concatenate((c2, -c2), axis=0) / 2.**.5 cls.mf2.mo_coeff = [numpy.concatenate((c1, c2), axis=1)[:, cls.order]] cls.mf2.mo_energy = [numpy.concatenate(cls.mf.mo_energy)[cls.order]] cls.mf2.mo_occ = [numpy.concatenate(cls.mf.mo_occ)[cls.order]] cls.mf2.make_rdm1() # CCSD cls.ccsd = cc.KRCCSD(cls.mf) cls.ccsd.conv_tol_normt = 1e-8 cls.ccsd.kernel() cls.ccsd2 = cc.KRCCSD(cls.mf2) cls.ccsd2.conv_tol_normt = 1e-8 cls.ccsd2.kernel() # TODO: lambda iterations cls.ccsd.l1 = cls.ccsd.t1 cls.ccsd.l2 = cls.ccsd.t2 # cls.ccsd.ipccsd(nroots=2) # cls.ccsd.eaccsd(nroots=2) # cls.ip_samples = [-0.71, -1] cls.ip_samples = [-0.71] cls.ea_samples = [1.13, 0.3] cls.eta = 0.01 # ===== cls.nocc, cls.nvirt = cls.ccsd.t1[0].shape cls.nmo = cls.nocc + cls.nvirt cls.o1 = cls.order[:2*cls.nocc] < cls.nmo cls.o2 = cls.order[:2*cls.nocc] >= cls.nmo cls.v1 = cls.order[2*cls.nocc:] < cls.nmo cls.v2 = cls.order[2*cls.nocc:] >= cls.nmo cls.a1 = cls.order < cls.nmo cls.a2 = cls.order >= cls.nmo # ===== cls.ccsd2.l1 = cls.ccsd2.t1 cls.ccsd2.l2 = cls.ccsd2.t2