示例#1
0
 def test_ragf2_2_2(self):
     ragf2 = agf2.RAGF2(self.rhf, nmom=(1, 1), verbose=False, etol=1e-7)
     ragf2.run()
     ragf2 = agf2.RAGF2(self.rhf,
                        nmom=(2, 2),
                        dm0=ragf2.rdm1,
                        damping=True,
                        verbose=False)
     ragf2.run()
     self.assertTrue(ragf2.converged)
     self.assertAlmostEqual(np.trace(ragf2.rdm1), self.m.nelec, 6)
     self.assertAlmostEqual(ragf2.e_1body, -74.91982717846034, 6)
     self.assertAlmostEqual(ragf2.e_2body, -0.08303692458141082, 6)
     self.assertAlmostEqual(ragf2.e_hf, -74.9611711378676, 6)
     self.assertAlmostEqual(ragf2.e_corr, -0.041692965174149776, 6)
     self.assertAlmostEqual(ragf2.e_tot, -75.00286410304174, 6)
示例#2
0
 def test_get_fock(self):
     ragf2 = agf2.RAGF2(self.rhf, nmom=(2, 2), verbose=False)
     self.assertAlmostEqual(
         np.max(np.absolute(ragf2.get_fock() - self.rhf.fock_mo)), 0, 8)
     self.assertAlmostEqual(
         np.max(
             np.absolute(
                 ragf2.get_fock(self.rhf.rdm1_mo) - self.rhf.fock_mo)), 0,
         8)
示例#3
0
 def setUpClass(self):
     import warnings
     warnings.simplefilter('ignore', FutureWarning)
     self.m = mol.Molecule(atoms='O 0 0 0; H 0 0 1; H 0 1 0',
                           basis='sto-3g')
     self.rhf = hf.RHF(self.m).run()
     self.gf2 = agf2.RAGF2(self.rhf, nmom=(2, 3), verbose=False,
                           maxiter=3).run()
     self.se = self.gf2.se
     self.fock = self.gf2.get_fock()
示例#4
0
 def test_ragf2_1_1(self):
     ragf2 = agf2.RAGF2(self.rhf, nmom=(1, 1), verbose=False, etol=1e-7)
     ragf2.run()
     self.assertTrue(ragf2.converged)
     self.assertAlmostEqual(ragf2.e_mp2, self.e_mp2, 3)
     self.assertAlmostEqual(np.trace(ragf2.rdm1), self.m.nelec, 6)
     self.assertAlmostEqual(ragf2.e_1body, -74.92304938877345, 6)
     self.assertAlmostEqual(ragf2.e_2body, -0.08160143359098293, 6)
     self.assertAlmostEqual(ragf2.e_hf, -74.9611711378676, 6)
     self.assertAlmostEqual(ragf2.e_corr, -0.043479684496844584, 6)
     self.assertAlmostEqual(ragf2.e_tot, -75.00465082236444, 6)
示例#5
0
 def test_ip(self):
     ragf2 = agf2.RAGF2(self.rhf, nmom=(2, 2), verbose=False, etol=1e-7)
     ragf2.run()
     w, v = ragf2.se.eig(ragf2.get_fock())
     arg = np.argmax(w[w < ragf2.chempot])
     e1, v1 = -w[w < ragf2.chempot][arg], v[:,
                                            w < ragf2.chempot][:,
                                                               arg][:ragf2.
                                                                    nphys]
     e2, v2 = ragf2.ip
     self.assertAlmostEqual(e1, e2, 8)
     self.assertAlmostEqual(np.linalg.norm(v1), np.linalg.norm(v2), 8)
