# 10.21.12. Mixing PBC and molecular modules¶

Post-HF methods, as standalone numerical solvers, do not require knowledge of the boundary conditions. Calculations on finite-sized systems and extended systems are distinguished by the boundary conditions of the integrals (and basis). The same post-HF solver can thus be used for both finite-size problems and the periodic boundary problems if they have a compatible Hamiltonian structure.

In PySCF, many molecular post-HF solvers have two implementations: an incore and outcore version. These differ by the treatment of the 2-electron integrals. The incore solver takes the _eri (or with_df, see df — Density fitting) from the underlying mean-field object as the two-electron interaction part of the Hamiltonian while the outcore solver generates the 2-electron integrals (with free boundary conditions) on the fly. To use the molecular post-HF solvers in PBC code, we need to ensure that the incore version solver is called.

Generating _eri in a mean-field object is the straightforward way to trigger the incore post-HF solver. If the allowed memory is large enough to hold the entire 2-electron integral array, the Gamma point HF solver always generates and holds this array. A second choice is to set incore_anyway in cell which forces the program to generate and hold _eri in the mean-field object.

Note

If the problem is big, incore_anyway may overflow the available physical memory.

Holding the full integral array _eri in memory limits the problem size one can treat. Using the density fitting object with_df to hold the integrals can overcome this problem. This architecture has been bound to PBC and molecular mean-field modules. Not all post-HF methods are available with density fitting.

Aside from the 2-electron integrals, there are some attributes and methods required by the post-HF solver. They are get_hcore(), and get_ovlp() for 1-electron integrals, _numint, grids for the numerical integration of DFT exchange-correlation functionals. These are all overloaded in the PBC mean-field object to produce the PBC integrals.

## 10.21.12.1. Examples¶

#!/usr/bin/env python

'''
Gamma point post-HF calculation needs only real integrals.
Methods implemented in finite-size system can be directly used here without
any modification.
'''

import numpy
from pyscf.pbc import gto, scf

cell = gto.M(
a = numpy.eye(3)*3.5668,
atom = '''C     0.      0.      0.
C     0.8917  0.8917  0.8917
C     1.7834  1.7834  0.
C     2.6751  2.6751  0.8917
C     1.7834  0.      1.7834
C     2.6751  0.8917  2.6751
C     0.      1.7834  1.7834
C     0.8917  2.6751  2.6751''',
basis = '6-31g',
verbose = 4,
)

mf = scf.RHF(cell).density_fit()
mf.with_df.mesh = [10]*3
mf.kernel()

#
# Import CC, TDDFT module from the molecular implementations
#
from pyscf import cc, tddft
mycc = cc.CCSD(mf)
mycc.kernel()

mytd = tddft.TDHF(mf)
mytd.nstates = 5
mytd.kernel()