Esempio n. 1
0
    def test_init(self):
        from pyscf.pbc import dft
        cell_u = cell.copy()
        cell_u.spin = 2
        self.assertTrue(isinstance(pscf.RKS  (cell  ), dft.rks.RKS    ))
        self.assertTrue(isinstance(pscf.RKS  (cell_u), dft.roks.ROKS  ))
        self.assertTrue(isinstance(pscf.UKS  (cell  ), dft.uks.UKS    ))
        self.assertTrue(isinstance(pscf.ROKS (cell  ), dft.roks.ROKS  ))
        self.assertTrue(isinstance(pscf.KS   (cell  ), dft.rks.RKS    ))
        self.assertTrue(isinstance(pscf.KS   (cell_u), dft.uks.UKS    ))
        self.assertTrue(isinstance(pscf.KRKS (cell  ), dft.krks.KRKS  ))
        self.assertTrue(isinstance(pscf.KRKS (cell_u), dft.krks.KRKS  ))
        self.assertTrue(isinstance(pscf.KUKS (cell  ), dft.kuks.KUKS  ))
        self.assertTrue(isinstance(pscf.KROKS(cell  ), dft.kroks.KROKS))
        self.assertTrue(isinstance(pscf.KKS  (cell  ), dft.krks.KRKS  ))
        self.assertTrue(isinstance(pscf.KKS  (cell_u), dft.kuks.KUKS  ))

        self.assertTrue(isinstance(pscf.RHF  (cell  ), pscf.hf.RHF     ))
        self.assertTrue(isinstance(pscf.RHF  (cell_u), pscf.rohf.ROHF  ))
        self.assertTrue(isinstance(pscf.KRHF (cell  ), pscf.khf.KRHF   ))
        self.assertTrue(isinstance(pscf.KRHF (cell_u), pscf.khf.KRHF   ))
        self.assertTrue(isinstance(pscf.UHF  (cell  ), pscf.uhf.UHF    ))
        self.assertTrue(isinstance(pscf.KUHF (cell_u), pscf.kuhf.KUHF  ))
        self.assertTrue(isinstance(pscf.GHF  (cell  ), pscf.ghf.GHF    ))
        self.assertTrue(isinstance(pscf.KGHF (cell_u), pscf.kghf.KGHF  ))
        self.assertTrue(isinstance(pscf.ROHF (cell  ), pscf.rohf.ROHF  ))
        self.assertTrue(isinstance(pscf.ROHF (cell_u), pscf.rohf.ROHF  ))
        self.assertTrue(isinstance(pscf.KROHF(cell  ), pscf.krohf.KROHF))
        self.assertTrue(isinstance(pscf.KROHF(cell_u), pscf.krohf.KROHF))
        self.assertTrue(isinstance(pscf.HF   (cell  ), pscf.hf.RHF     ))
        self.assertTrue(isinstance(pscf.HF   (cell_u), pscf.uhf.UHF    ))
        self.assertTrue(isinstance(pscf.KHF  (cell  ), pscf.khf.KRHF   ))
        self.assertTrue(isinstance(pscf.KHF  (cell_u), pscf.kuhf.KUHF  ))
Esempio n. 2
0
    def test_small_system(self):
        mol = pgto.Cell(atom='H 0 0 0;',
                        a=[[3, 0, 0], [0, 3, 0], [0, 0, 3]],
                        basis=[[0, [1, 1]]],
                        spin=1,
                        verbose=7,
                        output='/dev/null')
        mf = pscf.KUHF(mol, kpts=[[0., 0., 0.]]).run()
        self.assertAlmostEqual(mf.e_tot, -0.10439957735616917, 8)

        mol = pgto.Cell(atom='He 0 0 0;',
                        a=[[3, 0, 0], [0, 3, 0], [0, 0, 3]],
                        basis=[[0, [1, 1]]],
                        verbose=7,
                        output='/dev/null')
        mf = pscf.KUHF(mol, kpts=[[0., 0., 0.]]).run()
        self.assertAlmostEqual(mf.e_tot, -2.2719576422665635, 8)
Esempio n. 3
0
    def test_uhf_exx_ewald(self):
        mf = pscf.UHF(cell, exxdiv='ewald')
        mf.init_guess = 'hcore'
        e1 = mf.kernel()
        self.assertAlmostEqual(e1, -4.3511582287379111, 8)
        self.assertTrue(mf.mo_coeff[0].dtype == numpy.double)

        kmf = pscf.KUHF(cell, [[0,0,0]], exxdiv='ewald')
        kmf.init_guess = 'hcore'
        e0 = kmf.kernel()
        self.assertTrue(numpy.allclose(e0,e1))

        # test bands
        numpy.random.seed(1)
        kpts_band = numpy.random.random((2,3))
        e1a, e1b = mf.get_bands(kpts_band)[0]
        e0a, e0b = kmf.get_bands(kpts_band)[0]
        self.assertAlmostEqual(abs(e0a[0]-e1a[0]).max(), 0, 5)
        self.assertAlmostEqual(abs(e0a[1]-e1a[1]).max(), 0, 5)
        self.assertAlmostEqual(abs(e0b[0]-e1b[0]).max(), 0, 5)
        self.assertAlmostEqual(abs(e0b[1]-e1b[1]).max(), 0, 5)
        self.assertAlmostEqual(lib.finger(e1a[0]), -6.2986775452228283, 5)
        self.assertAlmostEqual(lib.finger(e1a[1]), -7.6616273746782362, 5)

        numpy.random.seed(1)
        k = numpy.random.random(3)
        mf = pscf.UHF(cell, k, exxdiv='ewald')
        e1 = mf.kernel()
        self.assertAlmostEqual(e1, -4.2048655827967139, 8)
        self.assertTrue(mf.mo_coeff[0].dtype == numpy.complex128)

        kmf = pscf.KUHF(cell, k, exxdiv='ewald')
        e0 = kmf.kernel()
        self.assertTrue(numpy.allclose(e0,e1))

        # test bands
        numpy.random.seed(1)
        kpts_band = numpy.random.random((2,3))
        e1a, e1b = mf.get_bands(kpts_band)[0]
        e0a, e0b = kmf.get_bands(kpts_band)[0]
        self.assertAlmostEqual(abs(e0a[0]-e1a[0]).max(), 0, 5)
        self.assertAlmostEqual(abs(e0a[1]-e1a[1]).max(), 0, 5)
        self.assertAlmostEqual(abs(e0b[0]-e1b[0]).max(), 0, 5)
        self.assertAlmostEqual(abs(e0b[1]-e1b[1]).max(), 0, 5)
        self.assertAlmostEqual(lib.finger(e1a[0]), -6.8312867098806249, 5)
        self.assertAlmostEqual(lib.finger(e1a[1]), -6.1120214505413086, 5)
