Exemple #1
0
def run(b, dm, mo, ci=None):
    mol = gto.Mole()
    mol.verbose = 5
    mol.output = 'cr2-%2.1f.out' % b
    mol.atom = [
        ['Cr',(  0.000000,  0.000000, -b/2)],
        ['Cr',(  0.000000,  0.000000,  b/2)],
    ]
    mol.basis = 'cc-pVTZ'
    mol.symmetry = 1
    mol.build()
    mf = scf.RHF(mol)
    mf.level_shift_factor = .4
    mf.max_cycle = 100
    mf.conv_tol = 1e-9
    ehf.append(mf.scf(dm))

    mc = mcscf.CASSCF(mf, 12, 12)
    mc.fcisolver.conv_tol = 1e-9
    if mo is None:
        # the initial guess for b = 1.5
        ncore = {'A1g':5, 'A1u':5}  # Optional. Program will guess if not given
        ncas = {'A1g':2, 'A1u':2,
                'E1ux':1, 'E1uy':1, 'E1gx':1, 'E1gy':1,
                'E2ux':1, 'E2uy':1, 'E2gx':1, 'E2gy':1}
        mo = mcscf.sort_mo_by_irrep(mc, mf.mo_coeff, ncas, ncore)
    else:
        mo = mcscf.project_init_guess(mc, mo)
    emc.append(mc.kernel(mo)[0])
    mc.analyze()
    return mf.make_rdm1(), mc.mo_coeff, mc.ci
Exemple #2
0
def run(b, mo0=None, dm0=None):
    mol = gto.Mole()
    mol.build(
        verbose = 5,
        output = 'o2rhf-%3.2f.out' % b,
        atom = [
            ['O', (0, 0,  b/2)],
            ['O', (0, 0, -b/2)],],
        basis = 'cc-pvdz',
        spin = 2,
        symmetry = 1,
    )

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

    mc = mcscf.CASSCF(mf, 12, 8)
    if mo0 is not None:
        #from pyscf import lo
        #mo0 = lo.orth.vec_lowdin(mo0, mf.get_ovlp())
        mo0 = mcscf.project_init_guess(mc, mo0)
    else:
        mo0 = mcscf.sort_mo(mc, mf.mo_coeff, [5,6,7,8,9,11,12,13,14,15,16,17])
        mc.max_orb_stepsize = .02
    mc.kernel(mo0)
    mc.analyze()
    return mf, mc
Exemple #3
0
def run(b, dm, mo, ci=None):
    mol = gto.Mole()
    mol.verbose = 5
    mol.output = 'cr2-%2.1f.out' % b
    mol.atom = [
        ['Cr',(  0.000000,  0.000000, -b/2)],
        ['Cr',(  0.000000,  0.000000,  b/2)],
    ]
    mol.basis = 'cc-pVTZ'
    mol.symmetry = 1
    mol.build()
    m = scf.RHF(mol)
    m.level_shift_factor = .4
    m.max_cycle = 100
    m.conv_tol = 1e-9
    ehf.append(m.scf(dm))

    mc = mcscf.CASSCF(m, 12, 12)
    mc.fcisolver.conv_tol = 1e-9
    if mo is None:
        # the initial guess for b = 1.5
        caslst = [19,20,21,22,23,24,25,28,29,31,32,33]
        mo = mcscf.addons.sort_mo(mc, m.mo_coeff, caslst, 1)
    else:
        mo = mcscf.project_init_guess(mc, mo)
    emc.append(mc.kernel(mo)[0])
    mc.analyze()
    return m.make_rdm1(), mc.mo_coeff, mc.ci
