Esempio n. 1
0
    def test_nr_uks_fast_newton(self):
        mf = dft.UKS(h4_z1_s)
        mf.xc = 'b3lyp'
        mf1 = scf.fast_newton(mf)
        self.assertAlmostEqual(mf1.e_tot, -39.696083841107587, 9)

        mf1 = scf.fast_newton(dft.UKS(h4_z1_s))
        self.assertAlmostEqual(mf1.e_tot, -39.330377813428001, 9)
Esempio n. 2
0
    def test_nr_uks_fast_newton(self):
        mf = dft.UKS(h4_z1_s)
        mf.xc = 'b3lyp'
        mf1 = scf.fast_newton(mf)
        self.assertAlmostEqual(mf1.e_tot, -39.696083841107587, 8)

        mf1 = scf.fast_newton(dft.UKS(h4_z1_s))
        self.assertAlmostEqual(mf1.e_tot, -39.330377813428001, 8)
Esempio n. 3
0
    def test_scanner(self):
        from pyscf import dft
        mol1 = molsym.copy()
        mol1.set_geom_('''
        O   0.   0.       .1
        H   0.   -0.757   0.587
        H   0.   0.757    0.587''')
        mf_scanner = scf.UHF(molsym).density_fit('weigend').as_scanner()
        self.assertAlmostEqual(mf_scanner(molsym), -75.98321088694874, 8)
        self.assertAlmostEqual(mf_scanner(mol1), -75.97901175977492, 8)

        mf_scanner = scf.fast_newton(scf.ROHF(molsym)).as_scanner()
        self.assertAlmostEqual(mf_scanner(molsym), -75.983948498066198, 8)
        self.assertAlmostEqual(mf_scanner(mol1), -75.97974371226907, 8)

        mf_scanner = dft.RKS(molsym).set(xc='bp86').as_scanner()
        self.assertAlmostEqual(mf_scanner(molsym), -76.385043416002361, 8)
        eref = dft.RKS(mol1).set(xc='bp86').kernel()
        e1 = mf_scanner(mol1)
        self.assertAlmostEqual(e1, -76.372784697245777, 8)
        self.assertAlmostEqual(e1, eref, 8)

        # Test init_guess_by_chkfile for stretched geometry and different basis set
        mol1.atom = '''
        O   0.   0.      -.5
        H   0.  -0.957   0.587
        H   0.   0.957   0.587'''
        mol1.basis = 'ccpvdz'
        mol1.build(0, 0)
        self.assertAlmostEqual(mf_scanner(mol1), -76.273052274103648, 7)
Esempio n. 4
0
    def test_scanner(self):
        from pyscf import dft
        mol1 = molsym.copy()
        mol1.set_geom_('''
        O   0.   0.       .1
        H   0.   -0.757   0.587
        H   0.   0.757    0.587''')
        mf_scanner = scf.UHF(molsym).density_fit('weigend').as_scanner()
        self.assertAlmostEqual(mf_scanner(molsym), -75.98321088694874, 8)
        self.assertAlmostEqual(mf_scanner(mol1), -75.97901175977492, 8)

        mf_scanner = scf.fast_newton(scf.ROHF(molsym)).as_scanner()
        self.assertAlmostEqual(mf_scanner(molsym), -75.983948498066198, 8)
        self.assertAlmostEqual(mf_scanner(mol1), -75.97974371226907, 8)

        mf_scanner = dft.RKS(molsym).set(xc='bp86').as_scanner()
        self.assertAlmostEqual(mf_scanner(molsym), -76.385043416002361, 8)
        self.assertAlmostEqual(mf_scanner(mol1), -76.372784697245777, 8)

        # Test init_guess_by_chkfile for stretched geometry and different basis set
        mol1.atom = '''
        O   0.   0.      -.5
        H   0.  -0.957   0.587
        H   0.   0.957   0.587'''
        mol1.basis = 'ccpvdz'
        mol1.build(0,0)
        self.assertAlmostEqual(mf_scanner(mol1), -76.273052274103648, 8)
Esempio n. 5
0
 def test_fast_newton(self):
     nao = mol.nao_nr()
     dm0 = numpy.zeros((nao, nao))
     mf = scf.fast_newton(scf.RHF(mol),
                          dm0=dm0,
                          dual_basis=True,
                          kf_trust_region=3.)
     self.assertAlmostEqual(mf.e_tot, -75.983948497843272, 9)
