Theoretical study of the phase transitions and electronic structure of (Zr0.5, Mg0.5)N and (Hf0.5, Mg0.5)N