Exemple #4
0
def run(b, dm, mo):
    mol = gto.Mole()
    mol.verbose = 5
    mol.output = 'out_hf-%2.1f' % b
    mol.atom = [
        ["F", (0., 0., 0.)],
        ["H", (0., 0., b)],
    ]

    mol.basis = {
        'F': 'cc-pvdz',
        'H': 'cc-pvdz',
    }
    mol.build()
    mf = scf.RHF(mol)
    ehf.append(mf.scf(dm))

    mc = mcscf.CASSCF(mf, 6, 6)
    if mo is None:
        # initial guess for b = 0.7
        mo = mcscf.sort_mo(mc, mf.mo_coeff, [3, 4, 5, 6, 8, 9])
    else:
        mo = mcscf.project_init_guess(mc, mo)
    e1 = mc.mc1step(mo)[0]
    emc.append(e1)
    return mf.make_rdm1(), mc.mo_coeff
Exemple #5
0
def run(i, dm0, mo0, ci0):
    x = i
    y = (2.54 - 0.46 * x)
    x = x * 0.529177249
    y = y * 0.529177249
    mol = gto.M(verbose=0,
                atom=[
                    ['Be', (0., 0., 0.)],
                    ['H', (x, -y, 0.)],
                    ['H', (x, y, 0.)],
                ],
                basis='6-311G',
                symmetry=True)

    mf = scf.RHF(mol)
    ehf = mf.scf(dm0)

    mc = mcscf.CASSCF(mf, 2, 2)
    mc.fcisolver.davidson_only = True  # force the CI solver stick on (A1)^2(B1)^0 configuration
    if mo0 is not None:
        mo0 = mcscf.project_init_guess(mc, mo0)

    emc = mc.mc1step(mo0, ci0)[0]

    print('%2.1f bohr, HF energy: %12.8f, CASSCF energy: %12.8f' %
          (i, ehf, emc))
    return mf, mc
Exemple #6
0
def run(i, dm0, mo0):
    x = i
    y = (2.54 - 0.46 * x)
    x = x * 0.529177249
    y = y * 0.529177249
    mol = gto.M(
        verbose = 5,
        output = 'out-%2.1f'%i,
        atom = [
            ['Be',( 0., 0.    , 0.   )],
            ['H', ( x, -y    , 0.    )],
            ['H', ( x,  y    , 0.    )],],
        basis = '6-311G',
        symmetry = True)

    mf = scf.RHF(mol)
    ehf = mf.scf(dm0)
    mf.analyze()

    mc = mcscf.CASSCF(mf, 2, 2)
    mc.fcisolver.davidson_only = True # force the CI solver stick on (A1)^2(B1)^0 configuration
    if mo0 is not None:
        mo0 = mcscf.project_init_guess(mc, mo0)

    emc = mc.mc1step(mo0)[0]
    mc.analyze()

    print('%2.1f bohr, HF energy: %12.8f, CASSCF energy: %12.8f' % (i, ehf, emc))
    return mf, mc
Exemple #7
0
    def test_project_init_guess(self):
        b = 1.5
        mol1 = gto.M(
            verbose=0, atom=[["O", (0.000000, 0.000000, -b / 2)], ["O", (0.000000, 0.000000, b / 2)]], basis="ccpvtz"
        )
        mf1 = scf.RHF(mol1).run()
        mc1 = mcscf.CASSCF(mf1, 4, 4)
        mo1 = mcscf.project_init_guess(mc1, mfr.mo_coeff, prev_mol=mol)
        s1 = reduce(numpy.dot, (mo1.T, mf1.get_ovlp(), mo1))
        self.assertEqual(numpy.count_nonzero(numpy.linalg.eigh(s1)[0] > 1e-10), s1.shape[0])
        self.assertAlmostEqual(numpy.linalg.norm(s1), 7.7459666924148349, 9)

        self.assertRaises(AssertionError, mcscf.project_init_guess, mc1, mfr.mo_coeff)