示例#6
0
 def test_ea(self):
     opt_ragf2 = mpi.agf2.OptRAGF2(self.rhf_df, verbose=False, etol=1e-7)
     opt_ragf2.run()
     ragf2 = agf2.RAGF2(self.rhf, nmom=(None,0), verbose=False, etol=1e-7)
     ragf2.run()
     w, v = opt_ragf2.se.eig(opt_ragf2.get_fock())
     arg = np.argmin(w[w >= opt_ragf2.chempot])
     e1, v1 = w[w >= opt_ragf2.chempot][arg], v[:,w >= opt_ragf2.chempot][:,arg][:opt_ragf2.nphys]
     e2, v2 = opt_ragf2.ea
     e3, v3 = ragf2.ea
     self.assertAlmostEqual(e1, e2, 8)
     self.assertAlmostEqual(e2, e3, 4)
     self.assertAlmostEqual(np.linalg.norm(v1), np.linalg.norm(v2), 8)
     self.assertAlmostEqual(np.linalg.norm(v2), np.linalg.norm(v3), 4)
示例#7
0
 def test_ragf2(self):
     # Dependent upon RAGF2 passing tests
     dm0 = self.rhf.rdm1_mo
     opt_ragf2 = mpi.agf2.OptRAGF2(self.rhf_df, dm0=dm0, verbose=False, etol=1e-7)
     opt_ragf2.run()
     ragf2 = agf2.RAGF2(self.rhf, nmom=(None,0), verbose=False, etol=1e-7)
     ragf2.run()
     self.assertAlmostEqual(ragf2.e_mp2, opt_ragf2.e_mp2, 4)
     self.assertAlmostEqual(np.trace(ragf2.rdm1), np.trace(opt_ragf2.rdm1), 4)
     self.assertAlmostEqual(ragf2.e_1body, opt_ragf2.e_1body, 3)
     self.assertAlmostEqual(ragf2.e_2body, opt_ragf2.e_2body, 3)
     self.assertAlmostEqual(ragf2.e_hf, opt_ragf2.e_hf, 3)
     self.assertAlmostEqual(ragf2.e_corr, opt_ragf2.e_corr, 3)
     self.assertAlmostEqual(ragf2.e_tot, opt_ragf2.e_tot, 3)
     self.assertAlmostEqual(ragf2.chempot, opt_ragf2.chempot, 4)
示例#8
0
 def test_ragf2_None_3(self):
     ragf2 = agf2.RAGF2(self.rhf,
                        nmom=(None, 3),
                        damping=True,
                        delay_damping=5,
                        verbose=False,
                        etol=1e-7)
     ragf2.run()
     self.assertTrue(ragf2.converged)
     self.assertAlmostEqual(ragf2.e_mp2, self.e_mp2, 6)
     self.assertAlmostEqual(np.trace(ragf2.rdm1), self.m.nelec, 6)
     self.assertAlmostEqual(ragf2.e_1body, -74.92061986016013, 6)
     self.assertAlmostEqual(ragf2.e_2body, -0.08225785253628955, 6)
     self.assertAlmostEqual(ragf2.e_hf, -74.9611711378676, 6)
     self.assertAlmostEqual(ragf2.e_corr, -0.04170657482882234, 6)
     self.assertAlmostEqual(ragf2.e_tot, -75.00287771269642, 6)
示例#9
0
from auxgf.util import Timer

timer = Timer()


# Build the Molecule object:
m = mol.Molecule(atoms='H 0 0 0; Li 0 0 1.64', basis='cc-pvdz')

# Build the RHF object:
rhf = hf.RHF(m)
rhf.run()

# Build the AGF2 object and run it for a few different settings:
# Simple RAGF2(1,1) setup without damping:
opts = dict(verbose=False, nmom=(1,1), damping=0.0)
gf2 = agf2.RAGF2(rhf, **opts)
gf2.run()
print('RAGF2(1,1): converged = %s  iterations = %d  E(corr) = %.12f' % (gf2.converged, gf2.iteration, gf2.e_corr))

# Tighten the Fock loop and increase to RAGF2(2,2):
opts.update(dict(nmom=(2,2), dtol=1e-10, diis_space=10, fock_maxiter=100, fock_maxruns=25))
gf2 = agf2.RAGF2(rhf, **opts)
gf2.run()
print('RAGF2(2,2): converged = %s  iterations = %d  E(corr) = %.12f' % (gf2.converged, gf2.iteration, gf2.e_corr))

