コード例 #1
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.UHF))
        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.ROHF))
        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.ROHF))
        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.GHF))
        self.assertTrue(not 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.ROHF))
        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.UHF))
        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.ROHF))
        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.GHF))

        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))
コード例 #2
0
H 0.000000 -1.246998 15.695371
   
                                                                ''',
    unit='Angstrom',
    basis='ccpvtz',
    max_memory=10000,
)

#
# By default optimal auxiliary basis (if possible) or even-tempered gaussian
# functions are used fitting basis.  You can assign with_df.auxbasis to change
# the change the fitting basis.
#
mol.spin = 0
mol.charge = 0
mol.build(0, 0)
mf = scf.RKS(mol)
mf.xc = 'cam-b3lyp'
energy = mf.kernel()
mos = mf.mo_energy
print(mos)
print('mo occ: ', mf.mo_occ)
print('total num of electrons: ', sum(mf.mo_occ))
homoIndex = int(sum(mf.mo_occ) / 2 - 1)
lumoIndex = homoIndex + 1
bandGap = (mos[lumoIndex] - mos[homoIndex]) * 27.2114
print('index: ', homoIndex, lumoIndex)
print('h**o E:', mos[homoIndex])
print('lumo E:', mos[lumoIndex])
print('band Gap (eV):', bandGap)
コード例 #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
コード例 #4
0
import os
import matplotlib.pyplot as plt

# Some input parameters, where obviously looping over dists is possible
basisname = "cc-pvdz"  # reference basis set
dist = 0.7608986485  # equilibrium distance at this level of theory, verified!
coord = 'H 0 0 0; H 0 0 {0}'.format(str(dist))
verb = 0  # integer verbosity flag
step = 0.001  # should be adapted and so on but whatever

# Do a mean-field KS-DFT calculation at dist
mol = gto.Mole(
    atom=coord, basis=basisname, charge=0,
    spin=0)  # build a molecule, neutral species, spin is N\alpha-N\beta here
mol.build()
mf = scf.RKS(mol)  # run DFT calculation as reference
mf.verbose = verb  # reduce output
mf.xc = 'lda,vwn'  # we select an approximate xc functional, many options available e.g. 'pbe,pbe' or 'b3lyp'
edft = mf.kernel()  # get DFT energy
nelec = mol.nelec  # number of electrons
print('The number of electrons is now {0}'.format(nelec))
print(' At a distance R = {0} angstrom:'.format(dist))
print(' DFT energy: {0} a.u.\n'.format(edft))  # total energies
gradients = grad.RKS(mf).kernel(
)  # We calculate analytical nuclear gradients, we choose the level of theory of the gradients
grad_atom_1 = gradients[0][2]
grad_atom_2 = gradients[1][2]
print(
    ' In the cartesian frame, gradient for atom 1 is {0}, gradient for atom 2 is {1}'
    .format(grad_atom_1, grad_atom_2))
totgrad = -1 * grad_atom_1 + grad_atom_2
コード例 #5
0
H    22.973000    23.598000    24.457000
H    23.982000    21.424000    25.481000
H    26.234000    21.645000    26.532000
H    27.292000    23.851000    26.796000
"""
mol.basis = "6-31G*"
mol.build()
pe_options = cppe.PeOptions()
pe_options.do_diis = True
pe_options.potfile = "nilered_in_water.pot"
pe = pol_embed.PolEmbed(mol, pe_options)
pe.verbose = 4

lib.num_threads(32)

mf = solvent.PE(scf.RKS(mol), pe)
mf.xc = "camb3lyp"

mf._numint.libxc = xcfun
mf.conv_tol = 1e-8
mf.verbose = 4
mf.kernel()

print(mf._pol_embed.cppe_state.summary_string)

td = TDA(mf)
td.verbose = 5
td.conv_tol = 1e-7
td.triplet = False
td.singlet = True
td.nstates = 3
コード例 #6
0
from __future__ import print_function, division
import unittest, numpy as np
from pyscf import gto, tddft, scf
from pyscf.nao import tddft_tem
from pyscf.nao import polariz_inter_ave, polariz_nonin_ave

mol = gto.M(
    verbose=1,
    atom=''' H  -0.5  -0.5  -0.5; H  0.5  0.5  0.5''',
    basis='cc-pvdz',
)

gto_mf = scf.RKS(mol)
gto_mf.kernel()
gto_td = tddft.TDDFT(gto_mf)
gto_td.nstates = 9
gto_td.kernel()

nao_td = tddft_tem(mf=gto_mf, gto=mol)


class KnowValues(unittest.TestCase):
    def test_tddft_tem(self):
        """ Interacting case """
        p_iter = -nao_td.get_spectrum_inter().imag
        data = np.array([nao_td.freq.real * 27.2114, p_iter])
        np.savetxt('hydrogen.tddft_tem_lda.omega.inter.pav.txt',
                   data.T,
                   fmt=['%f', '%f'])

コード例 #7
0
ファイル: 02-g_tensor.py プロジェクト: zzy2014/pyscf
gobj.so_eff_charge = True
gobj.kernel()

#
# Attribute gauge_orig controls whether to use GIAO.  GIAO is used by default.
#
gobj.gauge_orig = mol.atom_coord(1)  # on N atom
gobj.dia_soc2e = False
gobj.para_soc2e = True
gobj.so_eff_charge = False
gobj.kernel()

#
# In pure DFT (LDA, GGA), CPSCF has no effects.  Setting cphf=False can switch
# off CPSCF.
#
mf = dft.UKS(mol).set(xc='bp86').run()
gobj = gtensor.uks.GTensor(mf).set(verbose=4)
gobj.cphf = False
gobj.gauge_orig = (0, 0, 0)
gobj.kernel()

#
# Only UHF and UKS are supported in g-tensor module.  ROHF and ROKS need to be
# transfered to UHF or UKS before calling g-tensor methods.
#
mf = scf.RKS(mol).run()
mf = scf.convert_to_uhf(mf)
gobj = gtensor.uhf.GTensor(mf).set(verbose=4)
print(gobj.kernel())
コード例 #8
0
def do_scf(mol, func, dm0=None):
    mf = scf.RKS(mol)
    mf.xc = func
    mf.kernel(dm0=dm0)
    dm = mf.make_rdm1()
    return (mf, dm)
コード例 #9
0
import sys
import os
import matplotlib.pyplot as plt

# Some input parameters, where obviously looping over dists is possible
basisname = "cc-pvdz"  # reference basis set
dist = 0.7608986485  # equilibrium distance at this level of theory, verified!
coord = 'H 0 0 0; H 0 0 {0}'.format(str(dist))
verb = 0  # integer verbosity flag

# Do a mean-field KS-DFT calculation at dist
mol = gto.Mole(
    atom=coord, basis=basisname, charge=0,
    spin=0)  # build a molecule, neutral species, spin is N\alpha-N\beta here
mol.build()
mf = scf.RKS(mol)  # run DFT calculation as reference
mf.verbose = verb  # reduce output
mf.xc = 'lda,vwn'  # we select an approximate xc functional, many options available e.g. 'pbe,pbe' or 'b3lyp'
edft = mf.kernel()  # get DFT energy
nelec = mol.nelec  # number of electrons
print('The number of electrons is now {0}'.format(nelec))
print(' At a distance R = {0} angstrom:'.format(dist))
print(' DFT energy: {0} a.u.\n'.format(edft))  # total energies
mol_eq = optimize(mf)
#print(mol_eq.atom_coords())
dist = (mol_eq.atom_coords()[0][2] +
        mol_eq.atom_coords()[1][2]) * 0.529177  # bohr to angstrom conversion
mf = scf.RKS(mol_eq).run(xc='lda,vwn', verbose=0)
print(' At a distance R = {0} angstrom:'.format(dist))
print('DFT energy is now: {0} a.u.\n'.format(mf.e_tot))