Esempio n. 4
0
    def test_kuhf_stability(self):
        kumf = pscf.KUHF(cell, kpts, exxdiv='ewald').run(conv_tol=1e-12)
        mo_i, mo_e = kumf.stability(internal=True, external=True)
        self.assertAlmostEqual(abs(kumf.mo_coeff[0][0]-mo_i[0][0]).max(), 0, 9)
        self.assertAlmostEqual(abs(kumf.mo_coeff[1][0]-mo_i[1][0]).max(), 0, 9)

        hop2, hdiag2 = stability._gen_hop_uhf_external(kumf)
        self.assertAlmostEqual(lib.fp(hdiag2), 10.977759629315884, 7)
        self.assertAlmostEqual(lib.fp(hop2(hdiag2)), 86.425042652868, 5)
Esempio n. 5
0
    def test_he(self):
        cell = gto.Cell()
        cell.atom = '''
        C 0.000000000000   0.000000000000   0.000000000000
        C 1.685068664391   1.685068664391   1.685068664391
        '''
        cell.basis = {'C': [[0, (0.8, 1.0)], [1, (1.0, 1.0)]]}
        cell.pseudo = 'gth-pade'
        cell.a = '''
        0.000000000, 3.370137329, 3.370137329
        3.370137329, 0.000000000, 3.370137329
        3.370137329, 3.370137329, 0.000000000'''
        cell.unit = 'B'
        cell.verbose = 5
        cell.build()

        nmp = [1, 1, 2]
        '''
        # treating 1*1*2 supercell at gamma point
        supcell = super_cell(cell,nmp)
        gmf  = scf.UHF(supcell,exxdiv=None)
        ehf  = gmf.kernel()
        gcc  = cc.UCCSD(gmf)
        gcc.conv_tol=1e-12
        gcc.conv_tol_normt=1e-10
        gcc.max_cycle=250
        ecc, t1, t2 = gcc.kernel()
        print('UHF energy (supercell) %.7f \n' % (float(ehf)/2.))
        print('UCCSD correlation energy (supercell) %.7f \n' % (float(ecc)/2.))

        #eom = eom_uccsd.EOMIP(gcc)
        #e1, v = eom.ipccsd(nroots=2)
        #eom = eom_uccsd.EOMEA(gcc)
        #e2, v = eom.eaccsd(nroots=2, koopmans=True)
        '''
        # Running HF and CCSD with 1x1x2 Monkhorst-Pack k-point mesh
        kmf = scf.KUHF(cell, kpts=cell.make_kpts(nmp), exxdiv=None)
        ehf2 = kmf.kernel()

        mycc = cc.KUCCSD(kmf)
        mycc.conv_tol = 1e-7
        mycc.conv_tol_normt = 1e-7
        mycc.max_cycle = 250
        ecc2, t1, t2 = mycc.kernel()
        print('UHF energy %.7f \n' % (float(ehf2)))
        print('UCCSD correlation energy  %.7f \n' % (float(ecc2)))

        kptlist = cell.make_kpts(nmp)
        eom = EOMIP(mycc)
        e1_obt, v = eom.ipccsd(nroots=2, kptlist=[0])
        eom = EOMEA(mycc)
        e2_obt, v = eom.eaccsd(nroots=2, koopmans=True, kptlist=[0])
        print(e1_obt)
        print(e2_obt)
