integrate nearest neighbour calculations