예제 #1
0
파일: test_roks.py 프로젝트: zhcui/pyscf
    def test_finite_diff_roks_grad(self):
        mf = scf.ROKS(mol)
        mf.xc = 'b3lypg'
        mf.conv_tol = 1e-14
        e0 = mf.kernel()
        g = grad.ROKS(mf).kernel()
        mf_scanner = mf.as_scanner()

        e1 = mf_scanner('''O    0.   0.       0.
                        H     0.8  0.3      0.2
                        H    0.   -0.758   0.587
                        H    0.   0.757    0.587''')
        e2 = mf_scanner('''O    0.   0.       0.
                        H     0.8  0.3      0.2
                        H    0.   -0.756   0.587
                        H    0.   0.757    0.587''')
        self.assertAlmostEqual(g[2, 1], (e2 - e1) / 2e-3 * lib.param.BOHR, 4)
예제 #2
0
    def test_init(self):
        from pyscf import dft
        from pyscf import x2c
        mol_r = mol
        mol_u = gto.M(atom='Li', spin=1, verbose=0)
        mol_r1 = gto.M(atom='H', spin=1, verbose=0)
        sym_mol_r = molsym
        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(scf.RKS(mol_r), dft.rks.RKS))
        self.assertTrue(isinstance(scf.RKS(mol_u), dft.roks.ROKS))
        self.assertTrue(isinstance(scf.UKS(mol_r), dft.uks.UKS))
        self.assertTrue(isinstance(scf.ROKS(mol_r), dft.roks.ROKS))
        self.assertTrue(isinstance(scf.GKS(mol_r), dft.gks.GKS))
        self.assertTrue(isinstance(scf.KS(mol_r), dft.rks.RKS))
        self.assertTrue(isinstance(scf.KS(mol_u), dft.uks.UKS))

        self.assertTrue(isinstance(scf.RHF(mol_r), scf.hf.RHF))
        self.assertTrue(isinstance(scf.RHF(mol_u), scf.rohf.ROHF))
        self.assertTrue(isinstance(scf.RHF(mol_r1), scf.rohf.ROHF))
        self.assertTrue(isinstance(scf.UHF(mol_r), scf.uhf.UHF))
        self.assertTrue(isinstance(scf.UHF(mol_u), scf.uhf.UHF))
        self.assertTrue(isinstance(scf.UHF(mol_r1), scf.uhf.HF1e))
        self.assertTrue(isinstance(scf.ROHF(mol_r), scf.rohf.ROHF))
        self.assertTrue(isinstance(scf.ROHF(mol_u), scf.rohf.ROHF))
        self.assertTrue(isinstance(scf.ROHF(mol_r1), scf.rohf.HF1e))
        self.assertTrue(isinstance(scf.HF(mol_r), scf.hf.RHF))
        self.assertTrue(isinstance(scf.HF(mol_u), scf.uhf.UHF))
        self.assertTrue(isinstance(scf.HF(mol_r1), scf.rohf.HF1e))
        self.assertTrue(isinstance(scf.GHF(mol_r), scf.ghf.GHF))
        self.assertTrue(isinstance(scf.GHF(mol_u), scf.ghf.GHF))
        self.assertTrue(isinstance(scf.GHF(mol_r1), scf.ghf.HF1e))
        #TODO: self.assertTrue(isinstance(scf.DHF(mol_r), scf.dhf.RHF))
        self.assertTrue(isinstance(scf.DHF(mol_u), scf.dhf.UHF))
        self.assertTrue(isinstance(scf.DHF(mol_r1), scf.dhf.HF1e))

        self.assertTrue(isinstance(scf.RHF(sym_mol_r), scf.hf_symm.RHF))
        self.assertTrue(isinstance(scf.RHF(sym_mol_u), scf.hf_symm.ROHF))
        self.assertTrue(isinstance(scf.RHF(sym_mol_r1), scf.hf_symm.HF1e))
        self.assertTrue(isinstance(scf.UHF(sym_mol_r), scf.uhf_symm.UHF))
        self.assertTrue(isinstance(scf.UHF(sym_mol_u), scf.uhf_symm.UHF))
        self.assertTrue(isinstance(scf.UHF(sym_mol_r1), scf.uhf_symm.HF1e))
        self.assertTrue(isinstance(scf.ROHF(sym_mol_r), scf.hf_symm.ROHF))
        self.assertTrue(isinstance(scf.ROHF(sym_mol_u), scf.hf_symm.ROHF))
        self.assertTrue(isinstance(scf.ROHF(sym_mol_r1), scf.hf_symm.HF1e))
        self.assertTrue(isinstance(scf.HF(sym_mol_r), scf.hf_symm.RHF))
        self.assertTrue(isinstance(scf.HF(sym_mol_u), scf.uhf_symm.UHF))
        self.assertTrue(isinstance(scf.HF(sym_mol_r1), scf.hf_symm.ROHF))
        self.assertTrue(isinstance(scf.GHF(sym_mol_r), scf.ghf_symm.GHF))
        self.assertTrue(isinstance(scf.GHF(sym_mol_u), scf.ghf_symm.GHF))
        self.assertTrue(isinstance(scf.GHF(sym_mol_r1), scf.ghf_symm.HF1e))

        self.assertTrue(isinstance(scf.X2C(mol_r), x2c.x2c.UHF))
        self.assertTrue(isinstance(scf.sfx2c1e(scf.HF(mol_r)), scf.rhf.RHF))
        self.assertTrue(isinstance(scf.sfx2c1e(scf.HF(mol_u)), scf.uhf.UHF))
        self.assertTrue(isinstance(scf.sfx2c1e(scf.HF(mol_r1)), scf.rohf.ROHF))
        self.assertTrue(
            isinstance(scf.sfx2c1e(scf.HF(sym_mol_r)), scf.rhf_symm.RHF))
        self.assertTrue(
            isinstance(scf.sfx2c1e(scf.HF(sym_mol_u)), scf.uhf_symm.UHF))
        self.assertTrue(
            isinstance(scf.sfx2c1e(scf.HF(sym_mol_r1)), scf.hf_symm.ROHF))
        self.assertTrue(isinstance(scf.density_fit(scf.HF(mol_r)),
                                   scf.rhf.RHF))
        self.assertTrue(isinstance(scf.density_fit(scf.HF(mol_u)),
                                   scf.uhf.UHF))
        self.assertTrue(
            isinstance(scf.density_fit(scf.HF(mol_r1)), scf.rohf.ROHF))
        self.assertTrue(
            isinstance(scf.density_fit(scf.HF(sym_mol_r)), scf.rhf_symm.RHF))
        self.assertTrue(
            isinstance(scf.density_fit(scf.HF(sym_mol_u)), scf.uhf_symm.UHF))
        self.assertTrue(
            isinstance(scf.density_fit(scf.HF(sym_mol_r1)), scf.hf_symm.ROHF))
        self.assertTrue(isinstance(scf.newton(scf.HF(mol_r)), scf.rhf.RHF))
        self.assertTrue(isinstance(scf.newton(scf.HF(mol_u)), scf.uhf.UHF))
        self.assertTrue(isinstance(scf.newton(scf.HF(mol_r1)), scf.rohf.ROHF))
        self.assertTrue(
            isinstance(scf.newton(scf.HF(sym_mol_r)), scf.rhf_symm.RHF))
        self.assertTrue(
            isinstance(scf.newton(scf.HF(sym_mol_u)), scf.uhf_symm.UHF))
        self.assertTrue(
            isinstance(scf.newton(scf.HF(sym_mol_r1)), scf.hf_symm.ROHF))
