We put forward a scheme to study the anisotropic magnetic couplings in Sr 2 IrO 4 by mapping fully relativistic constrained noncollinear density functional theory including an on-site Hubbard U correction onto a general spin model Hamiltonian. This procedure allows for the simultaneous account and direct control of the lattice, spin and orbital interactions within a fully ab initio scheme. We compute the isotropic, single site anisotropy and Dzyaloshinskii-Moriya (DM) coupling parameters, and clarify that the origin of the canted magnetic state in Sr 2 IrO 4 arises from the interplay between structural distortions and the competition between isotropic exchange and DM interactions. A complete magnetic phase diagram with respect to the tetragonal distortion and the rotation of IrO 6 octahedra is constructed, revealing the presence of two types of canted to collinear magnetic transitions: a spin-flop transition with increasing tetragonal distortion and a complete quenching of the basal weak ferromagnetic moment below a critical octahedral rotation.In weak ferromagnetic materials the subtle interplay among different types of magnetic interactions can cause the formation of complex canted spin structures involving the so-called Dzyaloshinskii-Moriya (DM) effect, arising from the coupling between the spin and orbital angular momenta [1,2]. Intense research was done in this field in the last few years, motivated by the foreseeable applications in storage technology and by the air of mystery enveloping the quantum-mechanical origin of DM structures [3][4][5][6]. A crucial aspect of the DM systems is the entanglement between structural distortions and magnetism, which could be exploited as a way to tune the spin texture by modifying the structure upon external stimuli such as pressure and strain [4,7,8].The cross coupling between the different electronic, lattice and spin degrees of freedom is particulary rich in iridates. Here, the spin-orbit coupling (SOC), electron-electron correlations, and spin-exchange interactions operate with comparable strengths and gives rise to a large variety of exotic states [9][10][11][12][13][14][15]. The most striking example of this class of materials is the layered perovskite Sr 2 IrO 4 , characterized by a novel relativistic Mott insulating state [10-12, 16, 17] and an unusual in-plane canted antiferromagnetism (AFM) with a weak net ferromagnetic (FM) component [4,18]. The small electronic gap (≈ 0.3 eV [17]) is opened by modest Hubbard interactions (U ≈ 1.5-2 eV [19]) and by the strong spin-orbit coupling (ξ soc ≈ 0.5 eV [20]) which effectively narrows the d orbital bandwidth and give rise to an ideal J eff =1/2-like state [10,21,22]. This is considered to be robust despite the presence of noncubic structural distortions [23]. Neutron diffraction experiments indicate that the IrO 6 octahedra are rotated by α =11.5• and elongated in the c direction (c/a ≈ 1.04) [24], generating the enlarged √ 2a ×2c I4 1 /acd tetragonal cell shown in Fig. 1(a). The spins, coupled with the orbital mome...