# Spin contamination

In computational chemistry, spin contamination is the artificial mixing of different electronic spin-states. This can occur when an approximate orbital-based wave function is represented in an unrestricted form – that is, when the spatial parts of α and β spin-orbitals are permitted to differ. Approximate wave functions with a high degree of spin contamination are undesirable. In particular, they are not eigenfunctions of the total spin-squared operator, Ŝ$^2$, but can formally be expanded in terms of pure spin states of higher multiplicities (the contaminants).

## Open-shell wave functions

Within Hartree–Fock theory, the wave function is approximated as a Slater determinant of spin-orbitals. For an open-shell system, the mean-field approach of Hartree–Fock theory gives rise to different equations for the α and β orbitals. Consequently, there are two approaches that can be taken – either to force double occupation of the lowest orbitals by constraining the α and β spatial distributions to be the same (restricted open-shell Hartree–Fock, ROHF) or permit complete variational freedom (unrestricted Hartree–Fock UHF). In general, an N-electron Hartree–Fock wave function composed of N$_α$ α-spin orbitals and N$_β$ β-spin orbitals can be written as
    $\Psi ^{\mathrm {HF} }(\mathbf {r} _{1}\sigma (1)\cdots \mathbf {r} _{N}\sigma (N))={\mathcal {A}}\left(\psi _{1}^{\alpha }(\mathbf {r} _{1}\alpha _{1})\cdots \psi _{N_{\alpha }}^{\alpha }(\mathbf {r} _{N_{\alpha }}\alpha _{N_{\alpha }})\psi _{N_{\alpha }+1}^{\beta }(\mathbf {r} _{N_{\alpha }+1}\beta _{N_{\alpha }+1})\cdots \psi _{N}^{\beta }(\mathbf {r} _{N}\beta _{N})\right).$
where ${\mathcal {A}}$ is the antisymmetrization operator. This wave function is an eigenfunction of the total spin projection operator, Ŝ$_z$, with eigenvalue (N$_α$ − N$_β$)/2 (assuming N$_α$ ≥ N$_β$). For a ROHF wave function, the first 2N$_β$ spin-orbitals are forced to have the same spatial distribution:
    $\psi _{j}^{\alpha }(\mathbf {r} _{j})=\psi _{N_{\alpha }+j}^{\beta }(\mathbf {r} _{N_{\alpha }+j}),\ \ \ 1\leq j\leq N_{\beta }.$
There is no such constraint in an UHF approach.

## Contamination

The total spin-squared operator commutes with the nonrelativistic molecular Hamiltonian, so it is desirable that any approximate wave function is an eigenfunction of Ŝ$^2$. The eigenvalues of Ŝ$^2$ are S(S + 1), where S is the spin quantum number of the system and can take the values 0 (singlet), 1/2 (doublet), 1 (triplet), 3/2 (quartet), and so forth. The Ŝ$^2$ eigenvalues of the most common spin multiplicities are listed below.
Spin quantum numbers, spin multiplicities and Ŝ$^2$ eigenvalues :
| Spin quantum number S | Spin multiplicity 2S+1 | Ŝ$^2$ eigenvalue S(S+1) |
| 0 | 1 (singlet) | 0.00 |
| 1/2 | 2 (doublet) | 0.75 |
| 1 | 3 (triplet) | 2.00 |
| 3/2 | 4 (quartet) | 3.75 |
| 2 | 5 (quintet) | 6.00 |
| 5/2 | 6 (sextet) | 8.75 |
| 3 | 7 (septet) | 12.00 |
| 7/2 | 8 (octet) | 15.75 |
| 4 | 9 (nonet) | 20.00 |

### Calculating ⟨Ŝ²⟩ for arbitrary Slater determinants

The Ŝ² operator can be decomposed as:
    ${\hat {S}}^{2}={\hat {S}}_{z}+{\hat {S}}_{z}^{2}+{\hat {S}}_{-}{\hat {S}}_{+}$
