def _psi4cc(mol, h1e, eri, mo, nelec, with_1pdm, with_e2frag, ccname="CCSD"): import psi4 eri = ao2mo.restore(8, eri, mo.shape[1]) hf_energy, mo_energy, mo, mo_occ = simple_hf(h1e, eri, mo, nelec) h1e = reduce(numpy.dot, (mo.T, h1e, mo)) eri = ao2mo.incore.full(eri, mo) rdm1 = None ps = psi4.Solver(max_memory=1 << 34) with psi4.capture_stdout(): nmo = h1e.shape[0] ps.prepare("RHF", numpy.eye(nmo), h1e, eri, nelec) ecc = ps.energy(ccname) if with_1pdm or with_e2frag: rdm1, rdm2 = ps.density() rdm1 *= 2 # Psi4 gives rdm1 of alpha spin # note the rdm1,rdm2 from psi4 solver EXCLUDES HF contributions for i in range(nelec / 2): rdm1[i, i] += 2 for j in range(nelec / 2): rdm2[i, j, i, j] += 4 rdm2[i, j, j, i] += -2 rdm1 = reduce(numpy.dot, (mo, rdm1, mo.T)) e2frag = 0 if with_e2frag: nmo = mo.shape[1] nimp = with_e2frag p = numpy.dot(mo[:nimp, :].T, mo[:nimp, :]) # psi4 store DM in the order of p^+ q^+ r s eri1 = ao2mo.restore(1, eri, nmo).transpose(0, 2, 1, 3) frag_rdm2 = numpy.dot(p, rdm2.reshape(nmo, -1)) e2frag = 0.5 * numpy.dot(frag_rdm2.reshape(-1), eri1.reshape(-1)) return hf_energy, ecc + hf_energy, e2frag, rdm1
eibja =((eri_full[:m,m:,:m,m:]*rdm2[:m,m:,:m,m:]).sum() + (eri_full[m:,:m,m:,:m]*rdm2[m:,:m,m:,:m]).sum()) * .5 eciab =((eri_full[m:,:m,m:,m:]*rdm2[m:,:m,m:,m:]).sum() + (eri_full[m:,m:,:m,m:]*rdm2[m:,m:,:m,m:]).sum() + (eri_full[m:,m:,m:,:m]*rdm2[m:,m:,m:,:m]).sum() + (eri_full[:m,m:,m:,m:]*rdm2[:m,m:,m:,m:]).sum()) * .5 eabcd = (eri_full[m:,m:,m:,m:]*rdm2[m:,m:,m:,m:]).sum() * .5 assert(abs( 0.000199604546228-eijkl) < 1e-10) assert(abs(-0.000507942173007-eijka) < 1e-10) assert(abs(-0.006798942593477-eijab) < 1e-10) assert(abs( 0.000499123140399-eibja) < 1e-10) assert(abs(-0.000074579201724-eciab) < 1e-10) assert(abs( 0.000078881603460-eabcd) < 1e-10) print 'restrict CCSD PASS' with psi4.capture_stdout(): ps.prepare('RHF', c, h1e, eri, m*2, 0) ecc = ps.energy('CCSD') rdm1, rdm2 = ps.density() e1 = numpy.dot(rdm1.flatten(), h1e.flatten()) * 2 e2 = numpy.dot(rdm2.flatten(), eri_full.flatten()) * .5 assert(abs(-0.0034808845203719995-ecc) < 1e-10) assert(abs( 0.003122970157749-e1) < 1e-10) assert(abs(-0.006603854678121-e2) < 1e-10) eijkl = (eri_full[:m,:m,:m,:m]*rdm2[:m,:m,:m,:m]).sum() * .5 eijka =((eri_full[:m,:m,:m,m:]*rdm2[:m,:m,:m,m:]).sum() + (eri_full[:m,:m,m:,:m]*rdm2[:m,:m,m:,:m]).sum() + (eri_full[:m,m:,:m,:m]*rdm2[:m,m:,:m,:m]).sum() + (eri_full[m:,:m,:m,:m]*rdm2[m:,:m,:m,:m]).sum()) * .5 eijab =((eri_full[:m,:m,m:,m:]*rdm2[:m,:m,m:,m:]).sum()