  In this paper, it is presented a novel strategy to optimize the determination
of magnetic couplings by using ab-initio calculations of the energy. This
approach allows determining efficiently, in terms of a proposed effective
magnetic spin model, an optimal set of magnetic configurations to be simulated
by DFT methods. Moreover, a procedure to estimate the values of the coupling
constants and their error bounds from the estimated energies is proposed. This
method, based on Monte Carlo sampling, takes into account the accuracy of the
ab - initio simulations. A strategy to refine models reusing previously
computed configuration energies is also presented. We apply the method to
determine a magnetic model for the recently synthesized material
Bi$_3$Mn$_4$O$_{12}$(NO$_3$). Finally, an open source software that implements
and automatizes the whole process is presented.
