Structural and functional comparison of magnesium transporters throughout evolution