def test_sort_mo_by_irrep(self): mc1 = mcscf.CASSCF(mfr, 8, 4) mo0 = mcscf.sort_mo_by_irrep(mc1, mfr.mo_coeff, { 'E1ux': 2, 'E1uy': 2, 'E1gx': 2, 'E1gy': 2 }) mo1 = mcscf.sort_mo_by_irrep(mc1, mfr.mo_coeff, { 2: 2, 3: 2, 6: 2, 7: 2 }, { 2: 0, 3: 0, 6: 0, 7: 0 }) mo2 = mcscf.sort_mo_by_irrep(mc1, mfr.mo_coeff, (0, 0, 2, 2, 0, 0, 2, 2)) mo3 = mcscf.sort_mo_by_irrep(mc1, mfr.mo_coeff, { 'E1ux': 2, 'E1uy': 2, 2: 2, 3: 2 }) self.assertTrue(numpy.allclose(mo0, mo1)) self.assertTrue(numpy.allclose(mo0, mo2)) self.assertTrue(numpy.allclose(mo0, mo3))
def test_sort_mo_by_irrep(self): mc1 = mcscf.CASSCF(mfr, 8, 4) mo0 = mcscf.sort_mo_by_irrep(mc1, mfr.mo_coeff, {'E1ux':2, 'E1uy':2, 'E1gx':2, 'E1gy':2}) mo1 = mcscf.sort_mo_by_irrep(mc1, mfr.mo_coeff, {2:2, 3:2, 6:2, 7:2}, {2:0, 3:0, 6:0, 7:0}) mo2 = mcscf.sort_mo_by_irrep(mc1, mfr.mo_coeff, (0,0,2,2,0,0,2,2)) mo3 = mcscf.sort_mo_by_irrep(mc1, mfr.mo_coeff, {'E1ux':2, 'E1uy':2, 2:2, 3:2}) self.assertTrue(numpy.allclose(mo0, mo1)) self.assertTrue(numpy.allclose(mo0, mo2)) self.assertTrue(numpy.allclose(mo0, mo3))
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
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
nelec = 44 # Building SHCISCF Object mch = shci.SHCISCF(mf, norb, nelec) mo = mcscf.sort_mo_by_irrep( mch, mf.mo_coeff, { "Ag": 6, "B3u": 3, "B2u": 3, "B1g": 4, "B1u": 7, "B2g": 8, "B3g": 8, "Au": 5 }, { "Ag": 21, "B3u": 18, "B2u": 18, "B1g": 12, "B1u": 2, "B2g": 0, "B3g": 0, "Au": 0 }, ) mch.chkfile = "fe_dz_5Ag_SHCISCF_44e_44o.chk" mch.fcisolver.sweep_iter = [0, 3, 6] mch.fcisolver.sweep_epsilon = [1e-3, 5e-4, 1e-4]
#!/usr/bin/env python # # Author: Qiming Sun <*****@*****.**> # ''' Active space can be adjusted by specifing the number of orbitals for each irrep. ''' from pyscf import gto, scf, mcscf mol = gto.Mole() mol.build( atom='N 0 0 0; N 0 0 2', basis='ccpvtz', symmetry=True, ) myhf = scf.RHF(mol) myhf.kernel() mymc = mcscf.CASSCF(myhf, 8, 4) mo = mcscf.sort_mo_by_irrep(mymc, myhf.mo_coeff, { 'E1gx': 2, 'E1gy': 2, 'E1ux': 2, 'E1uy': 2 }) mymc.kernel(mo)
nelec = 32 # Building SHCISCF Object mch = shci.SHCISCF(mf, norb, nelec) mo = mcscf.sort_mo_by_irrep( mch, mf.mo_coeff, { "Ag": 2, "B3u": 0, "B2u": 0, "B1g": 1, "B1u": 7, "B2g": 7, "B3g": 7, "Au": 5 }, { "Ag": 23, "B3u": 19, "B2u": 19, "B1g": 14, "B1u": 2, "B2g": 0, "B3g": 0, "Au": 0 }, ) mch.chkfile = "fe_tz_5Ag_SHCISCF.chk" mch.fcisolver.sweep_iter = [0, 3, 6] mch.fcisolver.sweep_epsilon = [1e-3, 5e-4, 1e-4]
from pyscf import gto, scf, mcscf mol = gto.Mole() mol.build( atom='N 0 0 0; N 0 0 2', basis='ccpvtz', symmetry=True, ) myhf = scf.RHF(mol) myhf.kernel() mymc = mcscf.CASSCF(myhf, 8, 4) # Select active orbitals which have the specified symmetry # 2 E1gx orbitals, 2 E1gy orbitals, 2 E1ux orbitals, 2 E1uy orbitals cas_space_symmetry = {'E1gx': 2, 'E1gy': 2, 'E1ux': 2, 'E1uy': 2} mo = mcscf.sort_mo_by_irrep(mymc, myhf.mo_coeff, cas_space_symmetry) mymc.kernel(mo) mol = gto.Mole() mol.build( atom='Ti', basis='ccpvdz', symmetry=True, spin=2, ) myhf = scf.RHF(mol) myhf.kernel() myhf.analyze() mymc = mcscf.CASSCF(myhf, 14, 2) # Put 3d, 4d, 4s, 4p orbtials in active space
mol.build() mf = scf.RHF(mol) mf.kernel() 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} mc = mcscf.CASSCF(mf, 12, 12) mc.max_cycle_macro = 250 mc.max_cycle_micro = 7 mc.fcisolver = fci.direct_spin0_symm.FCI() #mc.fix_spin_(shift=.5, ss=0) mo = mcscf.sort_mo_by_irrep(mc, mf.mo_coeff, ncas, ncore) emc = mc.mc1step(mo)[0] mo = mc.mo_coeff nmo = mo.shape[1] ncore = mc.ncore ncas = mc.ncas nocc = mc.ncore + mc.ncas nvir = mo.shape[1] - nocc # transform the CAS natural orbitals rdm1 = mc.fcisolver.make_rdm1(mc.ci, mc.ncas, mc.nelecas) occ, ucas = scipy.linalg.eigh(rdm1) logger.info(mc, 'Natural occs') logger.info(mc, str(occ)) natocc = numpy.zeros(mo.shape[1])
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.sfx2c1e(scf.RHF(mol)) 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 = mcscf.sort_mo_by_irrep(mc, mf.mo_coeff, ncas, ncore) 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() # Passing the results as an initial guess to the next point. return mf.make_rdm1(), mc.mo_coeff, mc.ci
from pyscf import gto, scf, mcscf mol = gto.Mole() mol.build( atom = 'N 0 0 0; N 0 0 2', basis = 'ccpvtz', symmetry = True, ) myhf = scf.RHF(mol) myhf.kernel() mymc = mcscf.CASSCF(myhf, 8, 4) # Select active orbitals which have the specified symmetry # 2 E1gx orbitals, 2 E1gy orbitals, 2 E1ux orbitals, 2 E1uy orbitals cas_space_symmetry = {'E1gx':2, 'E1gy':2, 'E1ux':2, 'E1uy':2} mo = mcscf.sort_mo_by_irrep(mymc, myhf.mo_coeff, cas_space_symmetry) mymc.kernel(mo) mol = gto.Mole() mol.build( atom = 'Ti', basis = 'ccpvdz', symmetry = True, spin = 2, ) myhf = scf.RHF(mol) myhf.kernel() myhf.analyze() mymc = mcscf.CASSCF(myhf, 14, 2)
#!/usr/bin/env python # # Author: Qiming Sun <*****@*****.**> # from pyscf import gto, scf, mcscf ''' Active space can be adjusted by specifing the number of orbitals for each irrep. ''' mol = gto.Mole() mol.build( atom = 'N 0 0 0; N 0 0 2', basis = 'ccpvtz', symmetry = True, ) myhf = scf.RHF(mol) myhf.kernel() mymc = mcscf.CASSCF(myhf, 8, 4) mo = mcscf.sort_mo_by_irrep(mymc, myhf.mo_coeff, {'E1gx':2, 'E1gy':2, 'E1ux':2, 'E1uy':2}) mymc.kernel(mo)