Solution (source code)

= Solution

Define $h_{pq}=\langle p|\hat h|q\rangle$, the one-electron kinetic plus nuclear-attraction integral, and physicists' two-electron integrals
$$
\langle pq|rs\rangle=\iint\phi_p(1)\phi_q(2)
\frac1{r_{12}}\phi_r(1)\phi_s(2)\,d1\,d2
$$
in <atomic units>. With $E_{\rm NN}$ the zero-electron nuclear-repulsion term, the <Slater determinant> expectation is
$$
E_0=E_{\rm NN}+\sum_i h_{ii}
+\frac12\sum_{ij}\bigl(\langle ij|ij\rangle-\langle ij|ji\rangle\bigr).
$$
The occupied sums include spin-orbitals, so the exchange integral vanishes for incompatible spins without needing a separate closed-shell factor.