示例#1
0
 def test_h4_rdm(self):
     mol = gto.Mole()
     mol.verbose = 0
     mol.atom = [
         ['H', ( 1.,-1.    , 0.   )],
         ['H', ( 0.,-1.    ,-1.   )],
         ['H', ( 1.,-0.5   , 0.   )],
         ['H', ( 0.,-1.    , 1.   )],
     ]
     mol.charge = 2
     mol.spin = 2
     mol.basis = '6-31g'
     mol.build()
     mf = scf.UHF(mol).set(init_guess='1e').run(conv_tol=1e-14)
     ehf0 = mf.e_tot - mol.energy_nuc()
     mycc = uccsd.UCCSD(mf).run()
     mycc.solve_lambda()
     eri_aa = ao2mo.kernel(mf._eri, mf.mo_coeff[0])
     eri_bb = ao2mo.kernel(mf._eri, mf.mo_coeff[1])
     eri_ab = ao2mo.kernel(mf._eri, [mf.mo_coeff[0], mf.mo_coeff[0],
                                     mf.mo_coeff[1], mf.mo_coeff[1]])
     h1a = reduce(numpy.dot, (mf.mo_coeff[0].T, mf.get_hcore(), mf.mo_coeff[0]))
     h1b = reduce(numpy.dot, (mf.mo_coeff[1].T, mf.get_hcore(), mf.mo_coeff[1]))
     efci, fcivec = direct_uhf.kernel((h1a,h1b), (eri_aa,eri_ab,eri_bb),
                                      h1a.shape[0], mol.nelec)
     dm1ref, dm2ref = direct_uhf.make_rdm12s(fcivec, h1a.shape[0], mol.nelec)
     t1, t2 = mycc.t1, mycc.t2
     l1, l2 = mycc.l1, mycc.l2
     rdm1 = mycc.make_rdm1(t1, t2, l1, l2)
     rdm2 = mycc.make_rdm2(t1, t2, l1, l2)
     self.assertAlmostEqual(abs(dm1ref[0] - rdm1[0]).max(), 0, 6)
     self.assertAlmostEqual(abs(dm1ref[1] - rdm1[1]).max(), 0, 6)
     self.assertAlmostEqual(abs(dm2ref[0] - rdm2[0]).max(), 0, 6)
     self.assertAlmostEqual(abs(dm2ref[1] - rdm2[1]).max(), 0, 6)
     self.assertAlmostEqual(abs(dm2ref[2] - rdm2[2]).max(), 0, 6)
示例#2
0
文件: test_uccsd.py 项目: sunqm/pyscf
 def test_h4_rdm(self):
     mol = gto.Mole()
     mol.verbose = 0
     mol.atom = [
         ['H', ( 1.,-1.    , 0.   )],
         ['H', ( 0.,-1.    ,-1.   )],
         ['H', ( 1.,-0.5   , 0.   )],
         ['H', ( 0.,-1.    , 1.   )],
     ]
     mol.charge = 2
     mol.spin = 2
     mol.basis = '6-31g'
     mol.build()
     mf = scf.UHF(mol).set(init_guess='1e').run(conv_tol=1e-14)
     ehf0 = mf.e_tot - mol.energy_nuc()
     mycc = uccsd.UCCSD(mf).run()
     mycc.solve_lambda()
     eri_aa = ao2mo.kernel(mf._eri, mf.mo_coeff[0])
     eri_bb = ao2mo.kernel(mf._eri, mf.mo_coeff[1])
     eri_ab = ao2mo.kernel(mf._eri, [mf.mo_coeff[0], mf.mo_coeff[0],
                                     mf.mo_coeff[1], mf.mo_coeff[1]])
     h1a = reduce(numpy.dot, (mf.mo_coeff[0].T, mf.get_hcore(), mf.mo_coeff[0]))
     h1b = reduce(numpy.dot, (mf.mo_coeff[1].T, mf.get_hcore(), mf.mo_coeff[1]))
     efci, fcivec = direct_uhf.kernel((h1a,h1b), (eri_aa,eri_ab,eri_bb),
                                      h1a.shape[0], mol.nelec)
     dm1ref, dm2ref = direct_uhf.make_rdm12s(fcivec, h1a.shape[0], mol.nelec)
     t1, t2 = mycc.t1, mycc.t2
     l1, l2 = mycc.l1, mycc.l2
     rdm1 = mycc.make_rdm1(t1, t2, l1, l2)
     rdm2 = mycc.make_rdm2(t1, t2, l1, l2)
     self.assertAlmostEqual(abs(dm1ref[0] - rdm1[0]).max(), 0, 6)
     self.assertAlmostEqual(abs(dm1ref[1] - rdm1[1]).max(), 0, 6)
     self.assertAlmostEqual(abs(dm2ref[0] - rdm2[0]).max(), 0, 6)
     self.assertAlmostEqual(abs(dm2ref[1] - rdm2[1]).max(), 0, 6)
     self.assertAlmostEqual(abs(dm2ref[2] - rdm2[2]).max(), 0, 6)
