Rationalizing the structural changes and spectra of manganese and their temperature dependence in a series of garnets with first-principles calculations