  A method to simulate local properties and processes in crystals with
impurities via constructing cluster models within the frame of the
compound-tunable embedding potential (CTEP) and highly-accurate {\it ab initio}
relativistic molecular-type electronic structure calculations is developed and
applied to the Ce and Th-doped yttrium orthophosphate crystals, YPO$_4$, having
xenotime structure. Two embedded cluster models are considered, the "minimal"
one, YO$_8$@CTEP$_{\rm min}$, consisting of the central Y$^{3+}$ cation and its
first coordination sphere of eight O$^{2-}$ anions (i.~e.\ with broken P--O
bonds), and its extended counterpart, Y(PO$_4$)$_6$@CTEP$_{\rm ext}$, implying
the full treatment of all atoms of the PO$_4^{3-}$ anions nearest to the
central Y$^{3+}$ cation. CTEP$_{\rm min,ext}$ denote here the corresponding
cluster environment described within the CTEP method. The relativistic
Fock-space coupled cluster (FS RCC) theory is applied to the minimal cluster
model to study electronic excitations localized on Ce$^{3+}$ and Th$^{3+}$
impurity ions. Calculated transition energies for the cerium-doped xenotime are
in a good agreement with the available experimental data (mean absolute
deviation of ca.0.3 eV for $4f{\to}5d$ type transitions). For the thorium-doped
crystal the picture of electronic states is predicted to be quite complicated,
the ground state is expected to be of the $6d$ character. The uncertainty for
the excitation energies of thorium-doped xenotime is estimated to be within
0.35 eV. Radiative lifetimes of excited states are calculated at the FS RCC
level for both doped crystals. The calculated lifetime of the lowest $5d$ state
of Ce$^{3+}$ differs from the experimentally measured one by no more than
twice.
