  A first-principles theory of resonant magnetic scattering of x rays is
presented. The scattering amplitudes are calculated using a standard
time-dependent perturbation theory to second order in the electron-photon
interaction vertex. In order to calculate the cross section reliably an
accurate description of the electronic states in the material under
investigation is required and this is provided by the density functional theory
(DFT) employing the Local Spin Density Approximation combined with the
self-interaction corrections (SIC-LSD). The magnetic x-ray resonant scattering
(MXRS) theory has been implemented in the framework of the relativistic
spin-polarized LMTO-ASA band structure calculation method. The theory is
illustrated with an application to ferromagnetic praseodymium. It is shown that
the theory quantitatively reproduces the dependence on the spin and orbital
magnetic moments originally predicted qualitatively (Blume, J. Appl. Phys, {\bf
57}, 3615 (1985)) and yields results that can be compared directly with
experiment.
