Exemple #1
0
def test_kuccsd_openshell():
    cell = gto.M(
        unit='B',
        a=[[0., 6.74027466, 6.74027466], [6.74027466, 0., 6.74027466],
           [6.74027466, 6.74027466, 0.]],
        mesh=[13] * 3,
        atom='''H 0 0 0
                  H 1.68506866 1.68506866 1.68506866
                  H 3.37013733 3.37013733 3.37013733''',
        basis=[[0, (1., 1.)], [0, (.5, 1.)]],
        verbose=1,
        charge=0,
        spin=1,
    )

    nmp = [3, 1, 1]
    # cell spin multiplied by nkpts
    cell.spin = cell.spin * 3

    # treating 3*1*1 supercell at gamma point
    supcell = super_cell(cell, nmp)
    umf = scf.UHF(supcell, exxdiv=None)
    umf.conv_tol = 1e-11
    ehf = umf.kernel()

    ucc = cc.UCCSD(umf)
    ucc.conv_tol = 1e-12
    ecc, t1, t2 = ucc.kernel()
    print('UHF energy (supercell) %.9f \n' % (float(ehf) / 3.))
    print('UCCSD correlation energy (supercell) %.9f \n' % (float(ecc) / 3.))
    assert abs(ehf / 3 - -1.003789445) < 1e-7
    assert abs(ecc / 3 - -0.029056542) < 1e-6

    # kpts calculations
    kpts = cell.make_kpts(nmp)
    kpts -= kpts[0]
    kmf = scf.KUHF(cell, kpts, exxdiv=None)
    kmf.conv_tol = 1e-11
    ehf = kmf.kernel()
    kcc = cc.KUCCSD(kmf)
    kcc.conv_tol = 1e-12
    ecc, t1, t2 = kcc.kernel()
    print('UHF energy (kpts) %.9f \n' % (float(ehf)))
    print('UCCSD correlation energy (kpts) %.9f \n' % (float(ecc)))
    assert abs(ehf - -1.003789445) < 1e-7
    assert abs(ecc - -0.029056542) < 1e-6
def test_kuccsd_supercell_vs_kpts_high_cost():
    cell = gto.M(
        unit = 'B',
        a = [[ 0.,          3.37013733,  3.37013733],
             [ 3.37013733,  0.,          3.37013733],
             [ 3.37013733,  3.37013733,  0.        ]],
        mesh = [13]*3,
        atom = '''He 0 0 0
                  He 1.68506866 1.68506866 1.68506866''',
        basis = [[0, (1., 1.)], [0, (.5, 1.)]],
        verbose = 0,
    )

    nmp = [3,3,1]

    # treating supercell at gamma point
    supcell = super_cell(cell,nmp)

    gmf  = scf.UHF(supcell,exxdiv=None)
    ehf  = gmf.kernel()
    gcc  = cc.UCCSD(gmf)
    ecc, t1, t2 = gcc.kernel()
    print('UHF energy (supercell) %f \n' % (float(ehf)/numpy.prod(nmp)))
    print('UCCSD correlation energy (supercell) %f \n' % (float(ecc)/numpy.prod(nmp)))
    assert abs(ehf / 9 - -4.343308413289) < 1e-7
    assert abs(ecc / 9 - -0.009470753047083676) < 1e-6

    # treating mesh of k points

    kpts  = cell.make_kpts(nmp)
    kpts -= kpts[0]
    kmf   = scf.KUHF(cell,kpts,exxdiv=None)
    ehf   = kmf.kernel()
    kcc   = cc.KUCCSD(kmf)
    ecc, t1, t2 = kcc.kernel()

    print('UHF energy (kpts) %f \n' % ehf)
    print('UCCSD correlation energy (kpts) %f \n' % ecc)
    assert abs(ehf - -4.343308413289) < 1e-7
    assert abs(ecc - -0.009470753047083676) < 1e-6
Exemple #3
0
mf = scf.RHF(cell, kpt=kpt, exxdiv=None)
ehf = mf.kernel()

