Seminumerical exchange (SGX)

Modules: sgx

The SGX module implements seminumerical computation of the exchange matrix.


Direct computation of the Hartree-Fock exchange matrix in the atomic orbital basis scales poorly with system size. To achieve better scaling, one three-dimensional integral in the 6-dimensional two-electron integrals can be computed analytically, while the other can be evaluated on a real-space grid, as proposed by Friesner [1]. The PySCF implementation resembles the chain-of-spheres (COSX) algorithm of Neese et al. [2], but uses more conservative grids and does not implement P-junction screening. Overlap fitting is used to reduce aliasing errors [3]. SGX scales as \(O(N^2)\) with system size, as opposed to the \(O(N^4)\) scaling of analytical exchange [2].

Usage and Example

Any scf.hf.SCF object mf can be converted to an equivalent object that computes the Coulomb and exchange matrices with SGX instead of analytical integration by calling sgx.sgx_fit(mf).

#!/usr/bin/env python

This example shows how to use pseudo spectral integrals in SCF calculation.

from pyscf import gto
from pyscf import scf
from pyscf import sgx
mol = gto.M(
    atom='''O    0.   0.       0.
            H    0.   -0.757   0.587
            H    0.   0.757    0.587
    basis = 'ccpvdz',
mf = sgx.sgx_fit(scf.RHF(mol))

# Using RI for Coulomb matrix while K-matrix is constructed with COS-X method
mf.with_df.dfj = True
converged SCF energy = -76.0267374704185
converged SCF energy = -76.0267978618974

In this case, the error of SGX compared to analytical exchange is about 0.06 mEh. The line

mf.with_df.dfj = True

specifies to compute the Coulomb matrix using density fitting (DF-J) while using SGX for the exchange matrix.

Adjustable Parameters

Calling the sgx_fit function on an scf.hf.SCF object returns an equivalent SGXHF object with a with_df attribute that handles SGX integration. To use a non-default auxiliary basis (for dfj=True), auxbasis can be specified in the call to sgx_fit. In addition, there are five main adjustable parameters for this object:

  • grids_level_i: The grid level to use for initial SCF iterations.

  • grids_level_f: The grid level to use for final SCF iterations.

  • grids_thrd: The grid points where no atomic orbital is significant (has a value greater than this threshold) are removed from consideration.

  • grids_switch_thrd: The threshold for the magnitude of the change in the density matrix that triggers the switch from the initial grid specified by grids_level_i to the final grid specified by grids_level_f.

  • blockdim: The maximum number of grid points to loop over at once. The number of grid points per batch is the minimum of blockmin and the maximum number of points allowed by the memory available for the calculation. The maximum memory can be adjusted by setting the max_memory attribute, which is initially set to mol.max_memory, the max memory setting for the Mole object.



Richard A. Friesner. Solution of self-consistent field electronic structure equations by a pseudospectral method. Chem. Phys. Lett., 116:39–43, 1985. doi:10.1016/0009-2614(85)80121-4.


Frank Neese, Frank Wennmohs, Andreas Hansen, and Ute Becker. Efficient, approximate and parallel Hartree-Fock and hybrid DFT calculations. A ‘chain-of-spheres’ algorithm for the Hartree-Fock exchange. Chem. Phys., 356:98, 2009. doi:10.1016/j.chemphys.2008.10.036.


Róbert Izsák and Frank Neese. An overlap fitted chain of spheres exchange method. J. Chem. Phys., 135:144105, 2011. doi:10.1063/1.3646921.