Esempio n. 6
0
def solve_scf(mol, **scfargs):
    HFmethod = scf.HF if not _MUST_UNRES else scf.UHF
    mf = HFmethod(mol).set(init_guess_breaksym=True)
    init_dm = mf.get_init_guess()
    # if _MUST_UNRES:
    #     init_dm[1][:2,:2] = 0
    mf.kernel(init_dm)
    if _USE_NEWTON:
        mf = scf.fast_newton(mf)
    return mf
Esempio n. 7
0
    def test_nr_uks_fast_newton(self):
        mol = gto.M(
            verbose = 5,
            output = '/dev/null',
            atom = '''C 0 0 0
            H  1  1  1
            H -1 -1  1
            H -1  1 -1
            H  1 -1 -1''',
            basis = '6-31g',
            charge = 1,
            spin = 1,
            symmetry = 1,
        )
        mf = dft.UKS(mol)
        mf.xc = 'b3lyp'
        mf1 = scf.fast_newton(mf)
        self.assertAlmostEqual(mf1.e_tot, -39.69608384046235, 9)

        mf1 = scf.fast_newton(dft.UKS(mol))
        self.assertAlmostEqual(mf1.e_tot, -39.330377813428001, 9)
Esempio n. 8
0
    def test_nr_uks_fast_newton(self):
        mol = gto.M(
            verbose=5,
            output='/dev/null',
            atom='''C 0 0 0
            H  1  1  1
            H -1 -1  1
            H -1  1 -1
            H  1 -1 -1''',
            basis='6-31g',
            charge=1,
            spin=1,
            symmetry=1,
        )
        mf = dft.UKS(mol)
        mf.xc = 'b3lyp'
        mf1 = scf.fast_newton(mf)
        self.assertAlmostEqual(mf1.e_tot, -39.696083841107587, 9)

        mf1 = scf.fast_newton(dft.UKS(mol))
        self.assertAlmostEqual(mf1.e_tot, -39.330377813428001, 9)
Esempio n. 9
0
 def test_nr_rks_fast_newton(self):
     mol = gto.M(
         verbose = 5,
         output = '/dev/null',
         atom = '''C 0 0 0
         H  1  1  1
         H -1 -1  1
         H -1  1 -1
         H  1 -1 -1''',
         basis = '6-31g',
         symmetry = 1,
     )
     mf = dft.RKS(mol)
     mf.xc = 'b3lyp'
     mf1 = scf.fast_newton(mf)
     self.assertAlmostEqual(mf1.e_tot, -40.10277421254213, 9)
Esempio n. 10
0
 def test_nr_rks_fast_newton(self):
     mol = gto.M(
         verbose=5,
         output='/dev/null',
         atom='''C 0 0 0
         H  1  1  1
         H -1 -1  1
         H -1  1 -1
         H  1 -1 -1''',
         basis='6-31g',
         symmetry=1,
     )
     mf = dft.RKS(mol)
     mf.xc = 'b3lyp'
     mf1 = scf.fast_newton(mf)
     self.assertAlmostEqual(mf1.e_tot, -40.10277421254213, 9)
Esempio n. 11
0
 def test_nr_rohf_fast_newton(self):
     mol = gto.M(
         verbose=5,
         output='/dev/null',
         atom='''C 0 0 0
         H  1  1  1
         H -1 -1  1
         H -1  1 -1
         H  1 -1 -1''',
         basis='6-31g',
         charge=1,
         spin=1,
         symmetry=1,
     )
     mf = scf.ROHF(mol)
     mf1 = scf.fast_newton(mf)
     self.assertAlmostEqual(mf1.e_tot, -39.365972147397649, 9)
Esempio n. 12
0
 def test_nr_rohf_fast_newton(self):
     mol = gto.M(
         verbose = 5,
         output = '/dev/null',
         atom = '''C 0 0 0
         H  1  1  1
         H -1 -1  1
         H -1  1 -1
         H  1 -1 -1''',
         basis = '6-31g',
         charge = 1,
         spin = 1,
         symmetry = 1,
     )
     mf = scf.ROHF(mol)
     mf1 = scf.fast_newton(mf)
     self.assertAlmostEqual(mf1.e_tot, -39.365972147397649, 9)
