Exemple #1
0
 def test_roks_b3lypg(self):
     mf = dft.ROKS(h2o_n)
     mf.run(conv_tol=1e-14, xc='b3lypg')
     g = roks.Grad(mf)
     self.assertAlmostEqual(lib.finger(g.grad()), -0.14281412906618443, 6)
     g.grid_response = True
     self.assertAlmostEqual(lib.finger(g.grad()), -0.14281571291026954, 6)
Exemple #2
0
    def test_mom_occ(self):
        mf = dft.UKS(mol)
        mf.xc = 'b3lyp'
        mf.scf()
        mo0 = mf.mo_coeff
        occ = mf.mo_occ
        occ[0][4] = 0.
        occ[0][5] = 1.
        mf = scf.addons.mom_occ(mf, mo0, occ)
        dm = mf.make_rdm1(mo0, occ)
        self.assertAlmostEqual(mf.scf(dm), -76.0606858747, 9)
        self.assertTrue(numpy.allclose(mf.mo_occ[0][:6], [1,1,1,1,0,1]))

        mf = dft.ROKS(mol)
        mf.xc = 'b3lyp'
        mf.scf()
        mo0 = mf.mo_coeff
        occ = mf.mo_occ
        setocc = numpy.zeros((2, occ.size))
        setocc[:, occ==2] = 1
        setocc[0][4] = 0
        setocc[0][5] = 1
        newocc = setocc[0][:] + setocc[1][:]
        mf = scf.addons.mom_occ(mf, mo0, setocc)
        dm = mf.make_rdm1(mo0, newocc)
        self.assertAlmostEqual(mf.scf(dm), -76.0692546639, 9)
        self.assertTrue(numpy.allclose(mf.mo_occ[:6], [2,2,2,2,1,1]))
    def test_hsros_supersystem(self):
        mol = gto.Mole()
        mol.verbose = 3
        mol.atom = '''
        H 0. -2.757 2.857
        H 0. 2.757 2.857
        '''
        mol.basis = '3-21g'
        mol.spin = 2
        mol.build()
        env_method = 'm06'
        hl_method = 'ccsd'
        subsys = cluster_subsystem.ClusterHLSubSystem(mol, env_method, hl_method)

        mol2 = gto.Mole()
        mol2.verbose = 3
        mol2.atom = '''
        He 1.0 20.0 0.0
        He 3.0 20.0 0.0'''
        mol2.basis = '3-21g'
        mol2.build()

        env_method = 'm06'
        subsys2 = cluster_subsystem.ClusterEnvSubSystem(mol2, env_method)
        mol12 = helpers.concat_mols([mol, mol2])
        fs_scf_obj = helpers.gen_scf_obj(mol12, 'm06')
        supersystem = cluster_supersystem.ClusterSuperSystem([subsys, subsys2], 'm06', fs_scf_obj, init_guess='minao')

        #Check SCF object
        scf_obj = supersystem.fs_scf_obj
        comp_scf_obj = dft.ROKS(gto.mole.conc_mol(mol, mol2))
        self.assertEqual(type(scf_obj), type(comp_scf_obj))
        self.assertEqual(scf_obj.xc, 'm06')
Exemple #4
0
 def test_roks_lda(self):
     mf = dft.ROKS(h2o_p)
     mf.run(conv_tol=1e-14, xc='lda,vwn')
     g = roks.Grad(mf)
     self.assertAlmostEqual(lib.finger(g.grad()), -0.12051785975616186, 6)
     g.grid_response = True
     self.assertAlmostEqual(lib.finger(g.grad()), -0.12052121736985746, 6)
Exemple #5
0
 def test_roks_b3lypg(self):
     mf = dft.ROKS(h2o_n)
     mf.run(conv_tol=1e-14, xc='b3lypg')
     g = roks.Grad(mf)
     self.assertAlmostEqual(lib.finger(g.grad()), -0.16655206305717471, 6)
     g.grid_response = True
     self.assertAlmostEqual(lib.finger(g.grad()), -0.16655364690125929, 6)
