# Residual minimization method¶

## Algorithm¶

1. Initial guess for wave functions ($$\tilde{\psi}_n$$).

2. Orthogonalize wavefunctions (make sure $$\langle \tilde{\psi}_n | \hat{S} | \tilde{\psi}_m \rangle = \delta_{nm}$$).

3. Calculate density ($$\tilde{n}$$, $$D_{ij}^a$$).

4. Calculate potential ($$\tilde{v}$$, $$\Delta H_{ij}^a$$).

5. Apply hamiltonian ($$\hat{H}\tilde{\psi}_n$$).

6. Subspace diagonalization (rotate $$\tilde{\psi}_n$$ so that $$\langle \tilde{\psi}_n | \hat{H} | \tilde{\psi}_m \rangle = \delta_{nm} \epsilon_n$$).

7. Calculate residuals ($$R_n = \hat{H}\tilde{\psi}_n - \epsilon_n \hat{S}\tilde{\psi}_n$$).

8. Improve wave functions using the RMM-DIIS algorithm (see below).

9. Back to (2).

## RMM-DIIS step¶

For each wave function we calculate the residual:

$R_n = (\hat{H} - \epsilon_n \hat{S}) \tilde{\psi}_n$

New improved wave function: $$\tilde{\psi}_n' = \tilde{\psi}_n + \lambda \hat{P} R_n$$, where $$\hat{P}$$ is a preconditioner. Find step length $$\lambda$$ by minimizing the norm of:

$R_n' = (\hat{H} - \epsilon_n \hat{S}) \tilde{\psi}_n'$

Since we already have $$R_n'$$, we might as well use it to take an extra step (with the same step length as for the first step):

$\tilde{\psi}_n \leftarrow \tilde{\psi}_n' + \lambda \hat{P} R_n' = \tilde{\psi}_n + \lambda \hat{P} R_n + \lambda \hat{P} R_n'$

See [Kresse96] for details.

## Preconditioning¶

The ideal preconditioner would be:

$\hat{P} = -(\hat{H} - \epsilon_n \hat{S})^{-1}.$

For the short wavelength parts of the residuals, $$\hat{H} - \epsilon_n \hat{S}$$ will be dominated by the kinetic energy operator, so we have approximately $$\hat{P} \simeq -\hat{T}^{-1}$$.

We calculate preconditioned residuals ($$\tilde{R}_n = \hat{P} R_n$$) by solving $$\hat{T} \tilde{R}_n = -R_n$$ or equivalently

$\frac{1}{2} \nabla^2 \tilde{R}_n = R_n$

approximately using multigrid techniques as described in [Briggs95].