I am implementing a Hartree-Fock SCF program with an educational purpose. Although the code works fine using a Core Hamiltonian guess for the SCF iterative process, I want to implement a more accurate initial guess, so I have programmed a simple Extended Hückel guess using a minimal basis set (MINI) and the parameters used by the GAMESS-US software as the diagonal elements of the matrix. This guess works fine for Hartree-Fock SCF calculations using minimal basis sets, but I want to generalize it for any type of basis set (my code support some split-valence basis sets, such as 3-21G). The manuals of some popular quantum chemistry packages state that the density matrix guess obtained using the Extended Hückel Method can be projected onto the desired basis set, but not explaining explicitly how it's done. After some search, I've found that the pyscf package implements a function called project_dm_nr2nr()
which does exactly what I'm looking for. The guide of the program (https://pyscf.org/pyscf_api_docs/pyscf.scf.html) states that the projection is done using the equation:
$$
D_{AO2}=PD_{AO1}P^T
$$
with
$$
P=S^{-1}_{AO2}\langle AO2|AO1\rangle
$$
where $D_{AO2}$ is the electronic density matrix expressed in the new atomic orbital basis,$D_{AO1}$ is the density matrix expressed in the minimal basis set (in which the extended Hückel calculation has been done), $S^{-1}_{AO2}$ is the inverse of the overlap matrix of the new basis set and $\langle AO2|AO1\rangle$ is the overlap matrix between the two basis sets.
Although I've been searching information about the topic, I haven't found any information about where this formula(in textbooks about quantum chemistry nor the Internet) comes from and I wouldn't like to implement something that I don't understand in my program.I suspect that it is a basic question and I lack the mathematical knowledge for deriving the formula.Could you help me deriving this equation?