def electrostatic_energy_dict(E, slicing):
    """
    Dictionary of the electrostatic energies starting from a slicing
    defining the blocks of atom to be considered

    Args:
        E (matrix): electrostatic_energies_matrix of the atoms
        slicing (dict): slicing of the fragments, given for example
            by `py:meth:~BigDFT.Systems.System.dataframe_slicing`
    Returns:
        dict: dictionary of the electrostatic interaction per blocks
    """
    eldict = {}
    for frag1 in slicing:
        for frag2 in slicing:
            if frag2 in eldict and frag1 in eldict[frag2]:
                e = eldict[frag2][frag1]
            else:
                s1, e1 = slicing[frag1]
                s2, e2 = slicing[frag2]
                e = E[s1:e1, s2:e2].sum()
                # E[group1][:, group2].sum() useful for non-contiguous
            eldict.setdefault(frag1, {})[frag2] = e
    return eldict