Optimization of Densities in Hartree-Fock and