A variational formulation of the polarizable continuum model