Exemple #8
0
 def test_project_init_guess(self):
     b = 1.5
     mol1 = gto.M(
     verbose = 0,
     atom = [
         ['N',(  0.000000,  0.000000, -b/2)],
         ['N',(  0.000000,  0.000000,  b/2)], ],
     basis = 'ccpvdz',)
     mf1 = scf.RHF(mol1).run()
     mc1 = mcscf.CASSCF(mf1, 4, 4).run()
     mo1 = mcscf.project_init_guess(mc1, mfr.mo_coeff, prev_mol=mol)
     s1 = reduce(numpy.dot, (mo1.T, mf1.get_ovlp(), mo1))
     self.assertEqual(numpy.count_nonzero(numpy.linalg.eigh(s1)[0]>1e-10),
                      s1.shape[0])
     self.assertAlmostEqual(numpy.linalg.norm(s1), 5.2915026221291841, 9)
Exemple #9
0
 def test_project_init_guess(self):
     b = 1.5
     mol1 = gto.M(
         verbose=0,
         atom=[
             ['N', (0.000000, 0.000000, -b / 2)],
             ['N', (0.000000, 0.000000, b / 2)],
         ],
         basis='ccpvdz',
     )
     mf1 = scf.RHF(mol1).run()
     mc1 = mcscf.CASSCF(mf1, 4, 4).run()
     mo1 = mcscf.project_init_guess(mc1, mfr.mo_coeff, prev_mol=mol)
     s1 = reduce(numpy.dot, (mo1.T, mf1.get_ovlp(), mo1))
     self.assertEqual(numpy.count_nonzero(numpy.linalg.eigh(s1)[0] > 1e-10),
                      s1.shape[0])
     self.assertAlmostEqual(numpy.linalg.norm(s1), 5.2915026221291841, 9)
Exemple #10
0
    def test_project_init_guess(self):
        b = 1.5
        mol1 = gto.M(
        verbose = 0,
        atom = [
            ['O',(  0.000000,  0.000000, -b/2)],
            ['O',(  0.000000,  0.000000,  b/2)], ],
        basis = 'ccpvtz',)
        mf1 = scf.RHF(mol1).run()
        mc1 = mcscf.CASSCF(mf1, 4, 4)
        mo1 = mcscf.project_init_guess(mc1, mfr.mo_coeff, prev_mol=mol)
        s1 = reduce(numpy.dot, (mo1.T, mf1.get_ovlp(), mo1))
        self.assertEqual(numpy.count_nonzero(numpy.linalg.eigh(s1)[0]>1e-10),
                         s1.shape[0])
        self.assertAlmostEqual(numpy.linalg.norm(s1), 7.7459666924148349, 9)

        self.assertRaises(AssertionError, mcscf.project_init_guess, mc1, mfr.mo_coeff)
Exemple #11
0
def run(b, dm, mo):
    mol = gto.Mole()
    mol.verbose = 5
    mol.output = 'out_hf-%2.1f' % b
    mol.atom = [
        ["F", (0., 0., 0.)],
        ["H", (0., 0., b)],]
    mol.spin = 2
    mol.basis = {'F': 'cc-pvdz',
                 'H': 'cc-pvdz',}
    mol.build()
    m = scf.RHF(mol)
    ehf.append(m.scf(dm))

    mc = mcscf.CASSCF(m, 6, 6)
    if mo is None:
        mo = mcscf.sort_mo(mc, m.mo_coeff, [3,4,5,6,8,9])
    else:
        mo = mcscf.project_init_guess(mc, mo)
    e1 = mc.mc1step(mo)[0]
    emc.append(e1)
    return m.make_rdm1(), mc.mo_coeff
