%!TEX root=./user_guide.tex
\chapter{\label{chap:interpolation}Some notes on the interpolation}

In \wannier{} v.2.1, a new flag {\tt use\_ws\_distance} has been 
introduced (and it is set to {\tt .true.} by default since
version v3.0). Setting it to {\tt .false.} reproduces the 
``standard'' behavior of \wannier{} in v.2.0.1 and earlier,
while setting it to {\tt .true.} changes the interpolation method
as described below. In general, this allows a smoother interpolation,
helps reducing (a bit) the number of $k-$points required for interpolation,
and reproduces the band structure of large supercells sampled at $\Gamma$ 
only (setting it to {\tt .false.} produces instead flat bands, which 
might instead be the intended behaviour for small molecules carefully
placed at the centre of the cell).

The core idea rests on the fact that the Wannier functions $w_{n\bvec{R}}(\bvec{r})$
that we build from $N\times M\times L$ $k-$points are actually periodic 
over a supercell of size $N\times M\times L$, but when you use 
them to interpolate you want them to be \emph{zero} outside this supercell. 
In 1D it is pretty obvious want we mean here, but in 3D what you really 
want that they are zero outside the Wigner--Seitz cell of the 
$N\times M\times L$ superlattice.

The best way to impose this condition is to check that every real-space 
distance that enters in the $R\to k$ Fourier transform is the shortest possible 
among all the $N\times M\times L-$periodic equivalent copies. 

If the distances were between unit cells, this would be trivial, but the 
distances are between Wannier functions which are not centred on $\bvec R=0$. 
Hence, when you want to consider the matrix element of a generic operator $\bvec O$
(i.e., the Hamiltonian)  $\langle w_{i\bvec 0}(\bvec{r})|\bvec{O}|w_{j\bvec{R}}(\bvec{r})\rangle$ 
you must take in account that the centre $\bvec{\tau}_i$ of $w_{i\bvec 0}(\bvec{r})$ may 
be very far away from $\bvec{0}$ and the centre $\bvec{\tau}_j$ of $w_{j\bvec{R}}(\bvec{r})$
may be very far away from $\bvec{R}$.

There are many way to find the shortest possible distance between $w_{i\bvec{0}}(\bvec{r})$ and 
$w_{j\bvec{R}}(\bvec{r}-\bvec{R})$, the one used here is to consider the distance
$\bvec{d}_{ij\bvec{R}} = \bvec{\tau}_i - (\bvec{\tau}_j+\bvec{R})$
and all its superlattice periodic equivalents
$\bvec{d}_{ij\bvec{R}}+ \bvec{\tilde R}_{nml}$, with 
$\bvec{\tilde R}_{nml} = (Nn\bvec{a}_1 + Mm\bvec{a}_2 + Ll\bvec{a}_3)$
and $n,l,m = {-L,-L+1,...0,...,L-1,L}$, with $L$ controlled by the parameter {\tt ws\_search\_size}.

Then,
\begin{enumerate}
\item if $\bvec{d}_{ij\bvec{R}}+ \bvec{\tilde R}_{nml}$ is inside the  
  $N\times M \times L$ super-WS cell, then it is the shortest, take it and quit

\item if it is outside the WS, then it is not the shortest, throw it away

\item if it is on the border/corner of the WS then it is the shortest, but there 
are other choices of $(n,m,l)$ which are equivalent, find all of them
\end{enumerate}

In all distance comparisons, a small but finite tolerance is considered,
which can be controlled with the parameter {\tt ws\_distance\_tol}.

Because of how the Fourier transform is defined in the \wannier{} code (not the only 
possible choice) it is only $\bvec{R}+\bvec{\tilde R}_{nml}$ 
that enters the exponential, but you still have to consider the distance 
among the actual centres of the Wannier functions. Using 
the centres of the unit-cell to which the Wannier functions belong 
is not enough (but is easier, and saves you one index).

Point 3 is not stricly necessary, but using it helps enforcing the 
symmetry of the system in the resulting band structure. You 
will get some small but evident symmetry breaking in the band 
plots if you just pick one of the equivalent $\bvec{\tilde R}$ vectors.

Note that in some cases, all this procedure does absolutely nothing,
for instance if all the Wannier function centres are very close to 0 
(e.g., a molecule carefully placed in the periodic cell).

In some other cases, the effect may exist but be imperceptible. E.g.,
if you use a very fine grid of $k-$points, even if you don't centre 
each functions perfectly, the periodic copies will still be so far away 
that the change in centre applied with $\tt use\_ws\_distance$ does not matter. 

When instead you use few $k-$points, activating the $\tt use\_ws\_distance$
may help a lot in avoiding spurious oscillations of the band structure
even when the Wannier functions are well converged.
