Ab initio study of the structural properties of magnesium