def _test_ea_diag(self, kmf, kshift=0): cc = kccsd.KUCCSD(kmf) Ecc = cc.kernel()[0] eom = kccsd_uhf.EOMEA(cc) imds = eom.make_imds() t1a, t1b = imds.t1 nkpts, nocc_a, nvir_a = t1a.shape nkpts, nocc_b, nvir_b = t1b.shape nocc = nocc_a + nocc_b nvir = nvir_a + nvir_b diag = kccsd_uhf.eaccsd_diag(eom, kshift, imds=imds) I = np.identity(diag.shape[0], dtype=complex) indices = np.arange(diag.shape[0]) H = np.zeros((I.shape[0], len(indices)), dtype=complex) for j, idx in enumerate(indices): H[:, j] = kccsd_uhf.eaccsd_matvec(eom, I[:, idx], kshift, imds=imds) diag_ref = np.zeros(len(indices), dtype=complex) diag_out = np.zeros(len(indices), dtype=complex) for j, idx in enumerate(indices): diag_ref[j] = H[idx, j] diag_out[j] = diag[idx] diff = np.linalg.norm(diag_ref - diag_out) self.assertTrue( abs(diff) < KGCCSD_TEST_THRESHOLD, "Difference in EA diag: {}".format(diff))
def _test_ip_diag(self,kmf,kshift=0): cc = kccsd.KUCCSD(kmf) Ecc = cc.kernel()[0] eom = kccsd_uhf.EOMIP(cc) imds = eom.make_imds() t1a,t1b = imds.t1 nkpts, nocc_a, nvir_a = t1a.shape nkpts, nocc_b, nvir_b = t1b.shape nocc = nocc_a + nocc_b diag = kccsd_uhf.ipccsd_diag(eom,kshift,imds=imds) I = np.zeros((diag.shape[0],diag.shape[0]),dtype=complex) I[:nocc,:nocc] = np.identity(nocc,dtype=complex) indices = get_ip_identity(nocc_a,nocc_b,nvir_a,nvir_b,nkpts,I) H = np.zeros((I.shape[0],len(indices)),dtype=complex) for j,idx in enumerate(indices): H[:,j] = kccsd_uhf.ipccsd_matvec(eom,I[:,idx],kshift,imds=imds) diag_ref = np.zeros(len(indices),dtype=complex) diag_out = np.zeros(len(indices),dtype=complex) for j,idx in enumerate(indices): diag_ref[j] = H[idx,j] diag_out[j] = diag[idx] diff = np.linalg.norm(diag_ref - diag_out) self.assertTrue(abs(diff) < thresh,"Difference in IP diag: {}".format(diff))
def _test_ea_diag(self,kmf,kshift=0): cc = kccsd.KUCCSD(kmf) Ecc = cc.kernel()[0] eom = kccsd_uhf.EOMEA(cc) imds = eom.make_imds() t1a,t1b = imds.t1 nkpts, nocc_a, nvir_a = t1a.shape nkpts, nocc_b, nvir_b = t1b.shape nocc = nocc_a + nocc_b nvir = nvir_a + nvir_b diag = kccsd_uhf.eaccsd_diag(eom,kshift,imds=imds) I = np.zeros((diag.shape[0],diag.shape[0]),dtype=complex) I[:nvir,:nvir] = np.identity(nvir,dtype=complex) indices = get_ea_identity(kshift,nocc_a,nocc_b,nvir_a,nvir_b,nkpts,I,cc) H = np.zeros((I.shape[0],len(indices)),dtype=complex) for j,idx in enumerate(indices): H[:,j] = kccsd_uhf.eaccsd_matvec(eom,I[:,idx],kshift,imds=imds) diag_ref = np.zeros(len(indices),dtype=complex) diag_out = np.zeros(len(indices),dtype=complex) for j,idx in enumerate(indices): diag_ref[j] = H[idx,j] diag_out[j] = diag[idx] diff = np.linalg.norm(diag_ref - diag_out) self.assertTrue(abs(diff) < thresh,"Difference in EA diag: {}".format(diff))
def test_he_131_diag(self): kpts = cell.make_kpts([1,3,1]) kmf = pbcscf.KGHF(cell, kpts, exxdiv=None) Escf = kmf.scf() cc = kccsd.KGCCSD(kmf) Ecc = cc.kernel()[0] self._test_ip_diag(cc) self._test_ea_diag(cc)
def test_he_112_diag(self): kpts = cell.make_kpts([1, 1, 2]) kmf = pbcscf.KGHF(cell, kpts, exxdiv=None) Escf = kmf.scf() cc = kccsd.KGCCSD(kmf) Ecc = cc.kernel()[0] self._test_ip_diag(cc) self._test_ea_diag(cc)
def run_kcell(cell, n, nk): ############################################# # Do a k-point calculation # ############################################# abs_kpts = cell.make_kpts(nk, wrap_around=True) #cell.verbose = 7 # HF kmf = pbcscf.KRHF(cell, abs_kpts, exxdiv=None) kmf.conv_tol = 1e-14 ekpt = kmf.scf() # CCSD cc = pbcc.kccsd_rhf.RCCSD(kmf) cc.conv_tol = 1e-8 ecc, t1, t2 = cc.kernel() return ekpt, ecc
def test_frozen_n3(self): mesh = 5 cell = make_test_cell.test_cell_n3([mesh] * 3) nk = (1, 1, 2) ehf_bench = -8.348616843863795 ecc_bench = -0.037920339437169 abs_kpts = cell.make_kpts(nk, with_gamma_point=True) # RHF calculation kmf = pbcscf.KRHF(cell, abs_kpts, exxdiv=None) kmf.conv_tol = 1e-9 ehf = kmf.scf() # KRCCSD calculation, equivalent to running supercell # calculation with frozen=[0,1,2] (if done with larger mesh) cc = pyscf.pbc.cc.kccsd_rhf.RCCSD(kmf, frozen=[[0], [0, 1]]) cc.diis_start_cycle = 1 ecc, t1, t2 = cc.kernel() self.assertAlmostEqual(ehf, ehf_bench, 9) self.assertAlmostEqual(ecc, ecc_bench, 9)
def test_frozen_n3(self): mesh = 5 cell = make_test_cell.test_cell_n3([mesh]*3) nk = (1, 1, 2) ehf_bench = -8.348616843863795 ecc_bench = -0.037920339437169 abs_kpts = cell.make_kpts(nk, with_gamma_point=True) # RHF calculation kmf = pbcscf.KRHF(cell, abs_kpts, exxdiv=None) kmf.conv_tol = 1e-9 ehf = kmf.scf() # KRCCSD calculation, equivalent to running supercell # calculation with frozen=[0,1,2] (if done with larger mesh) cc = pbcc.kccsd_rhf.RCCSD(kmf, frozen=[[0],[0,1]]) cc.diis_start_cycle = 1 ecc, t1, t2 = cc.kernel() self.assertAlmostEqual(ehf, ehf_bench, 9) self.assertAlmostEqual(ecc, ecc_bench, 7)