Beispiel #1
0
    def test_phys(self):
        from cqcpy import integrals
        mo_coeff = self.mf.mo_coeff
        mol = self.mol
        nao = mo_coeff[0].shape[0]
        mo1 = mo_coeff[0][:,0].reshape((nao,1))
        mo2 = mo_coeff[0][:,1].reshape((nao,1))
        mo3 = mo_coeff[1][:,0].reshape((nao,1))
        mo4 = mo_coeff[1][:,1].reshape((nao,1))

        ref = integrals.get_chem(mol, mo1, mo3, mo2, mo4, anti=True).transpose((0,2,1,3))
        out = integrals.get_phys(mol, mo1, mo2, mo3, mo4, anti=True)
        diff = abs(ref[0,0,0,0] - out[0,0,0,0])
        self.assertTrue(diff < 1e-12)
Beispiel #2
0
    def test_cis(self):
        from pyscf import gto
        from pyscf.tdscf.rhf import scf

        # reference
        mol = gto.Mole()
        mol.build(
            atom='H 0 0 0; H 0 0 0.77',  # in Angstrom
            basis='631g', verbose=0)

        mf = scf.RHF(mol)
        mf.conv_tol_grad = 1e-9
        Escf = mf.kernel()
        mf.verbose = 0
        tda = mf.TDA()
        tda.nstates = 6
        erefs = tda.kernel()[0]
        tda.singlet = False
        ereft = tda.kernel()[0]

        # run CIS calculation
        mos = mf.mo_coeff
        nmo = mos.shape[1]
        hcore = mf.get_hcore()
        ha = numpy.einsum('mp,mn,nq->pq', mos, hcore, mos)
        hb = ha.copy()
        I = integrals.get_phys(mol, mos, mos, mos, mos)

        N = mol.nelectron
        na = N//2
        nb = na
        basis = ci_utils.ucis_basis(nmo, na, nb, gs=False)
        nd = len(basis)

        H = numpy.zeros((nd, nd))
        const = -Escf + mol.energy_nuc()
        F = mf.get_fock()
        F = numpy.einsum('mp,mn,nq->pq', mos, F, mos)
        for i, b in enumerate(basis):
            for j, k in enumerate(basis):
                H[i, j] = ci_utils.ci_matrixel(
                    b[0], b[1], k[0], k[1], ha, hb, I, I, I, const)

        eout, v = numpy.linalg.eigh(H)
        eref = numpy.sort(numpy.concatenate((erefs, ereft)))
        diff = numpy.linalg.norm(eref - eout)
        self.assertTrue(diff < 1e-10)
Beispiel #3
0
    def test_cisd(self):
        from pyscf import gto, scf, ci

        mol = gto.M(
            atom='Be 0 0 0',
            basis='631g', verbose=0)
        mf = scf.RHF(mol)
        mf.conv_tol = 1e-12
        Escf = mf.kernel()
        myci = ci.CISD(mf).run()
        #print('RCISD correlation energy', myci.e_corr)
        ref = myci.e_corr

        # run naive CISD calculation
        mos = mf.mo_coeff
        nmo = mos.shape[1]
        hcore = mf.get_hcore()
        ha = numpy.einsum('mp,mn,nq->pq', mos, hcore, mos)
        hb = ha.copy()
        I = integrals.get_phys(mol, mos, mos, mos, mos)

        N = mol.nelectron
        na = N//2
        nb = na

        basis = ci_utils.ucisd_basis(nmo, na, nb)
        nd = len(basis)
        H = numpy.zeros((nd, nd))
        const = -Escf + mol.energy_nuc()
        for i, b in enumerate(basis):
            for j, k in enumerate(basis):
                H[i, j] = ci_utils.ci_matrixel(
                    b[0], b[1], k[0], k[1], ha, hb, I, I, I, const)

        eout, v = numpy.linalg.eigh(H)
        #print('RCISD correlation energy', eout[0])
        diff = abs(ref - eout[0])
        self.assertTrue(diff < 1e-12)
