square lattice with lattice constant $a$, the Wannier center can be set to ${\mathbf{r}}_{0}={\mathbf{R}}$ (on-site) or ${\mathbf{r}}_{0}={\mathbf{R+T}}$ (between), where ${\mathbf{T}}=(0.5a,0.5a)$.

![Second moments $\mathcal{S}_n$ (inverse locality) of the Wannier functions in the $n$th band, minimized by using the conjugate gradient method. Four different, randomly chosen initial sets of Bloch phases, A, B, C, D, were used for the CG optimization. Top: Sq-D crystal, TM polarization. Bottom: Tr-D crystal, TE polarization.[]{data-label="fig:cg_results_sm"}](sm){width="0.95\columnwidth"}

Conjugate gradient method
-------------------------

The commonly adopted way of finding maximally localized Wannier functions is to minimize the corresponding second moment $\mathcal S_n$ with respect to the set of Bloch phases $\phi_{n{\mathbf{k}}}$ in the $n$th band. Note that, by definition of the SM, the regions far away from the Wannier center (where the Wannier functions usually have an increasingly complex structure) contribute to the SM with quadratically increasing weight. For this optimization we first apply a standard conjugate gradient (CG) method. This method tends to get trapped in the local extrema and, hence, requires a careful choice of the initial set of Bloch phases [@john]. In figure \[fig:cg\_results\_sm\] representative examples of the locality of the SM-optimized Wannier functions are shown for Sq-D (TM polarization) and Tr-D (TE polarization) structures. Here and 