Fitting of local densities in periodic systems