示例#3
0
        ['H', (1., -0.5, 0.)],
        ['H', (0., -1., 1.)],
    ]
    mol.charge = 2
    mol.spin = 2
    mol.basis = '6-31g'
    mol.build()
    mf = scf.UHF(mol).run(init_guess='hcore', conv_tol=1.)
    ehf0 = mf.e_tot - mol.energy_nuc()
    mycc = uccsd.UCCSD(mf).run()
    mycc.solve_lambda()
    eri_aa = ao2mo.kernel(mf._eri, mf.mo_coeff[0])
    eri_bb = ao2mo.kernel(mf._eri, mf.mo_coeff[1])
    eri_ab = ao2mo.kernel(
        mf._eri,
        [mf.mo_coeff[0], mf.mo_coeff[0], mf.mo_coeff[1], mf.mo_coeff[1]])
    h1a = reduce(numpy.dot, (mf.mo_coeff[0].T, mf.get_hcore(), mf.mo_coeff[0]))
    h1b = reduce(numpy.dot, (mf.mo_coeff[1].T, mf.get_hcore(), mf.mo_coeff[1]))
    efci, fcivec = direct_uhf.kernel((h1a, h1b), (eri_aa, eri_ab, eri_bb),
                                     h1a.shape[0], mol.nelec)
    dm1ref, dm2ref = direct_uhf.make_rdm12s(fcivec, h1a.shape[0], mol.nelec)
    t1, t2 = mycc.t1, mycc.t2
    l1, l2 = mycc.l1, mycc.l2
    rdm1 = make_rdm1(mycc, t1, t2, l1, l2)
    rdm2 = make_rdm2(mycc, t1, t2, l1, l2)
    print('dm1a', abs(dm1ref[0] - rdm1[0]).max())
    print('dm1b', abs(dm1ref[1] - rdm1[1]).max())
    print('dm2aa', abs(dm2ref[0] - rdm2[0]).max())
    print('dm2ab', abs(dm2ref[1] - rdm2[1]).max())
    print('dm2bb', abs(dm2ref[2] - rdm2[2]).max())
示例#4
0
fin.write("1000   20    1e-12   2      0\n")
fin.write("1200   20    1e-12   2      0\n")
fin.write("1600   20    1e-16   2      0\n")
fin.write("2000   20    1e-16   2      0\n")
fin.write("}\n")
fin.write("quiet = yes\n")
fin.write("}\n")
fin.close()

# run mps
subprocess.call(["../impsolver_dmet", "input_solver"])