Exemple #12
0
def run(b, dm, mo, ci=None):
    mol = gto.M(
        verbose = 5,
        output = 'cr2-%2.1f.out' % b,
        atom = 'Cr 0 0 0; Cr 0 0 %f' % b,
        basis = 'cc-pVTZ',
        symmetry = 1,
    )
    m = scf.RHF(mol)
    m.conv_tol = 1e-9
    ehf.append(m.scf(dm))

    mc = mcscf.CASSCF(m, 12, 12)
    if mo is None:
        # the initial guess for b = 1.5
        caslst = [19,20,21,22,23,24,25,28,29,31,32,33]
        mo = mcscf.addons.sort_mo(mc, m.mo_coeff, caslst, 1)
    else:
        mo = mcscf.project_init_guess(mc, mo)
    emc.append(mc.kernel(mo)[0])
    mc.analyze()
    ept.append(mrpt.NEVPT(mc).kernel())
    return m.make_rdm1(), mc.mo_coeff, mc.ci
Exemple #13
0
def run(b, dm, mo, ci=None):
    mol = gto.M(
        verbose=5,
        output='cr2-%2.1f.out' % b,
        atom='Cr 0 0 0; Cr 0 0 %f' % b,
        basis='cc-pVTZ',
        symmetry=1,
    )
    m = scf.RHF(mol)
    m.conv_tol = 1e-9
    ehf.append(m.scf(dm))

    mc = mcscf.CASSCF(m, 12, 12)
    if mo is None:
        # the initial guess for b = 1.4
        caslst = [19, 20, 21, 22, 23, 24, 25, 28, 29, 31, 32, 33]
        mo = mcscf.addons.sort_mo(mc, m.mo_coeff, caslst, 1)
    else:
        mo = mcscf.project_init_guess(mc, mo)
    emc.append(mc.kernel(mo)[0])
    mc.analyze()
    ept.append(mrpt.nevpt2.kernel(mc))
    return m.make_rdm1(), mc.mo_coeff, mc.ci
Exemple #14
0
def run(b, dm, mo, ci=None):
    mol = gto.Mole()
    mol.verbose = 5
    mol.output = "cr2-%2.1f.out" % b
    mol.atom = [["Cr", (0.000000, 0.000000, -b / 2)], ["Cr", (0.000000, 0.000000, b / 2)]]
    mol.basis = "cc-pVTZ"
    mol.symmetry = 1
    mol.build()
    m = scf.RHF(mol)
    m.level_shift_factor = 0.4
    m.max_cycle = 100
    m.conv_tol = 1e-9
    ehf.append(m.scf(dm))

    mc = mcscf.CASSCF(m, 12, 12)
    mc.fcisolver.conv_tol = 1e-9
    if mo is None:
        # the initial guess for b = 1.5
        ncore = {"A1g": 5, "A1u": 5}  # Optional. Program will guess if not given
        ncas = {
            "A1g": 2,
            "A1u": 2,
            "E1ux": 1,
            "E1uy": 1,
            "E1gx": 1,
            "E1gy": 1,
            "E2ux": 1,
            "E2uy": 1,
            "E2gx": 1,
            "E2gy": 1,
        }
        mo = mcscf.sort_mo_by_irrep(mc, m.mo_coeff, ncas, ncore)
    else:
        mo = mcscf.project_init_guess(mc, mo)
    emc.append(mc.kernel(mo)[0])
    mc.analyze()
    return m.make_rdm1(), mc.mo_coeff, mc.ci
Exemple #15
0
def urun(b, mo0=None, dm0=None):
    mol = gto.Mole()
    mol.build(
        verbose = 5,
        output = 'o2uhf-%3.2f.out' % b,
        atom = [
            ['O', (0, 0,  b/2)],
            ['O', (0, 0, -b/2)],],
        basis = 'cc-pvdz',
        spin = 2,
    )

    mf = scf.UHF(mol)
    mf.scf(dm0)

    mc = mcscf.CASSCF(mf, 12, 8)
    if mo0 is not None:
        #from pyscf import lo
        #mo0 =(lo.orth.vec_lowdin(mo0[0], mf.get_ovlp()),
        #      lo.orth.vec_lowdin(mo0[1], mf.get_ovlp()))
        mo0 = mcscf.project_init_guess(mc, mo0)
    mc.kernel(mo0)
    mc.analyze()
    return mf, mc
