Permanent magnets are a key technology for modern society with applications in air conditioning, mobility or power generation. The measured coercive fields in modern permanent magnets reach only a small fraction of the theoretical values. A series of experimental studies have shown that discontinuities and misalignment at the atomic scale significantly affect the macroscopic coercivity. In this project, we develop a quantitative theory of coercivity, taking into account the local atomic structure, the spatial variation of the intrinsic magnetic properties, and the physical microstructure of the magnet. To achieve this goal we bridge the length scale between ab-initio simulations, atomistic spin dynamics and continuum micromagnetic simulations. Atomic defects at interfaces and grain boundaries will be considered already at the smallest possible length scale, the unit cells of the material composition. The developed theory is guided by well described magnetic materials to validate the system throughout the progress of the project.