Slater determinants have well-defined spin projections:
$\langle {\hat {S}}_{z}\rangle =m_{s}={\frac {N_{\alpha }-N_{\beta }}{2}}\quad$ $\quad \langle {\hat {S}}_{z}^{2}\rangle =m_{s}^{2}=\left({\frac {N_{\alpha }-N_{\beta }}{2}}\right)^{2}$
${\hat {S}}_{-}{\hat {S}}_{+}$ can be expressed in terms of individual electron operators: ${\hat {S}}_{-}{\hat {S}}_{+}=\sum _{i}{\hat {s}}_{-}(i)\sum _{j}{\hat {s}}_{+}(j)$.
For an Unrestricted Hartree-Fock (UHF) wavefunction, the expectation value Ŝ$^2$ is
    $\langle \Phi _{\mathrm {UHF} }|{\hat {S}}^{2}|\Phi _{\mathrm {UHF} }\rangle ={\frac {N_{\alpha }-N_{\beta }}{2}}+\left({\frac {N_{\alpha }-N_{\beta }}{2}}\right)^{2}+N_{\beta }-\sum _{i}^{N_{\alpha }^{\mathrm {occupied} }}\sum _{j}^{N_{\beta }^{\mathrm {occupied} }}|\langle \psi _{i}^{\alpha }|\psi _{j}^{\beta }\rangle |^{2}$
where the first two terms follow directly from the decomposition of Ŝ², the third term corresponds to the diagonal contribution of ${\hat {S}}_{-}{\hat {S}}_{+}$ and the last term involves the overlap between the $\alpha$ and $\beta$ spin-orbitals with the negative sign arising from the antisymmetry of the Hartree-Fock wavefunction.
For Slater determinants constructed from restricted spin-orbitals, the spatial parts of corresponding $\alpha$ and $\beta$ orbitals are the same, thus the $\alpha$ and $\beta$ overlaps evaluate to 1 for $i=j$ and 0 otherwise. This simplifies to:
    ${\begin{aligned}\langle \Phi _{\mathrm {restricted} }|{\hat {S}}^{2}|\Phi _{\mathrm {restricted} }\rangle &={\frac {N_{\alpha }-N_{\beta }}{2}}+\left({\frac {N_{\alpha }-N_{\beta }}{2}}\right)^{2}+N_{\beta }-\sum _{i}^{N_{\alpha }^{\mathrm {occupied} }}\sum _{j}^{N_{\beta }^{\mathrm {occupied} }}\delta _{ij}\\&={\frac {N_{\alpha }-N_{\beta }}{2}}+\left({\frac {N_{\alpha }-N_{\beta }}{2}}\right)^{2}+N_{\beta }-N_{\beta }^{\mathrm {paired} }\\&={\frac {N_{\alpha }-N_{\beta }}{2}}+\left({\frac {N_{\alpha }-N_{\beta }}{2}}\right)^{2}+N_{\beta }^{\mathrm {unpaired} }\end{aligned}}$
In Restricted open-shell Hartree-Fock (ROHF), all unpaired electrons have the same spin, yielding:
    $\langle \Phi _{\mathrm {ROHF} }|{\hat {S}}^{2}|\Phi _{\mathrm {ROHF} }\rangle =|m_{s}|+m_{s}^{2}=S(S+1)$
making ROHF wavefunctions eigenfunctions of Ŝ².

#### Multi-configurational wavefunctions

For multi-configurational wavefunctions expressed as $|\Psi \rangle =\sum _{I}c_{I}|\Phi _{I}\rangle$ with $\Phi _{I}$ being Slater determinants, ⟨Ŝ²⟩ is :
$\langle \Psi |{\hat {S}}^{2}|\Psi \rangle =\sum _{I,J}c_{I}^{*}c_{J}\langle \Phi _{I}|{\hat {S}}^{2}|\Phi _{J}\rangle$.
The diagonal terms $\langle \Phi _{I}|{\hat {S}}^{2}|\Phi _{I}\rangle$ are calculated as above, while cross-terms $\langle \Phi _{J}|{\hat {S}}^{2}|\Phi _{I}\rangle$ (where I≠J) require computing $\langle \Phi _{J}|{\hat {S}}_{-}{\hat {S}}_{+}|\Phi _{I}\rangle$ using individual electron operators. $\langle \Phi _{J}|{\hat {S}}_{z}|\Phi _{I}\rangle$ and $\langle \Phi _{J}|{\hat {S}}_{z}^{2}|\Phi _{I}\rangle$ vanish when I≠J.

### Measuring spin contamination