Esempio n. 13
0
    def test_scanner(self):
        from pyscf import dft
        mol1 = molsym.copy()
        mol1.set_geom_('''
        O   0.   0.       .1
        H   0.   -0.757   0.587
        H   0.   0.757    0.587''')
        mf_scanner = scf.UHF(molsym).density_fit('weigend').as_scanner()
        self.assertAlmostEqual(mf_scanner(molsym), -75.98321088694874, 9)
        self.assertAlmostEqual(mf_scanner(mol1), -75.97901175977492, 9)

        mf_scanner = scf.fast_newton(scf.ROHF(molsym)).as_scanner()
        self.assertAlmostEqual(mf_scanner(molsym), -75.983948498066198, 9)
        self.assertAlmostEqual(mf_scanner(mol1), -75.97974371226907, 9)

        mf_scanner = dft.RKS(molsym).set(xc='bp86').as_scanner()
        self.assertAlmostEqual(mf_scanner(molsym), -76.385043416002361, 9)
        self.assertAlmostEqual(mf_scanner(mol1), -76.372784697245777, 9)
Esempio n. 14
0
 def test_nr_rohf_fast_newton(self):
     mf = scf.ROHF(h4_z1_s)
     mf1 = scf.fast_newton(mf)
     self.assertAlmostEqual(mf1.e_tot, -39.365972147397649, 9)
Esempio n. 15
0
 def test_nr_rks_fast_newton(self):
     mf = dft.RKS(h4_z0_s)
     mf.xc = 'b3lyp'
     mf1 = scf.fast_newton(mf)
     self.assertAlmostEqual(mf1.e_tot, -40.10277421254213, 9)
Esempio n. 16
0
 def test_nr_rohf_fast_newton(self):
     mf = scf.ROHF(h4_z1_s)
     mf1 = scf.fast_newton(mf)
     self.assertAlmostEqual(mf1.e_tot, -39.365972147397649, 9)
