# Adjust the MPI schedular and scratch directory if needed. # NOTE the DMRG-NEVPT2 is expensive, it requires about 8 GB memory per processor # #from pyscf.dmrgscf import settings #settings.MPIPREFIX = 'srun' #settings.BLOCKSCRATCHDIR = '/scratch' from pyscf.dmrgscf.dmrgci import DMRGCI, DMRGSCF from pyscf.mrpt.nevpt2 import sc_nevpt # # Redirect output to another file # mol.build_(verbose=7, output = 'hs_dmrg.out') mf = scf.sfx2c1e(scf.RHF(mol)) mc = DMRGSCF(mf, norb, [nalpha,nbeta]) mc.chkfile = 'hs_mc.chk' mc.max_memory = 30000 mc.fcisolver.maxM = 1000 mc.fcisolver.tol = 1e-6 orbs = mc.sort_mo(caslst, coeff, base=0) mc.mc1step(orbs) # # CASCI-NEVPT2 # # If DMRG-CASSCF was finished without any problems (eg convergence, wall time # limits on cluster etc), one can simply continue with DMRG-NEVPT2 like # sc_nevpt(mc)
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.HF1e)) 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.HF1e)) 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.HF1e)) 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.HF1e)) #TODO: self.assertTrue(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.HF1e)) 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.HF1e)) 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.HF1e)) 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.HF1e)) 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))
the Hessian for the large-basis-density-fitted-scf scheme. ''' mol = gto.Mole() mol.build( verbose = 0, atom = '''8 0 0. 0 1 0 -0.757 0.587 1 0 0.757 0.587''', basis = 'ccpvdz', ) # # 1. spin-free X2C-HF with density fitting approximation on 2E integrals # mf = scf.density_fit(scf.sfx2c1e(scf.RHF(mol))) mf = scf.RHF(mol).x2c().density_fit() # Stream style energy = mf.kernel() print('E = %.12f, ref = -76.075408156180' % energy) # # 2. spin-free X2C correction for density-fitting HF. Since X2C correction is # commutable with density fitting operation, it is fully equivalent to case 1. # mf = scf.sfx2c1e(scf.density_fit(scf.RHF(mol))) mf = scf.RHF(mol).density_fit().x2c() # Stream style energy = mf.kernel() print('E = %.12f, ref = -76.075408156180' % energy) # # 3. The order to apply X2C or newton method matters. If relativistic effects
# Adjust the MPI schedular and scratch directory if needed. # NOTE the DMRG-NEVPT2 is expensive, it requires about 8 GB memory per processor # #from pyscf.dmrgscf import settings #settings.MPIPREFIX = 'srun' #settings.BLOCKSCRATCHDIR = '/scratch' from pyscf.dmrgscf import DMRGCI, DMRGSCF from pyscf import mrpt # # Redirect output to another file # mol.build(verbose=7, output='hs_dmrg.out') mf = scf.sfx2c1e(scf.RHF(mol)) mc = DMRGSCF(mf, norb, [nalpha, nbeta]) mc.chkfile = 'hs_mc.chk' mc.max_memory = 30000 mc.fcisolver.maxM = 1000 mc.fcisolver.tol = 1e-6 orbs = mc.sort_mo(caslst, coeff, base=0) mc.mc1step(orbs) # # CASCI-NEVPT2 # # If DMRG-CASSCF was finished without any problems (eg convergence, wall time # limits on cluster etc), one can simply continue with DMRG-NEVPT2 # mrpt.NEVPT(mc).kernel() #
# NEVPT2 calculation requires about 200 GB memory in total # b = 1.5 mol = gto.Mole() mol.verbose = 5 mol.output = 'cr2-%3.2f.out' % b mol.atom = [ ['Cr',( 0.000000, 0.000000, -b/2)], ['Cr',( 0.000000, 0.000000, b/2)], ] mol.basis = {'Cr': 'ccpvdz-dk'} mol.symmetry = True mol.build() m = scf.sfx2c1e(scf.RHF(mol)).run(conv_tol=1e-9, chkfile='hf_chk-%s'%b, level_shift=0.5) # # Note: stream operations are used here. This one line code is equivalent to # the following serial statements. # #m = scf.sfx2c1e(scf.RHF(mol)) #m.conv_tol = 1e-9 #m.chkfile = 'hf_chk-%s'%b #m.level_shift = 0.5 #m.kernel() dm = m.make_rdm1() m.level_shift = 0 m.scf(dm) mc = DMRGSCF(m, 20, 28) # 20o, 28e
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))
mf = scf.RHF(mol) mf.irrep_nelec = {'Ag': (6, 3), 'B1g': (1, 0), 'B2g': (1, 0), 'B3g': (1, 0)} mf.scf(rdm1) # # The third way to force the calculation strictly following the correct # configurations is the second order SCF optimizaiton. In the following code, # we call a calculation on cation for a correct HF configuration with spherical # symmetry. This HF configuration is next pass to second order SCF solver # scf.newton to solve X2C-ROHF model of the open shell atom. # mol = gto.M(verbose=4, symmetry=True, atom=[ ['Cr', (0, 0, 0)], ], basis='cc-pvdz-dk', charge=6, spin=0) mf = scf.sfx2c1e(scf.RHF(mol)).run() mo, mo_occ = mf.mo_coeff, mf.mo_occ mol.charge = 0 mol.spin = 6 mol.build(False, False) mf = scf.newton(scf.sfx2c1e(scf.RHF(mol))) mo_occ[9:15] = 1 mf.kernel(mo, mo_occ) #mf.analyze()
the Hessian for the large-basis-density-fitted-scf scheme. ''' mol = gto.Mole() mol.build( verbose=0, atom='''8 0 0. 0 1 0 -0.757 0.587 1 0 0.757 0.587''', basis='ccpvdz', ) # # 1. spin-free X2C-HF with density fitting approximation on 2E integrals # mf = scf.density_fit(scf.sfx2c1e(scf.RHF(mol))) mf = scf.RHF(mol).x2c().density_fit() # Stream style energy = mf.kernel() print('E = %.12f, ref = -76.075408156180' % energy) # # 2. spin-free X2C correction for density-fitting HF. Since X2C correction is # commutable with density fitting operation, it is fully equivalent to case 1. # mf = scf.sfx2c1e(scf.density_fit(scf.RHF(mol))) mf = scf.RHF(mol).density_fit().x2c() # Stream style energy = mf.kernel() print('E = %.12f, ref = -76.075408156180' % energy) # # 3. The order to apply X2C or newton method matters. If relativistic effects
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