  A method is developed to calculate the ligand field (LF) parameters and the
multiplet spectra of local magnetic centers with open $d$- and $f$-shells in
solids in a parameter-free way. This method proceeds from density functional
theory and employs Wannier projections of nonmagnetic band structures onto
local $d$- or $f$-orbitals. Energies of multiplets and optical, as well as
X-ray spectra are determined by exact numerical diagonalization of a local
Hamiltonian describing Coulomb, LF, and spin-orbit interactions. The method is
tested for several 3$d$- and 5$f$-compounds for which the LF parameters and
multiplet spectra are experimentally well known. In this way, we obtain good
agreement with experiment for La$_2$NiO$_4$, CaCuO$_2$, Li$_2$CuO$_2$, ZnO:Co,
and UO$_2$.
