  Magnetic rare-earth orthoferrites $R$FeO$_3$ host a variety of functional
properties from multiferroicity and strong magnetostriction, to
spin-reorientation transitions and ultrafast light-driven manipulation of
magnetism, which can be exploited in spintronics and next-generation devices.
Among these systems, SmFeO$_3$ is attracting a particular interest for its rich
phase diagram and the high temperature Fe-spin magnetic transitions, which
combines with a very low temperature and as yet unclear Sm-spin ordering.
Various experiments suggest that the interaction between the Sm and Fe magnetic
moments (further supported by the magnetic anisotropy), is at the origin of the
complex cascade of transitions, but a conclusive and clear picture has not yet
been reached. In this work, by means of comprehensive first-principles
calculations, we unravel the role of the magnetic Sm ions in the Fe-spin
reorientation transition and in the detected anomalies in the lattice
vibrational spectrum, which are a signature of a relevant spin-phonon coupling.
By including both Sm-$f$ electrons and non-collinear magnetism, we find
frustrated and anisotropic Sm interactions, and a large magnetocrystalline
anisotropy mediated by the SOC of the Sm-$4f$ electrons, which drive the
complex magnetic properties and phase diagram of SmFeO$_3$.