Esempio n. 6
0
    def test_eris(self):
        numpy.random.seed(1)
        kpts = cell.make_kpts([1,1,3])
        kmf = scf.KUHF(cell, kpts=kpts, exxdiv=None)
        nmo = cell.nao_nr()
        kmf.mo_occ = numpy.zeros((2,3,nmo))
        kmf.mo_occ[0,:,:3] = 1
        kmf.mo_occ[1,:,:1] = 1
        kmf.mo_energy = (numpy.arange(nmo) +
                         numpy.random.random((2,3,nmo)) * .3)
        kmf.mo_energy[kmf.mo_occ == 0] += 2

        kmf.mo_coeff = (numpy.random.random((2,3,nmo,nmo)) +
                        numpy.random.random((2,3,nmo,nmo))*1j - .5-.5j)

        mycc = kccsd_uhf.UCCSD(kmf)
        eris = mycc.ao2mo()

        self.assertAlmostEqual(lib.finger(eris.fock[0]), 0.53719738596848132 +0.83031462049142502j, 11)
        self.assertAlmostEqual(lib.finger(eris.fock[1]), 0.043623927844025398+0.20815796288019522j, 11)

        self.assertAlmostEqual(lib.finger(eris.oooo), 0.10126616996580763    -0.89787173918481156j  , 11)
        self.assertAlmostEqual(lib.finger(eris.ooov), -0.035814310241888067  +0.20393025075274804j  , 11)
        self.assertAlmostEqual(lib.finger(eris.oovv), -0.032378345849800663  +0.015060519910448879j , 11)
        self.assertAlmostEqual(lib.finger(eris.ovov), 0.017919215232962762   -0.37180556037878837j  , 11)
        self.assertAlmostEqual(lib.finger(eris.voov), -0.33038865500581482   +0.18384096784449852j  , 11)
        self.assertAlmostEqual(lib.finger(eris.vovv), 0.078104278754223946   +0.0004014143354997223j, 11)
        self.assertAlmostEqual(lib.finger(eris.vvvv), -0.0199910973368542    -0.0019864189992825137j, 11)

        self.assertAlmostEqual(lib.finger(eris.OOOO), 0.022687859086726745   +0.0076542690105189095j, 11)
        self.assertAlmostEqual(lib.finger(eris.OOOV), -0.024119030579269278  -0.15249100640417029j  , 11)
        self.assertAlmostEqual(lib.finger(eris.OOVV), 0.085942751462484687   -0.27088394382044989j  , 11)
        self.assertAlmostEqual(lib.finger(eris.OVOV), 0.35291244981540776    +0.080119865729794376j , 11)
        self.assertAlmostEqual(lib.finger(eris.VOOV), 0.0045484393536995267  +0.0094123990059577414j, 11)
        self.assertAlmostEqual(lib.finger(eris.VOVV), -0.28341581692294759   +0.0022174023470048921j, 11)
        self.assertAlmostEqual(lib.finger(eris.VVVV), 0.96007536729340814    -0.019410945571596398j , 11)

        self.assertAlmostEqual(lib.finger(eris.ooOO), -0.32831508979976765   -0.32180378432620471j  , 11)
        self.assertAlmostEqual(lib.finger(eris.ooOV), 0.33617152217704632    -0.34130555912360216j  , 11)
        self.assertAlmostEqual(lib.finger(eris.ooVV), -0.00011230004797088339-1.2850251519380604j   , 11)
        self.assertAlmostEqual(lib.finger(eris.ovOV), 0.1365118156144336     +0.16999367231786541j  , 11)
        self.assertAlmostEqual(lib.finger(eris.voOV), 0.19736044623396901    -0.047060848969879901j , 11)
        self.assertAlmostEqual(lib.finger(eris.voVV), 0.44513499758124858    +0.06343379901453805j  , 11)
        self.assertAlmostEqual(lib.finger(eris.vvVV), -0.070971875998391304  -0.31253893124900545j  , 11)

        #self.assertAlmostEqual(lib.finger(eris.OOoo), 0.031140414688898856   -0.23913617484062258j  , 11)
        self.assertAlmostEqual(lib.finger(eris.OOov), 0.20355552926191381    +0.18712171841650935j  , 11)
        self.assertAlmostEqual(lib.finger(eris.OOvv), 0.070789122903945706   -0.013360818695166678j , 11)
        #self.assertAlmostEqual(lib.finger(eris.OVov), 0.38230103404493437    -0.019845885264560274j , 11)
        #self.assertAlmostEqual(lib.finger(eris.VOov), 0.081760186267865437   -0.052409714443657308j , 11)
        self.assertAlmostEqual(lib.finger(eris.VOvv), -0.036061642075282056  +0.019284185856121634j , 11)
Esempio n. 7
0
    def test_kuhf_smearing(self):
        mf = pscf.KUHF(cell, cell.make_kpts([2,1,1]))
        nkpts = len(mf.kpts)
        pscf.addons.smearing_(mf, 0.1, 'fermi')
        mo_energy_kpts = numpy.array([numpy.arange(nao)*.2+numpy.cos(i+.5)*.1
                                      for i in range(nkpts)])
        mo_energy_kpts = numpy.array([mo_energy_kpts,
                                      mo_energy_kpts+numpy.cos(mo_energy_kpts)*.02])
        occ = mf.get_occ(mo_energy_kpts)
        self.assertAlmostEqual(mf.entropy, 6.1803390081500869/2, 9)

        mf.smearing_method = 'gauss'
        occ = mf.get_occ(mo_energy_kpts)
        self.assertAlmostEqual(mf.entropy, 0.9554526863670467/2, 9)
Esempio n. 8
0
def copy_mf(mf, cell):
    if mf.__class__.__name__ == 'KRHF':
        mf1 = scf.KRHF(cell)
    elif mf.__class__.__name__ == 'KUHF':
        mf1 = scf.KUHF(cell)
    elif mf.__class__.__name__ == 'KRKS':
        mf1 = dft.KRKS(cell)
        mf1.xc = mf.xc
    elif mf.__class__.__name__ == 'KUKS':
        mf1 = dft.KUKS(cell)
        mf1.xc = mf.xc
    mf1.kpts = mf.kpts
    mf1.exxdiv = getattr(mf, 'exxdiv', None)
    mf1.conv_tol = mf.conv_tol
    mf1.conv_tol_grad = mf.conv_tol_grad
    return mf1
