Phase transition and magnetic properties of Mg-doped hexagonal close-packed Ni nanoparticles