Beispiel #4
0
    def test_Be_plus(self):
        from pyscf import gto, scf, cc
        from cqcpy import integrals
        mol = gto.M(
            verbose = 0,
            atom = 'Be 0 0 0',
            basis = 'sto-3G',
            spin = 1, charge = 1)
        mf = scf.UHF(mol)
        mf.conv_tol = 1e-13
        Escf = mf.scf()
        mo_coeff = mf.mo_coeff
        mo_occ = mf.mo_occ
        mo_occa = mo_occ[0]
        mo_occb = mo_occ[1]
        moa = mf.mo_coeff[0]
        mob = mf.mo_coeff[1]
        oa = (mf.mo_coeff[0])[:,mo_occa>0]
        va = (mf.mo_coeff[0])[:,mo_occa==0]
        ob = (mf.mo_coeff[1])[:,mo_occb>0]
        vb = (mf.mo_coeff[1])[:,mo_occb==0]
        noa = oa.shape[1]
        nva = va.shape[1]
        nob = ob.shape[1]
        nvb = vb.shape[1]
        Iaaaa = integrals.get_phys(mol,moa,moa,moa,moa)
        Iaaaa = test_utils.make_two_e_blocks_full(Iaaaa,noa,nva,noa,nva,noa,nva,noa,nva)
        Ibbbb = integrals.get_phys(mol,mob,mob,mob,mob)
        Ibbbb = test_utils.make_two_e_blocks_full(Ibbbb,nob,nvb,nob,nvb,nob,nvb,nob,nvb)
        Iabab = integrals.get_phys(mol,moa,mob,moa,mob)
        Iabab = test_utils.make_two_e_blocks_full(Iabab,noa,nva,nob,nvb,noa,nva,nob,nvb)
        I = spin_utils.int_to_spin(Iaaaa, Ibbbb, Iabab, noa, nva, nob, nvb)
        I_ref = integrals.eri_blocks(mf)
        z = I.vvvv - I_ref.vvvv
        s = numpy.linalg.norm(z) < self.thresh
        err = "error in vvvv block"
        self.assertTrue(s,err)

        z = I.vvvo - I_ref.vvvo
        s = numpy.linalg.norm(z) < self.thresh
        err = "error in vvvo block"
        self.assertTrue(s,err)

        z = I.vovv - I_ref.vovv
        s = numpy.linalg.norm(z) < self.thresh
        err = "error in vovo block"
        self.assertTrue(s,err)

        z = I.vovo - I_ref.vovo
        s = numpy.linalg.norm(z) < self.thresh
        err = "error in vovo block"
        self.assertTrue(s,err)

        z = I.vvoo - I_ref.vvoo
        s = numpy.linalg.norm(z) < self.thresh
        err = "error in vvoo block"
        self.assertTrue(s,err)

        z = I.oovv - I_ref.oovv
        s = numpy.linalg.norm(z) < self.thresh
        err = "error in oovv block"
        self.assertTrue(s,err)

        z = I.vooo - I_ref.vooo
        s = numpy.linalg.norm(z) < self.thresh
        err = "error in vooo block"
        self.assertTrue(s,err)

        z = I.ooov - I_ref.ooov
        s = numpy.linalg.norm(z) < self.thresh
        err = "error in ooov block"
        self.assertTrue(s,err)

        z = I.oooo - I_ref.oooo
        s = numpy.linalg.norm(z) < self.thresh
        err = "error in oooo block"
        self.assertTrue(s,err)
Beispiel #5
0
mol = gto.M(atom='H 0 0 0; F 0 0 1.1', basis='631g')
mf = scf.RHF(mol)
mf.conv_tol_grad = 1e-9
Escf = mf.kernel()
print(Escf)
myci = ci.CISD(mf).run()
print('RCISD correlation energy', myci.e_corr)

# run naive CISD calculation
mos = mf.mo_coeff
nmo = mos.shape[1]
hcore = mf.get_hcore()
ha = numpy.einsum('mp,mn,nq->pq', mos, hcore, mos)
hb = ha.copy()
I = integrals.get_phys(mol, mos, mos, mos, mos)

N = mol.nelectron
N = mol.nelectron
na = N // 2
nb = na

basis = ci_utils.ucisd_basis(nmo, na, nb)
nd = len(basis)
H = numpy.zeros((nd, nd))
const = -Escf + mol.energy_nuc()
for i, b in enumerate(basis):
    for j, k in enumerate(basis):
        H[i, j] = ci_utils.ci_matrixel(b[0], b[1], k[0], k[1], ha, hb, I, I, I,
                                       const)