Esempio n. 9
0
    def test_init_guess_by_chkfile(self):
        np.random.seed(1)
        k = np.random.random(3)
        mf = pscf.KUHF(cell, [k], exxdiv='vcut_sph')
        mf.max_cycle = 1
        mf.diis = None
        e1 = mf.kernel()
        self.assertAlmostEqual(e1, -3.3058403617753886, 9)

        mf1 = pscf.UHF(cell, exxdiv='vcut_sph')
        mf1.chkfile = mf.chkfile
        mf1.init_guess = 'chkfile'
        mf1.diis = None
        mf1.max_cycle = 1
        e1 = mf1.kernel()
        self.assertAlmostEqual(e1, -3.4204798298887615, 9)
        self.assertTrue(mf1.mo_coeff[0].dtype == np.double)
Esempio n. 10
0
    def test_init_guess_by_chkfile(self):
        np.random.seed(1)
        k = np.random.random(3)
        mf = pscf.KUHF(cell, [k], exxdiv='vcut_sph')
        mf.max_cycle = 1
        mf.diis = None
        e1 = mf.kernel()
        self.assertAlmostEqual(e1, -3.4070772194665477, 9)

        mf1 = pscf.UHF(cell, exxdiv='vcut_sph')
        mf1.chkfile = mf.chkfile
        mf1.init_guess = 'chkfile'
        mf1.diis = None
        mf1.max_cycle = 1
        e1 = mf1.kernel()
        self.assertAlmostEqual(e1, -3.4272925247351256, 9)
        self.assertTrue(mf1.mo_coeff[0].dtype == np.double)
Esempio n. 11
0
    def test_kuhf_vs_uhf(self):
        np.random.seed(1)
        k = np.random.random(3)
        mf = pscf.UHF(cell, k, exxdiv='vcut_sph')
        dm = mf.get_init_guess(key='1e')

        mf.max_cycle = 1
        mf.diis = None
        e1 = mf.kernel(dm)

        nao = cell.nao
        kmf = pscf.KUHF(cell, [k], exxdiv='vcut_sph')
        kmf.max_cycle = 1
        kmf.diis = None
        e2 = kmf.kernel(dm.reshape(2, 1, nao, nao))
        self.assertAlmostEqual(e1, e2, 9)
        self.assertAlmostEqual(e1, -3.498612316383892, 9)
Esempio n. 12
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
Esempio n. 13
0
def setUpModule():
    global cell, mf, kmf, kpts
    cell = pgto.Cell()
    cell.atom = '''
    He 0 0 1
    He 1 0 1
    '''
    cell.basis = '321g'
    cell.a = np.eye(3) * 3
    cell.mesh = [8] * 3
    cell.verbose = 7
    cell.output = '/dev/null'
    cell.spin = 2
    cell.build()
    nk = [2, 2, 1]
    kpts = cell.make_kpts(nk, wrap_around=True)
    kmf = pscf.KUHF(cell, kpts).run()
    mf = pscf.UHF(cell).run()
Esempio n. 14
0
def setUpModule():
    global cell, kmf, kpts
    cell = gto.Cell()
    cell.build(unit='B',
               a=[[0., 6.74027466, 6.74027466], [6.74027466, 0., 6.74027466],
                  [6.74027466, 6.74027466, 0.]],
               atom='''H 0 0 0
                  H 1.68506866 1.68506866 1.68506866
                  H 3.37013733 3.37013733 3.37013733''',
               basis='gth-dzvp',
               pseudo='gth-pade',
               verbose=7,
               output='/dev/null',
               charge=0,
               spin=None)
    cell.spin = 3
    kpts = cell.make_kpts([3, 1, 1], scaled_center=[0, 0, 0])
    kmf = scf.KUHF(cell, kpts, exxdiv=None).density_fit()
    kmf.run()
Esempio n. 15
0
    def test_kuhf_grad(self):
        g_scan = scf.KUHF(cell, kpts,
                          exxdiv=None).nuc_grad_method().as_scanner()
        g = g_scan(cell)[1]
        self.assertAlmostEqual(finger(g), 0.11476575559553441, 6)

        mfs = g_scan.base.as_scanner()
        e1 = mfs(
            [['C', [0.0, 0.0, 0.0]],
             [
                 'C',
                 [1.685068664391, 1.685068664391, 1.685068664391 + disp / 2.0]
             ]])
        e2 = mfs(
            [['C', [0.0, 0.0, 0.0]],
             [
                 'C',
                 [1.685068664391, 1.685068664391, 1.685068664391 - disp / 2.0]
             ]])
        self.assertAlmostEqual(g[1, 2], (e1 - e2) / disp, 6)
Esempio n. 16
0
    def test_kuhf_grad(self):
        g_scan = scf.KUHF(cell, kpts, exxdiv=None).set(
            conv_tol=1e-10, conv_tol_grad=1e-6).nuc_grad_method().as_scanner()
        g = g_scan(cell)[1]
        self.assertAlmostEqual(lib.fp(g), -0.9017171774435333, 6)

        mfs = g_scan.base.as_scanner()
        e1 = mfs(
            [['C', [0.0, 0.0, 0.0]],
             [
                 'C',
                 [1.685068664391, 1.685068664391, 1.685068664391 + disp / 2.0]
             ]])
        e2 = mfs(
            [['C', [0.0, 0.0, 0.0]],
             [
                 'C',
                 [1.685068664391, 1.685068664391, 1.685068664391 - disp / 2.0]
             ]])
        self.assertAlmostEqual(g[1, 2], (e1 - e2) / disp, 6)
