qstack.fields.decomposition

Density matrix decomposition onto auxiliary basis sets.

qstack.fields.decomposition.correct_N(mol, c0, N=None, mode='Lagrange', metric='u')[source]

Corrects decomposition coefficients to match the target total number of electrons.

Parameters:
  • mol (pyscf Mole) – pyscf Mole object used for the computation of the density matrix.

  • c0 (numpy ndarray) – 1D array of initial decomposition coefficients.

  • N (int, optional) – Target number of electrons. If None, uses mol.nelectron. Defaults to None.

  • mode (str) – Correction method (‘scale’ or ‘Lagrange’). Defaults to ‘Lagrange’.

  • metric (str) – Metric type for Lagrange correction (‘u’, ‘s’, or ‘j’). Defaults to ‘u’.

Returns:

Corrected decomposition coefficients (1D array).

Return type:

numpy ndarray

qstack.fields.decomposition.correct_N_atomic(mol, N, c0, metric='u')[source]

Corrects decomposition coefficients to match the target number of electrons per atom.

Uses Lagrange multipliers to enforce the correct number of electrons per atom while minimizing changes to the decomposition coefficients.

Parameters:
  • mol (pyscf Mole) – pyscf Mole object used for the computation of the density matrix.

  • N (numpy ndarray) – Target number of electrons per atom.

  • c0 (numpy ndarray) – 1D array of initial decomposition coefficients.

  • metric (str) – Metric type for correction (‘u’ for unit, ‘s’ for overlap, ‘j’ for coulomb). Defaults to ‘u’.

Returns:

Corrected decomposition coefficients (1D array).

Return type:

numpy ndarray

qstack.fields.decomposition.decompose(mol, dm, auxbasis)[source]

Fit molecular density onto an atom-centered basis.

Parameters:
  • mol (pyscf Mole) – pyscf Mole objec used for the computation of the density matrix.

  • dm (2D numpy array) – Density matrix.

  • auxbasis (string / pyscf basis dictionary) – Atom-centered basis to decompose on.

Returns:

  • copy of the pyscf Mole object with the auxbasis basis in a pyscf Mole object,

  • 1D numpy array containing the decomposition coefficients.

Return type:

Tuple containing

qstack.fields.decomposition.decomposition_error(self_repulsion, c, eri2c, eri3c, dm)[source]

Compute the decomposition error for optimal density fitting.

int int rho_DM(r1) 1/|r1-r2| rho_DF(r2) dr1 dr2

Parameters:
  • self_repulsion (float) – Self-repulsion energy from the original density matrix.

  • c (numpy ndarray) – 1D array of density expansion coefficients.

  • eri2c (numpy ndarray) – 2D array of 2-center ERIs.

  • eri3c (numpy ndarray) – 3D array of 3-center ERIs.

  • dm (numpy ndarray) – Density matrix.

Returns:

The decomposition error.

Return type:

float

Notes

  • If c are the optimal coefficients obtained from the density matrix, optimal_decomposition_error() can be used instead.

  • self_repulsion can be set to 0 to avoid expensive computations when only the relative error is needed.

qstack.fields.decomposition.get_coeff(dm, eri2c, eri3c, slices=None)[source]

Compute the density expansion coefficients.

Parameters:
  • dm (numpy ndarray) – Density matrix.

  • eri2c (numpy ndarray) – 2-centers ERI matrix.

  • eri3c (numpy ndarray) – 3-centers ERI matrix.

  • slices (optional numpy ndarray) – Assume that eri2c is bloc-diagonal, by giving the boundaries of said blocks.

Returns:

A numpy ndarray containing the expansion coefficients of the density onto the auxiliary basis.

Raises:

RuntimeError – If the slices argument is incorrectly formatted or inconsistent with the auxiliary basis size.

qstack.fields.decomposition.get_integrals(mol, auxmol)[source]

Compute overlap integrals and 2-/3-centers ERI matrices.

Parameters:
  • mol (pyscf Mole) – pyscf Mole object used for the computation of the density matrix.

  • auxmol (pyscf Mole) – pyscf Mole object of the same molecule with an auxiliary basis set.

Returns:

  • overlap matrix (auxmol.nao,auxmol.nao) for the auxiliary basis,

  • 2-centers ERI matrix (auxmol.nao,auxmol.nao) for the auxiliary basis,

  • 3-centers ERI matrix (mol.nao,mol.nao,auxmol.nao) between AO and auxiliary basis.

Return type:

Tuple of three numpy ndarray containing

qstack.fields.decomposition.get_self_repulsion(mol_or_mf, dm)[source]

Compute the self-repulsion of the density.

int int rho_DM(r1) 1/|r1-r2| rho_DM(r2) dr1 dr2

Parameters:
  • mol_or_mf (pyscf Mole or SCF) – pyscf Mole or Mean Field object.

  • dm (2D numpy ndarray) – Density matrix.

Returns:

Self-repulsion energy (a.u).

Return type:

float

qstack.fields.decomposition.optimal_decomposition_error(self_repulsion, c, eri2c)[source]

Compute the decomposition error for optimal density fitting.

int int rho_DM(r1) 1/|r1-r2| rho_DF(r2) dr1 dr2

Parameters:
  • self_repulsion (float) – Self-repulsion energy from the original density matrix.

  • c (numpy ndarray) – 1D array of density expansion coefficients.

  • eri2c (numpy ndarray) – 2D array of 2-center electron repulsion integrals.

Returns:

The decomposition error.

Return type:

float

Notes

  • It is assumed that c are the optimal coefficients obtained from the density matrix.

  • self_repulsion can be set to 0 to avoid expensive computations when only the relative error is needed.