I'm attempting to make a Hartree-Fock solver, using Python, following Daniel Crawford's guide.
I have been successful with the first four steps. However, I am having some trouble with this part in step 5:
$$ F^0_c C^{'}_0 = C^{'}_0 \epsilon_0 $$
I have the correct transformed Fock matrix (I can verify this as the site as step-by-step matrices that you can check against). My problem is that the MO coefficient matrix I get does not quite match the one on the site. I obtain it by multiplying the above equation by $C^{' -1}_0$ on the right:
$$ F^0_c = C^{'}_0 \epsilon_0 C^{' -1}_0 $$
Now it's in diagonalized form, which means $C^{'}_0$, the transformed MO coefficients, is the eigenvectors of $F^0_c$ and $\epsilon_0$ is a diagonal matrix of the eigenvalues. After I obtain $C^{'}_0$, I obtain the original untransformed MO coefficients $C_0$ using the next equation on the site:
$$ C_0 = S^{-1/2} C^{'}_0 $$
where $S^{-1/2}$ is the transformation matrix used to get the transformed Fock matrix from earlier. My transformation matrix, by the way, matches exactly the one on the site.
This is where my problem comes in. The $C_0$ matrix I get is this:
The one the website has as a reference is this:
If you look carefully, you will notice that mine and the reference one have the same columns; however, some are swapped around, and some have sign flips. This causes problems with the next steps, such as finding the density matrix.
I thought maybe the order should be such that $\epsilon_0$ is in order. The $\epsilon_0$ matrix I get is indeed out of order, and the same permutations and sign flips that will make it in order also makes my $C_0$ match the reference one in terms of where each column is, but NOT sign. Sadly the reference site does not have a $\epsilon_0$ matrix or $C{'}_0$ for me to compare with, only the final $C_0$, so I'm not sure if those are coming out of order also.
My first question is, will these sign flips matter? Is ordering the $C_0$ matrix in terms of getting $\epsilon_0$ the right thing to do?
I am carrying out these matrix operations with basic NumPy functions such as numpy.linalg.eig
and numpy.dot
. Nothing fancy there. It's worth noting that finding the transformation matrix, $S^{-1/2}$, requires diagonalizing in a similar way, but I didn't have any column switching problems there. It came out exactly as expected.
My second question relates to building the density matrix at the end of step 5. The website has this equation:
$$ D^0_{\mu\nu} = \sum_{m}^{occ} (C_0)^m_\mu (C_0)^m_\nu $$
It says sum over the occupied MOs. The molecule being used in the example calculation is water, so two H's, and one O, so there are 10 electrons, so 5 orbitals. If I sum using the correct $C_0$ matrix I get on the reference website, from m = 1 to 5, I get the correct $D^0_{\mu\nu}$ result. However my textbook (Szabo and Ostlund, Modern Quantum Chemistry) has this equation (changing some of the notation to match):
$$ D^0_{\mu\nu} = 2 \sum_{m}^{N/2} (C_0)^m_\mu (C_0)^m_\nu $$
Where N is the number of electrons. Well, 10/5 is 5, so I'm summing from 1 to 5 again, but now there's a 2 in front, so the sum will be doubled. Now, using the one on the website gets me the correct answer, but what could this 2 in the book mean?