def test_make_natural_orbitals_from_unrestricted(self): from pyscf import mp, ci, cc npt = numpy.testing mol = gto.M(atom = 'O 0 0 0; O 0 0 1.2', basis = '3-21g', spin = 2) myhf = scf.UHF(mol).run() ncas, nelecas = (8, 12) mymc = mcscf.CASCI(myhf, ncas, nelecas) # Test MP2 # Trusted results from ORCA v4.2.1 rmp2_noons = [1.99992786,1.99992701,1.99414062,1.98906552,1.96095173,1.96095165,1.95280755,1.02078458,1.02078457,0.04719006,0.01274288,0.01274278,0.00728679,0.00582683,0.00543964,0.00543962,0.00290772,0.00108258] mymp = mp.UMP2(myhf).run() noons, natorbs = mcscf.addons.make_natural_orbitals(mymp) npt.assert_array_almost_equal(rmp2_noons, noons) mymc.kernel(natorbs) # The tests below are only to ensure that `make_natural_orbitals` can # run at all since we've confirmed above that the NOONs are correct. # Test CISD mycisd = ci.CISD(myhf).run() noons, natorbs = mcscf.addons.make_natural_orbitals(mycisd) mymc.kernel(natorbs) # Test CCSD myccsd = cc.CCSD(myhf).run() noons, natorbs = mcscf.addons.make_natural_orbitals(myccsd) mymc.kernel(natorbs)
def test_ump2_ao2mo_ovov(self): pt = mp.UMP2(mf) nocca, noccb = mol.nelec orboa = mf.mo_coeff[0][:, :nocca] orbva = mf.mo_coeff[0][:, nocca:] orbob = mf.mo_coeff[1][:, :noccb] orbvb = mf.mo_coeff[1][:, noccb:] orbs = (orboa, orbva, orbob, orbvb) ftmp = lib.H5TmpFile() mp.ump2._ao2mo_ovov(pt, orbs, ftmp, 1) ovov = numpy.asarray(ftmp['ovov']) ovOV = numpy.asarray(ftmp['ovOV']) OVOV = numpy.asarray(ftmp['OVOV']) ovov_ref = ao2mo.general(mf._eri, (orboa, orbva, orboa, orbva)) ovOV_ref = ao2mo.general(mf._eri, (orboa, orbva, orbob, orbvb)) OVOV_ref = ao2mo.general(mf._eri, (orbob, orbvb, orbob, orbvb)) self.assertAlmostEqual(numpy.linalg.norm(ovov_ref - ovov), 0, 9) self.assertAlmostEqual(numpy.linalg.norm(ovOV_ref - ovOV), 0, 9) self.assertAlmostEqual(numpy.linalg.norm(OVOV_ref - OVOV), 0, 9)
mol.verbose = 4 mol.atom = ''' O 0.000000 0.000000 0.118351 H 0.000000 0.761187 -0.469725 H 0.000000 -0.761187 -0.469725 ''' mol.basis = 'sto-3g' mol.symmetry = 0 mol.build() a = scf.UHF(mol) a.scf() ####### This can be removed ###### frozen = [[0], [0]] # 1sa and 1sb pt2 = mp.UMP2(a) pt2.frozen = frozen pt2.kernel() rdm1a, rdm1b = pt2.make_rdm1() rdm2aa, rdm2ab, rdm2bb = pt2.make_rdm2() mo_a = a.mo_coeff[0] mo_b = a.mo_coeff[1] nmoa = mo_a.shape[1] nmob = mo_b.shape[1] eriaa = ao2mo.kernel(a._eri, mo_a, compact=False).reshape([nmoa] * 4) eribb = ao2mo.kernel(a._eri, mo_b, compact=False).reshape([nmob] * 4) eriab = ao2mo.kernel(a._eri, (mo_a, mo_a, mo_b, mo_b), compact=False) eriab = eriab.reshape([nmoa, nmoa, nmob, nmob]) hcore = a.get_hcore() h1a = reduce(numpy.dot, (mo_a.T.conj(), hcore, mo_a))
mol = gto.M(atom='C 0 0 0; C 0 0 1.24253', basis='def2-svp', spin=excited_spin, symmetry=True) mol.verbose = 0 # UHF for UNOs mf = scf.UHF(mol).run(max_cycle=100) mo_new = mf.stability()[0] while mo_new is not mf.mo_coeff: mf.kernel(dm0=mf.make_rdm1(mo_coeff=mo_new)) mo_new = mf.stability()[0] no, occ = UNOs(mf) # UHF UMP2 mp2 = mp.UMP2(mf).run() no, occ = nat_orbs_obj(mp2) # UHF UCISD mci = ci.UCISD(mf).run() no, occ = nat_orbs_obj(mci) # RHF UCCSD dm0 = mf.make_rdm1() mf = scf.RHF(mol) mf.kernel(dm0=dm0) mcc = cc.UCCSD(mf).run() no, occ = nat_orbs_obj(mcc) # Run a symmetric CASCI to test symmetric natural orbitals. mc = mcscf.CASCI(mf, 6, 6)
H 1 1.1 H 1 1.1 2 104 ''' mol.charge = 0 mol.spin = 0 mol.symmetry = 1 mol.verbose = 4 mol.build() mf = scf.UHF(mol) ehf = mf.kernel() nao, nmo = mf.mo_coeff[0].shape #frozen = [[0],[0]] frozen = None pt2 = mp.UMP2(mf, frozen=frozen) emp2, t2 = pt2.kernel() rdm1a, rdm1b = pt2.make_rdm1() rdm2aa, rdm2ab, rdm2bb = pt2.make_rdm2() rdm2ba = rdm2ab.transpose(2, 3, 0, 1) occ_a = mf.mo_occ[0] occ_b = mf.mo_occ[1] mo_a = mf.mo_coeff[0] mo_b = mf.mo_coeff[1] nmoa = mo_a.shape[1] nmob = mo_b.shape[1] coeff = numpy.hstack([mo_a, mo_b]) occ = numpy.hstack([occ_a, occ_b])