Calculating spin-lattice interactions in ferro- and antiferromagnets