Esempio n. 17
0
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
Esempio n. 18
0
cell = pgto.Cell()
cell.atom = '''
He 0 0 1
He 1 0 1
'''
cell.basis = '321g'
cell.a = np.eye(3) * 3
cell.mesh = [8] * 3
cell.verbose = 7
cell.output = '/dev/null'
cell.spin = 2
cell.build()
nk = [2, 2, 1]
kpts = cell.make_kpts(nk, wrap_around=True)
kmf = pscf.KUHF(cell, kpts).run()
mf = pscf.UHF(cell).run()

def tearDownModule():
    global cell, kmf, mf
    cell.stdout.close()
    del cell, kmf, mf

class KnownValues(unittest.TestCase):
    def test_kuhf_kernel(self):
        self.assertAlmostEqual(kmf.e_tot, -4.586720023431593, 8)

    def test_uhf_kernel(self):
        self.assertAlmostEqual(mf.e_tot, -3.3634535013441855, 8)

    def test_kuhf_vs_uhf(self):
Esempio n. 19
0
 def test_he_212_ea_diag_high_cost(self):
     kpts = cell.make_kpts([2, 1, 2])
     kmf = pbcscf.KUHF(cell, kpts, exxdiv=None)
     Escf = kmf.scf()
     self._test_ea_diag(kmf)
Esempio n. 20
0
               pseudo='gth-pade',
               verbose=5,
               charge=0,
               spin=1)

    cell.spin = cell.spin * 3
    kpts = cell.make_kpts([3, 1, 1], scaled_center=[0, 0, 0])
    gdf = df.GDF(cell, kpts)
    gdf_fname = 'h3_ints_311.h5'
    gdf._cderi_to_save = gdf_fname
    if not os.path.isfile(gdf_fname):
        gdf.build()

    chkfname = 'h_311.chk'
    if os.path.isfile(chkfname):
        kmf = scf.KUHF(cell, kpts, exxdiv=None)
        kmf.with_df = gdf
        kmf.with_df._cderi = gdf_fname
        data = chkfile.load(chkfname, 'scf')
        kmf.__dict__.update(data)
    else:
        kmf = scf.KUHF(cell, kpts, exxdiv=None)
        kmf.with_df = gdf
        kmf.with_df._cderi = gdf_fname
        kmf.conv_tol = 1e-12
        kmf.chkfile = chkfname
        kmf.kernel()

    gw = KUGWAC(kmf)
    gw.linearized = False
    gw.ac = 'pade'
