  The link between the crystal distortions of the perovskite structure and the
magnetic exchange interaction, the single-ion anisotropy (SIA) and the
Dzyaloshinsky-Moriya (DM) interaction are investigated by means of
density-functional calculations. Using BiFeO$_3$ and LaFeO$_3$ as model
systems, we quantify the relationship between the oxygen octahedra rotations,
the ferroelectricity and the weak ferromagnetism (wFM). We recover the fact
that the wFM is due to the DM interaction induced by the oxygen octahedra
rotations. We find a simple relationship between the wFM, the oxygen rotation
amplitude and the ratio between the DM vector and the exchange parameter such
as the wFM increases with the oxygen octahedra rotation when the SIA does not
compete with the DM forces induced on the spins. Unexpectedly, we also find
that, in spite of the $d^5$ electronic configuration of Fe$^{3+}$, the SIA is
very large in some structures and is surprisingly strongly sensitive to the
chemistry of the $A$-site cation of the $A$BO$_3$ perovskite. In the ground
$R3c$ state phase we show that the SIA shape induced by the ferroelectricity
and the oxygen octahedra rotations are in competition such as it is possible to
tune the wFM "on" and "off" through the relative size of the two types of
distortion.
