pyscf.mcscf package¶
Submodules¶
pyscf.mcscf.PiOS module¶
When using results of this code for publications, please cite the following paper: “Constructing molecular pi-orbital active spaces for multireference calculations of conjugated systems”
Sayfutyarova and S. Hammes-Schiffer, J. Chem. Theory Comput., 15, 1679 (2019).
- pyscf.mcscf.PiOS.MakeOverlappingOrbSubspace(Space, Name, COrb, nOrbExpected, CTargetIb, S1, Fock)[source]¶
- pyscf.mcscf.PiOS.MakePiSystemOrbitals(TargetName, iTargetAtomsForPlane_, iTargetAtomsForBasis_, Elements, Coords, CIb, Shells, S1, S12, S2, Fock, COcc, CVir)[source]¶
- pyscf.mcscf.PiOS.MakeShellsForElement(mol, Element)[source]¶
make a list with MINAO basis set data for a given element in the mol object
pyscf.mcscf.addons module¶
- class pyscf.mcscf.addons.StateAverageMixFCISolver_state_args(data)[source]¶
Bases:
pyscf.mcscf.addons.StateAverageMixFCISolver_solver_args
- pyscf.mcscf.addons.cas_natorb(casscf, mo_coeff=None, ci=None, sort=False)[source]¶
Natrual orbitals in CAS space
- pyscf.mcscf.addons.caslst_by_irrep(casscf, mo_coeff, cas_irrep_nocc, cas_irrep_ncore=None, s=None, base=1)[source]¶
Given number of active orbitals for each irrep, return the orbital indices of active space
- Args:
casscf : an
CASSCF
orCASCI
object- cas_irrep_nocclist or dict
Number of active orbitals for each irrep. It can be a dict, eg {‘A1’: 2, ‘B2’: 4} to indicate the active space size based on irrep names, or {0: 2, 3: 4} for irrep Id, or a list [2, 0, 0, 4] (identical to {0: 2, 3: 4}) in which the list index is served as the irrep Id.
- Kwargs:
- cas_irrep_ncorelist or dict
Number of closed shells for each irrep. It can be a dict, eg {‘A1’: 6, ‘B2’: 4} to indicate the closed shells based on irrep names, or {0: 6, 3: 4} for irrep Id, or a list [6, 0, 0, 4] (identical to {0: 6, 3: 4}) in which the list index is served as the irrep Id. If cas_irrep_ncore is not given, the program will generate a guess based on the lowest
CASCI.ncore
orbitals.- sndarray
overlap matrix
- baseint
0-based (C-like) or 1-based (Fortran-like) caslst
- Returns:
A list of orbital indices
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvtz', symmetry=True, verbose=0) >>> mf = scf.RHF(mol) >>> mf.kernel() >>> mc = mcscf.CASSCF(mf, 12, 4) >>> mcscf.caslst_by_irrep(mc, mf.mo_coeff, {'E1gx':4, 'E1gy':4, 'E1ux':2, 'E1uy':2}) [5, 7, 8, 10, 11, 14, 15, 20, 25, 26, 31, 32]
- pyscf.mcscf.addons.get_fock(casscf, mo_coeff=None, ci=None)[source]¶
Generalized Fock matrix in AO representation
- pyscf.mcscf.addons.make_rdm1(casscf, mo_coeff=None, ci=None, **kwargs)[source]¶
One-particle densit matrix in AO representation
- Args:
casscf : an
CASSCF
orCASCI
object- Kwargs:
- cindarray
CAS space FCI coefficients. If not given, take casscf.ci.
- mo_coeffndarray
Orbital coefficients. If not given, take casscf.mo_coeff.
Examples:
>>> import scipy.linalg >>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='sto-3g', verbose=0) >>> mf = scf.RHF(mol) >>> res = mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> res = mc.kernel() >>> natocc = numpy.linalg.eigh(mcscf.make_rdm1(mc), mf.get_ovlp(), type=2)[0] >>> print(natocc) [ 0.0121563 0.0494735 0.0494735 1.95040395 1.95040395 1.98808879 2. 2. 2. 2. ]
- pyscf.mcscf.addons.make_rdm1s(casscf, mo_coeff=None, ci=None, **kwargs)[source]¶
Alpha and beta one-particle densit matrices in AO representation
- pyscf.mcscf.addons.map2hf(casscf, mf_mo=None, base=1, tol=0.4)[source]¶
The overlap between the CASSCF optimized orbitals and the canonical HF orbitals.
- pyscf.mcscf.addons.project_init_guess(casscf, mo_init, prev_mol=None, priority=None, use_hf_core=None)[source]¶
Project the given initial guess to the current CASSCF problem giving using a sequence of SVDs on orthogonal orbital subspaces.
- Args:
casscf : an
CASSCF
orCASCI
object- mo_initndarray or list of ndarray
Initial guess orbitals which are not orthonormal for the current molecule. When the casscf is UHF-CASSCF, mo_init needs to be a list of two ndarrays, for alpha and beta orbitals. Cannot have linear dependencies (i.e., you cannot give more orbitals than the basis of casscf.mol has). Must have at least ncore+ncas columns with active orbitals last, even if use_hf_core=True. If incomplete, additional virtual orbitals will be constructed and appended automatically.
- Kwargs:
- prev_molan instance of
Mole
If given, the inital guess orbitals are associated to the basis of prev_mol. Otherwise, the orbitals are presumed to be in the basis of casscf.mol. Beware linear dependencies if you are projecting from a LARGER basis to a SMALLER one.
- priority‘active’, ‘core’, nested idx arrays, or mask array
If arrays are 3d, UHF-CASSCF must be used; arrays can always be 2d. Specifies the order in which groups of orbitals are projected. Orbitals orthogonalized earlier are deformed less than those orthogonalized later. ‘core’ means core, then active, then virtual; ‘active’ means active, then core, then virtual, and the Gram-Schmidt process is generated by [[0],[1],[2],…] or numpy.eye (nmo). Missing orbitals are presumed virtual. Defaults to ‘active’ if you are projecting from the same basis set (prev_mol is None or has the same basis functions) and ‘core’ otherwise.
- use_hf_corelogical
If True, the core orbitals of mo_init are swapped out with HF orbitals chosen by maximum overlap. Defaults to True if you are projecting from a different basis and False if you are projecting from a different geometry.
- prev_molan instance of
- Returns:
New orthonormal initial guess orbitals
- pyscf.mcscf.addons.project_init_guess_old(casscf, init_mo, prev_mol=None)[source]¶
Project the given initial guess to the current CASSCF problem. The projected initial guess has two parts. The core orbitals are directly taken from the Hartree-Fock orbitals, and the active orbitals are projected from the given initial guess.
- Args:
casscf : an
CASSCF
orCASCI
object- init_mondarray or list of ndarray
Initial guess orbitals which are not orth-normal for the current molecule. When the casscf is UHF-CASSCF, the init_mo needs to be a list of two ndarrays, for alpha and beta orbitals
- Kwargs:
- prev_molan instance of
Mole
If given, the inital guess orbitals are associated to the geometry and basis of prev_mol. Otherwise, the orbitals are based of the geometry and basis of casscf.mol
- prev_molan instance of
- Returns:
New orthogonal initial guess orbitals with the core taken from Hartree-Fock orbitals and projected active space from original initial guess orbitals
Examples:
import numpy from pyscf import gto, scf, mcscf mol = gto.Mole() mol.build(atom='H 0 0 0; F 0 0 0.8', basis='ccpvdz', verbose=0) mf = scf.RHF(mol) mf.scf() mc = mcscf.CASSCF(mf, 6, 6) mo = mcscf.sort_mo(mc, mf.mo_coeff, [3,4,5,6,8,9]) print('E(0.8) = %.12f' % mc.kernel(mo)[0]) init_mo = mc.mo_coeff for b in numpy.arange(1.0, 3., .2): mol.atom = [['H', (0, 0, 0)], ['F', (0, 0, b)]] mol.build(0, 0) mf = scf.RHF(mol) mf.scf() mc = mcscf.CASSCF(mf, 6, 6) mo = mcscf.project_init_guess(mc, init_mo) print('E(%2.1f) = %.12f' % (b, mc.kernel(mo)[0])) init_mo = mc.mo_coeff
- pyscf.mcscf.addons.sort_mo(casscf, mo_coeff, caslst, base=1)[source]¶
Pick orbitals for CAS space
- Args:
casscf : an
CASSCF
orCASCI
object- mo_coeffndarray or a list of ndarray
Orbitals for CASSCF initial guess. In the UHF-CASSCF, it’s a list of two orbitals, for alpha and beta spin.
- caslstlist of int or nested list of int
A list of orbital indices to represent the CAS space. In the UHF-CASSCF, it’s consist of two lists, for alpha and beta spin.
- Kwargs:
- baseint
0-based (C-style) or 1-based (Fortran-style) caslst
- Returns:
An reoreded mo_coeff, which put the orbitals given by caslst in the CAS space
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 4, 4) >>> cas_list = [5,6,8,9] # pi orbitals >>> mo = mc.sort_mo(cas_list) >>> mc.kernel(mo)[0] -109.007378939813691
- pyscf.mcscf.addons.sort_mo_by_irrep(casscf, mo_coeff, cas_irrep_nocc, cas_irrep_ncore=None, s=None)[source]¶
Given number of active orbitals for each irrep, construct the mo initial guess for CASSCF
- Args:
casscf : an
CASSCF
orCASCI
object- cas_irrep_nocclist or dict
Number of active orbitals for each irrep. It can be a dict, eg {‘A1’: 2, ‘B2’: 4} to indicate the active space size based on irrep names, or {0: 2, 3: 4} for irrep Id, or a list [2, 0, 0, 4] (identical to {0: 2, 3: 4}) in which the list index is served as the irrep Id.
- Kwargs:
- cas_irrep_ncorelist or dict
Number of closed shells for each irrep. It can be a dict, eg {‘A1’: 6, ‘B2’: 4} to indicate the closed shells based on irrep names, or {0: 6, 3: 4} for irrep Id, or a list [6, 0, 0, 4] (identical to {0: 6, 3: 4}) in which the list index is served as the irrep Id. If cas_irrep_ncore is not given, the program will generate a guess based on the lowest
CASCI.ncore
orbitals.- sndarray
overlap matrix
- Returns:
sorted orbitals, ordered as [c,..,c,a,..,a,v,..,v]
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvtz', symmetry=True, verbose=0) >>> mf = scf.RHF(mol) >>> mf.kernel() >>> mc = mcscf.CASSCF(mf, 12, 4) >>> mo = mc.sort_mo_by_irrep({'E1gx':4, 'E1gy':4, 'E1ux':2, 'E1uy':2}) >>> # Same to mo = sort_mo_by_irrep(mc, mf.mo_coeff, {2: 4, 3: 4, 6: 2, 7: 2}) >>> # Same to mo = sort_mo_by_irrep(mc, mf.mo_coeff, [0, 0, 4, 4, 0, 0, 2, 2]) >>> mc.kernel(mo)[0] -108.162863845084
- pyscf.mcscf.addons.spin_square(casscf, mo_coeff=None, ci=None, ovlp=None)[source]¶
Spin square of the UHF-CASSCF wavefunction
- Returns:
A list of two floats. The first is the expectation value of S^2. The second is the corresponding 2S+1
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='O 0 0 0; O 0 0 1', basis='sto-3g', spin=2, verbose=0) >>> mf = scf.UHF(mol) >>> res = mf.scf() >>> mc = mcscf.CASSCF(mf, 4, 6) >>> res = mc.kernel() >>> print('S^2 = %.7f, 2S+1 = %.7f' % mcscf.spin_square(mc)) S^2 = 3.9831589, 2S+1 = 4.1149284
- pyscf.mcscf.addons.state_average(casscf, weights=(0.5, 0.5), wfnsym=None)[source]¶
State average over the energy. The energy funcitonal is E = w1<psi1|H|psi1> + w2<psi2|H|psi2> + …
Note we may need change the FCI solver to
mc.fcisolver = fci.solver(mol, False)
before calling state_average_(mc), to mix the singlet and triplet states
MRH, 04/08/2019: Instead of turning casscf._finalize into an instance attribute that points to the previous casscf object, I’m going to make a whole new child class. This will have the added benefit of making state_average and state_average_ actually behave differently for the first time (until now they both modified the casscf object inplace). I’m also going to assign the weights argument as a member of the mc child class because an accurate second-order CASSCF algorithm for state-averaged calculations requires that the gradient and Hessian be computed for CI vectors of each root individually and then multiplied by that root’s weight. The second derivatives computed by newton_casscf.py need to be extended to state-averaged calculations in order to be used as intermediates for calculations of the gradient of a single root in the context of the SA-CASSCF method; see: Mol. Phys. 99, 103 (2001).
- pyscf.mcscf.addons.state_average_(casscf, weights=(0.5, 0.5))[source]¶
Inplace version of state_average
- pyscf.mcscf.addons.state_average_mix(casscf, fcisolvers, weights=(0.5, 0.5))[source]¶
State-average CASSCF over multiple FCI solvers.
- pyscf.mcscf.addons.state_average_mix_(casscf, fcisolvers, weights=(0.5, 0.5))[source]¶
Inplace version of state_average
- pyscf.mcscf.addons.state_specific(casscf, state=1, wfnsym=None)¶
For excited state
- Kwargs:
state : int 0 for ground state; 1 for first excited state.
pyscf.mcscf.avas module¶
Automated construction of molecular active spaces from atomic valence orbitals. Ref. arXiv:1701.07862 [physics.chem-ph]
- pyscf.mcscf.avas.avas(mf, aolabels, threshold=0.2, minao='minao', with_iao=False, openshell_option=2, canonicalize=True, ncore=0, verbose=None)¶
AVAS method to construct mcscf active space. Ref. arXiv:1701.07862 [physics.chem-ph]
- Args:
mf : an
SCF
object- aolabelsstring or a list of strings
AO labels for AO active space
- Kwargs:
- thresholdfloat
Tructing threshold of the AO-projector above which AOs are kept in the active space.
- minaostr
A reference AOs for AVAS.
- with_iaobool
Whether to use IAO localization to construct the reference active AOs.
- openshell_optionint
How to handle singly-occupied orbitals in the active space. The singly-occupied orbitals are projected as part of alpha orbitals if openshell_option=2, or completely kept in active space if openshell_option=3. See Section III.E option 2 or 3 of the reference paper for more details.
- canonicalizebool
Orbitals defined in AVAS method are local orbitals. Symmetrizing the core, active and virtual space.
- ncoreinteger
Number of core orbitals to exclude from the AVAS method.
- Returns:
active-space-size, #-active-electrons, orbital-initial-guess-for-CASCI/CASSCF
Examples:
>>> from pyscf import gto, scf, mcscf >>> from pyscf.mcscf import avas >>> mol = gto.M(atom='Cr 0 0 0; Cr 0 0 1.6', basis='ccpvtz') >>> mf = scf.RHF(mol).run() >>> ncas, nelecas, mo = avas.avas(mf, ['Cr 3d', 'Cr 4s']) >>> mc = mcscf.CASSCF(mf, ncas, nelecas).run(mo)
- pyscf.mcscf.avas.kernel(mf, aolabels, threshold=0.2, minao='minao', with_iao=False, openshell_option=2, canonicalize=True, ncore=0, verbose=None)[source]¶
AVAS method to construct mcscf active space. Ref. arXiv:1701.07862 [physics.chem-ph]
- Args:
mf : an
SCF
object- aolabelsstring or a list of strings
AO labels for AO active space
- Kwargs:
- thresholdfloat
Tructing threshold of the AO-projector above which AOs are kept in the active space.
- minaostr
A reference AOs for AVAS.
- with_iaobool
Whether to use IAO localization to construct the reference active AOs.
- openshell_optionint
How to handle singly-occupied orbitals in the active space. The singly-occupied orbitals are projected as part of alpha orbitals if openshell_option=2, or completely kept in active space if openshell_option=3. See Section III.E option 2 or 3 of the reference paper for more details.
- canonicalizebool
Orbitals defined in AVAS method are local orbitals. Symmetrizing the core, active and virtual space.
- ncoreinteger
Number of core orbitals to exclude from the AVAS method.
- Returns:
active-space-size, #-active-electrons, orbital-initial-guess-for-CASCI/CASSCF
Examples:
>>> from pyscf import gto, scf, mcscf >>> from pyscf.mcscf import avas >>> mol = gto.M(atom='Cr 0 0 0; Cr 0 0 1.6', basis='ccpvtz') >>> mf = scf.RHF(mol).run() >>> ncas, nelecas, mo = avas.avas(mf, ['Cr 3d', 'Cr 4s']) >>> mc = mcscf.CASSCF(mf, ncas, nelecas).run(mo)
pyscf.mcscf.casci module¶
- class pyscf.mcscf.casci.CASCI(mf_or_mol, ncas, nelecas, ncore=None)[source]¶
Bases:
pyscf.lib.misc.StreamObject
- Args:
- mf_or_molSCF object or Mole object
SCF or Mole to define the problem size.
- ncasint
Number of active orbitals.
- nelecasint or a pair of int
Number of electrons in active space.
- Kwargs:
- ncoreint
Number of doubly occupied core orbitals. If not presented, this parameter can be automatically determined.
- Attributes:
- verboseint
Print level. Default value equals to
Mole.verbose
.- max_memoryfloat or int
Allowed memory in MB. Default value equals to
Mole.max_memory
.- ncasint
Active space size.
- nelecastuple of int
Active (nelec_alpha, nelec_beta)
- ncoreint or tuple of int
Core electron number. In UHF-CASSCF, it’s a tuple to indicate the different core eletron numbers.
- natorbbool
Whether to transform natural orbitals in active space. Note: when CASCI/CASSCF are combined with DMRG solver or selected CI solver, enabling this parameter may slightly change the total energy. False by default.
- canonicalizationbool
Whether to canonicalize orbitals in core and external space against the general Fock matrix. The orbitals in active space are NOT transformed by default. To get the natural orbitals in active space, the attribute .natorb needs to be enabled. True by default.
- sorting_mo_energybool
Whether to sort the orbitals based on the diagonal elements of the general Fock matrix. Default is False.
- fcisolveran instance of
FCISolver
The pyscf.fci module provides several FCISolver for different scenario. Generally, fci.direct_spin1.FCISolver can be used for all RHF-CASSCF. However, a proper FCISolver can provide better performance and better numerical stability. One can either use
fci.solver()
function to pick the FCISolver by the program or manually assigen the FCISolver to this attribute, e.g.>>> from pyscf import fci >>> mc = mcscf.CASSCF(mf, 4, 4) >>> mc.fcisolver = fci.solver(mol, singlet=True) >>> mc.fcisolver = fci.direct_spin1.FCISolver(mol)
You can control FCISolver by setting e.g.:
>>> mc.fcisolver.max_cycle = 30 >>> mc.fcisolver.conv_tol = 1e-7
For more details of the parameter for FCISolver, See
fci
.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- e_casfloat
CAS space FCI energy
- cindarray
CAS space FCI coefficients
- mo_coeffndarray
When canonicalization is specified, the orbitals are canonical orbitals which make the general Fock matrix (Fock operator on top of MCSCF 1-particle density matrix) diagonalized within each subspace (core, active, external). If natorb (natural orbitals in active space) is specified, the active segment of the mo_coeff is natural orbitls.
- mo_energyndarray
Diagonal elements of general Fock matrix (in mo_coeff representation).
- mo_occndarray
Occupation numbers of natural orbitals if natorb is specified.
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASCI(mf, 6, 6) >>> mc.kernel()[0] -108.980200816243354
- Gradients(*args, **kwargs)¶
Non-relativistic restricted Hartree-Fock gradients
- analyze(mo_coeff=None, ci=None, verbose=None, large_ci_tol=0.1, with_meta_lowdin=True, **kwargs)¶
- as_scanner()¶
Generating a scanner for CASCI PES.
The returned solver is a function. This function requires one argument “mol” as input and returns total CASCI energy.
The solver will automatically use the results of last calculation as the initial guess of the new calculation. All parameters of MCSCF object are automatically applied in the solver.
Note scanner has side effects. It may change many underlying objects (_scf, with_df, with_x2c, …) during calculation.
Examples:
>>> from pyscf import gto, scf, mcscf >>> mf = scf.RHF(gto.Mole().set(verbose=0)) >>> mc_scanner = mcscf.CASCI(mf, 4, 4).as_scanner() >>> mc_scanner(gto.M(atom='N 0 0 0; N 0 0 1.1')) >>> mc_scanner(gto.M(atom='N 0 0 0; N 0 0 1.5'))
- canonicalization = True¶
- canonicalize(mo_coeff=None, ci=None, eris=None, sort=False, cas_natorb=False, casdm1=None, verbose=3, with_meta_lowdin=True)¶
Canonicalized CASCI/CASSCF orbitals of effecitive Fock matrix and update CI coefficients accordingly.
Effective Fock matrix is built with one-particle density matrix (see also
mcscf.casci.get_fock()
). For state-average CASCI/CASSCF object, the canonicalized orbitals are based on the state-average density matrix. To obtain canonicalized orbitals for an individual state, you need to pass “casdm1” of the specific state to this function.- Args:
mc: a CASSCF/CASCI object or RHF object
- Kwargs:
- mo_coeff (ndarray): orbitals that span the core, active and external
space.
- ci (ndarray): CI coefficients (or objects to represent the CI
wavefunctions in DMRG/QMC-MCSCF calculations).
- eris: Integrals for the MCSCF object. Input this object to reduce the
overhead of computing integrals. It can be generated by
mc.ao2mo()
method.- sort (bool): Whether the canonicalized orbitals are sorted based on
the orbital energy (diagonal part of the effective Fock matrix) within each subspace (core, active, external). If point group symmetry is not available in the system, orbitals are always sorted. When point group symmetry is available, sort=False will preserve the symmetry label of input orbitals and only sort the orbitals in each symmetry sector. sort=True will reorder all orbitals over all symmetry sectors in each subspace and the symmetry labels may be changed.
- cas_natorb (bool): Whether to transform active orbitals to natual
orbitals. If enabled, the output orbitals in active space are transformed to natural orbitals and CI coefficients are updated accordingly.
- casdm1 (ndarray): 1-particle density matrix in active space. This
density matrix is used to build effective fock matrix. Without input casdm1, the density matrix is computed with the input ci coefficients/object. If neither ci nor casdm1 were given, density matrix is computed by
mc.fcisolver.make_rdm1()
method. For state-average CASCI/CASCF calculation, this results in a set of canonicalized orbitals of state-average effective Fock matrix. To canonicalize the orbitals for one particular state, you can assign the density matrix of that state to the kwarg casdm1.
- Returns:
A tuple, (natural orbitals, CI coefficients, orbital energies) The orbital energies are the diagonal terms of effective Fock matrix.
- canonicalize_(mo_coeff=None, ci=None, eris=None, sort=False, cas_natorb=False, casdm1=None, verbose=None, with_meta_lowdin=True)[source]¶
Canonicalized CASCI/CASSCF orbitals of effecitive Fock matrix and update CI coefficients accordingly.
Effective Fock matrix is built with one-particle density matrix (see also
mcscf.casci.get_fock()
). For state-average CASCI/CASSCF object, the canonicalized orbitals are based on the state-average density matrix. To obtain canonicalized orbitals for an individual state, you need to pass “casdm1” of the specific state to this function.- Args:
mc: a CASSCF/CASCI object or RHF object
- Kwargs:
- mo_coeff (ndarray): orbitals that span the core, active and external
space.
- ci (ndarray): CI coefficients (or objects to represent the CI
wavefunctions in DMRG/QMC-MCSCF calculations).
- eris: Integrals for the MCSCF object. Input this object to reduce the
overhead of computing integrals. It can be generated by
mc.ao2mo()
method.- sort (bool): Whether the canonicalized orbitals are sorted based on
the orbital energy (diagonal part of the effective Fock matrix) within each subspace (core, active, external). If point group symmetry is not available in the system, orbitals are always sorted. When point group symmetry is available, sort=False will preserve the symmetry label of input orbitals and only sort the orbitals in each symmetry sector. sort=True will reorder all orbitals over all symmetry sectors in each subspace and the symmetry labels may be changed.
- cas_natorb (bool): Whether to transform active orbitals to natual
orbitals. If enabled, the output orbitals in active space are transformed to natural orbitals and CI coefficients are updated accordingly.
- casdm1 (ndarray): 1-particle density matrix in active space. This
density matrix is used to build effective fock matrix. Without input casdm1, the density matrix is computed with the input ci coefficients/object. If neither ci nor casdm1 were given, density matrix is computed by
mc.fcisolver.make_rdm1()
method. For state-average CASCI/CASCF calculation, this results in a set of canonicalized orbitals of state-average effective Fock matrix. To canonicalize the orbitals for one particular state, you can assign the density matrix of that state to the kwarg casdm1.
- Returns:
A tuple, (natural orbitals, CI coefficients, orbital energies) The orbital energies are the diagonal terms of effective Fock matrix.
- cas_natorb(mo_coeff=None, ci=None, eris=None, sort=False, casdm1=None, verbose=None, with_meta_lowdin=True)[source]¶
Transform active orbitals to natrual orbitals, and update the CI wfn accordingly
- Args:
mc : a CASSCF/CASCI object or RHF object
- Kwargs:
- sortbool
Sort natural orbitals wrt the occupancy.
- Returns:
A tuple, the first item is natural orbitals, the second is updated CI coefficients, the third is the natural occupancy associated to the natural orbitals.
- cas_natorb_(mo_coeff=None, ci=None, eris=None, sort=False, casdm1=None, verbose=None, with_meta_lowdin=True)[source]¶
Transform active orbitals to natrual orbitals, and update the CI wfn accordingly
- Args:
mc : a CASSCF/CASCI object or RHF object
- Kwargs:
- sortbool
Sort natural orbitals wrt the occupancy.
- Returns:
A tuple, the first item is natural orbitals, the second is updated CI coefficients, the third is the natural occupancy associated to the natural orbitals.
- fix_spin(shift=0.2, ss=None)¶
Use level shift to control FCI solver spin.
\[(H + shift*S^2) |\Psi\rangle = E |\Psi\rangle\]- Kwargs:
- shiftfloat
Energy penalty for states which have wrong spin
- ssnumber
S^2 expection value == s*(s+1)
- fix_spin_(shift=0.2, ss=None)[source]¶
Use level shift to control FCI solver spin.
\[(H + shift*S^2) |\Psi\rangle = E |\Psi\rangle\]- Kwargs:
- shiftfloat
Energy penalty for states which have wrong spin
- ssnumber
S^2 expection value == s*(s+1)
- get_h1cas(mo_coeff=None, ncas=None, ncore=None)¶
CAS sapce one-electron hamiltonian
- Args:
casci : a CASSCF/CASCI object or RHF object
- Returns:
A tuple, the first is the effective one-electron hamiltonian defined in CAS space, the second is the electronic energy from core.
- get_h1eff(mo_coeff=None, ncas=None, ncore=None)[source]¶
CAS sapce one-electron hamiltonian
- Args:
casci : a CASSCF/CASCI object or RHF object
- Returns:
A tuple, the first is the effective one-electron hamiltonian defined in CAS space, the second is the electronic energy from core.
- get_h2cas(mo_coeff=None)[source]¶
Compute the active space two-particle Hamiltonian.
Note It is different to get_h2eff when df.approx_hessian is applied, in which get_h2eff function returns the DF integrals while get_h2cas returns the regular 2-electron integrals.
- get_h2eff(mo_coeff=None)[source]¶
Compute the active space two-particle Hamiltonian.
Note It is different to get_h2cas when df.approx_hessian is applied. in which get_h2eff function returns the DF integrals while get_h2cas returns the regular 2-electron integrals.
- get_jk(mol, dm, hermi=1, with_j=True, with_k=True, omega=None)[source]¶
Compute J, K matrices for all input density matrices
- Args:
mol : an instance of
Mole
- dmndarray or list of ndarrays
A density matrix or a list of density matrices
- Kwargs:
- hermiint
Whether J, K matrix is hermitian
0 : not hermitian and not symmetric1 : hermitian or symmetric2 : anti-hermitian- vhfopt :
A class which holds precomputed quantities to optimize the computation of J, K matrices
- with_jboolean
Whether to compute J matrices
- with_kboolean
Whether to compute K matrices
- omegafloat
Parameter of range-seperated Coulomb operator: erf( omega * r12 ) / r12. If specified, integration are evaluated based on the long-range part of the range-seperated Coulomb operator.
- Returns:
Depending on the given dm, the function returns one J and one K matrix, or a list of J matrices and a list of K matrices, corresponding to the input density matrices.
Examples:
>>> from pyscf import gto, scf >>> from pyscf.scf import _vhf >>> mol = gto.M(atom='H 0 0 0; H 0 0 1.1') >>> dms = numpy.random.random((3,mol.nao_nr(),mol.nao_nr())) >>> j, k = scf.hf.get_jk(mol, dms, hermi=0) >>> print(j.shape) (3, 2, 2)
- get_veff(mol=None, dm=None, hermi=1)[source]¶
Hartree-Fock potential matrix for the given density matrix
- Args:
mol : an instance of
Mole
- dmndarray or list of ndarrays
A density matrix or a list of density matrices
- Kwargs:
- dm_lastndarray or a list of ndarrays or 0
The density matrix baseline. If not 0, this function computes the increment of HF potential w.r.t. the reference HF potential matrix.
- vhf_lastndarray or a list of ndarrays or 0
The reference HF potential matrix.
- hermiint
Whether J, K matrix is hermitian
0 : no hermitian or symmetric1 : hermitian2 : anti-hermitian- vhfopt :
A class which holds precomputed quantities to optimize the computation of J, K matrices
- Returns:
matrix Vhf = 2*J - K. Vhf can be a list matrices, corresponding to the input density matrices.
Examples:
>>> import numpy >>> from pyscf import gto, scf >>> from pyscf.scf import _vhf >>> mol = gto.M(atom='H 0 0 0; H 0 0 1.1') >>> dm0 = numpy.random.random((mol.nao_nr(),mol.nao_nr())) >>> vhf0 = scf.hf.get_veff(mol, dm0, hermi=0) >>> dm1 = numpy.random.random((mol.nao_nr(),mol.nao_nr())) >>> vhf1 = scf.hf.get_veff(mol, dm1, hermi=0) >>> vhf2 = scf.hf.get_veff(mol, dm1, dm_last=dm0, vhf_last=vhf0, hermi=0) >>> numpy.allclose(vhf1, vhf2) True
- h1e_for_cas(mo_coeff=None, ncas=None, ncore=None)¶
CAS sapce one-electron hamiltonian
- Args:
casci : a CASSCF/CASCI object or RHF object
- Returns:
A tuple, the first is the effective one-electron hamiltonian defined in CAS space, the second is the electronic energy from core.
- kernel(mo_coeff=None, ci0=None, verbose=None)[source]¶
- Returns:
Five elements, they are total energy, active space CI energy, the active space FCI wavefunction coefficients or DMRG wavefunction ID, the MCSCF canonical orbital coefficients, the MCSCF canonical orbital coefficients.
They are attributes of mcscf object, which can be accessed by .e_tot, .e_cas, .ci, .mo_coeff, .mo_energy
- make_rdm1(mo_coeff=None, ci=None, ncas=None, nelecas=None, ncore=None, **kwargs)[source]¶
One-particle density matrix in AO representation
- make_rdm1s(mo_coeff=None, ci=None, ncas=None, nelecas=None, ncore=None, **kwargs)[source]¶
One-particle density matrices for alpha and beta spin on AO basis
- natorb = False¶
- property ncore¶
- sort_mo(caslst, mo_coeff=None, base=1)[source]¶
Pick orbitals for CAS space
- Args:
casscf : an
CASSCF
orCASCI
object- mo_coeffndarray or a list of ndarray
Orbitals for CASSCF initial guess. In the UHF-CASSCF, it’s a list of two orbitals, for alpha and beta spin.
- caslstlist of int or nested list of int
A list of orbital indices to represent the CAS space. In the UHF-CASSCF, it’s consist of two lists, for alpha and beta spin.
- Kwargs:
- baseint
0-based (C-style) or 1-based (Fortran-style) caslst
- Returns:
An reoreded mo_coeff, which put the orbitals given by caslst in the CAS space
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 4, 4) >>> cas_list = [5,6,8,9] # pi orbitals >>> mo = mc.sort_mo(cas_list) >>> mc.kernel(mo)[0] -109.007378939813691
- sorting_mo_energy = False¶
- state_average(weights=(0.5, 0.5))[source]¶
State average over the energy. The energy funcitonal is E = w1<psi1|H|psi1> + w2<psi2|H|psi2> + …
Note we may need change the FCI solver to
mc.fcisolver = fci.solver(mol, False)
before calling state_average_(mc), to mix the singlet and triplet states
MRH, 04/08/2019: Instead of turning casscf._finalize into an instance attribute that points to the previous casscf object, I’m going to make a whole new child class. This will have the added benefit of making state_average and state_average_ actually behave differently for the first time (until now they both modified the casscf object inplace). I’m also going to assign the weights argument as a member of the mc child class because an accurate second-order CASSCF algorithm for state-averaged calculations requires that the gradient and Hessian be computed for CI vectors of each root individually and then multiplied by that root’s weight. The second derivatives computed by newton_casscf.py need to be extended to state-averaged calculations in order to be used as intermediates for calculations of the gradient of a single root in the context of the SA-CASSCF method; see: Mol. Phys. 99, 103 (2001).
- state_average_(weights=(0.5, 0.5))[source]¶
State average over the energy. The energy funcitonal is E = w1<psi1|H|psi1> + w2<psi2|H|psi2> + …
Note we may need change the FCI solver to
mc.fcisolver = fci.solver(mol, False)
before calling state_average_(mc), to mix the singlet and triplet states
MRH, 04/08/2019: Instead of turning casscf._finalize into an instance attribute that points to the previous casscf object, I’m going to make a whole new child class. This will have the added benefit of making state_average and state_average_ actually behave differently for the first time (until now they both modified the casscf object inplace). I’m also going to assign the weights argument as a member of the mc child class because an accurate second-order CASSCF algorithm for state-averaged calculations requires that the gradient and Hessian be computed for CI vectors of each root individually and then multiplied by that root’s weight. The second derivatives computed by newton_casscf.py need to be extended to state-averaged calculations in order to be used as intermediates for calculations of the gradient of a single root in the context of the SA-CASSCF method; see: Mol. Phys. 99, 103 (2001).
- state_specific_(state=1)[source]¶
For excited state
- Kwargs:
state : int 0 for ground state; 1 for first excited state.
- x2c()¶
- x2c1e()¶
- pyscf.mcscf.casci.analyze(casscf, mo_coeff=None, ci=None, verbose=None, large_ci_tol=0.1, with_meta_lowdin=True, **kwargs)[source]¶
- pyscf.mcscf.casci.as_scanner(mc)[source]¶
Generating a scanner for CASCI PES.
The returned solver is a function. This function requires one argument “mol” as input and returns total CASCI energy.
The solver will automatically use the results of last calculation as the initial guess of the new calculation. All parameters of MCSCF object are automatically applied in the solver.
Note scanner has side effects. It may change many underlying objects (_scf, with_df, with_x2c, …) during calculation.
Examples:
>>> from pyscf import gto, scf, mcscf >>> mf = scf.RHF(gto.Mole().set(verbose=0)) >>> mc_scanner = mcscf.CASCI(mf, 4, 4).as_scanner() >>> mc_scanner(gto.M(atom='N 0 0 0; N 0 0 1.1')) >>> mc_scanner(gto.M(atom='N 0 0 0; N 0 0 1.5'))
- pyscf.mcscf.casci.canonicalize(mc, mo_coeff=None, ci=None, eris=None, sort=False, cas_natorb=False, casdm1=None, verbose=3, with_meta_lowdin=True)[source]¶
Canonicalized CASCI/CASSCF orbitals of effecitive Fock matrix and update CI coefficients accordingly.
Effective Fock matrix is built with one-particle density matrix (see also
mcscf.casci.get_fock()
). For state-average CASCI/CASSCF object, the canonicalized orbitals are based on the state-average density matrix. To obtain canonicalized orbitals for an individual state, you need to pass “casdm1” of the specific state to this function.- Args:
mc: a CASSCF/CASCI object or RHF object
- Kwargs:
- mo_coeff (ndarray): orbitals that span the core, active and external
space.
- ci (ndarray): CI coefficients (or objects to represent the CI
wavefunctions in DMRG/QMC-MCSCF calculations).
- eris: Integrals for the MCSCF object. Input this object to reduce the
overhead of computing integrals. It can be generated by
mc.ao2mo()
method.- sort (bool): Whether the canonicalized orbitals are sorted based on
the orbital energy (diagonal part of the effective Fock matrix) within each subspace (core, active, external). If point group symmetry is not available in the system, orbitals are always sorted. When point group symmetry is available, sort=False will preserve the symmetry label of input orbitals and only sort the orbitals in each symmetry sector. sort=True will reorder all orbitals over all symmetry sectors in each subspace and the symmetry labels may be changed.
- cas_natorb (bool): Whether to transform active orbitals to natual
orbitals. If enabled, the output orbitals in active space are transformed to natural orbitals and CI coefficients are updated accordingly.
- casdm1 (ndarray): 1-particle density matrix in active space. This
density matrix is used to build effective fock matrix. Without input casdm1, the density matrix is computed with the input ci coefficients/object. If neither ci nor casdm1 were given, density matrix is computed by
mc.fcisolver.make_rdm1()
method. For state-average CASCI/CASCF calculation, this results in a set of canonicalized orbitals of state-average effective Fock matrix. To canonicalize the orbitals for one particular state, you can assign the density matrix of that state to the kwarg casdm1.
- Returns:
A tuple, (natural orbitals, CI coefficients, orbital energies) The orbital energies are the diagonal terms of effective Fock matrix.
- pyscf.mcscf.casci.cas_natorb(mc, mo_coeff=None, ci=None, eris=None, sort=False, casdm1=None, verbose=None, with_meta_lowdin=True)[source]¶
Transform active orbitals to natrual orbitals, and update the CI wfn accordingly
- Args:
mc : a CASSCF/CASCI object or RHF object
- Kwargs:
- sortbool
Sort natural orbitals wrt the occupancy.
- Returns:
A tuple, the first item is natural orbitals, the second is updated CI coefficients, the third is the natural occupancy associated to the natural orbitals.
- pyscf.mcscf.casci.get_fock(mc, mo_coeff=None, ci=None, eris=None, casdm1=None, verbose=None)[source]¶
Effective one-electron Fock matrix in AO representation f = sum_{pq} E_{pq} F_{pq} F_{pq} = h_{pq} + sum_{rs} [(pq|rs)-(ps|rq)] DM_{sr}
Ref. Theor. Chim. Acta., 91, 31 Chem. Phys. 48, 157
For state-average CASCI/CASSCF object, the effective fock matrix is based on the state-average density matrix. To obtain Fock matrix of a specific state in the state-average calculations, you can pass “casdm1” of the specific state to this function.
- Args:
mc: a CASSCF/CASCI object or RHF object
- Kwargs:
- mo_coeff (ndarray): orbitals that span the core, active and external
space.
- ci (ndarray): CI coefficients (or objects to represent the CI
wavefunctions in DMRG/QMC-MCSCF calculations).
- eris: Integrals for the MCSCF object. Input this object to reduce the
overhead of computing integrals. It can be generated by
mc.ao2mo()
method.- casdm1 (ndarray): 1-particle density matrix in active space. Without
input casdm1, the density matrix is computed with the input ci coefficients/object. If neither ci nor casdm1 were given, density matrix is computed by
mc.fcisolver.make_rdm1()
method. For state-average CASCI/CASCF calculation, this results in the effective Fock matrix based on the state-average density matrix. To obtain the effective Fock matrix for one particular state, you can assign the density matrix of that state to the kwarg casdm1.
- Returns:
Fock matrix
- pyscf.mcscf.casci.h1e_for_cas(casci, mo_coeff=None, ncas=None, ncore=None)[source]¶
CAS sapce one-electron hamiltonian
- Args:
casci : a CASSCF/CASCI object or RHF object
- Returns:
A tuple, the first is the effective one-electron hamiltonian defined in CAS space, the second is the electronic energy from core.
pyscf.mcscf.casci_symm module¶
- pyscf.mcscf.casci_symm.CASCI¶
- class pyscf.mcscf.casci_symm.SymAdaptedCASCI(mf_or_mol, ncas, nelecas, ncore=None)[source]¶
Bases:
pyscf.mcscf.casci.CASCI
- kernel(mo_coeff=None, ci0=None, verbose=None)[source]¶
- Returns:
Five elements, they are total energy, active space CI energy, the active space FCI wavefunction coefficients or DMRG wavefunction ID, the MCSCF canonical orbital coefficients, the MCSCF canonical orbital coefficients.
They are attributes of mcscf object, which can be accessed by .e_tot, .e_cas, .ci, .mo_coeff, .mo_energy
- sort_mo_by_irrep(cas_irrep_nocc, cas_irrep_ncore=None, mo_coeff=None, s=None)[source]¶
Select active space based on symmetry information. See also
pyscf.mcscf.addons.sort_mo_by_irrep()
- property wfnsym¶
pyscf.mcscf.chkfile module¶
pyscf.mcscf.df module¶
- pyscf.mcscf.df.approx_hessian(casscf, auxbasis=None, with_df=None)[source]¶
Approximate the orbital hessian with density fitting integrals
Note this function has no effects if the input casscf object is DF-CASSCF. It only modifies the orbital hessian of normal CASSCF object.
- Args:
casscf : an CASSCF object
- Kwargs:
- auxbasisstr or basis dict
Same format to the input attribute mol.basis. The default basis ‘weigend+etb’ means weigend-coulomb-fit basis for light elements and even-tempered basis for heavy elements.
- Returns:
A CASSCF object with approximated JK contraction for orbital hessian
Examples:
>>> mol = gto.M(atom='H 0 0 0; F 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.approx_hessian(mcscf.CASSCF(mf, 4, 4)) -100.06458716530391
- pyscf.mcscf.df.density_fit(casscf, auxbasis=None, with_df=None)[source]¶
Generate DF-CASSCF for given CASSCF object. It is done by overwriting three CASSCF member functions:
casscf.ao2mo which generates MO integrals
casscf.get_veff which generate JK from core density matrix
casscf.get_jk which
- Args:
casscf : an CASSCF object
- Kwargs:
- auxbasisstr or basis dict
Same format to the input attribute mol.basis. If auxbasis is None, auxiliary basis based on AO basis (if possible) or even-tempered Gaussian basis will be used.
- Returns:
An CASSCF object with a modified J, K matrix constructor which uses density fitting integrals to compute J and K
Examples:
>>> mol = gto.M(atom='H 0 0 0; F 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = DFCASSCF(mf, 4, 4) -100.05994191570504
pyscf.mcscf.dmet_cas module¶
- pyscf.mcscf.dmet_cas.dmet_cas(mf, dm, aolabels_or_baslst, threshold=0.05, occ_cutoff=1e-06, base=0, orth_method='meta_lowdin', s=None, canonicalize=True, freeze_imp=False, verbose=None)¶
DMET method to generate CASSCF initial guess. Ref. arXiv:1701.07862 [physics.chem-ph]
- Args:
mf : an
SCF
object- dm2D np.array or a list of 2D array
Density matrix
- aolabels_or_baslststring or a list of strings or a list of index
AO labels or indices
- Kwargs:
- thresholdfloat
Entanglement threshold of DMET bath. If the occupancy of an orbital is less than threshold, the orbital is considered as bath orbtial. If occ is greater than (1-threshold), the orbitals are taken for core determinant.
- baseint
0-based (C-style) or 1-based (Fortran-style) for baslst if baslst is index list
- orth_methodstr
It can be one of ‘lowdin’ and ‘meta_lowdin’
- s2D array
AO overlap matrix. This option is mainly used for custom Hamilatonian.
- canonicalizebool
Orbitals defined in AVAS method are local orbitals. Symmetrizing the core, active and virtual space.
- Returns:
active-space-size, #-active-electrons, orbital-initial-guess-for-CASCI/CASSCF
Examples:
>>> from pyscf import gto, scf, mcscf >>> from pyscf.mcscf import dmet_cas >>> mol = gto.M(atom='Cr 0 0 0; Cr 0 0 1.6', basis='ccpvtz') >>> mf = scf.RHF(mol).run() >>> ncas, nelecas, mo = dmet_cas.dmet_cas(mf, ['Cr 3d', 'Cr 4s']) >>> mc = mcscf.CASSCF(mf, ncas, nelecas).run(mo)
- pyscf.mcscf.dmet_cas.guess_cas(mf, dm, aolabels_or_baslst, threshold=0.05, occ_cutoff=1e-06, base=0, orth_method='meta_lowdin', s=None, canonicalize=True, freeze_imp=False, verbose=None)¶
DMET method to generate CASSCF initial guess. Ref. arXiv:1701.07862 [physics.chem-ph]
- Args:
mf : an
SCF
object- dm2D np.array or a list of 2D array
Density matrix
- aolabels_or_baslststring or a list of strings or a list of index
AO labels or indices
- Kwargs:
- thresholdfloat
Entanglement threshold of DMET bath. If the occupancy of an orbital is less than threshold, the orbital is considered as bath orbtial. If occ is greater than (1-threshold), the orbitals are taken for core determinant.
- baseint
0-based (C-style) or 1-based (Fortran-style) for baslst if baslst is index list
- orth_methodstr
It can be one of ‘lowdin’ and ‘meta_lowdin’
- s2D array
AO overlap matrix. This option is mainly used for custom Hamilatonian.
- canonicalizebool
Orbitals defined in AVAS method are local orbitals. Symmetrizing the core, active and virtual space.
- Returns:
active-space-size, #-active-electrons, orbital-initial-guess-for-CASCI/CASSCF
Examples:
>>> from pyscf import gto, scf, mcscf >>> from pyscf.mcscf import dmet_cas >>> mol = gto.M(atom='Cr 0 0 0; Cr 0 0 1.6', basis='ccpvtz') >>> mf = scf.RHF(mol).run() >>> ncas, nelecas, mo = dmet_cas.dmet_cas(mf, ['Cr 3d', 'Cr 4s']) >>> mc = mcscf.CASSCF(mf, ncas, nelecas).run(mo)
- pyscf.mcscf.dmet_cas.kernel(mf, dm, aolabels_or_baslst, threshold=0.05, occ_cutoff=1e-06, base=0, orth_method='meta_lowdin', s=None, canonicalize=True, freeze_imp=False, verbose=None)[source]¶
DMET method to generate CASSCF initial guess. Ref. arXiv:1701.07862 [physics.chem-ph]
- Args:
mf : an
SCF
object- dm2D np.array or a list of 2D array
Density matrix
- aolabels_or_baslststring or a list of strings or a list of index
AO labels or indices
- Kwargs:
- thresholdfloat
Entanglement threshold of DMET bath. If the occupancy of an orbital is less than threshold, the orbital is considered as bath orbtial. If occ is greater than (1-threshold), the orbitals are taken for core determinant.
- baseint
0-based (C-style) or 1-based (Fortran-style) for baslst if baslst is index list
- orth_methodstr
It can be one of ‘lowdin’ and ‘meta_lowdin’
- s2D array
AO overlap matrix. This option is mainly used for custom Hamilatonian.
- canonicalizebool
Orbitals defined in AVAS method are local orbitals. Symmetrizing the core, active and virtual space.
- Returns:
active-space-size, #-active-electrons, orbital-initial-guess-for-CASCI/CASSCF
Examples:
>>> from pyscf import gto, scf, mcscf >>> from pyscf.mcscf import dmet_cas >>> mol = gto.M(atom='Cr 0 0 0; Cr 0 0 1.6', basis='ccpvtz') >>> mf = scf.RHF(mol).run() >>> ncas, nelecas, mo = dmet_cas.dmet_cas(mf, ['Cr 3d', 'Cr 4s']) >>> mc = mcscf.CASSCF(mf, ncas, nelecas).run(mo)
pyscf.mcscf.mc1step module¶
- class pyscf.mcscf.mc1step.CASSCF(mf_or_mol, ncas, nelecas, ncore=None, frozen=None)[source]¶
Bases:
pyscf.mcscf.casci.CASCI
- Args:
- mf_or_molSCF object or Mole object
SCF or Mole to define the problem size.
- ncasint
Number of active orbitals.
- nelecasint or a pair of int
Number of electrons in active space.
- Kwargs:
- ncoreint
Number of doubly occupied core orbitals. If not presented, this parameter can be automatically determined.
- Attributes:
- verboseint
Print level. Default value equals to
Mole.verbose
.- max_memoryfloat or int
Allowed memory in MB. Default value equals to
Mole.max_memory
.- ncasint
Active space size.
- nelecastuple of int
Active (nelec_alpha, nelec_beta)
- ncoreint or tuple of int
Core electron number. In UHF-CASSCF, it’s a tuple to indicate the different core eletron numbers.
- natorbbool
Whether to transform natural orbitals in active space. Note: when CASCI/CASSCF are combined with DMRG solver or selected CI solver, enabling this parameter may slightly change the total energy. False by default.
- canonicalizationbool
Whether to canonicalize orbitals in core and external space against the general Fock matrix. The orbitals in active space are NOT transformed by default. To get the natural orbitals in active space, the attribute .natorb needs to be enabled. True by default.
- sorting_mo_energybool
Whether to sort the orbitals based on the diagonal elements of the general Fock matrix. Default is False.
- fcisolveran instance of
FCISolver
The pyscf.fci module provides several FCISolver for different scenario. Generally, fci.direct_spin1.FCISolver can be used for all RHF-CASSCF. However, a proper FCISolver can provide better performance and better numerical stability. One can either use
fci.solver()
function to pick the FCISolver by the program or manually assigen the FCISolver to this attribute, e.g.>>> from pyscf import fci >>> mc = mcscf.CASSCF(mf, 4, 4) >>> mc.fcisolver = fci.solver(mol, singlet=True) >>> mc.fcisolver = fci.direct_spin1.FCISolver(mol)
You can control FCISolver by setting e.g.:
>>> mc.fcisolver.max_cycle = 30 >>> mc.fcisolver.conv_tol = 1e-7
For more details of the parameter for FCISolver, See
fci
.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- e_casfloat
CAS space FCI energy
- cindarray
CAS space FCI coefficients
- mo_coeffndarray
When canonicalization is specified, the orbitals are canonical orbitals which make the general Fock matrix (Fock operator on top of MCSCF 1-particle density matrix) diagonalized within each subspace (core, active, external). If natorb (natural orbitals in active space) is specified, the active segment of the mo_coeff is natural orbitls.
- mo_energyndarray
Diagonal elements of general Fock matrix (in mo_coeff representation).
- mo_occndarray
Occupation numbers of natural orbitals if natorb is specified.
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASCI(mf, 6, 6) >>> mc.kernel()[0] -108.980200816243354 CASSCF
Extra attributes for CASSCF:
- conv_tolfloat
Converge threshold. Default is 1e-7
- conv_tol_gradfloat
Converge threshold for CI gradients and orbital rotation gradients. Default is 1e-4
- max_stepsizefloat
The step size for orbital rotation. Small step (0.005 - 0.05) is prefered. Default is 0.03.
- max_cycle_macroint
Max number of macro iterations. Default is 50.
- max_cycle_microint
Max number of micro iterations in each macro iteration. Depending on systems, increasing this value might reduce the total macro iterations. Generally, 2 - 5 steps should be enough. Default is 3.
- ah_level_shiftfloat, for AH solver.
Level shift for the Davidson diagonalization in AH solver. Default is 1e-8.
- ah_conv_tolfloat, for AH solver.
converge threshold for AH solver. Default is 1e-12.
- ah_max_cyclefloat, for AH solver.
Max number of iterations allowd in AH solver. Default is 30.
- ah_lindepfloat, for AH solver.
Linear dependence threshold for AH solver. Default is 1e-14.
- ah_start_tolflat, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 0.2.
- ah_start_cycleint, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 2.
ah_conv_tol
,ah_max_cycle
,ah_lindep
,ah_start_tol
andah_start_cycle
can affect the accuracy and performance of CASSCF solver. Lowerah_conv_tol
andah_lindep
might improve the accuracy of CASSCF optimization, but decrease the performance.>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.UHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.conv_tol = 1e-10 >>> mc.ah_conv_tol = 1e-5 >>> mc.kernel()[0] -109.044401898486001 >>> mc.ah_conv_tol = 1e-10 >>> mc.kernel()[0] -109.044401887945668
- chkfilestr
Checkpoint file to save the intermediate orbitals during the CASSCF optimization. Default is the checkpoint file of mean field object.
- ci_response_spaceint
subspace size to solve the CI vector response. Default is 3.
- callbackfunction(envs_dict) => None
callback function takes one dict as the argument which is generated by the builtin function
locals()
, so that the callback function can access all local variables in the current envrionment.- scale_restorationfloat
When a step of orbital rotation moves out of trust region, the orbital optimization will be restored to previous state and the step size of the orbital rotation needs to be reduced. scale_restoration controls how much to scale down the step size.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- e_casfloat
CAS space FCI energy
- cindarray
CAS space FCI coefficients
- mo_coeffndarray
Optimized CASSCF orbitals coefficients. When canonicalization is specified, the returned orbitals make the general Fock matrix (Fock operator on top of MCSCF 1-particle density matrix) diagonalized within each subspace (core, active, external). If natorb (natural orbitals in active space) is enabled, the active segment of mo_coeff is transformed to natural orbitals.
- mo_energyndarray
Diagonal elements of general Fock matrix (in mo_coeff representation).
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.kernel()[0] -109.044401882238134
- Gradients(*args, **kwargs)¶
Non-relativistic restricted Hartree-Fock gradients
- ah_conv_tol = 1e-12¶
- ah_grad_trust_region = 3.0¶
- ah_level_shift = 1e-08¶
- ah_lindep = 1e-14¶
- ah_max_cycle = 30¶
- ah_start_cycle = 3¶
- ah_start_tol = 2.5¶
- ao2mo_level = 2¶
- as_scanner()¶
Generating a scanner for CASSCF PES.
The returned solver is a function. This function requires one argument “mol” as input and returns total CASSCF energy.
The solver will automatically use the results of last calculation as the initial guess of the new calculation. All parameters of MCSCF object (conv_tol, max_memory etc) are automatically applied in the solver.
Note scanner has side effects. It may change many underlying objects (_scf, with_df, with_x2c, …) during calculation.
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1.2', verbose=0) >>> mc_scanner = mcscf.CASSCF(scf.RHF(mol), 4, 4).as_scanner() >>> e = mc_scanner(gto.M(atom='N 0 0 0; N 0 0 1.1')) >>> e = mc_scanner(gto.M(atom='N 0 0 0; N 0 0 1.5'))
- canonicalization = True¶
- chk_ci = False¶
- ci_grad_trust_region = 3.0¶
- ci_response_space = 4¶
- property ci_update_dep¶
- conv_tol = 1e-07¶
- conv_tol_grad = None¶
- gen_g_hop(mo, u, casdm1, casdm2, eris)¶
- get_h2cas(mo_coeff=None)[source]¶
Computing active space two-particle Hamiltonian.
Note It is different to get_h2eff when df.approx_hessian is applied, in which get_h2eff function returns the DF integrals while get_h2cas returns the regular 2-electron integrals.
- get_h2eff(mo_coeff=None)[source]¶
Computing active space two-particle Hamiltonian.
Note It is different to get_h2cas when df.approx_hessian is applied, in which get_h2eff function returns the DF integrals while get_h2cas returns the regular 2-electron integrals.
- property grad_update_dep¶
- internal_rotation = False¶
- kernel(mo_coeff=None, ci0=None, callback=None, _kern=<function kernel>)[source]¶
- Returns:
Five elements, they are total energy, active space CI energy, the active space FCI wavefunction coefficients or DMRG wavefunction ID, the MCSCF canonical orbital coefficients, the MCSCF canonical orbital coefficients.
They are attributes of mcscf object, which can be accessed by .e_tot, .e_cas, .ci, .mo_coeff, .mo_energy
- kf_interval = 4¶
- kf_trust_region = 3.0¶
- property max_cycle¶
- max_cycle_macro = 50¶
- max_cycle_micro = 4¶
- property max_orb_stepsize¶
- max_stepsize = 0.02¶
- natorb = False¶
- rotate_orb_cc(mo, fcivec, fcasdm1, fcasdm2, eris, x0_guess=None, conv_tol_grad=0.0001, max_stepsize=None, verbose=None)¶
- scale_restoration = 0.5¶
- solve_approx_ci(h1, h2, ci0, ecore, e_cas, envs)[source]¶
Solve CI eigenvalue/response problem approximately
- sorting_mo_energy = False¶
- update(chkfile=None)¶
- with_dep4 = False¶
- pyscf.mcscf.mc1step.as_scanner(mc)[source]¶
Generating a scanner for CASSCF PES.
The returned solver is a function. This function requires one argument “mol” as input and returns total CASSCF energy.
The solver will automatically use the results of last calculation as the initial guess of the new calculation. All parameters of MCSCF object (conv_tol, max_memory etc) are automatically applied in the solver.
Note scanner has side effects. It may change many underlying objects (_scf, with_df, with_x2c, …) during calculation.
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1.2', verbose=0) >>> mc_scanner = mcscf.CASSCF(scf.RHF(mol), 4, 4).as_scanner() >>> e = mc_scanner(gto.M(atom='N 0 0 0; N 0 0 1.1')) >>> e = mc_scanner(gto.M(atom='N 0 0 0; N 0 0 1.5'))
pyscf.mcscf.mc1step_symm module¶
- pyscf.mcscf.mc1step_symm.CASSCF¶
- class pyscf.mcscf.mc1step_symm.SymAdaptedCASSCF(mf_or_mol, ncas, nelecas, ncore=None, frozen=None)[source]¶
Bases:
pyscf.mcscf.mc1step.CASSCF
- Args:
- mf_or_molSCF object or Mole object
SCF or Mole to define the problem size.
- ncasint
Number of active orbitals.
- nelecasint or a pair of int
Number of electrons in active space.
- Kwargs:
- ncoreint
Number of doubly occupied core orbitals. If not presented, this parameter can be automatically determined.
- Attributes:
- verboseint
Print level. Default value equals to
Mole.verbose
.- max_memoryfloat or int
Allowed memory in MB. Default value equals to
Mole.max_memory
.- ncasint
Active space size.
- nelecastuple of int
Active (nelec_alpha, nelec_beta)
- ncoreint or tuple of int
Core electron number. In UHF-CASSCF, it’s a tuple to indicate the different core eletron numbers.
- natorbbool
Whether to transform natural orbitals in active space. Note: when CASCI/CASSCF are combined with DMRG solver or selected CI solver, enabling this parameter may slightly change the total energy. False by default.
- canonicalizationbool
Whether to canonicalize orbitals in core and external space against the general Fock matrix. The orbitals in active space are NOT transformed by default. To get the natural orbitals in active space, the attribute .natorb needs to be enabled. True by default.
- sorting_mo_energybool
Whether to sort the orbitals based on the diagonal elements of the general Fock matrix. Default is False.
- fcisolveran instance of
FCISolver
The pyscf.fci module provides several FCISolver for different scenario. Generally, fci.direct_spin1.FCISolver can be used for all RHF-CASSCF. However, a proper FCISolver can provide better performance and better numerical stability. One can either use
fci.solver()
function to pick the FCISolver by the program or manually assigen the FCISolver to this attribute, e.g.>>> from pyscf import fci >>> mc = mcscf.CASSCF(mf, 4, 4) >>> mc.fcisolver = fci.solver(mol, singlet=True) >>> mc.fcisolver = fci.direct_spin1.FCISolver(mol)
You can control FCISolver by setting e.g.:
>>> mc.fcisolver.max_cycle = 30 >>> mc.fcisolver.conv_tol = 1e-7
For more details of the parameter for FCISolver, See
fci
.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- e_casfloat
CAS space FCI energy
- cindarray
CAS space FCI coefficients
- mo_coeffndarray
When canonicalization is specified, the orbitals are canonical orbitals which make the general Fock matrix (Fock operator on top of MCSCF 1-particle density matrix) diagonalized within each subspace (core, active, external). If natorb (natural orbitals in active space) is specified, the active segment of the mo_coeff is natural orbitls.
- mo_energyndarray
Diagonal elements of general Fock matrix (in mo_coeff representation).
- mo_occndarray
Occupation numbers of natural orbitals if natorb is specified.
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASCI(mf, 6, 6) >>> mc.kernel()[0] -108.980200816243354 CASSCF
Extra attributes for CASSCF:
- conv_tolfloat
Converge threshold. Default is 1e-7
- conv_tol_gradfloat
Converge threshold for CI gradients and orbital rotation gradients. Default is 1e-4
- max_stepsizefloat
The step size for orbital rotation. Small step (0.005 - 0.05) is prefered. Default is 0.03.
- max_cycle_macroint
Max number of macro iterations. Default is 50.
- max_cycle_microint
Max number of micro iterations in each macro iteration. Depending on systems, increasing this value might reduce the total macro iterations. Generally, 2 - 5 steps should be enough. Default is 3.
- ah_level_shiftfloat, for AH solver.
Level shift for the Davidson diagonalization in AH solver. Default is 1e-8.
- ah_conv_tolfloat, for AH solver.
converge threshold for AH solver. Default is 1e-12.
- ah_max_cyclefloat, for AH solver.
Max number of iterations allowd in AH solver. Default is 30.
- ah_lindepfloat, for AH solver.
Linear dependence threshold for AH solver. Default is 1e-14.
- ah_start_tolflat, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 0.2.
- ah_start_cycleint, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 2.
ah_conv_tol
,ah_max_cycle
,ah_lindep
,ah_start_tol
andah_start_cycle
can affect the accuracy and performance of CASSCF solver. Lowerah_conv_tol
andah_lindep
might improve the accuracy of CASSCF optimization, but decrease the performance.>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.UHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.conv_tol = 1e-10 >>> mc.ah_conv_tol = 1e-5 >>> mc.kernel()[0] -109.044401898486001 >>> mc.ah_conv_tol = 1e-10 >>> mc.kernel()[0] -109.044401887945668
- chkfilestr
Checkpoint file to save the intermediate orbitals during the CASSCF optimization. Default is the checkpoint file of mean field object.
- ci_response_spaceint
subspace size to solve the CI vector response. Default is 3.
- callbackfunction(envs_dict) => None
callback function takes one dict as the argument which is generated by the builtin function
locals()
, so that the callback function can access all local variables in the current envrionment.- scale_restorationfloat
When a step of orbital rotation moves out of trust region, the orbital optimization will be restored to previous state and the step size of the orbital rotation needs to be reduced. scale_restoration controls how much to scale down the step size.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- e_casfloat
CAS space FCI energy
- cindarray
CAS space FCI coefficients
- mo_coeffndarray
Optimized CASSCF orbitals coefficients. When canonicalization is specified, the returned orbitals make the general Fock matrix (Fock operator on top of MCSCF 1-particle density matrix) diagonalized within each subspace (core, active, external). If natorb (natural orbitals in active space) is enabled, the active segment of mo_coeff is transformed to natural orbitals.
- mo_energyndarray
Diagonal elements of general Fock matrix (in mo_coeff representation).
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.kernel()[0] -109.044401882238134
- kernel(mo_coeff=None, ci0=None, callback=None, _kern=None)[source]¶
- Returns:
Five elements, they are total energy, active space CI energy, the active space FCI wavefunction coefficients or DMRG wavefunction ID, the MCSCF canonical orbital coefficients, the MCSCF canonical orbital coefficients.
They are attributes of mcscf object, which can be accessed by .e_tot, .e_cas, .ci, .mo_coeff, .mo_energy
- sort_mo_by_irrep(cas_irrep_nocc, cas_irrep_ncore=None, mo_coeff=None, s=None)[source]¶
Select active space based on symmetry information. See also
pyscf.mcscf.addons.sort_mo_by_irrep()
- property wfnsym¶
pyscf.mcscf.mc2step module¶
pyscf.mcscf.mc_ao2mo module¶
pyscf.mcscf.newton_casscf module¶
Second order CASSCF
- class pyscf.mcscf.newton_casscf.CASSCF(mf_or_mol, ncas, nelecas, ncore=None, frozen=None)[source]¶
Bases:
pyscf.mcscf.mc1step.CASSCF
- Args:
- mf_or_molSCF object or Mole object
SCF or Mole to define the problem size.
- ncasint
Number of active orbitals.
- nelecasint or a pair of int
Number of electrons in active space.
- Kwargs:
- ncoreint
Number of doubly occupied core orbitals. If not presented, this parameter can be automatically determined.
- Attributes:
- verboseint
Print level. Default value equals to
Mole.verbose
.- max_memoryfloat or int
Allowed memory in MB. Default value equals to
Mole.max_memory
.- ncasint
Active space size.
- nelecastuple of int
Active (nelec_alpha, nelec_beta)
- ncoreint or tuple of int
Core electron number. In UHF-CASSCF, it’s a tuple to indicate the different core eletron numbers.
- natorbbool
Whether to transform natural orbitals in active space. Note: when CASCI/CASSCF are combined with DMRG solver or selected CI solver, enabling this parameter may slightly change the total energy. False by default.
- canonicalizationbool
Whether to canonicalize orbitals in core and external space against the general Fock matrix. The orbitals in active space are NOT transformed by default. To get the natural orbitals in active space, the attribute .natorb needs to be enabled. True by default.
- sorting_mo_energybool
Whether to sort the orbitals based on the diagonal elements of the general Fock matrix. Default is False.
- fcisolveran instance of
FCISolver
The pyscf.fci module provides several FCISolver for different scenario. Generally, fci.direct_spin1.FCISolver can be used for all RHF-CASSCF. However, a proper FCISolver can provide better performance and better numerical stability. One can either use
fci.solver()
function to pick the FCISolver by the program or manually assigen the FCISolver to this attribute, e.g.>>> from pyscf import fci >>> mc = mcscf.CASSCF(mf, 4, 4) >>> mc.fcisolver = fci.solver(mol, singlet=True) >>> mc.fcisolver = fci.direct_spin1.FCISolver(mol)
You can control FCISolver by setting e.g.:
>>> mc.fcisolver.max_cycle = 30 >>> mc.fcisolver.conv_tol = 1e-7
For more details of the parameter for FCISolver, See
fci
.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- e_casfloat
CAS space FCI energy
- cindarray
CAS space FCI coefficients
- mo_coeffndarray
When canonicalization is specified, the orbitals are canonical orbitals which make the general Fock matrix (Fock operator on top of MCSCF 1-particle density matrix) diagonalized within each subspace (core, active, external). If natorb (natural orbitals in active space) is specified, the active segment of the mo_coeff is natural orbitls.
- mo_energyndarray
Diagonal elements of general Fock matrix (in mo_coeff representation).
- mo_occndarray
Occupation numbers of natural orbitals if natorb is specified.
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASCI(mf, 6, 6) >>> mc.kernel()[0] -108.980200816243354 CASSCF
Extra attributes for CASSCF:
- conv_tolfloat
Converge threshold. Default is 1e-7
- conv_tol_gradfloat
Converge threshold for CI gradients and orbital rotation gradients. Default is 1e-4
- max_stepsizefloat
The step size for orbital rotation. Small step (0.005 - 0.05) is prefered. (see notes in max_cycle_micro_inner attribute) Default is 0.03.
- max_cycle_macroint
Max number of macro iterations. Default is 50.
- max_cycle_microint
Max number of micro (CIAH) iterations in each macro iteration.
- ah_level_shiftfloat, for AH solver.
Level shift for the Davidson diagonalization in AH solver. Default is 1e-8.
- ah_conv_tolfloat, for AH solver.
converge threshold for AH solver. Default is 1e-12.
- ah_max_cyclefloat, for AH solver.
Max number of iterations allowd in AH solver. Default is 30.
- ah_lindepfloat, for AH solver.
Linear dependence threshold for AH solver. Default is 1e-14.
- ah_start_tolflat, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 0.2.
- ah_start_cycleint, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 2.
ah_conv_tol
,ah_max_cycle
,ah_lindep
,ah_start_tol
andah_start_cycle
can affect the accuracy and performance of CASSCF solver. Lowerah_conv_tol
andah_lindep
might improve the accuracy of CASSCF optimization, but decrease the performance.>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.UHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.conv_tol = 1e-10 >>> mc.ah_conv_tol = 1e-5 >>> mc.kernel() -109.044401898486001 >>> mc.ah_conv_tol = 1e-10 >>> mc.kernel() -109.044401887945668
- chkfilestr
Checkpoint file to save the intermediate orbitals during the CASSCF optimization. Default is the checkpoint file of mean field object.
- callbackfunction(envs_dict) => None
callback function takes one dict as the argument which is generated by the builtin function
locals()
, so that the callback function can access all local variables in the current envrionment.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- cindarray
CAS space FCI coefficients
- convergedbool
It indicates CASSCF optimization converged or not.
- mo_coeffndarray
Optimized CASSCF orbitals coefficients
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.kernel()[0] -109.044401882238134
- get_h2cas(mo_coeff=None)[source]¶
Computing active space two-particle Hamiltonian.
Note It is different to get_h2eff when df.approx_hessian is applied, in which get_h2eff function returns the DF integrals while get_h2cas returns the regular 2-electron integrals.
- get_h2eff(mo_coeff=None)[source]¶
Computing active space two-particle Hamiltonian.
Note It is different to get_h2cas when df.approx_hessian is applied, in which get_h2eff function returns the DF integrals while get_h2cas returns the regular 2-electron integrals.
- kernel(mo_coeff=None, ci0=None, callback=None)[source]¶
- Returns:
Five elements, they are total energy, active space CI energy, the active space FCI wavefunction coefficients or DMRG wavefunction ID, the MCSCF canonical orbital coefficients, the MCSCF canonical orbital coefficients.
They are attributes of mcscf object, which can be accessed by .e_tot, .e_cas, .ci, .mo_coeff, .mo_energy
pyscf.mcscf.newton_casscf_symm module¶
- class pyscf.mcscf.newton_casscf_symm.CASSCF(mf_or_mol, ncas, nelecas, ncore=None, frozen=None)[source]¶
Bases:
pyscf.mcscf.newton_casscf.CASSCF
- Args:
- mf_or_molSCF object or Mole object
SCF or Mole to define the problem size.
- ncasint
Number of active orbitals.
- nelecasint or a pair of int
Number of electrons in active space.
- Kwargs:
- ncoreint
Number of doubly occupied core orbitals. If not presented, this parameter can be automatically determined.
- Attributes:
- verboseint
Print level. Default value equals to
Mole.verbose
.- max_memoryfloat or int
Allowed memory in MB. Default value equals to
Mole.max_memory
.- ncasint
Active space size.
- nelecastuple of int
Active (nelec_alpha, nelec_beta)
- ncoreint or tuple of int
Core electron number. In UHF-CASSCF, it’s a tuple to indicate the different core eletron numbers.
- natorbbool
Whether to transform natural orbitals in active space. Note: when CASCI/CASSCF are combined with DMRG solver or selected CI solver, enabling this parameter may slightly change the total energy. False by default.
- canonicalizationbool
Whether to canonicalize orbitals in core and external space against the general Fock matrix. The orbitals in active space are NOT transformed by default. To get the natural orbitals in active space, the attribute .natorb needs to be enabled. True by default.
- sorting_mo_energybool
Whether to sort the orbitals based on the diagonal elements of the general Fock matrix. Default is False.
- fcisolveran instance of
FCISolver
The pyscf.fci module provides several FCISolver for different scenario. Generally, fci.direct_spin1.FCISolver can be used for all RHF-CASSCF. However, a proper FCISolver can provide better performance and better numerical stability. One can either use
fci.solver()
function to pick the FCISolver by the program or manually assigen the FCISolver to this attribute, e.g.>>> from pyscf import fci >>> mc = mcscf.CASSCF(mf, 4, 4) >>> mc.fcisolver = fci.solver(mol, singlet=True) >>> mc.fcisolver = fci.direct_spin1.FCISolver(mol)
You can control FCISolver by setting e.g.:
>>> mc.fcisolver.max_cycle = 30 >>> mc.fcisolver.conv_tol = 1e-7
For more details of the parameter for FCISolver, See
fci
.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- e_casfloat
CAS space FCI energy
- cindarray
CAS space FCI coefficients
- mo_coeffndarray
When canonicalization is specified, the orbitals are canonical orbitals which make the general Fock matrix (Fock operator on top of MCSCF 1-particle density matrix) diagonalized within each subspace (core, active, external). If natorb (natural orbitals in active space) is specified, the active segment of the mo_coeff is natural orbitls.
- mo_energyndarray
Diagonal elements of general Fock matrix (in mo_coeff representation).
- mo_occndarray
Occupation numbers of natural orbitals if natorb is specified.
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASCI(mf, 6, 6) >>> mc.kernel()[0] -108.980200816243354 CASSCF
Extra attributes for CASSCF:
- conv_tolfloat
Converge threshold. Default is 1e-7
- conv_tol_gradfloat
Converge threshold for CI gradients and orbital rotation gradients. Default is 1e-4
- max_stepsizefloat
The step size for orbital rotation. Small step (0.005 - 0.05) is prefered. (see notes in max_cycle_micro_inner attribute) Default is 0.03.
- max_cycle_macroint
Max number of macro iterations. Default is 50.
- max_cycle_microint
Max number of micro (CIAH) iterations in each macro iteration.
- ah_level_shiftfloat, for AH solver.
Level shift for the Davidson diagonalization in AH solver. Default is 1e-8.
- ah_conv_tolfloat, for AH solver.
converge threshold for AH solver. Default is 1e-12.
- ah_max_cyclefloat, for AH solver.
Max number of iterations allowd in AH solver. Default is 30.
- ah_lindepfloat, for AH solver.
Linear dependence threshold for AH solver. Default is 1e-14.
- ah_start_tolflat, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 0.2.
- ah_start_cycleint, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 2.
ah_conv_tol
,ah_max_cycle
,ah_lindep
,ah_start_tol
andah_start_cycle
can affect the accuracy and performance of CASSCF solver. Lowerah_conv_tol
andah_lindep
might improve the accuracy of CASSCF optimization, but decrease the performance.>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.UHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.conv_tol = 1e-10 >>> mc.ah_conv_tol = 1e-5 >>> mc.kernel() -109.044401898486001 >>> mc.ah_conv_tol = 1e-10 >>> mc.kernel() -109.044401887945668
- chkfilestr
Checkpoint file to save the intermediate orbitals during the CASSCF optimization. Default is the checkpoint file of mean field object.
- callbackfunction(envs_dict) => None
callback function takes one dict as the argument which is generated by the builtin function
locals()
, so that the callback function can access all local variables in the current envrionment.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- cindarray
CAS space FCI coefficients
- convergedbool
It indicates CASSCF optimization converged or not.
- mo_coeffndarray
Optimized CASSCF orbitals coefficients
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.kernel()[0] -109.044401882238134
- kernel(mo_coeff=None, ci0=None, callback=None, _kern=None)[source]¶
- Returns:
Five elements, they are total energy, active space CI energy, the active space FCI wavefunction coefficients or DMRG wavefunction ID, the MCSCF canonical orbital coefficients, the MCSCF canonical orbital coefficients.
They are attributes of mcscf object, which can be accessed by .e_tot, .e_cas, .ci, .mo_coeff, .mo_energy
pyscf.mcscf.ucasci module¶
UCASCI (CASCI with non-degenerated alpha and beta orbitals, typically UHF orbitals)
- pyscf.mcscf.ucasci.CASCI¶
alias of
pyscf.mcscf.ucasci.UCASCI
- class pyscf.mcscf.ucasci.UCASCI(mf_or_mol, ncas, nelecas, ncore=None)[source]¶
Bases:
pyscf.mcscf.casci.CASCI
- analyze(mo_coeff=None, ci=None, verbose=None, large_ci_tol=0.1, with_meta_lowdin=True, **kwargs)[source]¶
- cas_natorb(mo_coeff=None, ci0=None)[source]¶
Transform active orbitals to natrual orbitals, and update the CI wfn accordingly
- Args:
mc : a CASSCF/CASCI object or RHF object
- Kwargs:
- sortbool
Sort natural orbitals wrt the occupancy.
- Returns:
A tuple, the first item is natural orbitals, the second is updated CI coefficients, the third is the natural occupancy associated to the natural orbitals.
- cas_natorb_(mo_coeff=None, ci0=None)[source]¶
Transform active orbitals to natrual orbitals, and update the CI wfn accordingly
- Args:
mc : a CASSCF/CASCI object or RHF object
- Kwargs:
- sortbool
Sort natural orbitals wrt the occupancy.
- Returns:
A tuple, the first item is natural orbitals, the second is updated CI coefficients, the third is the natural occupancy associated to the natural orbitals.
- fix_spin = None¶
- fix_spin_ = None¶
- get_h1cas(mo_coeff=None, ncas=None, ncore=None)¶
CAS sapce one-electron hamiltonian for UHF-CASCI or UHF-CASSCF
- Args:
casci : a U-CASSCF/U-CASCI object or UHF object
- get_h1eff(mo_coeff=None, ncas=None, ncore=None)[source]¶
CAS sapce one-electron hamiltonian for UHF-CASCI or UHF-CASSCF
- Args:
casci : a U-CASSCF/U-CASCI object or UHF object
- get_h2cas(mo_coeff=None)[source]¶
Compute the active space two-particle Hamiltonian.
Note It is different to get_h2eff when df.approx_hessian is applied, in which get_h2eff function returns the DF integrals while get_h2cas returns the regular 2-electron integrals.
- get_h2eff(mo_coeff=None)[source]¶
Compute the active space two-particle Hamiltonian.
Note It is different to get_h2cas when df.approx_hessian is applied. in which get_h2eff function returns the DF integrals while get_h2cas returns the regular 2-electron integrals.
- get_veff(mol=None, dm=None, hermi=1)[source]¶
Hartree-Fock potential matrix for the given density matrix
- Args:
mol : an instance of
Mole
- dmndarray or list of ndarrays
A density matrix or a list of density matrices
- Kwargs:
- dm_lastndarray or a list of ndarrays or 0
The density matrix baseline. If not 0, this function computes the increment of HF potential w.r.t. the reference HF potential matrix.
- vhf_lastndarray or a list of ndarrays or 0
The reference HF potential matrix.
- hermiint
Whether J, K matrix is hermitian
0 : no hermitian or symmetric1 : hermitian2 : anti-hermitian- vhfopt :
A class which holds precomputed quantities to optimize the computation of J, K matrices
- Returns:
matrix Vhf = 2*J - K. Vhf can be a list matrices, corresponding to the input density matrices.
Examples:
>>> import numpy >>> from pyscf import gto, scf >>> from pyscf.scf import _vhf >>> mol = gto.M(atom='H 0 0 0; H 0 0 1.1') >>> dm0 = numpy.random.random((mol.nao_nr(),mol.nao_nr())) >>> vhf0 = scf.hf.get_veff(mol, dm0, hermi=0) >>> dm1 = numpy.random.random((mol.nao_nr(),mol.nao_nr())) >>> vhf1 = scf.hf.get_veff(mol, dm1, hermi=0) >>> vhf2 = scf.hf.get_veff(mol, dm1, dm_last=dm0, vhf_last=vhf0, hermi=0) >>> numpy.allclose(vhf1, vhf2) True
- h1e_for_cas(mo_coeff=None, ncas=None, ncore=None)¶
CAS sapce one-electron hamiltonian for UHF-CASCI or UHF-CASSCF
- Args:
casci : a U-CASSCF/U-CASCI object or UHF object
- kernel(mo_coeff=None, ci0=None)[source]¶
- Returns:
Five elements, they are total energy, active space CI energy, the active space FCI wavefunction coefficients or DMRG wavefunction ID, the MCSCF canonical orbital coefficients, the MCSCF canonical orbital coefficients.
They are attributes of mcscf object, which can be accessed by .e_tot, .e_cas, .ci, .mo_coeff, .mo_energy
- make_rdm1(mo_coeff=None, ci=None, ncas=None, nelecas=None, ncore=None, **kwargs)[source]¶
One-particle density matrix in AO representation
- make_rdm1s(mo_coeff=None, ci=None, ncas=None, nelecas=None, ncore=None, **kwargs)[source]¶
One-particle density matrices for alpha and beta spin on AO basis
- property ncore¶
- sort_mo(caslst, mo_coeff=None, base=1)[source]¶
Pick orbitals for CAS space
- Args:
casscf : an
CASSCF
orCASCI
object- mo_coeffndarray or a list of ndarray
Orbitals for CASSCF initial guess. In the UHF-CASSCF, it’s a list of two orbitals, for alpha and beta spin.
- caslstlist of int or nested list of int
A list of orbital indices to represent the CAS space. In the UHF-CASSCF, it’s consist of two lists, for alpha and beta spin.
- Kwargs:
- baseint
0-based (C-style) or 1-based (Fortran-style) caslst
- Returns:
An reoreded mo_coeff, which put the orbitals given by caslst in the CAS space
Examples:
>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.RHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 4, 4) >>> cas_list = [5,6,8,9] # pi orbitals >>> mo = mc.sort_mo(cas_list) >>> mc.kernel(mo)[0] -109.007378939813691
pyscf.mcscf.umc1step module¶
UCASSCF (CASSCF without spin-degeneracy between alpha and beta orbitals) 1-step optimization algorithm
- pyscf.mcscf.umc1step.CASSCF¶
alias of
pyscf.mcscf.umc1step.UCASSCF
- class pyscf.mcscf.umc1step.UCASSCF(mf_or_mol, ncas, nelecas, ncore=None, frozen=None)[source]¶
Bases:
pyscf.mcscf.ucasci.UCASCI
- ah_conv_tol = 1e-12¶
- ah_grad_trust_region = 3.0¶
- ah_level_shift = 1e-08¶
- ah_lindep = 1e-14¶
- ah_max_cycle = 30¶
- ah_start_cycle = 3¶
- ah_start_tol = 2.5¶
- chk_ci = False¶
- ci_response_space = 4¶
- conv_tol = 1e-07¶
- conv_tol_grad = None¶
- get_h2cas(mo_coeff=None)[source]¶
Compute the active space two-particle Hamiltonian.
Note It is different to get_h2eff when df.approx_hessian is applied, in which get_h2eff function returns the DF integrals while get_h2cas returns the regular 2-electron integrals.
- internal_rotation = False¶
- kernel(mo_coeff=None, ci0=None, callback=None, _kern=<function kernel>)[source]¶
- Returns:
Five elements, they are total energy, active space CI energy, the active space FCI wavefunction coefficients or DMRG wavefunction ID, the MCSCF canonical orbital coefficients, the MCSCF canonical orbital coefficients.
They are attributes of mcscf object, which can be accessed by .e_tot, .e_cas, .ci, .mo_coeff, .mo_energy
- kf_interval = 4¶
- kf_trust_region = 3.0¶
- max_cycle_macro = 50¶
- max_cycle_micro = 4¶
- property max_orb_stepsize¶
- max_stepsize = 0.02¶
- natorb = False¶
- rotate_orb_cc(mo, fcivec, fcasdm1, fcasdm2, eris, x0_guess=None, conv_tol_grad=0.0001, max_stepsize=None, verbose=None)¶
- solve_approx_ci(h1, h2, ci0, ecore, e_cas)[source]¶
Solve CI eigenvalue/response problem approximately
- with_dep4 = False¶
pyscf.mcscf.umc2step module¶
UCASSCF (CASSCF without spin-degeneracy between alpha and beta orbitals) 2-step optimization algorithm
pyscf.mcscf.umc_ao2mo module¶
MO integrals for UCASSCF methods
Module contents¶
CASCI and CASSCF
When using results of this code for publications, please cite the following paper: “A general second order complete active space self-consistent-field solver for large-scale systems”, Q. Sun, J. Yang, and G. K.-L. Chan, Chem. Phys. Lett. 683, 291 (2017).
Simple usage:
>>> from pyscf import gto, scf, mcscf
>>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0)
>>> mf = scf.RHF(mol).run()
>>> mc = mcscf.CASCI(mf, 6, 6)
>>> mc.kernel()[0]
-108.980200816243354
>>> mc = mcscf.CASSCF(mf, 6, 6)
>>> mc.kernel()[0]
-109.044401882238134
>>> mc = mcscf.CASSCF(mf, 4, 4)
>>> cas_list = [5,6,8,9] # pick orbitals for CAS space, 1-based indices
>>> mo = mcscf.sort_mo(mc, mf.mo_coeff, cas_list)
>>> mc.kernel(mo)[0]
-109.007378939813691
mcscf.CASSCF()
or mcscf.CASCI()
returns a proper instance of CASSCF/CASCI class.
There are some parameters to control the CASSCF/CASCI method.
- verboseint
Print level. Default value equals to
Mole.verbose
.- max_memoryfloat or int
Allowed memory in MB. Default value equals to
Mole.max_memory
.- ncasint
Active space size.
- nelecastuple of int
Active (nelec_alpha, nelec_beta)
- ncoreint or tuple of int
Core electron number. In UHF-CASSCF, it’s a tuple to indicate the different core eletron numbers.
- natorbbool
Whether to restore the natural orbital during CASSCF optimization. Default is not.
- canonicalizationbool
Whether to canonicalize orbitals. Default is True.
- fcisolveran instance of
FCISolver
The pyscf.fci module provides several FCISolver for different scenario. Generally, fci.direct_spin1.FCISolver can be used for all RHF-CASSCF. However, a proper FCISolver can provide better performance and better numerical stability. One can either use
fci.solver()
function to pick the FCISolver by the program or manually assigen the FCISolver to this attribute, e.g.>>> from pyscf import fci >>> mc = mcscf.CASSCF(mf, 4, 4) >>> mc.fcisolver = fci.solver(mol, singlet=True) >>> mc.fcisolver = fci.direct_spin1.FCISolver(mol)You can control FCISolver by setting e.g.:
>>> mc.fcisolver.max_cycle = 30 >>> mc.fcisolver.conv_tol = 1e-7For more details of the parameter for FCISolver, See
fci
.By replacing this fcisolver, you can easily use the CASCI/CASSCF solver with other FCI replacements, such as DMRG, QMC. See
dmrgscf
andfciqmcscf
.
The Following attributes are used for CASSCF
- conv_tolfloat
Converge threshold. Default is 1e-7
- conv_tol_gradfloat
Converge threshold for CI gradients and orbital rotation gradients. Default is 1e-4
- max_stepsizefloat
The step size for orbital rotation. Small step size is prefered. Default is 0.03. (NOTE although the default step size is small enough for many systems, it happens that the orbital optimizor crosses the barriar of local minimum and converge to the neighbour solution, e.g. the CAS(4,4) for C2H4 in the test files. In these systems, adjusting max_stepsize, max_ci_stepsize and max_cycle_micro, max_cycle_micro_inner and ah_start_tol may be helpful)
>>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.max_stepsize = .01 >>> mc.max_cycle_micro = 1 >>> mc.max_cycle_macro = 100 >>> mc.max_cycle_micro_inner = 1 >>> mc.ah_start_tol = 1e-6- max_ci_stepsizefloat
The max size for approximate CI updates. The approximate updates are used in 1-step algorithm, to estimate the change of CI wavefunction wrt the orbital rotation. Small step size is prefered. Default is 0.01.
- max_cycle_macroint
Max number of macro iterations. Default is 50.
- max_cycle_microint
Max number of micro iterations in each macro iteration. Depending on systems, increasing this value might reduce the total macro iterations. Generally, 2 - 3 steps should be enough. Default is 2.
- max_cycle_micro_innerint
Max number of steps for the orbital rotations allowed for the augmented hessian solver. It can affect the actual size of orbital rotation. Even with a small max_stepsize, a few max_cycle_micro_inner can accumulate the rotation and leads to a significant change of the CAS space. Depending on systems, increasing this value migh reduce the total number of macro iterations. The value between 2 - 8 is preferred. Default is 4.
- frozenint or list
If integer is given, the inner-most orbitals are excluded from optimization. Given the orbital indices (0-based) in a list, any doubly occupied core orbitals, active orbitals and external orbitals can be frozen.
- ah_level_shiftfloat, for AH solver.
Level shift for the Davidson diagonalization in AH solver. Default is 0.
- ah_conv_tolfloat, for AH solver.
converge threshold for Davidson diagonalization in AH solver. Default is 1e-8.
- ah_max_cyclefloat, for AH solver.
Max number of iterations allowd in AH solver. Default is 20.
- ah_lindepfloat, for AH solver.
Linear dependence threshold for AH solver. Default is 1e-16.
- ah_start_tolflat, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 1e-4.
- ah_start_cycleint, for AH solver.
In AH solver, the orbital rotation is started without completely solving the AH problem. This value is to control the start point. Default is 3.
ah_conv_tol
,ah_max_cycle
,ah_lindep
,ah_start_tol
andah_start_cycle
can affect the accuracy and performance of CASSCF solver. Lowerah_conv_tol
andah_lindep
can improve the accuracy of CASSCF optimization, but slow down the performance.>>> from pyscf import gto, scf, mcscf >>> mol = gto.M(atom='N 0 0 0; N 0 0 1', basis='ccpvdz', verbose=0) >>> mf = scf.UHF(mol) >>> mf.scf() >>> mc = mcscf.CASSCF(mf, 6, 6) >>> mc.conv_tol = 1e-10 >>> mc.ah_conv_tol = 1e-5 >>> mc.kernel() -109.044401898486001 >>> mc.ah_conv_tol = 1e-10 >>> mc.kernel() -109.044401887945668- chkfilestr
Checkpoint file to save the intermediate orbitals during the CASSCF optimization. Default is the checkpoint file of mean field object.
Saved results
- e_totfloat
Total MCSCF energy (electronic energy plus nuclear repulsion)
- cindarray
CAS space FCI coefficients
- convergedbool, for CASSCF only
It indicates CASSCF optimization converged or not.
- mo_energy: ndarray,
Diagonal elements of general Fock matrix
- mo_coeffndarray, for CASSCF only
Optimized CASSCF orbitals coefficients Note the orbitals are NOT natural orbitals by default. There are two inbuilt methods to convert the mo_coeff to natural orbitals. 1. Set .natorb attribute. It can be used before calculation. 2. call .cas_natorb_ method after the calculation to in-place convert the orbitals
- pyscf.mcscf.RCASCI(mf_or_mol, ncas, nelecas, ncore=None)¶
- pyscf.mcscf.RCASSCF(mf_or_mol, ncas, nelecas, ncore=None, frozen=None)¶