Exemple #6
0
 def test_nr_roks_b3lypg(self):
     method = dft.ROKS(h2o_cation)
     method.xc = 'b3lypg'
     method.grids.prune = dft.gen_grid.treutler_prune
     method.grids.atom_grid = {"H": (50, 194), "O": (50, 194),}
     self.assertAlmostEqual(method.scf(), -75.926526046608529, 9)
     g = method.nuc_grad_method().kernel()
     self.assertAlmostEqual(lib.finger(g), -0.10184251826412283, 6)
Exemple #7
0
 def test_nr_symm_roks_b3lypg_direct(self):
     method = dft.ROKS(h2osym_cation)
     method.xc = 'b3lypg'
     method.max_memory = 0
     method.direct_scf = True
     method.grids.prune = dft.gen_grid.treutler_prune
     method.grids.atom_grid = {"H": (50, 194), "O": (50, 194),}
     self.assertAlmostEqual(method.scf(), -75.926526046608529, 9)
Exemple #8
0
 def test_nr_symm_roks_lsda(self):
     mol1 = h2osym.copy()
     mol1.charge = 1
     mol1.spin = 1
     mol1.build(0, 0)
     method = dft.ROKS(mol1)
     method.grids.prune = dft.gen_grid.treutler_prune
     method.grids.atom_grid = {"H": (50, 194), "O": (50, 194),}
     self.assertAlmostEqual(method.scf(), -75.350333965173704, 9)
Exemple #9
0
 def test_nr_symm_roks_b3lypg(self):
     mol1 = h2osym.copy()
     mol1.charge = 1
     mol1.spin = 1
     mol1.build(0, 0)
     method = dft.ROKS(mol1)
     method.xc = 'b3lypg'
     method.grids.prune = dft.gen_grid.treutler_prune
     method.grids.atom_grid = {"H": (50, 194), "O": (50, 194),}
     self.assertAlmostEqual(method.scf(), -75.926526046608529, 9)
Exemple #10
0
    def test_init_guess_by_vsap(self):
        dm = dft.RKS(h2o).get_init_guess(key='vsap')
        self.assertAlmostEqual(lib.fp(dm), 1.7285100188309719, 9)

        dm = dft.ROKS(h2osym).get_init_guess(key='vsap')
        self.assertEqual(dm.ndim, 3)
        self.assertAlmostEqual(lib.fp(dm), 1.9698972986009409, 9)

        dm = dft.UKS(h2osym).init_guess_by_vsap()
        self.assertEqual(dm.ndim, 3)
        self.assertAlmostEqual(lib.fp(dm), 1.9698972986009409, 9)
Exemple #11
0
    def test_restrictedos_subsystem(self):
        mol = self.cs_mol.copy()
        mol.spin = 2
        mol.build()
        subsys = cluster_subsystem.ClusterEnvSubSystem(mol, self.env_method)
        subsys.init_density()

        #Check SCF object
        scf_obj = subsys.env_scf
        comp_scf_obj = dft.ROKS(mol)
        self.assertEqual(type(scf_obj), type(comp_scf_obj))
        self.assertEqual(scf_obj.xc, 'm06')
Exemple #12
0
    def test_init(self):
        mol_r = h2o
        mol_u = gto.M(atom='Li', spin=1, verbose=0)
        mol_r1 = gto.M(atom='H', spin=1, verbose=0)
        sym_mol_r = h2osym
        sym_mol_u = gto.M(atom='Li', spin=1, symmetry=1, verbose=0)
        sym_mol_r1 = gto.M(atom='H', spin=1, symmetry=1, verbose=0)
        self.assertTrue(isinstance(dft.RKS(mol_r), dft.rks.RKS))
        self.assertTrue(isinstance(dft.RKS(mol_u), dft.roks.ROKS))
        self.assertTrue(isinstance(dft.UKS(mol_r), dft.uks.UKS))
        self.assertTrue(isinstance(dft.ROKS(mol_r), dft.roks.ROKS))
        self.assertTrue(isinstance(dft.GKS(mol_r), dft.gks.GKS))
        self.assertTrue(isinstance(dft.KS(mol_r), dft.rks.RKS))
        self.assertTrue(isinstance(dft.KS(mol_u), dft.uks.UKS))
        self.assertTrue(isinstance(dft.DKS(mol_u), dft.dks.UDKS))

        self.assertTrue(isinstance(mol_r.RKS(), dft.rks.RKS))
        self.assertTrue(isinstance(mol_u.RKS(), dft.roks.ROKS))
        self.assertTrue(isinstance(mol_r.UKS(), dft.uks.UKS))
        self.assertTrue(isinstance(mol_r.ROKS(), dft.roks.ROKS))
        self.assertTrue(isinstance(mol_r.GKS(), dft.gks.GKS))
        self.assertTrue(isinstance(mol_r.KS(), dft.rks.RKS))
        self.assertTrue(isinstance(mol_u.KS(), dft.uks.UKS))
        self.assertTrue(isinstance(mol_u.DKS(), dft.dks.UDKS))
