The crystal-field (CF) model is a well established phenomenological way of describing the excitation spectrum and many related properties of localized rare-earth 4f electrons in condensed matter. Beyond phenomenology, effective ionic point charges can be used to approximate reasonably the electronic multipole interaction of the 4f shell with the surrounding atoms in insulators. In contrast, in the case of metallic systems the complete spatial charge distribution has to be considered, which can be derived from density-functional calculations. Ail of the artificial constraints on the 4f charge density employed in earlier density-functional CF calculations can be avoided by taking into account self-interaction corrections for the 4f states. In this way, all the CF parameters of the hard magnetic compound SmCo5 were recalculated and compared with experimental data. In particular, the spatial origin of the crystal electric field in this compound was analyzed.