Esempio n. 21
0
def kernel(gw,
           mo_energy,
           mo_coeff,
           orbs=None,
           kptlist=None,
           nw=None,
           verbose=logger.NOTE):
    '''
    GW-corrected quasiparticle orbital energies
    Returns:
        A list :  converged, mo_energy, mo_coeff
    '''
    mf = gw._scf
    if gw.frozen is None:
        frozen = 0
    else:
        frozen = gw.frozen
    assert (frozen == 0)

    nmoa, nmob = gw.nmo
    nocca, noccb = gw.nocc
    nvira = nmoa - nocca
    nvirb = nmob - noccb

    if orbs is None:
        orbs = range(nmoa)
    if kptlist is None:
        kptlist = range(gw.nkpts)

    nkpts = gw.nkpts
    nklist = len(kptlist)
    norbs = len(orbs)

    # v_xc
    dm = np.array(mf.make_rdm1())
    v_mf = np.array(mf.get_veff())
    vj = np.array(mf.get_j(dm_kpts=dm))
    v_mf[0] = v_mf[0] - (vj[0] + vj[1])
    v_mf[1] = v_mf[1] - (vj[0] + vj[1])
    for s in range(2):
        for k in range(nkpts):
            v_mf[s, k] = reduce(
                numpy.dot,
                (mo_coeff[s, k].T.conj(), v_mf[s, k], mo_coeff[s, k]))

    # v_hf from DFT/HF density
    if gw.fc:
        exxdiv = 'ewald'
    else:
        exxdiv = None
    uhf = scf.KUHF(gw.mol, gw.kpts, exxdiv=exxdiv)
    uhf.with_df = gw.with_df
    uhf.with_df._cderi = gw.with_df._cderi
    vk = uhf.get_veff(gw.mol, dm_kpts=dm)
    vj = uhf.get_j(gw.mol, dm_kpts=dm)
    vk[0] = vk[0] - (vj[0] + vj[1])
    vk[1] = vk[1] - (vj[0] + vj[1])
    for s in range(2):
        for k in range(nkpts):
            vk[s,
               k] = reduce(numpy.dot,
                           (mo_coeff[s, k].T.conj(), vk[s, k], mo_coeff[s, k]))

    # Grids for integration on imaginary axis
    freqs, wts = _get_scaled_legendre_roots(nw)

    # Compute self-energy on imaginary axis i*[0,iw_cutoff]
    sigmaI, omega = get_sigma_diag(gw, orbs, kptlist, freqs, wts, iw_cutoff=5.)

    # Analytic continuation
    coeff_a = []
    coeff_b = []
    if gw.ac == 'twopole':
        for k in range(nklist):
            coeff_a.append(AC_twopole_diag(sigmaI[0, k], omega[0], orbs,
                                           nocca))
            coeff_b.append(AC_twopole_diag(sigmaI[1, k], omega[1], orbs,
                                           noccb))
    elif gw.ac == 'pade':
        for k in range(nklist):
            coeff_a_tmp, omega_fit_a = AC_pade_thiele_diag(
                sigmaI[0, k], omega[0])
            coeff_b_tmp, omega_fit_b = AC_pade_thiele_diag(
                sigmaI[1, k], omega[1])
            coeff_a.append(coeff_a_tmp)
            coeff_b.append(coeff_b_tmp)
        omega_fit = np.asarray((omega_fit_a, omega_fit_b))
    coeff = np.asarray((coeff_a, coeff_b))

    conv = True
    # This code does not support metals
    h**o = -99.
    lumo = 99.
    mo_energy = np.asarray(mf.mo_energy)
    for k in range(nkpts):
        if h**o < max(mo_energy[0, k][nocca - 1], mo_energy[1, k][noccb - 1]):
            h**o = max(mo_energy[0, k][nocca - 1], mo_energy[1, k][noccb - 1])
        if lumo > min(mo_energy[0, k][nocca], mo_energy[1, k][noccb]):
            lumo = min(mo_energy[0, k][nocca], mo_energy[1, k][noccb])
    ef = (h**o + lumo) / 2.

    mo_energy = np.zeros_like(np.array(mf.mo_energy))
    for s in range(2):
        for k in range(nklist):
            kn = kptlist[k]
            for p in orbs:
                if gw.linearized:
                    # linearized G0W0
                    de = 1e-6
                    ep = mf.mo_energy[s][kn][p]
                    #TODO: analytic sigma derivative
                    if gw.ac == 'twopole':
                        sigmaR = two_pole(ep - ef, coeff[s, k, :,
                                                         p - orbs[0]]).real
                        dsigma = two_pole(
                            ep - ef + de,
                            coeff[s, k, :, p - orbs[0]]).real - sigmaR.real
                    elif gw.ac == 'pade':
                        sigmaR = pade_thiele(ep - ef, omega_fit[s,
                                                                p - orbs[0]],
                                             coeff[s, k, :, p - orbs[0]]).real
                        dsigma = pade_thiele(
                            ep - ef + de, omega_fit[s, p - orbs[0]],
                            coeff[s, k, :, p - orbs[0]]).real - sigmaR.real
                    zn = 1.0 / (1.0 - dsigma / de)
                    e = ep + zn * (sigmaR.real + vk[s, kn, p, p].real -
                                   v_mf[s, kn, p, p].real)
                    mo_energy[s, kn, p] = e
                else:
                    # self-consistently solve QP equation
                    def quasiparticle(omega):
                        if gw.ac == 'twopole':
                            sigmaR = two_pole(omega - ef,
                                              coeff[s, k, :, p - orbs[0]]).real
                        elif gw.ac == 'pade':
                            sigmaR = pade_thiele(omega - ef,
                                                 omega_fit[s, p - orbs[0]],
                                                 coeff[s, k, :,
                                                       p - orbs[0]]).real
                        return omega - mf.mo_energy[s][kn][p] - (
                            sigmaR.real + vk[s, kn, p, p].real -
                            v_mf[s, kn, p, p].real)

                    try:
                        e = newton(quasiparticle,
                                   mf.mo_energy[s][kn][p],
                                   tol=1e-6,
                                   maxiter=100)
                        mo_energy[s, kn, p] = e
                    except RuntimeError:
                        conv = False
    mo_coeff = mf.mo_coeff

    if gw.verbose >= logger.DEBUG:
        numpy.set_printoptions(threshold=nmoa)
        for k in range(nkpts):
            logger.debug(gw, '  GW mo_energy spin-up @ k%d =\n%s', k,
                         mo_energy[0, k])
        for k in range(nkpts):
            logger.debug(gw, '  GW mo_energy spin-down @ k%d =\n%s', k,
                         mo_energy[1, k])
        numpy.set_printoptions(threshold=1000)

    return conv, mo_energy, mo_coeff
Esempio n. 22
0
    def init_scf(self, cell=None, method=None, verbose=None, damp=None,
                 shift=None, kpts=None, grid_level=None, rho_cutoff=None,
                 density_fit=None, auxbasis=None):
        """
        Initializes the supersystem PySCF SCF object using given settings.

        Parameters
        ----------
            cell : pyscf.pbc.gto.Cell object
                Concatenated supersystem Cell object
            fs_method : str
                Supersystem SCF method
            verbose : int
                PySCF verbosity parameter for output
            damp : float
                Damping parameter for SCF convergence
            shift : float
                Energy level shift parameter for convergence

        Returns
        -------
            scf_obj : pyscf.pbc.SCF object
                SCF object for the supersystem
        """

        import pyscf
        from pyscf.pbc import scf as pbcscf, df as pbcdf, dft as pbcdft

        if cell is None:
            cell = self.cell
        if method is None:
            method = self.fs_method
        if verbose is None:
            verbose = self.verbose
        if damp is None:
            damp = self.fs_damp
        if shift is None:
            shift = self.fs_shift
        if kpts is None:
            kpts = self.kpts
        if grid_level is None:
            grid_level = self.grid_level
        if rho_cutoff is None:
            rho_cutoff = self.rho_cutoff
        if density_fit is None:
            density_fit = self.density_fit
        if auxbasis is None:
            auxbasis = self.auxbasis

