Local stresses and elastic constants at the atomic scale