mycc = cc.RCCSD(mf).run()
print("RCCSD energy (per unit cell) at k-point =", mycc.e_tot)
dm1 = mycc.make_rdm1()
dm2 = mycc.make_rdm2()
nmo = mf.mo_coeff.shape[1]
eri_mo = mf.with_df.ao2mo(mf.mo_coeff, kpts=kpt).reshape([nmo]*4)
h1 = reduce(numpy.dot, (mf.mo_coeff.conj().T, mf.get_hcore(), mf.mo_coeff))
e_tot = numpy.einsum('ij,ji', h1, dm1) + numpy.einsum('ijkl,jilk', eri_mo, dm2)*.5 + mf.energy_nuc()
print("RCCSD energy based on CCSD density matrices =", e_tot.real)


mf = scf.addons.convert_to_uhf(mf)
mycc = cc.UCCSD(mf).run()
print("UCCSD energy (per unit cell) at k-point =", mycc.e_tot)
dm1a, dm1b = mycc.make_rdm1()
dm2aa, dm2ab, dm2bb = mycc.make_rdm2()
nmo = dm1a.shape[0]
eri_aa = mf.with_df.ao2mo(mf.mo_coeff[0], kpts=kpt).reshape([nmo]*4)
eri_bb = mf.with_df.ao2mo(mf.mo_coeff[1], kpts=kpt).reshape([nmo]*4)
eri_ab = mf.with_df.ao2mo((mf.mo_coeff[0],mf.mo_coeff[0],mf.mo_coeff[1],mf.mo_coeff[1]), kpts=kpt).reshape([nmo]*4)
hcore = mf.get_hcore()
h1a = reduce(numpy.dot, (mf.mo_coeff[0].conj().T, hcore, mf.mo_coeff[0]))
h1b = reduce(numpy.dot, (mf.mo_coeff[1].conj().T, hcore, mf.mo_coeff[1]))
e_tot = (numpy.einsum('ij,ji', h1a, dm1a) +
         numpy.einsum('ij,ji', h1b, dm1b) +
         numpy.einsum('ijkl,jilk', eri_aa, dm2aa)*.5 +
         numpy.einsum('ijkl,jilk', eri_ab, dm2ab)    +
         numpy.einsum('ijkl,jilk', eri_bb, dm2bb)*.5 + mf.energy_nuc())
Exemple #4
0
ehf = kmf.kernel(dmk)

kcc = cc.KUCCSD(kmf)
ecc, t1, t2 = kcc.kernel()

print('========================================')
print('UHF energy (kpts) %f \n' % (float(ehf)))
print('UCCSD correlation energy (kpts) %f \n' % (float(ecc)))
print('========================================')

# Gamma point supercell calculation
supcell = super_cell(cell, nmp)

dms = np.zeros([2, supcell.nao_nr(), supcell.nao_nr()])
for i in range(nkpts):
    for j in range(2):
        dms[0][j + i * nao][j + i * nao] = 0.5
        dms[1][j + i * nao + nao_half][j + i * nao + nao_half] = 0.5

gmf = scf.UHF(supcell, exxdiv=None).density_fit()
gmf.chkfile = 'supcell.chk'
ehf = gmf.kernel(dms)

gcc = cc.UCCSD(gmf)
ecc, t1, t2 = gcc.kernel()
print('========================================')
print('UHF energy (supercell) %f' % (float(ehf) / nk))
print('UCCSD correlation energy (supercell) %f' % (float(ecc) / nk))
print('========================================')
    verbose=1,
    charge=0,
    spin=1,
)

nmp = [3, 1, 1]
# cell spin multiplied by nkpts
cell.spin = cell.spin * 3

# treating 3*1*1 supercell at gamma point
supcell = super_cell(cell, nmp)
umf = scf.UHF(supcell, exxdiv=None)
umf.conv_tol = 1e-11
ehf = umf.kernel()

ucc = cc.UCCSD(umf)
ucc.conv_tol = 1e-12
ecc, t1, t2 = ucc.kernel()
print('UHF energy (supercell) %.9f \n' % (float(ehf) / 3.))
print('UCCSD correlation energy (supercell) %.9f \n' % (float(ecc) / 3.))

# kpts calculations
kpts = cell.make_kpts(nmp)
kpts -= kpts[0]
kmf = scf.KUHF(cell, kpts, exxdiv=None)
kmf.conv_tol = 1e-11
ehf = kmf.kernel()
kcc = cc.KUCCSD(kmf)
kcc.conv_tol = 1e-12
ecc, t1, t2 = kcc.kernel()
print('UHF energy (kpts) %.9f \n' % (float(ehf)))