I have localized the canonical Hartree-Fock orbitals for a molecule in PySCF. Now I want to perform ccsd calculations with these localized orbitals. Is it possible with pyscf?

Example with CCSD with canonical HF orbitals.

import numpy
from pyscf import gto,scf,cc,lo
mol = gto.M(
    verbose = 4,
    atom = [
       [ 'H'   ,             0.000000 ,  0.000000 ,  0.100000],
       [ 'H1'   ,             0.000000 ,  0.000000 ,  0.860000],
       [ 'H'   ,             2.000000 ,  0.000000 ,  0.100000],
       [ 'H1'   ,             2.000000 ,  0.000000 ,  0.860000]],
    basis = {'H': gto.parse('''
      0.9000000000D+00  0.1000000000D+01
      0.3000000000D+00  0.1000000000D+01
                 '''),'H1': gto.parse('''
      0.9900000000D+00  0.1000000000D+01
      0.3900000000D+00  0.1000000000D+01
# Canonical CCSD calculation
ccsd_can = cc.CCSD(mf)

Which runs fine. The energies are,

converged SCF energy = -2.06459106224567
Init t2, MP2 energy = -2.09735912778898  E_corr(MP2) -0.0327680655433131
E(CCSD) = -2.113707458228744  E_corr = -0.04911639598307826

Example with Boys localization followed by CCSD calculation.

localization_method = 'boys'  # You can choose 'boys', 'iao', 'pipek', etc.
mo_coeff_localized = lo.orth.orth_ao(mol, localization_method) 
mo_occ_localized = mf.mo_occ

This shows, warning, WARN: Weak orthogonality for localized orbitals 2.449489742783178. Now going to the CCSD calculation,

ccsd_localized = cc.CCSD(mf)
ccsd_localized.mo_coeff = mo_coeff_localized
mo_occ_localized = mf.mo_occ
ccsd_localized.mo_occ = mo_occ_localized

Which shows

******** <class 'pyscf.cc.ccsd.CCSD'> ********
CC2 = 0
CCSD nocc = 2, nmo = 8
max_cycle = 50
direct = 0
conv_tol = 1e-07
conv_tol_normt = 1e-05
diis_space = 6
diis_start_cycle = 0
diis_start_energy_diff = 1e+09
max_memory 4000 MB (current use 158 MB)

WARN: HOMO-LUMO gap 0.0 too small for CCSD.
CCSD may be difficult to converge. Increasing CCSD Attribute level_shift may improve convergence.

/home/pro/psi4conda/lib/python3.10/site-packages/pyscf/cc/ccsd.py:1053: RuntimeWarning: invalid value encountered in divide
  t1 = eris.fock[:nocc,nocc:] / eia
/home/pro/psi4conda/lib/python3.10/site-packages/pyscf/cc/ccsd.py:1060: RuntimeWarning: invalid value encountered in divide
  t2[:,:,p0:p1] = (eris_ovov.transpose(0,2,1,3).conj()
Init t2, MP2 energy = nan  E_corr(MP2) nan
Init E_corr(CCSD) = nan
cycle = 1  E_corr(CCSD) = nan  dE = nan  norm(t1,t2) = nan
cycle = 2  E_corr(CCSD) = nan  dE = nan  norm(t1,t2) = nan
cycle = 3  E_corr(CCSD) = nan  dE = nan  norm(t1,t2) = nan
cycle = 4  E_corr(CCSD) = nan  dE = nan  norm(t1,t2) = nan
cycle = 47  E_corr(CCSD) = nan  dE = nan  norm(t1,t2) = nan
cycle = 48  E_corr(CCSD) = nan  dE = nan  norm(t1,t2) = nan
cycle = 49  E_corr(CCSD) = nan  dE = nan  norm(t1,t2) = nan
cycle = 50  E_corr(CCSD) = nan  dE = nan  norm(t1,t2) = nan
CCSD not converged
E(CCSD) = nan  E_corr = nan

2 Answers 2


Working input file and output

Without changing your input lines for the HF calculation and the CCSD calculation without localization of orbitals, the following lines worked for doing CCSD with localized orbitals, the full input and output files can be found in our chat conversation, but I'll present the part involving localized orbitals here (and I'll use [...] to remove some less exciting parts):

ccsd_boys = cc.CCSD(mf)
ccsd_boys.mo_occ = mf.mo_occ
ccsd_boys.mo_coeff = boys_localized.mo_coeff

Output (Boys localization):

******** <class 'pyscf.lo.boys.Boys'> ********
CCSD converged
E(CCSD) = -1.255725715461556 E_corr = -0.07723572035747919

These can be compared the CCSD output when localization of orbitals had not been done:

CCSD converged 
E(CCSD) = -1.255729964675672 E_corr = -0.07349346928566028 

Why did your original attempt not work?

I found your original code confusing. For example, I could not see why you had the following command twice, with just mo_occ_localized = mf.mo_occ in between:

mo_occ_localized = mf.mo_occ

Also, while a more verbose code can have its advantages, it was hard for me to digest what was happening when you had 8 lines used to accomplish what seems to be more digestable when presented in 4 lines, as I did in our chat conversation. You then wrote:

"After your advice, I ran the code again in a fresh notebook. Now it seems it runs fine. Let me share the input and output."

Based on your input and output, it seems that my advice to remove the duplicate line and to condense the input file commands a bit, was indeed followed and led to a working calculation although your final version is a bit different from what I wrote.


CCSD is invariant to a unitary transformation of the orbitals, as a localization is. You should thus get the same result with canonical and localized orbitals. However, since the CCSD amplitudes are determined by solving a set of non-linear equations, some orbitals may be easier to get amplitude convergence than others. Most (all?) CCSD codes likely assume canonical orbitals, and the implemented amplitude solver perhaps assumes this.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .