Changed to contact.atom_distance for calculation.

Also this has the effect of removing triple nested for
loop to one loop