Origin and ab initio evaluation of magnetic interactions in rare earth intermetallics