예제 #3
0
def gen_scf_obj(mol, scf_method, **kwargs):
    """Generates an scf object setting all relevant parameters for use later in
    embedding"""

    if 'unrestricted' in kwargs and kwargs.get('unrestricted'):
        if 'hf' in scf_method:
            scf_obj = scf.UHF(mol)
        else:
            scf_obj = scf.UKS(mol)
            scf_obj.xc = scf_method
    elif mol.spin != 0:
        if 'hf' in scf_method:
            scf_obj = scf.ROHF(mol)
        else:
            scf_obj = scf.ROKS(mol)
            scf_obj.xc = scf_method
    else:
        if 'hf' in scf_method:
            scf_obj = scf.RHF(mol)
        else:
            scf_obj = scf.RKS(mol)
            scf_obj.xc = scf_method

    if 'diis_num' in kwargs:
        if kwargs.get('diis_num') == 0:
            scf_obj.DIIS = None
        if kwargs.get('diis_num') == 1:
            scf_obj.DIIS = scf.CDIIS
        if kwargs.get('diis_num') == 2:
            scf_obj.DIIS = scf.EDIIS
        if kwargs.get('diis_num') == 3:
            scf_obj.DIIS = scf.ADIIS

    if 'grid_level' in kwargs:
        grids = dft.gen_grid.Grids(mol)
        grids.level = kwargs.pop('grid_level')
        grids.build()
        scf_obj.grids = grids

    if 'dynamic_level_shift' in kwargs and kwargs.get('dynamic_level_shift'):
        if 'level_shift_factor' in kwargs:
            lev_shift_factor = kwargs.pop('level_shift_factor')
            scf.addons.dynamic_level_shift_(scf_obj, lev_shift_factor)
        else:
            scf.addons.dynamic_level_shift_(scf_obj)

    if 'newton' in kwargs and kwargs.pop('newton'):
        scf_obj = scf.newton(scf_obj)

    if 'fast_newton' in kwargs and kwargs.pop('fast_newton'):
        scf_obj.use_fast_newton = True

    if 'frac_occ' in kwargs and kwargs.get('frac_occ'):
        scf_obj = scf.addons.frac_occ(mf)

    if 'remove_linear_dep' in kwargs and kwargs.get('remove_linear_dep'):
        scf_obj = scf_obj.apply(scf.addons.remove_linear_dep)

    if 'density_fitting' in kwargs and kwargs.get('density_fitting'):
        scf_obj = scf_obj.density_fit()

    if 'excited' in kwargs:
        scf_obj.excited = kwargs['excited']
        #Setup excited object.
        pass

    for key in kwargs:
        setattr(scf_obj, key, kwargs[key])

    return scf_obj