## 6 Methodology for First-Principles Studies of Localization
### From DFT to the EDHM
Specifically, the difference between the single impurity and pure Hamiltonian is taken to derive the single-impurity potential: \(V^{(x_{j})}=H^{(x_{j})}-H^{0}\). To remove the influence of the periodically repeated impurities in the single-impurity supercell calculation a partitioning procedure is necessary. A detailed account of this procedure is given in [202]. From single-impurity potential the effective Hamiltonian of a disordered impurity configuration with \(N\) impurities can be assembled as follows: \(H^{(x_{1},\ldots,x_{N})}_{\rm eff}=H^{0}+\sum_{j=1}^{N}V^{(x_{j})}\). To illustrate the accuracy and efficiency of the EDHM we present in Figure 29 a comparison of spectral functions for a K\({}_{4}\)Fe\({}_{8}\)Se\({}_{10}\) supercell calculated from the full DFT and the effective Hamiltonian. The size of the deviations between the spectral functions obtained from the full DFT and the EDHM should be compared with the size of the impurity-induced changes. For this purpose, the spectral function of the undoped KFe\({}_{2}\)Se\({}_{2}\) is also plotted as a reference. As can be seen from Figure 29, the effective Hamiltonian describes the influence of the Fe and K vacancies with high accuracy. All the detailed gap openings and shadow bands induced by the vacancies are captured. However, the basis set of Linear Augmented Plane Waves (LAPW's) used in the full DFT is \(\sim\)30 times larger than the basis set of Wannier functions used in the EDHM. This reduction in the size of the basis set dramatically improves the efficiency of model-based calculations, especially when combined with model solvers such as the TMDCA. Many more benchmarks can be found in the supplementary materials of Ref. [192; 198; 199; 200] demonstrating the high accuracy and efficiency of the method. In addition to chemical disorder it is also possible to take into account the influence of magnetic disorder by mapping the DFT onto a generalized spin-fermion model as we describe below. This is relevant for dilute magnetic semiconductors in which a strongly interacting impurity is embedded into a weakly interacting host. In practice, the generalized spin-fermion model is derived as follows. First we perform spin-DFT (using for example an LDA+U [203; 204] exchange correlation functional). Then we perform a Wannier transformation of the low-energy bands by projecting only the host orbitals and not the impurity orbitals. This effectively integrates out the charge degrees of freedom corresponding to the impurity. For example in the case of Ga\({}_{1-x}\)Mn\({}_{x}\)N [205] we project only on the N\(-sp\)3 host orbitals thereby integrating out the charge degrees of freedom of the strongly interacting Mn-\(d\) impurity orbitals. Next, one derives the impurity potential in each of the two spin-channels resulting in \(V^{x_{j}}_{\uparrow}\) and \(V^{x_{j}}_{\downarrow}\) corresponding to the impurity at site \(x_{j}\). In the generalized spin-fermion model the impurity potential is given by:  
\[V^{x_{j}}=\sum_{{\bf i}^{\prime}nn^{\prime}}\left(T^{nn^{\prime}}_{{\bf i}^{ \prime}}c^{\dagger}_{{\bf i}nn^{\prime}}c_{{\bf i}^{\prime}n^{\prime}}+J^{nn^ {\prime}}_{{\bf j}^{\prime}}c^{\dagger}_{{\bf i}n^{\prime}}\mathbf{\tau_{op^{ \prime}}}c_{{\bf i}^{\prime}n^{\prime}}\cdot\mathbf{S_{\bf j}}\right) \tag{82}\]  
which incorporates the effect of the strong Coulomb repulsion at the impurity site. As usual, \(c_{{\bf i}n^{\prime}}\) (\(c^{\dagger}_{{\bf i}nc}\)) annihilates (creates) an electron with spin \(\sigma\) in unit-cell \(r_{i}\) in the \(n\)-th host orbital. \(\mathbf{\tau_{op^{\prime}}}\) and \(\mathbf{S_{\bf j}}\) are the Pauli matrices and the spin-vector operator. The non-magnetic and magnetic coefficients are determined \(T_{\rm\mu\
u}^{nn^{\prime}}=\langle r_{i}n|V_{\uparrow}^{x_{j}}+V_{\downarrow}^{x_{ j}}|r_{j^{\prime}}n^{\prime}\rangle\) and \(\int_{\rm\mu\
u}^{nn^{\prime}}=\langle r_{i}n|V_{\uparrow}^{x_{j}}-V_{\downarrow} ^{x_{j}}|r_{j^{\prime}}n^{\prime}\rangle\) respectively.