def test_n3_diffuse_frozen(self): ehf2 = kmf.e_tot self.assertAlmostEqual(ehf2, -6.1870676561725695, 6) mycc = pbcc.KUCCSD(kmf, frozen=([[0,],[0,1]],[[0],[0,1]])) mycc.conv_tol = 1e-7 mycc.conv_tol_normt = 1e-7 ecc2, t1, t2 = mycc.kernel() self.assertAlmostEqual(ecc2, -0.0442506265840587, 6) eom = EOMIP(mycc) e1_obt, v = eom.ipccsd(nroots=3, koopmans=True, kptlist=[0]) self.assertAlmostEqual(e1_obt[0][0], -1.1316152294295743, 6) self.assertAlmostEqual(e1_obt[0][1], -1.1041637212148683, 6) self.assertAlmostEqual(e1_obt[0][2], -1.104163717600433, 6) eom = EOMEA(mycc) e2_obt, v = eom.eaccsd(nroots=3, koopmans=True, kptlist=[0]) self.assertAlmostEqual(e2_obt[0][0], 1.2572812499753756, 6) self.assertAlmostEqual(e2_obt[0][1], 1.257281253091707, 6) self.assertAlmostEqual(e2_obt[0][2], 1.2807473549827182, 6) eom = EOMIP(mycc) e1_obt, v = eom.ipccsd(nroots=2, kptlist=[1]) self.assertAlmostEqual(e1_obt[0][0], -1.04309071165136, 6) self.assertAlmostEqual(e1_obt[0][1], -1.04309071165136, 6) #self.assertAlmostEqual(e1_obt[0][2], -0.09623848794144876, 6) eom = EOMEA(mycc) e2_obt, v = eom.eaccsd(nroots=3, koopmans=True, kptlist=[1]) 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_he(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.UHF(supcell,exxdiv=None) ehf = gmf.kernel() gcc = cc.UCCSD(gmf) gcc.conv_tol=1e-12 gcc.conv_tol_normt=1e-10 gcc.max_cycle=250 ecc, t1, t2 = gcc.kernel() print('UHF energy (supercell) %.7f \n' % (float(ehf)/2.)) print('UCCSD correlation energy (supercell) %.7f \n' % (float(ecc)/2.)) #eom = eom_uccsd.EOMIP(gcc) #e1, v = eom.ipccsd(nroots=2) #eom = eom_uccsd.EOMEA(gcc) #e2, v = eom.eaccsd(nroots=2, koopmans=True) ''' # Running HF and CCSD with 1x1x2 Monkhorst-Pack k-point mesh kmf = scf.KUHF(cell, kpts=cell.make_kpts(nmp), exxdiv=None) ehf2 = kmf.kernel() mycc = cc.KUCCSD(kmf) mycc.conv_tol = 1e-7 mycc.conv_tol_normt = 1e-7 mycc.max_cycle = 250 ecc2, t1, t2 = mycc.kernel() print('UHF energy %.7f \n' % (float(ehf2))) print('UCCSD 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]) print(e1_obt) print(e2_obt)
def test_n3_diffuse(self): self.assertAlmostEqual(kmf.e_tot, -6.1870676561721227, 6) cell = make_test_cell.test_cell_n3_diffuse() nmp = [1, 1, 2] ''' # treating 1*1*2 supercell at gamma point supcell = super_cell(cell,nmp) gmf = scf.UHF(supcell,exxdiv=None) ehf = gmf.kernel() gcc = cc.UCCSD(gmf) gcc.conv_tol=1e-12 gcc.conv_tol_normt=1e-10 gcc.max_cycle=250 ecc, t1, t2 = gcc.kernel() print('UHF energy (supercell) %.7f \n' % (float(ehf)/2.)) print('UCCSD correlation energy (supercell) %.7f \n' % (float(ecc)/2.)) #eom = eom_uccsd.EOMIP(gcc) #e1, v = eom.ipccsd(nroots=2) #eom = eom_uccsd.EOMEA(gcc) #e2, v = eom.eaccsd(nroots=2, koopmans=True) ''' mycc = pbcc.KUCCSD(kmf) mycc.conv_tol = 1e-7 mycc.conv_tol_normt = 1e-7 ecc2, t1, t2 = mycc.kernel() self.assertAlmostEqual(ecc2, -0.0676483711263548, 6) eom = EOMIP(mycc) e1_obt, v = eom.ipccsd(nroots=3, koopmans=True, kptlist=[0]) self.assertAlmostEqual(e1_obt[0][0], -1.148946994550331, 6) self.assertAlmostEqual(e1_obt[0][1], -1.148946994544336, 6) self.assertAlmostEqual(e1_obt[0][2], -1.10881945217663, 6) eom = EOMEA(mycc) e2_obt, v = eom.eaccsd(nroots=3, koopmans=True, kptlist=[0]) self.assertAlmostEqual(e2_obt[0][0], 1.26697897719539, 6) self.assertAlmostEqual(e2_obt[0][1], 1.26697897720534, 6) self.assertAlmostEqual(e2_obt[0][2], 1.278883205460933, 6) eom = EOMIP(mycc) e1_obt, v = eom.ipccsd(nroots=3, koopmans=True, kptlist=[1]) self.assertAlmostEqual(e1_obt[0][0], -0.9074337295664157, 6) self.assertAlmostEqual(e1_obt[0][1], -0.9074337295664148, 6) self.assertAlmostEqual(e1_obt[0][2], -0.9074331791699104, 6) eom = EOMEA(mycc) e2_obt, v = eom.eaccsd(nroots=3, koopmans=True, kptlist=[1]) self.assertAlmostEqual(e2_obt[0][0], 1.227583017460536, 6) self.assertAlmostEqual(e2_obt[0][1], 1.227583017460617, 6) self.assertAlmostEqual(e2_obt[0][2], 1.383037918699404, 6)
def test_kuccsd_openshell(): cell = gto.M( unit='B', a=[[0., 6.74027466, 6.74027466], [6.74027466, 0., 6.74027466], [6.74027466, 6.74027466, 0.]], mesh=[13] * 3, atom='''H 0 0 0 H 1.68506866 1.68506866 1.68506866 H 3.37013733 3.37013733 3.37013733''', basis=[[0, (1., 1.)], [0, (.5, 1.)]], verbose=1, charge=0, spin=1, ) nmp = [3, 1, 1] # cell spin multiplied by nkpts cell.spin = cell.spin * 3 # treating 3*1*1 supercell at gamma point supcell = super_cell(cell, nmp) umf = scf.UHF(supcell, exxdiv=None) umf.conv_tol = 1e-11 ehf = umf.kernel() ucc = cc.UCCSD(umf) ucc.conv_tol = 1e-12 ecc, t1, t2 = ucc.kernel() print('UHF energy (supercell) %.9f \n' % (float(ehf) / 3.)) print('UCCSD correlation energy (supercell) %.9f \n' % (float(ecc) / 3.)) assert abs(ehf / 3 - -1.003789445) < 1e-7 assert abs(ecc / 3 - -0.029056542) < 1e-6 # kpts calculations kpts = cell.make_kpts(nmp) kpts -= kpts[0] kmf = scf.KUHF(cell, kpts, exxdiv=None) kmf.conv_tol = 1e-11 ehf = kmf.kernel() kcc = cc.KUCCSD(kmf) kcc.conv_tol = 1e-12 ecc, t1, t2 = kcc.kernel() print('UHF energy (kpts) %.9f \n' % (float(ehf))) print('UCCSD correlation energy (kpts) %.9f \n' % (float(ecc))) assert abs(ehf - -1.003789445) < 1e-7 assert abs(ecc - -0.029056542) < 1e-6
def test_kuccsd_supercell_vs_kpts_high_cost(): cell = gto.M( unit = 'B', a = [[ 0., 3.37013733, 3.37013733], [ 3.37013733, 0., 3.37013733], [ 3.37013733, 3.37013733, 0. ]], mesh = [13]*3, atom = '''He 0 0 0 He 1.68506866 1.68506866 1.68506866''', basis = [[0, (1., 1.)], [0, (.5, 1.)]], verbose = 0, ) nmp = [3,3,1] # treating supercell at gamma point supcell = super_cell(cell,nmp) gmf = scf.UHF(supcell,exxdiv=None) ehf = gmf.kernel() gcc = cc.UCCSD(gmf) ecc, t1, t2 = gcc.kernel() print('UHF energy (supercell) %f \n' % (float(ehf)/numpy.prod(nmp))) print('UCCSD correlation energy (supercell) %f \n' % (float(ecc)/numpy.prod(nmp))) assert abs(ehf / 9 - -4.343308413289) < 1e-7 assert abs(ecc / 9 - -0.009470753047083676) < 1e-6 # treating mesh of k points kpts = cell.make_kpts(nmp) kpts -= kpts[0] kmf = scf.KUHF(cell,kpts,exxdiv=None) ehf = kmf.kernel() kcc = cc.KUCCSD(kmf) ecc, t1, t2 = kcc.kernel() print('UHF energy (kpts) %f \n' % ehf) print('UCCSD correlation energy (kpts) %f \n' % ecc) assert abs(ehf - -4.343308413289) < 1e-7 assert abs(ecc - -0.009470753047083676) < 1e-6
#primitive cell with k points kpts = cell.make_kpts(nmp) nkpts = len(kpts) kmf = scf.KUHF(cell, kpts, exxdiv=None).density_fit() kmf.chkfile = 'kpt.chk' nao_half = nao // 2 dmk = np.zeros([2, nkpts, nao, nao]) for i in range(nkpts): for j in range(2): dmk[0][i][j, j] = 0.5 dmk[1][i][j + nao_half, j + nao_half] = 0.5 ehf = kmf.kernel(dmk) kcc = cc.KUCCSD(kmf) ecc, t1, t2 = kcc.kernel() print('========================================') print('UHF energy (kpts) %f \n' % (float(ehf))) print('UCCSD correlation energy (kpts) %f \n' % (float(ecc))) print('========================================') # Gamma point supercell calculation supcell = super_cell(cell, nmp) dms = np.zeros([2, supcell.nao_nr(), supcell.nao_nr()]) for i in range(nkpts): for j in range(2): dms[0][j + i * nao][j + i * nao] = 0.5 dms[1][j + i * nao + nao_half][j + i * nao + nao_half] = 0.5
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.mesh = [13]*3 cell.precision = 1e-10 cell.build() np.random.seed(2) kmf = pbcscf.KUHF(cell, kpts=cell.make_kpts([1,1,3]), exxdiv=None) nmo = cell.nao_nr() kmf.mo_occ = np.zeros((2,3,nmo)) kmf.mo_occ[0,:,:3] = 1 kmf.mo_occ[1,:,:1] = 1 kmf.mo_energy = np.arange(nmo) + np.random.random((2,3,nmo)) * .3 kmf.mo_energy[kmf.mo_occ == 0] += 2 mo = (np.random.random((2,3,nmo,nmo)) + np.random.random((2,3,nmo,nmo))*1j - .5-.5j) s = kmf.get_ovlp() kmf.mo_coeff = np.empty_like(mo) nkpts = len(kmf.kpts) for k in range(nkpts): kmf.mo_coeff[0,k] = lo.orth.vec_lowdin(mo[0,k], s[k]) kmf.mo_coeff[1,k] = lo.orth.vec_lowdin(mo[1,k], s[k]) def rand_t1_t2(mycc): nkpts = mycc.nkpts nocca, noccb = mycc.nocc nmoa, nmob = mycc.nmo nvira, nvirb = nmoa - nocca, nmob - noccb np.random.seed(1) t1a = (np.random.random((nkpts,nocca,nvira)) + np.random.random((nkpts,nocca,nvira))*1j - .5-.5j) t1b = (np.random.random((nkpts,noccb,nvirb)) + np.random.random((nkpts,noccb,nvirb))*1j - .5-.5j) t2aa = (np.random.random((nkpts,nkpts,nkpts,nocca,nocca,nvira,nvira)) + np.random.random((nkpts,nkpts,nkpts,nocca,nocca,nvira,nvira))*1j - .5-.5j) kconserv = kpts_helper.get_kconserv(kmf.cell, kmf.kpts) t2aa = t2aa - t2aa.transpose(1,0,2,4,3,5,6) tmp = t2aa.copy() for ki, kj, kk in kpts_helper.loop_kkk(nkpts): kl = kconserv[ki, kk, kj] t2aa[ki,kj,kk] = t2aa[ki,kj,kk] - tmp[ki,kj,kl].transpose(0,1,3,2) t2ab = (np.random.random((nkpts,nkpts,nkpts,nocca,noccb,nvira,nvirb)) + np.random.random((nkpts,nkpts,nkpts,nocca,noccb,nvira,nvirb))*1j - .5-.5j) t2bb = (np.random.random((nkpts,nkpts,nkpts,noccb,noccb,nvirb,nvirb)) + np.random.random((nkpts,nkpts,nkpts,noccb,noccb,nvirb,nvirb))*1j - .5-.5j) t2bb = t2bb - t2bb.transpose(1,0,2,4,3,5,6) tmp = t2bb.copy() for ki, kj, kk in kpts_helper.loop_kkk(nkpts): kl = kconserv[ki, kk, kj] t2bb[ki,kj,kk] = t2bb[ki,kj,kk] - tmp[ki,kj,kl].transpose(0,1,3,2) t1 = (t1a, t1b) t2 = (t2aa, t2ab, t2bb) return t1, t2 mycc = pbcc.KUCCSD(kmf) t1, t2 = rand_t1_t2(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), (4.126336947439054 +0.5931985341760211j), 9) hc = eom.matvec(vector, 1, imds) self.assertAlmostEqual(lib.finger(hc), (1.248516714348047 +2.310336141756983j), 9) hc = eom.matvec(vector, 2, imds) self.assertAlmostEqual(lib.finger(hc), (-3.4529892564020126-5.093287166283228j), 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), (4.045928342346641 +0.5861843966140339j), 8) hc = eom.matvec(vector, 1, imds) self.assertAlmostEqual(lib.finger(hc), (1.2695743252320795+2.28060203958305j ), 8) hc = eom.matvec(vector, 2, imds) self.assertAlmostEqual(lib.finger(hc), (-3.435385905375094-5.0991524119952505j), 8) mycc.max_memory = 4000 eris = mycc.ao2mo() imds = eom.make_imds(eris) hc = eom.matvec(vector, 0, imds) self.assertAlmostEqual(lib.finger(hc), (4.045928342346641 +0.5861843966140339j), 8) hc = eom.matvec(vector, 1, imds) self.assertAlmostEqual(lib.finger(hc), (1.2695743252320795+2.28060203958305j ), 8) hc = eom.matvec(vector, 2, imds) self.assertAlmostEqual(lib.finger(hc), (-3.435385905375094-5.0991524119952505j), 8)