  A first-principles approach combining density functional and dynamical
mean-field theories in conjunction with a quasi-atomic approximation for the
strongly localized 4$f$ shell is applied to Nd$_{2}$Fe$_{14}$B-based hard
magnets in order to evaluate crystal-field and exchange-field parameters at
rare-earth sites and their corresponding single-ion contribution to the
magnetic anisotropy. In pure Nd$_2$Fe$_{14}$B, our calculations reproduce the
easy-cone to easy axis transition; theoretical magnetization curves agree
quantitatively with experiment. Our study reveals that the rare-earth
single-ion anisotropy in the "2-14-1" structure is strongly site-dependent,
with the $g$ rare-earth site exhibiting a larger value. In particular, we
predict that increased $f$ and $g$-site occupancy of $R=$ Ce and Dy,
respectively, leads to an increase of the magnetic anisotropy of the
corresponding (Nd,$R$)$_{2}$Fe$_{14}$B substituted compounds.