The sum of the last two terms in the UHF equation is a measure of the extent of spin contamination in the unrestricted Hartree–Fock approach and is always non-negative – the wave function is usually contaminated to some extent by higher order spin eigenstates unless a ROHF approach is taken. Therefore, the deviation of the UHF expectation value of Ŝ$^2$ from the exact Ŝ$^2$ eigenvalue as would be expected from the spin multiplicity (see the table above) is usually taken as a measure of the severity of the spin contamination. Naturally, there is no contamination if all electrons are the same spin. Also, there is often (but not always, as in open-shell singlets) no contamination if the number of α and β electrons is the same. A small basis set could also constrain the wavefunction sufficiently to prevent spin contamination.
Such contamination is a manifestation of the different treatment of α and β electrons that would otherwise occupy the same molecular orbital. It is also present in Møller–Plesset perturbation theory calculations that employ an unrestricted wave function as a reference state (and even some that employ a restricted wave function) and, to a much lesser extent, in the unrestricted Kohn–Sham approach to density functional theory using approximate exchange-correlation functionals.

## Elimination

Although the ROHF approach does not suffer from spin contamination, it is less commonly available in quantum chemistry computer programs. Given this, several approaches to remove or minimize spin contamination from UHF wave functions have been proposed.
The annihilated UHF (AUHF) approach involves the annihilation of first spin contaminant of the density matrix at each step in the self-consistent solution of the Hartree–Fock equations using a state-specific Löwdin annihilator. The resulting wave function, while not completely free of contamination, dramatically improves upon the UHF approach especially in the absence of high order contamination.
Projected UHF (PUHF) annihilates all spin contaminants from the self-consistent UHF wave function. The projected energy is evaluated as the expectation of the projected wave function.
The spin-constrained UHF (SUHF) introduces a constraint into the Hartree–Fock equations of the form λ(Ŝ$^2$ − S(S + 1)), which as λ tends to infinity reproduces the ROHF solution.
All of these approaches are readily applicable to unrestricted Møller–Plesset perturbation theory.

## Density functional theory

Although many density functional theory (DFT) codes simply calculate spin-contamination using the Kohn-Sham orbitals as if they were Hartree-Fock orbitals, this is not necessarily correct. The unrestricted Kohn-Sham (UKS) wavefunction of a spin-pure electronic state may have a Ŝ$^2$ expectation value that is inconsistent with a spin-pure state, if it is calculated using the UHF formula. Therefore, the benefits of using a restricted open-shell treatment over an unrestricted one is smaller in a DFT context than in HF. In particular, the exact spin density of the S$_z$=S spin-component of an open-shell molecule generally adopts negative values in small parts of the real space due to spin polarization, but a restricted open-shell Kohn-Sham (ROKS) treatment necessarily gives non-negative spin density everywhere, which proves that, in general, only UKS can possibly give the exact spin density of a system. In practical calculations, the energy error of an unrestricted DFT calculation due to spin contamination can sometimes be remedied by a spin projection approach, particularly if the spin contamination is large (e.g. when there is antiferromagnetic coupling in the system). However, for moderate spin contamination, spin projection may actually be counterproductive, and create unphysical cusps (i.e. derivative discontinuities) on potential energy curves.
On the other hand, in TDDFT calculations, one frequently observes severe spin contamination in the excited states, even if the ground state is described by ROKS (i.e. even when the ground state itself is not spin contaminated). This is because the single excitations out of an open-shell reference state (usually the ground state) do not span a spin-complete manifold, i.e. it is impossible to unitarily transform the set of all single excitations of an open-shell reference state, such that all of the transformed states are eigenstates of the Ŝ$^2$ operator. The excited state 〈Ŝ$^2$〉 values of a TDDFT calculation of an open-shell state can have a maximum error of 2 when the ground state is described by ROKS, and sometimes slightly larger than 2 when the ground state is described by UKS. To eliminate the excited state spin contamination in TDDFT, spin-adapted TDDFT methods must be used, which either explicitly or implicitly include some double excitations and thereby go beyond the adiabatic approximation of the TDDFT response kernel. Spin-adapted TDDFT methods not only improve the prediction of absorption spectra, but also improve the prediction of the fluorescence spectra and excited state relaxation pathways of open-shell molecules.