An expression is derived for the total energy of a system of interacting atoms based on an ansatz for the total electron density of the system as a superposition of atom densities taken from calculations for the atoms embedded in a homogeneous electron gas. This leads to an expression for the interaction energy in terms of the embedding energy of the atoms in a homogeneous electron gas, and corrections accounting, for instance, for the d-d hybridization in the transition metals. The density of the homogeneous electron gas is chosen as the average of the density from the surrounding atoms. Due to the variational property of the total-energy functional, the errors in the interaction energy are second order in the deviation of the ansatz densi...