Influence of a transition metal atom on the geometry and electronic structure of Mg and Mg–H clusters