CASSCF solver can use any orbital as initial guess, no matter how and where
you get the orbital coeffcients.  It can even be the orbitals of different
molecule.
'''

mol1 = gto.M(
    atom = 'C 0 0 0; C 0 0 1.2',
    basis = '6-31g')
mf = scf.RHF(mol1)
mf.kernel()

mo_init_guess = mf.mo_coeff

#############################################################
#
# Use the inital guess from mol1 system for mol2 CASSCF
#
#############################################################
mol2 = gto.M(
    atom = 'O 0 0 0; O 0 0 1.2',
    basis = 'ccpvdz',
    spin = 2)
mf = scf.RHF(mol2)
mf.kernel()
mc = mcscf.CASSCF(mf, 4, 4)
mo = mcscf.project_init_guess(mc, mo_init_guess, mol1)
mc.verbose = 4
mc.kernel(mo)
print('E(CAS) = %.12f, ref = -149.622580905034' % mc.e_tot)

mo_init_guess = mf.mo_coeff

#############################################################
#
# Use the initial guess from mol1 system for mol2 CASSCF
#
#############################################################

# 1. If only the geometry is different, we only need to give
#    the function the guess orbitals

mol1 = gto.M(atom='C 0 0 0; C 0 0 1.3', basis='6-31g', verbose=4)
mf = scf.RHF(mol1)
mf.kernel()
mc1 = mcscf.CASSCF(mf, 4, 4)
mo = mcscf.project_init_guess(mc1, mo_init_guess)
mc1.kernel(mo)
print('E(CAS) = %.12f, ref = -75.465214455907' % mc1.e_tot)

# 2. When we change the basis set, we also need to give it
#    the original molecule corresponding to our guess

mol2 = gto.M(atom='C 0 0 0; C 0 0 1.2', basis='cc-pvdz', verbose=4)
mf = scf.RHF(mol2)
mf.kernel()
mc2 = mcscf.CASSCF(mf, 4, 4)
mo = mcscf.project_init_guess(mc2, mo_init_guess, prev_mol=mol0)
mc2.kernel(mo)
print('E(CAS) = %.12f, ref = -75.482856483217' % mc2.e_tot)

# 3. Changing the basis set and geometry at the same time is
Exemple #18
0
def run(b, dm_guess, mo_guess, ci=None):
    mol = gto.Mole()
    mol.verbose = 5
    mol.output = 'cr2-%3.2f.out' % b
    mol.atom = [
        ['Cr',(  0.,  0., -b/2)],
        ['Cr',(  0.,  0.,  b/2)],
    ]
    mol.basis = 'ccpvdzdk'
    mol.symmetry = True
    mol.build()

    mf = scf.RHF(mol).x2c()
    mf.max_cycle = 100
    mf.conv_tol = 1e-9
    mf.kernel(dm_guess)

#---------------------
# CAS(12,12)
#
# The active space of CAS(12,42) can be generated by function sort_mo_by_irrep,
# or AVAS, dmet_cas methods.  Here we first run a CAS(12,12) calculation and
# using the lowest CASSCF canonicalized orbitals in the CAS(12,42) calculation
# as the core and valence orbitals.
    mc = mcscf.CASSCF(mf, 12, 12)
    if mo_guess is None:
# the initial guess for first calculation
        ncas = {'A1g' : 2, 'E1gx' : 1, 'E1gy' : 1, 'E2gx' : 1, 'E2gy' : 1,
                'A1u' : 2, 'E1ux' : 1, 'E1uy' : 1, 'E2ux' : 1, 'E2uy' : 1}
        mo_guess = mc.sort_mo_by_irrep(ncas)
    else:
        mo_guess = mcscf.project_init_guess(mc, mo_guess)

# Projection may destroy the spatial symmetry of the MCSCF orbitals.
        try:
            print('Irreps of the projected CAS(12,12) orbitals',
                  symm.label_orb_symm(mol, mol.irrep_id, mol.symm_orb, mo_guess))
        except:
            print('Projected CAS(12,12) orbitals does not have right symmetry')

# FCI solver with multi-threads is not stable enough for this sytem
    mc.fcisolver.threads = 1
# To avoid spin contamination
    mc.fix_spin_()
# By default, canonicalization as well as the CASSCF optimization do not
# change the orbital symmetry labels. "Orbital energy" mc.mo_energy, the
# diagonal elements of the general fock matrix, may have wrong ordering.
# To use the lowest CASSCF orbitals as the core + active orbitals in the next
# step, we have to sort the orbitals based on the "orbital energy". This
# operation will change the orbital symmetry labels.
    mc.sorting_mo_energy = True
# "mc.natorb = True" will transform the active space, to its natural orbital
# representation.  By default, the active space orbitals are NOT reordered
# even the option sorting_mo_energy is enabled.  Transforming the active space
# orbitals is a dangerous operation because it needs also to update the CI
# wavefunction. For DMRG solver (or other approximate FCI solver), the CI
# wavefunction may not be able to consistently converged and it leads to
# inconsistency between the orbital space and the CI wavefunction
# representations.  Unless required by the following CAS calculation, setting
# mc.natorb=True should be avoided
#    mc.natorb = True

    mc.kernel(mo_guess, ci)
    mc.analyze()

#---------------------
# CAS(12,42)
#
# Using the lowest CASSCF canonicalized orbitals in the CAS(12,42) DMRG-CASSCF
# calculation.
    norb = 42
    nelec = 12
    mc1 = DMRGSCF(mf, norb, nelec)
    mc1.fcisolver.maxM = 4000

# Enable internal rotation since the bond dimension of DMRG calculation is
# small, the active space energy can be optimized wrt to the orbital rotation
# within the active space.
    mc1.internal_rotation = True
# Sorting the orbital energy is not a step of must here.
#    mc1.sorting_mo_energy = True
#    mc1.natorb = True

    mc1.kernel(mc.mo_coeff)

# Passing the results as an initial guess to the next point.
    return mf.make_rdm1(), mc.mo_coeff, mc.ci
Exemple #19
0
    idx_h1_1s = mol.search_ao_label ('1 H 1s')[0]
    idx_h0_2s = mol.search_ao_label ('0 H 2s')[0]
    idx_h1_2s = mol.search_ao_label ('1 H 2s')[0]
    dma = np.zeros ((nao, nao))
    dmb = np.zeros ((nao, nao))
    dma[idx_h0_1s,idx_h0_1s] = dmb[idx_h1_1s,idx_h1_1s] = dma[idx_h0_2s,idx_h0_2s] = dmb[idx_h1_2s,idx_h1_2s] = 1
dm0 = [dma, dmb]

# Restricted mean-field base of MC-SCF objects
mf = scf.RHF (mol).run ()

# MC-PDFT objects
if gsbasis:
    gsmo = np.load (gsmofile)
    mc = mcpdft.CASSCF (mf, transl_type + fnal, ncas, nelecas, grids_level = 3)
    mo = mcscf.project_init_guess (mc, gsmo, prev_mol=gsmol)
    molden.from_mo (mol, 'check_projection.molden', mo)
    mc.kernel (mo)
    mc = mc.as_scanner ()
else:  
    mc = mcpdft.CASSCF (mf, transl_type + fnal, ncas, nelecas, grids_level = 3).run ().as_scanner ()
np.save (mofile, mc.mo_coeff)

# Do MCSCF scan forwards
table = np.zeros ((HHrange.size, 9))
table[:,0] = HHrange
for ix, HHdist in enumerate (HHrange):
    geom = 'H 0 0 0; H 0 0 {:.6f}'.format (HHdist)
    table[ix,1] = mc (geom)
    table[ix,2] = mc.e_mcscf
    table[ix,3:] = list (mc.get_energy_decomposition ())