#        if self.pmem:
#            self.cell.max_memory = self.pmem

        nkpts = len(kpts)

        if self.unrestricted:
            if method in ('hf', 'hartree-fock'):
                scf_obj = pbcscf.KUHF(cell, kpts)
            else:
                scf_obj = pbcscf.KUKS(cell, kpts)
                scf_obj.xc = method

        elif cell.spin != 0:
            if method in ('hf', 'hartree-fock'):
                scf_obj = pbcscf.KROHF(cell, kpts)
            else:
                scf_obj = pbcscf.KROKS(cell, kpts)
                scf_obj.xc = method

        else:
            if method in ('hf', 'hartree-fock'):
                scf_obj = pbcscf.KRHF(cell, kpts)
            else:
                scf_obj = pbcscf.KRKS(cell, kpts)
                scf_obj.xc = method

        scf_obj.kpts = kpts
        scf_obj.verbose = verbose

        # build grids
        scf_obj.grids = pbcdft.gen_grid.BeckeGrids(cell)
        scf_obj.grids.level = grid_level
        scf_obj.grids.build()

        # density fitting (can be very time consuming)
        if density_fit == 'fftdf':
            DensityFit = pbcdf.FFTDF
        elif density_fit == 'mdf':
            DensityFit = pbcdf.MDF
        elif density_fit == 'pwdf':
            DensityFit = pbcdf.PWDF
        elif density_fit == 'gdf':
            DensityFit = pbcdf.GDF
        elif density_fit == 'aftdf':
            DensityFit = pbcdf.AFTDF
        else:
            DensityFit = pbcdf.DF

        scf_obj.with_df = DensityFit(cell)
        scf_obj.with_df.kpts = kpts
        scf_obj.with_df.auxbasis = auxbasis

        scf_obj.damp = damp

        self.smat = scf_obj.get_ovlp()

        return scf_obj
Esempio n. 23
0
                    [numpy.dot(mo, u[k]) for k, mo in enumerate(mo_coeff)])

        return KRHF()


if __name__ == '__main__':
    import pyscf.pbc.gto as pbcgto
    import pyscf.pbc.scf as pscf
    cell = pbcgto.Cell()
    cell.atom = '''
    He 0 0 1
    He 1 0 1
    '''
    cell.basis = 'ccpvdz'
    cell.a = numpy.eye(3) * 4
    cell.gs = [8] * 3
    cell.verbose = 4
    cell.build()
    nks = [2, 1, 1]
    mf = pscf.KRHF(cell, cell.make_kpts(nks))
    mf.max_cycle = 2
    mf.kernel()
    mf.max_cycle = 5
    pscf.newton(mf).kernel()

    mf = pscf.KUHF(cell, cell.make_kpts(nks))
    mf.max_cycle = 2
    mf.kernel()
    mf.max_cycle = 5
    pscf.newton(mf).kernel()
Esempio n. 24
0
 def test_he_131_ea_diag(self):
     kpts = cell.make_kpts([1, 3, 1])
     kmf = pbcscf.KUHF(cell, kpts, exxdiv=None)
     Escf = kmf.scf()
     self._test_ea_diag(kmf)
Esempio n. 25
0
 def test_he_112_ip_diag(self):
     kpts = cell.make_kpts([1, 1, 2])
     kmf = pbcscf.KUHF(cell, kpts, exxdiv=None)
     Escf = kmf.scf()
     self._test_ip_diag(kmf)
Esempio n. 26
0
    def test_convert_to_kscf(self):
        from pyscf.pbc import df
        from pyscf.soscf import newton_ah
        cell1 = cell.copy()
        cell1.verbose = 0
        pscf.addons.convert_to_rhf(pscf.KRHF(cell1))
        pscf.addons.convert_to_uhf(pscf.KRHF(cell1))
        pscf.addons.convert_to_ghf(pscf.KRHF(cell1))
        pscf.addons.convert_to_rhf(pscf.KROHF(cell1))
        pscf.addons.convert_to_uhf(pscf.KROHF(cell1))
        pscf.addons.convert_to_ghf(pscf.KROHF(cell1))
        pscf.addons.convert_to_rhf(pscf.KUHF(cell1))
        pscf.addons.convert_to_uhf(pscf.KUHF(cell1))
        pscf.addons.convert_to_ghf(pscf.KUHF(cell1))
        #pscf.addons.convert_to_rhf(pscf.KGHF(cell1))
        #pscf.addons.convert_to_uhf(pscf.KGHF(cell1))
        pscf.addons.convert_to_ghf(pscf.KGHF(cell1))

        self.assertTrue(
            isinstance(
                pscf.addons.convert_to_rhf(
                    pscf.KRHF(cell1).newton().density_fit().x2c()),
                newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                pscf.addons.convert_to_uhf(
                    pscf.KRHF(cell1).newton().density_fit().x2c()),
                newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                pscf.addons.convert_to_ghf(
                    pscf.KRHF(cell1).newton().density_fit().x2c()),
                newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                pscf.addons.convert_to_rhf(
                    pscf.KUHF(cell1).newton().density_fit().x2c()),
                newton_ah._CIAH_SOSCF))
        self.assertTrue(
            isinstance(
                pscf.addons.convert_to_uhf(
                    pscf.KUHF(cell1).newton().density_fit().x2c()),
                newton_ah._CIAH_SOSCF))
        self.assertFalse(
            isinstance(
                pscf.addons.convert_to_ghf(
                    pscf.KUHF(cell1).newton().density_fit().x2c()),
                newton_ah._CIAH_SOSCF))
        #self.assertFalse(isinstance(pscf.addons.convert_to_rhf(pscf.KGHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF))
        #self.assertFalse(isinstance(pscf.addons.convert_to_uhf(pscf.KGHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF))
        #self.assertTrue (isinstance(pscf.addons.convert_to_ghf(pscf.KGHF(cell1).newton().density_fit().x2c()), newton_ah._CIAH_SOSCF))

        mf1 = pscf.khf.KRHF(cell1)
        cell2 = cell1.copy()
        cell2.spin = 2
        self.assertTrue(isinstance(mf1.convert_from_(kmf_u), pscf.khf.KRHF))
        self.assertTrue(
            isinstance(mf1.convert_from_(pscf.KUHF(cell2)), pscf.khf.KRHF))
        self.assertFalse(
            isinstance(mf1.convert_from_(pscf.KUHF(cell2)), pscf.krohf.KROHF))
        self.assertFalse(
            isinstance(mf1.convert_from_(kmf_u.newton()),
                       newton_ah._CIAH_SOSCF))
        self.assertTrue(
            isinstance(
                mf1.convert_from_(pscf.KUHF(cell2).density_fit()).with_df,
                df.df.GDF))
        self.assertTrue(
            isinstance(
                mf1.convert_from_(pscf.KUHF(cell2).mix_density_fit()).with_df,
                df.mdf.MDF))
        self.assertFalse(
            isinstance(mf1.convert_from_(pscf.KROHF(cell2)), pscf.krohf.KROHF))
        self.assertRaises(AssertionError, mf1.convert_from_, pscf.UHF(cell1))

        mf1 = pscf.krohf.KROHF(cell1)
        self.assertTrue(isinstance(mf1.convert_from_(kmf_u), pscf.krohf.KROHF))
        self.assertTrue(
            isinstance(mf1.convert_from_(pscf.KUHF(cell2)), pscf.krohf.KROHF))
        self.assertFalse(
            isinstance(mf1.convert_from_(kmf_u.newton()),
                       newton_ah._CIAH_SOSCF))
        self.assertTrue(
            isinstance(
                mf1.convert_from_(pscf.KUHF(cell2).density_fit()).with_df,
                df.df.GDF))
        self.assertTrue(
            isinstance(
                mf1.convert_from_(pscf.KUHF(cell2).mix_density_fit()).with_df,
                df.mdf.MDF))
        self.assertTrue(isinstance(mf1.convert_from_(kmf_r), pscf.krohf.KROHF))
        self.assertRaises(AssertionError, mf1.convert_from_, pscf.UHF(cell1))

        mf1 = pscf.kuhf.KUHF(cell1)
        self.assertTrue(isinstance(mf1.convert_from_(kmf_r), pscf.kuhf.KUHF))
        self.assertFalse(
            isinstance(mf1.convert_from_(kmf_r.newton()),
                       newton_ah._CIAH_SOSCF))
        self.assertTrue(
            isinstance(
                mf1.convert_from_(kmf_r.density_fit()).with_df, df.df.GDF))
        self.assertTrue(
            isinstance(
                mf1.convert_from_(kmf_ro.mix_density_fit()).with_df,
                df.mdf.MDF))
        self.assertRaises(AssertionError, mf1.convert_from_, pscf.UHF(cell1))
