Exemple #1
0
ASF = asf.asf()

mol = gto.Mole()
mol.atom = """
C          0.00000        0.00000        0.00000
C          0.00000        0.00000        1.20000
"""
mol.basis = 'def2-svp'
mol.charge = 0
mol.spin = 0
mol.build()
# UHF for UNOs
mf = scf.RHF(mol).run(max_cycle=100)
mo_new = mf.stability()[0]
while mo_new is not mf.mo_coeff:
    mf.kernel(dm0=mf.make_rdm1(mo_coeff=mo_new))
    mo_new = mf.stability()[0]

# AVAS initial guess.
ao_labels = ['C 2s', 'C 2p']
norb, ne_act, orbs = avas.avas(mf, ao_labels, canonicalize=False)

# Plot AVAS selected orbitals.
# orbital list
fao = asf.act_fao(mf.mo_occ, ne_act)
orblist = fao + np.array(list(range(norb)))
asf.visualize_mos(mol, orbs, orblist)

# Select an active space using entropies.
ele, mos = ASF.find_active_space(mol, ne_act, norb, orbs, plot=True)
Exemple #2
0
# core: 1s2 2s2 2p6 3s2 3p6 (18e, 9o)
# active: 3d10 4s1/ 3d9 4s2 (11e, 11o)
ao_lb = gto.sph_labels(mol)
for i in range(30):
    ivs = np.argsort(mf.mo_coeff[:, i]**2)
    ss = ""
    for iv in ivs[::-1][:3]:
        ss += "%10.6f (%s)" % (mf.mo_coeff[iv, i]**2, ao_lb[iv].strip())
    print(" MO %2d :: %s" % (i, ss))

print("\n CASSCF(12, 11):\n")

from pyscf.mcscf import avas
ao_labels = ['Cu 3d', 'Cu 4s']
norb, ne_act, orbs = avas.avas(mf,
                               ao_labels,
                               threshold=0.001,
                               canonicalize=True)
print(norb, ne_act)

mc = mcscf.CASSCF(mf, norb, ne_act)
mc.state_average_((0.5, 0.1, 0.1, 0.1, 0.1, 0.1))
mc.kernel(orbs)

# cas_list = [9, 10, 11, 12, 13, 14, 22, 23, 24, 25, 26]
# mc = mcscf.CASSCF(mf, 11, (6, 5))
# mc.fix_spin_(ss=0.75)
# mo = mcscf.sort_mo(mc, mf.mo_coeff, cas_list, base=0)
# mc.state_average_((0.5, 0.1, 0.1, 0.1, 0.1, 0.1))
# mc.kernel(mo)

print(mc.nelecas, mc.e_states)
Exemple #3
0
def avas_active_space(pyscf_mf,
                      ao_list=None,
                      molden_fname='avas_localized_orbitals',
                      **kwargs):
    """ Return AVAS active space as PySCF molecule and mean-field object

    Args:
        pyscf_mf:  PySCF mean field object

    Kwargs:
        ao_list: list of strings of AOs (print mol.ao_labels() to see options)
                 Example: ao_list = ['H 1s', 'O 2p', 'O 2s'] for water
        verbose (bool): do additional print
        molden_fname (str): MOLDEN filename to save AVAS active space orbitals.
                            Default is to save
                            to 'avas_localized_orbitals.molden'
        **kwargs: other keyworded arguments to pass into avas.avas()

    Returns:
        pyscf_active_space_mol: Updated PySCF molecule object from
                                AVAS-selected active space
        pyscf_active_space_mf:  Updated PySCF mean field object from
                                AVAS-selected active space
    """

    # Note: requires openshell_option = 3 for this to work, which keeps all
    #     singly occupied in CAS
    # we also require canonicalize = False so that we don't destroy local orbs
    avas_output = avas.avas(pyscf_mf,
                            ao_list,
                            canonicalize=False,
                            openshell_option=3,
                            **kwargs)
    active_norb, active_ne, reordered_orbitals = avas_output

    active_alpha, _ = get_num_active_alpha_beta(pyscf_mf, active_ne)

    if molden_fname is not None:
        # save set of localized orbitals for active space
        if isinstance(pyscf_mf, scf.rohf.ROHF):
            frozen_alpha = pyscf_mf.nelec[0] - active_alpha
            assert frozen_alpha >= 0
        else:
            frozen_alpha = pyscf_mf.mol.nelectron // 2 - active_alpha
            assert frozen_alpha >= 0

        active_space_idx = slice(frozen_alpha, frozen_alpha + active_norb)
        active_mos = reordered_orbitals[:, active_space_idx]
        tools.molden.from_mo(pyscf_mf.mol,
                             molden_fname + '.molden',
                             mo_coeff=active_mos)

    # Choosing an active space changes the molecule ("freezing" electrons,
    # for example), so we
    # form the active space tensors first, then re-form the PySCF objects to
    # ensure consistency
    pyscf_active_space_mol, pyscf_active_space_mf = cas_to_pyscf(
        *pyscf_to_cas(pyscf_mf,
                      cas_orbitals=active_norb,
                      cas_electrons=active_ne,
                      avas_orbs=reordered_orbitals))

    return pyscf_active_space_mol, pyscf_active_space_mf
