Reduce duplicate code for calculating electrostic pair interaction