Esempio n. 27
0
 def test_he_112_ea_diag_shift(self):
     kpts = cell.make_kpts([1, 1, 2])
     kmf = pbcscf.KUHF(cell, kpts, exxdiv=None)
     Escf = kmf.scf()
     self._test_ea_diag(kmf, kshift=1)
Esempio n. 28
0
File: kuhf.py Progetto: tmash/pyscf
    cell.unit = 'B'
    cell.atom = '''
    C  0.          0.          0.        
    C  1.68506879  1.68506879  1.68506879
    '''
    cell.a = '''
    0.          3.37013758  3.37013758
    3.37013758  0.          3.37013758
    3.37013758  3.37013758  0.
    '''

    cell.basis = 'gth-szv'
    cell.pseudo = 'gth-pade'
    cell.mesh = [37] * 3
    cell.build()
    mf = scf.KUHF(cell, cell.make_kpts([2, 1, 1])).set(exxdiv=None)
    #    mf.with_df = df.DF(cell, cell.make_kpts([2,1,1]))
    #    mf.with_df.auxbasis = 'weigend'
    #    mf.with_df._cderi = 'eri3d-df.h5'
    #    mf.with_df.build(with_j3c=False)
    mf.run()

    td = TDA(mf)
    td.verbose = 5
    td.nstates = 5
    print(td.kernel()[0] * 27.2114)

    td = TDHF(mf)
    td.verbose = 5
    td.nstates = 5
    print(td.kernel()[0] * 27.2114)
Esempio n. 29
0
cell = gto.Cell()
cell.build(unit='B',
           a=[[0., 6.74027466, 6.74027466], [6.74027466, 0., 6.74027466],
              [6.74027466, 6.74027466, 0.]],
           atom='''H 0 0 0
              H 1.68506866 1.68506866 1.68506866
              H 3.37013733 3.37013733 3.37013733''',
           basis='gth-dzvp',
           pseudo='gth-pade',
           verbose=7,
           output='/dev/null',
           charge=0,
           spin=None)
cell.spin = 3
kpts = cell.make_kpts([3, 1, 1], scaled_center=[0, 0, 0])
kmf = scf.KUHF(cell, kpts, exxdiv=None).density_fit()
kmf.run()


def tearDownModule():
    global cell, kmf
    cell.stdout.close()
    del cell, kmf


class KnownValues(unittest.TestCase):
    def test_gwac_pade(self):
        gw = kugw_ac.KUGWAC(kmf)
        gw.linearized = False
        gw.ac = 'pade'
        gw.fc = False
Esempio n. 30
0
 def test_nr_kuhf(self):
     mf = scf.KUHF(cell, cell.make_kpts([2, 1, 1]))
     mf = scf.newton(mf)
     mf.conv_tol_grad = 1e-4
     mf.kernel()
     self.assertAlmostEqual(mf.e_tot, -10.5309059210831, 8)