Exemple #4
0
'''
mol.basis = 'cc-pvtz-dk'
mol.spin = 0
mol.build()

mf = scf.ROHF(mol).x2c()
mf.kernel()

#
# The active space can be generated by pyscf.mcscf.avas.avas function
#
from pyscf.mcscf import avas
# See also 43-dmet_cas.py and function gto.mole.search_ao_label for the rules
# of "ao_labels" in the following
ao_labels = ['Fe 3d', 'C 2pz']
norb, ne_act, orbs = avas.avas(mf, ao_labels, canonicalize=False)

weights = numpy.ones(13)/13
solver1 = fci.addons.fix_spin(fci.direct_spin1.FCI(mol), ss=2) # <S^2> = 2 for Triplet
solver1.spin = 2
solver1.nroots = 6
solver2 = fci.addons.fix_spin(fci.direct_spin1.FCI(mol), ss=0) # <S^2> = 0 for Singlet
solver2.spin = 0
solver2.nroots = 7

mycas = mcscf.CASSCF(mf, norb, ne_act)
mycas.chkfile ='fecp2_3dpz.chk'
mcscf.state_average_mix_(mycas, [solver1, solver2], weights)
mycas.verbose = 6
mycas.kernel(orbs)
Exemple #5
0
Cl    1.639807   -1.639807   -0.539657
Cl   -1.639807   -1.639807   -0.539657
''',
    basis = 'cc-pvtz-dk',
    spin = 1,
    charge = -2,
    verbose = 5)

mf = scf.sfx2c1e(scf.ROHF(mol))
mf.chkfile = 'vocl4.chk'
mf.kernel()

#
# Generate the DMRG-CASSCF initial guess with AVAS (atomic valence active space) method.
#
norb_act, ne_act, mos = avas.avas(mf, ['V 3s', 'V 3p', 'V 3d', 'O 2p', 'Cl 3p'])

#
# Pass 1
# DMRG-CASSCF calculation with small M.  In many systems, the mcscf orbitals has
# weak dependence to the quality of the active space solution.  We can use small
# M to approximate the active space wave function and increase M for DMRG-CASCI
# and DMRG-NEVPT2 in next step.
#
mc = dmrgscf.DMRGSCF(mf, norb_act, ne_act)
mc.fcisolver.maxM = 500
mc.fcisolver.extraline = ['num_thrds %d'%lib.num_threads(), 'warmup local_2site']
mc.fcisolver.memory = 100  # GB
mc.conv_tol = 1e-6
mc.state_average_([.2]*3)
mc.kernel(mos)
Exemple #6
0
H      0.000000    2.292835    1.638208 
H      2.180615    0.708525    1.638208 
H      1.347694   -1.854942    1.638208  
'''
mol.basis = 'cc-pvtz-dk'
mol.spin = 0
mol.build()

mf = scf.sfx2c1e(scf.ROHF(mol))
mf.kernel()

#
# The active space can be generated by pyscf.mcscf.avas.avas function
#
from pyscf.mcscf import avas
norb, ne_act, orbs = avas.avas(mf, ['Fe 3d', 'C 2pz'], canonicalize=False)

#
# The followings are the step-by-step solution to construct the active space
# based on the formulas provided by the paper.
#

#====================================================================
#  To choose AOs for a given atom and a given shell to project into
#====================================================================
def AOset(mol, AO_id, l, shell):
  AOs =[]
  m=-l
  for i in range (2*l+1):
    AOs.append(mol.search_ao_nr(AO_id,l,m,shell))
    m +=1
Exemple #7
0
cell.precision = 1e-6
cell.a = '''
0.000000000, 3.370137329, 3.370137329
3.370137329, 0.000000000, 3.370137329
3.370137329, 3.370137329, 0.000000000'''
cell.unit = 'B'
cell.verbose = 4
cell.build()

mf = scf.RHF(cell).density_fit(auxbasis='def2-svp-jkfit')
mf.exxdiv = None
ehf = mf.kernel()

from pyscf.mcscf import avas
ao_labels = ['C 2s', 'C 2p']
norb, ne_act, orbs = avas.avas(mf, ao_labels, canonicalize=True, ncore=2)

mc = mcscf.CASSCF(mf, norb, ne_act)
#mc.fcisolver = fci.selected_ci_spin0.SCI()
#mc.fix_spin_(shift=.5, ss=0.0000)
#mc.fcisolver.ci_coeff_cutoff = 0.005
#mc.fcisolver.select_cutoff = 0.005
mc.kernel(orbs)

nmo = mc.ncore + mc.ncas
rdm1, rdm2 = mc.fcisolver.make_rdm12(mc.ci, mc.ncas, mc.nelecas) 
rdm1, rdm2 = mcscf.addons._make_rdm12_on_mo(rdm1, rdm2, mc.ncore, mc.ncas, nmo)

#natocc, natorb = numpy.linalg.eigh(-rdm1)
#for i, k in enumerate(numpy.argmax(abs(natorb), axis=0)):
#    if natorb[k,i] < 0:
Exemple #8
0
H      0.000000    2.292835    1.638208 
H      2.180615    0.708525    1.638208 
H      1.347694   -1.854942    1.638208  
'''
mol.basis = 'cc-pvtz-dk'
mol.spin = 0
mol.build()

mf = scf.sfx2c1e(scf.ROHF(mol))
mf.kernel()

#
# The active space can be generated by pyscf.mcscf.avas.avas function
#
from pyscf.mcscf import avas
norb, ne_act, orbs = avas.avas(mf, ['Fe 3d', 'C 2pz'], canonicalize=False)

#
# The followings are the step-by-step solution to construct the active space
# based on the formulas provided by the paper.
#


#====================================================================
#  To choose AOs for a given atom and a given shell to project into
#====================================================================
def AOset(mol, AO_id, l, shell):
    AOs = []
    m = -l
    for i in range(2 * l + 1):
        AOs.append(mol.search_ao_nr(AO_id, l, m, shell))