urlretrieve("{0}/{1}/{2}/{3}".format(pplib,atom,pptype,basfile),
        filename=basfile)
urlretrieve("{0}/{1}/{2}/{3}".format(pplib,atom,pptype,ecpfile),
        filename=ecpfile)
urlretrieve("{0}/{1}/{2}/{3}".format(pplib,atom,pptype,xmlfile),
        filename=xmlfile)

#Initialize molecule object
mol = gto.Mole()
mol.atom = "{0} 0.0 0.0 0.0".format(atom)
with open(os.path.join(cwd,basfile)) as f:
    bas = f.read()
mol.basis = {atom: gto.basis.parse(bas)} 
with open(os.path.join(cwd,ecpfile)) as f:
    ecp = f.read()
mol.ecp = {atom: gto.basis.parse_ecp(ecp)}
mol.spin = 2
mol.charge = 0
mol.build()

#run HF and PBE
hf = scf.ROHF(mol)
hf.kernel()
pbe = dft.ROKS(mol)
pbe.xc = 'pbe'
pbe.kernel()

savetoqmcpack(mol,hf,title='{}.hf'.format(atom))
savetoqmcpack(mol,pbe,title='{}.pbe'.format(atom))

Exemple #14
0
def do_scf(inp):
    '''Do the requested SCF.'''

    from pyscf import gto, scf, dft, cc, fci, ci, ao2mo, mcscf, mrpt, lib, mp, tdscf
    from pyscf.cc import ccsd_t, uccsd_t
    import numpy as np
    from .fcidump import fcidump

    # sort out the method
    mol = inp.mol
    method = inp.scf.method.lower()

    # UHF
    if method == 'uhf':
        ehf, mSCF = do_hf(inp, unrestricted=True)
        print_energy('UHF', ehf)

        if inp.scf.exci is not None:
            inp.timer.start('TDHF')
            mtd = do_TDDFT(inp, mSCF)
            inp.timer.end('TDHF')

    # RHF
    elif method in ('rhf', 'hf'):
        ehf, mSCF = do_hf(inp)
        print_energy('RHF', ehf)

        if inp.scf.exci is not None:
            inp.timer.start('TDHF')
            mtd = do_TDDFT(inp, mSCF)
            inp.timer.end('TDHF')

    # CCSD and CCSD(T)
    elif method in ('ccsd', 'ccsd(t)', 'uccsd', 'uccsd(t)', 'eomccsd'):
        if 'u' in method:
            ehf, tSCF = do_hf(inp, unrestricted=True)
            print_energy('UHF', ehf)
        else:
            ehf, tSCF = do_hf(inp)
            print_energy('RHF', ehf)

        inp.timer.start('ccsd')
        frozen = 0
        if inp.scf.freeze is not None: frozen = inp.scf.freeze
        if 'u' in method:
            mSCF = cc.UCCSD(tSCF, frozen=frozen)
        else:
            mSCF = cc.CCSD(tSCF, frozen=frozen)
        mSCF.max_cycle = inp.scf.maxiter
        eccsd, t1, t2 = mSCF.kernel()
        print_energy('CCSD', ehf + eccsd)
        inp.timer.end('ccsd')

        if method == 'eomccsd':
            inp.timer.start('eomccsd')
            ee = mSCF.eomee_ccsd_singlet(nroots=4)[0]
            inp.timer.end('eomccsd')
            for i in range(len(ee)):
                print_energy('EOM-CCSD {0} (eV)'.format(i+1), ee[i] * 27.2114)

        if method in ('ccsd(t)', 'uccsd(t)'):
            inp.timer.start('ccsd(t)')
            eris = mSCF.ao2mo()

            if method == 'ccsd(t)':
                e3 = ccsd_t.kernel(mSCF, eris)
            else:
                e3 = uccsd_t.kernel(mSCF, eris)
            print_energy('CCSD(T)', ehf + eccsd + e3)
            inp.timer.end('ccsd(t)')

    # MP2
    elif method == 'mp2':
        ehf, tSCF = do_hf(inp)
        print_energy('RHF', ehf)

        inp.timer.start('mp2')
        frozen = 0 
        if inp.scf.freeze is not None: frozen = inp.scf.freeze
        mSCF = mp.MP2(tSCF, frozen=frozen)
        emp2, t2 = mSCF.kernel()
        print_energy('MP2', ehf+emp2)
        inp.timer.end('mp2')

    # CISD
    elif method == 'cisd' or method == 'cisd(q)':
        ehf, tSCF = do_hf(inp)
        print_energy('RHF', ehf)

        inp.timer.start('cisd')
        frozen = 0
        if inp.scf.freeze is not None: frozen = inp.scf.freeze
        mSCF = ci.CISD(tSCF, frozen=frozen)
        ecisd = mSCF.kernel()[0]
        print_energy('CISD', ehf + ecisd)
        inp.timer.end('cisd')

        # perform Davison quadruples correction
        c0 = np.max(np.abs(mSCF.ci))
        c02 = c0**2
        ne = mSCF.mol.nelectron
        eq = ( 1.0 - c02 ) * ecisd
        print_energy('CISD(Q) Davidson', ehf + ecisd + eq)
        eq = ( 1.0 - c02 ) / c02 * ecisd
        print_energy('CISD(Q) Renomalized-Davidson', ehf + ecisd + eq)
        eq = ( 1.0 - c02 ) / ( 2.0 * c02 - 1.0 ) * ecisd
        print_energy('CISD(Q) Davison-Silver', ehf + ecisd + eq)
        eq = (( 2.0 * c02 ) / ((2.0*c02-1.0)*(1.0 + np.sqrt(1.0 + (8.0*c02*(1.0-c02))
         / ( ne * (2.0*c02-1.0)**2 )))) - 1.0 ) * ecisd
        print_energy('CISD(Q) PC', ehf + ecisd + eq)
        eq = ( 1.0 - c02 ) / c02 * ((ne-2)*(ne-3.0)) / (ne*(ne-1.0)) * ecisd
        print_energy('CISD(Q) MC', ehf + ecisd + eq)
        if ne > 2:
            eq = ( 2.0 - c02 ) / (2.0 * (ne-1.0)/(ne-2.0) * c02 - 1.0)
        else:
            eq = 0.0
        print_energy('CISD(Q) DD', ehf + ecisd + eq)


    # UKS
    elif method in ('uks' or 'udft'):
        inp.timer.start('uks')
        inp.timer.start('grids')
        grids = dft.gen_grid.Grids(mol)
        grids.level = inp.scf.grid
        grids.build()
        inp.timer.end('grids')
        mSCF = dft.UKS(mol)
        mSCF.grids = grids
        mSCF.xc = inp.scf.xc
        mSCF.conv_tol = inp.scf.conv
        mSCF.conv_tol_grad = inp.scf.grad
        mSCF.max_cycle = inp.scf.maxiter
        mSCF.init_guess = inp.scf.guess
        mSCF.small_rho_cutoff = 1e-20
        eks = mSCF.kernel()
        print_energy('UKS', eks)
        inp.timer.end('uks')

        if inp.scf.exci is not None:
            inp.timer.start('TDDFT')
            mtd = do_TDDFT(inp, mSCF)
            inp.timer.end('TDDFT')

    # RKS
    elif method in ('rks', 'ks', 'rdft', 'dft'):
        inp.timer.start('ks')
        inp.timer.start('grids')
        grids = dft.gen_grid.Grids(mol)
        grids.level = inp.scf.grid
        grids.build()
        inp.timer.end('grids')
        if mol.nelectron%2 == 0:
            mSCF = dft.RKS(mol)
        else:
            mSCF = dft.ROKS(mol)
        mSCF.grids = grids
        mSCF.xc = inp.scf.xc
        mSCF.conv_tol = inp.scf.conv
        mSCF.conv_tol_grad = inp.scf.grad
        mSCF.max_cycle = inp.scf.maxiter
        mSCF.init_guess = inp.scf.guess
        mSCF.small_rho_cutoff = 1e-20
        mSCF.damp = inp.scf.damp
        mSCF.level_shift = inp.scf.shift
        eks = mSCF.kernel()
        print_energy('RKS', eks)
        inp.timer.end('ks')

        if inp.scf.exci is not None:
            inp.timer.start('TDDFT')
            mtd = do_TDDFT(inp, mSCF)
            inp.timer.end('TDDFT')

    # Unrestricted FCI
    elif method == 'ufci':
        ehf, mSCF = do_hf(inp, unrestricted=True)
        print_energy('UHF', ehf)

        inp.timer.start('fci')
        cis = fci.direct_uhf.FCISolver(mol)
        norb = mSCF.mo_energy[0].size
        nea = (mol.nelectron+mol.spin) // 2
        neb = (mol.nelectron-mol.spin) // 2
        nelec = (nea, neb)
        mo_a = mSCF.mo_coeff[0]
        mo_b = mSCF.mo_coeff[1]
        h1e_a = reduce(np.dot, (mo_a.T, mSCF.get_hcore(), mo_a))
        h1e_b = reduce(np.dot, (mo_b.T, mSCF.get_hcore(), mo_b))
        g2e_aa = ao2mo.incore.general(mSCF._eri, (mo_a,)*4, compact=False)
        g2e_aa = g2e_aa.reshape(norb,norb,norb,norb)
        g2e_ab = ao2mo.incore.general(mSCF._eri, (mo_a,mo_a,mo_b,mo_b), compact=False)
        g2e_ab = g2e_ab.reshape(norb,norb,norb,norb)
        g2e_bb = ao2mo.incore.general(mSCF._eri, (mo_b,)*4, compact=False)
        g2e_bb = g2e_bb.reshape(norb,norb,norb,norb)
        h1e = (h1e_a, h1e_b)
        eri = (g2e_aa, g2e_ab, g2e_bb)

        eci = fci.direct_uhf.kernel(h1e, eri, norb, nelec)[0]
        print_energy('FCI', eci)
        inp.timer.end('fci')

    # FCI
    elif method in ('fci'):
        ehf, mSCF = do_hf(inp)
        print_energy('RHF', ehf)

        inp.timer.start('fci')
        if inp.scf.freeze is None:
            mCI = fci.FCI(mSCF)
            if inp.scf.roots is not None:
                mCI.nroots = inp.scf.roots
            mCI.kernel()[0]
            eci = mCI.eci

        else:
            nel  = mol.nelectron - inp.scf.freeze * 2
            ncas = mol.nao_nr() - inp.scf.freeze
            if mol.spin == 0:
                nelecas = nel
                mCI = mcscf.CASCI(mSCF, ncas, nelecas)
                mCI.fcisolver = fci.solver(mol)
            else:
                if mol.spin%2 == 0:
                    nelecas = (nel//2+mol.spin//2, nel//2-mol.spin//2)
                else:
                    nelecas = (nel//2+mol.spin//2+1, nel//2-mol.spin//2)
                mCI = mcscf.CASCI(mSCF, ncas, nelecas)
                mCI.fcisolver = fci.direct_spin1.FCISolver(mol)
            eci = mCI.kernel()[0]
            dm = mCI.make_rdm1()
            dip = mSCF.dip_moment(dm=dm)

        if inp.scf.roots is None:
            print_energy('FCI', eci)
        else:
            for i in range(inp.scf.roots):
                print_energy('FCI {0}'.format(i), eci[i])
        inp.timer.end('fci')

    # CASCI
    elif method == 'casci':
        if inp.scf.cas is None and inp.scf.casorb is None:
            print ('ERROR: Must specify CAS space or CASORB')
            return inp

        ehf, mSCF = do_hf(inp)
        print_energy('RHF', ehf)

        # get cas space
        if inp.scf.cas is not None:
            if mol.spin == 0:
                nelecas = inp.scf.cas[0]
            else:
                nelecas = (inp.scf.cas[0]//2 + mol.spin//2,
                           inp.scf.cas[0]//2 - mol.spin//2)
            ncasorb = inp.scf.cas[1]
        elif inp.scf.casorb is not None:
            ncasorb = len(inp.scf.casorb)
            nelecas = int(np.sum(mSCF.mo_occ[inp.scf.casorb]))
            if inp.scf.casspin is not None:
                nelecas = (nelecas//2 + inp.scf.casspin//2,
                           nelecas//2 - inp.scf.casspin//2)

        inp.timer.start('casci')
        mCI = mcscf.CASCI(mSCF, ncasorb, nelecas)

        if inp.scf.casorb is not None:
            mo = mcscf.addons.sort_mo(mCI, np.copy(mSCF.mo_coeff), inp.scf.casorb, 0)
        else:
            mo = np.copy(mSCF.mo_coeff)

        eci = mCI.kernel(mo)[0]
        print_energy('CASCI', eci)
        inp.timer.end('casci')

    # CASSCF
    elif method == 'casscf' or method == 'ucasscf':
        if inp.scf.cas is None and inp.scf.casorb is None:
            print ('ERROR: Must specify CAS space or CASORB')
            return inp

        lunrestricted = (method == 'ucasscf')
        ehf, mSCF = do_hf(inp, unrestricted=lunrestricted)
        print_energy('HF', ehf)

        # get cas space
        if inp.scf.cas is not None:
            if mol.spin == 0:
                nelecas = inp.scf.cas[0]
            else:
                nelecas = (inp.scf.cas[0]//2 + mol.spin//2,
                           inp.scf.cas[0]//2 - mol.spin//2)
            ncasorb = inp.scf.cas[1]
        elif inp.scf.casorb is not None:
            ncasorb = len(inp.scf.casorb)
            nelecas = int(np.sum(mSCF.mo_occ[inp.scf.casorb]))
            if inp.scf.casspin is not None:
                nelecas = (nelecas//2 + inp.scf.casspin//2,
                           nelecas//2 - inp.scf.casspin//2)

        inp.timer.start('casscf')
        mCI = mcscf.CASSCF(mSCF, ncasorb, nelecas)

        if inp.scf.casorb is not None:
            mo = mcscf.addons.sort_mo(mCI, np.copy(mSCF.mo_coeff), inp.scf.casorb, 0)
        else:
            mo = np.copy(mSCF.mo_coeff)

        eci = mCI.kernel(mo)[0]
        print_energy('CASSCF', eci)
        inp.timer.end('casscf')

    # NEVPT2
    elif method == 'nevpt2' or method == 'unevpt2':
        if inp.scf.cas is None and inp.scf.casorb is None:
            print ('ERROR: Must specify CAS space or CASORB')
            return inp

        ehf, mSCF = do_hf(inp)
        print_energy('RHF', ehf)

        inp.timer.start('casscf')

        # get cas space
        if inp.scf.cas is not None:
            if mol.spin == 0:
                nelecas = inp.scf.cas[0]
            else:
                nelecas = (inp.scf.cas[0]//2 + mol.spin//2,
                           inp.scf.cas[0]//2 - mol.spin//2)
            ncasorb = inp.scf.cas[1]
        elif inp.scf.casorb is not None:
            ncasorb = len(inp.scf.casorb)
            nelecas = int(np.sum(mSCF.mo_occ[inp.scf.casorb]))
            if inp.scf.casspin is not None:
                nelecas = (nelecas//2 + inp.scf.casspin//2,
                           nelecas//2 - inp.scf.casspin//2)

        mCI = mcscf.CASSCF(mSCF, ncasorb, nelecas, frozen=inp.scf.freeze)

        if inp.scf.casorb is not None:
            mo = mcscf.addons.sort_mo(mCI, np.copy(mSCF.mo_coeff), inp.scf.casorb, 0)
        else:
            mo = np.copy(mSCF.mo_coeff)

        eci = mCI.kernel(mo)[0]
        print_energy('CASSCF', eci)
        inp.timer.end('casscf')

        inp.timer.start('nevpt2')
        mpt2 = mrpt.NEVPT(mCI)
        ept2 = mpt2.kernel() + eci
        print_energy('NEVPT2', ept2)
        inp.timer.end('nevpt2')

    else:
        print ('ERROR: Unrecognized SCF method!')
        raise SystemExit

    # dump fcidump file if needed
    if inp.fcidump:
        if inp.filename[-4:].lower() == '.inp':
            fcifile = inp.filename[:-4] + '.fcidump'
        else:
            fcifile = inp.filename + '.fcidump'
        fcidump(mSCF, filename=fcifile, tol=1e-6)

    # plot MOs if needed
    if inp.mo2cube:
        from .mo_2_cube import save_MOs
        save_MOs(inp, mSCF, mSCF.mo_coeff)

    # save molden file if needed
    if inp.molden:
        from pyscf.tools import molden
        molden_file = inp.filename[:-4] + '.molden'
        molden.from_mo(inp.mol, molden_file, mSCF.mo_coeff, ene=mSCF.mo_energy)

    # save and return
    inp.mf = mSCF
    return inp
Exemple #15
0
    4] = 0  # this excited state is originated from H**O(alpha) -> LUMO(alpha)
occ[0][5] = 1  # it is still a singlet state

# New SCF caculation
b = dft.UKS(mol)
b.xc = 'b3lyp'

# Construct new dnesity matrix with new occpuation pattern
dm_u = b.make_rdm1(mo0, occ)
# Apply mom occupation principle
b = scf.addons.mom_occ(b, mo0, occ)
# Start new SCF with new density matrix
b.scf(dm_u)

# 2. mom-Delta-SCF based on restricted open-shell HF/KS
c = dft.ROKS(mol)
c.xc = 'b3lyp'
# Use chkfile to store ground state information and start excited state
# caculation from these information directly
#c.chkfile='ground_ro.chkfile'
c.scf()

# Read MO coefficients and occpuation number from chkfile
#mo0 = scf.chkfile.load('ground_ro.chkfile', 'scf/mo_coeff')
#occ = scf.chkfile.load('ground_ro.chkfile', 'scf/mo_occ')
# Change 1-dimension occupation number list into 2-dimension occupation number
# list like the pattern in unrestircted calculation
mo0 = c.mo_coeff
occ = c.mo_occ
setocc = numpy.zeros((2, occ.size))
setocc[:, occ == 2] = 1
Exemple #16
0
from pyscf import dft
dft.roks.ROKS.Gradients = dft.rks_symm.ROKS.Gradients = lib.class_as_method(
    Gradients)

if __name__ == '__main__':
    from pyscf import gto
    from pyscf import dft

    mol = gto.Mole()
    mol.atom = [['O', (0., 0., 0.)], [1, (0., -0.757, 0.587)],
                [1, (0., 0.757, 0.587)]]
    mol.basis = '631g'
    mol.charge = 1
    mol.spin = 1
    mol.build()
    mf = dft.ROKS(mol)
    mf.conv_tol = 1e-12
    #mf.grids.atom_grid = (20,86)
    e0 = mf.scf()
    g = mf.Gradients()
    print(g.kernel())
    #[[ -4.20040265e-16  -6.59462771e-16   2.10150467e-02]
    # [  1.42178271e-16   2.81979579e-02  -1.05137653e-02]
    # [  6.34069238e-17  -2.81979579e-02  -1.05137653e-02]]
    g.grid_response = True
    print(g.kernel())

    mf.xc = 'b88,p86'
    e0 = mf.scf()
    g = Gradients(mf)
    print(g.kernel())
Exemple #17
0
 def test_nr_b3lypg_1e(self):
     mf = dft.ROKS(mol1).set(xc='b3lypg').run()
     self.assertAlmostEqual(mf.e_tot, -1.9931564410562266, 9)
Exemple #18
0
def ROKS(mol, *args):
    from pyscf import dft
    return dft.ROKS(mol, *args)