Replica derivation of Sompolinsky free energy functional for mean field spin glasses