Diffraction analysis of elastic and inelastic scattering by magnesium