Spectral quadrature for the first principles study of crystal defects: Application to magnesium