Esempio n. 17
0
H 6.771983 5.230175 -0.172724
H 7.325546 6.456228 -1.103449
H 8.153994 6.005554 0.233135
H 3.372639 5.237613 5.430001
H 2.420871 5.752619 4.203299
H 2.631033 4.150531 4.458321
H 6.225091 2.641675 2.914287
H 5.612530 2.721618 4.428971
H 4.651591 2.282146 3.180231
H 4.947415 4.665452 0.537824
H 3.725531 3.767789 1.151899
H 3.515369 5.369877 0.896878
H 9.224480 4.780740 3.228456
H 10.002053 5.784964 4.259380
H 9.010897 4.621544 4.842435
H 7.210886 6.878915 6.599377
H 8.578203 7.641391 6.125073
H 7.135300 8.403680 6.011782
H 8.308553 8.287098 2.094287
H 7.797036 9.254716 3.309999
H 9.239940 8.492427 3.423290 
''',
            basis = 'ccpvdz',
            charge = 3,
            spin = 3,
            verbose = 5,
            output = 'cu3.out')

mf = scf.fast_newton(scf.RHF(mol))
mf.kernel()
Esempio n. 18
0
    ['C' , (-2.4150 , -2.4083 , 0.0000)],
    ['C' , (2.4150  , -2.4083 , 0.0000)],
    ['H' , (3.1855  , 3.1752  , 0.0000)],
    ['H' , (-3.1855 , 3.1752  , 0.0000)],
    ['H' , (-3.1855 , -3.1752 , 0.0000)],
    ['H' , (3.1855  , -3.1752 , 0.0000)],
]
mol.basis = 'ccpvdz'
mol.verbose = 4
mol.output = 'fepor.out'
mol.spin = 4
mol.symmetry = True
mol.build()

mf = scf.ROHF(mol)
mf = scf.fast_newton(mf)

#
# CAS(8e, 11o)
#
# mcscf.density_fit approximates the orbital hessian.  It does not affect
# CASSCF results.
#
mc = mcscf.density_fit(mcscf.CASSCF(mf, 11, 8))
idx = [i for i,s in enumerate(mol.spheric_labels(1)) if 'Fe 3d' in s or 'Fe 4d' in s]
mo = dmet_cas(mc, mf.make_rdm1(), idx)

mc.fcisolver.wfnsym = 'Ag'
mc.kernel(mo)
#mc.analyze()
e_q = mc.e_tot  # -2244.82910509839
Esempio n. 19
0
    ['C' , (-2.4150 , -2.4083 , 0.0000)],
    ['C' , (2.4150  , -2.4083 , 0.0000)],
    ['H' , (3.1855  , 3.1752  , 0.0000)],
    ['H' , (-3.1855 , 3.1752  , 0.0000)],
    ['H' , (-3.1855 , -3.1752 , 0.0000)],
    ['H' , (3.1855  , -3.1752 , 0.0000)],
]
mol.basis = 'ccpvdz'
mol.verbose = 4
mol.output = 'fepor.out'
mol.spin = 4
mol.symmetry = True
mol.build()

mf = scf.ROHF(mol)
mf = scf.fast_newton(mf)
# ao_labels are keyword(s) to match the AOs generated by mol.ao_labels()
# function.  ao_labels can be a string, or a pattern of regular expression
# or a list of strings/patterns.  The code can detect the format and find
# the AOs to be taken into the active space.
# See also function gto.mole.search_ao_label for the rules of ao_pattern
ao_pattern = ['Fe 3d', 'Fe 4d']
ncas, nelecas, mo = dmet_cas.guess_cas(mf, mf.make_rdm1(), ao_pattern)
mc = mcscf.approx_hessian(mcscf.CASSCF(mf, ncas, nelecas))
mc.kernel(mo)
e_q = mc.e_tot  # -2244.82910509839




Esempio n. 20
0
 def test_fast_newton(self):
     nao = mol.nao_nr()
     dm0 = numpy.zeros((nao,nao))
     mf = scf.fast_newton(scf.RHF(mol), dm0=dm0, dual_basis=True,
                          kf_trust_region=3.)
     self.assertAlmostEqual(mf.e_tot, -75.983948497843272, 9)
    ['H' , (-1.3558 , -5.0416 , 0.0000)],
    ['H' , (1.3558  , -5.0416 , 0.0000)],
    ['C' , (2.4150  , 2.4083  , 0.0000)],
    ['C' , (-2.4150 , 2.4083  , 0.0000)],
    ['C' , (-2.4150 , -2.4083 , 0.0000)],
    ['C' , (2.4150  , -2.4083 , 0.0000)],
    ['H' , (3.1855  , 3.1752  , 0.0000)],
    ['H' , (-3.1855 , 3.1752  , 0.0000)],
    ['H' , (-3.1855 , -3.1752 , 0.0000)],
    ['H' , (3.1855  , -3.1752 , 0.0000)],
]

mol.basis = 'ccpvdz'
mol.verbose = 5
mol.output = 'fepor3.out'
mol.spin = 2
mol.symmetry = True
mol.build()

m = scf.ROHF(mol)
m.level_shift_factor = 1.5
scf.fast_newton(m)

mc = mcscf.CASSCF(m, 10, 10)
idx3d = [i for i,s in enumerate(mol.spheric_labels(1)) if 'Fe 3d' in s]
mo = dmet_cas.dmet_cas(mc, m.make_rdm1(), idx3d, base=0)
fci.addons.fix_spin_(mc.fcisolver, ss_value=2)  # Triplet, ss_value = S*(S+1)
mc.fcisolver.wfnsym = 'B1g'
mc.kernel(mo)

Esempio n. 22
0
 def test_nr_rks_fast_newton(self):
     mf = dft.RKS(h4_z0_s)
     mf.xc = 'b3lyp'
     mf1 = scf.fast_newton(mf)
     self.assertAlmostEqual(mf1.e_tot, -40.10277421254213, 9)
Esempio n. 23
0
H 10.002053 5.784964 4.259380
H 9.010897 4.621544 4.842435
H 7.210886 6.878915 6.599377
H 8.578203 7.641391 6.125073
H 7.135300 8.403680 6.011782
H 8.308553 8.287098 2.094287
H 7.797036 9.254716 3.309999
H 9.239940 8.492427 3.423290 
''',
            basis='ccpvdz',
            charge=3,
            spin=3,
            verbose=4,
            output='cu3.out')

mf = scf.fast_newton(scf.RHF(mol))
print('E(tot) %.15g  ref = -5668.38221757799' % mf.e_tot)

#
# scf.fast_newton function can be used for specific initial guess.
#
# We first create an initial guess with DIIS iterations. The DIIS results are
# saved in a checkpoint file which can be load in another calculation.
#
mf = scf.RHF(mol)
mf.chkfile = 'cu3-diis.chk'
mf.max_cycle = 2
mf.kernel()

#
# Load the DIIS results then use it as initial guess for function
Esempio n. 24
0
#!/usr/bin/env python
#
# Author: Qiming Sun <*****@*****.**>
#

from pyscf import gto
from pyscf import scf, dft

'''
As a Python script, you can use any Python trick to create your calculation.
In this example, we read the molecule geometry from another file.
'''

mol = gto.Mole()
mol.verbose = 5
mol.atom = open('glycine.xyz').read()
mol.basis = '6-31g*'
mol.build()

mf = scf.RHF(mol)
scf.fast_newton(mf)

mf = dft.RKS(mol)
scf.fast_newton(mf)