Python-based quantum chemistry framework providing electronic structure methods for molecular simulations
—
Atomic orbital to molecular orbital integral transformations essential for post-SCF methods, providing both in-core and out-of-core algorithms for different system sizes and memory requirements.
Core functions for transforming 2-electron integrals from atomic orbital to molecular orbital basis.
def kernel(eri_or_mol, mo_coeffs, erifile=None, dataname='eri_mo', intor='int2e', **kwargs):
"""
General AO→MO integral transformation.
Parameters:
- eri_or_mol: ndarray or Mole, AO integrals or molecule object
- mo_coeffs: ndarray or tuple, MO coefficients for transformation
- erifile: str, output file for transformed integrals
- dataname: str, dataset name in output file
- intor: str, integral type ('int2e', 'int2e_spinor', etc.)
Returns:
ndarray or str, transformed integrals or filename
"""
def full(eri_or_mol, mo_coeff, erifile=None, dataname='eri_mo', intor='int2e', **kwargs):
"""
Full 4-index (ij|kl) integral transformation.
Transform all four indices using the same MO coefficients.
Most common transformation for post-SCF methods.
"""
def general(eri_or_mol, mo_coeffs, erifile=None, dataname='eri_mo', intor='int2e', **kwargs):
"""
General transformation with different orbital sets.
Parameters:
- mo_coeffs: tuple of 4 arrays, MO coefficients for each index
Allows different orbital spaces for each integral index,
useful for excited states and response properties.
"""def get_ao_eri(mol, aosym='s1', **kwargs):
"""
Get atomic orbital 2-electron repulsion integrals.
Parameters:
- mol: Mole object
- aosym: str, symmetry ('s1', 's4', 's8')
Returns:
ndarray, AO 2-electron integrals
"""
def restore(eri_mo, norb, tao):
"""
Restore packed integral arrays to full format.
Parameters:
- eri_mo: ndarray, packed MO integrals
- norb: int, number of orbitals
- tao: ndarray, transformation coefficients
Returns:
ndarray, restored integrals
"""import pyscf
# Full transformation for post-SCF
mol = pyscf.M(atom='H2O', basis='6-31g')
mf = mol.RHF().run()
# Transform all integrals to MO basis
eri_mo = pyscf.ao2mo.full(mol, mf.mo_coeff)
print(f"MO integrals shape: {eri_mo.shape}")
# For large systems, use out-of-core
eri_file = pyscf.ao2mo.full(mol, mf.mo_coeff, erifile='h2o_mo.h5')# Separate occupied and virtual orbitals
nocc = mol.nelectron // 2
mo_occ = mf.mo_coeff[:, :nocc]
mo_vir = mf.mo_coeff[:, nocc:]
# (ov|ov) integrals for MP2
eri_ovov = pyscf.ao2mo.general(mol, [mo_occ, mo_vir, mo_occ, mo_vir])
# Mixed transformations for excited states
eri_mixed = pyscf.ao2mo.general(mol, [mo_occ, mo_occ, mo_vir, mo_vir])from typing import Union, Tuple
from typing_extensions import Literal
import numpy as np
ndarray = np.ndarray
# Orbital coefficient specifications
MOCoeffs = Union[ndarray, Tuple[ndarray, ...]]
# Symmetry specifications
AOSymmetry = Literal['s1', 's4', 's8']Install with Tessl CLI
npx tessl i tessl/pypi-pyscf