# fci reference on solving impurity
h1fci = (h1emb[0], h1emb[1])
g2fci = (Vemb * 0.0, Vemb, Vemb * 0.0)
e, c = fcisolver.kernel(h1fci, g2fci, nemb, nelec_emb)
ci0 = np.random.rand(c.shape[0], c.shape[1])
ci0 /= np.linalg.norm(ci0)
#e, c = fcisolver.kernel(h1fci, g2fci, nemb, nelec_emb, ci0=ci0)
rdm1s, rdm2s = fcisolver.make_rdm12s(c, nemb, nelec_emb)
rdm1s = np.asarray(rdm1s).reshape(2 * nemb, nemb)
rdm2ab = rdm2s[1]
print "FCI energy: ", e

if ibath:
    # test the difference of rdms
    emps = np.loadtxt("./dump/energy.txt")
    print "Energy difference: ", emps - e

    rdm1mps = np.loadtxt("./dump/rdm1s.txt")
    print "RDM1 difference: ", np.linalg.norm(rdm1mps - rdm1s)
示例#5
0
        ['H', ( 0.,-1.    ,-1.   )],
        ['H', ( 1.,-0.5   , 0.   )],
        ['H', ( 0.,-1.    , 1.   )],
    ]
    mol.charge = 2
    mol.spin = 2
    mol.basis = '6-31g'
    mol.build()
    mf = scf.UHF(mol).run(init_guess='hcore', conv_tol=1.)
    ehf0 = mf.e_tot - mol.energy_nuc()
    mycc = uccsd.UCCSD(mf).run()
    mycc.solve_lambda()
    eri_aa = ao2mo.kernel(mf._eri, mf.mo_coeff[0])
    eri_bb = ao2mo.kernel(mf._eri, mf.mo_coeff[1])
    eri_ab = ao2mo.kernel(mf._eri, [mf.mo_coeff[0], mf.mo_coeff[0],
                                    mf.mo_coeff[1], mf.mo_coeff[1]])
    h1a = reduce(numpy.dot, (mf.mo_coeff[0].T, mf.get_hcore(), mf.mo_coeff[0]))
    h1b = reduce(numpy.dot, (mf.mo_coeff[1].T, mf.get_hcore(), mf.mo_coeff[1]))
    efci, fcivec = direct_uhf.kernel((h1a,h1b), (eri_aa,eri_ab,eri_bb),
                                     h1a.shape[0], mol.nelec)
    dm1ref, dm2ref = direct_uhf.make_rdm12s(fcivec, h1a.shape[0], mol.nelec)
    t1, t2 = mycc.t1, mycc.t2
    l1, l2 = mycc.l1, mycc.l2
    rdm1 = make_rdm1(mycc, t1, t2, l1, l2)
    rdm2 = make_rdm2(mycc, t1, t2, l1, l2)
    print('dm1a', abs(dm1ref[0] - rdm1[0]).max())
    print('dm1b', abs(dm1ref[1] - rdm1[1]).max())
    print('dm2aa', abs(dm2ref[0] - rdm2[0]).max())
    print('dm2ab', abs(dm2ref[1] - rdm2[1]).max())
    print('dm2bb', abs(dm2ref[2] - rdm2[2]).max())
示例#6
0
            h1e[-1,0] = 0
            #h1e[0,0] = 0.1
            #h1e[1,1] = 0.4
            #noise = np.random.randn(norb, norb)*0.0
            #noise += noise.T
            #h1e += noise
            h1e = (h1e, h1e)
            eri = np.zeros((norb,norb,norb,norb))
            for i in range(norb):
                eri[i,i,i,i] = 4
            g2e = (np.zeros((norb,)*4), eri,np.zeros((norb,)*4))
            rdm1, rdm2, e, z = ft_solver(h1e,g2e,fcisolver,norb,nelec,T,mu,m=80)
            e /= z
            rdm1 /=z
            rdm2 /=z
            e0, v = fcisolver.kernel(h1e,g2e,norb,nelec,nroots=1)
            #print e0
            rdm10,rdm20 = fcisolver.make_rdm12s(v,norb,nelec)
 
        #print rdm1[0]
        #print rdm10[0]
        
            print e/norb - e0/norb
            print np.linalg.norm(rdm1-rdm10)
            print np.linalg.norm(rdm2-rdm20)