# Tighten the AGF2 loop and add some damping:
opts.update(dict(etol=1e-7, maxiter=100, damping=0.25))
gf2 = agf2.RAGF2(rhf, **opts)
gf2.run()
print('RAGF2(2,2): converged = %s  iterations = %d  E(corr) = %.12f' % (gf2.converged, gf2.iteration, gf2.e_corr))
示例#10
0
# Build the grid:
refq = grids.ReFqGrid(2**8, minpt=-5, maxpt=5, eta=0.1)

# Build the Hartree-Fock Green's function:
g_hf = aux.Aux(np.zeros(0), np.zeros((rhf.nao, 0)), chempot=rhf.chempot)

# Build the MP2 self-energy:
s_mp2 = aux.build_rmp2_iter(g_hf, rhf.fock_mo, rhf.eri_mo)

# Build the second-iteration Green's function, which corresponds to the QP spectrum at MP2 level or G^(2):
e, c = s_mp2.eig(rhf.fock_mo)
g_2 = g_hf.new(e, c[:rhf.nao])  # inherits g_hf.chempot

# Run an RAGF2 calcuation and get the converged Green's function and self-energy (we also use the RAGF2 density):
gf2 = agf2.RAGF2(rhf, nmom=(2, 3), verbose=False)
gf2.run()
s_gf2 = gf2.se
e, c = s_gf2.eig(rhf.get_fock(gf2.rdm1, basis='mo'))
g_gf2 = s_gf2.new(e, c[:rhf.nao])


# For each Green's function, get the spectrum (Aux.as_spectrum only represents the function on a grid, we must
# also provide ordering='retarded' and then refactor):
def aux_to_spectrum(g):
    a = g.as_spectrum(refq, ordering='retarded')
    a = a.imag / np.pi
    a = a.trace(axis1=1, axis2=2)
    return a

示例#11
0
 def test_rmp2(self):
     ragf2 = agf2.RAGF2(self.rhf, nmom=(10, 10), verbose=False)
     self.assertAlmostEqual(ragf2.e_1body, self.rhf.e_tot, 8)
     self.assertAlmostEqual(ragf2.e_2body, self.e_mp2, 8)
     self.assertAlmostEqual(ragf2.e_tot, self.rhf.e_tot + self.e_mp2, 8)
     self.assertAlmostEqual(ragf2.e_mp2, self.e_mp2, 8)
示例#12
0
from pyscf.lib.linalg_helper import davidson
from auxgf import mol, hf, cc, aux, agf2
from auxgf.util import Timer

timer = Timer()


# Build the Molecule object:
m = mol.Molecule(atoms='H 0 0 0; Li 0 0 1.64', basis='cc-pvdz')

# Build the RHF object:
rhf = hf.RHF(m)
rhf.run()

# Run some RAGF2 calculations:
gf2_a = agf2.RAGF2(rhf, nmom=(1,1), verbose=False).run() 
gf2_b = agf2.RAGF2(rhf, nmom=(2,2), verbose=False).run()
gf2_c = agf2.RAGF2(rhf, nmom=(3,3), verbose=False).run()

# Method 1: using very little aux.Aux functionality
f_ext = np.block(([[rhf.get_fock(gf2_a.rdm1, basis='mo'), gf2_a.se.v],
                   [gf2_a.se.v.T,                         np.diag(gf2_a.se.e)]]))
e, c = np.linalg.eigh(f_ext)
c = c[:rhf.nao]
occ, vir = e < gf2_a.chempot, e >= gf2_a.chempot
e_hoqmo, e_luqmo = e[occ][-1], e[vir][0]  # only works because the eigenvalues are sorted
v_hoqmo, v_luqmo = c[:,occ][:,-1], c[:,vir][:,0]
print('RAGF2(1,1):')
print('IP = %.6f  weight = %.6f' % (-e_hoqmo, np.linalg.norm(v_hoqmo)))
print('EA = %.6f  weight = %.6f' % (e_luqmo, np.linalg.norm(v_luqmo)))
print('Gap = %.6f' % (e_luqmo - e_hoqmo))