%\documentclass[aps,showpacs,prb,floatfix,twocolumn]{revtex4}
\documentclass[aps,prb,floatfix,epsfig,singlecolumn,showpacs,preprintnumbers]{revtex4}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath,amssymb,graphicx,bm,epsfig}
\usepackage{color}
\usepackage{braket}

\newcommand{\eps}{\epsilon}
\newcommand{\vR}{{\mathbf{R}}}
\newcommand{\vF}{{\mathbf{F}}}
\renewcommand{\vr}{{\mathbf{r}}}
\newcommand{\hr}{{\hat{\textbf{r}}}}
\newcommand{\vk}{{\mathbf{k}}}
\newcommand{\vdelta}{{\mathbf{\delta}}}
\newcommand{\vK}{{\mathbf{K}}}
\newcommand{\vG}{{\mathbf{G}}}
\newcommand{\vq}{{\mathbf{q}}}
\newcommand{\vQ}{{\mathbf{Q}}}
\newcommand{\vPhi}{{\mathbf{\Phi}}}
\newcommand{\vS}{{\mathbf{S}}}
\newcommand{\cG}{{\cal G}}
\newcommand{\cR}{{\cal R}}
\newcommand{\cF}{{\cal F}}
\newcommand{\cT}{{\cal T}}
\newcommand{\cO}{{\cal O}}
\newcommand{\cH}{{\cal H}}
\newcommand{\cJ}{{\cal J}}
\newcommand{\cD}{{\cal D}}
\newcommand{\cU}{{\cal U}}
\newcommand{\cL}{{\cal L}}
\newcommand{\Tr}{\mathrm{Tr}}
\renewcommand{\a}{\alpha}
\renewcommand{\b}{\beta}
\newcommand{\g}{\gamma}
\renewcommand{\d}{\delta}
\newcommand{\npsi}{\underline{\psi}}
\renewcommand{\Im}{\textrm{Im}}
\renewcommand{\Re}{\textrm{Re}}
\newcommand{\cA}{{\cal A}}
\newcommand{\vcA}{\vec{\cal A}}
\newcommand{\vcB}{\vec{\cal B}}
\newcommand{\vcC}{\vec{\cal C}}
\newcommand{\cB}{{\cal B}}
\newcommand{\cC}{{\cal C}}

\begin{document}

\title{Some notes on forces in LAPW}
\author{Kristjan Haule}
\affiliation{Department of Physics, Rutgers University, Piscataway, NJ 08854, USA}
\date{\today}

%\begin{abstract}
%\end{abstract}
\pacs{71.27.+a,71.30.+h}
\date{\today}
\maketitle

\section{LAPW Intro}

First we refresh the basic LAPW equations.  The LAPW basis in the
interstitials is
\begin{eqnarray}
\chi_{\vk+\vK}(\vr) = \frac{1}{\sqrt{V}} e^{i(\vk+\vK)\vr}
=\sum_{lm}\frac{4\pi i^l}{\sqrt{V}}e^{i(\vk+\vK)\vr_{\mu}}Y_{lm}^*(R_{\mu}(\hat{\vk}+\hat{\vK}))j_l(|\vk+\vK||\vr-\vr_{\mu}|)Y_{lm}(R_{\mu}(\vr-\vr_\alpha))
\label{eq:bI}
\end{eqnarray}
and in the MT-spheres is
\begin{eqnarray}
&& \chi_{\vk+\vK}(\vr) = \sum_{lm,\mu}\frac{4\pi i^l S^2}{\sqrt{V}}e^{i(\vk+\vK)\vr_\mu} Y^*_{lm}(R_\mu(\vk+\vK))\left( \bar{a}^{\vk+\vK}_{l}  u_l(|\vr-\vr_\mu|) + \bar{b}^{\vk+\vK}_{l} \dot{u}_l(|\vr-\vr_\mu|)\right) Y_{lm}(R_{\mu}(\vr-\vr_\mu))
\label{eq:bMT}\\
&& \chi_{\nu=(lm\mu)}(\vr) = \sum_{m'\mu'}\frac{4\pi i^l  S^2}{\sqrt{V}}e^{i(\vk+\vK_\nu)\vr_{\mu'}}Y^*_{lm'}(R_{\mu'}(\vk+\vK_\nu))
 (a^{lo}_{\nu} u_l(|\vr-\vr_{\mu'}|) + b^{lo}_{\nu}\dot{u}_l(|\vr-\vr_{\mu'}|) + c^{lo}_{\nu} u^{LO}_l(|\vr-\vr_{\mu'}|)) Y^*_{lm'}(R_{\mu'}\vr)
\nonumber
\end{eqnarray}
In the last term we take a combination of $a^{lo}$, $b^{lo}$ and $c^{lo}$ so that
the combined orbital
\begin{eqnarray}
u^{loc}_\nu(r) = a^{lo}_\nu u_l(r) + b^{lo}_\nu \dot{u}(r) + c^{lo}_\nu u_l^{LO}
\end{eqnarray}
vanishes at the MT-boundary.
In LAPW method, we can also make derivative $d u^{loc}_\nu(r=R_{MT})/dr$
vanish, while in APW+lo only the value $u^{loc}_\nu(r=R_{MT})$ vanishes.
Note that the index for the local orbital $\nu$ comprises
$(\mu,l,j_{lo},\alpha,m)$ in this order, where ($\mu$, $l$, $j_{lo}$, $\alpha$, $m$) are
(index of a sort, $l$, index enumerates local orbital, index of the
equivalent atom, $m$).

Notice that the phase factor in the local orbital functions is taken
to be the same as in augmented plane waves. Moreover, $\vK_\nu$ is
taken to be different for each local orbital component. Namely, each
set of equivalent atoms and their $m$ quantum numbers are assigmed a unique set
of $\vK$'s, usually just starting from the beginning of the
list. For different atom types and different $l$'s the reciprocal
vectors repeat, so that for example each first atom of a new type and
its first $m=-l$ will have $K_\nu=0$ vector.

% Here $u_{LO}(r)$ is choosen such that it vanishes at the muffin thin
% sphere $S$, hence it does not need to be match outside the sphere.
The matching conditions, which give continuous derivative of $\chi_{\vk+\vK}$
across $S$ are
\begin{eqnarray}
\left(
\begin{array}{cc}
u_l(S) & \dot{u}_l(S)\\
\frac{d}{dr} u_l(S) & \frac{d}{dr} \dot{u}_l(S)
\end{array}
\right)
\left(
\begin{array}{c}
\bar{a}^{\vk+\vK}_{l}\\
\bar{b}^{\vk+\vK}_{l}
\end{array}
\right)=
\frac{1}{S^2}
%\frac{4\pi i^l}{\sqrt{V}}e^{i(\vk+\vK)\vr_\alpha}Y_{lm}^*(R(\hat{\vk}+\hat{\vK}))
\left(
\begin{array}{c}
j_l(|\vk+\vK|S)\\
\frac{d}{dr} j_l(|\vk+\vK|S)
\end{array}
\right)
\end{eqnarray}
with the solution
\begin{eqnarray}
\left(
\begin{array}{c}
\bar{a}^{\vk+\vK}_{l}\\
\bar{b}^{\vk+\vK}_{l}
\end{array}
\right)=
%\frac{4\pi i^l}{\sqrt{V}}e^{i(\vk+\vK)\vr_\alpha}Y_{lm}^*(R(\hat{\vk}+\hat{\vK}))
\frac{1}{S^2}
\left(
\begin{array}{cc}
\frac{d}{dr} \dot{u}_l(S)  & -\dot{u}_l(S)\\
-\frac{d}{dr} u_l(S) & u_l(S)
\end{array}
\right)
\frac{1}{u_l(S) \frac{d}{dr} \dot{u}_l(S)-\dot{u}_l(S) \frac{d}{dr} u_l(S)}
%
\left(
\begin{array}{c}
j_l(|\vk+\vK|S)\\
\frac{d}{dr} j_l(|\vk+\vK|S)
\end{array}
\right)
\end{eqnarray}

The two solutions satisfy the following equations
\begin{eqnarray}
&&\left(-\frac{d^2}{dr^2}+\frac{l(l+1)}{r^2}+V_{KS}(r)-E_\nu \right) r   u_l(r)=0
\label{Eq:S1}\\
&&\left(-\frac{d^2}{dr^2}+\frac{l(l+1)}{r^2}+V_{KS}(r)-E_\nu \right)r \dot{u}_l(r)= r u_l(r)
\label{Eq:S2}
\end{eqnarray}
We multiply the first equation by $r\dot{u}_l(r)$ and the second by $ru_l(r)$ to obtain
\begin{eqnarray}
\int_0^S dr\left\{ r\dot{u}_l(r) \left(-\frac{d^2}{dr^2}\right) r u_l(r)
-r u_l(r)
\left(-\frac{d^2}{dr^2}\right)r \dot{u}_l(r)\right\}=-\int_0^S dr r^2 u_l(r)u_l(r)
\end{eqnarray}
Integration by parts gives
\begin{eqnarray}
\left[
- r\dot{u}_l(r) \frac{d}{dr} \left(r u_l(r)\right)
+r u_l(r) \frac{d}{dr} \left(r \dot{u}_l(r)\right)\right]_0^S
=-1
\end{eqnarray}
which finally leads to
\begin{eqnarray}
\dot{u}_l(S) \frac{d}{dr} u_l(S)
-u_l(S) \frac{d}{dr} \dot{u}_l(S) =\frac{1}{S^2}
\label{Eq:tar}
\end{eqnarray}
Hence, we can than simplify the solution for $a_{lm}$ and $b_{lm}$ to
\begin{eqnarray}
\left(
\begin{array}{c}
\bar{a}^{\vk+\vK}_{l}\\
\bar{b}^{\vk+\vK}_{l}
\end{array}
\right)=
%\frac{4\pi i^l S^2}{\sqrt{V}}e^{i(\vk+\vK)\vr_\alpha}Y_{lm}^*(R(\hat{\vk}+\hat{\vK}))
%
\left(
\begin{array}{c}
\dot{u}_l(S)\frac{d}{dr} j_l(|\vk+\vK|S)-\frac{d}{dr} \dot{u}_l(S) j_l(|\vk+\vK|S)\\
\frac{d}{dr} u_l(S) j_l(|\vk+\vK|S)- u_l(S) \frac{d}{dr} j_l(|\vk+\vK|S)
\end{array}
\right)
\label{eq:alm}
\end{eqnarray}
This equation is implemented in Wien2k, and also in both dmft1 and
dmft2 steps.

In the following we will many times use alternative shorter notation
for these coefficients, namely,
\begin{eqnarray}
\tilde{a}_{l\vK}\equiv \bar{a}^{\vk+\vK}_l\\
\tilde{b}_{l\vK}\equiv \bar{b}^{\vk+\vK}_l
\end{eqnarray}

To construct the basis functions $u_l$, the Hamiltonian in the
muffin-thin sphere is solved in so-called spherical approximation to
Kohn-Sham potential. The KS Hamiltonian has the form
\begin{eqnarray}
H^{sph}=-\nabla^2 +V_{KS}(\vr)
\end{eqnarray}
where $V_{KS}(\vr)= V^{sym}_{KS}(r)+V_{KS}^{n-sym}(\vr)$ is split into  spherically symmetryc and the rest.
In the calculation we actually use an equivalent but more symmetric
form of the kinetic energy operators, namely
\begin{eqnarray}
T_{\vK'\vK} = \braket{\chi_{\vK'}|T|\chi_{\vK}} = \int_{\vr}  (\nabla\chi_{\vK'}^*)\cdot (\nabla\chi_{\vK})=
\int_{\vr} \nabla\cdot (\chi_{\vK'}^* \nabla\chi_{\vK} ) +\int \chi_{\vK'}^*(-\nabla^2)\chi_{\vK}
\end{eqnarray}
In the interstitials we use directly $\nabla\cdot\nabla$ operator,
while in the MT-spheres, we need to add the surface term on the
MT-sphere, i.e.,
\begin{eqnarray}
\braket{\chi_{\vK'}|H^{sym}|\chi_\vK}_{MT}=\int_{MT}d\vr\; \chi^*_{\vK'}(-\nabla^2+V_{KS}^{sym})\chi_{\vK}+\oint_{MT} d\vec{S}\chi^*_{\vK'}\nabla_\vr\chi_{\vK}\\
\end{eqnarray}
To evaluate these terms in the MT-sphere, we first define
\begin{eqnarray}
a_{lm\vK} \equiv \bar{a}^{\vk+\vK}_{l}\;\frac{4\pi i^l S^2}{\sqrt{V}}e^{i(\vk+\vK)\vr_\mu}  Y^*_{lm}(R_\mu(\vk+\vK))\\
b_{lm\vK} \equiv \bar{b}^{\vk+\vK}_{l}\;\frac{4\pi i^l S^2}{\sqrt{V}}e^{i(\vk+\vK)\vr_\mu}  Y^*_{lm}(R_\mu(\vk+\vK))\\
a^{lo}_{\vK_\nu,\nu,m,\mu}\equiv a^{lo}_\nu\;\frac{4\pi i^l S^2}{\sqrt{V}}e^{i(\vk+\vK_\nu)\vr_\mu}  Y^*_{lm}(R_\mu(\vk+\vK_\nu))\\
b^{lo}_{\vK_\nu,\nu,m,\mu}\equiv b^{lo}_\nu\;\frac{4\pi i^l S^2}{\sqrt{V}}e^{i(\vk+\vK_\nu)\vr_\mu}  Y^*_{lm}(R_\mu(\vk+\vK_\nu))\\
c^{lo}_{\vK_\nu,\nu,m,\mu}\equiv c^{lo}_\nu\;\frac{4\pi i^l S^2}{\sqrt{V}}e^{i(\vk+\vK_\nu)\vr_\mu}  Y^*_{lm}(R_\mu(\vk+\vK_\nu))\\
\end{eqnarray}
We also define the following matrices of matrix elements
\begin{eqnarray}
\cH \equiv \left(
\begin{array}{c|c|c}
E_l-\varepsilon & \frac{1}{2} & \left(\frac{E_l+E'_l}{2}-\varepsilon\right) \braket{u_l|u_l^{LO}} \\
\hline
\frac{1}{2} & (E_l-\varepsilon) \braket{\dot{u}|\dot{u}} & \left(\frac{E_l+E'_l}{2}-\varepsilon\right) \braket{\dot{u}|u^{LO}} +\frac{1}{2}\braket{u_l|u_l^{LO}}\\
\hline
\left(\frac{E_l+E'_l}{2}-\varepsilon\right) \braket{u_l|u^{LO}_l}&\left(\frac{E_l+E'_l}{2}-\varepsilon\right) \braket{\dot{u}_l|u^{LO}_l}+\frac{1}{2}\braket{u_l|u_l^{LO}}& ({E'}_l-\varepsilon)\braket{u_l^{LO}|u_l^{LO}}
\end{array}
\right)
\end{eqnarray}
and for the surface term
\begin{eqnarray}
{\cal H}^S=S^2
\left(\begin{array}{c|c|c}
u_l\frac{d u_l}{dr} & \frac{1}{2 S^2}+ u_l\frac{d\dot{u}_l}{dr} & \frac{1}{2}\left[u_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{du_l}{dr}\right]\\
\hline
\frac{1}{2 S^2}+ u_l \frac{d\dot{u}_l}{dr} & \dot{u}_l \frac{d\dot{u}_l}{dr} &\frac{1}{2}\left[\dot{u}_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{d\dot{u}_l}{dr}\right]\\
\hline
\frac{1}{2}\left[u_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{du_l}{dr}\right]&\frac{1}{2}\left[\dot{u}_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{d\dot{u}_l}{dr}\right]& u^{LO}_l\frac{d u^{LO}_l}{dr}
\end{array}
\right)_{r=S}
\end{eqnarray}
The matrices correspond to
$(\braket{u_l^{\kappa'}|H_{sym}-\varepsilon|u_l^{\kappa}}+\braket{u_l^{\kappa}|H_{sym}-\varepsilon|u_l^{\kappa'}}^*)/2$,
where $\kappa$ runs over $[u,\dot{u},u^{LO}]$. The derivation of these
matrix elements will  become clear below.
Note also that the $\cH^S_{12}$ term looks different, but we could
cast it into more symmetric form using Eq.~\ref{Eq:tar}, namely
$\cH^S_{12}=\frac{1}{2}[u_l\frac{d\dot{u}_l}{dr} +\dot{u}_l\frac{d
  u_l}{dr}] $ so that the matrix is
\begin{eqnarray}
{\cal H}^S=S^2
\left(\begin{array}{c|c|c}
u_l\frac{d u_l}{dr} & \frac{1}{2}[u_l\frac{d\dot{u}_l}{dr} +\dot{u}_l\frac{d u_l}{dr}] & \frac{1}{2}\left[u_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{du_l}{dr}\right]\\
\hline
\frac{1}{2}[u_l\frac{d\dot{u}_l}{dr} +\dot{u}_l\frac{d u_l}{dr}] & \dot{u}_l \frac{d\dot{u}_l}{dr} &\frac{1}{2}\left[\dot{u}_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{d\dot{u}_l}{dr}\right]\\
\hline
\frac{1}{2}\left[u_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{du_l}{dr}\right]&\frac{1}{2}\left[\dot{u}_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{d\dot{u}_l}{dr}\right]& u^{LO}_l\frac{d u^{LO}_l}{dr}
\end{array}
\right)_{r=S}
\end{eqnarray}

% For the overlap, we have
% \begin{eqnarray}
% \braket{\chi_{\vK'}|\chi_\vK}_{MT}=
% \sum_{lm}\int_{MT} d\vr (a_{lm\vK'}^* u_l+b_{lm\vK'}^* \dot{u}_l) (a_{lm\vK}  u_l+b_{lm\vK} \dot{u}_l)=
% \sum_{lm} a_{lm\vK'}^* a_{lm\vK}  +b_{lm\vK'}^*b_{lm\vK} \braket{\dot{u}|\dot{u}}
% \end{eqnarray}
Using Eq.~\ref{Eq:S1} and~\ref{Eq:S2} we can evaluate the Hamiltonian
in the MT-sphere. First we calculate the terms without local orbitals:
\begin{eqnarray}
&&\braket{\chi_{\vK'}|H^{sym}-\varepsilon|\chi_\vK}_{MT}=\int_{MT}d\vr\; \chi^*_{\vK'}(-\nabla^2+V_{KS}^{sym}-\varepsilon)\chi_{\vK}+\oint_{MT} d\vec{S}
\chi^*_{\vK'}\nabla_\vr\chi_{\vK}\\
&&=
\sum_{lm}\int_{MT}d\vr\; Y_{lm}^*(\vr) (a_{lm\vK'}^* u_l+b_{lm\vK'}^* \dot{u}_l)
(-\nabla^2+V_{KS}^{sym}-\varepsilon)  (a_{lm\vK} u_l+b_{lm\vK} \dot{u}_l)Y_{lm}(\vr)
\nonumber\\
&&+S^2\sum_{lm}\int_{MT} d\Omega (a_{lm\vK'}^* u_l(S)+b_{lm\vK'}^*  \dot{u}_l(S))  (a_{lm\vK} \frac{d u_l(S)}{dr}+b_{lm\vK}  \frac{d\dot{u}_l(S)}{dr}) Y_{lm}^*  Y_{lm}
\nonumber\\
&&=
\sum_{lm}\int_{MT} dr (a_{lm\vK'}^* u_l+b_{lm\vK'}^* \dot{u}_l)  \left[(E_l-\varepsilon)(a_{lm\vK} u_l+b_{lm\vK} \dot{u}_l) +b_{lm\vK}  u_l \right]
\nonumber\\
&&+S^2\sum_{lm} (a_{lm\vK'}^* u_l(S)+b_{lm\vK'}^*  \dot{u}_l(S))  (a_{lm\vK} \frac{d u_l(S)}{dr}+b_{lm\vK}  \frac{d\dot{u}_l(S)}{dr})
\nonumber\\
&&=\sum_{lm}(E_l-\varepsilon) (a_{lm\vK'}^* a_{lm\vK} +b_{lm\vK'}^* b_{lm\vK}  \braket{\dot{u}_l|\dot{u}_l})+a_{lm\vK'}^* b_{lm\vK}
\\
&&+S^2 \sum_{lm}\left(
a_{lm\vK'}^*a_{lm\vK} u_l(S) \frac{d u_l(S)}{dr}+
b_{lm\vK'}^* b_{lm\vK}  \dot{u}_l(S) \frac{d\dot{u}_l(S)}{dr}+
a_{lm\vK'}^* b_{lm\vK}  u_l(S) \frac{d\dot{u}_l(S)}{dr}+
b_{lm\vK'}^*  a_{lm\vK} \dot{u}_l(S) \frac{d u_l(S)}{dr}\right)\nonumber
\end{eqnarray}
Here we center the origin on studied atom, and assume that the axis
was properly rotated to the local coordinate axis.
 We know that
\begin{eqnarray}
\dot{u}(S)\frac{du(S)}{dr}-u(S) \frac{d\dot{u}(S)}{dr}=\frac{1}{S^2}
\end{eqnarray}
hence we can use this identity in the last term to obtain more
symmetric result
\begin{eqnarray}
\braket{\chi_{\vK'}|H^{sym}-\varepsilon|\chi_\vK}_{MT}&=&(E_l-\varepsilon) (a_{lm\vK'}^* a_{lm\vK} +b_{lm\vK'}^* b_{lm\vK}  \braket{\dot{u}_l|\dot{u}_l})+a_{lm\vK'}^* b_{lm\vK} +b_{lm\vK'}^*  a_{lm\vK}
\\
&+&S^2 \left(
a_{lm\vK'}^*a_{lm\vK} u_l(S) \frac{d u_l(S)}{dr}+
b_{lm\vK'}^* b_{lm\vK}  \dot{u}_l(S) \frac{d\dot{u}_l(S)}{dr}+
(a_{lm\vK'}^* b_{lm\vK}+b_{lm\vK'}^*  a_{lm\vK})  u_l(S) \frac{d\dot{u}_l(S)}{dr}
\right)\nonumber
\end{eqnarray}
We can cast this equation into the following matrix form
\begin{eqnarray}
\braket{\chi_{\vK'}|H^{sym}-\varepsilon|\chi_\vK}_{MT}=
\left(
\begin{array}{ccc}
a_{lm\vK'}^* & b_{lm\vK'}^* & 0
\end{array}
\right)
(\cH+\cH^S)
\left(
\begin{array}{c}
a_{lm\vK}\\
b_{lm\vK}\\
0
\end{array}
\right)
\end{eqnarray}
% so that
% \begin{eqnarray}
% \cH=
% \left(\begin{array}{c|c}
% E_l-\varepsilon + S^2 [u_l \frac{d u_l}{dr}]_{r=S}& 1+ S^2 [u_l\frac{d\dot{u}_l}{dr}]_{r=S}\\
% \hline
% 1+ S^2 [u_l\frac{d\dot{u}_l}{dr}]_{r=S} & (E_l-\varepsilon)\braket{\dot{u}|\dot{u}}+S^2[\dot{u}_l\frac{d\dot{u}_l}{dr}]_{r=S}
% \end{array}
% \right)
% \end{eqnarray}

Next we calculate the local-orbital part.
% The overlap for mixed
% term is
% \begin{eqnarray}
% O_{\vK,\nu} &=&\braket{\chi_\nu|\chi_\vK}=\frac{(4\pi  S^2)^2}{V}\sum_{m'\mu'} e^{i(\vK-\vK_\nu)\vr_{\mu'}}
% Y_{lm'}(R_{\mu'}(\vK+\vk))  Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))\\
% &&\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad \times
% {\braket{a^{lo}_{\nu}u_l+b^{lo}_{\nu}\dot{u}_l+c^{lo}_{\nu}u^{LO}_l|\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK} \dot{u}_l}}=\\
% &=&\frac{(4\pi  S^2)^2}{V}\sum_{m'\mu'} e^{i(\vK-\vK_\nu)\vr_{\mu'}}
% Y_{lm'}(R_{\mu'}(\vK+\vk))  Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))\times (\tilde{a}_{l\vK} C^\nu_1 + \tilde{b}_{l\vK} C^\nu_2)
% \end{eqnarray}
% Here
% \begin{eqnarray}
% &&C^\nu_1  = \braket{u^{loc}_\nu|u_l}    = a^{lo}_\nu + c^{lo}_\nu\braket{u_l|u_l^{LO}}\\
% && C^\nu_2  = \braket{u^{loc}|\dot{u}_l} = b^{lo}_\nu\braket{\dot{u}_l|\dot{u}_l} + c^{lo}_\nu\braket{\dot{u}_l|u^{LO}_l}
% \end{eqnarray}
%
The mixed term of the Hamiltonian is symmetrize and takes the form
\begin{eqnarray}
\widetilde{H}_{\vK\nu}\equiv \frac{1}{2}\braket{\chi_{\vK}|H^{sym}-\varepsilon|\chi_\nu}_{MT}
+\frac{1}{2}\braket{\chi_{\nu}|H^{sym}-\varepsilon|\chi_\vK}^*_{MT}
=\\
\frac{1}{2}\int_{MT}d\vr[ \chi^*_{\vK}(-\nabla^2+V_{KS}^{sym}-\varepsilon)\chi_{\nu}+\chi_{\nu}(-\nabla^2+V_{KS}^{sym}-\varepsilon)\chi^*_{\vK}]+
\frac{1}{2}\oint_{MT} d\vec{S}[\chi^*_{\vK}\nabla_\vr\chi_{\nu}+\chi_{\nu}\nabla_\vr\chi^*_{\vK}]
\end{eqnarray}
\begin{eqnarray}
\widetilde{H}_{\vK\nu}=
\frac{(4\pi  S^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_\nu-\vK)\vr_{\mu'}}
Y_{lm'}(R_{\mu'}(\vK+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))
\\
\times
\left(\overline{\braket{a^{lo}_{\nu}u_l+b^{lo}_{\nu}\dot{u}_l+c^{lo}_{\nu}u^{LO}_l|H-\varepsilon|\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK} \dot{u}_l}}
\right.
\\
+\left.
\frac{S^2}{2}
\left(
(\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK} \dot{u}_l)
\frac{d u^{local}_l}{dr}
+
u^{local}_l\frac{d (\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK} \dot{u}_l)}{dr}
\right)\biggl|_{r=S}
\right)
\label{Eq:wdrop}
\end{eqnarray}
Here overline means symmetrize the matrix elements.
Note that $u^{loc}_\nu$ is the orbital which vanishes at the MT-boundary
\begin{eqnarray}
u^{loc}_\nu(r) = a^{lo}_\nu u_l(r) + b^{lo}_\nu \dot{u}(r) + c^{lo}_\nu u_l^{LO}
\end{eqnarray}
and hence we can drop the last term of Eq.~\ref{Eq:wdrop}.
But in this derivation we will keep it, so that the result is more
symmetric. We will again use the identity
\begin{eqnarray}
\dot{u}_l(S)\frac{d u_l(S)}{dr}= u_l(S) \frac{d \dot{u}_l(S)}{dr} + \frac{1}{S^2}
\end{eqnarray}
to obtain a symmetric form of the surface term
\begin{eqnarray}
\frac{S^2}{2}(\tilde{a}_{l\vK} u_l(S) + \tilde{b}_{l\vK} \dot{u}_l(S))\frac{d u^{local}_l}{dr}
+\frac{S^2}{2}u^{local}_l\frac{d (\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK}  \dot{u}_l)}{dr}=\\
 \tilde{a}_{l\vK} a_\nu^{lo} {S^2}u_l(S)\frac{du_l(S)}{dr} +\tilde{b}_{l\vK}  b_\nu^{lo} {S^2} \dot{u}_l(S)\frac{d\dot{u}_l(S)}{dr} \\
+( \tilde{a}_{l\vK} b_\nu^{lo} + \tilde{b}_{l\vK} a_\nu^{lo})(  \frac{1}{2} + S^2 u_l(S)\frac{d\dot{u}_l(S)}{dr})\\
%+\frac{1}{2}  (\tilde{b}_{l\vK} a_\nu^{lo} + b_\nu^{lo} \tilde{a}_{l\vK}) \\
+\tilde{a}_{l\vK} c_\nu^{lo} \frac{S^2}{2} (u_l(S)\frac{du_l^{LO}(S)}{dr}+u^{LO}_l(S)\frac{u_l}{dr})\\
+\tilde{b}_{l\vK} c_\nu^{lo} \frac{S^2}{2} (\dot{u}_l(S)\frac{du^{LO}(S)}{dr}+u^{LO}_l(S) \frac{\dot{u}_l}{dr} )\\
\end{eqnarray}

Next we need the action of the Hamiltonian operator on the local orbital
\begin{eqnarray}
(-\nabla^2+V_{sym}-\varepsilon) u^{loc}_\nu(r) =
 a^{lo}_\nu u_l \; (E_l-\varepsilon)
+  b^{lo}_\nu (\dot{u}_l  (E_l-\varepsilon) + u_l)
+ c^{lo}_\nu u^{LO}_l  (E'_l-\varepsilon)
=\\
 (a^{lo}_\nu (E_l-\varepsilon)+b^{lo}_\nu) u_l +
b^{lo}_\nu (E_l-\varepsilon) \dot{u}_l + c^{lo}_\nu (E'_l-\varepsilon)  u^{LO}_l
\end{eqnarray}
and we also use the action of H on LAPW
\begin{eqnarray}
&& (-\nabla^2+V_{sym}-\varepsilon) u_l =  (E_l-\varepsilon) u_l\\
&& (-\nabla^2+V_{sym}-\varepsilon)\dot{u}_l=(E_l-\varepsilon) \dot{u}_l+ u_l
\end{eqnarray}

We hence get the following expression (in the form used in lapw1)
\begin{eqnarray}
\widetilde{H}_{\vK\nu}=\frac{(4\pi  S^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_\nu-\vK)\vr_{\mu'}}
Y_{lm'}(R_{\mu'}(\vK+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))  \times\\
\times\left[
\tilde{a}_{l\vK} (C^\nu_{11} +u_l(S) k_{inlo} ) + \tilde{b}_{l\vK} (C^\nu_{12}+\dot{u}_l(S) k_{inlo})
\right]
\end{eqnarray}
\begin{eqnarray}
&& C^\nu_{11} = \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}-\varepsilon|u_l}+\braket{u_l|H_{sym}-\varepsilon|u^{loc}_\nu})
   = a^{lo}_\nu (E_l-\varepsilon) + \frac{1}{2} b^{lo}_\nu + c^{lo}_\nu \braket{u|u^{LO}}\left(\frac{E_l+E'_l}{2}-\varepsilon\right)\\
&& C^\nu_{12} =  \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}-\varepsilon|\dot{u}_l}+\braket{\dot{u}_l|H_{sym}-\varepsilon|u^{loc}_\nu})
= \nonumber\\
&&\qquad\qquad\qquad =b^{lo}_\nu \braket{\dot{u}_l|\dot{u}_l}(E_l-\varepsilon) +
c^{lo}_\nu\braket{\dot{u}_l|u^{LO}}\left(\frac{E_l+E'_l}{2}-\varepsilon\right) +
\frac{1}{2} a^{lo}_\nu+
\frac{1}{2}c^{lo}_\nu\braket{u_l|u_l^{LO}}
\\
&& k_{inlo} = \frac{1}{2}  S^2  \frac{du_\nu^{loc}(r)}{dr}|_{r=S}
\end{eqnarray}
Inserting the above quantities into the previous equation, we get an
equivalent expression
% \begin{eqnarray}
% \widetilde{H}_{\vK\nu}=\frac{(4\pi  S^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_\nu-\vK)\vr_{\mu'}}
% Y_{lm'}(R_{\mu'}(\vK+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))
% \times\\
% \left[
% \tilde{a}_{l\vK} a^{lo}_\nu \left( (E_l-\varepsilon) + S^2   u_l(S)\frac{du_l(S)}{dr} \right)+
% \tilde{a}_{l\vK}  b^{lo}_\nu \left(1+ S^2 u_l(S)\frac{d\dot{u}_l(S)}{dr}\right)
% \right.
% \\
% +\tilde{b}_{l\vK}  a^{lo}_\nu \left(1+S^2 u_l(S)\frac{d\dot{u}_l(S)}{dr}\right)
% +\tilde{b}_{l\vK}  b^{lo}_\nu \left(  \braket{\dot{u}_l|\dot{u}_l}(E_l-\varepsilon) + S^2 \dot{u}_l(S)\frac{d\dot{u}_l(S)}{dr}\right)\\
% +\tilde{a}_{l\vK}  c^{lo}_\nu \left(\braket{u|u^{LO}}\left(\frac{E_l+E'_l}{2}-\varepsilon\right)+\frac{S^2}{2} (u_l(S)\frac{du_l^{LO}(S)}{dr}+u^{LO}_l(S)\frac{u_l}{dr})\right) \\
% \left.
% +\tilde{b}_{l\vK}  c^{lo}_\nu\left( \braket{\dot{u}_l|u^{LO}}\left(\frac{E_l+E'_l}{2}-\varepsilon\right)+\frac{1}{2}\braket{u_l|u_l^{LO}}+\frac{S^2}{2} (\dot{u}_l(S)\frac{du^{LO}(S)}{dr}+u^{LO}_l(S) \frac{\dot{u}_l}{dr} )\right)
% \right]
% \end{eqnarray}
% which can be cast into the form
\begin{eqnarray}
\widetilde{H}_{\vK\nu}=\sum_{m'\mu'}
\left(
\begin{array}{ccc}
a^*_{lm'\mu'\vK} & b^*_{lm'\mu'\vK} & 0
\end{array}
\right)(\cH+\cH^S)
\left(
\begin{array}{c}
a^{lo}_{\vK_\nu,\nu,m',\mu'}\\
b^{lo}_{\vK_\nu,\nu,m',\mu'}\\
c^{lo}_{\vK_\nu,\nu,m',\mu'}
\end{array}
\right)
\end{eqnarray}
% with
% \begin{eqnarray}
% {\cal H}=
% \left(\begin{array}{c|c|c}
% E_l-\varepsilon + S^2 \left[u_l\frac{d u_l}{dr}\right]_{r=S}& 1+ S^2 \left[u_l\frac{d\dot{u}_l}{dr}\right]_{r=S}
%  & \braket{u_l|u_l^{LO}}\left(\frac{E_l+E'_l}{2}-\varepsilon\right)+\frac{S^2}{2}\left[u_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{du_l}{dr}\right]_{r=S}\\
% \hline
% 1+ S^2 [u_l \frac{d\dot{u}_l}{dr}]_{r=S} & (E_l-\varepsilon)\braket{\dot{u}|\dot{u}}+S^2 \left[\dot{u}_l \frac{d\dot{u}_l}{dr}\right]_{r=S}&
% \braket{\dot{u}_l|u_l^{LO}}\left(\frac{E_l+E'_l}{2}-\varepsilon\right)+
% \frac{S^2}{2}\left[\dot{u}_l\frac{du_l^{LO}}{dr}+u^{LO}_l\frac{d\dot{u}_l}{dr}\right]_{r=S}+\frac{1}{2}\braket{u_l|u^{LO}_l}
% \end{array}
% \right)
% \end{eqnarray}

% \begin{eqnarray}
% (\tilde{a}_{l\vK} u_l(S) + \tilde{b}_{l\vK} \dot{u}_l(S)) k_{inlo}=
%   \frac{1}{2}  S^2  \tilde{a}_{l\vK} a_\nu^{lo} u(S)\frac{du(S)}{dr}
% +\frac{1}{2}  S^2 \tilde{b}_{l\vK}  b_\nu^{lo} \dot{u}_l(S)\frac{d\dot{u}(S)}{dr} \\
% +\frac{1}{2}  S^2  ( \tilde{a}_{l\vK} b_\nu^{lo} + \tilde{b}_{l\vK} a_\nu^{lo} ) u\frac{d\dot{u}}{dr}
% +\frac{1}{2}  \tilde{b}_{l\vK} a_\nu^{lo}
% \\
% +\frac{1}{2}  S^2   \tilde{a}_{l\vK} c_\nu^{lo} u_l(S)\frac{du_l^{LO}(S)}{dr}
% +\frac{1}{2}  S^2 \tilde{b}_{l\vK} c_\nu^{lo} \dot{u}_l(S)\frac{du^{LO}(S)}{dr}
% \end{eqnarray}
%
% \begin{eqnarray}
% \frac{S^2}{2}u^{local}_l\frac{d (\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK}  \dot{u}_l)}{dr}=
% a_\nu^{lo} \tilde{a}_{l\vK} \frac{S^2}{2} u_l(S) \frac{u_l}{dr}
% +b_\nu^{lo} \tilde{b}_{l\vK}  \frac{S^2}{2} \dot{u}_l(S) \frac{\dot{u}_l}{dr}
% +\frac{1}{2}b_\nu^{lo} \tilde{a}_{l\vK} \\
% +(b_\nu^{lo} \tilde{a}_{l\vK} +a_\nu^{lo} \tilde{b}_{l\vK} ) \frac{S^2}{2} u_l(S) \frac{\dot{u}_l}{dr}
% + c_\nu^{lo}\tilde{a}_{l\vK} \frac{S^2}{2} u^{LO}_l(S)\frac{u_l}{dr}
% +c_\nu^{lo}\tilde{b}_{l\vK} \frac{S^2}{2}  u^{LO}_l(S) \frac{\dot{u}_l}{dr}
% \end{eqnarray}
%
% \begin{eqnarray}
% (\tilde{a}_{l\vK} u_l(S) + \tilde{b}_{l\vK} \dot{u}_l(S))  k_{inlo}+\frac{S^2}{2}u^{local}_l\frac{d (\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK}  \dot{u}_l)}{dr}=\\
%  (\tilde{a}_{l\vK} a_\nu^{lo} + a_\nu^{lo} \tilde{a}_{l\vK} )\frac{S^2}{2}   u_l(S)\frac{du_l(S)}{dr} \\
% +(\tilde{b}_{l\vK}  b_\nu^{lo}+b_\nu^{lo} \tilde{b}_{l\vK} ) \frac{S^2}{2} \dot{u}_l(S)\frac{d\dot{u}_l(S)}{dr} \\
% +2( \tilde{a}_{l\vK} b_\nu^{lo} + \tilde{b}_{l\vK} a_\nu^{lo})\frac{S^2}{2} u_l(S)\frac{d\dot{u}_l(S)}{dr}\\
% +\frac{1}{2}  (\tilde{b}_{l\vK} a_\nu^{lo} + b_\nu^{lo} \tilde{a}_{l\vK}) \\
% +\tilde{a}_{l\vK} c_\nu^{lo} \frac{S^2}{2} (u_l(S)\frac{du_l^{LO}(S)}{dr}+u^{LO}_l(S)\frac{u_l}{dr})\\
% +\tilde{b}_{l\vK} c_\nu^{lo} \frac{S^2}{2} (\dot{u}_l(S)\frac{du^{LO}(S)}{dr}+u^{LO}_l(S) \frac{\dot{u}_l}{dr} )\\
% \end{eqnarray}
%
% ?????
% In the code we define
% \begin{eqnarray}
% && C^\nu_1  = \braket{u^{loc}_\nu|u_l}    = a^{lo}_\nu + c^{lo}_\nu\braket{u_l|u_l^{LO}}\\
% && C^\nu_2  = \braket{u^{loc}|\dot{u}_l} = b^{lo}_\nu\braket{\dot{u}_l|\dot{u}_l} + c^{lo}_\nu\braket{\dot{u}_l|u^{LO}_l}\\
% && C^\nu_3  = \braket{u^{loc}|u^{LO}_l} = c_\nu^{lo} + b_\nu^{lo}\braket{\dot{u}_l|u^{LO}_l} + a^{lo}_\nu\braket{u_l|u^{LO}_l}\\
% && C^\nu_{11} = \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}|u_l}+\braket{u_l|H_{sym}|u^{loc}_\nu})
%    = a^{lo}_\nu E_\mu^l + \frac{1}{2} b^{lo}_\nu + \frac{1}{2} c^{lo}_\nu \braket{u|u^{LO}}(E^l_\mu+E^l_{\mu'})\\
% && C^\nu_{12} =  \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}|\dot{u}_l}+\braket{\dot{u}_l|H_{sym}|u^{loc}_\nu})
% = b^{lo}_\nu \braket{\dot{u}_l|\dot{u}_l}E^l_\mu +
% \frac{1}{2} a^{lo}_\nu+
% \frac{1}{2}c^{lo}_\nu\braket{u_l|u_l^{LO}}+
% c^{lo}_\nu\braket{\dot{u}_l|u^{LO}}\frac{1}{2}(E^l_\mu+E^l_{\mu'})
% \\
% && C^\nu_{13} =  \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}|u^{LO}_l}+\braket{u^{LO}_l|H_{sym}|u^{loc}_\nu})
% = c^{lo}_\nu E_{\mu'} +
% \frac{1}{2} b^{lo}_\nu \braket{u_l|u^{LO}_l} +
% \left(a^{lo}_\mu\braket{u_l|u^{LO}_l}+b^{lo}_\nu\braket{\dot{u}_l|u^{LO}_l}\right) \frac{1}{2}(E_\mu+E_{\mu'})
% \nonumber\\
% && ak_{inlo} = \frac{1}{2}  R_{MT}^2  \frac{du_\nu^{loc}(r)}{dr}|_{r=R_{MT}}
% \end{eqnarray}

% Finally, for the last term we have
% \begin{eqnarray}
% O_{\nu'\nu}=\braket{\chi_\nu|\chi_{\nu'}}=
% \frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_{\nu'}-\vK_\nu)\vr_{\mu'}}Y_{lm'}(R_{\mu'}(\vK_{\nu'}+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))
% (a^{lo}_{\nu'} C_1^\nu + b^{lo}_{\nu'} C_2^\nu + c^{lo}_{\nu'} C_3^\nu)
% \end{eqnarray}
% and
%

Finally, we work our the local-orbital part of the form
\begin{eqnarray}
\widetilde{H}_{\nu\nu'}\equiv \frac{1}{2}(\braket{\chi_{\nu}|H^{sym}-\varepsilon|\chi_{\nu'}}+\braket{\chi_{\nu'}|H^{sym}-\varepsilon|\chi_{\nu}}^*)
\end{eqnarray}
First we recognize
\begin{eqnarray}
\braket{\chi_{\nu}|H^{sym}-\varepsilon|\chi_{\nu'}}=\frac{(4\pi  S^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_{\nu'}-\vK_\nu)\vr_{\mu'}}Y^*_{lm'}(R_{\mu'}(\vK_{\nu'}+\vk)) Y_{lm'}(R_{\mu'}(\vK_\nu+\vk))\times\\
(a^{lo}_{\nu} \braket{u_l|H-\varepsilon|u_{\nu'}^{loc}} +
b^{lo}_{\nu}  \braket{\dot{u}_l|H-\varepsilon|u_{\nu'}^{loc}}  +
c^{lo}_{\nu} \braket{u^{LO}_l|H-\varepsilon|u_{\nu'}^{loc}})
\end{eqnarray}
and hence
% \begin{eqnarray}
% \widetilde{H}_{\nu\nu'}=\frac{(4\pi  S^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_{\nu'}-\vK_\nu)\vr_{\mu'}}Y^*_{lm'}(R_{\mu'}(\vK_{\nu'}+\vk)) Y_{lm'}(R_{\mu'}(\vK_\nu+\vk))\times
% (a^{lo}_{\nu'} C_{11}^\nu+
% b^{lo}_{\nu'}  C_{12}^\nu+
% c^{lo}_{\nu'} C_{13}^\nu)
% \end{eqnarray}
%
%
% \begin{eqnarray}
% && C^\nu_{11} = \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}|u_l}+\braket{u_l|H_{sym}|u^{loc}_\nu})
%    = a^{lo}_\nu E_\mu^l + \frac{1}{2} b^{lo}_\nu + \frac{1}{2} c^{lo}_\nu \braket{u|u^{LO}}(E^l_\mu+E^l_{\mu'})\\
% && C^\nu_{12} =  \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}|\dot{u}_l}+\braket{\dot{u}_l|H_{sym}|u^{loc}_\nu})
% = b^{lo}_\nu \braket{\dot{u}_l|\dot{u}_l}E^l_\mu +
% \frac{1}{2} a^{lo}_\nu+
% \frac{1}{2}c^{lo}_\nu\braket{u_l|u_l^{LO}}+
% c^{lo}_\nu\braket{\dot{u}_l|u^{LO}}\frac{1}{2}(E^l_\mu+E^l_{\mu'})
% \\
% && C^\nu_{13} =  \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}|u^{LO}_l}+\braket{u^{LO}_l|H_{sym}|u^{loc}_\nu})
% = c^{lo}_\nu E_{\mu'} +
% \frac{1}{2} b^{lo}_\nu \braket{u_l|u^{LO}_l} +
% \left(a^{lo}_\mu\braket{u_l|u^{LO}_l}+b^{lo}_\nu\braket{\dot{u}_l|u^{LO}_l}\right) \frac{1}{2}(E_\mu+E_{\mu'})
% \end{eqnarray}
%
\begin{eqnarray}
\widetilde{H}_{\nu\nu'}=\frac{(4\pi  S^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_{\nu'}-\vK_\nu)\vr_{\mu'}}Y^*_{lm'}(R_{\mu'}(\vK_{\nu'}+\vk)) Y_{lm'}(R_{\mu'}(\vK_\nu+\vk))\times
\left(
\begin{array}{ccc}
a^{lo}_{\nu}, & b^{lo}_{\nu} & c^{lo}_{\nu}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
a^{lo}_{\nu'}\\
b^{lo}_{\nu'}\\
c^{lo}_{\nu'}
\end{array}
\right)
\end{eqnarray}
% where
% \begin{eqnarray}
% \cH \equiv \left(
% \begin{array}{c|c|c}
% E_l-\varepsilon & \frac{1}{2} & \left(\frac{E_l+E'_l}{2}-\varepsilon\right) \braket{u_l|u_l^{LO}} \\
% \hline
% \frac{1}{2} & (E_l-\varepsilon) \braket{\dot{u}|\dot{u}} & \left(\frac{E_l+E'_l}{2}-\varepsilon\right) \braket{\dot{u}|u^{LO}} +\frac{1}{2}\braket{u_l|u_l^{LO}}\\
% \hline
% \left(\frac{E_l+E'_l}{2}-\varepsilon\right) \braket{u_l|u^{LO}_l}&\left(\frac{E_l+E'_l}{2}-\varepsilon\right) \braket{\dot{u}_l|u^{LO}_l}+\frac{1}{2}\braket{u_l|u_l^{LO}}& ({E'}_l-\varepsilon)\braket{u_l^{LO}|u_l^{LO}}
% \end{array}
% \right)
% \end{eqnarray}
%
In more compact form we can write
\begin{eqnarray}
\widetilde{H}_{\nu\nu'}=\sum_{m''\mu''}
\left(
\begin{array}{ccc}
a^{lo\;*}_{\vK_\nu,\nu,m'',\mu''}, & b^{lo\;*}_{\vK_\nu,\nu,m'',\mu''} & c^{lo\;*}_{\vK_\nu,\nu,m''\mu''}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
a^{lo}_{\vK_{\nu'},\nu',m'',\mu''}\\
b^{lo}_{\vK_{\nu'},\nu',m'',\mu''}\\
c^{lo}_{\vK_{\nu'},\nu',m'',\mu''}
\end{array}
\right)
\label{Eq:locloc}
\end{eqnarray}
The surface term vanishes here, as we are evaluating terms like
$u^{loc}_{\nu'}(S)\frac{d}{dr} u^{loc}_{\nu}(S)$.
We can therefore add to $\cH$ the surface term $\cH^S$ without
changing the result. Namely, we could send $\cH\rightarrow\cH+\cH^S$
in Eq.~\ref{Eq:locloc}.

We will need quantities like
\begin{eqnarray}
\sum_{\vK'\vK}A^\dagger_{i\vK'}\widetilde{H}_{\vK'\vK} A_{\vK j}
\end{eqnarray}
where $A_{\vK i}$ are KS-eigenvectors and $\vK$ runs over reciprocal
vectors as well as local orbitals.
Since $\cH$ is equal in all terms, we can simplify
\begin{eqnarray}
\left(
\begin{array}{c}
\sum_{\vK'} A^\dagger_{i\vK'} a^*_{lm\mu\vK'}+\sum_{\vK_\nu}A^\dagger_{i\vK_\nu}a^{lo\;*}_{\vK_\nu,\nu,m\mu}\\
\sum_{\vK'} A^\dagger_{i\vK'} b^*_{lm\mu\vK'}+\sum_{\vK_\nu}A^\dagger_{i\vK_\nu}b^{lo\;*}_{\vK_\nu,\nu,m\mu}\\
\sum_{\vK_\nu}A^\dagger_{i\vK_\nu}c^{lo\;*}_{\vK_\nu,\nu,m\mu}
\end{array}
\right)\cH
\left(
\begin{array}{c}
\sum_{\vK} a_{lm\mu\vK}A_{\vK j}  +\sum_{\vK_\nu}a^{lo}_{\vK_\nu,\nu,m\mu}A_{\vK_\nu j}\\
\sum_{\vK} b_{lm\mu\vK}A_{\vK j}  +\sum_{\vK_\nu}b^{lo}_{\vK_\nu,\nu,m\mu}A_{\vK_\nu j}\\
\sum_{\vK_\nu}c^{lo}_{\vK_\nu,\nu,m\mu}A_{\vK_\nu j}
\end{array}
\right)
\end{eqnarray}
and if we call
\begin{eqnarray}
\left(
\begin{array}{c}
a_{i,lm\mu}\\
b_{i,lm\mu}\\
c_{i,lm\mu}
\end{array}
\right)
\equiv
\left(
\begin{array}{c}
\sum_{\vK} a_{lm\mu\vK}A_{\vK j}  +\sum_{\vK_\nu}a^{lo}_{\vK_\nu,\nu,m\mu}A_{\vK_\nu j}\\
\sum_{\vK} b_{lm\mu\vK}A_{\vK j}  +\sum_{\vK_\nu}b^{lo}_{\vK_\nu,\nu,m\mu}A_{\vK_\nu j}\\
\sum_{\vK_\nu}c^{lo}_{\vK_\nu,\nu,m\mu}A_{\vK_\nu j}
\end{array}
\right)
\end{eqnarray}
we get
\begin{eqnarray}
\left(
\begin{array}{c}
a_{i,lm\mu}^*\\
b_{i,lm\mu}^*\\
c_{i,lm\mu}^*
\end{array}
\right)\cH
\left(
\begin{array}{c}
a_{j,lm\mu}\\
b_{j,lm\mu}\\
c_{j,lm\mu}
\end{array}
\right)
\end{eqnarray}

--------------------
BELOW IS THE OLD TEXT, WHICH IS WRONG
--------------------

\begin{eqnarray}
(H^{sph}-\varepsilon)\ket{\chi_\vK}=
Y_{lm}(\hat{\vr})
[a_{lm}^{\vK}(E_l-\varepsilon) u_l(r) + b_{lm}^\vK(E_l-\varepsilon)\dot{u}_l(r) + b_{lm}^\vK u_l(r)]
\end{eqnarray}
Here we center the origin on studied atom, and assume that the axis
was properly rotated to the local coordinate axis.

The Hamiltonian is then given by
\begin{small}
\begin{eqnarray}
\braket{\chi_{\vK'}|H^{sph}-\varepsilon|\chi_\vK}=
\int dr [a^{\vK' *}_{lm} u_l(r) + b^{\vK' *}_{lm}  \dot{u}_l(r)+c^{\vK' *}_{lm} u_{LO}(r)]
[a_{lm}^{\vK}(E_\nu-\varepsilon) u_l(r) + b_{lm}^\vK(E_\nu-\varepsilon)\dot{u}_l(r) + b_{lm}^\vK u_l(r) + c_{lm}^\vK(E_{\mu}-\varepsilon)u_{LO}(r)]
\end{eqnarray}
\end{small}
which gives
\begin{eqnarray}
\braket{\chi_{\vK'}|H^{sph}-\varepsilon|\chi_\vK}&=&
a^{\vK' *}_{lm} [a_{lm}^{\vK}(E_\nu-\varepsilon)  + b_{lm}^\vK + c_{lm}^\vK(E_{\mu}-\varepsilon)\braket{u|u_{LO}}]\nonumber\\
&+&b^{\vK' *}_{lm} [b_{lm}^\vK(E_\nu-\varepsilon)\braket{\dot{u}_l|\dot{u}_l} + c_{lm}^\vK(E_{\mu}-\varepsilon)\braket{\dot{u}_l|u_{LO}}]\nonumber\\
&+&c^{\vK' *}_{lm} [a_{lm}^{\vK}(E_\nu-\varepsilon) \braket{u_{LO}|u_l}  +b_{lm}^\vK \braket{u_{LO}|u_l} + b_{lm}^\vK(E_\nu-\varepsilon)\braket{u_{LO}|\dot{u}_l}  + c_{lm}^\vK(E_{\mu}-\varepsilon)]
\end{eqnarray}
Here we used the relation $\braket{u_l|\dot{u}_l}=0$.
The Hamiltonian is Hermitian, but in its current form appears
non-Hermitian, hence we will symmetrize it,
\begin{small}
\begin{eqnarray}
\braket{\chi_{\vK'}|H^{sph}-\varepsilon|\chi_\vK}&=&
a^{\vK' *}_{lm}  a_{lm}^{\vK}(E_\nu-\varepsilon)  +
\frac{1}{2}[a^{\vK' *}_{lm} b_{lm}^\vK +b_{lm}^{\vK'*} a^{\vK}_{lm} ]+
\frac{1}{2}[a^{\vK' *}_{lm} c_{lm}^\vK + c^{\vK' *}_{lm} a_{lm}^\vK ] (E_{\mu}-\varepsilon)\braket{u|u_{LO}}+
\nonumber\\
&+&
b^{\vK' *}_{lm}  b_{lm}^\vK(E_\nu-\varepsilon)\braket{\dot{u}_l|\dot{u}_l} +
\frac{1}{2}[b^{\vK' *}_{lm}   c_{lm}^\vK +c^{\vK' *}_{lm}  b_{lm}^\vK ]
(E_{\mu}-\varepsilon)\braket{\dot{u}_l|u_{LO}}+
\nonumber\\
&+&
\frac{1}{2}[c^{\vK' *}_{lm} a_{lm}^{\vK} +a^{\vK' *}_{lm} c_{lm}^{\vK} ] (E_\nu-\varepsilon) \braket{u_{LO}|u_l}  +
\frac{1}{2}[c^{\vK' *}_{lm}  b_{lm}^\vK + b^{\vK' *}_{lm}  c_{lm}^\vK ][ \braket{u_{LO}|u_l}  + (E_\nu-\varepsilon)\braket{u_{LO}|\dot{u}_l} ] +
c^{\vK' *}_{lm}  c_{lm}^\vK(E_{\mu}-\varepsilon)
\nonumber
\end{eqnarray}
\end{small}
which is simlified to
\begin{eqnarray}
\braket{\chi_{\vK'}|H^{sph}-\varepsilon|\chi_\vK}&=&
a^{\vK' *}_{lm}  a_{lm}^{\vK}(E_\nu-\varepsilon)  +
b^{\vK' *}_{lm}  b_{lm}^\vK(E_\nu-\varepsilon)\braket{\dot{u}_l|\dot{u}_l} +
\frac{1}{2}[a^{\vK' *}_{lm} b_{lm}^\vK +b_{lm}^{\vK'*} a^{\vK}_{lm} ]+
%
\nonumber\\
&+&
c^{\vK' *}_{lm}  c_{lm}^\vK(E_{\mu}-\varepsilon) +
\frac{1}{2}[a^{\vK' *}_{lm} c_{lm}^\vK + c^{\vK' *}_{lm} a_{lm}^\vK ]  (E_{\mu}+E_\nu-2\varepsilon)\braket{u|u_{LO}} +
\nonumber\\
&+&
\frac{1}{2}[c^{\vK' *}_{lm}  b_{lm}^\vK + b^{\vK' *}_{lm}  c_{lm}^\vK ][ \braket{u_{LO}|u_l}  + (E_\mu+E_\nu-2\varepsilon)\braket{u_{LO}|\dot{u}_l} ]
\label{Eq:HmE}
\end{eqnarray}

--------------------
END THE OLD TEXT
--------------------

% We first perform the calculation in the absence of local orbitals.
% For overlap, we have
% \begin{eqnarray}
% \braket{\chi_{\vK'}|\chi_\vK}_{MT}=
% \int_{MT} dr (a_{lm\vK'}^* u_l+b_{lm\vK'}^* \dot{u}_l) (a_{lm\vK}  u_l+b_{lm\vK} \dot{u}_l)=
% a_{lm\vK'}^* a_{lm\vK}  +b_{lm\vK'}^*b_{lm\vK} \braket{\dot{u}|\dot{u}}
% \end{eqnarray}
% For Hamiltonian, we have two parts, i.e,
% \begin{eqnarray}
% &&\braket{\chi_{\vK'}|H^{sym}|\chi_\vK}_{MT}=\int_{MT} \chi^*_{\vK'}(-\nabla^2+V_{KS}^{sym})\chi_{\vK}+\oint_{MT} d\vec{S}
% \chi^*_{\vK'}\nabla_\vr\chi_{\vK}\\
% &&=
% \int_{MT}d^3r Y_{lm}^*(\vr) (a_{lm\vK'}^* u_l+b_{lm\vK'}^* \dot{u}_l)
% (-\nabla^2+V_{KS}^{sym})  (a_{lm\vK} u_l+b_{lm\vK} \dot{u}_l)Y_{lm}(\vr)
% \nonumber\\
% &&+R_{MT}^2\int_{MT} d\Omega (a_{lm\vK'}^* u_l(R)+b_{lm\vK'}^*  \dot{u}_l(R))  (a_{lm\vK} \frac{d u_l(R)}{dr}+b_{lm\vK}  \frac{d\dot{u}_l(R)}{dr}) Y_{lm}^*  Y_{lm}
% \nonumber\\
% &&=
% \int_{MT} dr (a_{lm\vK'}^* u_l+b_{lm\vK'}^* \dot{u}_l)  \left[\varepsilon_l(a_{lm\vK} u_l+b_{lm\vK} \dot{u}_l) +b_{lm\vK}  u_l \right]
% \nonumber\\
% &&+R_{MT}^2 (a_{lm\vK'}^* u_l(R)+b_{lm\vK'}^*  \dot{u}_l(R))  (a_{lm\vK} \frac{d u_l(R)}{dr}+b_{lm\vK}  \frac{d\dot{u}_l(R)}{dr})
% \nonumber\\
% &&=\varepsilon_l (a_{lm\vK'}^* a_{lm\vK} +b_{lm\vK'}^* b_{lm\vK}  \braket{\dot{u}_l|\dot{u}_l})+a_{lm\vK'}^* b_{lm\vK}
% \\
% &&+R_{MT}^2 \left(
% a_{lm\vK'}^*a_{lm\vK} u_l(R) \frac{d u_l(R)}{dr}+
% b_{lm\vK'}^* b_{lm\vK}  \dot{u}_l(R) \frac{d\dot{u}_l(R)}{dr}+
% a_{lm\vK'}^* b_{lm\vK}  u_l(R) \frac{d\dot{u}_l(R)}{dr}+
% b_{lm\vK'}^*  a_{lm\vK} \dot{u}_l(R) \frac{d u_l(R)}{dr}\right)\nonumber
% \end{eqnarray}
% We know that
% \begin{eqnarray}
% \dot{u}(R)\frac{du(R)}{dr}-u(R) \frac{d\dot{u}(R)}{dr}=\frac{1}{R^2}
% \end{eqnarray}
% hence we can use this identity in the last term to obtain more
% symmetric result
% \begin{eqnarray}
% \braket{\chi_{\vK'}|H^{sym}|\chi_\vK}_{MT}&=&\varepsilon_l (a_{lm\vK'}^* a_{lm\vK} +b_{lm\vK'}^* b_{lm\vK}  \braket{\dot{u}_l|\dot{u}_l})+a_{lm\vK'}^* b_{lm\vK} +b_{lm\vK'}^*  a_{lm\vK}
% \\
% &+&R_{MT}^2 \left(
% a_{lm\vK'}^*a_{lm\vK} u_l(R) \frac{d u_l(R)}{dr}+
% b_{lm\vK'}^* b_{lm\vK}  \dot{u}_l(R) \frac{d\dot{u}_l(R)}{dr}+
% (a_{lm\vK'}^* b_{lm\vK}+b_{lm\vK'}^*  a_{lm\vK})  u_l(R) \frac{d\dot{u}_l(R)}{dr}
% \right)\nonumber
% \end{eqnarray}
%

\subsubsection{Extra term when using APW+lo}
\label{APWlo}

For efficiency, wien2k uses APW+lo for many atoms (and for others LAPW),
because less plane waves is needed in this case.
The basis function in the  MT part looks similar, except that
$b_{lm}=0$, i.e.,
\begin{eqnarray}
\chi_{\vk+\vK}(\vr) = \left( a_{lm} u_l(|\vr-\vr_\alpha|) + c_{lm} u^{loc}(|\vr-\vr_\alpha|)\right)
  Y_{lm}(R(\hat{\vr}-\hat{\vr_\alpha}))\qquad MT-sphere
\label{eq:bMT2}
\end{eqnarray}
As $u^{loc}$ vanishes at $R_{MT}$ only the value of $\chi_{\vk+\vK}$ is
matched to determine $a_{lm}$:
\begin{eqnarray}
a_{lm}=
\frac{4\pi i^l}{\sqrt{V}}e^{i(\vk+\vK)\vr_\alpha}Y_{lm}^*(R(\hat{\vk}+\hat{\vK}))
j_l(|\vk+\vK|S)/u_l(S)
\end{eqnarray}
%
However, $u^{loc}(r)$ is constructed differently in APW+lo. In LAPW method,
$u^{loc}(r)$ is constructed from $u_l$, $\dot{u}_l$ and $u_l^2$,
where $u_l^2$ is linearized solution at some other energy $E'_l$, different
from $E_l$.  To costruct $u^{loc}$, however, we use just the
combination of $u_l$ and $\dot{u}_l$ only, i.e., $u^{loc}=\alpha u_l + \beta
\dot{u}_l$. The combination of these two function suffices
to achieve
$u^{loc}(S)=0$ and $\int |u^{loc}|^2 dr=1$.
The dissadvatage of this basis is that the derivative of
$\chi_{\vk+\vK}(\vr)$ across the MT-boundary is not continuous, hence
additionsl term in the Hamiltonian and forces is present. But since
the convergence with plane-wave cut-off is better, this is a small
price to pay.

The form of the kinetic operator used in the interstitials is
\begin{eqnarray}
T_{\vK'\vK}=\int d^3r (\nabla\chi^*_{\vK'})(\nabla\chi_\vK),
\end{eqnarray}
while in the MT-sphere, we use the alternative form
$\braket{\chi|-\nabla^2|\chi}$. Using Stokes theorem, we can always
change between the two forms
\begin{eqnarray}
 (\nabla\chi^*_{\vK'})(\nabla\chi_\vK)=  \nabla\cdot\left(\chi^*_{\vK'}\;\nabla\chi_\vK\right)
+\chi^*_{\vK'}\;(-\nabla^2)\chi_\vK
\end{eqnarray}
hence
\begin{eqnarray}
\int d^3r (\nabla\chi^*_{\vK'})(\nabla\chi_\vK)=
\int d^3 r \chi^*_{\vK'}\;(-\nabla^2)\chi_\vK +
\oint \vec{S} \left(\chi^*_{\vK'}\;\nabla\chi_\vK\right)
\end{eqnarray}
We use this for the MT-sphere part, and whenewer $T$ needs to be
evaluated, we add this extra surface term
\begin{eqnarray}
\int_{MT} d^3r (\nabla\chi^*_{\vK'})(\nabla\chi_\vK)=
\int_{MT} d^3 r \chi^*_{\vK'}\;(-\nabla^2)\chi_\vK +
\oint_{MT} d\vec{S} \left(\chi^*_{\vK'}\;\nabla\chi_\vK\right)
\end{eqnarray}
Discussion about this can be found in PRB~\textbf{64}, 195134 (2001) in appendix.

\section{Forces}

We start with DFT forces in LAPW. The DFT functional is
\begin{eqnarray}
E = \Tr(-\nabla^2 G) + E_H[\rho]+E_{xc}[\rho]+\Tr[\rho  V_{nucleous}]+E_{nucleous}
\end{eqnarray}
Here $E_{nucleous}=\frac{1}{2} \sum_{\alpha\ne \beta}\frac{Z_\alpha
  Z_\beta}{|\vR_\alpha-\vR_\beta|}$ and $V_{nucleous}(\vr)=-\sum_\alpha \frac{Z_\alpha}{|\vr-\vR_\alpha|}$

We can rearange the functional using the eigenvalues in the DFT
solution
\begin{eqnarray}
(-\nabla^2+V_{KS}-\varepsilon_i)\ket{\psi_{i\vk}}=0
\end{eqnarray}
and get
\begin{eqnarray}
E = \Tr(\varepsilon_i G) - \Tr(V_{KS}\rho )+E_H[\rho]+E_{xc}[\rho]+\Tr[\rho  V_{nucleous}]+E_{nucleous}=\\
\sum_i \varepsilon_i f_i - \Tr(V_{KS}\rho )+E_H[\rho]+E_{xc}[\rho]+\Tr[\rho  V_{nucleous}]+E_{nucleous}
\end{eqnarray}
This is the equation being implemented, hence we have to look at small
variation of this functional with respect to small movement of a
nucleous $\delta \vR_\alpha$.

We get Helman-Feynman forces $\vF^{HF}$ by varying the following two
terms
\begin{eqnarray}
\frac{\delta E_{nucleous}}{\delta \vR_\alpha}+\Tr(\rho \frac{\delta V_{nucleous}}{\delta \vR_\alpha})=-\vF^{HF}_\alpha
\end{eqnarray}
The rest of the variations can contribute to Pulley forces
\begin{eqnarray}
\delta E=\sum_i \delta \varepsilon_i f_i - \Tr(\rho \delta V_{KS})-\Tr(V_{KS}\delta \rho )
+\Tr(V_H \delta\rho)+\Tr(V_{xc} \delta\rho)+\Tr[V_{nucleous}\delta\rho]-\sum_\alpha\vF^{HF}_\alpha\delta \vR_\alpha
\end{eqnarray}
Notice that we did not varry $f_i$. This is because such term would
contribute to entropy, which we neglected here anyway. Within DMFT,
this has to be handled correctly.
The terms 2-6 are all computed in real space with numeric integration,
so we can safely cancel terms 3-6, since they are computed in exactly the
same way. We get
\begin{eqnarray}
\delta E=\sum_i \delta \varepsilon_i f_i - \Tr(\rho \delta V_{KS})-\sum_\alpha\vF^{HF}_\alpha\delta \vR_\alpha
\label{Eq:forceL}
\end{eqnarray}

The first two terms do not cancel because of the discretization using
LAPW basis set in computing eigenvalues.

To get variation of eigenvalues, we need to follow their computation,
which is achieved through the following diagonalization
\begin{eqnarray}
\sum_{\vK\vK'} A_{i,\vK'}^* (H_{\vK'\vK}-\varepsilon_i O_{\vK'\vK})A_{i,\vK}=0
\label{Eq:eigval}
\end{eqnarray}
Even when atoms move, this equation remains satisfied, hence variation
of the equation has to vanish.
The variation gives
\begin{eqnarray}
0=\sum_{\vK\vK'} \delta A_{i,\vK'}^* (H_{\vK'\vK}-\varepsilon_i O_{\vK'\vK})A_{i,\vK}+
 A_{i,\vK'}^* (H_{\vK'\vK}-\varepsilon_i O_{\vK'\vK})\delta A_{i,\vK}+
 A_{i,\vK'}^* (\delta H_{\vK'\vK}-\varepsilon_i \delta O_{\vK'\vK})A_{i,\vK}-
 A_{i,\vK'}^* O_{\vK'\vK}A_{i,\vK} \delta\varepsilon_i
\nonumber
\end{eqnarray}
The first two terms vanish, the term $\sum_{\vK\vK'}A_{i,\vK'}^*
O_{\vK'\vK}A_{i,\vK} =1$, hence
\begin{eqnarray}
\delta \varepsilon_i=\sum_{\vK,\vK'} A_{i,\vK'}^* (\delta H_{\vK'\vK}-\varepsilon_i \delta O_{\vK'\vK})A_{i,\vK}
\label{Eq:EVA}
\end{eqnarray}
Next we vary Hamiltonian and overlap
\begin{eqnarray}
&& \delta\braket{\chi_{\vK'}|H|\chi_{\vK}}=\braket{\delta  \chi_{\vK'}|H|\chi_{\vK}}+\braket{\chi_{\vK'}|H|\delta\chi_{\vK}}+\braket{\chi_{\vK'}|\delta  H|\chi_{\vK}}\\
&& \delta\braket{\chi_{\vK'}|\chi_{\vK}}=\braket{\delta \chi_{\vK'}|\chi_{\vK}}+\braket{\chi_{\vK'}|\delta\chi_{\vK}}
\end{eqnarray}
to obtain
\begin{eqnarray}
\delta \varepsilon_i=\sum_{\vK,\vK'} A_{i,\vK'}^*
\left(
\braket{\delta  \chi_{\vK'}|H-\varepsilon_i|\chi_{\vK}}+\braket{\chi_{\vK'}|H-\varepsilon_i|\delta\chi_{\vK}}+\braket{\chi_{\vK'}|\delta  H|\chi_{\vK}}
\right)A_{i,\vK}
\label{Eq:deltae}
\end{eqnarray}

Putting all terms together gives
\begin{eqnarray}
\delta E = \sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
\left(
\braket{\delta  \chi_{\vK'}|H-\varepsilon_i|\chi_{\vK}}+\braket{\chi_{\vK'}|H-\varepsilon_i|\delta\chi_{\vK}}+\braket{\chi_{\vK'}|\delta  H|\chi_{\vK}}
\right)A_{i,\vK} - \Tr(\rho \delta V_{KS})-\sum_\alpha\vF^{HF}_\alpha\delta \vR_\alpha
\end{eqnarray}
and hence Pulley forces are
\begin{eqnarray}
\vF^{Pulley}_\alpha = -\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
\left(
\braket{\frac{\delta \chi_{\vK'}}{\delta\vR_\alpha}  |H-\varepsilon_i|\chi_{\vK}}+
\braket{\chi_{\vK'}|H-\varepsilon_i|\frac{\delta\chi_{\vK}}{\delta\vR_\alpha}}+
\braket{\chi_{\vK'}|\frac{\delta}{\delta\vR_\alpha} H|\chi_{\vK}}\right)A_{i,\vK}
+\Tr(\rho \frac{\delta V_{KS}}{\delta\vR_\alpha})
\end{eqnarray}
which can also be written as
\begin{eqnarray}
\vF^{Pulley}_\alpha = -\sum_i f_i
\left(
\braket{\frac{\partial \psi_{i\vk}}{\partial\vR_\alpha}  |H-\varepsilon_i|\psi_{i\vk}}+
\braket{\psi_{i\vk}|H-\varepsilon_i|\frac{\partial\psi_{i\vk}}{\partial\vR_\alpha}}+
\braket{\psi_{i\vk}|\frac{\delta}{\delta\vR_\alpha} H|\psi_{i\vk}}\right)
+\Tr(\rho \frac{\delta V_{KS}}{\delta\vR_\alpha})
\end{eqnarray}

Here
\begin{eqnarray}
\braket{\psi_{i\vk}|\frac{\delta}{\delta\vR_\alpha}  H|\psi_{i\vk}}=
\braket{\psi_{i\vk}|\frac{\delta V_{KS}}{\delta\vR_\alpha} |\psi_{i\vk}}+
\braket{\psi_{i\vk}|\frac{\delta T}{\delta\vR_\alpha} |\psi_{i\vk}}
\end{eqnarray}
The first term $\sum_i f_i \braket{\psi_{i\vk}|\frac{\delta   V_{KS}}{\delta\vR_\alpha} |\psi_{i\vk}}=\Tr(\rho \frac{\delta V_{KS}}{\delta\vR_\alpha})$
cancels with the last term above, when $V_{KS}$ is treated exactly (not approximated by
spherical symmetric part).

The kinetic part $\braket{\psi_{i\vk}|\frac{\delta  T}{\delta\vR_\alpha} |\psi_{i\vk}}$ is present when the
$\braket{\chi_{vK'}|\nabla^2|\chi_{\vK}}$ jumps across MT-boundary, as there is
additional surface term.

\subsection{Core}

In core, the index is $l,m$ instead of $\vK$.  The wave functions of
core states have the following form $\chi^\alpha_{lm}(\vr-\vR_\alpha)$, hence
they move with the atom, and their derivative is
\begin{eqnarray}
\frac{\delta \chi^\alpha_{lm}(\vr-\vR_\alpha)}{\delta\vR_\alpha}=-\nabla_\vr \chi^\alpha_{lm}
\end{eqnarray}
hence we have
\begin{eqnarray}
\vF^{Pulley}_\alpha = \sum_{lm}
\left(
\braket{\nabla\chi^\alpha_{lm}  |H-\varepsilon_i|\chi^\alpha_{lm}}+
\braket{\chi^\alpha_{lm}|H-\varepsilon_i|\nabla\chi^\alpha_{lm}}-
\braket{\chi^\alpha_{lm}|\frac{\delta}{\delta\vR_\alpha} H|\chi^\alpha_{lm}}\right)
+\Tr(\rho \frac{\delta V_{KS}}{\delta\vR_\alpha})
\end{eqnarray}
In core we approximate $V_{KS}(r)$ to be spherically symmetric. It is
then easy to see that $H$ is spherically symmetric too. In fact, all
$m$'s are degenerate, hence $\sum_m \nabla \chi_{lm}^\alpha\propto
\textrm{e}_\vr$, and consequently all three terms on the left vanish,
as they are odd in space. The only nonzero term is
\begin{eqnarray}
\vF^{Pulley}_\alpha =\Tr(\rho \frac{\delta  V_{KS}}{\delta\vR_\alpha})=-\Tr(\rho \nabla_\vr V_{KS}^\alpha)
\end{eqnarray}
Note that here spherical symmetric  part ov $V_{KS}(r)$ does not
contribute, as such term appears also in the thirt term above and we
argued above that it is odd. Hence, only the non-spherical part of
$V_{KS}(\vr)$ gives contribution to the integral
\begin{eqnarray}
\vF^{Pulley}_\alpha =-\Tr(\rho_\alpha \nabla_\vr V_{KS}^{non-sph,\alpha})
\end{eqnarray}

\subsection{Valence states}

\subsubsection{Basic Derivation}

In the interstitials, we use originless plane waves, hence
\begin{eqnarray}
\frac{\delta\chi^{I}_{\vK}}{\delta \vR_\alpha}=0.
\end{eqnarray}
In MT-part, we check definition of $\chi_{\vK}^{MT}$ in
Eqs.~\ref{eq:bMT} and ~\ref{eq:alm}.
The approximate formula is
\begin{eqnarray}
\frac{\delta\chi^{MT}_{\vK}}{\delta \vR_\alpha}=i(\vK+\vk)\chi^{MT}_{\vK}-\nabla_\vr\chi^{MT}_\vK+\cdots
\end{eqnarray}
The first term comes from the phase factor of $a_{lm}$'s
Eq.~\ref{eq:alm}, while the second term is from differentiating $u_l(|\vr-\vR_\alpha|) Y_{lm}(\hat{\vr}-\hat{\vR}_\alpha)$.
There are additional terms when differentiating $a_{lm}$'s as $u_l(S)$
changes as well, but their contribution is here neglected.

We hence have
\begin{eqnarray}
\vF^{Pulley}_\alpha =
-\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
i(\vK-\vK')\braket{ \chi_{\vK'}  |H-\varepsilon_i|\chi_{\vK}}_{MT}A_{i,\vK}+
\label{eq:Pu1}\\
+\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^* \left(
\braket{\nabla_\vr \chi_{\vK'}  |H-\varepsilon_i|\chi_{\vK}}_{MT}
+\braket{\chi_{\vK'}|H-\varepsilon_i|\nabla_\vr\chi_{\vK}}_{MT}
\right)A_{i,\vK} -
\label{eq:Pu2}\\
-\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^* \left(
%
\braket{\chi_{\vK'}|\frac{\delta T}{\delta\vR_\alpha} |\chi_{\vK}} +
\braket{\chi_{\vK'}|\frac{\delta V_{KS}}{\delta\vR_\alpha} |\chi_{\vK}}\right)A_{i,\vK}
%
+\Tr(\rho \frac{\delta V_{KS}}{\delta\vR_\alpha})
\label{eq:Pu3}
\end{eqnarray}

First we simplify Eq.~\ref{eq:Pu2}. We split $H-\varepsilon=V_{KS}+T-\varepsilon$ and simplify
\begin{eqnarray}
\int_{MT} d^3r\left(  (\nabla_\vr\chi^*_{\vK'+\vk}) (V_{KS}+T-\varepsilon_i)\chi_{\vK+\vk}+
\chi^*_{\vK'+\vk}(V_{KS}+T-\varepsilon_i)\nabla_\vr\chi_{\vK+\vk}\right)=\\
%\int_{MT} d^3r \nabla_\vr \left( \chi^*_{\vK'+\vk} \chi_{\vK+\vk}  \right) V_{KS}+
%\int_{MT} d^3r\left(  \nabla_\vr\chi^*_{\vK'+\vk} (T-\varepsilon_i)\chi_{\vK+\vk}+
%\chi^*_{\vK'+\vk}(T-\varepsilon_i)\nabla_\vr\chi_{\vK+\vk}\right)=\\
\int_{MT} d^3r V_{KS} \nabla_\vr \left( \chi^*_{\vK'+\vk} \chi_{\vK+\vk}  \right)+
\int_{MT} d^3r \nabla_\vr \left( \chi^*_{\vK'+\vk} (T-\varepsilon_i)\chi_{\vK+\vk}\right)
\end{eqnarray}
The last term is because $\nabla$ comutes with $\nabla^2$, i.e,
\begin{eqnarray}
\int \nabla\chi^* (-\nabla^2\chi)+\chi^*(-\nabla^2)\nabla\chi=\int \nabla(\chi^*(-\nabla^2)\chi)
\end{eqnarray}
We thus have
\begin{eqnarray}
\int_{MT} d^3r\left(  \nabla_\vr\chi^*_{\vK'+\vk} (H-\varepsilon_i)\chi_{\vK+\vk}+
\chi^*_{\vK'+\vk}(H-\varepsilon_i)\nabla_\vr\chi_{\vK+\vk}\right)=\\
\int_{MT} d^3r V_{KS} \nabla_\vr \left( \chi^*_{\vK'+\vk} \chi_{\vK+\vk}  \right)+
\oint_{r=R_{MT}^-} d\vec{S}  \chi^*_{\vK'+\vk} (T-\varepsilon_i)\chi_{\vK+\vk}
\end{eqnarray}
Inserting this simplifiaction into Eq.~\ref{eq:Pu2}, we get
\begin{eqnarray}
Eq.~\ref{eq:Pu2}=\int_{MT} d^3 V_{KS}(\vr) \nabla_\vr \rho^{val}(\vr) +
\sum_i  f_i \sum_{\vK\vK'}A^*_{i,\vK'}A_{i,\vK} \oint_{r=R_{MT}^-} d\vec{S}  \chi^*_{\vK'+\vk} (T-\varepsilon_i)\chi_{\vK+\vk}
\label{eq:Pu2n}
\end{eqnarray}

Next we simplify Eq.~\ref{eq:Pu3}. The second and the third term
cancel, as we compute density by
$\rho(\vr)=\sum_i f_i \sum_{\vK\vK'}A_{i,\vK'}^* \chi^*_{\vK'}(\vr)
A_{i,\vK} \chi_{\vK}(\vr)$, hence for any function $X(\vr)$ we have
$\Tr(X(\vr)\rho(\vr))=\sum_i f_i \sum_{\vK\vK'}A_{i,\vK'}^* A_{i,\vK}
\int d^3r \chi^*_{\vK'}(\vr) X(\vr)\chi_{\vK}(\vr) $.
%
We are hence left with the first term in Eq.~\ref{eq:Pu3} only.
When we integrate a function whith discontinuity at the
MT-boundary, we need to take into account an extra term due to the
jump. One can derive the following identity (see section~\ref{discontinuity})
\begin{eqnarray}
\braket{\chi_\mu|\delta T|\chi_\nu}=\delta\vR_\alpha \oint_{RMT}
  d\vec{S}\left[ (\chi_\mu^* T \chi_\nu)_{MT} -(\chi_\mu^* T \chi_\nu)_I \right]
\end{eqnarray}
This term is just because $\chi_\mu(\vr)T\chi_\nu(\vr)$ is not continuous across the boundary,
and hence the difference at the boundary adds an extra term to the
ingeral. We thus conclude
\begin{eqnarray}
Eq.~\ref{eq:Pu3}=-\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*A_{i,\vK}
\oint_{RMT}d\vec{S}
\left[
(\chi^*_{\vK'+\vk}(\vr) T  \chi_{\vK+\vk}(\vr))_{MT}-
(\chi_{\vK'+\vk}(\vr) T  \chi_{\vK+\vk}(\vr))_I
 \right]
\end{eqnarray}
since $\chi_{\vk+\vK}(\vr)$ are continuous across MT-boundary, we can
also write
\begin{eqnarray}
Eq.~\ref{eq:Pu3}=-\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*A_{i,\vK}
\left[
\oint_{r=R_{MT}^-}d\vec{S}
\chi^*_{\vK'+\vk}(\vr)(T-\varepsilon_i) \chi_{\vK+\vk}(\vr)
-\oint_{r=R_{MT}^+}d\vec{S}
\chi^*_{\vK'+\vk}(\vr)(T-\varepsilon_i) \chi_{\vK+\vk}(\vr)
 \right]
\label{eq:Pu3n}
\end{eqnarray}
Finally, we notice that the second term in \ref{eq:Pu2n} and the
MT-part of Eq.~\ref{eq:Pu3n} cancel, hence we obtain
\begin{eqnarray}
Eq.~\ref{eq:Pu2} + Eq.~\ref{eq:Pu3}=
\int_{MT} d^3 V_{KS}(\vr) \nabla_\vr \rho^{val}(\vr)+
\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*A_{i,\vK}
\oint_{r=R_{MT}^+}d\vec{S}
\chi^*_{\vK'+\vk}(\vr)(T-\varepsilon_i)\chi_{\vK+\vk}(\vr)
\label{eq:Pu4}
\end{eqnarray}
Notice that the functions $\chi_{\vK+\vk}$, which appear in the integral, are evaluated
in the interstitial, hence the symbol $r=R_{MT}^+$.

The final result for Pulley forces, which is the sum of
Eqs.~\ref{eq:Pu1}, \ref{eq:Pu2} and \ref{eq:Pu3} is
\begin{eqnarray}
\vF^{Pulley}_\alpha =
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
(\vK-\vK')\braket{ \chi_{\vK'}  |H-\varepsilon_i|\chi_{\vK}}_{MT}A_{i,\vK}+
\label{eq:Pul1}\\
+
\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*A_{i,\vK}
\oint_{r=R_{MT}^+}d\vec{S}
\chi^*_{\vK'+\vk}(\vr)(T-\varepsilon_i) \chi_{\vK+\vk}(\vr)+
\label{eq:Pul2}\\
+\int_{MT} d^3 V_{KS}(\vr) \nabla_\vr \rho^{val}(\vr)
\label{eq:Pul3}
\end{eqnarray}

In the MT part, the kinetic part $T$ does not have the form ($\nabla\cdot\nabla$) proposed in
Sec.~\ref{APWlo} (but $-\nabla^2$), hence we need to write
\begin{eqnarray}
Eq.~\ref{eq:Pul1} =
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
(\vK-\vK')\braket{ \chi_{\vK'}  |-\nabla^2+V_{KS}-\varepsilon_i|\chi_{\vK}}_{MT}A_{i,\vK}-
\label{eq:Pul1a}
\\
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^* A_{i,\vK}
(\vK-\vK') \oint_{r=R_{MT}^-} d\vec{S} \chi_{\vK'+\vk}^*(\vr)  \nabla_\vr\chi_{\vK+\vk}(\vr)
\label{eq:Pul1b}
\end{eqnarray}
Moreover, the MT part is usually broaken into two parts, the
spherically symmetric potential $V_{KS}^{sym}(r)$ and the
non-symmetryc part $V_{KS}^{n-sym}(\vr)$, i.e.,
$$V_{KS}(\vr)=V_{KS}^{sym}(r)+V_{KS}^{n-sym}(\vr)$$
hence we can write
\begin{eqnarray}
Eq.~\ref{eq:Pul1} =
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
(\vK-\vK')\braket{ \chi_{\vK'}  |-\nabla^2+V^{sym}_{KS}(r)-\varepsilon_i|\chi_{\vK}}_{MT}A_{i,\vK}-
\label{eq:Pul1a}\\
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
(\vK-\vK')\braket{ \chi_{\vK'}  |V_{KS}^{n-sym}(\vr)|\chi_{\vK}}_{MT}A_{i,\vK}-
\label{eq:Pul1b}
\\
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^* A_{i,\vK}
(\vK-\vK') \oint_{r=R_{MT}^-} d\vec{S} \chi_{\vK'+\vk}^*(\vr)  \nabla_\vr\chi_{\vK+\vk}(\vr)
\label{eq:Pul1c}
\end{eqnarray}

In the interstitails, $T$ has the form ($\nabla\cdot\nabla$) proposed in Sec.~\ref{APWlo},
hence Eq.~\ref{eq:Pul2} takes the form
\begin{eqnarray}
Eq.~\ref{eq:Pul2}=
\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*A_{i,\vK}   [(\vK+\vk)(\vK'+\vk)-\varepsilon_i] \oint_{r=R_{MT}^+}d\vec{S} \chi^*_{\vK'+\vk}(\vr)\chi_{\vK+\vk}(\vr) =\\
=\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*A_{i,\vK}  [(\vK+\vk)(\vK'+\vk)-\varepsilon_i] R_{MT}^2 \int d\Omega \frac{e^{i(\vK-\vK')\vr}}{V_{cell}}\vec{e}_\vr=\\
=\sum_i f_i \sum_{\vK,\vG} A_{i,\vK-\vG}^*A_{i,\vK}  [(\vK+\vk)(\vK-\vG+\vk)-\varepsilon_i] R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr
\label{eq:Pul2a}
 \end{eqnarray}
where we used $\vK'=\vK-\vG$.

Using the above derived identities
Eqs.\ref{eq:Pul1a},\ref{eq:Pul1b},\ref{eq:Pul1c},\ref{eq:Pul2a}, we transform
$\vF^{Pulley}$ to
\begin{eqnarray}
\vF^{Pulley}_\alpha =
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
(\vK-\vK')\braket{ \chi_{\vK'}  |-\nabla^2+V^{sym}_{KS}(r)-\varepsilon_i|\chi_{\vK}}_{MT}A_{i,\vK}-
\label{eq:Pule1}\\
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
(\vK-\vK')\braket{ \chi_{\vK'}  |V_{KS}^{n-sym}(\vr)|\chi_{\vK}}_{MT}A_{i,\vK}-
\label{eq:Pule2}
\\
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^* A_{i,\vK}
(\vK-\vK') \oint_{r=R_{MT}^-} d\vec{S} \chi_{\vK'+\vk}^*(\vr)  \nabla_\vr\chi_{\vK+\vk}(\vr)
\label{eq:Pule3}
\\
+\sum_i f_i \sum_{\vK,\vG} A_{i,\vK-\vG}^*A_{i,\vK}  [(\vK+\vk)(\vK-\vG+\vk)-\varepsilon_i] R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr
\label{eq:Pule4}\\
+\int_{MT} d^3 V_{KS}(\vr) \nabla_\vr \rho^{val}(\vr)
\label{eq:Pule5}
\end{eqnarray}

\subsubsection{Implementation of term ~\ref{eq:Pule1}}

The first contribution to $\vF^{Pulley}$
we are considering is Eq. ~\ref{eq:Pule1}
\begin{eqnarray}
\vF(1)^{Pulley}_\alpha =
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
(\vK-\vK')\braket{ \chi_{\vK'}  |-\nabla^2+V^{sym}_{KS}(r)-\varepsilon_i|\chi_{\vK}}_{MT}A_{i,\vK}
\end{eqnarray}

We first repeat Eq.~\ref{Eq:HmE}, which gives spherically symetric
part of Hamiltonian in the MT-part:
\begin{eqnarray}
\braket{\chi_{\vK'}|-\nabla^2+V^{sym}_{KS}(r)-\varepsilon|\chi_\vK}&=&
a^{\vK' *}_{lm}  a_{lm}^{\vK}(E_\nu-\varepsilon)  +
b^{\vK' *}_{lm}  b_{lm}^\vK(E_\nu-\varepsilon)\braket{\dot{u}_l|\dot{u}_l} +
\frac{1}{2}[a^{\vK' *}_{lm} b_{lm}^\vK +b_{lm}^{\vK'*} a^{\vK}_{lm} ]+
%
\nonumber\\
&+&
c^{\vK' *}_{lm}  c_{lm}^\vK(E_{\mu}-\varepsilon) +
\frac{1}{2}[a^{\vK' *}_{lm} c_{lm}^\vK + c^{\vK' *}_{lm} a_{lm}^\vK ]  (E_{\mu}+E_\nu-2\varepsilon)\braket{u|u_{LO}} +
\nonumber\\
&+&
\frac{1}{2}[c^{\vK' *}_{lm}  b_{lm}^\vK + b^{\vK' *}_{lm}  c_{lm}^\vK ][ \braket{u_{LO}|u_l}  + (E_\mu+E_\nu-2\varepsilon)\braket{u_{LO}|\dot{u}_l} ]
\label{Eq:HmEn}
\end{eqnarray}
Clearly, we can split the sum over $\vK$ and $\vK'$ into two
indepedent sums which take $O(N)$ time.[We want to avoid $O(N^2)$
scaling, since there are very many number of plane waves $\vK$].

We first define (compute) the following quantities
\begin{eqnarray}
a_{i,lm}=\sum_\vK A_{i\vK} \; a_{lm}^\vK\\
\vcA_{i,lm}=\sum_\vK \vK \; A_{i\vK} \; a_{lm}^\vK
\end{eqnarray}
which take $O(N)$ time to compute. Here $A_{i,\vK}$ are eigenvectors corresponding to the Kohn-Sham
energy $\varepsilon_i$. We assume corresponding expression for $b_{i,lm}$,
$c_{i,lm}$, $\vcB_{i,lm}$, $\vcC_{i,lm}$.

The quadratic terms of the form $a^*_{lm} a_{lm}$ become
\begin{eqnarray}
\sum_{\vK\vK'} (\vK-\vK') A_{i\vK'}^*  a^{\vK' *}_{lm}  a_{lm}^{\vK}  A_{i\vK} =
a_{i,lm}^* \vcA_{i,lm} - \vcA^*_{i,lm}  a_{i,lm} =
2i\; \Im\{ a_{i,lm}^* \vcA_{i,lm} \}
\end{eqnarray}
while those of the form $a^*_{lm}b_{lm}+b^*_{lm} a_{lm}$ become
\begin{eqnarray}
\sum_{\vK\vK'} (\vK-\vK') A_{i\vK'}^*  \frac{1}{2}[a^{\vK' *}_{lm}  b_{lm}^{\vK} + b^{\vK' *}_{lm}  a_{lm}^{\vK} ]A_{i\vK} =
\frac{1}{2} [a_{i,lm}^* \vcB_{i,lm} - \vcA^*_{i,lm} b_{i,lm} +
  b^*_{i,lm} \vcA_{i,lm} - \vcB^*_{i,lm} a_{i,lm}]= \nonumber\\
=i\; \Im\{ a_{i,lm}^* \vcB_{i,lm} + b_{i,lm}^* \vcA_{i,lm}  \}
\end{eqnarray}
The entire term can be expressed in this way. We start from
Eq.~\ref{Eq:HmEn} and derive
\begin{eqnarray}
&& \sum_{\vK\vK'} (\vK-\vK')  A^*_{i\vK'}\braket{\chi_{\vK'}|-\nabla^2+V_{KS}^{sph}(r)-\varepsilon_i|\chi_\vK}_{MT}A_{i\vK}=
\nonumber\\
&& i\Im\left\{
2 a_{i,lm}^* \vcA_{i,lm} \; (E_\nu-\varepsilon_i)  +
2  b_{i,lm}^* \vcB_{i,lm} \; (E_\nu-\varepsilon_i)\braket{\dot{u}_l|\dot{u}_l} +
 a_{i,lm}^* \vcB_{i,lm} + b_{i,lm}^* \vcA_{i,lm}
\right\}+
%
\nonumber\\
&+& i\Im\left\{
2 c^*_{i,lm}  \vcC_{i,lm} \; (E_{\mu}-\varepsilon_i) \braket{u_{LO}|u_{LO}}+
[a^*_{i,lm} \vcC_{i,lm} + c^*_{i,lm} \vcA_{i,lm} ]  (E_{\mu}+E_\nu-2\varepsilon_i)\braket{u|u_{LO}}
\right\}+
\nonumber\\
&+& i\Im\left\{
[c^*_{i,lm}  \vcB_{i,lm} + b^*_{i,lm}  \vcC_{i,lm} ][ \braket{u_{LO}|u_l}  + (E_\mu+E_\nu-2\varepsilon_i)\braket{u_{LO}|\dot{u}_l} ]
\right\}
\end{eqnarray}
which finally gives
\begin{eqnarray}
&&\vF(1)^{Pulley}_\alpha= -i \sum_i f_i \sum_{\vK\vK'} (\vK-\vK')  A^*_{i\vK'}\braket{\chi_{\vK'}|-\nabla^2+V_{KS}^{sym}-\varepsilon_i|\chi_\vK}_{MT}A_{i\vK}=
\label{Eq:Term1}\\
&& \sum_i f_i\; \Im\left\{
\left[
2 a_{i,lm}^* \; (E_\nu-\varepsilon_i)  +
b_{i,lm}^*  +
c^*_{i,lm} (E_{\mu}+E_\nu-2\varepsilon_i)\braket{u|u_{LO}}
\right]
\vcA_{i,lm}
\right\}+
\nonumber\\
&+& \sum_i f_i\; \Im\left\{
\left[
 a_{i,lm}^* +
2  b_{i,lm}^* \;  (E_\nu-\varepsilon_i)\braket{\dot{u}_l|\dot{u}_l} +
c^*_{i,lm}  [ \braket{u_{LO}|u_l}  + (E_\mu+E_\nu-2\varepsilon_i)\braket{u_{LO}|\dot{u}_l} ]
\right]
\vcB_{i,lm}
\right\}+
%
\nonumber\\
&+&\sum_i f_i\; \Im\left\{
\left[
b^*_{i,lm}   \braket{u_{LO}|u_l}  +
[a^*_{i,lm} \braket{u_{LO}|u_l} + b^*_{i,lm} \braket{u_{LO}|\dot{u}_l} ](E_{\mu}+E_\nu-2\varepsilon_i)+
2 c^*_{i,lm}  \; (E_{\mu}-\varepsilon_i) \braket{u_{LO}|u_{LO}}
\right]
\vcC_{i,lm}
\right\}
\nonumber
\end{eqnarray}
This is implemented in function \verb fomai1 .
Note that $\vcA$,$\vcB$ and $\vcC$ are called
$aalm$,$bblm$, and $cclm$.
 Also note that $\braket{\dot{u}|\dot{u}}=pei$, $\braket{u_{LO}|u}=pi12lo$, $\braket{u_{LO}|\dot{u}}=pe12lo$, $\braket{u_{LO}|u_{LO}}=pr12lo$.

This force is called \verb fsph  and is coded in \verb Force1 .

\subsubsection{Implementation of term ~\ref{eq:Pule2}}

The second term we are considering is Eq. ~\ref{eq:Pule2}
\begin{eqnarray}
\vF(2)^{Pulley}_\alpha =
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
(\vK-\vK')\braket{ \chi_{\vK'}  |V_{KS}^{n-sym}(\vr)|\chi_{\vK}}_{MT}A_{i,\vK}-
\label{eq:Pule2n}
\end{eqnarray}

% For solving the Dirac equation inside MT-spheres, we use spherically averaged
% KS-potential. The non-spherical symmetric part of the equation
% \begin{eqnarray}
% \sum_{\vK,\vK'} (\vK-\vK') A_{i\vK'}^* \braket{\chi_{\vK'}|H-\varepsilon_i|\chi_\vK}_{MT}A_{i\vK}
% \end{eqnarray}
% is
% \begin{eqnarray}
% \sum_{\vK,\vK'} (\vK-\vK') A_{i\vK'}^* \braket{\chi_{\vK'}|V^{n-sym}|\chi_\vK}_{MT}A_{i\vK}
% \end{eqnarray}

In file case.nsh, we read non-spherical symmetric potential, which is
given in the following form
\begin{eqnarray}
V^{non-sph}_{\kappa_1 l_1 m_1 \kappa_2 l_2 m_2} = \int d^3 r Y^*_{l_1 m_1}(\hat{\vr}) u^{\kappa_1} V^{n-sym}(\vr) u^{\kappa_2}Y_{l_2 m_2}(\hat{\vr})
\end{eqnarray}

The data in case.nsh contains the following matrix elements
\begin{eqnarray}
\braket{u|V|u} \rightarrow tuu\\
\braket{u|V|\dot{u}} \rightarrow tud\\
\braket{\dot{u}|V|u} \rightarrow tdu\\
\braket{\dot{u}|V|\dot{u}}\rightarrow tdd\\
\cdots
\end{eqnarray}

To evaluate the term, we substutute the definition for $\chi_\vK$ to obtain
\begin{eqnarray}
&& \sum_{\vK,\vK'} (\vK-\vK') A_{i\vK'}^* \braket{\chi_{\vK'}|V^{n-sym}|\chi_\vK}_{MT}A_{i\vK} =\\
&& \sum_{\vK,\vK'} (\vK-\vK') A_{i\vK'}^* \braket{
Y_{l_1 m_1}\sum_{\kappa_1} a_{l_1 m_1}^{\kappa_1,\vK'} u^{\kappa_1}_{l_1}|V^{n-sym}|
Y_{l_2 m_2}\sum_{\kappa_2} a_{l_2 m_2}^{\kappa_2,\vK} u^{\kappa_2}_{l_2}}A_{i\vK}
\end{eqnarray}
which simplifies to
\begin{eqnarray}
&&\sum_{\vK,\vK'} (\vK-\vK') A_{i\vK'}^* \braket{\chi_{\vK'}|V^{n-sym}|\chi_\vK}_{MT}A_{i\vK} =
\\
&& \sum_{\kappa_1 l_1 m_1,\kappa_2 l_2 m_2}
a_{l_1 m_1}^{*\kappa_1,i}\vcA_{l_2 m_2}^{\kappa_2,i}
V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}
-
\vcA_{l_1 m_1}^{*\kappa_1,i}a_{l_2 m_2}^{\kappa_2,i}
V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}=\\
&& 2i\Im\left\{
\sum_{\kappa_1 l_1 m_1,\kappa_2 l_2 m_2}
a_{l_1 m_1}^{*\kappa_1,i}\vcA_{l_2 m_2}^{\kappa_2,i}
V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}
\right\}
\end{eqnarray}
hence, we have
\begin{eqnarray}
&&\vF(2)^{Pulley}_\alpha=
\sum_i f_i \sum_{\kappa_1 l_1 m_1,\kappa_2 l_2 m_2}
2\Im
\left\{
a_{l_1 m_1}^{*\kappa_1,i}
V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}
\vcA_{l_2 m_2}^{\kappa_2,i}
\right\}
\end{eqnarray}
This is implemented in \verb fomai1  and has name \verb fnsp .
Note that $\vcA,\vcB,\vcC$ are called
\verb aalm, \verb bblm, \verb cclm   and matrix elements of $V$ are called tuu,tud,tdu,....

Implementation builds the following quantity
\begin{eqnarray}
afac(\kappa_2, l_1 m_1,l_2 m_2) = \sum_{\kappa_1} a_{l_1 m_1}^{*\kappa_1,i} V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}
\end{eqnarray}
and evaluates
\begin{eqnarray}
\vF(2)^{Pulley}_\alpha=\sum_i f_i \sum_{l_1 m_1,l_2 m_2, \kappa_2} 2\Im[afac(\kappa_2, l_1 m_1,l_2 m_2) \vcA_{l_2 m_2}^{\kappa_2,i} ]
\end{eqnarray}

It is implemented in \verb Force2 .

\subsubsection{Implementation of term ~\ref{eq:Pule3}}

Next we consider Eq.~\ref{eq:Pule3}, which is
\begin{eqnarray}
\vF(3)^{Pulley}_\alpha =
-i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^* A_{i,\vK}
(\vK-\vK') \oint_{r=R_{MT}^-} d\vec{S} \chi_{\vK'+\vk}^*(\vr)  \nabla_\vr\chi_{\vK+\vk}(\vr)
\label{eq:Pule3n}
\end{eqnarray}
We know that the therm should be real, therefore we will symmetrize it
to make it real
\begin{eqnarray}
\vF(3)^{Pulley}_\alpha = -\frac{i}{2}\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^* A_{i,\vK}
(\vK-\vK') \oint_{r=R_{MT}^-} d\vec{S}
[\chi_{\vK'+\vk}^*(\vr)  \nabla_\vr\chi_{\vK+\vk}(\vr) +  \chi_{\vK+\vk}(\vr) \nabla \chi_{\vK'+\vk}^*(\vr)  ]
\label{eq:Pule3n}
\end{eqnarray}
which is equal to
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=-\frac{i}{2}\sum_{\vk,i} f_i
\sum_{\vK,\vK'} A^*_{i\vK'} A_{i\vK}\;
(\vK-\vK') R_{MT}^2
\oint_{r=R_{MT^-}} d\Omega\;
[
\chi_{\vK'+\vk}^*(\vr) \frac{\partial}{\partial r}\chi_{\vK+\vk}+
\chi_{\vK+\vk}(\vr)  \frac{\partial}{\partial r}\chi_{\vK'+\vk}^*(\vr)
]
\end{eqnarray}
and inserting expression for $\chi$ we get
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=-\frac{i}{2}\sum_{\vk,i} f_i
\sum_{\vK,\vK'} A^*_{i\vK'} A_{i\vK}\;
(\vK-\vK') R_{MT}^2
\sum_{l,m,\kappa',\kappa}
a_{lm,\vK'}^{\kappa'\,*} u_l^{\kappa'} a_{lm,\vK}^\kappa  {u'}_l^\kappa+
a_{lm,\vK}^{\kappa'} u_l^{\kappa'} a^{\kappa\,*}_{lm,\vK'} {u'}_l^\kappa
\end{eqnarray}
and summing over $\vK$ and $\vK'$ gives
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=-\frac{i}{2}\sum_{\vk,i} f_i
R_{MT}^2
\sum_{l,m,\kappa',\kappa}
[
a_{i,lm}^{\kappa'\,*} u_l^{\kappa'} \vcA_{i,lm}^\kappa  {u'}_l^\kappa+
\vcA_{i,lm}^{\kappa'} u_l^{\kappa'} a^{\kappa\,*}_{i,lm}  {u'}_l^\kappa
-\vcA_{i,lm}^{\kappa'\,*} u_l^{\kappa'} a_{i,lm}^\kappa  {u'}_l^\kappa
-a_{i,lm}^{\kappa'} u_l^{\kappa'} \vcA^{\kappa\,*}_{i,lm} {u'}_l^\kappa
]
\end{eqnarray}
which can be simplified to
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=R_{MT}^2 \sum_{\vk,i} f_i
\sum_{l,m,\kappa',\kappa}
\Im[a_{i,lm}^{\kappa'\,*} u_l^{\kappa'} \vcA_{i,lm}^\kappa  {u'}_l^\kappa
-\vcA_{i,lm}^{\kappa'\,*} u_l^{\kappa'} a_{i,lm}^\kappa  {u'}_l^\kappa]
\end{eqnarray}

We can then define the following quantities
\begin{eqnarray}
kinfac(1,ilm) = \sum_{\kappa} a_{i,lm}^{\kappa} u_l^{\kappa}(R_{MT})\\
kinfac(2,ilm) = \sum_\kappa a_{i,lm}^\kappa  {u'}_l^\kappa(R_{MT})\\
kinfac(3,ilm) = \sum_\kappa \vcA_{i,lm}^\kappa  {u'}_l^\kappa(R_{MT})\\
kinfac(4,ilm) = \sum_{\kappa} \vcA_{i,lm}^{\kappa} u_l^{\kappa}(R_{MT})
\end{eqnarray}
and write
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=R_{MT}^2 \sum_{\vk,i} f_i \sum_{l,m}\Im[
kinfac^*(1,ilm) kinfac(3,ilm)-kinfac^*(4,ilm) kinfac(2,ilm)]
\end{eqnarray}

This part of the force is named \verb fsph2  and is coded in
\verb fomai1  within Wien2k, and in \verb Force3  in my code.

\subsubsection{Implementation of term ~\ref{eq:Pule4}}

Finally we discuss implementation of Eq.~\ref{eq:Pule4}:
\begin{eqnarray}
\vF(4)^{Pulley}_\alpha =
\sum_i f_i \sum_{\vK,\vG} A_{i,\vK-\vG}^*A_{i,\vK}  [(\vK+\vk)(\vK-\vG+\vk)-\varepsilon_i] R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr
\label{eq:Pule4n}
\end{eqnarray}

The convolution in $\vK$ needs quadratic amount of time ($O(N^2)$). By using FFT
and turning it into product in real space, it takes only $N\log(N)$
time, hence we will use FFT for the following quantities
\begin{eqnarray}
&&\vec{X}_i(\vr)=\sum_\vK A_{i,\vK}(\vK+\vk)e^{i\vK\vr}\\
&& Y_i(\vr)=\sum_\vK A_{i,\vK}e^{i\vK\vr}
\end{eqnarray}
The inverse FFT should then be used to obtain aternative
representation for convolution
\begin{eqnarray}
\vF(4)^{Pulley}_\alpha  =
\sum_i f_i\int d^3r e^{-i\vK\vr}[\vec{X}_i^*(\vr)\vec{X}_i(\vr)-\varepsilon_i Y_i^*(\vr)Y_i(\vr)] R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr
 \end{eqnarray}
Finally, one can check that
\begin{equation}
\int d\Omega e^{i\vG\vr}\vec{e}_\vr={4\pi } \frac{\vG}{|\vG|}\;j_1(|\vG|R_{MT}) i e^{i\vG\vr_\alpha}
\end{equation}

This code appears in \verb Force_surface .

\subsubsection{Implementation of term ~\ref{eq:Pule5}}

The last part in the Eq.~\ref{eq:Pule5} is
% \begin{eqnarray}
% \vF(5)^{Pulley}_\alpha = \int_{MT} d^3 V_{KS}(\vr) \nabla_\vr  \rho^{val}(\vr) \label{eq:Pule5n}
% \end{eqnarray}
% and I did not find it in the code yet....
%
%\subsection{Force terms 2}
%
%The following term is needed in LAPW force calculation
\begin{eqnarray}
\vF(5)^{Pulley}_\alpha=\int_{MT} d^3r V_{KS}(\vr) \nabla\rho(\vr) = \sum_{l m l' m'}\int d^3r
  V_{l'm'}(r) Y^*_{l'm'}(\hat{\vr}) \nabla (\rho_{lm}(r) Y_{lm}(\hat{\vr}))
\end{eqnarray}

The operator $\nabla$ is spheric harmonics is
\begin{eqnarray}
\nabla f = \vec{e}_r\frac{\partial}{\partial r} +\frac{\sin\theta}{r}
\left(\begin{array}{c}
-\cos\theta\cos\phi\\
-\cos\theta\sin\phi\\
\sin\theta
\end{array}
\right)
\frac{\partial}{\partial (\cos\theta)} +
\frac{1}{r\sin\theta}
\left(\begin{array}{c}
-\sin\phi\\
 \cos\phi\\
0
\end{array}
\right)
\frac{\partial}{\partial\phi}=
\vec{e}_r\frac{\partial}{\partial r} +\frac{1}{r} \nabla_{\theta\phi}
\end{eqnarray}
The last form emphasizes that $\nabla$ has the radial part and a angle
part. Using this decomposition, we can write
\begin{eqnarray}
\vF(5)^{Pulley}_\alpha=\int d^3r V_{KS}(\vr) \nabla\rho(\vr) &=&
 \sum_{l m l' m'}\int_0^\infty dr r^2  V_{l'm'}(r) \frac{d \rho_{lm}(r)}{dr} \int  d\Omega Y^*_{l'm'}(\hat{\vr})  \vec{e}_r Y_{lm}(\hat{\vr})\\
&+&\sum_{l m l' m'}\int_0^\infty dr r^2   \frac{V_{l'm'}(r) \rho_{lm}(r)}{r} \int  d\Omega Y^*_{l'm'}(\hat{\vr})  \nabla_{\theta\phi} Y_{lm}(\hat{\vr})
\end{eqnarray}

In the following, we will need these integrals:
\begin{eqnarray}
I^1_{l'm'lm} &\equiv& \int d\Omega Y^*_{l'm'}(\hat{\vr}) \vec{e}_\vr  Y_{lm}(\hat{\vr}) \\
I^2_{l'm'lm} &\equiv& \int d\Omega Y^*_{l'm'}(\hat{\vr}) (r\nabla Y_{lm}(\hat{\vr})) \\
I^3_{l'm'lm} &\equiv& \int d\Omega (r\nabla Y^*_{l'm'}(\hat{\vr}))\cdot ( r\nabla  Y_{lm}(\hat{\vr})) \vec{e}_\vr\\
\end{eqnarray}

We first compute the following integral
\begin{eqnarray}
&&I^1_{l'm'lm}\equiv\int d\Omega Y^*_{l'm'}(\hat{\vr}) \vec{e}_r Y_{lm}(\hat{\vr})=\\
&&(-1)^{m+m'}
\sqrt{\frac{(2l+1)(l-m)!(2l'+1)(l'-m')!}{4\pi(l+m)! 4\pi (l'+m')!}}
\int_{-1}^1 dx
 P_{l'}^{m'}(x) P_l^m(x)
\left(
\begin{array}{c}
\sqrt{1-x^2} \int_0^{2\pi} d\phi\;  e^{i(m-m')\phi}\cos\phi \\
\sqrt{1-x^2} \int_0^{2\pi} d\phi\;  e^{i(m-m')\phi}\sin\phi\\
x \int_0^{2\pi} d\phi\;  e^{i(m-m')\phi}
\end{array}
\right)
\end{eqnarray}

\begin{eqnarray}
I^1_{l'm'lm}=(-1)^{m+m'}\pi
\sqrt{\frac{(2l+1)(l-m)!(2l'+1)(l'-m')!}{4\pi(l+m)! 4\pi (l'+m')!}}
\int_{-1}^1 dx
 P_{l'}^{m'}(x) P_l^m(x)
 \left(
\begin{array}{c}
\sqrt{1-x^2} \delta_{m'=m\pm 1}\\
\mp i \sqrt{1-x^2}  \delta_{m'=m\pm 1}\\
2 x \delta_{mm'}
\end{array}
\right)
\end{eqnarray}
which is equal to
\begin{eqnarray}
I^1_{l'm'lm}=
\pi \delta_{m'=m\pm 1}
\sqrt{\frac{(2l+1)(l-m)!(2l'+1)(l'-m\mp 1)!}{4\pi(l+m)! 4\pi (l'+m\pm 1)!}}
\int_{-1}^1 dx
 P_{l'}^{m\pm 1}(x) P_l^m(x)
\sqrt{1-x^2}
 \left(
\begin{array}{c}
-1 \\
\pm i
\\
0\end{array}
\right)
\nonumber\\
+
2\pi \delta_{mm'}
\sqrt{\frac{(2l+1)(l-m)!(2l'+1)(l'-m)!}{4\pi(l+m)! 4\pi (l'+m)!}}
\int_{-1}^1 dx
 P_{l'}^{m}(x) P_l^m(x) x
 \left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\end{eqnarray}
With the help of the following well known recursion relation
\begin{eqnarray}
&& \sqrt{1-x^2}P_l^m = \frac{1}{2l+1}\left[P_{l-1}^{m+1}-P_{l+1}^{m+1}\right]
\\
&& \sqrt{1-x^2}P_l^m = \frac{1}{2l+1}
\left[(l-m+1)(l-m+2)P_{l+1}^{m-1}-(l+m-1)(l+m)P_{l-1}^{m-1}\right]
\\
&& x P_l^m = \frac{1}{2l+1} \left[
(l-m+1)P_{l+1}^m+(l+m)P_{l-1}^m
\right]
\end{eqnarray}
we arrive at
\begin{eqnarray}
I^1_{l'm'lm}=
\left(
\begin{array}{c}
-1\\
i\\
0
\end{array}
\right)
\frac{1}{2}\left[
\delta_{l'=l-1}
\sqrt{\frac{(l-m)(l-m-1)}{(2l+1)(2l-1)}}-
\delta_{l'=l+1}
\sqrt{\frac{(l+m+1)(l+m+2)}{(2l+1)(2l+3)}}
\right]\delta_{m'=m+1}
+\\+
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}\left[
\delta_{l'=l+1}
\sqrt{\frac{(l-m+1)(l-m+2)}{(2l+1)(2l+3)}}-
\delta_{l'=l-1}
\sqrt{\frac{(l+m)(l+m-1)}{(2l+1)(2l-1)}}
\right]\delta_{m'=m-1}
+\\+
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\left[
\delta_{l'=l+1}
\sqrt{\frac{(l-m+1)(l+m+1)}{(2l+1)(2l+3)}}+
\delta_{l'=l-1}
\sqrt{\frac{(l+m)(l-m)}{(2l-1)(2l+1)}}
\right]\delta_{m'=m}
\end{eqnarray}

Let's define
\begin{eqnarray}
a(l,m)=\sqrt{\frac{(l+m+1)(l+m+2)}{(2l+1)(2l+3)}}\\
f(l,m)=\sqrt{\frac{(l+m+1)(l-m+1)}{(2l+1)(2l+3)}}\\
\end{eqnarray}

and rewrite
\begin{eqnarray}
I^1_{l'm'lm}=
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}\left[
a(l,m)
\delta_{l'=l+1}-
a(l',-m')
\delta_{l'=l-1}
\right]\delta_{m'=m+1}
+\\+
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}\left[
a(l,-m)
\delta_{l'=l+1}
-
a(l',m')\delta_{l'=l-1}
\right]\delta_{m'=m-1}
+\\+
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\left[
f(l,m)
\delta_{l'=l+1}
+
f(l',m')
\delta_{l'=l-1}
\right]\delta_{m'=m}
\end{eqnarray}

Next we compute the following integral
\begin{eqnarray}
I^2_{l'm'lm}\equiv\int d\Omega Y^*_{l'm'}(\hat{\vr}) \nabla_{\theta\phi} Y_{lm}(\hat{\vr})=
\int d\Omega Y^*_{l'm'}(\hat{\vr}) (r\nabla)   Y_{lm}(\hat{\vr})
\end{eqnarray}

From W2k paper, it follows that
\begin{eqnarray}
r\frac{d}{dx}Y_{lm}=
\frac{1}{2}\left[
l\; a(l,m)\delta_{l'=l+1}+
(l+1)\; a(l-1,-m-1)\delta_{l'=l-1}
\right]\delta_{m'=m+1}Y_{l'm'}
-\\-
\frac{1}{2}
\left[l\; a(l,-m) \delta_{l'=l+1}+(l+1)\; a(l-1,m-1)\delta_{l'=l-1}
\right]\delta_{m'=m-1} Y_{l'm'}
\\
r\frac{d}{dy}Y_{lm}=
\frac{1}{2i}\left[
l\; a(l,m)\delta_{l'=l+1}+
(l+1)\; a(l-1,-m-1)\delta_{l'=l-1}
\right]\delta_{m'=m+1}Y_{l'm'}
+\\+
\frac{1}{2i}
\left[l\; a(l,-m) \delta_{l'=l+1}+(l+1)\; a(l-1,m-1)\delta_{l'=l-1}
\right]\delta_{m'=m-1} Y_{l'm'}\\
r\frac{d}{dz}Y_{lm}=
\left[-l\; f(l,m) \delta_{l'=l+1}
+
(l+1) f(l-1,m)\delta_{l'=l-1}
\right]\delta_{m'=m} Y_{l'm'}
\end{eqnarray}
It is easy to prove the last term
\begin{eqnarray}
&& r\frac{d}{dz} Y_{lm}=
(-1)^m\sqrt{\frac{(2l+1)(l-m)!}{4\pi (l+m)!}} e^{im\phi} (1-x^2) \frac{d}{d x}  P_l^m(x)=\\
&& =(-1)^m\sqrt{\frac{(2l+1)(l-m)!}{4\pi (l+m)!}} e^{im\phi}\frac{1}{2l+1}
\left[(l+1)(l+m) P_{l-1}^{m}(x)-l(l-m+1) P_{l+1}^m\right]=\\
&& =(l+1)\sqrt{\frac{(l-m)(l+m)}{(2l+1)(2l-1)}} Y_{l-1,m}
-l \sqrt{\frac{(l+m+1)(l-m+1)}{(2l+1)(2l+3)}}Y_{l+1,m}
\end{eqnarray}
The x,y components are a bit more challenging. Due to Wigner-Eckart
theorem, we know the dependence on $m,m'$. The dependence on $l,l'$
can be either found numerically, or analytically using several recursion relations.

The result for $I^2$ is
\begin{eqnarray}
I^2_{l'm'lm}=
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}\left[
-l\; a(l,m)\delta_{l'=l+1}-
(l+1)\; a(l',-m')\delta_{l'=l-1}
\right]\delta_{m'=m+1}
+\\+
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}
\left[-l\; a(l,-m) \delta_{l'=l+1}-(l+1)\; a(l',m')\delta_{l'=l-1}
\right]\delta_{m'=m-1}
+\\+
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\left[-l\; f(l,m) \delta_{l'=l+1}
+
(l+1) f(l',m')\delta_{l'=l-1}
\right]\delta_{m'=m}
\end{eqnarray}

We can write both integrals in a common form, namely,
\begin{eqnarray}
I^n_{l'm'lm}=c_{n,l}
\left[
a(l,m)
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l,-m)
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
+2 f(l,m)
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l+1}
\\
-d_{n,l}
\left[
a(l',-m')
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l',m')
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
-2 f(l',m')
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l-1}
\end{eqnarray}
where
\begin{eqnarray}
& c_{1,l} = \frac{1}{2}      & d_{1,l}=\frac{1}{2}\\
& c_{2,l}=-\frac{l}{2}       & d_{2,l}=\frac{l+1}{2}\\
& c_{3,l}=\frac{l(l+2)}{2} & d_{3,l}=\frac{(l-1)(l+1)}{2}
\end{eqnarray}
We also defined here $I^3$, which gives kinetic energy operatore
integrated over the sphere of the MT-sphere.

In the code, we use real spheric harmonics $y_{lm\pm}$, which are related
to complex spheric harmonics by
\begin{eqnarray}
&Y_{lm}&=(-1)^m \sqrt{\frac{1+\delta_{m,0}}{2}}(y_{lm+}+i y_{lm-})\\
&Y_{l,-m}&=\sqrt{\frac{1+\delta_{m,0}}{2}}(y_{lm+}-i y_{lm-})
\end{eqnarray}

In Section.~\ref{OnRealHarm} we derive the connection between the
matrix elements of the real harmonics and complex harmonics, and we
also derive the matrix elements $\braket{y_{l'm's'}|T|y_{lms}}$. Here
we just give the final result:

% Here we want to find the connection between
% $\braket{ Y^*_{l'm'}|T|Y_{lm}}$ and $\braket{y_{l'm's'}|T|y_{lms}}$.
% We will derive the connection for the case $m\ne 0$ and $m'\ne 0$ and
% $T$ being a real operator.
% We have
% \begin{eqnarray}
% \braket{ y_{l'm'+}|T|y_{lm+}} + \braket{ y_{l'm'-}|T|y_{lm-}} = \Re\left(\braket{ y_{l'm'+}-i y_{l'm'-}|T|y_{lm+}+ i y_{lm-}} \right)
% = (-1)^{m+m'} 2 \Re\left(\braket{Y_{l'm'}^*|T|Y_{lm}}\right)\\
% \braket{ y_{l'm'+}|T|y_{lm+}} - \braket{ y_{l'm'-}|T|y_{lm-}} = \Re\left(\braket{ y_{l'm'+}+i y_{l'm'-}|T|y_{lm+}+ i y_{lm-}} \right)
% = (-1)^{m} 2 \Re\left(\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)\\
% \braket{ y_{l'm'+}|T|y_{lm-}} - \braket{ y_{l'm'-}|T|y_{lm+}} = \Im\left(\braket{ y_{l'm'+}-i y_{l'm'-}|T|y_{lm+}+ i y_{lm-}} \right)
% = (-1)^{m+m'} 2 \Im\left(\braket{Y_{l'm'}^*|T|Y_{lm}}\right)\\
% \braket{ y_{l'm'+}|T|y_{lm-}} + \braket{ y_{l'm'-}|T|y_{lm+}} = \Im\left(\braket{ y_{l'm'+}+i y_{l'm'-}|T|y_{lm+}+ i y_{lm-}} \right)
% = (-1)^{m} 2 \Im\left(\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)
% \end{eqnarray}
% hence
% \begin{eqnarray}
% \braket{ y_{l'm'+}|T|y_{lm+}}&=& \frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m,0})(1+\delta_{m',0})}} \Re\left(\braket{Y_{l'm'}^*|T|Y_{lm}}+(-1)^{m'}\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)\\
% \braket{ y_{l'm'-}|T|y_{lm-}}&=& \frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m,0})(1+\delta_{m',0})}} \Re\left(\braket{Y_{l'm'}^*|T|Y_{lm}}-(-1)^{m'}\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)\\
% \braket{ y_{l'm'+}|T|y_{lm-}}&=& \frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m,0})(1+\delta_{m',0})}}  \Im\left(\braket{Y_{l'm'}^*|T|Y_{lm}}+(-1)^{m'}\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)\\
% -\braket{ y_{l'm'-}|T|y_{lm+}}&=& \frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m,0})(1+\delta_{m',0})}} \Im\left(\braket{Y_{l'm'}^*|T|Y_{lm}}-(-1)^{m'}\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)
% \end{eqnarray}
% We learned above in evaluating $I^1$,$I^2$ that $m'=m\pm 1$ or $m'=m$. If we avoid $m=0$ (and
% $m'=0$) case, which will need to be checked separately, we can
% conclude that both $m$ and $m'$ need to be of equal sign (except in
% case $m=0, m'=-1$, which will be discused separately). We can then
% conclude that the term $\braket{Y_{l'-m'}^*|T|Y_{lm}}$ is zero for $m>0$.
% Hence we have[NEEDS CORRECTION NOW]
% \begin{eqnarray}
% \braket{ y_{l'm' s}|\vec{e}_r|y_{lm s} }
% &=&
% \left(
% \begin{array}{c}
% 1\\
% 0\\
% 0
% \end{array}
% \right)
% \frac{\sqrt{1+s\delta_{m0}} \sqrt{1+s\delta_{m'0}} }{2}
% \left\{
% \delta_{l'=l+1}[a(l,-m)\delta_{m'=m-1}-a(l,m) \delta_{m'=m+1}]
% +\right.\nonumber\\
% &&\qquad\qquad \left.
% +
% \delta_{l'=l-1}[a(l-1,-m-1) \delta_{m'=m+1}-a(l-1,m-1)\delta_{m'=m-1}]
% \right\}
% +\nonumber\\
% &+&
% \left(
% \begin{array}{c}
% 0\\
% 0\\
% 1
% \end{array}
% \right)
% \frac{(1+s\delta_{m0})}{1+\delta_{m,0}}
% \left[
% f(l,m)
% \delta_{l'=l+1}
% +
% f(l-1,m)
% \delta_{l'=l-1}
% \right]\delta_{m'=m}
% \end{eqnarray}
% and
% \begin{eqnarray}
% \braket{ y_{l'm'+}|\vec{e}_r|y_{lm-} }=-\braket{ y_{l'm'-}|\vec{e}_r|y_{lm+} }
% &=&
% \left(
% \begin{array}{c}
% 0\\
% 1\\
% 0
% \end{array}
% \right)
% \frac{\sqrt{1+s\delta_{m0}}\sqrt{1+s'\delta_{m'0}}}{2}\left[
% \delta_{l'=l+1} [a(l,-m)\delta_{m'=m-1} +a(l,m) \delta_{m'=m+1}]
% \right.\\
% &&\qquad\qquad \left.
% -\delta_{l'=l-1}[a(l-1,-m-1) \delta_{m'=m+1}+a(l-1,m-1)\delta_{l'=l-1}\delta_{m'=m-1}]
% \right]\nonumber
% \end{eqnarray}
%
%
% Similarly we can derive[NEEDS CORRECTION NOW]
% \begin{eqnarray}
% \braket{ y_{l'm' s}|r\nabla|y_{lm s} }
% &=&
% \left(
% \begin{array}{c}
% 1\\
% 0\\
% 0
% \end{array}
% \right)
% \frac{\sqrt{1+s\delta_{m0}} \sqrt{1+s\delta_{m'0}} }{2}\left[
% \delta_{l'=l+1}\; l\; [a(l,-m)\delta_{m'=m-1}-a(l,m) \delta_{m'=m+1}]
% +\right.\nonumber\\
% &&\qquad\qquad \left.
% -
% \delta_{l'=l-1}\;(l+1)[a(l-1,-m-1) \delta_{m'=m+1}-a(l-1,m-1)\delta_{m'=m-1}]
% \right]
% +\nonumber\\
% &+&
% \left(
% \begin{array}{c}
% 0\\
% 0\\
% 1
% \end{array}
% \right)
% \frac{(1+s\delta_{m,0})}{1+\delta_{m,0}}
% \left[
% -l\; f(l,m)
% \delta_{l'=l+1}
% +
% (l+1)\; f(l-1,m)
% \delta_{l'=l-1}
% \right]\delta_{m'=m}
% \end{eqnarray}
% and
% \begin{eqnarray}
% \braket{ y_{l'm'+}|r\nabla|y_{lm-} }=-\braket{ y_{l'm'-}|r\nabla|y_{lm+} }
% &=&
% \left(
% \begin{array}{c}
% 0\\
% 1\\
% 0
% \end{array}
% \right)
% \frac{\sqrt{1+s\delta_{m0}} \sqrt{1+s'\delta_{m'0}} }{2}\left[
% \delta_{l'=l+1} \; l\; [a(l,-m)\delta_{m'=m-1} +a(l,m) \delta_{m'=m+1}]
% \right.
% \nonumber\\
% &&\left.
% +\delta_{l'=l-1}\;(l+1)\;[a(l-1,-m-1) \delta_{m'=m+1}+a(l-1,m-1)\delta_{l'=l-1}\delta_{m'=m-1}]
% \right]\nonumber
% \end{eqnarray}
%

\begin{eqnarray}
\braket{y_{l'm'\pm}|T|y_{lm\pm}}  =
c_{n,l}\;\delta_{l'=l+1}
\left(
\begin{array}{c}
-a(l,m)\delta_{m'=m+1}\frac{(1\pm\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}
+a(l,-m)\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}} \\
0\\
2 f(l,m)\delta_{m'=m} \frac{(1\pm\delta_{m=0})}{1+\delta_{m=0}}
\end{array}
\right)
%
\nonumber\\
\left.
%
-d_{n,l}\;\delta_{l'=l-1}
\left(
\begin{array}{c}
-a(l',-m')\delta_{m'=m+1}\frac{(1\pm\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}+a(l',m')\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}}\\
0\\
-2 f(l',m')\delta_{m'=m}\frac{(1\pm\delta_{m=0})}{1+\delta_{m=0}}
\end{array}
\right)
\right\}
\end{eqnarray}
and
\begin{eqnarray}
\braket{y_{l'm'\pm}|T|y_{lm\mp}}  =
\pm\left(
\begin{array}{c}
0\\
1\\
0
\end{array}
\right)
\left\{
c_{n,l}\;\delta_{l'=l+1}
\left(
  a(l,m)\delta_{m'=m+1}\frac{(1\mp\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}+a(l,-m)\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}}
\right)
\right.
%
\nonumber\\
%
\left.
-d_{n,l}\;\delta_{l'=l-1}
\left(
a(l',-m')\delta_{m'=m+1}\frac{(1\mp\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}+a(l',m')\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}}
\right)
\right\}
\end{eqnarray}

This term has name \verb fomai2  in Wien2k, and is coded in program \verb Force4_mine .
This part reads non-spherical potential $V_{KS}(\vr)$ and calls
another subprogram  \verb VdRho , which performns the integration.

\subsection{LDA+U Force term}

For LDA+U calculation, the LDA+U potential is added to the
Kohn-Sham potential, which takes the form
\begin{eqnarray}
V(\vr,\vr')= V^l_{m_1 m_2} Y_{l m_1}(\hat{\vr}) \delta(r-r') Y_{l m_2}^*(\hat{\vr})
\end{eqnarray}

We are evaluating the following tem
\begin{eqnarray}
F_U&=&-i\sum_{i,\vk} f_i \sum_{\vK,\vK'}(\vK-\vK')  A_{i\vK'}^*\braket{\chi_{\vK'}|V|\chi_{\vK}} A_{i\vK}=\\
&=&-i\sum_{i,\vk}f_i \sum_{\begin{array}{c}\vK,\vK',l\\m_1,m_2,\kappa_1,\kappa_2\end{array}}(\vK-\vK')
  A_{i\vK'}^*\braket{a_{l
  m_1}^{\kappa_1,\vK'\;*}u_{l}^{\kappa_1}Y_{lm_1}^*|V|Y_{lm_2}u_l^{\kappa_2}a_{lm}^{\kappa_2,\vK}}
  A_{i\vK}
\nonumber
\end{eqnarray}
which is
\begin{eqnarray}
F_U=-i \sum_{i,\vk}f_i \sum_{l,m_1,m_2,\kappa_1\kappa_2}V^l_{m_1 m_2} \braket{u_{l}^{\kappa_1}|u_l^{\kappa_2}}
\sum_{\vK,\vK'}(\vK-\vK')
A_{i\vK'}^* A_{i\vK}
a_{l m_1}^{\kappa_1,\vK'\;*} a_{lm}^{\kappa_2,\vK}=\\
=\sum_i f_i \sum_{l,m_1,m_2,\kappa_1\kappa_2}
2\Im\left(
a_{i l m_1}^{\kappa_1\;*}\vcA_{i l m_2}^{\kappa_2}
V^l_{m_1 m_2} \braket{u_{l}^{\kappa_1}|u_l^{\kappa_2}}
\right)
\label{Eq:160}
\end{eqnarray}

\section{LDA+DMFT Forces}

The Luttinger-Ward functional is
\begin{eqnarray}
\Gamma[G] = \Tr\log(G) - \Tr((G_0^{-1}-G^{-1})G) + \Phi[G]+   E_{nucleous}+\mu N
\end{eqnarray}
where LDA+DFMT $\Phi$ functional is
\begin{eqnarray}
\Phi[G] = E_H[\rho] + E_{xc}[\rho] + \Phi^{DMFT}[G_{loc}] -  \Phi^{DC}[\rho_{loc}]
\end{eqnarray}
The stationarity gives
\begin{eqnarray}
G^{-1}-G_0^{-1} + (V_H+V_{xc})\delta(\vr-\vr')\delta(\tau-\tau') +
  \ket{\phi}\Sigma\bra{\phi} - \ket{\phi}V_{DC}\bra{\phi}=0
\end{eqnarray}
Hence we have
\begin{eqnarray}
&& G_0^{-1}-G^{-1} = (V_H+V_{xc})\delta(\vr-\vr')+  \ket{\phi}(\Sigma-V_{DC})\bra{\phi}\\
&& G^{-1}=i\omega+\mu+\nabla^2-(V_{nucl} +V_H+V_{xc})\delta(\vr-\vr')-
  \ket{\phi}(\Sigma-V_{DC})\bra{\phi}
\end{eqnarray}
We also solve the following KS-problem
\begin{eqnarray}
(-\nabla^2+ V_{nucl} +V_H+V_{xc})\ket{\psi_{i\vk}}=\varepsilon_{i\vk}^{LDA}\ket{\psi_{i\vk}}
\end{eqnarray}
so thet we can write
\begin{eqnarray}
G^{-1}=i\omega+\mu-\ket{\psi_{i\vk}}\varepsilon^{LDA}_{i\vk}\bra{\psi_{i\vk}}- \ket{\phi}(\Sigma-V_{DC})\bra{\phi}
\end{eqnarray}
In the extremum, $\Gamma$ delivers free energy.
Inserting $G_0^{-1}-G^{-1}$, and $G^{-1}$ into the unctional $\Gamma$,
we get
\begin{eqnarray}
F = -\Tr\log\left( i\omega+\mu
-\ket{\psi_{i\vk}}\varepsilon^{LDA}_{i\vk}\bra{\psi_{i\vk}}
-\ket{\phi}(\Sigma-V_{dc})\bra{\phi} \right)
- \Tr((V_H+V_{xc})\rho) \nonumber\\
- \Tr( \ket{\phi}(\Sigma-V_{DC})\bra{\phi} G)
+ E_{H}[\rho]+E_{xc}[\rho]
+ \Phi^{DMFT}[G_{local}]-\Phi^{DC}[\rho_{local}]
+ E_{nucleous}+\mu N
\label{DFMT:func}
\end{eqnarray}

\subsection{LDA+U}

First we consider static approximation for
$\Phi^{DMFT}\rightarrow \Phi^{U}$ and we than call $\delta\Phi^U/\delta G \equiv V_U$, which
is static.

We then incorporate $V_U$ potential into KS-eigenvalue problem, i.e.,
\begin{eqnarray}
\varepsilon_{i\vk}^{LDA}\delta_{ij}+\braket{\psi_{i\vk}|\phi_m}(V_U-V_{DC})_{mm'}
  \braket{\phi_{m'}|\psi_{\vk j}}\equiv H_{ij}^{LDA+U}
\end{eqnarray}
and solve
\begin{eqnarray}
H_{ij}^{LDA+U} B_{jp}=\varepsilon_{p\vk} B_{ip}
\end{eqnarray}
hence
\begin{eqnarray}
H_{ij}^{LDA+U} = (B \varepsilon_\vk B^\dagger)_{ij}
\end{eqnarray}
so that
\begin{eqnarray}
\braket{\psi_{i\vk}|\left( i\omega+\mu-\ket{\psi_{i\vk}}\varepsilon^{LDA}_{i\vk}\bra{\psi_{i\vk}}-\ket{\phi}(\Sigma-V_{dc})\bra{\phi} \right)|\psi_{j\vk}}
=[B(i\omega+\mu-\varepsilon_\vk)B^\dagger]_{ij}
\end{eqnarray}
We then have
\begin{eqnarray}
F = -\Tr\log\left( i\omega+\mu-\varepsilon_{i\vk} \right) - \Tr((V_H+V_{xc})\rho)
- \Tr( \ket{\phi_m}(V_U-V_{DC})_{mm'}\bra{\phi_{m'}} G)\nonumber\\
+ E_{H}[\rho]+E_{xc}[\rho]
+ \phi^{U}[n_{local}]-\phi^{DC}[n_{local}]
+ E_{nucleous}
\label{LDAU:func}
\end{eqnarray}

Small change of nucleous position $\delta \vR_\alpha$ will give small
change in $F$ in the following way
\begin{eqnarray}
\delta F = \Tr(G\delta\varepsilon_{\vk}) - \Tr((\delta V_H+\delta V_{xc})\rho)
-\delta \Tr( \ket{\phi_m}(V_U-V_{DC})_{mm'}\bra{\phi_{m'}} G)
+\Tr((V_U-V_{DC})\delta n)+\delta E_{nucleous}
\end{eqnarray}
We can arrange the trace in the third term in the following way
\begin{eqnarray}
-\delta \Tr( (V_U-V_{DC})_{mm'}\braket{\phi_{m'}| G|\phi_m})=
-\delta \Tr( (V_U-V_{DC})_{mm'} n_{m'm})=-\delta \Tr( (V_U-V_{DC}) n)\\
=-\Tr( (\delta V_U-\delta V_{DC}) n)-\Tr( (V_U-V_{DC}) \delta n)
\end{eqnarray}
hence we obtain
\begin{eqnarray}
\delta F = \Tr(f_\vk \delta\varepsilon_{\vk}) -
\Tr((\delta V_H+\delta  V_{xc}+\delta V_{nuc})\rho)-\Tr((\delta V_U-\delta V_{DC}) n)
-\sum_\alpha\vF^{HF}_\alpha\delta \vR_\alpha
\end{eqnarray}
This equation is analogous to Eq.~\ref{Eq:forceL} in LDA method.
We did not yet write definition for $V_{KS}$ as there are two options,
one could include $V_U$ or not. We will exclude $V_U$ and choose $V_{KS}^{LDA}=V_{nuc}+V_{H}+V_{xc}$.

When we vary $\delta \varepsilon_\vk$, we have $V_U$ potential
included, hence using Eq.~\ref{Eq:deltae} we get
\begin{eqnarray}
\delta \varepsilon_{\vk,i}=
\sum_{\vK,\vK'} A_{i,\vK'}^* \left(
\braket{\delta
  \chi_{\vK'}|H-\varepsilon_i|\chi_{\vK}}+\braket{\chi_{\vK'}|H-\varepsilon_i|\delta\chi_{\vK}}+\braket{\chi_{\vK'}|\delta
  T + \delta V_{KS}^{LDA} + \delta (\ket{\phi_m}(V_U-V_{DC})_{mm'}\bra{\phi_{m'}}) \chi_{\vK}}
\right)A_{i,\vK}
\end{eqnarray}
Inserting the last equation into $\delta F$, we get
% \begin{eqnarray}
% \delta F =
% \sum_{i} f_{i\vk} \sum_{\vK,\vK'}
% A_{i,\vK'}^*
% \left(
% \braket{\delta  \chi_{\vK'}|H-\varepsilon_i|\chi_{\vK}}+\braket{\chi_{\vK'}|H-\varepsilon_i|\delta\chi_{\vK}}+
% \braket{\chi_{\vK'}|\delta
%   T + \delta V_{KS}^{LDA} + \delta (\ket{\phi_m}(V_U-V_{DC})_{mm'}\bra{\phi_{m'}}) \chi_{\vK}}
% \right)A_{i,\vK}\nonumber\\
% -\Tr((\delta V_H+\delta  V_{xc}+\delta V_{nuc})\rho)-\Tr((\delta V_U-\delta V_{DC}) n)
% -\sum_\alpha\vF^{HF}_\alpha\delta \vR_\alpha\nonumber
% \end{eqnarray}
% which can also be written as
\begin{eqnarray}
\delta F =
\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^*
\left(
\braket{\delta  \chi_{\vK'}|H-\varepsilon_i|\chi_{\vK}}+\braket{\chi_{\vK'}|H-\varepsilon_i|\delta\chi_{\vK}}
\right)A_{i,\vK}+\\
+\sum_i f_{i\vk}\braket{\psi_{i\vk}|\delta  T + \delta V_{KS}^{LDA} + \delta (\ket{\phi_m}(V_U-V_{DC})_{mm'}\bra{\phi_{m'}}) \psi_{i\vk}}
\nonumber\\
-\Tr((\delta V_H+\delta  V_{xc}+\delta V_{nuc})\rho)-\Tr((\delta V_U-\delta V_{DC}) n)
-\sum_\alpha\vF^{HF}_\alpha\delta \vR_\alpha\nonumber
\end{eqnarray}
Note that the term $\Tr(\delta V_{KS}^{LDA}\rho)$ cancels, and we obtain
\begin{eqnarray}
\delta F =
\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^*
\left(
\braket{\delta  \chi_{\vK'}|H-\varepsilon_i|\chi_{\vK}}+\braket{\chi_{\vK'}|H-\varepsilon_i|\delta\chi_{\vK}}
\right)A_{i,\vK}
\label{Eq:180}\\
+\sum_i f_{i\vk}\braket{\psi_{i\vk}| \delta (\ket{\phi_m}(V_U-V_{DC})_{mm'}\bra{\phi_{m'}})| \psi_{i\vk}}
-\Tr((\delta V_U-\delta V_{DC}) n)
\label{Eq:181}\\
+\sum_i f_{i\vk}\braket{\psi_{i\vk}|\delta  T|\psi_{i\vk}}
-\sum_\alpha\vF^{HF}_\alpha\delta \vR_\alpha
\end{eqnarray}
Note that the first two terms (Eq.~\ref{Eq:180}) still include $V_U$
term. It could be split into the following two terms
\begin{eqnarray}
Eq.~\ref{Eq:180} =
\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^* \left(\braket{\delta \chi_{\vK'}|-\nabla^2+V_{KS}^{LDA}-\varepsilon_i|\chi_{\vK}}+
                         \braket{\chi_{\vK'}|-\nabla^2+V_{KS}^{LDA}-\varepsilon_i|\delta\chi_{\vK}}
\right)A_{i,\vK}+\\
+\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^* \left(\braket{\delta  \chi_{\vK'} \ket{\phi_m}(V_U-V_{DC})_{mm'}\bra{\phi_{m'}}\chi_{\vK}}+
\braket{\chi_{\vK'}\ket{\phi_m}(V_U-V_{DC})_{mm'}\bra{\phi_{m'}} \delta\chi_{\vK}}\right)A_{i,\vK}
\label{Eq:184}
\end{eqnarray}
Now we combinte~\ref{Eq:181} and \ref{Eq:184}, to obtain
\begin{eqnarray}
Eq.~\ref{Eq:181}+Eq.~\ref{Eq:184}=
\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^* \delta \left(\braket{\chi_{\vK'} \ket{\phi_m}(V_U-V_{DC})_{mm'}\bra{\phi_{m'}}\chi_{\vK}}\right)A_{i,\vK}
-\Tr(n(\delta V_U-\delta V_{DC}))
\end{eqnarray}
which can also be written as
\begin{eqnarray}
Eq.~\ref{Eq:181}+Eq.~\ref{Eq:184}=
\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^*
A_{i,\vK}
(V_U-V_{DC})_{mm'}
\delta \left(\braket{\chi_{\vK'} \ket{\phi_m}\bra{\phi_{m'}}\chi_{\vK}}\right)
\end{eqnarray}
Finally, we have
\begin{eqnarray}
\delta F =
\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^* \left(\braket{\delta \chi_{\vK'}|-\nabla^2+V_{KS}^{LDA}-\varepsilon_i|\chi_{\vK}}+
                         \braket{\chi_{\vK'}|-\nabla^2+V_{KS}^{LDA}-\varepsilon_i|\delta\chi_{\vK}}
\right)A_{i,\vK}+\\
+\sum_i f_{i\vk}\braket{\psi_{i\vk}|\delta  T|\psi_{i\vk}}
-\sum_\alpha\vF^{HF}_\alpha\delta \vR_\alpha \\
+\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^*
A_{i,\vK}
(V_U-V_{DC})_{mm'}
\delta \left(\braket{\chi_{\vK'} \ket{\phi_m}\bra{\phi_{m'}}\chi_{\vK}}\right)
\end{eqnarray}
which gives
\begin{eqnarray}
\vF^{Pulley}_\alpha =
-\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^* \left(\braket{\frac{\delta\chi_{\vK'}}{\delta\vR_\alpha} |-\nabla^2+V_{KS}^{LDA}-\varepsilon_i|\chi_{\vK}}+
                         \braket{\chi_{\vK'}|-\nabla^2+V_{KS}^{LDA}-\varepsilon_i|\frac{\delta \chi_{\vK}}{\delta \vR_\alpha}}
\right)A_{i,\vK}\label{Eq:190}\\
-\sum_i f_{i\vk}\braket{\psi_{i\vk}|\frac{\delta T}{\delta \vR_\alpha} |\psi_{i\vk}}\label{Eq:191}\\
-\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^*
A_{i,\vK}
(V_U-V_{DC})_{m'm}
\frac{\delta}{\delta\vR_\alpha} \left(\braket{\chi_{\vK'} \ket{\phi_{m'}}\bra{\phi_{m}}\chi_{\vK}}\right)
\label{Eq:192}
\end{eqnarray}
Eqs.~\ref{Eq:190} and ~\ref{Eq:191} look just like the DFT part
above. The extra forces due to the $U$ terms are thus given by~\ref{Eq:192}.

We thus need the following derivative of the projector
\begin{eqnarray}
\frac{\delta}{\delta\vR_\alpha} \braket{\chi_{\vK'} \ket{\phi_{m'}}\bra{\phi_{m}}\chi_{\vK}}=
\braket{i(\vk+\vK')\chi_{\vK'}-\nabla\chi_{\vK'}|\phi_{m'}}\braket{\phi_m|\chi_{\vK}}+
\braket{\chi_{\vK'}|-\nabla\phi_{m'}}\braket{\phi_m|\chi_{\vK}}\\
+\braket{\chi_{\vK'}|\phi_{m'}}\braket{-\nabla\phi_m|\chi_{\vK}}+
\braket{\chi_{\vK'}|\phi_{m'}}\braket{\phi_m|i(\vk+\vK)\chi_{\vK}-\nabla\chi_{\vK}}\\
=
i(\vK-\vK')\braket{\chi_{\vK'}|\phi_{m'}}\braket{\phi_m|\chi_{\vK}}\\
-(\braket{\nabla\chi_{\vK'}|\phi_{m'}}+\braket{\chi_{\vK'}|\nabla\phi_{m'}})\braket{\phi_m|\chi_{\vK}}
-\braket{\chi_{\vK'}|\phi_{m'}}(\braket{\nabla\phi_m|\chi_{\vK}}+\braket{\phi_m|\nabla\chi_{\vK}})
\end{eqnarray}
We then recognize
\begin{eqnarray}
\braket{\nabla\phi_m|\chi_{\vK}}+\braket{\phi_m|\nabla\chi_{\vK}}=
\int d^3r \nabla(\phi^*_m(\vr) \chi_{\vK}) = \oint_{R_{MT}^-} d\vS\; \phi^*_m(\vr) \chi_{\vK}
\equiv \ll \phi_m|\chi_\vK \gg
\label{Eq:197}
\end{eqnarray}
and use to rewrite the projector variation
\begin{eqnarray}
\frac{\delta}{\delta\vR_\alpha} \braket{\chi_{\vK'} \ket{\phi_{m'}}\bra{\phi_{m}}\chi_{\vK}}=
i(\vK-\vK')\braket{\chi_{\vK'}|\phi_{m'}}\braket{\phi_m|\chi_{\vK}}
-\ll \chi_{\vK'}|\phi_{m'} \gg \braket{\phi_m|\chi_{\vK}}
-\braket{\chi_{\vK'}|\phi_{m'}}\ll \phi_m|\chi_{\vK} \gg
\end{eqnarray}

Finally, we can write extra LDA+U Pulley forces as
\begin{eqnarray}
\vF^{U+Pulley}_\alpha =
-\sum_{i} f_{i\vk} \sum_{\vK,\vK'}i(\vK-\vK')
A_{i,\vK'}^*
\braket{\chi_{\vK'}|\phi_{m'}}
(V_U-V_{DC})_{m'm}
\braket{\phi_m|\chi_{\vK}}
A_{i,\vK}
\label{Eq:199}\\
+\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^*
\ll \chi_{\vK'}|\phi_{m'} \gg (V_U-V_{DC})_{m'm}  \braket{\phi_m|\chi_{\vK}}A_{i,\vK}
\label{Eq:200}\\
+\sum_{i} f_{i\vk} \sum_{\vK,\vK'}
A_{i,\vK'}^*
\braket{\chi_{\vK'}|\phi_{m'}}(V_U-V_{DC})_{m'm}\ll \phi_m|\chi_{\vK} \gg
A_{i,\vK}
\label{Eq:201}
\end{eqnarray}
Note that Wien2k implements the first term (Eq.~\ref{Eq:199}), but
neglects the other two (Eq.~\ref{Eq:200},\ref{Eq:201}). It would be
nice to check how much difference the last two terms make.

\subsection{Proof that variation can be equivalently done in non-diagonal basis}

In this section the LDA Hamiltonian will be $H^0$, i.e.,
\begin{eqnarray}
H^0_{\vK'\vK} = \braket{\chi_{\vK'}|-\nabla^2+V_{KS}|\chi_\vK}
\end{eqnarray}
which is diagonalized by the generalized eigenvalue problem Eq.~\ref{Eq:eigval}
\begin{eqnarray}
A^{0\dagger}_{j\vK'} H^0_{\vK'\vK} A^0_{\vK i} - A^{0\dagger}_{j\vK'} O_{\vK'\vK} A^0_{\vK i} \varepsilon^0_i =0
\label{Eq:eigval2}
\end{eqnarray}
and the LDA+U Hamiltonian in KS basis:
\begin{eqnarray}
H^U_{ij} = \varepsilon^0_i\delta_{ij} +  \braket{\psi^0_{i\vk}|\phi_{m'}}V_{m'm}\braket{\phi_{m}|\psi^0_{j\vk}}\equiv (\varepsilon^0_\vk+V)_{ij}
\end{eqnarray}
where $V =V_U-V_{DC}$.

Note that the generalized eigenvalue problem (such as Eq.~\ref{Eq:eigval2}) has
the following properties (for both pairs $H$,$A$ or $H^0$,$A^0$):
\begin{eqnarray}
&& H A = O A \varepsilon\\
&& A^+ H = \varepsilon A^\dagger O\\
&& A^\dagger O A = 1\\
&& A^\dagger H A = \varepsilon
\end{eqnarray}

We can also diagonalize the LDA+U Hamiltnonian with a unitary
transformation $B$:
\begin{eqnarray}
B^\dagger (\varepsilon^0_\vk+V) B = \varepsilon_\vk.
\end{eqnarray}

Using transformation $B$, we can then also express LDA+U eigenvectors $A$ in terms of LDA
eigenvectors $A^0$.  We have
\begin{eqnarray}
\braket{\chi_{\vK'}|-\nabla^2 +  V_{KS}+\ket{\phi_{m'}}V_{m'm}\bra{\phi_{m}}|\chi_{\vK}} A_{\vK i}=O_{\vK'\vK}A_{\vK i}\varepsilon_{\vk i}
\end{eqnarray}
or
\begin{eqnarray}
(H^0_{\vK'\vK}+\braket{\chi_{\vK'}|\psi^0_{i\vk}}\braket{\psi^0_{i\vk}|\phi_{m'}}V_{m'm}\braket{\phi_m|\psi^0_{j\vk}}\braket{\psi^0_{j\vk}|\chi_{\vK}})
{A}_{\vK i}=O_{\vK'\vK}{A}_{\vK i}\varepsilon_i
\label{Eq:211}
\end{eqnarray}
We notice $\ket{\psi^0_{i\vk}}= \sum_{\vK}A^0_{\vK i}\ket{\chi_\vK}$ hence $\braket{\chi^0_{\vK'}|\psi^0_{i\vk}}=O_{\vK'\vK}A^0_{\vK i}$
and therefore
\begin{eqnarray}
(H^0+O A^0 V A^{0\dagger} O){A} =O{A}\varepsilon_\vk
\label{Eq:212}
\end{eqnarray}
We also defined above that
\begin{eqnarray}
\braket{\psi^0_{i\vk}|-\nabla^2 +  V_{KS}+\ket{\phi_{m'}}V_{m'm}\bra{\phi_m}|\psi^0_{j\vk}}=(\varepsilon_\vk^0+V)_{ij}=(B \varepsilon_\vk B^\dagger)_{ij}
\end{eqnarray}
which can be cast into the form
\begin{eqnarray}
A^{0\dagger}_{i\vK'}\braket{\chi_{\vK'}|-\nabla^2 +  V_{KS}+\ket{\phi_{m'}}V_{m'm}\bra{\phi_m}|\chi_{\vK}}A^0_{\vK j}=B \varepsilon_\vk B^\dagger
\end{eqnarray}
or
\begin{eqnarray}
A^{0\dagger} H A^0 = B\varepsilon_\vk B^\dagger
\label{Eq:215}
\end{eqnarray}
We multiply Eq.~\ref{Eq:215}  with $O A^0$ from the left and $B$ from the
right to obtain % combine Eq.~\ref{Eq:212} and to obtain
\begin{eqnarray}
H (A^0 B) = O (A^0 B) \varepsilon_\vk
\label{Eq:216}
\end{eqnarray}
Comparing Eq.~\ref{Eq:216} with Eq.~\ref{Eq:212} we recognize
${A}=A^0 B$ and $H=H^0+O A^0 V A^{0\dagger} O$, hence
\begin{eqnarray}
\ket{\psi_{i\vk}} = \sum_\vK \ket{\chi_{\vK}} (A^0 B)_{\vK i}
\end{eqnarray}
when
\begin{eqnarray}
\ket{\psi^0_{i\vk}} = \sum_\vK \ket{\chi_{\vK}} A^0_{\vK i}
\end{eqnarray}

Alternatively, we can derive the above identities from the fact that
\begin{eqnarray}
&& B^\dagger (\varepsilon^0 + V)B = \varepsilon \\
&& A^{0\dagger} H^0 A^0 =\varepsilon^0
\end{eqnarray}
which immediately gives
\begin{eqnarray}
&& B^\dagger (A^{0\dagger} H^0 A^0 +V)B=\varepsilon\\
&& B^\dagger A^{0\dagger}(H^0+{A^{0\dagger}}^{-1}V {A^0}^{-1})A^0B=\varepsilon\\
&& (A^{0}B)^{\dagger}(H^0+O A^0 V A^{0\dagger}O)A^0B=\varepsilon \\
&& (H^0+O A^0 V A^{0\dagger}O)A^0B=O(A^0 B)\varepsilon
\end{eqnarray}
%
% following matrix manipulations:
% \begin{eqnarray}
% && B^\dagger (\varepsilon^0 + V)B = \varepsilon \\
% && B^\dagger (A^{0\dagger} H^0 A^0 + V)B = \varepsilon\\
% && A^{0\dagger}( H^0 + O A^0 V {A^0}^{-1}) A^0 B = B\varepsilon\\
% && (H^0 + O A^0 V {A^0}^{-1}) A^0 B = O A^0 B \varepsilon\\
% && (H^0 + (O A^0 V A^{0\dagger} O)) (A^0 B) = O (A^0 B) \varepsilon\\
% && (H^0_{\vK'\vK} + (O A^0 V A^{0\dagger} O)_{\vK'\vK}) (A^0 B)_{\vK  i} = O_{\vK'\vK} (A^0 B)_{\vK i} \varepsilon_{i\vk}
% \end{eqnarray}

Now we check a small variation of the $\varepsilon^0$ by varying the
secular equation
$$H^0 A^0=O A^0\varepsilon^0$$
Note that this equation is always satisifed,
hence variation vanishes
\begin{eqnarray}
(\delta H^0) A^0 + H^0 (\delta A^0) - (\delta O) A^0 \varepsilon^0 - O  (\delta A^0)\varepsilon^0 - O A^0 \delta\varepsilon^0=0\\
A^{0\dagger}(\delta H^0) A^0 + A^{0\dagger} H^0 (\delta A^0) - A^{0\dagger} (\delta O) A^0 \varepsilon^0 - A^{0\dagger} O  (\delta A^0)\varepsilon^0 - A^{0\dagger} O A^0 \delta\varepsilon^0=0
\end{eqnarray}
We note that $A^{0\dagger} O A^0=1$ and $A^{0\dagger} H^0=\varepsilon^0A^{0\dagger}O$ hence
\begin{eqnarray}
\delta\varepsilon^0=A^{0\dagger}(\delta H^0) A^0 - A^{0\dagger} (\delta O) A^0 \varepsilon^0 +  \varepsilon^0A^{0\dagger}O (\delta A^0) - A^{0\dagger} O  (\delta A^0)\varepsilon^0
\label{Eq:227}
\end{eqnarray}
Note that although $\varepsilon^0$ is diagonal, its variation is not.
However, if only the diagonal components are needed, i.e.,
$(\delta\varepsilon^0)_{ii}$ then the last two terms cancel, and we get
\begin{eqnarray}
(\delta\varepsilon^0)_{ii}=(A^{0\dagger}(\delta H^0) A^0 - A^{0\dagger} (\delta O) A^0 \varepsilon^0)_{ii}
\label{Eq:228}
\end{eqnarray}
This equation is identical to Eq.~\ref{Eq:EVA}, however, now we also
have generalized variation of $\delta \varepsilon^0_{ij}$ in matrix form.

% STOPPED HERE. CONTINUE TOMORROW.
%
% Next we write the variation of LDA+U Hamiltonain $\delta H$
% \begin{eqnarray}
% \delta H = \delta\varepsilon^0 + \delta(\braket{\psi^0_{i\vk}|\phi_m}V_{mm'}\braket{\phi_{m'}|\psi^0_{j\vk}})
% \end{eqnarray}
% or
% \begin{eqnarray}
% \delta H =  A^\dagger (\delta H^0) A  -  A^\dagger  (\delta O) A \varepsilon_0 + \delta(\braket{\psi^0_{i\vk}|\phi_m}V_{mm'}\braket{\phi_{m'}|\psi^0_{j\vk}})
% \end{eqnarray}

We are now ready to take the variation of LDA+U functional Eq.~\ref{DFMT:func}
\begin{eqnarray}
F = -\Tr\log\left( (i\omega+\mu-\varepsilon^0_{\vk}) 1-\braket{\psi^0_{i\vk}|\phi_{m'}}(V_U-V_{DC})_{m'm}\braket{\phi_m|\psi^0_{j\vk}} \right)
- \Tr((V_H+V_{xc})\rho) \nonumber\\
- \Tr( \ket{\phi}(V_U-V_{DC})\bra{\phi} \rho)
+ E_{H}[\rho]+E_{xc}[\rho]
+ \phi^{U}[n]-\phi^{DC}[n]
+ E_{nucleous}
\end{eqnarray}
We get
\begin{eqnarray}
\delta F = \Tr\left( G \delta (\varepsilon^0_{\vk}+(\braket{\psi^0_{i\vk}|\phi_{m'}}(V_U-V_{DC})_{m'm}\braket{\phi_m|\psi^0_{j\vk}})) \right)
- \Tr((\delta V_H+\delta V_{xc}+\delta V_{nucl})\rho) \nonumber\\
-\delta \Tr( (\delta V_U-\delta V_{DC})\braket{\phi| \rho|\phi})
-\sum_\alpha F^{HF}_\alpha \delta R_\alpha
\label{Eq:230}
\end{eqnarray}

First we are going to concentrate on the first term, which comes from
derivative of logarithm
$$\delta F^0 = \Tr(G \delta H).$$
In matrix form, we have
\begin{eqnarray}
\delta F^0 = \Tr(\rho \delta(\varepsilon^0+V))
\end{eqnarray}
We also know that $\varepsilon^0+V = B\varepsilon B^\dagger$ and hence
$\rho = B \rho^d B^\dagger$, where $\rho^d$ is density matrix in
diagonal basis. The latter is important for some permutations of terms
we want to do. We get
\begin{eqnarray}
\delta F^0 = \Tr(B \rho^d B^{\dagger} \delta(\varepsilon^0+V))
\label{Eq:232}
\end{eqnarray}
We are first going to repeat the derivation from the previous section,
which transforms $H$ into diagonal form:
\begin{eqnarray}
\delta F^0 = \Tr(B \rho^d B^{\dagger} \delta( B\varepsilon B^\dagger )
\end{eqnarray}
which gives
\begin{eqnarray}
\delta F^0 = \Tr(\rho^d \delta \varepsilon) + \Tr(\rho^d B^\dagger  \delta B \varepsilon  + B\rho^d \varepsilon \delta B^\dagger)
\end{eqnarray}
Notice that both $\rho^d$ and $\varepsilon$ are diagional matrices,
hence they comute, hence we can write the last two terms in the form
$\Tr(\rho^d (B^\dagger  \delta B  + \delta B^\dagger B)\varepsilon)=0$ because
$B^\dagger B=1$ is always unitary and its variation has to
vanish. Hence we have
\begin{eqnarray}
\delta F^0 = \Tr(\rho^d \delta \varepsilon)
\end{eqnarray}
We could of course derive this equation directly from variation of
Green's function in diagonal form $\delta F^0=-\delta \ln (i\omega+\mu-\varepsilon)$, but we wanted to
check that the two derivations give identical results.

We next use Eq.~\ref{Eq:228} to get
\begin{eqnarray}
\delta F^0 = \Tr(\rho^d (A^{\dagger}(\delta H) A - A^{\dagger} (\delta O) A \varepsilon))
\end{eqnarray}
notice that because $\rho^d$ is diagonal and we have $\Tr$, only the
diagonal components of Eq.~\ref{Eq:227} are needed.
We also know from Eq.~\ref{Eq:212}  that $H=H^0+O A^0 V A^{0\dagger} O$, hence
\begin{eqnarray}
\delta F^0 = \Tr(\rho^d (A^{\dagger}(\delta H^0) A - A^{\dagger}  (\delta O) A \varepsilon)) + \Tr(\rho^d A^\dagger \delta(O A^0 V A^{0\dagger} O)A)
\label{Eq:237}
\end{eqnarray}
Next we notice that $ O A^0 V A^{0\dagger} O$ is $\braket{\chi_{\vK'}|\phi_{m'}}V_{m'm}\braket{\phi_m|\chi_\vK}$ (see
Eq.~\ref{Eq:211}), and when combined with $-\Tr(n_{mm'} \delta V_{m'm})$ from Eq.~\ref{Eq:230}, we get
\begin{eqnarray}
\delta F^0 -\Tr(n_{mm'} \delta V_{m'm})&=& \Tr(\rho^d
  (A^{\dagger}(\delta H^0) A - A^{\dagger}  (\delta O) A \varepsilon))\\
 &+& \Tr(\rho^d_{ii} A^\dagger_{i\vK'}  \delta(\braket{\chi_{\vK'}|\phi_{m'}}V_{m'm}\braket{\phi_m|\chi_\vK})A_{\vK  i})-\Tr(n_{mm'} \delta V_{m'm})\\
 &=& \Tr(\rho^d (A^{\dagger}(\delta H^0) A - A^{\dagger}  (\delta O) A  \varepsilon)) +
\Tr(\rho^d_{ii} A^\dagger_{i\vK'}  V_{m'm} A_{\vK  i}\delta(\braket{\chi_{\vK'}|\phi_{m'}}\braket{\phi_m|\chi_\vK}))
\end{eqnarray}
The last term is exactly the additional LDA+U force that we derived in
previous chapter Eq.~\ref{Eq:192}.

This was just equivalent derivation (using matrix notation) of the
derivation from the previous chapter. But now we want to see that
variation in basis, which is not an eigenbasis of $H^0+V$, also leads
to the same result. This is important in DMFT since $H^0+V$ basis is
frequency dependent, while $H^0$ basis is not, and we want to do most
of the calculation in frequency independent basis.

Notice that in DMFT transformation $B$ is frequency dependent
$B_\omega$, hence the expression in diagonal basis would be
\begin{eqnarray}
\delta F^0 -\Tr(G_{mm'} \delta \Sigma_{m'm})&=&
   \Tr( [B_\omega G^d_\omega B_\omega^\dagger]  (A^{0\dagger}(\delta H^0) A^0 ))
- \Tr( [B_\omega \varepsilon_\omega G^d_\omega B^\dagger_\omega]  A^{0\dagger}  (\delta O) A^0 )
\nonumber\\
 &+&
\Tr([(B_\omega G^d_\omega B^\dagger_\omega)_{ij}\Sigma^\omega_{m'm} ] A^{0\dagger}_{j\vK'}  \delta(\braket{\chi_{\vK'}|\phi_{m'}}\braket{\phi_m|\chi_\vK})A^0_{\vK  i} )
\nonumber
\end{eqnarray}
In particular, the last term would require
\begin{eqnarray}
(w\Sigma)_{ijm'm}= \frac{1}{\beta}\sum_{i\omega}  (B_\omega G^d_\omega B^\dagger_\omega)_{ij}\Sigma^\omega_{m'm}
\end{eqnarray}
We are hoping to find better expression in non-diagonal case.

The challenge now is to show that variation of $\delta F^0$ leads to
Eq.~\ref{Eq:237} even when we do not transform to eigenbasis. We
return to Eq.~\ref{Eq:232}, and write
\begin{eqnarray}
\delta F^0 = \Tr(B \rho^d B^{\dagger} \delta(\varepsilon^0+V)) =
\Tr(B \rho^d B^{\dagger}  \left(A^{0\dagger}(\delta H^0) A^0 -
  A^{0\dagger} (\delta O) A^0 \varepsilon^0 +
  \varepsilon^0A^{0\dagger}O (\delta A^0) - A^{0\dagger} O  (\delta
  A^0)\varepsilon^0 \right))+ \Tr(B \rho^d B^{\dagger} \delta V))
\nonumber
\end{eqnarray}
Notice that we had to use the non-diagonal form of
$\delta\varepsilon^0$ (Eq.~\ref{Eq:227}) and that diagonal form
Eq.~\ref{Eq:228}  would not be sufficient here.

We next notice that $A^0 B=A$ and $B^\dagger A^{0\dagger}=A^\dagger$
hence
\begin{eqnarray}
\delta F^0 = \Tr(\rho^d
\left(
{A^{\dagger}} (\delta H^0) {A} -
{A^{\dagger}} (\delta O) A B^\dagger \varepsilon^0 B +
{B^\dagger}\varepsilon^0B A^{\dagger}O (\delta A^0) B -
A^{\dagger} O  (\delta  A^0) B B^\dagger\varepsilon^0 B \right))+
\Tr(B \rho^d B^{\dagger} \delta V))
\end{eqnarray}
Next we replace $B^\dagger\varepsilon^0 B =\varepsilon-B^\dagger V B$ therefore
\begin{eqnarray}
\delta F^0 = \Tr(\rho^d
\left(
{A^{\dagger}} (\delta H^0) {A} -
{A^{\dagger}} (\delta O) A (\varepsilon-B^\dagger V B) +
(\varepsilon-{B^\dagger} V B) A^{\dagger}O (\delta A^0) B -
A^{\dagger} O  (\delta  A^0) B (\varepsilon-B^\dagger V B )
\right))+
\Tr(B \rho^d B^{\dagger} \delta V))
\nonumber
\end{eqnarray}
and now we notice that both $\varepsilon$ and $\rho^d$ are diagonal
matrices, hence the third and fourth terms have parts that cancel, i.e.,
$\Tr(\rho^d ( \varepsilon A^{\dagger}O (\delta A^0) B - A^{\dagger} O(\delta  A^0) B \varepsilon)=0$, hence

\begin{eqnarray}
\delta F^0 &=& \Tr(\rho^d
\left(
{A^{\dagger}} (\delta H^0) {A} -
{A^{\dagger}} (\delta O) A \varepsilon
\right))
\label{Eq:242}\\
&+&\Tr(\rho^d \left(
{A^{\dagger}} (\delta O) A B^\dagger V B
-({B^\dagger} V B) A^{\dagger}O (\delta A^0) B
+A^{\dagger} O  (\delta  A^0) B B^\dagger V B
\right))+
\Tr(B \rho^d B^{\dagger} \delta V))
\label{Eq:243}
\end{eqnarray}
Eq.~\ref{Eq:242} is already in the required form of
Eq.~\ref{Eq:237}. The second part Eq.~\ref{Eq:243} needs some further manipulation.
%
We write
\begin{eqnarray}
Eq.~\ref{Eq:243}=
\Tr(A \rho^d A^\dagger \left(
 (\delta O) A B^\dagger V B A^{-1}
- {A^{\dagger}}^{-1} {B^\dagger} V B  A^{\dagger}O (\delta A^0) B A^{-1}
+O  (\delta  A^0) V B A^{-1}
\right))+
\Tr(B \rho^d B^{\dagger} \delta V))
\end{eqnarray}
and we use $A^\dagger O A=1$ and  $A B^\dagger=A^0$ and $B A^\dagger =A^{0\dagger}$
\begin{eqnarray}
Eq.~\ref{Eq:243}=
\Tr(A \rho^d A^\dagger \left(
 (\delta O) A^0 V A^{0\dagger} O
- O A^0 V A^{0 \dagger}O (\delta A^0) A^{0\dagger} O
+O  (\delta  A^0) V A^{0\dagger} O
\right))+
\Tr(B \rho^d B^{\dagger} \delta V)
\end{eqnarray}
Next we vary $A^\dagger O A=1$ to obtain
$$A^{0 \dagger}O (\delta A^0)=-(\delta A^{0 \dagger})O A^0-A^{0  \dagger}(\delta O) A^0$$
hence
\begin{eqnarray}
Eq.~\ref{Eq:243}=
\Tr(A \rho^d A^\dagger \left(
 (\delta O) A^0 V A^{0\dagger} O
+ O A^0 V
((\delta A^{0 \dagger})O+A^{0  \dagger}(\delta O))
A^0 A^{0\dagger} O
+O  (\delta  A^0) V A^{0\dagger} O
\right))+
\Tr(B \rho^d B^{\dagger} \delta V)
\end{eqnarray}
we next use $A^0 A^{0\dagger} O=1$ (which is a consequence of $A^{0\dagger} O A^0=1$) to obtain
\begin{eqnarray}
Eq.~\ref{Eq:243}=
\Tr(A \rho^d A^\dagger \left(
 (\delta O) A^0 V A^{0\dagger} O
+ O A^0 V (\delta A^{0 \dagger})O
+ O A^0 V A^{0  \dagger}(\delta O)
+O  (\delta  A^0) V A^{0\dagger} O
\right))+
\Tr(B \rho^d B^{\dagger} \delta V)
\end{eqnarray}
We also notice that $\Tr(B \rho^d B^{\dagger} \delta V)=\Tr(A^0 B \rho^d B^{\dagger} A^{0\dagger} O A^0\delta V A^{0\dagger} O)=\Tr(A \rho^d A^{\dagger} O A^0\delta V A^{0\dagger} O)$
which gives
\begin{eqnarray}
Eq.~\ref{Eq:243}&=&
\Tr(A \rho^d A^\dagger \left(
 (\delta O) A^0 V A^{0\dagger} O
+ O A^0 V (\delta A^{0 \dagger})O
+ O A^0 V A^{0  \dagger}(\delta O)
+O  (\delta  A^0) V A^{0\dagger} O
+O A^0\delta V A^{0\dagger} O
\right))\nonumber\\
&=&\Tr(A \rho^d A^\dagger \delta\left(O A^0 V A^{0\dagger} O\right))
\end{eqnarray}
hence we conclude
\begin{eqnarray}
\delta F^0 = \Tr(\rho^d
\left(
{A^{\dagger}} (\delta H^0) {A} -
{A^{\dagger}} (\delta O) A \varepsilon
\right))
+\Tr(A \rho^d A^\dagger \delta\left(O A^0 V A^{0\dagger} O\right))
\end{eqnarray}
This is equal to Eq.~\ref{Eq:237}, hence we proved that variation
in the basis of diagonal $H$ or diagonal $H^0$ leads to the same
result.

\subsection{LDA+DMFT}

We first diagonalize the LDA+DMFT Green's function. We write
self-energy in static Kohn-Sham basis $\ket{\psi_i^0}$, in which
the LDA+DMFT eigenproblem is
\begin{eqnarray}
\varepsilon^0_{i}\delta_{ij}+\braket{\psi_i^0|\Sigma(\omega)-V_{DC}|\psi_j^0}=(B^R_\omega\varepsilon_\omega B^L_\omega)_{ij}
\label{Eq:251}
\end{eqnarray}
This defines the frequency dependent transformation $B_\omega$ between
the DMFT and DFT eigenbasis, which is not unitary (because
$H^0+\Sigma$ is not Hermitian).
The Green's function in the diagonal basis is then simply given by
\begin{eqnarray}
G^d(i\omega)= \frac{1}{i\omega+\mu-\varepsilon_\omega}
\end{eqnarray}
For convenience, we also define the following matrix
\begin{eqnarray}
(V_\omega)_{ij}\equiv \braket{\psi_i^0|\Sigma(\omega)-V_{DC}|\psi_j^0}
\end{eqnarray}
We will also need explicit formula for embedding self-energy into
Kohn-Sham basis
\begin{eqnarray}
(V_\omega)_{ij}= \braket{\psi_i^0|\Sigma(\omega)-V_{DC}|\psi_j^0}=\braket{\psi_i^0|\phi_m}\tilde{\Sigma}_{mm'}\braket{\phi_{m'}|\psi_j^0}
\end{eqnarray}
where $\tilde{\Sigma}_{mm'}=\Sigma_{mm'}(\omega)-V_{DC,mm'}$.

For DFT Hamiltonian $H^0$ we have eigenvalue proble
\begin{eqnarray}
\varepsilon^0 = A^{0\dagger} H^0 A^0
\end{eqnarray}
which together with Eq.~\ref{Eq:251} leads to the following LDA+DMFT
eigenproblem
\begin{eqnarray}
(H^0 + O A^0 V_\omega A^{0\dagger} O) A^R_\omega = O A^R_\omega\varepsilon_\omega
\label{Eq:256}
\end{eqnarray}
where $A^R_\omega = A^0 B^R_\omega$. Similarly, $A^L_\omega = B^L_\omega A^{0\dagger}$.

We vary eigenproblem Eq.~\ref{Eq:256} to get
\begin{eqnarray}
(\delta H^0)A^R_\omega + \delta(O A^0 V_\omega A^{0\dagger} O)A^R_\omega
- (\delta  O) A^R_\omega\varepsilon_\omega
- O A^R_\omega  \delta\varepsilon_\omega +
(H^0 + O A^0 V_\omega A^{0\dagger} O) (\delta  A^R_\omega)
- O (\delta A^R_\omega)\varepsilon_\omega=0
\end{eqnarray}
and multiplying by $A^L_\omega$ from left leads to
\begin{eqnarray}
A^L_\omega(\delta H^0)A^R_\omega + A^L_\omega\delta(O A^0 V_\omega A^{0\dagger} O)A^R_\omega
- A^L_\omega(\delta  O) A^R_\omega\varepsilon_\omega
- \delta\varepsilon_\omega
+\varepsilon_\omega A^L_\omega O (\delta  A^R_\omega)
- A^L_\omega O (\delta A^R_\omega)\varepsilon_\omega=0
\end{eqnarray}
which finally gives
\begin{eqnarray}
\delta\varepsilon_\omega =A^L_\omega(\delta H^0)A^R_\omega + A^L_\omega\delta(O A^0 V_\omega A^{0\dagger} O)A^R_\omega
- A^L_\omega(\delta  O) A^R_\omega\varepsilon_\omega
+\varepsilon_\omega A^L_\omega O (\delta  A^R_\omega)
- A^L_\omega O (\delta A^R_\omega)\varepsilon_\omega
\end{eqnarray}
Notice that when only the diagonal components of the variation are
needed, the last two terms cancel as $\varepsilon_\omega$ is diagonal
matrix
\begin{eqnarray}
(\delta\varepsilon_\omega)_{ii} = (A^L_\omega(\delta H^0)A^R_\omega + A^L_\omega\delta(O A^0 V_\omega A^{0\dagger} O)A^R_\omega
- A^L_\omega(\delta  O) A^R_\omega\varepsilon_\omega )_{ii}
\label{Eq:260}
\end{eqnarray}

To derive a small variation of DMFT free energy, we start from the expression Eq.~\ref{DFMT:func}.
\begin{eqnarray}
F = -\Tr\log\left( i\omega+\mu
-\ket{\psi_{i\vk}}\varepsilon^{LDA}_{i\vk}\bra{\psi_{i\vk}}
-\ket{\phi}(\Sigma-V_{dc})\bra{\phi} \right)
- \Tr((V_H+V_{xc})\rho) \nonumber\\
- \Tr( \ket{\phi}(\Sigma-V_{DC})\bra{\phi} G)
+ E_{H}[\rho]+E_{xc}[\rho]
+ \phi^{DMFT}[G_{local}]-\phi^{DC}[\rho_{local}]
+ E_{nucleous}+\mu N
\end{eqnarray}
which can now be rewritten as
\begin{eqnarray}
F = -\Tr\log\left( i\omega+\mu-\varepsilon_\omega\right)
- \Tr((V_H+V_{xc})\rho)
- \Tr( \tilde{\Sigma}\braket{\phi| G|\phi})
+ E_{H}[\rho]+E_{xc}[\rho] \nonumber\\
+ \phi^{DMFT}[G_{local}]-\phi^{DC}[\rho_{local}]
+ E_{nucleous}+\mu N
\end{eqnarray}
The variation then gives
\begin{eqnarray}
\delta F = \Tr(G^d \delta\varepsilon_\omega)
- \Tr( G_{local}\delta \tilde{\Sigma})
- \Tr((\delta V_H+\delta V_{xc}+\delta V_{nucl})\rho)
-\sum_\alpha F^{HF}_\alpha \delta R_\alpha + \mu\delta N
\end{eqnarray}
The charge neutrality is always enforced, hence $\delta N$ vanishes.
$G^d$ is the Green's function in diagonal basis, i.e., $G^d=1/(i\omega+\mu-\varepsilon_\omega)$.
We then insert the diagonal components of variation
$(\delta\varepsilon_\omega)_{ii}$, determined in Eq.~\ref{Eq:260}, to obtain
\begin{eqnarray}
\delta F =
\Tr\left(G^d (A^L_\omega(\delta H^0)A^R_\omega + A^L_\omega\delta(O A^0 V_\omega A^{0\dagger} O)A^R_\omega
- A^L_\omega(\delta  O) A^R_\omega\varepsilon_\omega )
\right)
- \Tr( G_{local}\delta \tilde{\Sigma})
- \Tr(\delta V_{KS}\rho)
-\sum_\alpha F^{HF}_\alpha \delta R_\alpha
\nonumber
\end{eqnarray}
We then split the eigenvectors into frequency dependent and independnt
parts $A^L_\omega=B^L_\omega A^{0\dagger}$ and $A^R_\omega=A^0
B^R_\omega$ and obtain
\begin{eqnarray}
\delta F =
\Tr\left( B^R_\omega G^d B^L_\omega A^{0\dagger}(\delta  H^0)A^0 \right)
+\Tr\left(B^R_\omega G^d B^L_\omega A^{0\dagger}\delta(O A^0 V_\omega A^{0\dagger} O)A^0 \right)
-\Tr\left(B^R_\omega\varepsilon_\omega G^d B^L_\omega A^{0\dagger}(\delta  O) A^0 \right)
\\
- \Tr( G_{local}\delta \tilde{\Sigma})
- \Tr(\delta V_{KS}\rho)
-\sum_\alpha F^{HF}_\alpha \delta R_\alpha
\nonumber
\end{eqnarray}
which can also be cast into the form
\begin{eqnarray}
\delta F =
\Tr\left( B^R_\omega G^d B^L_\omega A^{0\dagger}(\delta  H^0)A^0 \right)
-\Tr\left(B^R_\omega\varepsilon_\omega G^d B^L_\omega A^{0\dagger}(\delta  O) A^0 \right)
- \Tr(\delta V_{KS}\rho) -\sum_\alpha F^{HF}_\alpha \delta R_\alpha
\\
+\Tr\left( (B^R_\omega G^d B^L_\omega)_{ij}
  A^{0\dagger}_{j\vK'}\delta(\braket{\chi_{\vK'}|\phi_{m'}}\tilde{\Sigma}_{m'm}\braket{\phi_{m}|\chi_\vK})A^0_{\vK i}\right)\\
-\Tr\left( (B^R_\omega G^d B^L_\omega)_{ij}
  A^{0\dagger}_{ j\vK'} \braket{\chi_{\vK'}|\phi_{m'}}\delta(\tilde{\Sigma}_{m'm})\braket{\phi_{m}|\chi_\vK}A^0_{\vK i}\right)
\end{eqnarray}
where we used
\begin{eqnarray}
G_{local\; mm'} = \braket{\phi_m|G|\phi_{m'}}=
\braket{\phi_m|\chi_{\vK}}(A^R_\omega G^d A^L_\omega )_{\vK\vK'}\braket{\chi_{\vK'}|\phi_{m'}} =
\braket{\phi_m|\chi_{\vK}}(A^0 B^R_\omega  G^d B^L_\omega A^{0\dagger})_{\vK\vK'}\braket{\chi_{\vK'}|\phi_{m'}}
\end{eqnarray}
We thus obtain
\begin{eqnarray}
\delta F =
\Tr\left( B^R_\omega G^d B^L_\omega A^{0\dagger}(\delta  H^0)A^0 \right)
-\Tr\left(B^R_\omega\varepsilon_\omega G^d B^L_\omega A^{0\dagger}(\delta  O) A^0 \right)
- \Tr(\delta V_{KS}\rho) -\sum_\alpha F^{HF}_\alpha \delta R_\alpha
\\
+\Tr\left( (B^R_\omega G^d B^L_\omega)_{ij}
  A^{0\dagger}_{j\vK'}A^0_{\vK i}
\tilde{\Sigma}_{m'm}
\delta(\braket{\chi_{\vK'}|\phi_{m'}}\braket{\phi_{m}|\chi_\vK})\right)
\end{eqnarray}

We next define the following quantities
\begin{eqnarray}
&&\rho^{DMFT} \equiv \frac{1}{\beta}\sum_{i\omega} B^R_\omega \frac{1}{i\omega+\mu-\varepsilon_\omega}B^L_\omega
= \cB\; w\; \cB^\dagger
\label{Eq:271}\\
&&(\rho\varepsilon)^{DMFT} \equiv  \frac{1}{\beta}\sum_{i\omega} B^R_\omega\varepsilon_\omega \frac{1}{i\omega+\mu-\varepsilon_\omega} B^L_\omega
= \cB\;   (\widetilde{w\varepsilon})\; \cB^\dagger =
\widetilde{\cB}\; w_\varepsilon \;\widetilde{\cB}^\dagger
\label{Eq:272}\\
&& G(i\omega)_{ij} \equiv \left(B^R_\omega\frac{1}{i\omega+\mu-\varepsilon_\omega} B^L_\omega\right)_{ij}
\label{Eq:273}
%\\
% &&(\rho\Sigma)^{DMFT}_{ij;mm'} \equiv \frac{1}{\beta}\sum_{i\omega} (B^R_\omega\frac{1}{i\omega+\mu-\varepsilon_\omega} B^L_\omega)_{ij} \tilde{\Sigma}_{mm'}(\omega)
% \label{Eq:273}
\end{eqnarray}
The first line decomposes the DMFT density $\rho^{DMFT}$ by unitary
transformation $\cB$ to produce diagonal matrix of weights $w$, which
is possible because $\rho^{DMFT}$ is a Hermitian positive definite
matrix. The second equation determines an auxiliary off-diagonal matrix of energy
$\widetilde{w\varepsilon}$, which is also Hermitian,  since
$(\rho\varepsilon)^{DMFT}$ is hermitian. Finally, the last equation in
Eq.~\ref{Eq:272} determines another unitary transformation
$\widetilde{\cB}$ which diagonalizes Hermitian matrix $(\rho\varepsilon)^{DMFT}$.

Using the above defined quantities, we get for the variaton of the free energy:
\begin{eqnarray}
\delta F =
\Tr\left( \rho^{DMFT} A^{0\dagger}(\delta  H^0)A^0 \right)
-\Tr\left( (\rho\varepsilon)^{DMFT} A^{0\dagger}(\delta  O) A^0 \right)
- \Tr(\delta V_{KS}\rho) -\sum_\alpha F^{HF}_\alpha \delta R_\alpha
\nonumber\\
+\Tr\left(A^0_{\vK i}  G(i\omega)_{ij}  A^{0\dagger}_{j\vK'}
\;\tilde{\Sigma}_{m'm}(\omega)
\delta(\braket{\chi_{\vK'}|\phi_{m'}}\braket{\phi_{m}|\chi_\vK})\right)
\label{Eq:274}
\end{eqnarray}

We then derive the variation of LDA Hamiltonian and overlap
matrix elements using either Krakauer's formalism (Eqs.~\ref{Eq:384},
\ref{Eq:385}), or Soler/Williams formalism (\ref{Eq:386},
~\ref{Eq:388}, ~\ref{Eq:389}). In both cases we get
\begin{eqnarray}
\frac{\delta O}{\delta\vR_\alpha} &=&
 i(\vK-\vK')\braket{\chi_{\vK'}|\chi_{\vK}}_{MT} - \oint d\vec{S}\; \tilde{\chi}^*_{\vK'}\tilde{\chi}_{\vK}
\\
\frac{\delta\braket{\chi_{\vK'}|T|\chi_{\vK}}}{\delta\vR_\alpha}&=&
i(\vK-\vK')\braket{\chi_{\vK'}|T|\chi_{\vK}}_{MT} - \oint  d\vec{S}\; \tilde{\chi}^*_{\vK'} T \tilde{\chi}_{\vK}
\label{Eq:276}\\
\frac{\delta\braket{\chi_{\vK'}|V_{KS}|\chi_{\vK}}}{\delta\vR_\alpha}&=&
i(\vK-\vK')\braket{\chi_{\vK'}|V_{KS}|\chi_{\vK}}_{MT}
- \oint  d\vec{S}\; \tilde{\chi}^*_{\vK'} V_{KS} \tilde{\chi}_{\vK}
+\braket{\chi_{\vK'}|\frac{\delta V_{KS}}{\vR_\alpha}|\chi_{\vK}}
+\braket{\chi_{\vK'}|\nabla V_{KS}|\chi_{\vK}}_{MT}
\nonumber
\\
\end{eqnarray}
Notice that in Soler/Williams formalism we would use Gauss theorem to
write an equivalent form
\begin{eqnarray}
\frac{\delta O}{\delta\vR_\alpha} &=&
 i(\vK-\vK')\left[
\braket{\chi_{\vK'}|\chi_{\vK}}_{MT} -\braket{\tilde{\chi}_{\vK'}|\tilde{\chi}_{\vK}}_{MT}
\right]
\\
\frac{\delta\braket{\chi_{\vK'}|T|\chi_{\vK}}}{\delta\vR_\alpha}&=&
i(\vK-\vK')
\left[\braket{\chi_{\vK'}|T|\chi_{\vK}}_{MT} - \braket{\tilde{\chi}_{\vK'}|T|\tilde{\chi}_{\vK}}_{MT}\right]
\\
\frac{\delta\braket{\chi_{\vK'}|V_{KS}|\chi_{\vK}}}{\delta\vR_\alpha}&=&
i(\vK-\vK')\left[\braket{\chi_{\vK'}|V_{KS}|\chi_{\vK}}_{MT} -\braket{\tilde{\chi}_{\vK'}|V_{KS}|\tilde{\chi}_{\vK}}_{MT}\right]
+\braket{\chi_{\vK'}|\frac{\delta V_{KS}}{\vR_\alpha}|\chi_{\vK}}
\nonumber\\
&& +\braket{\chi_{\vK'}|\nabla V_{KS}|\chi_{\vK}}_{MT}
-\braket{\tilde{\chi}_{\vK'}|\nabla V_{KS}|\tilde{\chi}_{\vK}}_{MT}
\end{eqnarray}

Using Krakauer form, we obtain
\begin{eqnarray}
\frac{\delta H^0}{\delta\vR_\alpha}=
i(\vK-\vK')\braket{\chi_{\vK'}|H^0|\chi_{\vK}}_{MT} - \oint_{MT}  d\vec{S}\; \tilde{\chi}^*_{\vK'} H^0 \tilde{\chi}_{\vK}
+\braket{\chi_{\vK'}|\frac{\delta
  V_{KS}^{LDA}}{\vR_\alpha}|\chi_{\vK}}
\nonumber\\
-\int_{MT}d^3r V_{KS}^{LDA} \nabla(\chi^*_{\vK'} \chi_{\vK})
+\oint_{MT} d\vec{S} \chi^*_{\vK'} V_{KS}^{LDA} \chi_{\vK}
\end{eqnarray}
For the last two terms we used integration by parts to turn
$\int \chi^*_{\vK'} \chi_{\vK} \nabla V_{KS}$ into $-\int
V_{KS}\nabla(\chi^*_{\vK'} \chi_{\vK})$ plus the surface term.

% We then derive the variation of LDA Hamiltonian and overlap as before:
% \begin{eqnarray}
% \frac{\delta H^0}{\delta\vR_\alpha}&=&
% \braket{\frac{\delta \chi_{\vK'}}{\delta\vR_\alpha}|H^0|\chi_{\vK}}+\braket{\chi_{\vK'}|H^0|\frac{\delta\chi_{\vK}}{\delta\vR_\alpha}}+
% \braket{\chi_{\vK'}|\frac{\delta T}{\delta\vR_\alpha} + \frac{\delta V_{KS}^{LDA}}{\delta\vR_\alpha} |\chi_{\vK}}\nonumber\\
% &=&
% i(\vK-\vK')\braket{\chi_{\vK'}|H^0|\chi_{\vK}}
% -\braket{\nabla\chi_{\vK'}|H^0|\chi_{\vK}}
% -\braket{\chi_{\vK'}|H^0|\nabla\chi_{\vK}}+
% \braket{\chi_{\vK'}|\frac{\delta T}{\vR_\alpha} + \frac{\delta V_{KS}^{LDA}}{\vR_\alpha} |\chi_{\vK}}
% \\
% \frac{\delta O}{\delta\vR_\alpha} &=&
% \braket{\frac{\delta\chi_{\vK'}}{\delta\vR_\alpha}|\chi_{\vK}}+\braket{\chi_{\vK'}|\frac{\delta\chi_{\vK}}{\delta\vR_\alpha}}=
%  i(\vK-\vK')\braket{\chi_{\vK'}|\chi_{\vK}}
% -\braket{\nabla\chi_{\vK'}|\chi_{\vK}}
% -\braket{\chi_{\vK'}|\nabla\chi_{\vK}}
% \end{eqnarray}
% We use LDA derivation to further evaluate the terms which include derivative of basis functions
% \begin{eqnarray}
% \int_{MT} d^3r\left(  \nabla_\vr\chi^*_{\vK'+\vk} (T+V_{KS})\chi_{\vK+\vk}+
% \chi^*_{\vK'+\vk}(T+V_{KS})\nabla_\vr\chi_{\vK+\vk}\right)=\\
% \int_{MT} d^3r V_{KS} \nabla_\vr \left( \chi^*_{\vK'+\vk} \chi_{\vK+\vk}  \right)+
% \oint_{r=R_{MT}^-} d\vec{S}  \chi^*_{\vK'+\vk} (T)\chi_{\vK+\vk}
% \end{eqnarray}
% \begin{eqnarray}
% \int_{MT} d^3r\left(  \nabla_\vr\chi^*_{\vK'+\vk} \chi_{\vK+\vk}+
% \chi^*_{\vK'+\vk}\nabla_\vr\chi_{\vK+\vk}\right)=\oint_{r=R_{MT}^-} d\vec{S}  \chi^*_{\vK'+\vk} \chi_{\vK+\vk}
% \end{eqnarray}
% Further, the surface term due to discontinuity of the kinetic energy
% operator gives
% \begin{eqnarray}
% \braket{\chi_{\vK'}|\frac{\delta T}{\delta\vR_\alpha}|\chi_{\vK}}=
% \oint_{RMT}d\vec{S}
% \left[
% (\chi^*_{\vK'+\vk}(\vr) T  \chi_{\vK+\vk}(\vr))_{MT}-
% (\chi^*_{\vK'+\vk}(\vr) T  \chi_{\vK+\vk}(\vr))_I
%  \right]
% \end{eqnarray}
% Notice that here integration $\oint_{r=R_{MT}^\pm}\d\vec{S}$ has normal
% vector always turned outward of the MT-sphere.
Slight reshuffling of terms then gives
\begin{eqnarray}
\frac{\delta H^0}{\delta\vR_\alpha}=
i(\vK-\vK')\braket{\chi_{\vK'}|H^0|\chi_{\vK}}_{MT}
+\braket{\chi_{\vK'}|\frac{\delta  V_{KS}}{\vR_\alpha}|\chi_{\vK}}
-\int_{MT}d^3r V_{KS} \nabla_\vr (\chi^*_{\vK'} \chi_{\vK})
\nonumber\\
- \oint _{MT} d\vec{S}\; \tilde{\chi}^*_{\vK'} T \tilde{\chi}_{\vK}
+\oint_{MT} d\vec{S} \left[\chi^*_{\vK'} V_{KS} \chi_{\vK}-\tilde{\chi}^*_{\vK'} V_{KS} \tilde{\chi}_{\vK}\right]
\end{eqnarray}
The last term can be neglected if expansion in the MT-sphere goes
to large enough cutoff-$l_{max}$, as $\chi_{\vK}$ becomes continuous across
the MT-sphere. This term is neglected in Wien2K.

As explained in previous sections, in the interstitials we use the
symmetric form of the kinetic energy operator, i.e., $\nabla \psi_\vk \cdot
\nabla\psi_\vk$. In the MT-part, however, we use more common form
of $\psi_\vk (-\nabla^2)\psi_\vk$. Consequently, there is an extra
term generated on the surface of the MT sphere, which takes the form
\begin{eqnarray}
\braket{\chi_{\vK'}|T|\chi_\vK}_{MT} =  \braket{\chi_{\vK'}|-\nabla^2|\chi_\vK}_{MT}
+\oint_{MT} d\vec{S}\chi_{\vK'}^* \nabla_\vr \chi_{\vK}
\end{eqnarray}
This finally gives
\begin{eqnarray}
\frac{\delta H^0}{\delta\vR_\alpha}&=&
i(\vK-\vK')\braket{\chi_{\vK'}|-\nabla^2+V_{KS}|\chi_{\vK}}_{MT}
+i(\vK-\vK') \oint_{MT} d\vec{S}\chi_{\vK'}^* \nabla_\vr \chi_{\vK}
+\braket{\chi_{\vK'}|\frac{\delta V_{KS}^{LDA}}{\delta\vR_\alpha}|\chi_{\vK}}
\\
&-&\int_{MT} d^3r V_{KS} \nabla_\vr \left( \chi^*_{\vK'} \chi_{\vK}  \right)
-(\vk+\vK')(\vk+\vK)\oint_{MT}d\vec{S}\;\tilde{\chi}^*_{\vK'+\vk} \tilde{\chi}_{\vK+\vk}
+\oint_{MT} d\vec{S} \left[\chi^*_{\vK'} V_{KS} \chi_{\vK}-\tilde{\chi}^*_{\vK'} V_{KS} \tilde{\chi}_{\vK}\right]
\nonumber\\
\frac{\delta O}{\delta\vR_\alpha} &=&
 i(\vK-\vK')\braket{\chi_{\vK'}|\chi_{\vK}}_{MT}-\oint_{MT} d\vec{S}\;\tilde{\chi}^*_{\vK'}\tilde{\chi}_{\vK}
\end{eqnarray}

Notice that
\begin{equation}
\rho(\vr) = \braket{\vr|\psi^0_{\vk i}}\rho^{DMFT}_{ij}\braket{\psi^0_{\vk  j}|\vr}=
\braket{\vr|\chi_{\vK}} A^{0}_{\vK i}  \rho_{ij}^{DMFT}A^{0\dagger}_{j\vK'} \braket{\chi_{\vK'}|\vr}
\end{equation}
hence
\begin{eqnarray}
&& \Tr\left( \rho^{DMFT}_{ij} A^{0\dagger}_{j\vK'}  \braket{\chi_{\vK'}|\frac{\delta V_{KS}^{LDA}}{\delta\vR_\alpha}  |\chi_{\vK}} A^0_{\vK i} \right)=\Tr(\rho \frac{\delta V_{KS}^{LDA}}{\delta\vR_\alpha} )\\
&& \Tr\left( \rho^{DMFT}_{ij} A^{0\dagger}_{j\vK'}
\int_{MT} d^3r V_{KS} \nabla_\vr \left( \chi^*_{\vK'+\vk} \chi_{\vK+\vk}  \right)
A^0_{\vK i} \right)=\int_{MT} d^3r V_{KS}(\vr)\nabla\rho^{DMFT}(\vr)
\end{eqnarray}

For convenience, we define the following quantities
\begin{eqnarray}
&& R^{(1)}_{\vK'\vK}\equiv  i(\vK-\vK')\braket{\chi_{\vK'}|-\nabla^2+V_{KS}|\chi_{\vK}}_{MT}\\
&& R^{(2)}_{\vK'\vK}\equiv (\vk+\vK')(\vk+\vK)\oint_{MT}d\vec{S}  \tilde{\chi}^*_{\vK'}(\vr) \tilde{\chi}_{\vK}(\vr)\\
&& R^{(3)}_{\vK'\vK}\equiv i(\vK-\vK') \oint_{MT} d\vec{S}\chi_{\vK'}^* \nabla_\vr \chi_{\vK}\\
&& R^{(4)}_{\vK'\vK}\equiv \oint_{MT} d\vec{S} \left[\chi^*_{\vK'} V_{KS} \chi_{\vK}-\tilde{\chi}^*_{\vK'} V_{KS} \tilde{\chi}_{\vK}\right]\\
%&& R^{(5)}_{\vK'\vK}\equiv i(\vK-\vK')\braket{\tilde{\chi}_{\vK'}|T|\tilde{\chi}_\vK}_{MT}\\
&& Q^{(1)}_{\vK'\vK}\equiv i(\vK-\vK')\braket{\chi_{\vK'}|\chi_{\vK}}_{MT}\\
&& Q^{(2)}_{\vK'\vK}\equiv \oint_{r=R_{MT}} d\vec{S}  \tilde{\chi}^*_{\vK'}(\vr)\tilde{\chi}_{\vK}(\vr)\\
%&& Q^{(3)}_{\vK'\vK}\equiv i(\vK-\vK')\braket{\tilde{\chi}_{\vK'}|\tilde{\chi}_{\vK}}_{MT}
\end{eqnarray}
so that
\begin{eqnarray}
\frac{\delta  H^0}{\delta\vR_\alpha} &=& R^{(1)}-R^{(2)}+R^{(3)}+R^{(4)}
-\int_{MT} d^3r V_{KS} \nabla_\vr \left( \chi^*_{\vK'} \chi_{\vK}\right)
+\braket{\chi_{\vK'}|\frac{\delta V_{KS}^{LDA}}{\delta\vR_\alpha}|\chi_{\vK}}\\
\frac{\delta  O}{\delta\vR_\alpha}  &=& Q^{(1)} - Q^{(2)}
\end{eqnarray}
Notice that in Soler/Williams formalism, we would get a term like
$ i(\vK-\vK')\braket{\tilde{\chi}_{\vK'}|T|\tilde{\chi}_\vK}_{MT} $
which can be shown to be equivalent to $R^{(2)}$.
Also the term
$i(\vK-\vK')\braket{\tilde{\chi}_{\vK'}|\tilde{\chi}_{\vK}}_{MT}$ is
equivalent to $Q^{(2)}$.
% \begin{eqnarray}
% \frac{\delta  H^0}{\delta\vR_\alpha} &=& R^{(1)}+R^{(3)}+R^{(4)}-R^{(5)}
% -\int_{MT} d^3r V_{KS} \nabla_\vr \left( \chi^*_{\vK'} \chi_{\vK}\right)
% +\braket{\chi_{\vK'}|\frac{\delta V_{KS}^{LDA}}{\delta\vR_\alpha}|\chi_{\vK}}
% \\
% \frac{\delta  O}{\delta\vR_\alpha}  &=& Q^{(1)} - Q^{(3)}
% \end{eqnarray}

We can then evaluate term by term of $\delta F$. The first term is
\begin{eqnarray}
\Tr\left( \rho^{DMFT} A^{0\dagger}\frac{\delta  H^0}{\delta\vR_\alpha}A^0 \right)&=&
\Tr( \rho^{DMFT} A^{0\dagger}(R^{(1)}-R^{(2)}+R^{(3)}+R^{(4)}) A^0)
+\\
&+&\Tr(\rho^{DMFT} \frac{\delta V_{KS}^{LDA}}{\delta\vR_\alpha} )-\int_{MT} d^3r V^{LDA}_{KS}(\vr)\nabla\rho^{DMFT}(\vr)
\nonumber
% \\
% =
% \Tr( w (A^{0}\cB)^{\dagger}(R^{(1)}-R^{(2)}+R^{(3)}+R^{(4)}) {A^0\cB})
% +\Tr(\rho \frac{\delta V_{KS}^{LDA}}{\delta\vR_\alpha} )
% -\int_{MT} d^3r V_{KS}(\vr)\nabla\rho^{DMFT}(\vr)
\end{eqnarray}
The second term is
\begin{eqnarray}
\Tr\left( (\rho\varepsilon)^{DMFT} A^{0\dagger}\frac{\delta O}{\delta\vR_\alpha}A^0 \right)=
\Tr( (\rho\varepsilon)^{DMFT} A^{0\dagger}(Q^{(1)}-Q^{(2)})A^0)
% \\
% =\Tr((\widetilde{w\varepsilon})^{DMFT} (A^{0}\cB)^{\dagger}(Q^{(1)}-Q^{(2)}){A^0\cB})
\end{eqnarray}
The variation of the DMFT projector
$$\frac{\delta}{\delta\vR_\alpha} \braket{\chi_{\vK'}\ket{\phi_{m'}}\bra{\phi_{m}}\chi_{\vK}}$$
is a bit subtle. First, the DMFT
projector is zero outside MT-sphere, hence
$\delta\tilde{V}/\delta\vR_\alpha=0$ and $\tilde{V}=0$ outside
MT-sphere.  We move the
projector rigidly with the MT-sphere, hence inside MT-sphere we only have
$\delta V/\delta\vR_\alpha=-\nabla V$. We then use formulas derived in
Eq.~\ref{Eq:384}, which in this case takes the form
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|V|\chi_{\vK}} =
\braket{\frac{\delta \chi_{\vK'}}{\delta \vR_\alpha} |V|\chi_{\vK}}_{MT}
+\braket{\chi_{\vK'}|V|\frac{\delta \chi_{\vK}}{\delta \vR_\alpha}}_{MT}
-\braket{\chi_{\vK'}|\nabla V|\chi_{\vK}}_{MT}
+\oint_{MT} d\vec{S}\chi^*_{\vK'} V \chi_{\vK} \\
=i(\vK-\vK') \braket{\chi_{\vK'}|V|\chi_{\vK}}_{MT}
\end{eqnarray}
We just derived that
\begin{eqnarray}
\frac{\delta}{\delta\vR_\alpha} \braket{\chi_{\vK'} \ket{\phi_{m'}}\bra{\phi_{m}}\chi_{\vK}}=
i(\vK-\vK')\braket{\chi_{\vK'}|\phi_{m'}}\braket{\phi_m|\chi_{\vK}}.
\end{eqnarray}

We now insert all these terms in Eq.~\ref{Eq:274}, and obtain the Pulley forces
\begin{eqnarray}
\vF^{Pulley}_{\alpha} =
-\Tr(\rho^{DMFT} A^{0 \dagger}(R^{(1)}-R^{(2)}+R^{(3)}+R^{(4)}) A^0)
+\Tr((\rho\varepsilon)^{DMFT}A^{0 \dagger}(Q^{(1)}-Q^{(2)})A^0 ) \\
+\int_{MT} d^3r V_{KS}(\vr)\nabla\rho^{DMFT}(\vr)
-\Tr\left(
A^0_{\vK i}
G(i\omega)_{ij}
A^{0\dagger}_{j\vK'}
i(\vK-\vK')\braket{\chi_{\vK'}|\phi_{m'}}\widetilde{\Sigma}_{m'm}(i\omega)\braket{\phi_m|\chi_{\vK}}
\right)
\end{eqnarray}

We then use Eqs.~\ref{Eq:271} and \ref{Eq:272} and introduce the ``DMFT'' coefficients
\begin{eqnarray}
A \equiv A^0 \cB
\end{eqnarray}
to obtain Pulley forces in the form
\begin{eqnarray}
\vF^{Pulley}_{\alpha} =
-\Tr( w A^{\dagger}(R^{(1)}-R^{(2)}+R^{(3)}+R^{(4)}) A)
+\Tr( (\widetilde{w\varepsilon}) A^{\dagger}(Q^{(1)}-Q^{(2)})A) \\
+\int_{MT} d^3r V_{KS}(\vr)\nabla\rho^{DMFT}(\vr)
-\Tr\left(
A^0_{\vK i}
G(i\omega)_{ij}
A^{0\dagger}_{j\vK'}
i(\vK-\vK')\braket{\chi_{\vK'}|\phi_{m'}}\widetilde{\Sigma}_{m'm}(i\omega)\braket{\phi_m|\chi_{\vK}}
\right)
%
% -\Tr\left((\rho\Sigma)^{DMFT}_{ij;m'm}   A^{0\dagger}_{j\vK'}
% i(\vK-\vK')\braket{\chi_{\vK'}|\phi_{m'}}\braket{\phi_m|\chi_{\vK}}A^0_{\vK i}
% \right)
% \\
% +\Tr\left((\rho\Sigma)^{DMFT}_{ij;m'm}   A^{0\dagger}_{j\vK'}
% (\ll \chi_{\vK'}|\phi_{m'} \gg \braket{\phi_m|\chi_{\vK}}+\braket{\chi_{\vK'}|\phi_{m'}}\ll \phi_m|\chi_{\vK} \gg ) A^0_{\vK i}
% \right)
\end{eqnarray}
This can also be cast into the form
\begin{eqnarray}
\vF^{Pulley}_{\alpha} = -\sum_{i,j,\vK\vK'} A_{j\vK'}^{\dagger}  i(\vK-\vK')\braket{\chi_{\vK'}|(-\nabla^2+V_{KS}) w^{DMFT}_i\delta_{ij}-(\widetilde{w\varepsilon})_{ij}|\chi_\vK}_{MT}  A_{\vK i}
\label{Eq:305}\\
+\sum_{i,j\vK\vK'}A^{\dagger}_{j\vK'} [(\vk+\vK')(\vk+\vK) w^{DMFT}_i \delta_{ij}-(\widetilde{w\varepsilon})_{ij} ] A_{\vK i}\oint_{R_{MT}}d\vec{S}\tilde{\chi}_{\vk+\vK'}^*(\vr)\tilde{\chi}_{\vk+\vK}(\vr)
\label{Eq:306}\\
-\sum_i w^{DMFT}_i\sum_{\vK\vK'} A^{\dagger}_{i\vK'}  i(\vK-\vK')  A_{\vK i} \oint_{R_{MT}^-} d\vec{S}\chi^*_{\vk+\vK'}(\vr)\nabla_\vr \chi_{\vk+\vK}(\vr)
\label{Eq:307}\\
+\int_{MT} d^3r V_{KS}(\vr)\nabla\rho^{DMFT}(\vr)
\label{Eq:308}\\
-\frac{1}{\beta}\sum_{i\omega,ij,\vK\vK'}A^0_{\vK i} G_{ij}(i\omega) A^{0\dagger}_{j\vK'}i(\vK-\vK')\braket{\chi_{\vK'}|\phi_{m'}}\widetilde{\Sigma}_{m'm}(i\omega)\braket{\phi_m|\chi_{\vK}}
\label{Eq:309}\\
-\sum_i w_i^{DMFT}\sum_{\vK,\vK'} A^\dagger_{i\vK'} A_{\vK i} \oint_{MT}d\vec{S}
\left[\chi_{\vK'}^* V_{KS}\chi_{\vK} - \tilde{\chi}_{\vK'}^* V_{KS}\tilde{\chi}_{\vK}\right]
\label{Eq:310}
\end{eqnarray}
Notice that the last term is neglected as it should be small when
$l_{max}$ is sufficiently large.

\subsection{Implementation of Eq.~\ref{Eq:305}, symmetric part}

This is implemented in \verb Force1_DMFT .

Let's start with the part containing spherical symmetric Hamiltonian
\begin{eqnarray}
-i \sum_{i,\vK\vK'} w^{DMFT}_i (\vK-\vK') A^*_{\vK' i} \braket{\chi_{\vK'}|(-\nabla^2+V_{KS})| \chi_\vK}_{MT} A_{\vK i}
\end{eqnarray}

We first repeat Eq.~\ref{Eq:HmE}, which gives spherically symetric
part of Hamiltonian in the MT-part:
\begin{eqnarray}
\braket{\chi_{\vK'}|-\nabla^2+V^{sym}_{KS}(r)|\chi_\vK}_{MT}&=&
a^{\vK' *}_{lm}  a_{lm}^{\vK} E_\nu   +
b^{\vK' *}_{lm}  b_{lm}^\vK E_\nu \braket{\dot{u}_l|\dot{u}_l} +
\frac{1}{2}[a^{\vK' *}_{lm} b_{lm}^\vK +b_{lm}^{\vK'*} a^{\vK}_{lm} ]+
\nonumber\\
&+&
c^{\vK' *}_{lm}  c_{lm}^\vK E_{\mu}\braket{u_{LO}|u_{LO}} +
\frac{1}{2}[a^{\vK' *}_{lm} c_{lm}^\vK + c^{\vK' *}_{lm} a_{lm}^\vK ]  (E_{\mu}+E_\nu)\braket{u|u_{LO}} +
\nonumber\\
&+&
\frac{1}{2}[c^{\vK' *}_{lm}  b_{lm}^\vK + b^{\vK' *}_{lm}  c_{lm}^\vK ][ \braket{u_{LO}|u_l}  + (E_\mu+E_\nu)\braket{u_{LO}|\dot{u}_l} ]
\end{eqnarray}

Clearly, we can split the sum over $\vK$ and $\vK'$ into two
indepedent sums which take $O(N)$ time.[We want to avoid $O(N^2)$
scaling, since there are very many number of plane waves $\vK$].

We first define (compute) the following quantities
\begin{eqnarray}
a_{i,lm}=\sum_\vK A_{\vK i} \; a_{lm}^\vK\\
\vcA_{i,lm}=\sum_\vK \vK \; A_{\vK i} \; a_{lm}^\vK
\end{eqnarray}
which take $O(N)$ time to compute. Here $A_{\vK,i}$ are eigenvectors corresponding to the Kohn-Sham
energy $\varepsilon_i$. We assume corresponding expression for $b_{i,lm}$,
$c_{i,lm}$, $\vcB_{i,lm}$, $\vcC_{i,lm}$.

The quadratic terms of the form $a^*_{lm} a_{lm}$ become
\begin{eqnarray}
\sum_{\vK\vK'} (\vK-\vK') A_{\vK' i}^*  a^{\vK' *}_{lm}  a_{lm}^{\vK}  A_{i\vK} =
a_{i,lm}^* \vcA_{i,lm} - \vcA^*_{i,lm}  a_{i,lm} =
2i\; \Im\{ a_{i,lm}^* \vcA_{i,lm} \}
\end{eqnarray}
while those of the form $a^*_{lm}b_{lm}+b^*_{lm} a_{lm}$ become
\begin{eqnarray}
\sum_{\vK\vK'} (\vK-\vK') A_{\vK' i}^*  \frac{1}{2}[a^{\vK' *}_{lm} b_{lm}^{\vK} + b^{\vK' *}_{lm}  a_{lm}^{\vK} ]A_{\vK i} =
\frac{1}{2} [a_{i,lm}^* \vcB_{i,lm} - \vcA^*_{i,lm} b_{i,lm} +
  b^*_{i,lm} \vcA_{i,lm} - \vcB^*_{i,lm} a_{i,lm}]= \nonumber\\
=i\; \Im\{ a_{i,lm}^* \vcB_{i,lm} + b_{i,lm}^* \vcA_{i,lm}  \}
\end{eqnarray}

The term with $H^0$ can then be expressed by
\begin{eqnarray}
&& \sum_{\vK\vK'} (\vK-\vK')  A^*_{\vK'   i}\braket{\chi_{\vK'}|-\nabla^2+V_{KS}^{sph}(r)|\chi_\vK}_{MT}A_{\vK   i}=
\nonumber\\
&& i\Im\left\{
\left( 2 a_{i,lm}^* E_\nu + b_{i,lm}^* +   c^*_{i,lm} (E_{\mu}+E_\nu) \braket{u|u_{LO}} \right)\vcA_{i,lm}
\right\}+
%
\nonumber\\
&+& i\Im\left\{
\left(
a_{i,lm}^* +2 b_{i,lm}^* E_\nu \braket{\dot{u}_l|\dot{u}_l} +
c^*_{i,lm}  [ \braket{u_{LO}|u_l}  +    (E_\mu+E_\nu)\braket{u_{LO}|\dot{u}_l} ]\right)\vcB_{i,lm}
\right\}+
\nonumber\\
&+& i\Im\left\{
\left(
a^*_{i,lm} (E_{\mu}+E_\nu) \braket{u|u_{LO}}
+ b^*_{i,lm}  [ \braket{u_{LO}|u_l} + (E_\mu+E_\nu)\braket{u_{LO}|\dot{u}_l} ]
+ 2 E_\mu\; c^*_{i,lm}  \braket{u_{LO}|u_{LO}}
\right)\vcC_{i,lm}
\right\}
\end{eqnarray}

The overlap term is
\begin{eqnarray}
i \sum_{i,j,\vK\vK'} (\widetilde{w\varepsilon})_{ij} (\vK-\vK') A^*_{\vK' j} \braket{\chi_{\vK'}|\chi_\vK}_{MT}  A_{\vK i}
\end{eqnarray}
and the overlap of augmented PW functions is
\begin{eqnarray}
\braket{\chi_{\vK'}|\chi_\vK}_{MT}&=&
a^{\vK' *}_{lm}  a_{lm}^{\vK}  +
b^{\vK' *}_{lm}  b_{lm}^\vK \braket{\dot{u}_l|\dot{u}_l} +
\nonumber\\
&+&
c^{\vK' *}_{lm}  c_{lm}^\vK \braket{u_{LO}|u_{LO}}+
[a^{\vK' *}_{lm} c_{lm}^\vK + c^{\vK' *}_{lm} a_{lm}^\vK ]\braket{u|u_{LO}} +
\nonumber\\
&+&
[c^{\vK' *}_{lm}  b_{lm}^\vK + b^{\vK' *}_{lm}  c_{lm}^\vK ]\braket{u_{LO}|\dot{u}_l}
\end{eqnarray}
hence we obtain
\begin{eqnarray}
&& \sum_{ij}(\widetilde{w\varepsilon})_{ij}\sum_{\vK\vK'} (\vK-\vK')   A^*_{\vK' j}\braket{\chi_{\vK'}|\chi_\vK}_{MT}A_{\vK i}=
\nonumber\\
&& 2i\Im\left\{ \sum_{ij} (\widetilde{w\varepsilon})_{ij} \left(a_{j,lm}^*  + c^*_{j,lm} \braket{u_{LO}|u}\right)\vcA_{i,lm}\right\} +
\nonumber\\
&+& 2i\Im\left\{\sum_{ij} (\widetilde{w\varepsilon})_{ij}\left( b_{j,lm}^* \braket{\dot{u}_l|\dot{u}_l} +c^*_{j,lm}  \braket{u_{LO}|\dot{u}_l} \right) \vcB_{i,lm}\right\} +
\nonumber\\
&+& 2i\Im\left\{\sum_{ij} (\widetilde{w\varepsilon})_{ij}\left(a^*_{j,lm}\braket{u|u_{LO}} + b^*_{j,lm} \braket{\dot{u}_l|u_{LO}}  +c^*_{j,lm} \braket{u_{LO}|u_{LO}} \right)\vcC_{i,lm}\right\}
\nonumber
\end{eqnarray}
and the final result becomes
{
\small
\begin{eqnarray}
&&\vF(1)^{Pulley}_\alpha=
 -\sum_{i,j,\vK\vK'} A_{j\vK'}^{\dagger}  i(\vK-\vK')\braket{\chi_{\vK'}|(-\nabla^2+V_{KS}) w^{DMFT}_i\delta_{ij}-(\widetilde{w\varepsilon})_{ij}|\chi_\vK}  A_{\vK i}=
\nonumber\\
&& \sum_{i,lm} \Im\left\{
\left(
w_i \left[ 2 a_{i,lm}^* E_\nu + b_{i,lm}^* +   c^*_{i,lm} (E_{\mu}+E_\nu)  \braket{u|u_{LO}} \right]
-2\sum_{j} (\widetilde{w\varepsilon})_{ij}
\left [a_{j,lm}^*  + c^*_{j,lm} \braket{u|u_{LO}}\right]
\right)\vcA_{i,lm}
\right\}+
%
\nonumber\\
&+& \sum_{i,lm}\Im\left\{
\left(
w_i\left[
a_{i,lm}^* +2 b_{i,lm}^* E_\nu \braket{\dot{u}_l|\dot{u}_l} +c^*_{i,lm}  [ \braket{u_{LO}|u_l}  + (E_\mu+E_\nu)\braket{u_{LO}|\dot{u}_l} ]
\right]
-2\sum_j (\widetilde{w\varepsilon})_{ij}
\left[ b_{j,lm}^* \braket{\dot{u}_l|\dot{u}_l} +c^*_{j,lm}  \braket{u_{LO}|\dot{u}_l} \right]
\right)\vcB_{i,lm}
\right\}+
\nonumber\\
&+& \sum_{i,lm}\Im\Bigl\{
\Bigl(
w_i \left[
a^*_{i,lm} (E_{\mu}+E_\nu) \braket{u|u_{LO}} + b^*_{i,lm} [\braket{u_{LO}|u_l} + (E_\mu+E_\nu)\braket{u_{LO}|\dot{u}_l} ]+ 2  E_\mu\; c^*_{i,lm}\braket{u_{LO}|u_{LO}}
\right]
-\Bigr.
\Bigr.\nonumber\\
&&\qquad\qquad\qquad\qquad\qquad\qquad
\left.
\left.
-2\sum_j (\widetilde{w\varepsilon})_{ij}
\left[a^*_{j,lm}\braket{u|u_{LO}} + b^*_{j,lm} \braket{\dot{u}_l|u_{LO}}  +c^*_{j,lm} \braket{u_{LO}|u_{LO}} \right]
\right)\vcC_{i,lm}
\right\}
\end{eqnarray}
}
%
%
% which finally gives
% \begin{eqnarray}
% &&\vF(1)^{Pulley}_\alpha=
%  -\sum_i w^{DMFT}_i\sum_{j,\vK\vK'} A_{j\vK'}^{\dagger}  i(\vK-\vK')\braket{\chi_{\vK'}|(-\nabla^2+V_{KS})\delta_{ij}-\tilde{\varepsilon}_{ij}|\chi_\vK}  A_{\vK i}
% \\
% && \sum_i f_i\; \Im\left\{
% \left[
% 2 a_{i,lm}^* \; (E_\nu-\varepsilon_i)  +
% b_{i,lm}^*  +
% c^*_{i,lm} (E_{\mu}+E_\nu-2\varepsilon_i)\braket{u|u_{LO}}
% \right]
% \vcA_{i,lm}
% \right\}+
% \nonumber\\
% &+& \sum_i f_i\; \Im\left\{
% \left[
%  a_{i,lm}^* +
% 2  b_{i,lm}^* \;  (E_\nu-\varepsilon_i)\braket{\dot{u}_l|\dot{u}_l} +
% c^*_{i,lm}  [ \braket{u_{LO}|u_l}  + (E_\mu+E_\nu-2\varepsilon_i)\braket{u_{LO}|\dot{u}_l} ]
% \right]
% \vcB_{i,lm}
% \right\}+
% %
% \nonumber\\
% &+&\sum_i f_i\; \Im\left\{
% \left[
% b^*_{i,lm}   \braket{u_{LO}|u_l}  +
% [a^*_{i,lm} \braket{u_{LO}|u_l} + b^*_{i,lm} \braket{u_{LO}|\dot{u}_l} ](E_{\mu}+E_\nu-2\varepsilon_i)+
% 2 c^*_{i,lm}  \; (E_{\mu}-\varepsilon_i) \braket{u_{LO}|u_{LO}}
% \right]
% \vcC_{i,lm}
% \right\}
% \nonumber
% \end{eqnarray}

This force is called \verb fsph .

Note that $\vcA$, $\vcB$ and $\vcC$ are called
$aalm$, $bblm$, and $cclm$.

In Wien2k, this is implemented in function \verb fomai1 .
Also note that $\braket{\dot{u}|\dot{u}}=pei$, $\braket{u_{LO}|u}=pi12lo$, $\braket{u_{LO}|\dot{u}}=pe12lo$, $\braket{u_{LO}|u_{LO}}=pr12lo$.

\subsection{Implementation of Eq.~\ref{Eq:305}, non-symmetric part}

This is implemented in \verb Force2 .

The non-sperically symmetric part of Eq.~\ref{Eq:305} takes the form
\begin{eqnarray}
\vF(2)^{Pulley}_\alpha =
-i\sum_i w_i \sum_{\vK,\vK'} A_{i,\vK'}^* (\vK-\vK') A_{i,\vK}
\braket{ \chi_{\vK'}  |V_{KS}^{n-sym}(\vr)|\chi_{\vK}}_{MT}
\label{eq:Pule2n}
\end{eqnarray}

In file case.nsh, we read non-spherical symmetric potential, which is
given in the following form
\begin{eqnarray}
V^{non-sph}_{\kappa_1 l_1 m_1 \kappa_2 l_2 m_2} = \int d^3 r Y^*_{l_1 m_1}(\hat{\vr}) u^{\kappa_1} V^{n-sym}(\vr) u^{\kappa_2}Y_{l_2 m_2}(\hat{\vr})
\end{eqnarray}

The data in case.nsh contains the following matrix elements
\begin{eqnarray}
\braket{u|V|u} \rightarrow tuu\\
\braket{u|V|\dot{u}} \rightarrow tud\\
\braket{\dot{u}|V|u} \rightarrow tdu\\
\braket{\dot{u}|V|\dot{u}}\rightarrow tdd\\
\cdots
\end{eqnarray}

To evaluate the term, we substutute the definition for $\chi_\vK$ to obtain
\begin{eqnarray}
&& \sum_{\vK,\vK'} (\vK-\vK') A_{i\vK'}^* \braket{\chi_{\vK'}|V^{n-sym}|\chi_\vK}_{MT}A_{i\vK} =\\
&& \sum_{\vK,\vK'} (\vK-\vK') A_{i\vK'}^* \braket{
Y_{l_1 m_1}\sum_{\kappa_1} a_{l_1 m_1}^{\kappa_1,\vK'} u^{\kappa_1}_{l_1}|V^{n-sym}|
Y_{l_2 m_2}\sum_{\kappa_2} a_{l_2 m_2}^{\kappa_2,\vK} u^{\kappa_2}_{l_2}}A_{i\vK}
\end{eqnarray}
which simplifies to
\begin{eqnarray}
&&\sum_{\vK,\vK'} (\vK-\vK') A_{i\vK'}^* \braket{\chi_{\vK'}|V^{n-sym}|\chi_\vK}_{MT}A_{i\vK} =
\\
&& \sum_{\kappa_1 l_1 m_1,\kappa_2 l_2 m_2}
a_{l_1 m_1}^{*\kappa_1,i}\vcA_{l_2 m_2}^{\kappa_2,i}
V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}
-
\vcA_{l_1 m_1}^{*\kappa_1,i}a_{l_2 m_2}^{\kappa_2,i}
V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}=\\
&& 2i\Im\left\{
\sum_{\kappa_1 l_1 m_1,\kappa_2 l_2 m_2}
a_{l_1 m_1}^{*\kappa_1,i}\vcA_{l_2 m_2}^{\kappa_2,i}
V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}
\right\}
\end{eqnarray}
hence, we have
\begin{eqnarray}
&&\vF(2)^{Pulley}_\alpha=
\sum_i w_i \sum_{\kappa_1 l_1 m_1,\kappa_2 l_2 m_2}
2\Im
\left\{
a_{l_1 m_1}^{*\kappa_1,i}
V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}
\vcA_{l_2 m_2}^{\kappa_2,i}
\right\}
\end{eqnarray}

Implementation builds the following quantity
\begin{eqnarray}
afac(\kappa_2, l_1 m_1,l_2 m_2) = \sum_{\kappa_1} a_{l_1 m_1}^{*\kappa_1,i} V_{\kappa_1 l_1 m_1,\kappa_2  l_2 m_2}
\end{eqnarray}
and evaluates
\begin{eqnarray}
\vF(2)^{Pulley}_\alpha=\sum_i f_i \sum_{l_1 m_1,l_2 m_2, \kappa_2} 2\Im[afac(\kappa_2, l_1 m_1,l_2 m_2) \vcA_{l_2 m_2}^{\kappa_2,i} ]
\end{eqnarray}

Note that this force has name \verb fnsp .
Also note that $\vcA,\vcB,\vcC$ are called
\verb aalm, \verb bblm, \verb cclm   and matrix elements of $V$ are called tuu,tud,tdu,....

Within Wien2k this is implemented in \verb fomai1 .

\subsection{Implementation of term ~\ref{Eq:306}}

Next we discuss implementation of Eq.~\ref{Eq:306}:
\begin{eqnarray}
\vF(4)^{Pulley}_\alpha =
\sum_{i,\vK,\vG} w_i^{DMFT} (A^0\cB)_{\vK-\vG,i}^* (\vk+\vK-\vG)  (A^0\cB)_{\vK,i}  (\vk+\vK) R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr \\
-\sum_{ij,\vK,\vG} (A^0\cB)_{\vK,i} (\widetilde{w\varepsilon})_{ij} (A^0\cB)_{\vK-\vG,j}^* R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr
\label{eq:Pule4n}
\end{eqnarray}
or
\begin{eqnarray}
\vF(4)^{Pulley}_\alpha =
\sum_{i,\vK,\vG} w_i^{DMFT} (A^0\cB)_{\vK-\vG,i}^* (\vK+\vk-\vG)  (A^0\cB)_{\vK,i}  (\vK+\vk) R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr \\
-\sum_{ij,\vK,\vG} A^0_{\vK i}
(\cB (\widetilde{w\varepsilon}){\cB^\dagger})_{i j}
  A^{0*}_{\vK-\vG,j}R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr
\end{eqnarray}
or
\begin{eqnarray}
\vF(4)^{Pulley}_\alpha =
\sum_{i,\vK,\vG} w_i^{DMFT} (A^0\cB)_{\vK-\vG,i}^* (\vK+\vk-\vG)  (A^0\cB)_{\vK,i}  (\vK+\vk) R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}} \vec{e}_\vr\\
-\sum_{ij,\vK,\vG} A^0_{\vK i}  (\rho\varepsilon)^{DMFT}_{i j}
  A^{0*}_{\vK-\vG,j}R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr
\end{eqnarray}

We next diagonalize the density matrix
\begin{eqnarray}
 (\rho\varepsilon)^{DMFT} = \widetilde{\cB} w_\varepsilon \widetilde{\cB}^\dagger
\end{eqnarray}
and simplify
\begin{eqnarray}
\vF(4)^{Pulley}_\alpha =
\sum_{i,\vK,\vG} w_i^{DMFT} (A^0\cB)_{\vK-\vG,i}^* (\vK+\vk-\vG)  (A^0\cB)_{\vK,i}  (\vK+\vk) R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr \\
-\sum_{ij,\vK,\vG} (A^0\widetilde{\cB})_{\vK i} w_{\varepsilon,i}
(A^{0}\widetilde{\cB})^*_{\vK-\vG,i}R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr
\end{eqnarray}

The convolution in $\vK$ needs quadratic amount of time ($O(N^2)$). By using FFT
and turning it into product in real space, it takes only $N\log(N)$
time, hence we will use FFT for the following quantities
\begin{eqnarray}
&&\vec{X}_i(\vr)=\sum_\vK (A^0\cB)_{\vK,i}(\vK+\vk)e^{i\vK\vr}\\
&& Y_i(\vr)=\sum_\vK (A^0\widetilde{\cB})_{\vK,i}e^{i\vK\vr}
\end{eqnarray}
The inverse FFT should then be used to obtain aternative
representation for convolution
\begin{eqnarray}
\vF(4)^{Pulley}_\alpha  =
\int \frac{d^3r}{V} \sum_i e^{-i\vG\vr}[\vec{X}_i^*(\vr) w_i \vec{X}_i(\vr)- Y_i^*(\vr)w_{\varepsilon,i} Y_i(\vr)] R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}\vec{e}_\vr
 \end{eqnarray}
Finally, one can check that
\begin{equation}
\int d\Omega e^{i\vG\vr} \vec{e}_\vr={4\pi } \frac{\vG}{|\vG|}\;j_1(|\vG|R_{MT}) i e^{i\vG\vr_\alpha}
\end{equation}

In the code we compute
\begin{eqnarray}
ekink = \int \frac{d^3r}{V} \sum_i e^{-i\vG\vr}[\vec{X}_i^*(\vr) w_i \vec{X}_i(\vr)- Y_i^*(\vr)w_{\varepsilon,i} Y_i(\vr)]
\end{eqnarray}
which is computed in \verb l2main .

The final part of this force  is implemented in \verb Force_surface .

\subsection{Implementation of Eq.~\ref{Eq:307}}

Next we consider Eq.~\ref{Eq:307}, which is
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=-\sum_i w^{DMFT}_i\sum_{\vK\vK'} A^{\dagger}_{i\vK'}  i(\vK-\vK')  A_{\vK i} \oint_{R_{MT}^-} d\vec{S}\chi^*_{\vk+\vK'}(\vr)\nabla_\vr \chi_{\vk+\vK}(\vr)
\end{eqnarray}
We know that the therm should be real, therefore we will symmetrize it
to show this explicitely
\begin{eqnarray}
\vF(3)^{Pulley}_\alpha = -\frac{1}{2}\sum_i w_i \sum_{\vK,\vK'}
A_{i\vK'}^\dagger i(\vK-\vK')   A_{\vK i}
\oint_{r=R_{MT}^-} d\vec{S}
[\chi_{\vK'+\vk}^*(\vr)  \nabla_\vr\chi_{\vK+\vk}(\vr) +  \chi_{\vK+\vk}(\vr) \nabla \chi_{\vK'+\vk}^*(\vr)  ]
\end{eqnarray}
which is equal to
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=-\frac{1}{2}\sum_{\vk,i} w_i
\sum_{\vK,\vK'}
i(\vK-\vK') A^*_{\vK' i} A_{\vK i}\;
R_{MT}^2
\oint_{r=R_{MT^-}} d\Omega\;
[
\chi_{\vK'+\vk}^*(\vr) \frac{\partial}{\partial r}\chi_{\vK+\vk}+
\chi_{\vK+\vk}(\vr)  \frac{\partial}{\partial r}\chi_{\vK'+\vk}^*(\vr)
]
\end{eqnarray}
and inserting expression for $\chi$ we get
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=-\frac{1}{2}\sum_{\vk,i} w_i
\sum_{\vK,\vK'} i(\vK-\vK')
A^*_{\vK' i} A_{\vK i}\;
R_{MT}^2
\sum_{l,m,\kappa',\kappa}
a_{lm,\vK'}^{\kappa'\,*} u_l^{\kappa'} a_{lm,\vK}^\kappa  {u'}_l^\kappa+
a_{lm,\vK}^{\kappa'} u_l^{\kappa'} a^{\kappa\,*}_{lm,\vK'} {u'}_l^\kappa
\end{eqnarray}
and summing over $\vK$ and $\vK'$ gives
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=-\frac{i}{2}\sum_{\vk,i} w_i
R_{MT}^2
\sum_{l,m,\kappa',\kappa}
[
a_{i,lm}^{\kappa'\,*} u_l^{\kappa'} \vcA_{i,lm}^\kappa  {u'}_l^\kappa+
\vcA_{i,lm}^{\kappa'} u_l^{\kappa'} a^{\kappa\,*}_{i,lm}  {u'}_l^\kappa
-\vcA_{i,lm}^{\kappa'\,*} u_l^{\kappa'} a_{i,lm}^\kappa  {u'}_l^\kappa
-a_{i,lm}^{\kappa'} u_l^{\kappa'} \vcA^{\kappa\,*}_{i,lm} {u'}_l^\kappa
]
\end{eqnarray}
which can be simplified to
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=R_{MT}^2 \sum_{\vk,i} w_i
\sum_{l,m,\kappa',\kappa}
\Im[a_{i,lm}^{\kappa'\,*} u_l^{\kappa'} \vcA_{i,lm}^\kappa  {u'}_l^\kappa
+\vcA_{i,lm}^{\kappa'} u_l^{\kappa'} a^{\kappa\,*}_{i,lm}  {u'}_l^\kappa
]
\label{Eq:358}
\end{eqnarray}

We can then define the following quantities
\begin{eqnarray}
kinfac(1,ilm) = \sum_{\kappa} a_{i,lm}^{\kappa} u_l^{\kappa}(R_{MT})\\
kinfac(2,ilm) = \sum_\kappa a_{i,lm}^\kappa  {u'}_l^\kappa(R_{MT})\\
kinfac(3,ilm) = \sum_\kappa \vcA_{i,lm}^\kappa  {u'}_l^\kappa(R_{MT})\\
kinfac(4,ilm) = \sum_{\kappa} \vcA_{i,lm}^{\kappa} u_l^{\kappa}(R_{MT})
\end{eqnarray}
and write
\begin{eqnarray}
\vF(3)_\alpha^{Pulley}=R_{MT}^2 \sum_{\vk,i} w_i \sum_{l,m}\Im[
(kinfac(1,ilm))^* kinfac(3,ilm)+kinfac(4,ilm) (kinfac(2,ilm))^*]
\end{eqnarray}

This part of the force is named \verb fsph2  and is coded in
\verb fomai1  within Wien2k, and in \verb Force3  in my code.

\subsubsection{Alternative implementation using plane waves}

We are free to choose any form of the kinetic energy, either
$\nabla\cdot\nabla$ or $-\nabla^2$. We could choose the form to be
$-\nabla^2$ and then we would get the same term computed with the
interstitial basis functions. The problem is that these functions are
not continuous and hence the left derivative is different that the
right derivative. The best way out is than to use the average of the
left and right derivative, hence we will compute the same term with
interstitial charge, and then average over both terms.

The Eq.~\ref{Eq:307} using plane wave functions is
\begin{eqnarray}
\vF(3)^{Pulley}_\alpha
&=& -\frac{1}{2}\sum_i w_i \sum_{\vK,\vK'}
A_{i\vK'}^\dagger i(\vK-\vK')   A_{\vK i}
\oint_{r=R_{MT}} d\vec{S}
[\tilde{\chi}_{\vK'+\vk}^*(\vr)  \nabla_\vr\tilde{\chi}_{\vK+\vk}(\vr) +  \tilde{\chi}_{\vK+\vk}(\vr) \nabla \tilde{\chi}_{\vK'+\vk}^*(\vr)  ]=
\label{Eq:364}\\
&=&-\frac{1}{2}\sum_i w_i \sum_{\vK,\vK'}
A_{i\vK'}^\dagger i(\vK-\vK')   A_{\vK i}
\oint_{r=R_{MT}} d\vec{S}
\nabla_\vr( \tilde{\chi}_{\vK'+\vk}^*(\vr)\tilde{\chi}_{\vK+\vk}(\vr))
\label{Eq:365}
\end{eqnarray}
If we go one step back and check derivation of kinetic energy part,
Eq.~\ref{Eq:276}, we see that replacing $\nabla^2$ in the
interstitials with $\nabla\cdot\nabla$ would generate a term
\begin{eqnarray}
\oint_{MT}d\vec{S} \tilde{\chi}^*_{\vK'} (-\nabla^2)\tilde{\chi}_\vK = \oint_{MT} d\vec{S}\nabla\tilde{\chi}_{\vK'}^*\cdot\nabla\tilde{\chi}_\vK-
\oint_{MT} d\vec{S} \nabla\cdot(\tilde{\chi}_{\vK'}^* \nabla\tilde{\chi}_\vK)
\end{eqnarray}
which, when inserted into Pulley force, leads to a term
\begin{eqnarray}
\vF = -\sum_i w_i \sum_{\vK\vK}A_{i\vK'}^\dagger  A_{\vK i} \oint_{MT} d\vec{S} \nabla\cdot(\tilde{\chi}^*_{\vK'}\nabla\tilde{\chi}_{\vK})
\rightarrow -\frac{1}{2}\sum_i w_i \sum_{\vK\vK}A_{i\vK'}^\dagger  A_{\vK i}  \oint_{MT} d\vec{S} \nabla\cdot(
\tilde{\chi}^*_{\vK'}\nabla\tilde{\chi}_{\vK}+\tilde{\chi}_{\vK}  \nabla\tilde{\chi}^*_{\vK'})
\end{eqnarray}
The last simplification is obtained by symmetrizing the term, as force
should be real. We can notice that this expression is equivalent to
the above derived Eq.~\ref{Eq:364}, however, now we can rewrite the
integral into even a simpler form
\begin{eqnarray}
\vF = -\frac{1}{2}\sum_i w_i \sum_{\vK\vK}A_{i\vK'}^\dagger  A_{\vK i}
  \oint_{MT} d\vec{S} \nabla^2 (\tilde{\chi}^*_{\vK'} \tilde{\chi}_{\vK})=-\frac{1}{2}\oint_{MT}d\vec{S}\nabla^2\tilde{\rho}(\vr).
\label{Eq:368n}
\end{eqnarray}
We will show below that both forms Eq.~\ref{Eq:365} and
Eq.~\ref{Eq:368n} lead to the same expression for the force.

Starting from Eq.~\ref{Eq:365} we get
\begin{eqnarray}
\vF(3)^{Pulley}_\alpha = \frac{1}{2}\sum_i w_i \sum_{\vK,\vK'}
A_{i\vK'}^\dagger (\vK-\vK')   A_{\vK i}\; e^{i(\vK-\vK')\vR_\alpha}
\oint_{r=R_{MT}} d\vec{S} \cdot (\vK-\vK') \frac{1}{V_{cell}}e^{i(\vK-\vK')\vr}
\end{eqnarray}
or
\begin{eqnarray}
\vF(3)^{Pulley}_\alpha = \frac{1}{2}
\sum_{i,\vK,\vG} A_{\vK-\vG,i}^* w_i  A_{\vK i}\;
\vG\; e^{i\vG \vR_\alpha}
\oint_{r=R_{MT}} d\vec{S} \cdot \vG \frac{1}{V_{cell}}e^{i\vG \vr}
\end{eqnarray}
We then recognize the density in the interstitials, which was
previously computed by FFT
\begin{eqnarray}
\tilde{\rho}_\vG = \frac{1}{V_{cell}}\sum_{i,\vK,\vk} A_{\vK-\vG,i}^* w_i  A_{\vK i}
\end{eqnarray}
Our force then becomes
\begin{eqnarray}
\vF(3)^{Pulley}_\alpha = \frac{1}{2}
\sum_{\vG} \tilde{\rho}_\vG \vG\; e^{i\vG \vR_\alpha}
\oint_{r=R_{MT}} d\vec{S} \cdot \vG e^{i\vG \vr}
\end{eqnarray}

It is straighorward to show
\begin{eqnarray}
\int d\Omega (\vec{e}_\vr \cdot \vG) e^{i\vG\vr} = 4\pi i j_1(|G| R_{MT})|G|
\end{eqnarray}
hence the force is
\begin{eqnarray}
\vF(3)^{Pulley}_\alpha = \frac{R_{MT}^2}{2}
\sum_{\vG} \tilde{\rho}_\vG 4\pi j_1(|\vG| R_{MT})
i e^{i\vG \vR_\alpha}
|\vG| \vG
\end{eqnarray}

For alternative derivation we start from Eq.~\ref{Eq:368n} and write
\begin{eqnarray}
\vF = -\frac{1}{2}\oint_{MT}d\vec{S}\nabla^2\tilde{\rho}(\vr)=
\frac{1}{2}\oint_{MT}d\vec{S} \sum_\vG G^2 \tilde{\rho}_\vG e^{i\vG\vR_{\alpha}}e^{i\vG\vr}=
\frac{R_{MT}^2}{2}
\sum_\vG G^2 \tilde{\rho}_\vG e^{i\vG\vR_{\alpha}}
\int d\Omega e^{i\vG\vr}\vec{e}_\vr
\end{eqnarray}
It is easy to show that
\begin{eqnarray}
\int d\Omega \vec{e}_\vr e^{i\vG\vr} =4\pi i j_1(G R_{MT})\frac{\vG}{|\vG|}
\end{eqnarray}
hence we obtain the same expression
\begin{eqnarray}
\vF =\frac{R_{MT}^2}{2}
\sum_\vG \tilde{\rho}_\vG e^{i\vG\vR_{\alpha}}
4\pi i j_1(G R_{MT}) |\vG|\vG
\end{eqnarray}

[It turns out that this formula does not give the same value as its
implementation with augmented plane waves (inside MT sphere) Eq~\ref{Eq:358}. I do not
understand why. Misterious!].

\subsection{Implementation of Eq.~\ref{Eq:308}}

\begin{eqnarray}
\vF(5)^{Pulley}_\alpha=\int_{MT} d^3r V_{KS}(\vr) \nabla\rho(\vr) =
\sum_{l m s l' m' s'}\int d^3r  V_{l'm' s'}(r) y_{l'm's'}(\hat{\vr}) \nabla (\rho_{lms}(r) y_{lms}(\hat{\vr}))
\end{eqnarray}
Here we use the real spheric harmonics, introduced in Kurki-Suonio,
which are defined by
\begin{eqnarray}
y_{lm+} = \frac{1}{\sqrt{2(1+\delta_{m,0})}}(Y_{l,-m}+(-1)^m  Y_{l,m})=\sqrt{\frac{2}{1+\delta_{m,0}}}(-1)^m \Re Y_{lm}\\
y_{lm-} = \frac{1}{\sqrt{2(1+\delta_{m,0})}}(Y_{l,-m}-(-1)^m  Y_{l,m}) =\sqrt{\frac{2}{1+\delta_{m,0}}}(-1)^m \Im Y_{lm}
\end{eqnarray}
Notice that in Wien2k $Y_{lm}$'s are not defined in a standard way as
in most QM textbooks, but are defined as in classical mechanics with
an extra $(-1)^m$. Hence, in Wien2k, one needs to add $(-1)^m$ to the
above definitions.

The operator $\nabla$ in spheric harmonics is
\begin{eqnarray}
\nabla f = \vec{e}_r\frac{\partial}{\partial r} +\frac{\sin\theta}{r}
\left(\begin{array}{c}
-\cos\theta\cos\phi\\
-\cos\theta\sin\phi\\
\sin\theta
\end{array}
\right)
\frac{\partial}{\partial (\cos\theta)} +
\frac{1}{r\sin\theta}
\left(\begin{array}{c}
-\sin\phi\\
 \cos\phi\\
0
\end{array}
\right)
\frac{\partial}{\partial\phi}=
\vec{e}_r\frac{\partial}{\partial r} +\frac{1}{r} \nabla_{\theta\phi}
\end{eqnarray}
The last form emphasizes that $\nabla$ has the radial part and a angle
part. Using this decomposition, we can write
\begin{eqnarray}
\vF(5)^{Pulley}_\alpha=\int d^3r V_{KS}(\vr) \nabla\rho(\vr) &=&
 \sum_{l m s l' m' s'}\int_0^\infty dr r^2  V_{l'm' s'}(r) \frac{d\rho_{lms}(r)}{dr}
\int  d\Omega y_{l'm's'}(\hat{\vr})  \vec{e}_r y_{lms}(\hat{\vr})\\
&+&\sum_{l m s l' m' s' }\int_0^\infty dr r^2   \frac{V_{l'm' s'}(r) \rho_{lms}(r)}{r}
\int  d\Omega y_{l'm' s'}(\hat{\vr})  \nabla_{\theta\phi} Y_{lms}(\hat{\vr})
\end{eqnarray}
We then define the following integrals
\begin{eqnarray}
I^1_{l'm's'lms} &\equiv& \int d\Omega y_{l'm's'}(\hat{\vr}) \vec{e}_\vr  y_{lms}(\hat{\vr}) \\
I^2_{l'm's'lms} &\equiv& \int d\Omega y_{l'm's'}(\hat{\vr}) (r\nabla) y_{lms}(\hat{\vr}) \\
I^3_{l'm's'lms} &\equiv& \int d\Omega (r\nabla y_{l'm's'}(\hat{\vr}))\cdot ( r\nabla  y_{lms}(\hat{\vr})) \vec{e}_\vr
\end{eqnarray}
and rewrite
\begin{eqnarray}
\vF(5)^{Pulley}_\alpha =
 \sum_{l m s l' m' s'}\int_0^\infty dr r^2  V_{l'm' s'}(r) \frac{d\rho_{lms}(r)}{dr} I^1_{l'm's'lms}
+\sum_{l m s l' m' s' }\int_0^\infty dr r^2   \frac{V_{l'm' s'}(r) \rho_{lms}(r)}{r} I^2_{l'm's'lms}
\end{eqnarray}

In the following, we will need these integrals:
\begin{eqnarray}
I^1_{l'm'lm} &\equiv& \int d\Omega Y^*_{l'm'}(\hat{\vr}) \vec{e}_\vr  Y_{lm}(\hat{\vr}) \\
I^2_{l'm'lm} &\equiv& \int d\Omega Y^*_{l'm'}(\hat{\vr}) (r\nabla Y_{lm}(\hat{\vr})) \\
I^3_{l'm'lm} &\equiv& \int d\Omega (r\nabla Y^*_{l'm'}(\hat{\vr}))\cdot ( r\nabla  Y_{lm}(\hat{\vr})) \vec{e}_\vr\\
\end{eqnarray}

We first compute the following integral
\begin{eqnarray}
&&I^1_{l'm'lm}\equiv\int d\Omega Y^*_{l'm'}(\hat{\vr}) \vec{e}_r Y_{lm}(\hat{\vr})=\\
&&(-1)^{m+m'}
\sqrt{\frac{(2l+1)(l-m)!(2l'+1)(l'-m')!}{4\pi(l+m)! 4\pi (l'+m')!}}
\int_{-1}^1 dx
 P_{l'}^{m'}(x) P_l^m(x)
\left(
\begin{array}{c}
\sqrt{1-x^2} \int_0^{2\pi} d\phi\;  e^{i(m-m')\phi}\cos\phi \\
\sqrt{1-x^2} \int_0^{2\pi} d\phi\;  e^{i(m-m')\phi}\sin\phi\\
x \int_0^{2\pi} d\phi\;  e^{i(m-m')\phi}
\end{array}
\right)
\end{eqnarray}

\begin{eqnarray}
I^1_{l'm'lm}=(-1)^{m+m'}\pi
\sqrt{\frac{(2l+1)(l-m)!(2l'+1)(l'-m')!}{4\pi(l+m)! 4\pi (l'+m')!}}
\int_{-1}^1 dx
 P_{l'}^{m'}(x) P_l^m(x)
 \left(
\begin{array}{c}
\sqrt{1-x^2} \delta_{m'=m\pm 1}\\
\mp i \sqrt{1-x^2}  \delta_{m'=m\pm 1}\\
2 x \delta_{mm'}
\end{array}
\right)
\end{eqnarray}
which is equal to
\begin{eqnarray}
I^1_{l'm'lm}=
\pi \delta_{m'=m\pm 1}
\sqrt{\frac{(2l+1)(l-m)!(2l'+1)(l'-m\mp 1)!}{4\pi(l+m)! 4\pi (l'+m\pm 1)!}}
\int_{-1}^1 dx
 P_{l'}^{m\pm 1}(x) P_l^m(x)
\sqrt{1-x^2}
 \left(
\begin{array}{c}
-1 \\
\pm i
\\
0\end{array}
\right)
\nonumber\\
+
2\pi \delta_{mm'}
\sqrt{\frac{(2l+1)(l-m)!(2l'+1)(l'-m)!}{4\pi(l+m)! 4\pi (l'+m)!}}
\int_{-1}^1 dx
 P_{l'}^{m}(x) P_l^m(x) x
 \left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\end{eqnarray}
With the help of the following well known recursion relation
\begin{eqnarray}
&& \sqrt{1-x^2}P_l^m = \frac{1}{2l+1}\left[P_{l-1}^{m+1}-P_{l+1}^{m+1}\right]
\\
&& \sqrt{1-x^2}P_l^m = \frac{1}{2l+1}
\left[(l-m+1)(l-m+2)P_{l+1}^{m-1}-(l+m-1)(l+m)P_{l-1}^{m-1}\right]
\\
&& x P_l^m = \frac{1}{2l+1} \left[
(l-m+1)P_{l+1}^m+(l+m)P_{l-1}^m
\right]
\end{eqnarray}
we arrive at
\begin{eqnarray}
I^1_{l'm'lm}=
\left(
\begin{array}{c}
-1\\
i\\
0
\end{array}
\right)
\frac{1}{2}\left[
\delta_{l'=l-1}
\sqrt{\frac{(l-m)(l-m-1)}{(2l+1)(2l-1)}}-
\delta_{l'=l+1}
\sqrt{\frac{(l+m+1)(l+m+2)}{(2l+1)(2l+3)}}
\right]\delta_{m'=m+1}
+\\+
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}\left[
\delta_{l'=l+1}
\sqrt{\frac{(l-m+1)(l-m+2)}{(2l+1)(2l+3)}}-
\delta_{l'=l-1}
\sqrt{\frac{(l+m)(l+m-1)}{(2l+1)(2l-1)}}
\right]\delta_{m'=m-1}
+\\+
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\left[
\delta_{l'=l+1}
\sqrt{\frac{(l-m+1)(l+m+1)}{(2l+1)(2l+3)}}+
\delta_{l'=l-1}
\sqrt{\frac{(l+m)(l-m)}{(2l-1)(2l+1)}}
\right]\delta_{m'=m}
\end{eqnarray}

Let's define
\begin{eqnarray}
a(l,m)=\sqrt{\frac{(l+m+1)(l+m+2)}{(2l+1)(2l+3)}}\\
f(l,m)=\sqrt{\frac{(l+m+1)(l-m+1)}{(2l+1)(2l+3)}}\\
\end{eqnarray}

and rewrite
\begin{eqnarray}
I^1_{l'm'lm}=
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}\left[
a(l,m)
\delta_{l'=l+1}-
a(l',-m')
\delta_{l'=l-1}
\right]\delta_{m'=m+1}
+\\+
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}\left[
a(l,-m)
\delta_{l'=l+1}
-
a(l',m')\delta_{l'=l-1}
\right]\delta_{m'=m-1}
+\\+
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\left[
f(l,m)
\delta_{l'=l+1}
+
f(l',m')
\delta_{l'=l-1}
\right]\delta_{m'=m}
\end{eqnarray}

Next we compute the following integral
\begin{eqnarray}
I^2_{l'm'lm}\equiv\int d\Omega Y^*_{l'm'}(\hat{\vr}) \nabla_{\theta\phi} Y_{lm}(\hat{\vr})=
\int d\Omega Y^*_{l'm'}(\hat{\vr}) (r\nabla)   Y_{lm}(\hat{\vr})
\end{eqnarray}
Due to Wigner-Eckart theorem, we know the dependence on $m,m'$ is
equal to $I^1_{l'm'lm}$. The
dependence on $l,l'$ can be either found numerically, or analytically
using several recursion relations.

The result for $I^2$ is
\begin{eqnarray}
I^2_{l'm'lm}=
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}\left[
-l\; a(l,m)\delta_{l'=l+1}-
(l+1)\; a(l',-m')\delta_{l'=l-1}
\right]\delta_{m'=m+1}
+\\+
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\frac{1}{2}
\left[-l\; a(l,-m) \delta_{l'=l+1}-(l+1)\; a(l',m')\delta_{l'=l-1}
\right]\delta_{m'=m-1}
+\\+
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\left[-l\; f(l,m) \delta_{l'=l+1}
+
(l+1) f(l',m')\delta_{l'=l-1}
\right]\delta_{m'=m}
\end{eqnarray}

We can write both integrals in a common form, namely,
\begin{eqnarray}
I^n_{l'm'lm}=c_{n,l}
\left[
a(l,m)
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l,-m)
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
+2 f(l,m)
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l+1}
\\
-d_{n,l}
\left[
a(l',-m')
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l',m')
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
-2 f(l',m')
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l-1}
\end{eqnarray}
where
\begin{eqnarray}
& c_{1,l} = \frac{1}{2}      & d_{1,l}=\frac{1}{2}\\
& c_{2,l}=-\frac{l}{2}       & d_{2,l}=\frac{l+1}{2}\\
& c_{3,l}=\frac{l(l+2)}{2} & d_{3,l}=\frac{(l-1)(l+1)}{2}
\end{eqnarray}
We also gave coefficients for $I^3$, which gives kinetic energy operator
integrated over the sphere of the MT-sphere.

In the code, we use real spheric harmonics $y_{lm\pm}$, which are related
to complex spheric harmonics by
\begin{eqnarray}
&Y_{lm}&=(-1)^m \sqrt{\frac{1+\delta_{m,0}}{2}}(y_{lm+}+i y_{lm-})\\
&Y_{l,-m}&=\sqrt{\frac{1+\delta_{m,0}}{2}}(y_{lm+}-i y_{lm-})
\end{eqnarray}

In Section.~\ref{OnRealHarm} we derive the connection between the
matrix elements of the real harmonics and complex harmonics, and we
also derive the matrix elements $\braket{y_{l'm's'}|T|y_{lms}}$. Here
we just give the final result:

\begin{eqnarray}
\braket{y_{l'm'\pm}|T|y_{lm\pm}}  =
c_{n,l}\;\delta_{l'=l+1}
\left(
\begin{array}{c}
-a(l,m)\delta_{m'=m+1}\frac{(1\pm\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}
+a(l,-m)\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}} \\
0\\
2 f(l,m)\delta_{m'=m} \frac{(1\pm\delta_{m=0})}{1+\delta_{m=0}}
\end{array}
\right)
%
\nonumber\\
\left.
%
-d_{n,l}\;\delta_{l'=l-1}
\left(
\begin{array}{c}
-a(l',-m')\delta_{m'=m+1}\frac{(1\pm\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}+a(l',m')\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}}\\
0\\
-2 f(l',m')\delta_{m'=m}\frac{(1\pm\delta_{m=0})}{1+\delta_{m=0}}
\end{array}
\right)
\right\}
\end{eqnarray}
and
\begin{eqnarray}
\braket{y_{l'm'\pm}|T|y_{lm\mp}}  =
\pm\left(
\begin{array}{c}
0\\
1\\
0
\end{array}
\right)
\left\{
c_{n,l}\;\delta_{l'=l+1}
\left(
  a(l,m)\delta_{m'=m+1}\frac{(1\mp\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}+a(l,-m)\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}}
\right)
\right.
%
\nonumber\\
%
\left.
-d_{n,l}\;\delta_{l'=l-1}
\left(
a(l',-m')\delta_{m'=m+1}\frac{(1\mp\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}+a(l',m')\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}}
\right)
\right\}
\end{eqnarray}

This term has name \verb fomai2  in Wien2k, and is coded in program \verb Force4_mine .
This part reads non-spherical potential $V_{KS}(\vr)$ and calls
another subprogram  \verb VdRho , which performns the integration.

\subsection{Implementation of Eq.~\ref{Eq:309}}

This is implemented in \verb cmpLogGdloc .

% In Eq.~\ref{Eq:310} we have $\ll \phi_m|\chi_{\vK} \gg $ which is
% defined in  Eq.~\ref{Eq:197}, and takes the form
% \begin{eqnarray}
%  \ll \phi_m|\chi_\vK \gg\equiv \braket{\nabla\phi_m|\chi_{\vK}}+\braket{\phi_m|\nabla\chi_{\vK}}= \oint_{R_{MT}^-} d\vS\; \phi^*_m(\vr) \chi_{\vK}
% \end{eqnarray}
% If the localized projector has pure angular momentum character of $l$,
% than only angular momentum of $l\pm 1$ from $\chi_{\vK}$ would
% contribute to this integral. If an ion has mostly $3d$ states at the
% Fermi level, this would require $\chi_\vK$ to have non-negligible $2p$ or $4f$
% character on the same atom. This almost never happens as the
% separation of $l$ states is quite large in all ions. We therefore
% neglect the term Eq.~\ref{Eq:310}.
%
%

We will first rearange terms from Eq.~\ref{Eq:309} in the following way
\begin{eqnarray}
Eq.~\ref{Eq:309}=-\frac{1}{\beta}\sum_{i\omega}G_{ij}(i\omega)\left\{
 \braket{\psi^0_{j}|\phi_{m'}}\Sigma_{m'm}(i\omega)\braket{\phi_m|\psi^0_{i'}}\braket{\psi^0_{i'}|\chi_{\vK}}  i\vK  A^0_{\vK  i}
- A^{0\dagger}_{j\vK'} i\vK' \braket{\chi_{\vK'}|\psi^0_{i'}}\braket{\psi^0_{i'}|\phi_{m'}}\Sigma_{m'm}(i\omega)\braket{\phi_m|\psi^0_{i}}
\right\}
\nonumber
\end{eqnarray}
Now we recognize that
$\braket{\chi^0_{\vK'}|\psi^0_{i}}=O_{\vK'\vK}A^0_{\vK i}$ and
$U_{im} = \braket{\psi^0_i|\phi_m}$
hence
\begin{eqnarray}
Eq.~\ref{Eq:309}=-\frac{1}{\beta}\sum_{i\omega}G_{ij}(i\omega)\left\{
U_{jm'}\Sigma_{m'm}(i\omega)
U^\dagger_{m i'}
(A^{0\dagger} O)_{i'\vK} i\vK  A^0_{\vK  i}
- A^{0\dagger}_{j\vK'} i\vK' (O A^0)_{\vK' i'}
U_{i'm'}
\Sigma_{m'm}(i\omega)U^\dagger_{mi}
\right\}
\nonumber
\end{eqnarray}
We next define the following quantites
\begin{eqnarray}
&& \vec{\cR}_{ij} = \sum_\vK A^{0\dagger}_{i\vK} \vK (O A^0)_{\vK j}\\
&& \vec{U}_{im} = \sum_j \vec{\cR}_{ij} U_{jm}
\end{eqnarray}
In practice, we can directly compute $\vec{U}$ from the following
\begin{eqnarray}
\vec{U}_{im} = \sum_\vk A^{0*}_{\vK i}\vK\braket{\chi_{\vK}|\phi_m}
\end{eqnarray}
%
% to simplify
% \begin{eqnarray}
% Eq.~\ref{Eq:309}=-\frac{1}{\beta}\sum_{i\omega}G_{ij}(i\omega) i \left\{
% U_{jm'}\Sigma_{m'm}(i\omega)
% U^\dagger_{m i'}
% \vec{\cR}^\dagger_{i' i}
% - \vec{\cR}_{j i'}
% U_{i'm'}
% \Sigma_{m'm}(i\omega)U^\dagger_{mi}
% \right\}
% \nonumber
% \end{eqnarray}
% or
We then simplify
\begin{eqnarray}
Eq.~\ref{Eq:309}=
-\frac{1}{\beta}\sum_{i\omega}
i\left\{
\vec{U}^\dagger  G(i\omega) U
- U^\dagger  G(i\omega)  \vec{U} \right\}_{mm'}\Sigma_{m'm}(i\omega)
\nonumber
\end{eqnarray}
The first term has the form
$\Tr\left(\vec{U}^\dagger  G(i\omega) U  \Sigma(i\omega)\right)$
and if we just replace $i\omega\rightarrow -i\omega$, we get an
equivalent form
$\Tr\left(\vec{U}^\dagger  G(-i\omega) U \Sigma(-i\omega)\right)$,
which can also be written as
$\Tr\left(\vec{U}^\dagger G^\dagger(i\omega) U  \Sigma^\dagger(i\omega)\right)=
\textrm{Conjugate}\left(\Tr\left(\Sigma(i\omega) U^\dagger G(i\omega)    \vec{U}\right)\right)
=\textrm{Conjugate}\left(\Tr\left(U^\dagger    G(i\omega)  \vec{U}\Sigma(i\omega) \right)\right)$.
The last form is equal to the second term, but conjugated, hence, the
result is real. We can hence also write
\begin{eqnarray}
Eq.~\ref{Eq:309}=
2\Im\left\{ \frac{1}{\beta}\sum_{i\omega,mm'}
\left[ \vec{U}^\dagger  G(i\omega) U\right]_{mm'}\Sigma_{m'm}(i\omega) \right\}
\end{eqnarray}
We hence need to compute vector projector $\vec{U}$ in addition to
$U$ and project the DMFT Green's function to this vector form.
We define the following generalized projector
\begin{eqnarray}
\vec{\tau}_{ij}^{mm'}= i (\vec{U}^*_{im} U_{jm'}-U_{im}^* \vec{U}_{jm'})
\end{eqnarray}
which is called ``lgtrans'' in the code.
We then have
\begin{eqnarray}
Eq.~\ref{Eq:309}=
-\frac{1}{\beta}\sum_{i\omega,mm'}\Sigma_{m'm}(i\omega)\sum_{ij} \vec{\tau}_{ij}^{mm'} G_{ij}(i\omega)
\nonumber
\end{eqnarray}
We call $\vec{G}^{mm'}_{d\; local}=\sum_{ij} \vec{\tau}_{ij}^{mm'}G_{ij}(i\omega)$ and compute
it in ``cmp\_dmft\_weights''.

\subsection{Implementation of Eq.~\ref{Eq:310}}

We start with the plane-wave part of Eq.~\ref{Eq:310}, which takes the
form
\begin{eqnarray}
\vF^{Pulley} =\sum_i w_i^{DMFT}\sum_{\vK,\vK'} A^\dagger_{i\vK'} A_{\vK i} \oint_{MT}d\vec{S}\tilde{\chi}_{\vK'}^* V_{KS}\tilde{\chi}_{\vK}
\\
=\sum_\vG e^{i\vG\vR_\alpha}
\sum_{i,\vK}  A^*_{\vK-\vG i} w_i^{DMFT}  A_{\vK i} \oint_{R_{MT}}d\vec{S}  \frac{e^{i\vG\vr}}{V_{cell}} V_{KS}(\hat{\vr})
\label{Eq:396}
\end{eqnarray}

We use FFT to compute the convolution (charge in the interstitials):
\begin{eqnarray}
\widetilde{\rho}_{\vG} = \frac{1}{V_{cell}}\sum_{\vk,i,\vK}  A^{\vk*}_{\vK-\vG i} w_{\vk,i}^{DMFT}  A^{\vk}_{\vK i}
\end{eqnarray}
and  the expansion of the KS-potential in terms of real spheric
harmonics
\begin{eqnarray}
V_{KS}(\vr) = \sum_{lms} V^{KS}_{lms}(r)\; y_{lms}(\vr)
\end{eqnarray}
to obtain
\begin{eqnarray}
\vF^{Pulley} =\sum_\vG
e^{i\vG\vR_\alpha} \; \widetilde{\rho}_{\vG} \;{R_{MT}^2} \sum_{lms} V^{KS}_{lms}(R_{MT}) \int d\Omega\; y_{lms}(\hat{\vr}) e^{i\vG\vr}\vec{e}_\vr
\end{eqnarray}
Notice here that $V_{KS}$ is written in the local coordinate system,
hence $y_{lms}$'s also need to be specified in the local coordinate
system attached to an atom. On the other hand, $e^{i\vG\vR_\alpha} $ can be computed in
the global coordinate systsem.

Next we use the well known expansion of plane wave in spherical waves
\begin{eqnarray}
e^{i\vG\vr} = \sum_{l,m} 4\pi i^l j_l(G r) Y_{lm}^*(\hat{\vG})  Y_{lm}(\hat{\vr})=
\sum_l 4\pi i^l j_l(G r) \sum_{m\ge 0,s=\pm} y_{lm s}(\hat{\vG}) y_{lms}(\hat{\vr})
\end{eqnarray}
The second form is for real harmonics used for potential and charge
within Wien2k.
We hence obtain
\begin{eqnarray}
\vF^{Pulley} =\sum_\vG
e^{i\vG\vR_\alpha} \; \widetilde{\rho}_{\vG} \;{R_{MT}^2} \sum_{lms}  V^{KS}_{lms}(R_{MT})
\sum_{l'm's'} 4\pi i^{l'} j_{l'}(G r) y_{l'm' s'}(\hat{\vG})
\int d\Omega\; y_{lms}(\hat{\vr}) \vec{e}_\vr  y_{l'm's'}(\hat{\vr})
\end{eqnarray}

We then recognize the interstitial charge density on the MT-sphere, i.e.,
\begin{eqnarray}
\rho_{lms}(R_{MT}) = \sum_\vG \widetilde{\rho}_{\vG} \;  e^{i\vG\vR_\alpha}
4\pi i^l j_l(GR_{MT}) y_{lms}(\hat{\vG})
\label{Eq:405}
\end{eqnarray}
and the matrix elements previously computed
\begin{eqnarray}
\vec{I}^{1}_{l'm's'lms}\equiv \braket{y_{l'm's'}|\vec{e}_\vr|y_{lms}}
\end{eqnarray}
to simplify
\begin{eqnarray}
\vF^{Pulley} =R_{MT}^2 \sum_{lms} \rho_{lms}(R_{MT}) \sum_{l'm's'} V^{KS}_{l'm's'} I^1_{lmsl'm's'}
\end{eqnarray}

For each atom, we precompute the quantity
\begin{eqnarray}
\vec{V}_{lms}(R_\alpha) =\sum_{l'm's'} V^{KS}_{l'm's'}(R_{MT})  \vec{I}^{1}_{l'm's' lms}
\end{eqnarray}
which gives simple expression for the force
\begin{eqnarray}
\vF^{Pulley} =R_{MT}^2 \sum_{lms} \rho_{lms}(R_{MT}) \vec{V}_{lms}(R_\alpha)
\label{Eq:412}
\end{eqnarray}
The most time consuming is calculation of the interstitial charge on
the MT-sphere. It can be computed in the following way
\begin{eqnarray}
\rho_{lms}(R_{MT}) = 4\pi \sum_{\vG_0} \widetilde{\rho}_{\vG} \;
i^l j_l(GR_{MT})
\sum_{\vG\in \vG_0-star} e^{i\vG\vR_\alpha}
y_{lms}(\hat{\vG})
\end{eqnarray}

% ------------------------------------------
%
% \begin{eqnarray}
% \vF^{Pulley} =\sum_\vG \widetilde{\rho}_{\vG} \; e^{i\vG\vR_\alpha} R_{MT}^2 \sum_{lms} V^{KS}_{lms}(R_{MT}) \int d\Omega\; y_{lms}(\hat{\vr}) e^{i\vG\vr}\vec{e}_\vr
% \end{eqnarray}
% \begin{eqnarray}
% \vF^{Pulley} =\sum_\vG \widetilde{\rho}_{\vG} \; e^{i\vG\vR_\alpha}
% R_{MT}^2 \sum_{lms,l'm's'} 4\pi i^{l'} j_{l'}(G  R_{MT}) V^{KS}_{lms}(R_{MT}) y_{l'm' s'}(\hat{\vG})
% \int d\Omega\; y_{lms}(\hat{\vr}) \vec{e}_\vr   y_{l'm's'}(\hat{\vr})
% \end{eqnarray}
%
% to simplify
% \begin{eqnarray}
% \vF^{Pulley} =\sum_\vG \widetilde{\rho}_{\vG} \; e^{i\vG\vR_\alpha}
% {4\pi R_{MT}^2}\sum_{lms} i^{l} j_{l}(G  R_{MT}) y_{lm s}(\hat{\vG})
% \sum_{l'm's'} V^{KS}_{l'm's'}(R_{MT})  \vec{I}^{1}_{l'm's' lms}
% \end{eqnarray}
% and compute
% \begin{eqnarray}
% \vF^{Pulley} ={4\pi R_{MT}^2}\sum_{\vG_0} \widetilde{\rho}_{\vG_0}
%  \sum_{\vG\in \vG_0-star}\; e^{i\vG\vR_\alpha}
% \sum_{l} e^{i l \frac{\pi}{2}}  j_{l} (G_0  R_{MT})
% \sum_{ms}  y_{lm s}(\hat{\vG}) \vec{V}_{lms}(R_\alpha)
% \end{eqnarray}

The MT-part can also be computed with Eq.~\ref{Eq:412}, except that
$\rho_{lms}$ is in this case already computed and stored, hence the
calculation is trivial.

Alternatively, we can check the MT-part by using previously computed
voulme integrlas $\Tr(V_{KS}\nabla\rho)$. We
start from
\begin{eqnarray}
\vF^{Pulley}=-\sum_i w_i^{DMFT}\sum_{\vK,\vK'} A^\dagger_{i\vK'} A_{\vK i} \oint_{MT}d\vec{S}\chi_{\vK'}^* V_{KS}\chi_{\vK}
\end{eqnarray}
and use Gauss theorem to derive
\begin{eqnarray}
\oint_{MT}d\vec{S}\chi_{\vK'}^* V_{KS}\chi_{\vK}  = \int_{MT} d^3r  \left(\nabla(\chi^*_{\vK'}\chi_{\vK}) V_{KS} + \chi^*_{\vK'}\chi_{\vK} \nabla V_{KS} \right)
\end{eqnarray}
hence
\begin{eqnarray}
F^{Pulley}=-\sum_i w_i^{DMFT}\sum_{\vK,\vK'} A^\dagger_{i\vK'} A_{\vK i} \int_{MT} d^3r  \left(V_{KS}\nabla(\chi^*_{\vK'}\chi_{\vK})  + \chi^*_{\vK'}\chi_{\vK} \nabla V_{KS} \right)=
-\Tr(V_{KS}\nabla \rho)-\Tr(\rho \nabla V_{KS})
\end{eqnarray}
Above we computed $\Tr(V_{KS}\nabla \rho)$. In the same way we can
also compute $\Tr(\rho \nabla V_{KS})$.

\subsection{Check equivalence with LDA+U formula}
To check previous equation on LDA+U, we notice that in Wien2k
implementation, the projector is
$Y^*_{lm'}(\hat{\vr})\delta(r-r')Y_{lm}(\hat{\vr}')$. We then have
$U_{im'}\Sigma_{m'm}U^{\dagger}_{mj}=\braket{\psi^0_i|\phi_{m'}}\Sigma_{m'm}\braket{\phi_m|\psi^0_j}=
A^{0\dagger}_{i\vK'}\braket{\chi_{\vK'}|\phi_{m'}}\Sigma_{m'm}\braket{\phi_m|\chi_\vK}A^0_{\vK  j}$
and
$\vec{\cR}^\dagger=A^{0\dagger} O \vK A^0$
hence
\begin{eqnarray}
U_{im'}\Sigma_{m'm}U^{\dagger}_{mj'}\vec{\cR}^\dagger_{j'j}
=A^{0\dagger}_{i\vK'} {a^{\vK'\kappa'}_{lm'}}^*\Sigma^l_{m'm}a^{\vK\kappa}_{lm}
\braket{u^{\kappa'}_l|u^\kappa_l}(A^0 A^{0\dagger} O \vK A^0)_{\vK j}\\
=A^{0\dagger}_{i\vK'} {a^{\vK'\kappa'}_{lm'}}^*\Sigma^l_{m'm}a^{\vK\kappa}_{lm}
\braket{u^{\kappa'}_l|u^\kappa_l}\vK A^0_{\vK j}
={a^{\kappa'\;*}_{ilm'}}\Sigma^l_{m'm}\braket{u^{\kappa'}_l|u^\kappa_l}\vec{\cA}^\kappa_{jlm}
\end{eqnarray}
In LDA+U the self-energy $\Sigma$ is static, hence summation over $i\omega$ of
$G(i\omega)$ gives  $\delta_{ij} f_{\vk i}$ and then Eq.~\ref{Eq:309}
is equivalent to
$$2\Im\left\{\sum_i f_{\vk i} {a^{\kappa'\;*}_{ilm'}}\Sigma^l_{m'm}\braket{u^{\kappa'}_l|u^\kappa_l}\vec{\cA}^\kappa_{ilm}\right\}$$
which is exactly the LDA+U force implemented in Eq.~\ref{Eq:160}

\newpage
% % or
% % \begin{eqnarray}
% % \delta F = \Tr\left( G (A^\dagger (\delta H^0) A  -  A^\dagger  (\delta O) A \varepsilon_0)
% % +\Tr(G \delta (\braket{\psi^0_{i\vk}|\phi_{m'}}(V_U-V_{DC})_{m'm}\braket{\phi_m|\psi^0_{j\vk}})) \right)
% %  \nonumber\\
% % - \Tr( \delta V_{KS}^{LDA} \rho)
% % -\delta \Tr( (V_U-V_{DC})\braket{\phi| \rho|\phi})
% % + \Tr( (V_U-V_{DC})\delta n)
% % -\sum_\alpha F^{HF}_\alpha \delta R_\alpha
% % \end{eqnarray}
% %
% % \begin{eqnarray}
% % A^\dagger (\delta H^0) A  -  A^\dagger  (\delta O) A \varepsilon_0=
% % A^\dagger_{j\vK'} (\braket{\delta\chi_{\vK'}|H^0-\varepsilon^0_i|\chi_{\vK}} +  \braket{\chi_{\vK'}|H^0-\varepsilon^0_i|\delta\chi_{\vK}}  +\braket{\chi_{\vK'}|\delta H^0|\chi_{\vK}} )A_{\vK i}
% % \end{eqnarray}
% %
% % Note that the density can be expressed in old Kohn-Sham basis ($G$) or
% % new diagonal basis $B^\dagger G B = 1/(i\omega+\mu-\varepsilon)$, and hence
% % \begin{eqnarray}
% % \frac{1}{\beta}\sum_{i\omega} G_{ij}(i\omega)  = B_{il} f_{l\vk} B^\dagger_{lj}
% % \end{eqnarray}
% %
% % \begin{eqnarray}
% % \delta F = \Tr\left( B f_\vk B^\dagger (
% % A^\dagger_{j\vK'} (\braket{\delta\chi_{\vK'}|H^0-\varepsilon^0_i|\chi_{\vK}} +  \braket{\chi_{\vK'}|H^0-\varepsilon^0_i|\delta\chi_{\vK}}  +\braket{\chi_{\vK'}|\delta H^0|\chi_{\vK}} )A_{\vK i}
% % ) \right)\\
% % +\Tr\left(B f_{\vk} B^\dagger \delta (\braket{\psi^0_{i\vk}|\phi_{m'}}(V_U-V_{DC})_{m'm}\braket{\phi_m|\psi^0_{j\vk}})) \right)
% % - \Tr( \delta V_{KS}^{LDA} \rho)
% % -\Tr( (\delta V_U-\delta V_{DC}) n)
% % -\sum_\alpha F^{HF}_\alpha \delta R_\alpha
% % \end{eqnarray}
% % which becomes
% % \begin{eqnarray}
% % \delta F =  f_{i\vk}
% % (AB)^\dagger_{i\vK'}
% %   (\braket{\delta\chi_{\vK'}|H^0-\varepsilon^0_i|\chi_{\vK}} +
% %   \braket{\chi_{\vK'}|H^0-\varepsilon^0_i|\delta\chi_{\vK}}
% %   +\braket{\chi_{\vK'}|\delta T+\delta V_{KS}|\chi_{\vK}} )(AB)_{\vK i}
% % \\
% % +\Tr\left( B f_{i\vk} B^\dagger \delta  (\braket{\psi^0_{i\vk}|\phi_{m'}}(V_U-V_{DC})_{m'm}\braket{\phi_m|\psi^0_{j\vk}})  \right)
% % -\Tr( (\delta V_U-\delta V_{DC}) n)
% % \\
% % - \Tr( \delta V_{KS}^{LDA} \rho)
% % -\sum_\alpha F^{HF}_\alpha \delta R_\alpha
% % \end{eqnarray}
% % Now the term $\Tr(\delta V_{KS}\rho)$ cancels and we obtain
% % \begin{eqnarray}
% % \delta F =  f_{i\vk}
% % (AB)^\dagger_{i\vK'}
% %   (\braket{\delta\chi_{\vK'}|H^0-\varepsilon^0_i|\chi_{\vK}} +
% %   \braket{\chi_{\vK'}|H^0-\varepsilon^0_i|\delta\chi_{\vK}}
% % )(AB)_{\vK i}
% %  +\braket{\psi_{i\vk}|\delta T|\chi_{i\vk}}
% % \\
% % +\Tr\left((B f_{\vk} B^\dagger)_{ji} (V_U-V_{DC})_{m'm}
% % \delta (\braket{\psi^0_{i\vk}|\phi_{m'}}\braket{\phi_m|\psi^0_{j\vk}}) \right)
% % -\sum_\alpha F^{HF}_\alpha \delta R_\alpha
% % \end{eqnarray}
% %
% % This expression differs from the one in the previous section by
% % \begin{eqnarray}
% %   f_{i\vk}[
% % (\varepsilon_i-\varepsilon^0_i)
% % (AB)^\dagger_{i\vK'}\delta(O_{\vK'\vK}) (AB)_{\vK i}
% % -\delta(B_{ji}B^\dagger_{ip})
% % \braket{\psi^0_{p\vk}|V_U-V_{DC}|\psi^0_{j\vk}}
% % ]
% % \end{eqnarray}
% %
% % \subsection{LDA+DMFT}
% % We take small variation of the free energy to get
% % \begin{eqnarray}
% % \delta F = \Tr(\rho \delta (\ket{\psi_{i\vk}}\varepsilon^{LDA}_{i\vk}\bra{\psi_{i\vk}}) )
% % +\Tr(G\delta (\ket{\phi}(\Sigma-V_{DC})\bra{\phi} ))
% % -\Tr(\rho(\delta V_H + \delta V_{xc}))-\Tr((V_H+V_{xc})\delta\rho )\nonumber\\
% % -\Tr( G \delta(\ket{\phi}(\Sigma-V_{DC})\bra{\phi}))
% % -\Tr( \ket{\phi}(\Sigma-V_{DC})\bra{\phi} \delta G)
% % +\Tr( (V_H+V_{xc})\delta\rho)
% % +\Tr((\Sigma-V_{DC})\delta G_{loc})-\sum_\alpha \vec{F}^{HF}_\alpha \delta \vR_\alpha\nonumber
% % \end{eqnarray}
% %
% % \begin{eqnarray}
% % \delta F = \Tr(\rho^{DMFT} \delta (\ket{\psi_{i\vk}}\varepsilon^{LDA}_{i\vk}\bra{\psi_{i\vk}}) )
% % -\Tr(\rho^{DMFT}(\delta V_H + \delta V_{xc})) -\sum_\alpha \vec{F}^{HF}_\alpha \delta \vR_\alpha\nonumber
% % \\
% % -\Tr( \ket{\phi}(\Sigma-V_{DC})\bra{\phi} \delta G)
% % +\Tr((\Sigma-V_{DC})\delta G_{loc})
% % \end{eqnarray}
% % We know that
% % $$\Tr((\Sigma-V_{DC})\delta
% % G_{loc})=\Tr((\Sigma-V_{DC})\delta\braket{\phi|G|\phi})=\Tr((\Sigma-V_{DC})\braket{\delta\phi|G|\phi})+\Tr((\Sigma-V_{DC})\braket{\phi|G|\delta\phi})+\Tr((\Sigma-V_{DC})\braket{\phi|\delta
% %   G|\phi})$$
% % hence we have
% % \begin{eqnarray}
% % \delta F = \Tr(\rho^{DMFT} \delta (\ket{\psi_{i\vk}}\varepsilon^{LDA}_{i\vk}\bra{\psi_{i\vk}}) )
% % -\Tr(\rho^{DMFT}(\delta V_H + \delta V_{xc})) -\sum_\alpha \vec{F}^{HF}_\alpha \delta \vR_\alpha\nonumber
% % \\
% % +\Tr((\Sigma-V_{DC}) (\braket{\delta\phi|G|\phi}+ \braket{\phi|G|\delta\phi})))
% % \end{eqnarray}
% %
% % Different. We evaluate $\Tr\log$ and $\Tr\Sigma G$ in KS basis, while
% % the rest is integrated in real space with integration. The free energy
% % we evaluate thus takes the form
% % \begin{eqnarray}
% % F = -\Tr\log\left( i\omega+\mu
% % -\delta_{ij}\varepsilon^{LDA}_{i\vk}
% % -\braket{\psi_{i\vk}|\phi}(\Sigma-V_{dc})\braket{\phi|\psi_{j\vk}} \right)
% % - \Tr((V_H+V_{xc})\rho) \nonumber\\
% % - \Tr( \braket{\psi_{i\vk}|\phi}(\Sigma-V_{DC})\braket{\phi|\psi_{j\vk}} \braket{\psi_{j\vk}|G|\psi_{i\vk}})
% % + E_{H}[\rho]+E_{xc}[\rho]
% % + \phi^{DMFT}[G_{local}]-\phi^{DC}[\rho_{local}]
% % + E_{nucleous}
% % \label{DFMT:func2}
% % \end{eqnarray}
% % The variaton then gives
% % \begin{eqnarray}
% % \delta F =
% %   \Tr\left(G_{ii}\delta\varepsilon_{i\vk}^{LDA}\right)+\Tr\left(G_{ji}\delta(  \braket{\psi_{i\vk}|\phi}(\Sigma-V_{dc})\braket{\phi|\psi_{j\vk}})\right)
% % - \Tr((V_H+V_{xc})\delta\rho) -\Tr(\rho(\delta V_H+\delta V_{xc})) \nonumber\\
% % - \Tr(G_{ji}\delta( \braket{\psi_{i\vk}|\phi}(\Sigma-V_{DC})\braket{\phi|\psi_{j\vk}}))
% % - \Tr( \braket{\psi_{i\vk}|\phi}(\Sigma-V_{DC})\braket{\phi|\psi_{j\vk}}  \delta \braket{\psi_{j\vk}|G|\psi_{i\vk}}) \\
% % + \Tr((V_{H}+V_{xc})\delta\rho)
% % + \Tr( (\Sigma-V_{DC})\delta G_{loc})
% % -\sum_\alpha \vec{F}^{HF}_\alpha \delta \vR_\alpha
% % \label{DFMT:func3}
% % \end{eqnarray}
% % which siplifies to
% % \begin{eqnarray}
% % \delta F =
% %   \Tr\left(n^{DMFT}_{ii}\delta\varepsilon_{i\vk}^{LDA}\right)
% % -\Tr(\rho(\delta V_H+\delta V_{xc}))
% % -\sum_\alpha \vec{F}^{HF}_\alpha \delta \vR_\alpha
% % \\
% % - \Tr( \braket{\psi_{i\vk}|\phi}(\Sigma-V_{DC})\braket{\phi|\psi_{j\vk}}  \delta \braket{\psi_{j\vk}|G|\psi_{i\vk}})
% % + \Tr( (\Sigma-V_{DC})\delta \braket{\phi|\psi_{i\vk}}\braket{\psi_{i\vk}|G|\psi_{j\vk}}\braket{\psi_{j\vk}|\phi})
% % \label{DFMT:func3}
% % \end{eqnarray}

\section{Appendices}

\subsection{Equivalence between Krakauer and Soler derivation}

In Krakauer/Singh method, one uses an expansion of the basis function
to calculate matrix elements of overlap and kinetic energy.
The change of the basis functions due to a shift is
\begin{eqnarray}
\frac{\delta \chi_{\vK}(\vr-\vR_\alpha)}{\delta\vR_\alpha}\approx
  i(\vk+\vK)\chi_\vK(\vr-\vR_\alpha) - \nabla_\vr\chi_\vK(\vr-\vR_\alpha)+\cdots
\end{eqnarray}
and according to Singh, one should calculate the change of the matrix elements in the
following way
\begin{eqnarray}
\delta\braket{\chi_{\vK'}|T|\chi_{\vK}}&=&
\braket{\delta\chi_{\vK'}|T|\chi_{\vK}}
+\braket{\chi_{\vK'}|T|\delta\chi_{\vK}}
+\braket{\chi_{\vK'}|\delta T|\chi_{\vK}}\\
&=&
\braket{i(\vk+\vK')\chi_{\vK'}-\nabla\chi_{\vK'}|T|\chi_\vK}
+\braket{\chi_{\vK'}|T|i(\vk+\vK)\chi_{\vK}-\nabla\chi_{\vK}}\\
&+&\oint_{r=R_{MT}^-} d\vec{S}\chi^*_{\vK'} T \chi_{\vK}
-\oint_{r=R_{MT}^+} d\vec{S}\widetilde{\chi}^*_{\vK'} T \widetilde{\chi}_{\vK}
\end{eqnarray}
The last line stands for the discontinuity term, which appears when
the matrix elements $\chi_{\vK'}T\chi_{\vK}$ are not continuous
across the MT boundary.
For $r=R_{MT}^+$ we used different symbol for $\chi$ to emphasize its
form as plane wave in the interstitials [This convention is used in
Soler/Williams work].

It was shown by Soler/Williams in PRB 47, 6784 (1993) that this
expression is equivalent to their formulation of the force. For us, it
is important to get equivalent expression, which I can rationalize
(see below).

Let's simplify the above expression
\begin{eqnarray}
\delta\braket{\chi_{\vK'}|T|\chi_{\vK}}=
i(\vK-\vK')\braket{\chi_{\vK'}|T|\chi_\vK}_{MT}
-\int_{r<R_{MT}}d^3r [(\nabla\chi^*_{\vK'}) T \chi_\vK+\chi_{\vK'}^* T \nabla\chi_{\vK}]\\
+\oint_{r=R_{MT}^-} d\vec{S}\chi^*_{\vK'} T \chi_{\vK}
-\oint_{r=R_{MT}^+} d\vec{S}\widetilde{\chi}^*_{\vK'} T \widetilde{\chi}_{\vK}
\label{Eq:366}
\end{eqnarray}
Using Stokes theorem, we can convert
\begin{eqnarray}
\int_{r<R_{MT}}d^3r [(\nabla\chi^*_{\vK'}) T \chi_\vK+\chi_{\vK'}^* T  \nabla\chi_{\vK}=
\int_{r<R_{MT}}d^3r  \nabla (\chi^*_{\vK'}  T \chi_\vK) = \oint_{r=R_{MT}^-}d\vec{S}\chi^*_{\vK'}  T \chi_\vK
\end{eqnarray}
which cancels a term in Eq.~\ref{Eq:366} and gives
\begin{eqnarray}
\delta\braket{\chi_{\vK'}|T|\chi_{\vK}}=
i(\vK-\vK')\braket{\chi_{\vK'}|T|\chi_\vK}_{MT}
-\oint_{r=R_{MT}^+} d\vec{S}\widetilde{\chi}^*_{\vK'} T \widetilde{\chi}_{\vK}
\label{Eq:368}
\end{eqnarray}
We can use Stokes theorem one more time to obtain
\begin{eqnarray}
\oint_{r=R_{MT}^+} d\vec{S}\widetilde{\chi}^*_{\vK'} T  \widetilde{\chi}_{\vK}=
\int_{r<R_{MT}} d^3r \nabla (\widetilde{\chi}^*_{\vK'} T  \widetilde{\chi}_{\vK})=
\braket{\nabla\widetilde{\chi}_{\vK'} |T|\widetilde{\chi}_{\vK}}_{MT}+
\braket{\widetilde{\chi}_{\vK'} |T|\nabla\widetilde{\chi}_{\vK}}_{MT}
\end{eqnarray}
and since $\widetilde{\chi}_{\vK}$ are plane waves, we get
\begin{eqnarray}
\oint_{r=R_{MT}^+} d\vec{S}\widetilde{\chi}^*_{\vK'} T  \widetilde{\chi}_{\vK}=
i(\vK-\vK')\braket{\widetilde{\chi}_{\vK'} |T|\widetilde{\chi}_{\vK}}_{MT}
\end{eqnarray}
Inserting this expression back into Eq.~\ref{Eq:368}, gives
\begin{eqnarray}
\delta\braket{\chi_{\vK'}|T|\chi_{\vK}}=
i(\vK-\vK')\left[
\braket{\chi_{\vK'}|T|\chi_\vK}_{MT}-
\braket{\widetilde{\chi}_{\vK'} |T|\widetilde{\chi}_{\vK}}_{MT}
\right]
\label{Eq:371}
\end{eqnarray}
This latter expression Eq.~\ref{Eq:371} was used in Soler/Williams, and can be derived explicitely
from the form of the basis functions $\chi_{\vK}$.
For simplicity, we will work with APW basis functions, but the result
is general and works also for LAPW functions. The explicit form of
$\chi_\vK$ inside the MT-sphere at $\vR_\alpha$ is
\begin{eqnarray}
\chi_{\vK}(\vr) = u_l(|\vr-\vR_\alpha|)
  Y_{lm}(R(\hat{\vr}-\hat{\vR}_\alpha))
\frac{4\pi i^l}{\sqrt{V}}e^{i(\vk+\vK)\vR_\alpha}
  Y_{lm}^*(R(\vk+\vK)) \frac{j_l(|\vk+\vK|S)}{u_l(S)}
\end{eqnarray}
The form in the interstitial is as always the plane wave
\begin{eqnarray}
\widetilde{\chi}_\vK(\vr) = \frac{1}{\sqrt{V}} e^{i(\vk+\vK)\vr}
\end{eqnarray}
When we move the atom $\alpha$, we do not change the interstitial part
$\widetilde{\chi}_\vK$ or any other atom, except atom at
$\vR_\alpha$. (We imagine moving $\alpha$ atom at the fixed
interstitial wave function.) The reason that $\chi$ changes is because
of the matching condition at the MT sphere changes. We have
explicitely
\begin{eqnarray}
\braket{\chi_{\vK'}|T|\chi_{\vK}} =
\braket{\widetilde{\chi}_{\vK'}|T|\widetilde{\chi}_{\vK}}_I +
\sum_\beta \braket{\chi_{\vK'}|T|\chi_{\vK}}_{MT-\beta} =
\braket{\widetilde{\chi}_{\vK'}|T|\widetilde{\chi}_{\vK}}
+\sum_\beta \braket{\chi_{\vK'}|T|\chi_{\vK}}_{MT-\beta} -\braket{\widetilde{\chi}_{\vK'}|T|\widetilde{\chi}_{\vK}}_{MT-\beta}
\end{eqnarray}
The first term is now extended to the entire space, and is constant as
we move the atom. The second term is changed, but only $MT-\alpha$
term, when atom at $\vR_\alpha$ is moved.
 We can also explicitely write the second term
\begin{eqnarray}
\braket{\chi_{\vK'}|T|\chi_{\vK}} = \braket{\widetilde{\chi}_{\vK'}|T|\widetilde{\chi}_{\vK}} +
%
\sum_\alpha  e^{i(\vK-\vK')\vR_\alpha}
  Y_{l'm'}(R(\vk+\vK'))   Y_{lm}^*(R(\vk+\vK))
\frac{(4\pi)^2 j_l(|\vk+\vK|S) j_{l'}(|\vk+\vK'|S)}{V u_l(S) u_{l'}(S)}
\nonumber\\
\times
\int_{MT-\alpha} d^3r \;
u_{l'}(|\vr-\vR_\alpha|)  Y^*_{l'm'}(R(\hat{\vr}-\hat{\vR}_\alpha))
\hat{T}
u_l(|\vr-\vR_\alpha|)  Y_{lm}(R(\hat{\vr}-\hat{\vR}_\alpha)) \\
- e^{i(\vK-\vK')\vR_\alpha} \int_{MT-\alpha} d^3 r\; e^{-i(\vk+\vK')(\vr-\vR_\alpha)} \hat{T}  e^{i(\vk+\vK)(\vr-\vR_\alpha)}
\end{eqnarray}
We work at fixed $u_l$ functions, hence the form of $u_l(r)$ does not
change as we move the atom. Their position however changes. In the
last two parts of the above equation we can change the integration variable
from $\vr-\vR_\alpha$ to $\vr$ and we see
\begin{eqnarray}
\braket{\chi_{\vK'}|T|\chi_{\vK}} = \braket{\widetilde{\chi}_{\vK'}|T|\widetilde{\chi}_{\vK}} +
%
\sum_\alpha  e^{i(\vK-\vK')\vR_\alpha}
  Y_{l'm'}(R(\vk+\vK'))   Y_{lm}^*(R(\vk+\vK))
\frac{(4\pi)^2 j_l(|\vk+\vK|S) j_{l'}(|\vk+\vK'|S)}{V u_l(S) u_{l'}(S)}
\nonumber\\
\times
\int_{r<S} d^3r \;
u_{l'}(r)  Y^*_{l'm'}(R\hat{\vr})
\hat{T}
u_l(r)  Y_{lm}(R\hat{\vr}) \\
-  e^{i(\vK-\vK')\vR_\alpha} \int_{r<S} d^3 r\; e^{-i(\vk+\vK')\vr} \hat{T}  e^{i(\vk+\vK)\vr}
\end{eqnarray}
The only place where $\vR_\alpha$ appears is in the phase factor
$e^{i(\vK-\vK')\vR_\alpha}$, while the real space integral is not
affected at all by moving atom $\alpha$.
As the first term
$\braket{\widetilde{\chi}_{\vK'}|T|\widetilde{\chi}_{\vK}}$ is not
affected by moving the atom, we conclude
\begin{eqnarray}
\frac{\delta}{\delta\vR_\alpha}\braket{\chi_{\vK'}|T|\chi_{\vK}} =
%
i(\vK-\vK') e^{i(\vK-\vK')\vR_\alpha}\left\{
%
  Y_{l'm'}(R(\vk+\vK'))   Y_{lm}^*(R(\vk+\vK))
\frac{(4\pi)^2 j_l(|\vk+\vK|S) j_{l'}(|\vk+\vK'|S)}{V u_l(S)
  u_{l'}(S)}
\right.
\nonumber\\
\left.
\times
\int_{r<S} d^3r \;
u_{l'}(r)  Y^*_{l'm'}(R\hat{\vr})
\hat{T}
u_l(r)  Y_{lm}(R\hat{\vr})
-\int_{r<S} d^3 r\; e^{-i(\vk+\vK')\vr} \hat{T}  e^{i(\vk+\vK)\vr}\right\}
\end{eqnarray}
We can summarize our result by more concise equation
\begin{eqnarray}
\frac{\delta}{\delta\vR_\alpha}\braket{\chi_{\vK'}|T|\chi_{\vK}} =
i(\vK-\vK') \left[\braket{\chi_{\vK'}|T|\chi_{\vK}}_{MT-\alpha} -\braket{\widetilde{\chi}_{\vK'}|T|\widetilde{\chi}_{\vK}}_{MT-\alpha} \right]
\end{eqnarray}

\subsection{General form of small variation within both methods  Krakauer and Soler}

To show the connection between the Krakauer/Singh and Soler/Williams
more clearly, we write a case of 1D functions.
Imagine we have a 1D functions $f(x)=e^{i k a} f_0(x-a)$, $g(x)=e^{i  q a} g_0(x-a)$, defined in the interval $[a-S,a+S]$.
Outside this interval $f(x)$ and $g(x)$ are different functions [such
as plane waves] denoted by $\tilde{f}(x)$ and $\tilde{g}(x)$.
The functions outside the interval $[a-S,a+S]$ $\tilde{f}$ and
$\tilde{g}$ do not change with the shift.

We will discuss two types of operators, which we call ``rigid'' and
``non-rigid''.  If $\frac{\delta V}{\delta a}=0$, we call the operator
``rigid''. An example is kinetic energy operator
$T =\nabla\cdot\nabla$, which does not change as we shift the atom.

A ``non-rigid'' operator, such as Kohn-Sham potential, can be writen
within muffin-thin sphere as $V(a,x-a)$, to emphasize that an operator
shifts with the atom, but it also changes its shape within the sphere
(the shape changes even if we look at it in the coordinate system attached to the shifting
atom).
The derivative of such an operator is then
\begin{eqnarray}
\frac{\delta}{\delta a} V(a,x-a) =
\left(\frac{\partial V}{\partial  a}\right)_{x-a}
- \left(\frac{\partial V}{\partial  x}\right)_a
\label{Eq:381}
\end{eqnarray}
In the rest of the system (interstitals) and other MT-spheres -- in
which the basis does not change -- we replace all functions with their
smoothened equivalents, i.e., $V\rightarrow \tilde{V}(a,x)$. We
allowed $V$ to depend on the shift of $a$, as the charge distribution
changes, hence the Hartree potential will change as well (is a
solution of Poisson equation). Hence, the Hartree potential does
depend on $a$ also in the interstitials.  The local
exchange-correlation potential however does not change outside the
MT-sphere as the charge outside MT-sphere does not change, hence for
xc-potential $\delta\tilde{V}_{xc}/\delta a=0$.

The matrix element of such an operator can then be computed by
\begin{eqnarray}
\braket{f|V|g} = \int_{-\infty}^{a-S} \tilde{f}(x) \tilde{V} \tilde{g}(x) +
  \int_{a+S}^{\infty}\tilde{f}(x) \tilde{V}\tilde{g}(x) + \int_{a-S}^{a+S}  f(x) V(a,x-a) g(x)
\label{Eq:382}
\end{eqnarray}
which can also be simplified to
\begin{eqnarray}
\braket{f|V|g} = \int_{-\infty}^{a-S} \tilde{f}(x) \tilde{V} \tilde{g}(x) +
  \int_{a+S}^{\infty}\tilde{f}(x) \tilde{V}\tilde{g}(x) + \int_{a-S}^{a+S}
  e^{i (q-k)a} f_0(x-a) V(a,x-a) g_0(x-a)
\nonumber\\
= \int_{-\infty}^{a-S} \tilde{f}(x) \tilde{V} \tilde{g}(x) +
  \int_{a+S}^{\infty}\tilde{f}(x) \tilde{V}\tilde{g}(x)
+ e^{i (q-k)a} \int_{-S}^{S}  f_0(x) V(a,x) g_0(x)
\label{Eq:383}
\end{eqnarray}

If we move the interval for a bit $a\rightarrow a+\delta a$ we can
take the derivative of either Eq.~\ref{Eq:382} or Eq.~\ref{Eq:383} to
get two equivalent expressions for the same quantity.

Let's first take the derivative of Eq.~\ref{Eq:382}
\begin{eqnarray}
\frac{\delta}{\delta a}\braket{f|V|g} = (\tilde{f}V\tilde{g})(x=a-S) -  (\tilde{f} V\tilde{g})(x=a+S)
+(f V g)(x=a+S)-(f V g)(x=a-S) \\
+\int_{a-S}^{a+S}  (\frac{\delta f}{\delta a}) V g dx+
\int_{a-S}^{a+S}  f V (\frac{\delta g}{\delta a}) dx+
\int_{a-S}^{a+S} f (\frac{\delta V}{\delta a}) g dx
+\int_{-\infty}^{a-S} \tilde{f}(x) \frac{\delta\tilde{V}}{\delta a} \tilde{g}(x) + \int_{a+S}^{\infty}\tilde{f}(x) \frac{\delta\tilde{V}}{\delta a} \tilde{g}(x)
\end{eqnarray}
Here $(\frac{\delta V}{\delta a})$ contains both terms for the rigid
and non-rigid part from Eq.~\ref{Eq:381}. We can siplify this
expression to obtain
\begin{eqnarray}
\frac{\delta}{\delta a}\braket{f|V|g} =
\braket{\frac{\delta f}{\delta a}|V|g}_{MT}+
\braket{f|V|\frac{\delta g}{\delta a}}_{MT}+
(f V g - \tilde{f} V\tilde{g})(x=a+S)
-(f V g - \tilde{f} V\tilde{g})(x=a-S)
+\braket{f|\frac{\delta V}{\delta a}|g}
\end{eqnarray}
At the boundary $x=a\pm S$ the two forms of the potential are equal
$V(a,S)=\tilde{V}(a,a+S)$, hence we droped tilde sign.
Notice also that one term ($\braket{f|\frac{\delta V}{\delta a}|g}$)
extends over the entire space, while all others are integrated only
within MT-sphere.
This form of the differential is the Krakauer's way of differentiating matrix elements.

The alternative way is to differentiate Eq.~\ref{Eq:383}, to obtain
\begin{eqnarray}
\frac{\delta}{\delta a}\braket{f|V|g} = (\tilde{f} V \tilde{g})(x=a-S) -  (\tilde{f} V\tilde{g})(x=a+S) +
i(q-k) e^{i (q-k)a} \int_{-S}^{S}  f_0(x) V g_0(x)\\
+e^{i (q-k)a} \int_{-S}^{S}  f_0(x) \left(\frac{\partial V}{\partial a}\right)_{x-a} g_0(x)
+\int_{-\infty}^{a-S} \tilde{f}(x) \frac{\delta\tilde{V}}{\delta a} \tilde{g}(x) + \int_{a+S}^{\infty}\tilde{f}(x) \frac{\delta\tilde{V}}{\delta a} \tilde{g}(x)
\nonumber
\end{eqnarray}
which can also be written as
\begin{eqnarray}
\frac{\delta}{\delta a}\braket{f|V|g} = (\tilde{f} V \tilde{g})(x=a-S) -  (\tilde{f} V\tilde{g})(x=a+S) +
i(q-k) \braket{f|V|g}_{MT}
+\braket{f|\frac{\delta V}{\delta a}|g}
+\braket{f|\left(\frac{\partial V}{\partial x}\right)|g}_{MT}
\end{eqnarray}
or equivalently
\begin{eqnarray}
\frac{\delta}{\delta a}\braket{f|V|g} =
i(q-k) \braket{f|V|g}_{MT}
+\braket{f|\frac{\delta V}{\delta a}|g}
+\braket{f|\left(\frac{\partial V}{\partial x}\right)|g}_{MT}
-\int_{a-S}^{a+S} ( \frac{d\tilde{f}}{dx} V \tilde{g} +
  \tilde{f} \frac{d V}{dx} \tilde{g} +\tilde{f} V \frac{d\tilde{g}}{dx}  )
\end{eqnarray}

In 3D we can similarly derive two forms of differentiating the matrix
elements. The Krakauer's form is
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|V|\chi_{\vK}} =
\braket{\frac{\delta \chi_{\vK'}}{\delta \vR_\alpha} |V|\chi_{\vK}}_{MT}
+\braket{\chi_{\vK'}|V|\frac{\delta \chi_{\vK}}{\delta \vR_\alpha}}_{MT}
+\braket{\chi_{\vK'}|\frac{\delta  V}{\delta \vR_\alpha}|\chi_{\vK}}
+\oint_{MT} d\vec{S}( \chi^*_{\vK'} V \chi_{\vK} - \tilde{\chi}^*_{\vK'} V \tilde{\chi}_{\vK} )
\label{Eq:384}
\end{eqnarray}
where $\frac{\delta  V}{\delta \vR_\alpha}$ contains both ``rigid''
and ``non-rigid'' part of the derivative, and $\tilde{\chi}_\vK$ ($\chi_\vK$) are plane
wave functions (augmented basis functions), which are used in the
interstitials $r>S$ (in MT spheres $r<S$).
Notice that the kinetic energy part does not have terms like
$\frac{\delta  V}{\delta \vR_\alpha}$ because such derivative is
absent. We thus have
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|T|\chi_{\vK}} =
\braket{\frac{\delta \chi_{\vK'}}{\delta \vR_\alpha} |T|\chi_{\vK}}_{MT}
+\braket{\chi_{\vK'}|T|\frac{\delta \chi_{\vK}}{\delta \vR_\alpha} }_{MT}
+\oint_{MT} d\vec{S}( \chi^*_{\vK'} T \chi_{\vK} - \tilde{\chi}^*_{\vK'} T \tilde{\chi}_{\vK} )
\label{Eq:385}
\end{eqnarray}

The alternative form, which is used in Soler/Williams, is
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|V|\chi_{\vK}} =
i(\vK-\vK')\braket{\chi_{\vK'}|V|\chi_\vK}_{MT}
+ \braket{\chi_{\vK'}|\frac{\delta V}{\delta \vR_\alpha}|\chi_\vK}
+ \braket{\chi_{\vK'}|\nabla V|\chi_\vK}_{MT}
-\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* V  \tilde{\chi}_{\vK}
\label{Eq:386}
\end{eqnarray}
% The last two terms can also be simplified using the fact that
% \begin{eqnarray}
% \frac{\delta V}{\delta\vR_\alpha} = \left(\frac{\partial V}{\partial
%   \vR_\alpha}\right)_{\vr-\vR_\alpha} -\nabla V
% \end{eqnarray}
% and we get
% \begin{eqnarray}
% Eq.~\ref{Eq:386}=
% i(\vK-\vK')\braket{\chi_{\vK'}|V|\chi_\vK}_{MT}
% +\braket{\chi_{\vK'}|\frac{\delta V}{\delta\vR_\alpha}|\chi_\vK}
% +\braket{ \chi_{\vK'}|\nabla V|\chi_\vK}_{MT}
% \nonumber\\
% -\braket{\nabla\tilde{\chi}_{\vK'}|V|\tilde{\chi}_\vK}_{MT}
% -\braket{\tilde{\chi}_{\vK'}|V|\nabla \tilde{\chi}_\vK}_{MT}
% -\braket{\tilde{\chi}_{\vK'}|\nabla V|\tilde{\chi}_\vK}_{MT}
% \nonumber
% \end{eqnarray}
This can also be simplified to get
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|V|\chi_{\vK}} =
i(\vK-\vK')
\left[
\braket{\chi_{\vK'}|V|\chi_\vK}_{MT}
-\braket{\tilde{\chi}_{\vK'}|V|\tilde{\chi}_\vK}_{MT}
\right]
+\braket{\chi_{\vK'}|\frac{\delta V}{\delta\vR_\alpha}|\chi_\vK}
\nonumber\\
+\braket{ \chi_{\vK'}|\nabla V|\chi_\vK}_{MT}
-\braket{\tilde{\chi}_{\vK'}|\nabla V|\tilde{\chi}_\vK}_{MT}
\label{Eq:388}
\end{eqnarray}

For the kinetic energy there is no change of operator associated with
the shift, hence $\frac{\delta T}{\delta\vR_\alpha}=0$ and
$\nabla T=0 $.
We thus have
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|T|\chi_{\vK}} =
i(\vK-\vK')\braket{\chi_{\vK'}|T|\chi_\vK}_{MT}
-\oint_{\vr=R_{MT}^-} d\vec{S} \tilde{\chi}_{\vK'}^* T  \tilde{\chi}_{\vK}
\nonumber\\
=i(\vK-\vK')
\left[\braket{\chi_{\vK'}|T|\chi_\vK}_{MT}
-\braket{\tilde{\chi}_{\vK'}|T|\tilde{\chi}_\vK}_{MT}
\right]
\label{Eq:389}
\end{eqnarray}

\subsection{Discontinuous functions}
\label{discontinuity}

Let's start with discontinuity in 1D. If $H(x)$ is continuous
function in the interval $[-\infty,\infty]$, and we move the entire
function  for a small amount $a$, we expect no change in the
following integral
\begin{eqnarray}
0=\int dx[H(x-a)-H(x)] = -a\int \frac{dH}{dx}dx = -a [H(\infty)-H(-\infty)]
\end{eqnarray}
If the function is continuous and goes to zero at large distances,
this clearly works. But lets now take a function $H(x)$, which has a
single jump at $x_0$ so that $H(x_0^-) \ne H(x_0^+)$. We then need to
add the following term
\begin{eqnarray}
\int dx[H(x-a)-H(x)] = -a\int \frac{dH}{dx}dx +a (H[x_0^-]-H[x_0^+])
\end{eqnarray}
and by rearranging we have
\begin{eqnarray}
\int dx H(x-a) = \int dx H(x)  -a\int \frac{dH}{dx}dx +a (H[x_0^-]-H[x_0^+])
\end{eqnarray}
In higher $D$ we have similar equation. Let's move a sphere for a
small amount $\vec{a}$. We get
\begin{eqnarray}
\int d^3r H(\vec{r}-\vec{a}) = \int d^3r H(\vec{r})
-\vec{a}\int d^3r  \nabla_\vr H(\vr)  +\vec{a} \oint d\vec{S} (H[r_0^-]-H[r_0^+])
\end{eqnarray}

In summary, if we have a function $H(\vr)$ and we move the sphere for
vector $\vec{a}$, its change is ${\delta
  H}/{\delta\vec{a}}=-\nabla_\vr H(\vr)$. If there is discountinuity, we have
\begin{eqnarray}
\frac{\delta}{\delta\vec{a}} \int d^3r H(\vec{r}) =
\vec{a}\int d^3r \frac{ \delta H}{\delta\vec{a}}  +
\vec{a}\oint d\vec{S} (H[r_0^-]-H[r_0^+])
\end{eqnarray}

% \begin{eqnarray}
% && \frac{\delta}{\delta\Delta} \int_{a+\Delta}^{b+\Delta} f_\Delta(x) g_\Delta(x) dx =
% \frac{\delta}{\delta\Delta} \int_{a+\Delta}^{b+\Delta}  e^{i(k_g-k_f)(a+\Delta)}f_0(x-a-\Delta) g_0(x-a-\Delta) dx \\
% && =
% \frac{\delta}{\delta\Delta} \int_{a}^{b}  e^{i(k_g-k_f)(a+\Delta)}f_0(x-a) g_0(x-a) dx
% =i(k_g-k_f)  \int_{a}^{b}  e^{i(k_g-k_f)a}f_0(x-a) g_0(x-a) dx
% \end{eqnarray}
% Hence, we got only the phase factors, but not the derivative of $f_0$
% and $g_0$.
% We could derive the same result by taking the derivative in this way
% \begin{eqnarray}
% && \frac{\delta}{\delta\Delta} \int_{a+\Delta}^{b+\Delta}  e^{i(k_g-k_f)(a+\Delta)}f_0(x-a-\Delta) g_0(x-a-\Delta) dx \\
% && =
% i(k_g-k_f)  \int_{a}^{b}  e^{i(k_g-k_f)a}f_0(x-a) g_0(x-a) dx \\
% && -\int_{a}^{b}  e^{i(k_g-k_f)a} \frac{d}{dx}  (f_0(x-a) g_0(x-a)) dx \\
% && +e^{i(k_g-k_f)a} [(f_0(x-a) g_0(x-a))]_{a}^b
% \end{eqnarray}
% The last two terms clearly cancel and we get the above derived
% result.
%
% Physically, the function $f(x)$ does change according to
% $f\rightarrow e^{i k_f (a+\Delta)}f_0(x-a-\Delta)\approx [i k_f e^{i
%   k_f a}f_0(x-a) - e^{i k_f a} \frac{d f_0(x-a)}{dx}]\Delta +\cdots $,
% however, the integration interval also moves, hence the upper and
% lower limit of the interval also changes, canceling the $d/dx$ term.
%
% The same consideration is valid also in 3D, hence I think
% $\nabla\chi_{\vK}(\vr)$ terms should not be added. If we indeed neglect
% such terms, we arrive at DFT forces:
% %
% \begin{eqnarray}
% \vF^{Pulley}_\alpha =
% -i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
% (\vK-\vK')\braket{ \chi_{\vK'}  |-\nabla^2+V^{sym}_{KS}(r)-\varepsilon_i|\chi_{\vK}}_{MT}A_{i,\vK}-
% \label{Eq:68}\\
% -i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^*
% (\vK-\vK')\braket{ \chi_{\vK'}  |V_{KS}^{n-sym}(\vr)|\chi_{\vK}}_{MT}A_{i,\vK}-
% \label{Eq:69}
% \\
% -i\sum_i f_i \sum_{\vK,\vK'} A_{i,\vK'}^* A_{i,\vK}
% (\vK-\vK') \oint_{r=R_{MT}^-} d\vec{S} \chi_{\vK'+\vk}^*(\vr)  \nabla_\vr\chi_{\vK+\vk}(\vr)
% \label{Eq:70}
% \\
% +\sum_i f_i \sum_{\vK,\vG} A_{i,\vK-\vG}^*A_{i,\vK}  [(\vK+\vk)(\vK-\vG+\vk)] R_{MT}^2 \int d\Omega \frac{e^{i\vG\vr}}{V_{cell}}
% \label{Eq:71}\\
% -\sum_i f_i \sum_{\vK',\vK} A_{i,\vK'}^*A_{i,\vK}  \oint_{R_{MT}^-} d\vec{S} \nabla\chi^*_{\vK'}(\vr)\cdot\nabla\chi_\vK(\vr)
% \label{Eq:72}
% \end{eqnarray}
% Here Eq.~\ref{Eq:68}, \ref{Eq:69}, and~\ref{Eq:70} are equal to
% ~\ref{eq:Pule1}, \ref{eq:Pule2}, and \ref{eq:Pule3}, respectively.
% Moreover Eq.~\ref{Eq:71} is slightly modified ~\ref{eq:Pule4}.
% The only new equation is ~\ref{Eq:72}, which we simplify below.
%

\subsection{Another formula}

\begin{eqnarray}
\oint_{R_{MT}^-} d\vec{S}  \nabla\chi^*_{\vK'}(\vr)\cdot\nabla\chi_\vK(\vr)=
a_{l'm'}^{\vK',\kappa'\;*} a_{lm}^{\vK,\kappa} \int d\Omega  \vec{e}_r \;
(r\nabla)\left(\frac{u_{l'}^{\kappa'}}{r}Y_{l'm'}^*\right)\cdot
(r\nabla)\left(\frac{u_{l}^{\kappa}}{r}Y_{lm}\right)
\label{Eq:362}
\end{eqnarray}
We know that
$$(r\nabla) \left(\frac{u}{r}Y_{lm}\right)=\vec{e}_r r\frac{d}{dr}\left(\frac{u}{r}\right)+\frac{u}{r}(r\nabla)Y_{lm}$$
hence
\begin{eqnarray}
Eq.~\ref{Eq:362}=
a_{l'm'}^{\vK',\kappa'\;*} a_{lm}^{\vK,\kappa}
\left[
r^2
\frac{d}{dr} \left(\frac{u_{l'}^{\kappa'}}{r}\right)
\frac{d}{dr} \left(\frac{u_{l}^{\kappa}}{r}\right)
\oint Y_{l'm'}^* \vec{e_r} Y_{lm}d\Omega
+
\left(\frac{u_{l'}^{\kappa'}}{r}\right)
\left(\frac{u_{l}^{\kappa}}{r}\right)
\int (r\nabla)Y^*_{l'm'}(\hat{\vr})\cdot (r\nabla)Y_{lm}(\hat{\vr})\; \vec{e}_r d\Omega
\right]
\nonumber
\end{eqnarray}
We know that
$$\int (r\nabla)Y^*_{l'm'}(\hat{\vr})\; (r\nabla)Y_{lm}(\hat{\vr})\; d\Omega =l(l+1)\delta_{ll'}\delta_{mm'}.$$

To derive
\begin{eqnarray}
I^3_{l'm'lm}=\int ((r\nabla)Y^*_{l'm'}(\hat{\vr}))\cdot  ((r\nabla)Y_{lm}(\hat{\vr})) \vec{e}_r\; d\Omega
\end{eqnarray}
we use the standard procedure discussed above to obtain
%
\begin{eqnarray}
I^3_{l'm'lm}=\frac{l(l+2)}{2}\;
\left[
a(l,m)
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l,-m)
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
+2 f(l,m)
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l+1}
\nonumber\\
-\frac{(l-1)(l+1)}{2}
\left[
a(l',-m')
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l',m')
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
-2 f(l',m')
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l-1}
\end{eqnarray}
which can also be written as
\begin{eqnarray}
I^3_{l'm'lm}=\frac{l(l+2)}{2}\;\delta_{l'=l+1}
\left(
\begin{array}{c}
a(l,m) \delta_{m'=m+1}- a(l,-m)\delta_{m'=m-1}\\
-i[a(l,m)\delta_{m'=m+1}+a(l,-m)\delta_{m'=m-1} ]\\
2 f(l,m)\delta_{m'=m}
\end{array}
\right)
\nonumber\\
-\frac{(l-1)(l+1)}{2}
\delta_{l'=l-1}
\left(
\begin{array}{c}
a(l',-m')\delta_{m'=m+1}-a(l',m')\delta_{m'=m-1}\\
-i[a(l',-m')\delta_{m'=m+1}+a(l',m')\delta_{m'=m-1}]\\
-2 f(l',m')\delta_{m'=m}
\end{array}
\right)
\end{eqnarray}

\subsection{Matrix elements of the Spheric harmonics}
\label{OnRealHarm}

We are interested in the following integrals:
\begin{eqnarray}
I^1_{l'm'lm} &\equiv& \int d\Omega Y^*_{l'm'}(\hat{\vr}) \vec{e}_\vr  Y_{lm}(\hat{\vr}) \\
I^2_{l'm'lm} &\equiv& \int d\Omega Y^*_{l'm'}(\hat{\vr}) (r\nabla Y_{lm}(\hat{\vr})) \\
I^3_{l'm'lm} &\equiv& \int d\Omega (r\nabla Y^*_{l'm'}(\hat{\vr}))\cdot ( r\nabla  Y_{lm}(\hat{\vr})) \vec{e}_\vr\\
\end{eqnarray}
These integrals, computed above, take the form
\begin{eqnarray}
I^1_{l'm'lm}=
\frac{1}{2}
\left[
a(l,m)
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l,-m)
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
+2 f(l,m)
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l+1}
\nonumber\\
-\frac{1}{2}
\left[
a(l',-m')
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l',m')
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
-2 f(l',m')
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l-1}
\end{eqnarray}

\begin{eqnarray}
I^2_{l'm'lm}=-\frac{l}{2}\;
\left[
a(l,m)
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l,-m)
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
+2 f(l,m)
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l+1}
\nonumber\\
-\frac{l+1}{2}
\left[
a(l',-m')
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l',m')
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
-2 f(l',m')
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l-1}
\end{eqnarray}
\begin{eqnarray}
I^3_{l'm'lm}=\frac{l(l+2)}{2}\;
\left[
a(l,m)
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l,-m)
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
+2 f(l,m)
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l+1}
\nonumber\\
-\frac{(l-1)(l+1)}{2}
\left[
a(l',-m')
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l',m')
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
-2 f(l',m')
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l-1}
\end{eqnarray}

We can write all three integrals in a common form, namely,
\begin{eqnarray}
I^n_{l'm'lm}=c_{n,l}
\left[
a(l,m)
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l,-m)
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
+2 f(l,m)
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l+1}
\nonumber\\
-d_{n,l}
\left[
a(l',-m')
\left(
\begin{array}{c}
1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m+1}
+a(l',m')
\left(
\begin{array}{c}
-1\\
-i\\
0
\end{array}
\right)
\delta_{m'=m-1}
-2 f(l',m')
\left(
\begin{array}{c}
0\\
0\\
1
\end{array}
\right)
\delta_{m'=m}
\right]\delta_{l'=l-1}
\end{eqnarray}
where
\begin{eqnarray}
& c_{1,l} = \frac{1}{2}      & d_{1,l}=\frac{1}{2}\\
& c_{2,l}=-\frac{l}{2}       & d_{2,l}=\frac{l+1}{2}\\
& c_{3,l}=\frac{l(l+2)}{2} & d_{3,l}=\frac{(l-1)(l+1)}{2}
\end{eqnarray}

Next we want to derive the integrals in real spheric harmonics
$y_{lm\pm}$ which are related to complex spheric harmonics by
\begin{eqnarray}
&Y_{lm}&=(-1)^m \sqrt{\frac{1+\delta_{m,0}}{2}}(y_{lm+}+i y_{lm-})\\
&Y_{l,-m}&=\sqrt{\frac{1+\delta_{m,0}}{2}}(y_{lm+}-i y_{lm-})
\end{eqnarray}
Here we want to find the connection between
$\braket{ Y^*_{l'm'}|T|Y_{lm}}$ and $\braket{y_{l'm's'}|T|y_{lms}}$.
We will derive the connection for the case of $T$ being a real operator.
We have
\begin{eqnarray}
&&\braket{ y_{l'm'+}|T|y_{lm+}} + \braket{ y_{l'm'-}|T|y_{lm-}} = \Re\left(\braket{ y_{l'm'+}-i y_{l'm'-}|T|y_{lm+}+ i y_{lm-}} \right)
=\frac{(-1)^{m+m'} }{\sqrt{\cD}} 2\Re\left(\braket{Y_{l'm'}^*|T|Y_{lm}}\right)\nonumber\\
&& \braket{ y_{l'm'+}|T|y_{lm+}} - \braket{ y_{l'm'-}|T|y_{lm-}} = \Re\left(\braket{ y_{l'm'+}+i y_{l'm'-}|T|y_{lm+}+ i y_{lm-}} \right)
= \frac{(-1)^{m}}{\sqrt{\cD}} 2 \Re\left(\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)\nonumber\\
&& \braket{ y_{l'm'+}|T|y_{lm-}} - \braket{ y_{l'm'-}|T|y_{lm+}} = \Im\left(\braket{ y_{l'm'+}-i y_{l'm'-}|T|y_{lm+}+ i y_{lm-}} \right)
= \frac{(-1)^{m+m'}}{\sqrt{\cD}} 2 \Im\left(\braket{Y_{l'm'}^*|T|Y_{lm}}\right)\nonumber\\
&& \braket{ y_{l'm'+}|T|y_{lm-}} + \braket{ y_{l'm'-}|T|y_{lm+}} = \Im\left(\braket{ y_{l'm'+}+i y_{l'm'-}|T|y_{lm+}+ i y_{lm-}} \right)
= \frac{(-1)^{m}}{\sqrt{\cD}} 2 \Im\left(\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)\nonumber
\end{eqnarray}
where $\cD=(1+\delta_{m=0})(1+\delta_{m'=0})$.
We then have
\begin{eqnarray}
\braket{ y_{l'm'+}|T|y_{lm+}}&=& \frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m,0})(1+\delta_{m',0})}} \Re\left(\braket{Y_{l'm'}^*|T|Y_{lm}}+(-1)^{m'}\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)\\
\braket{ y_{l'm'-}|T|y_{lm-}}&=& \frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m,0})(1+\delta_{m',0})}} \Re\left(\braket{Y_{l'm'}^*|T|Y_{lm}}-(-1)^{m'}\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)\\
\braket{ y_{l'm'+}|T|y_{lm-}}&=& \frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m,0})(1+\delta_{m',0})}}  \Im\left(\braket{Y_{l'm'}^*|T|Y_{lm}}+(-1)^{m'}\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)\\
-\braket{ y_{l'm'-}|T|y_{lm+}}&=& \frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m,0})(1+\delta_{m',0})}} \Im\left(\braket{Y_{l'm'}^*|T|Y_{lm}}-(-1)^{m'}\braket{Y_{l'-m'}^*|T|Y_{lm}}\right)
\end{eqnarray}

To proceed, we
first turn the above complex harmonics integrals into slightly different form:
\begin{eqnarray}
\braket{Y_{l'm'}|T|Y_{lm}}=c_{n,l}\;\delta_{l'=l+1}
\left(
\begin{array}{c}
a(l,m) \delta_{m'=m+1}- a(l,-m)\delta_{m'=m-1}\\
-i[a(l,m)\delta_{m'=m+1}+a(l,-m)\delta_{m'=m-1} ]\\
2 f(l,m)\delta_{m'=m}
\end{array}
\right)
\nonumber\\
-d_{n,l}\;\delta_{l'=l-1}
\left(
\begin{array}{c}
a(l',-m')\delta_{m'=m+1}-a(l',m')\delta_{m'=m-1}\\
-i[a(l',-m')\delta_{m'=m+1}+a(l',m')\delta_{m'=m-1}]\\
-2 f(l',m')\delta_{m'=m}
\end{array}
\right)
\end{eqnarray}
For real spheric harmonics, we also need
$\braket{Y_{l'-m'}|T|Y_{lm}}$. But we are interested only in the case
when both $m>=0$ and $m'>=0$:
\begin{eqnarray}
\braket{Y_{l'-m'}|T|Y_{lm}}=c_{n,l}\;\delta_{l'=l+1}
\left(
\begin{array}{c}
-a(l,-m)\delta_{m'=-m+1}(\delta_{m=0}+\delta_{m=1})\\
-i a(l,-m)\delta_{m'=-m+1}(\delta_{m=0}+\delta_{m=1}) \\
2 f(l,m)\delta_{m'=-m}\delta_{m=0}
\end{array}
\right)
\nonumber\\
-d_{n,l}\;
\delta_{l'=l-1}
\left(
\begin{array}{c}
-a(l',-m')\delta_{m'=-m+1}(\delta_{m=0}+\delta_{m=1}))\\
-i a(l',-m')\delta_{m'=-m+1}(\delta_{m=0}+\delta_{m=1})\\
-2 f(l',-m')\delta_{m'=-m}\delta_{m=0}
\end{array}
\right)
\end{eqnarray}
If the two equations are put together, we obtain (for $m>=0$ and $m'>=0$):
\begin{eqnarray}
\braket{Y_{l' m'}|T|Y_{lm}}\pm (-1)^{m'}\braket{Y_{l' -m'}|T|Y_{lm}}=
c_{n,l}\;\delta_{l'=l+1}
\left(
\begin{array}{c}
a(l,m) \delta_{m'=m+1}(1\pm\delta_{m=0})-  a(l,-m)\delta_{m'=m-1}(1\pm\delta_{m=1}) \\
-i[  a(l,m)\delta_{m'=m+1}(1\mp\delta_{m=0})+a(l,-m)\delta_{m'=m-1}(1\pm\delta_{m=1})]  \\
2 f(l,m)\delta_{m'=m} (1\pm\delta_{m=0})
\end{array}
\right)
%
\nonumber\\
%
-d_{n,l}\;
\delta_{l'=l-1}
\left(
\begin{array}{c}
a(l',-m')\delta_{m'=m+1}(1\pm\delta_{m=0})-a(l',m')\delta_{m'=m-1}(1\pm\delta_{m=1})\\
-i[a(l',-m')\delta_{m'=m+1}(1\mp\delta_{m=0})+a(l',m')\delta_{m'=m-1}(1\pm\delta_{m=1})] \\
-2 f(l',m')\delta_{m'=m}(1\pm\delta_{m=0})
\end{array}
\right)
\nonumber
\end{eqnarray}
hence we have
\begin{eqnarray}
\braket{y_{l'm'\pm}|T|y_{lm\pm}}  =\frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m=0})(1+\delta_{m'=0})}}
\Re\left(\braket{Y_{l' m'}|T|Y_{lm}}\pm (-1)^{m'}\braket{Y_{l' -m'}|T|Y_{lm}}\right)=\nonumber\\
\frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m=0})(1+\delta_{m'=0})}}
\left\{
c_{n,l}\;\delta_{l'=l+1}
\left(
\begin{array}{c}
a(l,m) \delta_{m'=m+1}(1\pm\delta_{m=0})-  a(l,-m)\delta_{m'=m-1}(1\pm\delta_{m=1}) \\
0\\
2 f(l,m)\delta_{m'=m} (1\pm\delta_{m=0})
\end{array}
\right)
%
\right.
\nonumber\\
\left.
%
-d_{n,l}\;\delta_{l'=l-1}
\left(
\begin{array}{c}
a(l',-m')\delta_{m'=m+1}(1\pm\delta_{m=0})-a(l',m')\delta_{m'=m-1}(1\pm\delta_{m=1})\\
0\\
-2 f(l',m')\delta_{m'=m}(1\pm\delta_{m=0})
\end{array}
\right)
\right\}
\end{eqnarray}
and
\begin{eqnarray}
\braket{y_{l'm'\pm}|T|y_{lm\mp}}  =\pm\frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m=0})(1+\delta_{m'=0})}}
\Im\left(\braket{Y_{l' m'}|T|Y_{lm}}\pm (-1)^{m'}\braket{Y_{l' -m'}|T|Y_{lm}}\right)=\nonumber\\
\pm\frac{(-1)^{m+m'}}{\sqrt{(1+\delta_{m=0})(1+\delta_{m'=0})}}
\left\{
c_{n,l}\;\delta_{l'=l+1}
\left(
\begin{array}{c}
0\\
-[  a(l,m)\delta_{m'=m+1}(1\mp\delta_{m=0})+a(l,-m)\delta_{m'=m-1}(1\pm\delta_{m=1})]  \\
0
\end{array}
\right)
\right.
%
\nonumber\\
%
\left.
-d_{n,l}
\delta_{l'=l-1}
\left(
\begin{array}{c}
0\\
-[a(l',-m')\delta_{m'=m+1}(1\mp\delta_{m=0})+a(l',m')\delta_{m'=m-1}(1\pm\delta_{m=1})] \\
0
\end{array}
\right)
\right\}
\end{eqnarray}

These equations can be simplified, which gives the final result:
\begin{eqnarray}
\braket{y_{l'm'\pm}|T|y_{lm\pm}}  =
c_{n,l}\;\delta_{l'=l+1}
\left(
\begin{array}{c}
-a(l,m)\delta_{m'=m+1}\frac{(1\pm\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}
+a(l,-m)\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}} \\
0\\
2 f(l,m)\delta_{m'=m} \frac{(1\pm\delta_{m=0})}{1+\delta_{m=0}}
\end{array}
\right)
%
\nonumber\\
\left.
%
-d_{n,l}\;\delta_{l'=l-1}
\left(
\begin{array}{c}
-a(l',-m')\delta_{m'=m+1}\frac{(1\pm\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}+a(l',m')\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}}\\
0\\
-2 f(l',m')\delta_{m'=m}\frac{(1\pm\delta_{m=0})}{1+\delta_{m=0}}
\end{array}
\right)
\right\}
\end{eqnarray}
and
\begin{eqnarray}
\braket{y_{l'm'\pm}|T|y_{lm\mp}}  =
\pm\left(
\begin{array}{c}
0\\
1\\
0
\end{array}
\right)
\left\{
c_{n,l}\;\delta_{l'=l+1}
\left(
  a(l,m)\delta_{m'=m+1}\frac{(1\mp\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}+a(l,-m)\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}}
\right)
\right.
%
\nonumber\\
%
\left.
-d_{n,l}\;\delta_{l'=l-1}
\left(
a(l',-m')\delta_{m'=m+1}\frac{(1\mp\delta_{m=0})}{\sqrt{1+\delta_{m=0}}}+a(l',m')\delta_{m'=m-1}\frac{(1\pm\delta_{m'=0})}{\sqrt{1+\delta_{m'=0}}}
\right)
\right\}
\end{eqnarray}

\subsection{Debugging}

We can compute exact force in a very particular situation, in which we
rigidly move Kohn-Sham potential with the sphere of the moving
atom. In this case the change of matrix elements of the potential are
really simple
The alternative form, which is used in Soler/Williams, is
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|V|\chi_{\vK}} =
i(\vK-\vK')\braket{\chi_{\vK'}|V|\chi_\vK}_{MT}
-\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* V  \tilde{\chi}_{\vK}
\end{eqnarray}
This is because the MT-part is not changing except for the phase
factor in front $e^{i(\vk+\vK)\vR_\alpha}$, while the interstitial
part has a surface term because there is slightly more interstitial
volume behind the sphere and less infront.

The equation can also be memorized as a special case in which
$$\frac{\delta V}{\delta \vR_\alpha} = -\nabla V.$$

Note that in Wien2K the convolution of $V^{KS}_{\vG}$ and the plane
wave with the MT-hole's is computed in lapw0 step. Hence, when the
potential is kept constant, we actually fix also
$\braket{\tilde{\chi}_{\vK}|\tilde{V}^{KS}|\tilde{\chi}_{\vK'}}_{interstitials}$ (the
Kohn-Sham potential in interestitials), hence the last term of above
equation is absent.

For the kinetic part, similar equation holds
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|T|\chi_{\vK}} =
i(\vK-\vK')\braket{\chi_{\vK'}|T|\chi_\vK}_{MT}
-\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* T  \tilde{\chi}_{\vK}
\end{eqnarray}
hence we have
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|H^0|\chi_{\vK}} =
i(\vK-\vK')\braket{\chi_{\vK'}|H^0|\chi_\vK}_{MT}
-\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* H^0  \tilde{\chi}_{\vK}
\end{eqnarray}

But if we fix potential in lapw0, we actually just need
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|H^0|\chi_{\vK}} =
i(\vK-\vK')\braket{\chi_{\vK'}|H^0|\chi_\vK}_{MT}
-\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* T  \tilde{\chi}_{\vK}
\end{eqnarray}

For the overlap, the equation
\begin{eqnarray}
\frac{\delta}{\delta \vR_\alpha} \braket{\chi_{\vK'}|\chi_{\vK}} =
i(\vK-\vK')\braket{\chi_{\vK'}|\chi_\vK}_{MT}
-\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* \tilde{\chi}_{\vK}
\end{eqnarray}
is exact.

We want to simulate the following equations
\begin{eqnarray}
(A^{0\dagger}\frac{\delta O}{\delta \vR_\alpha}  A^0)_{ij}&=&
\sum_{\vK\vK'}A^{0\dagger}_{i\vK'}i(\vK-\vK')\braket{\chi_{\vK'}|\chi_\vK}_{MT} A^0_{\vK j}
-A^{0\dagger}_{i\vK'}\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* \tilde{\chi}_{\vK}A^0_{\vK j}\\
 (A^{0\dagger}\frac{\delta H^0}{\delta \vR_\alpha}  A^0)_{ij}&=&
\sum_{vK\vK'}A^{0\dagger}_{i\vK'}i(\vK-\vK')\braket{\chi_{\vK'}|H^0|\chi_\vK}_{MT}  A^0_{\vK j}
-A^{0\dagger}_{i\vK'}\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* T  \tilde{\chi}_{\vK}A^0_{\vK j}
\end{eqnarray}
and check it with simulating a finite difference. The latter is
obtained by computing $H^0$ and $O$ for unperturbed system, we then
move an atom and recompute $H^0$ and $O$, and then take numerically
finite difference and compare with analytically obtained derivative.

For the overlap, we need the following two terms:
The first term is
% \begin{eqnarray}
% (A^{0\dagger} O_{MT} A^0)_{ij}&\equiv& \sum_{\vK\vK'} A^\dagger_{i\vK'} i(\vK-\vK')\braket{\chi_{\vK'}|\chi_\vK}_{MT}A_{\vK j}=
% \nonumber\\
% &&-2\Im\left\{ \left(a_{i,lm}^*  + c^*_{i,lm} \braket{u_{LO}|u}\right)\vcA_{j,lm}\right\} +
% \nonumber\\
% &&-2\Im\left\{ \left( b_{i,lm}^* \braket{\dot{u}_l|\dot{u}_l} +c^*_{i,lm}  \braket{u_{LO}|\dot{u}_l} \right) \vcB_{j,lm}\right\} +
% \nonumber\\
% &&-2\Im\left\{\left(a^*_{i,lm}\braket{u|u_{LO}} + b^*_{i,lm} \braket{\dot{u}_l|u_{LO}}  +c^*_{i,lm} \braket{u_{LO}|u_{LO}} \right)\vcC_{j,lm}\right\}
% \nonumber
% \end{eqnarray}
%
\begin{eqnarray}
(A^{0\dagger} O_{MT} A^0)_{ij} &\equiv& \sum_{\vK\vK'} A^\dagger_{i\vK'} i(\vK-\vK')\braket{\chi_{\vK'}|\chi_\vK}_{MT}A_{\vK j}=
\\
&=&
\sum_{\vK\vK'} A^\dagger_{i\vK'} i(\vK-\vK')
\left(
\begin{array}{ccc}
a_{lm\vK'}^*, & b_{lm\vK'}^* & c^*_{lm\vK'}
\end{array}
\right)
\left(
\begin{array}{ccc}
{\braket{u_l|u_l}} & {\braket{u_l|\dot{u}_l}} & {\braket{u_l|u^{LO}_l}} \\
{\braket{\dot{u}_l|u_l}} & {\braket{\dot{u}_l|\dot{u}_l}} & {\braket{\dot{u}_l|u^{LO}_l}} \\
{\braket{u^{LO}_l|u_l}} & {\braket{u^{LO}_l|\dot{u}_l}} & {\braket{u^{LO}_l|u^{LO}_l}}
\end{array}
\right)
\left(
\begin{array}{c}
a_{lm\vK}\\
b_{lm\vK}\\
c_{lm\vK}
\end{array}
\right) A_{\vK j}
\nonumber\\
&=&
i\left(
\begin{array}{ccc}
a_{i,lm}^*, & b_{i,lm}^* & c^*_{i,lm}
\end{array}
\right)
\left(
\begin{array}{ccc}
1 & 0 & \braket{u_l|u^{LO}_l} \\
0 & \braket{\dot{u}_l|\dot{u}_l} & \braket{\dot{u}_l|u^{LO}_l} \\
\braket{u_l|u^{LO}_l} & \braket{\dot{u}_l|u^{LO}_l} & 1
\end{array}
\right)
\left(
\begin{array}{c}
\vcA_{j,lm}\\
\vcB_{j,lm}\\
\vcC_{j,lm}
\end{array}
\right)
\\
&& -i
\left(
\begin{array}{ccc}
\vcA^*_{i,lm}, & \vcB^*_{i,lm} & \vcC^*_{i,lm}
\end{array}
\right)
\left(
\begin{array}{ccc}
1 & 0 & \braket{u_l|u^{LO}_l} \\
0 & \braket{\dot{u}_l|\dot{u}_l} & \braket{\dot{u}_l|u^{LO}_l} \\
\braket{u_l|u^{LO}_l} & \braket{\dot{u}_l|u^{LO}_l} & 1
\end{array}
\right)
\left(
\begin{array}{c}
a_{j,lm}\\
b_{j,lm}\\
c_{j,lm}
\end{array}
\right)
\nonumber
\end{eqnarray}
which is equal to
\begin{eqnarray}
(A^{0\dagger} O_{MT} A^0) = i (\cO-\cO^\dagger)
\end{eqnarray}
where
\begin{eqnarray}
\cO_{ij} \equiv \left(
\begin{array}{ccc}
a_{i,lm}^*, & b_{i,lm}^* & c^*_{i,lm}
\end{array}
\right)
\left(
\begin{array}{ccc}
1 & 0 & \braket{u_l|u^{LO}_l} \\
0 & \braket{\dot{u}_l|\dot{u}_l} & \braket{\dot{u}_l|u^{LO}_l} \\
\braket{u_l|u^{LO}_l} & \braket{\dot{u}_l|u^{LO}_l} & 1
\end{array}
\right)
\left(
\begin{array}{c}
\vcA_{j,lm}\\
\vcB_{j,lm}\\
\vcC_{j,lm}
\end{array}
\right)
\end{eqnarray}

The second term is
\begin{eqnarray}
(A^{0\dagger} O_S A^0)_{ii} \equiv \sum_{\vK\vK'}A^{0\dagger}_{i\vK'}\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* \tilde{\chi}_{\vK}A^0_{\vK i}=
\sum_{\vK\vK'}A^{0*}_{\vK' i} A^0_{\vK i}\oint  d\vec{S}\frac{e^{i(\vK-\vK')\vr}}{V}=
\sum_{\vK\vG}A^{0*}_{\vK-\vG, i} A^0_{\vK  i}
\frac{R_{MT}^2}{V} e^{i\vG\vR_\alpha}\int d\Omega\vec{e}_\vr  {e^{i\vG\vr}}
\nonumber
\end{eqnarray}
The final result is clearly
\begin{eqnarray}
(A^{0\dagger}\frac{\delta O}{\delta \vR_\alpha}  A^0)_{ii}=(A^{0\dagger} O_{MT} A^0)_{ii}-(A^{0\dagger} O_S A^0)_{ii}
\end{eqnarray}

We need the following quantity
\begin{eqnarray}
D_\vG\equiv \sum_{\vK}A^{0*}_{\vK-\vG, i}A^0_{\vK  i}
\end{eqnarray}
which is computed by FFT. We first compute
\begin{eqnarray}
Y_i(\vr_l)= \sum_\vK A^0_{\vK  i} e^{-i\vK\vr_l}
\end{eqnarray}
and then obtain
\begin{eqnarray}
D_\vG = \frac{1}{N_l}\sum_{\vr_l} Y^*_i(\vr_l) Y_i(\vr_l) e^{i\vK\vr_l}
\end{eqnarray}
We hence have
\begin{eqnarray}
(A^{0\dagger} O_S A^0)_{ii} =
\sum_{\vG} D_\vG
\frac{R_{MT}^2}{V} e^{i\vG\vR_\alpha}\int d\Omega\vec{e}_\vr  {e^{i\vG\vr}}
\end{eqnarray}
and because
\begin{equation}
\int d\Omega e^{i\vG\vr} \vec{e}_\vr={4\pi i } \frac{\vG}{|\vG|}\;j_1(|\vG|R_{MT})
\end{equation}
we obtain
\begin{eqnarray}
(A^{0\dagger} O_S A^0)_{ii} =
\frac{4\pi R_{MT}^2}{V}
\sum_{\vG} D_\vG\;
i e^{i\vG\vR_\alpha}\frac{\vG}{|\vG|}\;j_1(|\vG|R_{MT})
\end{eqnarray}

For the Hamiltonian, we need many more terms. We write
\begin{eqnarray}
(A^{0\dagger}\frac{\delta H^0}{\delta \vR_\alpha}  A^0)_{ij}=
(A^{0\dagger}H_{MT}^{sym}A^0)_{ij} +
(A^{0\dagger}H_{MT}^{nsym}A^0)_{ij} +
(A^{0\dagger}dT_{MT}A^0)_{ij} -
(A^{0\dagger} T_{S}A^0)_{ij} -
(A^{0\dagger} V_{S}A^0)_{ij}
\end{eqnarray}
Note that the last term is absent when potential is held fixed in lapw0.

We start with the spherically-symmetric part in the MT-sphere:
%\begin{eqnarray}
%(A^{0\dagger} H_{MT}^{sym} A^0)_{ij} &\equiv& \sum_{\vK\vK'} A^\dagger_{i \vK'}i(\vK-\vK')  \braket{\chi_{\vK'}|-\nabla^2+V_{KS}^{sph}(r)|\chi_\vK}_{MT}A_{\vK   j}=
%\nonumber\\
%&-& \Im\left\{
%\left( 2 a_{i,lm}^* E_\nu + b_{i,lm}^* +   c^*_{i,lm} (E_{\mu}+E_\nu) \braket{u|u_{LO}} \right)\vcA_{j,lm}
%\right\}+
%%
%\nonumber\\
%&-& \Im\left\{
%\left(
%a_{i,lm}^* +2 b_{i,lm}^* E_\nu \braket{\dot{u}_l|\dot{u}_l} +
%c^*_{i,lm}  [ \braket{u_{LO}|u_l}  +    (E_\mu+E_\nu)\braket{u_{LO}|\dot{u}_l} ]\right)\vcB_{j,lm}
%\right\}+
%\\
%&-&\Im\left\{
%\left(
%a^*_{i,lm} (E_{\mu}+E_\nu) \braket{u|u_{LO}}
%+ b^*_{i,lm}  [ \braket{u_{LO}|u_l} + (E_\mu+E_\nu)\braket{u_{LO}|\dot{u}_l} ]
%+ 2 E_\mu\; c^*_{i,lm}  \braket{u_{LO}|u_{LO}}
%\right)\vcC_{j,lm}
%\right\}\nonumber
%\end{eqnarray}
%
\begin{eqnarray}
(A^{0\dagger} H_{MT}^{sym} A^0)_{ij} &\equiv& \sum_{\vK\vK'} A^\dagger_{i \vK'}i(\vK-\vK')  \braket{\chi_{\vK'}|-\nabla^2+V_{KS}^{sph}(r)|\chi_\vK}_{MT}A_{\vK   j}=
\nonumber\\
&& \sum_{\vK\vK'} A^\dagger_{i \vK'}i(\vK-\vK')
\left(
\begin{array}{ccc}
a_{lm\vK'}^*, & b_{lm\vK'}^* & c^*_{lm\vK'}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
a_{lm\vK}\\
b_{lm\vK}\\
c_{lm\vK}
\end{array}
\right)  A_{\vK   j}
\nonumber\\
&&
=i \left(
\begin{array}{ccc}
a_{i,lm}^*, & b_{i,lm}^* & c^*_{i,lm}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
\vcA_{j,lm}\\
\vcB_{j,lm}\\
\vcC_{j,lm}
\end{array}
\right)-
i\left(
\begin{array}{ccc}
\vcA_{i,lm}^*, & \vcB_{i,lm}^* & \vcC^*_{i,lm}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
a_{j,lm}\\
b_{j,lm}\\
c_{j,lm}
\end{array}
\right)
\end{eqnarray}
where
\begin{eqnarray}
\cH=\left(
\begin{array}{ccc}
\overline{\braket{u_l|H|u_l}} & \overline{\braket{u_l|H|\dot{u}_l}} & \overline{\braket{u_l|H|u^{LO}_l}} \\
\overline{\braket{\dot{u}_l|H|u_l}} & \overline{\braket{\dot{u}_l|H|\dot{u}_l}} & \overline{\braket{\dot{u}_l|H|u^{LO}_l}} \\
\overline{\braket{u^{LO}_l|H|u_l}} & \overline{\braket{u^{LO}_l|H|\dot{u}_l}} & \overline{\braket{u^{LO}_l|H|u^{LO}_l}}
\end{array}
\right)
\end{eqnarray}
and
$\overline{\braket{u^{LO}_l|H|u_l}} =\frac{1}{2}(\braket{u^{LO}_l|H|u_l} +\braket{u_l|H|u^{LO}_l})$.
When $H=-\nabla^2+V^{sph}$, we get for the MT part
$3\times 3$ matrix
\begin{eqnarray}
\cH \equiv \left(
\begin{array}{ccc}
E_l & \frac{1}{2} & \frac{1}{2}(E_l+E^{LO}_l) \braket{u|u^{LO}} \\
\frac{1}{2} & E_l \braket{\dot{u}|\dot{u}} & \frac{1}{2}(E_l+E^{LO}_l) \braket{\dot{u}|u^{LO}} +\frac{1}{2}\braket{u_l|u_l^{LO}}\\
\frac{1}{2}(E_l+E^{LO}_l) \braket{u_l|u^{LO}_l}&  \frac{1}{2}(E_l+E^{LO}_l) \braket{\dot{u}_l|u^{LO}_l}+\frac{1}{2}\braket{u_l|u_l^{LO}}& E^{LO}_l
\end{array}
\right)
\end{eqnarray}
The result is
\begin{eqnarray}
(A^{0\dagger} H_{MT}^{sym} A^0) = i (\cR-\cR^\dagger)
\end{eqnarray}
with
\begin{eqnarray}
\cR =
\left(
\begin{array}{ccc}
a_{i,lm}^*, & b_{i,lm}^* & c^*_{i,lm}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
\vcA_{j,lm}\\
\vcB_{j,lm}\\
\vcC_{j,lm}
\end{array}
\right)
\end{eqnarray}

Next we add non-spherically symmetric part
\begin{eqnarray}
(A^{0\dagger} H_{MT}^{nsym} A^0)_{ij} \equiv
\sum_{\vK\vK'}A^\dagger_{i\vK'}i(\vK-\vK')\braket{\chi_{\vK'}|V_{KS}^{nsph}(r)|\chi_\vK}_{MT}A_{\vK j}=\\
\sum_{\vK\vK'l'm'\kappa',lm\kappa}A^\dagger_{i\vK'}i(\vK-\vK')  a^{\kappa'\;*}_{l'm',\vK'}
a_{lm\vK}^\kappa A_{\vK j}
\int d\vr u_{l'}^{\kappa'}(r) Y_{l'm'}^*(\vr) V^{non-sph}(\vr)Y_{lm}(\vr) u_l^\kappa(r)
\end{eqnarray}
The non-spherical symmetric potential is read from case.nsh,
and takes the form
\begin{eqnarray}
V^{non-sph}_{\kappa_1 l_1 m_1 \kappa_2 l_2 m_2} = \int d^3 r Y^*_{l_1 m_1}(\hat{\vr}) u^{\kappa_1} V^{n-sym}(\vr) u^{\kappa_2}Y_{l_2 m_2}(\hat{\vr})
\end{eqnarray}
The result then is
\begin{eqnarray}
(A^{0\dagger} H_{MT}^{nsym} A^0)_{ij} =
i \sum_{l'm'\kappa',lm\kappa}
a^{\kappa'\;*}_{i, l'm'} V^{non-sph}_{\kappa' l' m' \kappa l m}  \vcA^\kappa_{j, lm}
-(\vcA^{\kappa'}_{i,l'm'} V^{non-sph\;*}_{\kappa' l' m' \kappa l m} a^{\kappa\;*}_{j,lm})^*
\end{eqnarray}
We next use the fact that
$$V^{non-sph\;*}_{\kappa' l' m' \kappa l m} =V^{non-sph}_{\kappa l m \kappa' l' m'} $$
to obtain
\begin{eqnarray}
(A^{0\dagger} H_{MT}^{nsym} A^0)_{ij} =
i \sum_{l'm'\kappa',lm\kappa}
a^{\kappa'\;*}_{i, l'm'} V^{non-sph}_{\kappa' l' m' \kappa l m}  \vcA^\kappa_{j, lm}
-(a^{\kappa'\;*}_{j,l' m'} V^{non-sph}_{\kappa' l' m' \kappa l m} \vcA^{\kappa}_{i,lm})^*
=i(\cR-\cR^\dagger)_{ij}
\end{eqnarray}
where
\begin{eqnarray}
\cR_{ij}=\sum_{l'm'\kappa',lm\kappa} a^{\kappa'\;*}_{i, l'm'} V^{non-sph}_{\kappa' l' m' \kappa l m}  \vcA^\kappa_{j, lm}
\end{eqnarray}

We also need to add the surface term because we use
$\nabla\cdot\nabla$ in the interstitial and $-\nabla^2$ in the
MT-sphere. This term is
% \begin{eqnarray}
% (A^{0\dagger} dT_{MT} A^0)_{ii} \equiv
% \sum_{\vK\vK'} A^{\dagger}_{i\vK'}  i(\vK-\vK')  A_{\vK i} \oint_{R_{MT}^-} d\vec{S}\chi^*_{\vk+\vK'}(\vr)\nabla_\vr \chi_{\vk+\vK}(\vr)
% =\\
% -R_{MT}^2 \sum_{l,m,\kappa',\kappa}
% \Im[a_{i,lm}^{\kappa'\,*} u_l^{\kappa'} \vcA_{i,lm}^\kappa  {u'}_l^\kappa
% +\vcA_{i,lm}^{\kappa'} u_l^{\kappa'} a^{\kappa\,*}_{i,lm}  {u'}_l^\kappa
% ]
% \end{eqnarray}
%
\begin{eqnarray}
(A^{0\dagger} dT_{MT} A^0)_{ij} \equiv
\sum_{\vK\vK'} A^{\dagger}_{i\vK'}  i(\vK-\vK')  A_{\vK j} \overline{\oint_{R_{MT}^-} d\vec{S}\chi^*_{\vk+\vK'}(\vr)\nabla_\vr \chi_{\vk+\vK}(\vr)}
=\\
R_{MT}^2\sum_{\vK\vK'} A^{\dagger}_{i\vK'}  i(\vK-\vK')
\left(
\begin{array}{ccc}
a_{lm\vK'}^*, & b_{lm\vK'}^* & c^*_{lm\vK'}
\end{array}
\right)
\cR
\left(
\begin{array}{c}
a_{lm\vK}\\
b_{lm\vK}\\
c_{lm\vK}
\end{array}
\right) A_{\vK j}
=\\
i\; R_{MT}^2
\left[
\left(
\begin{array}{ccc}
a_{i,lm}^*, & b_{i,lm}^* & c^*_{i,lm}
\end{array}
\right)
\cR
\left(
\begin{array}{c}
\vcA_{j,lm}\\
\vcB_{j,lm}\\
\vcC_{j,lm}
\end{array}
\right)
-
\left(
\begin{array}{ccc}
\vcA_{i,lm}^*, & \vcB_{i,lm}^* & \vcC^*_{i,lm}
\end{array}
\right)
\cR
\left(
\begin{array}{c}
a_{j,lm}\\
b_{j,lm}\\
c_{j,lm}
\end{array}
\right)
\right]
\end{eqnarray}
where
\begin{eqnarray}
\cR=\left(
\begin{array}{ccc}
u_l\frac{du_l}{dr} & u_l\frac{d\dot{u}_l}{dr}+\frac{1}{2R^2} &\frac{1}{2}(u_l\frac{du^{LO}_l}{dr} +u^{LO}_l\frac{du_l}{dr}) \\
u_l\frac{d\dot{u}_l}{dr}+\frac{1}{2R^2} & \dot{u}_l\frac{d\dot{u}_l}{dr} &  \frac{1}{2}(\dot{u}_l\frac{du^{LO}_l}{dr} +u^{LO}_l\frac{d\dot{u}_l}{dr}) \\
\frac{1}{2}(u_l\frac{du^{LO}_l}{dr} +u^{LO}_l\frac{du_l}{dr})&\frac{1}{2}(\dot{u}_l\frac{du^{LO}_l}{dr}+u^{LO}_l\frac{d\dot{u}_l}{dr}) & u_l^{LO}\frac{d u^{LO}_l}{dr}
\end{array}
\right)
\end{eqnarray}
so that
\begin{eqnarray}
(A^{0\dagger} dT_{MT} A^0)_{ij} = i (\cO-\cO^\dagger)
\end{eqnarray}
with
\begin{eqnarray}
\cO = R_{MT}^2
\left(
\begin{array}{ccc}
a_{i,lm}^*, & b_{i,lm}^* & c^*_{i,lm}
\end{array}
\right)
\cR
\left(
\begin{array}{c}
\vcA_{j,lm}\\
\vcB_{j,lm}\\
\vcC_{j,lm}
\end{array}
\right)
\end{eqnarray}

\begin{eqnarray}
(A^{0\dagger} T_S A^0)_{ii} \equiv \sum_{\vK\vK'}A^{0\dagger}_{i\vK'}\oint_{MT} d\vec{S} \tilde{\chi}_{\vK'}^* T  \tilde{\chi}_{\vK}A^0_{\vK i}=
\sum_{\vK\vK'}A^{0*}_{\vK' i} A^0_{\vK i}(\vK'+\vk)\cdot(\vK+\vk)\oint  d\vec{S}\frac{e^{i(\vK-\vK')\vr}}{V}=
\\
\sum_{\vK\vG}A^{0*}_{\vK-\vG, i} (\vK-\vG+\vk)\cdot(\vK+\vk) A^0_{\vK  i}
\frac{R_{MT}^2}{V} e^{i\vG\vR_\alpha}\int d\Omega\vec{e}_\vr  {e^{i\vG\vr}}
\end{eqnarray}
We then define
\begin{eqnarray}
C_\vG\equiv \sum_{\vK}A^{0*}_{\vK-\vG, i} (\vK-\vG+\vk)\cdot(\vK+\vk) A^0_{\vK  i}
\end{eqnarray}
which is obtained by FFT of
\begin{eqnarray}
\vec{X}_i(\vr_l)= \sum_\vK A^0_{\vK  i} (\vK+\vk) e^{-i\vK\vr_l}
\end{eqnarray}
and
\begin{eqnarray}
C_\vG = \frac{1}{N_l}\sum_{\vr_l}\vec{X}^*_i\cdot\vec{X}_i e^{i\vK\vr_l}
\end{eqnarray}
We finally have
\begin{eqnarray}
(A^{0\dagger} T_S A^0)_{ii} =
\sum_{\vG} C_\vG e^{i\vG\vR_\alpha}\frac{R_{MT}^2}{V} \int d\Omega\vec{e}_\vr  {e^{i\vG\vr}}=
\frac{4\pi R_{MT}^2}{V} \sum_{\vG}C_\vG\; i e^{i\vG\vR_\alpha}\;
\frac{\vG}{|\vG|} \; j_1(|\vG|R_{MT})
\end{eqnarray}
We conclude with the potential part
\begin{eqnarray}
(A^{0\dagger} V_S A^0)_{ii} =
\sum_{\vK'\vK} A^{0*}_{\vK' i} A^0_{\vK i} \oint_{MT} d\vec{S}  \frac{e^{i(\vK-\vK')\vr}}{V} V_{KS}(\vr)
\end{eqnarray}
The expansion of the potential exists
\begin{eqnarray}
V_{KS}(\vr) = \sum_{\vG_0} e^{-i\vG_0 \vr}V_{\vG_0},
\end{eqnarray}
which gives
\begin{eqnarray}
(A^{0\dagger} V_S A^0)_{ii} =
\sum_{\vK'\vK\vG_0} A^{0*}_{\vK' i} A^0_{\vK i} V_{\vG_0} \oint_{MT} d\vec{S}  \frac{e^{i(\vK-\vK'-\vG_0)\vr}}{V} =
\sum_{\vK\vG\vG_0} A^{0*}_{\vK-\vG_0-\vG, i} A^0_{\vK, i} V_{\vG_0} \oint_{MT} d\vec{S}  \frac{e^{i\vG\vr}}{V}
\end{eqnarray}
We then perform FFT on $A^0$ and $V$ to obtain
\begin{eqnarray}
Y_i(\vr_l) = \sum_\vK e^{-i\vK\vr_l} A_{\vK,i}\\
V(\vr_l) = \sum_{\vG_0} e^{i\vG_0\vr_l} V_{\vG_0}
\end{eqnarray}
We can then show that
\begin{eqnarray}
E_{\vG}\equiv \sum_{\vK\vG_0} A^{0*}_{\vK-\vG_0-\vG, i} A^0_{\vK, i}
  V_{\vG_0} =\frac{1}{N_l}\sum_{\vr_l} Y^*_i(\vr_l) V(\vr_l)
  Y_i(\vr_l) e^{i \vG\vr_l}
\end{eqnarray}
hence
\begin{eqnarray}
(A^{0\dagger} V_S A^0)_{ii} =
\sum_{\vG} E_{\vG} e^{i\vG\vR_\alpha} \frac{R_{MT}^2}{V}
\int d\Omega \vec{e}_\vr  e^{i\vG\vr} =
\frac{4\pi R_{MT}^2}{V} \sum_{\vG}E_\vG\; i e^{i\vG\vR_\alpha}\;
\frac{\vG}{|\vG|} \; j_1(|\vG|R_{MT})
\end{eqnarray}

If we want to compute the potential on the MT-sphere using
interstitial potential, we write
\begin{eqnarray}
V(\vr) = \sum_\vG V_\vG e^{-i\vG\vr} = e^{-i\vG\vR_\alpha} V_\vG 4\pi
 \sum_{lm} (-i)^l j_l(|G|R_{MT}) y_{lms}(\hat{\vG}) y_{lms}(\hat{\vr})
\end{eqnarray}
and compute
\begin{eqnarray}
V_{lms}(\vr) = \sum_\vG V_\vG e^{-i\vG\vr} = \sum_\vG e^{-i\vG\vR_\alpha} y_{lms}(\hat{\vG}) V_\vG 4\pi (-i)^l j_l(|G|R_{MT})
\end{eqnarray}

\subsection{Calculation of H in lapw1}
\subsubsection{Interstitails}

Note that in lapw1, the plane wave basis function (valid in the interstitial) is defined by
\begin{eqnarray}
\tilde{\chi}_{\vk+\vK} = \frac{1}{\sqrt{V}}e^{i(\vk+\vK)\vr}
\end{eqnarray}

In the interstitials, the overlap is
\begin{eqnarray}
\tilde{O}_{\vK\vK'}=\braket{\tilde{\chi}_{\vK'}|\tilde{\chi}_\vK}=\int_{interstitial} d^3 \tilde{\chi}^*_{\vK'}  \tilde{\chi}_\vK =
\delta_{\vK\vK'}- \sum_{\vR_\alpha} e^{i\vR_\alpha(\vK-\vK')}
\int_{MT}d^3r \frac{e^{i\vr(\vK-\vK')}}{V}\\
=
\delta_{\vK\vK'}-
 4\pi R_{MT}^2 \frac{j_1(|\vK-\vK'|R_{MT})}{V_{cell}|\vK-\vK'|}\sum_{\vR_\alpha} e^{i\vR_\alpha(\vK-\vK')}
\\
=\delta_{\vK\vK'}-  3 \frac{V_{MT}}{V_{cell}} \frac{j_1(|\vK-\vK'|R_{MT})}{|\vK-\vK'|R_{MT}}\sum_{\vR_\alpha} e^{i\vR_\alpha(\vK-\vK')}
\end{eqnarray}
and the kinetic part is
\begin{eqnarray}
\tilde{T}_{\vK\vK'}=\braket{\tilde{\chi}_{\vK'}|T|\tilde{\chi}_\vK}=\int_{interstitial} d^3 \tilde{\chi}^*_{\vK'}
  T\tilde{\chi}_\vK =  (\vK'+\vk)(\vK+\vk) \int_{interstitial} d^3
  \tilde{\chi}^*_{\vK'}  \tilde{\chi}_\vK=
(\vK'+\vk)(\vK+\vk) \tilde{O}_{\vK'\vK}
\end{eqnarray}
The potential part is
\begin{eqnarray}
\tilde{V}_{\vK\vK'}=\braket{\tilde{\chi}_{\vK'}|\tilde{V}|\tilde{\chi}_\vK}=
\int_{interstitial} d^3 \tilde{\chi}^*_{\vK'}
  \sum_{\vG} V_{\vG}e^{-i\vG\vr}\tilde{\chi}_\vK =
\sum_\vG  V_{\vG} \int_{interstitial}
e^{i(\vK-\vK'-\vG)\vr}=\\
\sum_{\vG}  V_{\vG}
\left(\delta_{\vK-\vK'-\vG}-
\sum_\alpha e^{i(\vK-\vK'-\vG)\vR_\alpha}
4\pi R_{MT}^2 \frac{j_1(|\vK-\vK'-\vG|R_{MT})}{|\vK-\vK'-\vG|}
\right)
\end{eqnarray}
We compute this by computing convolution of $V_\vG$ and the following
quantity
\begin{eqnarray}
\cR_\vK = \delta_{\vK}-\sum_\alpha e^{i\vK\vR_\alpha}4\pi R_{MT}^2 \frac{j_1(|\vK|R_{MT})}{|\vK|}
\end{eqnarray}
Let's define
\begin{eqnarray}
U_\vK \equiv \sum_\vG V_\vG \cR_{\vK-\vG}
\end{eqnarray}
We then see that the result is
\begin{eqnarray}
\tilde{V}_{\vK\vK'}= U_{\vK-\vK'}
\end{eqnarray}
Note that $U_\vK$ is named \textit{warp} or \textit{warpin}, and is
stored in \textit{case.vns}.

\subsubsection{Muffin-thin, non-local orbitals}

The basis inside MT-part is
\begin{eqnarray}
\chi_\vK(\vr) = \sum_{lm\mu'} \frac{4\pi i^l R_{MT}^2}{\sqrt{V}}e^{i(\vk+\vK)\vr_{\mu'}}Y_{lm}(R_{\mu'}(\vk+\vK))
 (\tilde{a}_{l\vK} u_l(r) + \tilde{b}_{l\vK}  \dot{u}_l(r))Y^*_{lm}(R_{\mu'}^{-1}\vr)
\end{eqnarray}

We first perform the calculation in the absence of local orbitals.
For overlap, we have
\begin{eqnarray}
\braket{\chi_{\vK'}|\chi_\vK}_{MT}=
\int_{MT} dr (a_{lm\vK'}^* u_l+b_{lm\vK'}^* \dot{u}_l) (a_{lm\vK}  u_l+b_{lm\vK} \dot{u}_l)=
a_{lm\vK'}^* a_{lm\vK}  +b_{lm\vK'}^*b_{lm\vK} \braket{\dot{u}|\dot{u}}
\end{eqnarray}
For Hamiltonian, we have two parts, i.e,
\begin{eqnarray}
&&\braket{\chi_{\vK'}|H^{sym}|\chi_\vK}_{MT}=\int_{MT} \chi^*_{\vK'}(-\nabla^2+V_{KS}^{sym})\chi_{\vK}+\oint_{MT} d\vec{S}
\chi^*_{\vK'}\nabla_\vr\chi_{\vK}\\
&&=
\int_{MT}d^3r Y_{lm}^*(\vr) (a_{lm\vK'}^* u_l+b_{lm\vK'}^* \dot{u}_l)
(-\nabla^2+V_{KS}^{sym})  (a_{lm\vK} u_l+b_{lm\vK} \dot{u}_l)Y_{lm}(\vr)
\nonumber\\
&&+R_{MT}^2\int_{MT} d\Omega (a_{lm\vK'}^* u_l(R)+b_{lm\vK'}^*  \dot{u}_l(R))  (a_{lm\vK} \frac{d u_l(R)}{dr}+b_{lm\vK}  \frac{d\dot{u}_l(R)}{dr}) Y_{lm}^*  Y_{lm}
\nonumber\\
&&=
\int_{MT} dr (a_{lm\vK'}^* u_l+b_{lm\vK'}^* \dot{u}_l)  \left[\varepsilon_l(a_{lm\vK} u_l+b_{lm\vK} \dot{u}_l) +b_{lm\vK}  u_l \right]
\nonumber\\
&&+R_{MT}^2 (a_{lm\vK'}^* u_l(R)+b_{lm\vK'}^*  \dot{u}_l(R))  (a_{lm\vK} \frac{d u_l(R)}{dr}+b_{lm\vK}  \frac{d\dot{u}_l(R)}{dr})
\nonumber\\
&&=\varepsilon_l (a_{lm\vK'}^* a_{lm\vK} +b_{lm\vK'}^* b_{lm\vK}  \braket{\dot{u}_l|\dot{u}_l})+a_{lm\vK'}^* b_{lm\vK}
\\
&&+R_{MT}^2 \left(
a_{lm\vK'}^*a_{lm\vK} u_l(R) \frac{d u_l(R)}{dr}+
b_{lm\vK'}^* b_{lm\vK}  \dot{u}_l(R) \frac{d\dot{u}_l(R)}{dr}+
a_{lm\vK'}^* b_{lm\vK}  u_l(R) \frac{d\dot{u}_l(R)}{dr}+
b_{lm\vK'}^*  a_{lm\vK} \dot{u}_l(R) \frac{d u_l(R)}{dr}\right)\nonumber
\end{eqnarray}
We know that
\begin{eqnarray}
\dot{u}(R)\frac{du(R)}{dr}-u(R) \frac{d\dot{u}(R)}{dr}=\frac{1}{R^2}
\end{eqnarray}
hence we can use this identity in the last term to obtain more
symmetric result
\begin{eqnarray}
\braket{\chi_{\vK'}|H^{sym}|\chi_\vK}_{MT}&=&\varepsilon_l (a_{lm\vK'}^* a_{lm\vK} +b_{lm\vK'}^* b_{lm\vK}  \braket{\dot{u}_l|\dot{u}_l})+a_{lm\vK'}^* b_{lm\vK} +b_{lm\vK'}^*  a_{lm\vK}
\\
&+&R_{MT}^2 \left(
a_{lm\vK'}^*a_{lm\vK} u_l(R) \frac{d u_l(R)}{dr}+
b_{lm\vK'}^* b_{lm\vK}  \dot{u}_l(R) \frac{d\dot{u}_l(R)}{dr}+
(a_{lm\vK'}^* b_{lm\vK}+b_{lm\vK'}^*  a_{lm\vK})  u_l(R) \frac{d\dot{u}_l(R)}{dr}
\right)\nonumber
\end{eqnarray}
In all cases, we have terms like $a_{lm\vK'}^*b_{lm\vK}$, which can be
further simplified
\begin{eqnarray}
\sum_m a_{lm\vK'}^*b_{lm\vK} =
\frac{(4\pi R_{MT}^2)^2}{V} e^{i(\vK-\vK')\vR_\alpha}  \tilde{a}_{l\vK'} \tilde{b}_{l\vK} \sum_m Y_{lm}(R_\alpha(\vK'+\vk))Y^*_{lm}(R_\alpha(\vK+\vk))
\\
=\frac{(4\pi R_{MT}^2)^2}{V} e^{i(\vK-\vK')\vR_\alpha}  \tilde{a}_{l\vK'}\tilde{b}_{l\vK}
\frac{2l+1}{4\pi}P_l((\vK'+\vk)(\vK+\vk))
\\
=\frac{ 4\pi R_{MT}^4}{V}
(2l+1)P_l((\vK'+\vk)(\vK+\vk))
e^{i(\vK-\vK')\vR_\alpha}  \tilde{a}_{l\vK'} \tilde{b}_{l\vK}
\end{eqnarray}
where
\begin{eqnarray}
\left(
\begin{array}{c}
\tilde{a}_{l\vK}\\
\tilde{b}_{l\vK}
\end{array}\right)
=
\left(
\begin{array}{c}
\dot{u}_l(S)\frac{d}{dr} j_l(|\vk+\vK|S)-\frac{d}{dr} \dot{u}_l(S) j_l(|\vk+\vK|S)\\
\frac{d}{dr} u_l(S) j_l(|\vk+\vK|S)- u_l(S) \frac{d}{dr} j_l(|\vk+\vK|S)
\end{array}
\right)
\end{eqnarray}

We first define
\begin{eqnarray}
C_l(\vK',\vK) = \left(\sum_{\alpha\in equivalent}e^{i(\vK-\vK')\vR_\alpha}\right)
\frac{ 4\pi R_{MT}^4}{V} (2l+1)P_l((\vK'+\vk)(\vK+\vk))
\end{eqnarray}

For the overlap we can get
\begin{eqnarray}
O_{\vK\vK'}\equiv \braket{\chi_{\vK'}|\chi_\vK}_{MT}=C_l(\vK',\vK)
\left(\tilde{a}_{l\vK'} \tilde{a}_{l\vK}  +\tilde{b}_{l\vK'}\tilde{b}_{l\vK} \braket{\dot{u}|\dot{u}}\right)
\end{eqnarray}
And for the Hamiltonian, we get
\begin{eqnarray}
H_{\vK\vK'}\equiv\braket{\chi_{\vK'}|H^{sym}|\chi_\vK}_{MT}=
C_l(\vK',\vK)
\{
\varepsilon_l (\tilde{a}_{l\vK'}\tilde{a}_{l\vK}+\tilde{b}_{l\vK'}\tilde{b}_{l\vK} \braket{\dot{u}_l|\dot{u}_l})+
\tilde{a}_{l\vK'}\tilde{b}_{l\vK}+\tilde{b}_{l\vK'}\tilde{a}_{l\vK}
\nonumber\\
+R_{MT}^2
\left[\tilde{a}_{l\vK'} u_l(R) \frac{d u_l(R)}{dr}+\tilde{b}_{l\vK'} u_l(R) \frac{d\dot{u}_l(R)}{dr}\right]\tilde{a}_{l\vK}
\nonumber\\
+R_{MT}^2
\left[\tilde{b}_{l\vK'}\dot{u}_l(R) \frac{d\dot{u}_l(R)}{dr}+\tilde{a}_{l\vK'} u_l(R) \frac{d\dot{u}_l(R)}{dr}\right]\tilde{b}_{l\vK}
\}
\end{eqnarray}

\subsubsection{Muffin-thin, local orbitals}

The basis inside the MT-part, in which Hamiltonian is diagonalized, is
\begin{eqnarray}
\chi_\vK(\vr) &=& \sum_{lm\mu'} \frac{4\pi i^l R_{MT}^2}{\sqrt{V}}e^{i(\vk+\vK)\vr_{\mu'}}Y_{lm}(R_{\mu'}(\vk+\vK))
 (\tilde{a}_{l\vK} u_l(r) + \tilde{b}_{l\vK}  \dot{u}_l(r))Y^*_{lm}(R_{\mu'}^{-1}\vr)\\
\chi_{\nu}(\vr) &=& \sum_{m'\mu'}\frac{4\pi i^l  R_{MT}^2}{\sqrt{V}}e^{i(\vk+\vK_\nu)\vr_{\mu'}}Y_{lm'}(R_{\mu'}(\vk+\vK_\nu))
 (a^{lo}_{\nu} u_l(r) + b^{lo}_{\nu}\dot{u}_l(r) + c^{lo}_{\nu} u^{LO}_l(r)) Y^*_{lm'}(R_{\mu'}^{-1}\vr)
\end{eqnarray}
In the last term we compute $a^{lo}$, $b^{lo}$ and $c^{lo}$ so that
$\chi_{\nu}(r=R_{MT}) =0$. In LAPW method, we can also make derivative $d\chi_\nu(r=R_{MT})/dr$
vanish, while in APW+lo only the value $\chi_\nu(r=R_{MT})$ vanishes.
Note that the index for the local orbital $\nu$ comprises
$(i,l,j_{lo},\alpha,m)$ in this order, where ($i$, $l$, $j_{lo}$, $\alpha$, $m$) are
(index of a sort, $l$, index enumerates local orbital, index of the
equivalent atom, $m$).

Notice that the phase factor in the local orbital functions is taken
to be the same as in augmented plane waves. Moreover, $\vK_\nu$ is
taken to be different for each local orbital component. Namely, each
set of equivalent atoms and their $m$ quantum numbers are assigmed a unique set
of $\vK$'s, usually just starting from the beginning of the
list. For different atom types and different $l$'s the reciprocal
vectors repeat, so that for example each first atom of a new type and
its first $m=-l$ will have $K_\nu=0$ vector. I do not know why is such
extra phase factor necessary.... but this is how it is implemented in Wien2k.

The orbital, which vanishes at the MT-boundary, has the following
form:
\begin{eqnarray}
u^{loc}_\nu(r) = a^{lo}_\nu u_l(r) + b^{lo}_\nu \dot{u}(r) + c^{lo}_\nu u_l^{LO}
\end{eqnarray}
\begin{eqnarray}
(-\nabla^2+V_{sym}) u^{loc}_\nu(r) =
 a^{lo}_\nu u_l \; E_{\mu} ^l
+  b^{lo}_\nu (\dot{u}_l  E_{\mu}^l + u_l)
+ c^{lo}_\nu u^{LO}_l  E^l_{\mu'}
= (a^{lo}_\nu E_{\mu}^l+b^{lo}_\nu) u_l +
b^{lo}_\nu E_\mu^l \dot{u}_l + c^{lo}_\nu E_{\mu'}^l  u^{LO}_l
\end{eqnarray}
In the code we define
\begin{eqnarray}
&& C^\nu_1  = \braket{u^{loc}_\nu|u_l}    = a^{lo}_\nu + c^{lo}_\nu\braket{u_l|u_l^{LO}}\\
&& C^\nu_2  = \braket{u^{loc}|\dot{u}_l} = b^{lo}_\nu\braket{\dot{u}_l|\dot{u}_l} + c^{lo}_\nu\braket{\dot{u}_l|u^{LO}_l}\\
&& C^\nu_3  = \braket{u^{loc}|u^{LO}_l} = c_\nu^{lo} + b_\nu^{lo}\braket{\dot{u}_l|u^{LO}_l} + a^{lo}_\nu\braket{u_l|u^{LO}_l}\\
&& C^\nu_{11} = \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}|u_l}+\braket{u_l|H_{sym}|u^{loc}_\nu})
   = a^{lo}_\nu E_\mu^l + \frac{1}{2} b^{lo}_\nu + \frac{1}{2} c^{lo}_\nu \braket{u|u^{LO}}(E^l_\mu+E^l_{\mu'})\\
&& C^\nu_{12} =  \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}|\dot{u}_l}+\braket{\dot{u}_l|H_{sym}|u^{loc}_\nu})
= b^{lo}_\nu \braket{\dot{u}_l|\dot{u}_l}E^l_\mu +
\frac{1}{2} a^{lo}_\nu+
\frac{1}{2}c^{lo}_\nu\braket{u_l|u_l^{LO}}+
c^{lo}_\nu\braket{\dot{u}_l|u^{LO}}\frac{1}{2}(E^l_\mu+E^l_{\mu'})
\\
&& C^\nu_{13} =  \frac{1}{2}(\braket{u^{loc}_\nu|H_{sym}|u^{LO}_l}+\braket{u^{LO}_l|H_{sym}|u^{loc}_\nu})
= c^{lo}_\nu E_{\mu'} +
\frac{1}{2} b^{lo}_\nu \braket{u_l|u^{LO}_l} +
\left(a^{lo}_\mu\braket{u_l|u^{LO}_l}+b^{lo}_\nu\braket{\dot{u}_l|u^{LO}_l}\right) \frac{1}{2}(E_\mu+E_{\mu'})
\nonumber\\
&& ak_{inlo} = \frac{1}{2}  R_{MT}^2  \frac{du_\nu^{loc}(r)}{dr}|_{r=R_{MT}}
\end{eqnarray}

We need to calculate the overlap terms, such as
\begin{eqnarray}
O_{\vK,\nu} &=&\braket{\chi_\nu|\chi_\vK}=\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK-\vK_\nu)\vr_{\mu'}}
Y_{lm'}(R_{\mu'}(\vK+\vk))  Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))\\
&&\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad \times
{\braket{a^{lo}_{\nu}u_l+b^{lo}_{\nu}\dot{u}_l+c^{lo}_{\nu}u^{LO}_l|\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK} \dot{u}_l}}=\\
&=&\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK-\vK_\nu)\vr_{\mu'}}
Y_{lm'}(R_{\mu'}(\vK+\vk))  Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))\times (\tilde{a}_{l\vK} C^\nu_1 + \tilde{b}_{l\vK} C^\nu_2)
\end{eqnarray}
Hamiltonian, which takes the form
\begin{eqnarray}
&&\braket{\chi_{\vK}|H^{sym}|\chi_\nu}_{MT}=\int \chi^*_{\vK}(-\nabla^2+V_{KS}^{sym})\chi_{\nu}+\oint_{MT} d\vec{S}\chi^*_{\vK}\nabla_\vr\chi_{\nu}
\end{eqnarray}
 is then given by
$$H_{\vK\nu}\equiv \frac{1}{2}(\braket{\chi_{\nu}|H^{sym}|\chi_\vK}_{MT}+\braket{\chi_{\vK}|H^{sym}|\chi_\nu}^*_{MT}) $$
\begin{eqnarray}
H_{\vK\nu}=
\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK-\vK_\nu)\vr_{\mu'}}
Y_{lm'}(R_{\mu'}(\vK+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))
\\
\times
\left(\overline{\braket{a^{lo}_{\nu}u_l+b^{lo}_{\nu}\dot{u}_l+c^{lo}_{\nu}u^{LO}_l|H|\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK} \dot{u}_l}}
\right.
\\
+\left.
\frac{R_{MT}^2}{2}
\left(
\frac{d u^{local}_l}{dr}
(\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK} \dot{u}_l)+
u^{local}_l\frac{d (\tilde{a}_{l\vK}  u_l+\tilde{b}_{l\vK} \dot{u}_l)}{dr}
\right)\biggl|_{r=R_{MT}}
\right)
\end{eqnarray}
Here overline means symmetrize the matrix elements.
Note that $u^{local}_l=0$, hence we can drop the last term.
The code computes this quantity:
\begin{eqnarray}
H_{\vK\nu}=\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK-\vK_\nu)\vr_{\mu'}}
Y_{lm'}(R_{\mu'}(\vK+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))
\times(\tilde{a}_{l\vK} C^\nu_{11} + \tilde{b}_{l\vK} C^\nu_{12})+\\
+\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK-\vK_\nu)\vr_{\mu'}}
Y_{lm'}(R_{\mu'}(\vK+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))  (\tilde{a}_{l\vK} u_l(R_{MT}) + \tilde{b}_{l\vK} \dot{u}_l(R_{MT})) ak_{inlo}
\end{eqnarray}

Hence the original surface term
\begin{eqnarray}
\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK-\vK_\nu)\vr_{\mu'}}
Y_{lm'}(R_{\mu'}(\vK+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))
%  (\tilde{a}_{l\vK} u_l(R_{MT}) + \tilde{b}_{l\vK} \dot{u}_l(R_{MT}))
\frac{R_{MT}^2 }{2}
\left[(\tilde{a}_{l\vK} u_l + \tilde{b}_{l\vK} \dot{u}_l) \frac{du_\nu^{loc}}{dr}+
u_\nu^{loc} \frac{\tilde{a}_{l\vK} u_l + \tilde{b}_{l\vK} \dot{u}_l}{dr}\right]\biggl|_{r=R_{MT}}
\nonumber
\end{eqnarray}
was simplified to
\begin{eqnarray}
\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK-\vK_\nu)\vr_{\mu'}}
Y_{lm'}(R_{\mu'}(\vK+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))
\frac{R_{MT}^2 }{2}
\left[(\tilde{a}_{l\vK} u_l + \tilde{b}_{l\vK} \dot{u}_l) \frac{du_\nu^{loc}}{dr}\right]\biggl|_{r=R_{MT}}
\nonumber
\end{eqnarray}
because $u^{local}_l=0$.

Finally, for the last term we have
\begin{eqnarray}
O_{\nu'\nu}=\braket{\chi_\nu|\chi_{\nu'}}=
\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_{\nu'}-\vK_\nu)\vr_{\mu'}}Y_{lm'}(R_{\mu'}(\vK_{\nu'}+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))
(a^{lo}_{\nu'} C_1^\nu + b^{lo}_{\nu'} C_2^\nu + c^{lo}_{\nu'} C_3^\nu)
\end{eqnarray}
and
\begin{eqnarray}
\braket{\chi_{\nu}|H^{sym}|\chi_{\nu'}}=\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_{\nu'}-\vK_\nu)\vr_{\mu'}}Y_{lm'}(R_{\mu'}(\vK_{\nu'}+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))\times\\
(a^{lo}_{\nu'} \braket{u_l|u_\nu^{loc}} +
b^{lo}_{\nu'}  \braket{\dot{u}_l|u_\nu^{loc}}  +
c^{lo}_{\nu'} \braket{u^{LO}_l|u_\nu^{loc}})
\end{eqnarray}
so that
\begin{eqnarray}
H_{\nu'\nu}\equiv \frac{1}{2}(\braket{\chi_{\nu}|H^{sym}|\chi_{\nu'}}+\braket{\chi_{\nu'}|H^{sym}|\chi_{\nu}}^*)
\end{eqnarray}
is
\begin{eqnarray}
H_{\nu'\nu}=\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_{\nu'}-\vK_\nu)\vr_{\mu'}}Y_{lm'}(R_{\mu'}(\vK_{\nu'}+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))\times
(a^{lo}_{\nu'} C_{11}^\nu+
b^{lo}_{\nu'}  C_{12}^\nu+
c^{lo}_{\nu'} C_{13}^\nu)
\end{eqnarray}

Note that this can also be written as
\begin{eqnarray}
H_{\nu'\nu}=\frac{(4\pi  R_{MT}^2)^2}{V}\sum_{m'\mu'} e^{i(\vK_{\nu'}-\vK_\nu)\vr_{\mu'}}Y_{lm'}(R_{\mu'}(\vK_{\nu'}+\vk)) Y^*_{lm'}(R_{\mu'}(\vK_\nu+\vk))\times
\left(
\begin{array}{ccc}
a^{lo}_{\nu}, & b^{lo}_{\nu} & c^{lo}_{\nu}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
a^{lo}_{\nu'}\\
b^{lo}_{\nu'}\\
c^{lo}_{\nu'}
\end{array}
\right)
\end{eqnarray}

\subsubsection{Non-spherical part}

We first construct $a_{lm\vK}$, $b_{lm\vK}$, $c_{lm\vK}$
coefficients, which take the form
\begin{eqnarray}
\left(\begin{array}{c}
a_{lm\vK}\\
b_{lm\vK}\\
c_{lm\vK}
\end{array}\right)=
\left(\begin{array}{c}
\tilde{a}_{l\vK}\\
\tilde{b}_{l\vK}\\
0
\end{array}\right)
\frac{4\pi R_{MT}^2}{\sqrt{V}} i^l e^{i(\vK+\vk)\vR_\alpha}  Y_{lm}^*(\vk+\vK)
\end{eqnarray}
for first $N_\vK$ reciprocal vectors. For $\vK$ index above $N_\vK$, we
populate $a_{lm\vK}$ with local orbitals, where the same coefficients take the form
\begin{eqnarray}
\left(\begin{array}{c}
a_{lm\vK_\nu}\\
b_{lm\vK_\nu}\\
c_{lm\vK_\nu}
\end{array}\right)=
\left(\begin{array}{c}
a^{lo}_\nu\\
b^{lo}_\nu\\
c^{lo}_\nu
\end{array}\right)
\frac{4\pi R_{MT}^2}{\sqrt{V}} i^l e^{i(\vK_\nu+\vk)\vR_\alpha}  Y_{lm}^*(\vk+\vK_\nu)
\end{eqnarray}
We then calculate
\begin{eqnarray}
&& H^{non-sym}_{\vK,\vK'} \equiv \braket{\chi_{\vK'}| V^{non-sym}|\chi_\vK}=\\
&& \int_{\vr} (a^*_{l'm'\vK'} u_{l'}(r) +
   b^*_{l'm'\vK'}\dot{u}_{l'}(r) +
   c^*_{l'm'\vK'}u^{LO}_{l'}(r))Y^*_{l'm'}(\vr)V(\vr)
   Y_{lm}(\vr)(a_{lm\vK} u_l(r) + b_{lm\vK}\dot{u}_l(r) +
   c_{lm\vK}u^{LO}(r))
\nonumber
\end{eqnarray}
We can define the following matrix
\begin{eqnarray}
V^{l'm',lm}=\int_\vr
\left(
\begin{array}{c}
u_{l'}(r) \\
\dot{u}_{l'}(r)\\
u^{LO}_{l'}(r)
\end{array}
\right)
Y_{l'm'}^*(\vr) V(\vr)
Y_{lm}(\vr)
\left(
\begin{array}{ccc}
u_{l'}(r), &\dot{u}_{l'}(r), &u^{LO}_{l'}(r)
\end{array}
\right)
\end{eqnarray}
and use it to evaluate the sum
\begin{eqnarray}
H^{non-sym}_{\vK,\vK'} =
\left(
\begin{array}{ccc}
a^*_{l'm'\vK'},&  b^*_{l'm'\vK'},& c^*_{l'm'\vK'}
\end{array}
\right)
V^{l'm',lm}
\left(
\begin{array}{c}
a_{lm\vK}\\
b_{lm\vK}\\
c_{lm\vK}
\end{array}
\right)
\nonumber
\end{eqnarray}

\subsection{Alternative derivation}

When calculating Hamiltonian or forces, we want to calculate the following matrix elements
\begin{eqnarray}
\frac{1}{2}(\braket{\chi_{\vK'}|H|\chi_\vK}+\braket{\chi_{\vK}|H|\chi_{\vK'}}^*=\\
=\frac{1}{2}
\left(
\begin{array}{ccc}
a_{lm\vK'}^*, & b_{lm\vK'}^* & c^*_{lm\vK'}
\end{array}
\right)
\left(
\begin{array}{ccc}
\braket{u_l|H|u_l} & \braket{u_l|H|\dot{u}_l} & \braket{u_l|H|u^{LO}_l} \\
\braket{\dot{u}_l|H|u_l} & \braket{\dot{u}_l|H|\dot{u}_l} & \braket{\dot{u}_l|H|u^{LO}_l} \\
\braket{u^{LO}_l|H|u_l} & \braket{u^{LO}_l|H|\dot{u}_l} & \braket{u^{LO}_l|H|u^{LO}_l}
\end{array}
\right)
\left(
\begin{array}{c}
a_{lm\vK}\\
b_{lm\vK}\\
c_{lm\vK}
\end{array}
\right)
\\
+\frac{1}{2}
\left(
\begin{array}{ccc}
a_{lm\vK}, & b_{lm\vK} & c_{lm\vK}
\end{array}
\right)
\left(
\begin{array}{ccc}
\braket{u_l|H|u_l} & \braket{u_l|H|\dot{u}_l} & \braket{u_l|H|u^{LO}_l} \\
\braket{\dot{u}_l|H|u_l} & \braket{\dot{u}_l|H|\dot{u}_l} & \braket{\dot{u}_l|H|u^{LO}_l} \\
\braket{u^{LO}_l|H|u_l} & \braket{u^{LO}_l|H|\dot{u}_l} & \braket{u^{LO}_l|H|u^{LO}_l}
\end{array}
\right)^*
\left(
\begin{array}{c}
a^*_{lm{\vK'}}\\
b^*_{lm{\vK'}}\\
c^*_{lm{\vK'}}
\end{array}
\right)
\end{eqnarray}
The product $\vec{a}_{\vK'} H \vec{a}_\vK+\vec{a}_\vK H^* \vec{a}_{\vK'}$ can be rearranged as
$\vec{a}_{\vK'} (H+H^\dagger) \vec{a}_\vK$, hence we have

\begin{eqnarray}
\frac{1}{2}(\braket{\chi_{\vK'}|H|\chi_\vK}+\braket{\chi_{\vK}|H|\chi_{\vK'}}^*=\\
=
\left(
\begin{array}{ccc}
a_{lm\vK'}^*, & b_{lm\vK'}^* & c^*_{lm\vK'}
\end{array}
\right)
\left(
\begin{array}{ccc}
\overline{\braket{u_l|H|u_l}} & \overline{\braket{u_l|H|\dot{u}_l}} & \overline{\braket{u_l|H|u^{LO}_l}} \\
\overline{\braket{\dot{u}_l|H|u_l}} & \overline{\braket{\dot{u}_l|H|\dot{u}_l}} & \overline{\braket{\dot{u}_l|H|u^{LO}_l}} \\
\overline{\braket{u^{LO}_l|H|u_l}} & \overline{\braket{u^{LO}_l|H|\dot{u}_l}} & \overline{\braket{u^{LO}_l|H|u^{LO}_l}}
\end{array}
\right)
\left(
\begin{array}{c}
a_{lm\vK}\\
b_{lm\vK}\\
c_{lm\vK}
\end{array}
\right)
\end{eqnarray}
where
$\overline{\braket{u^{LO}_l|H|u_l}} = \frac{1}{2}(\braket{u^{LO}_l|H|u_l} +\braket{u_l|H|u^{LO}_l})$

For example, for $H=-\nabla^2+V^{sim}$ and MT-part, we get for the
$3\times 3$ matrix
\begin{eqnarray}
\cH \equiv \left(
\begin{array}{ccc}
E_l & \frac{1}{2} & \frac{1}{2}(E_l+E^{LO}_l) \braket{u|u^{LO}} \\
\frac{1}{2} & E_l \braket{\dot{u}|\dot{u}} & \frac{1}{2}(E_l+E^{LO}_l) \braket{\dot{u}|u^{LO}} +\frac{1}{2}\braket{u_l|u_l^{LO}}\\
\frac{1}{2}(E_l+E^{LO}_l) \braket{u_l|u^{LO}_l}&  \frac{1}{2}(E_l+E^{LO}_l) \braket{\dot{u}_l|u^{LO}_l}+\frac{1}{2}\braket{u_l|u_l^{LO}}& E^{LO}_l
\end{array}
\right)
\end{eqnarray}
To get the component of the force, which takes the form
\begin{eqnarray}
\delta H_{ij} = \sum_{\vK\vK'}{A^0}^\dagger_{i,\vK'}\; i(\vK-\vK') \overline{\braket{\chi_{\vK'}|H|\chi_\vK}} {A^0}_{\vK,j}
\end{eqnarray}
we immediately get
\begin{eqnarray}
\delta H_{ij} =
i \left(
\begin{array}{ccc}
a_{lm,i}^*, & b_{lm,i}^* & c^*_{lm,i}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
\cA_{lm,j}\\
\cB_{lm,j}\\
\cC_{lm,j}
\end{array}
\right)
-i \left(
\begin{array}{ccc}
\cA_{lm,i}^*, & \cB_{lm,i}^* & \cC^*_{lm,i}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
a_{lm,j}\\
b_{lm,j}\\
c_{lm,j}
\end{array}
\right)
\end{eqnarray}
or
\begin{eqnarray}
\delta H_{ij} =
i \left(
\begin{array}{ccc}
a_{lm,i}^*, & b_{lm,i}^* & c^*_{lm,i}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
\cA_{lm,j}\\
\cB_{lm,j}\\
\cC_{lm,j}
\end{array}
\right)
-i \left[\left(
\begin{array}{ccc}
\cA_{lm,i}, & \cB_{lm,i} & \cC_{lm,i}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
a^*_{lm,j}\\
b^*_{lm,j}\\
c^*_{lm,j}
\end{array}
\right)
\right]^*
\end{eqnarray}
or
\begin{eqnarray}
\delta H_{ij} =
i \left(
\begin{array}{ccc}
a_{lm,i}^*, & b_{lm,i}^* & c^*_{lm,i}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
\cA_{lm,j}\\
\cB_{lm,j}\\
\cC_{lm,j}
\end{array}
\right)
-i \left[
\left(
\begin{array}{ccc}
a_{lm,j}^*, & b_{lm,j}^* & c^*_{lm,j}
\end{array}
\right)
\cH
\left(
\begin{array}{c}
\cA_{lm,i}\\
\cB_{lm,i}\\
\cC_{lm,i}
\end{array}
\right)
\right]^*
\end{eqnarray}
and finally
\begin{eqnarray}
\delta H_{ij} = i(\cH -\cH^\dagger)_{ij}
\end{eqnarray}
where
\begin{eqnarray}
\cH\equiv
\left(
\begin{array}{ccc}
E_l & \frac{1}{2} & \frac{1}{2}(E_l+E^{LO}_l) \braket{u|u^{LO}} \\
\frac{1}{2} & E_l \braket{\dot{u}|\dot{u}} & \frac{1}{2}(E_l+E^{LO}_l) \braket{\dot{u}|u^{LO}}+ \frac{1}{2}\braket{u_l|u_l^{LO}}\\
\frac{1}{2}(E_l+E^{LO}_l) \braket{u_l|u^{LO}_l}&  \frac{1}{2}(E_l+E^{LO}_l) \braket{\dot{u}_l|u^{LO}_l}+\frac{1}{2}\braket{u_l|u_l^{LO}}& E^{LO}_l
\end{array}
\right)
\end{eqnarray}

\subsection{How to get $a_{i,lm}$}

In dmft2, we need to compute coefficients $a_{i,lm}$ ($i$ is band
index) from $a_{lm\vK}$ and $a_{\nu}$. First, lets refresh the form of
the orbitals
\begin{eqnarray}
\chi_\vK(\vr) &=& \sum_{lm\mu'} \frac{4\pi i^l R_{MT}^2}{\sqrt{V}}e^{i(\vk+\vK)\vr_{\mu'}}Y^*_{lm}(R_{\mu'}(\vk+\vK))
 (\tilde{a}_{l\vK} u_l(r) + \tilde{b}_{l\vK}  \dot{u}_l(r))Y_{lm}(R_{\mu'}^{-1}\vr)\\
\chi_{\nu}(\vr) &=& \sum_{m'\mu'}\frac{4\pi i^l  R_{MT}^2}{\sqrt{V}}e^{i(\vk+\vK_\nu)\vr_{\mu'}}Y^*_{lm'}(R_{\mu'}(\vk+\vK_\nu))
 (a^{lo}_{\nu} u_l(r) + b^{lo}_{\nu}\dot{u}_l(r) + c^{lo}_{\nu} u^{LO}_l(r)) Y_{lm'}(R_{\mu'}^{-1}\vr)
\end{eqnarray}
The eigenvectors are large vectors of the form:
$(A_{\vK,i},A_{\nu,i})$. We want to write the KS-orbitals in the
MT-spheres as
\begin{eqnarray}
\psi_{i}(\vr) = \sum_{\mu,lm} (a_{i,lm}^\mu u_l(r) + b_{i,lm}^\mu  \dot{u}_l(r)+\sum_{j_{lo}}c_{i,lm,j_{lo}}^\mu u^{LO,j_{lo}}_l(r)) Y_{lm}(R_{\mu}^{-1}\vr)
\end{eqnarray}
Here $\nu=(i_{atom}^\nu,l^\nu,j_{lo}^\nu,\mu^\nu,m^\nu)$

We clearly have
\begin{eqnarray}
\left(
\begin{array}{c}
a_{i,lm}^\mu \\
b_{i,lm}^\mu \\
c_{i,lm,j_{lo}}^\mu
\end{array}
\right)=
\sum_\vK A_{i,\vK}
\frac{4\pi i^l R_{MT}^2}{\sqrt{V}}e^{i(\vk+\vK)\vr_{\mu}}Y^*_{lm}(R_{\mu}(\vk+\vK))
\left(
\begin{array}{c}
\tilde{a}_{l\vK}\\
\tilde{b}_{l\vK}\\
0
\end{array}
\right)
\nonumber\\
+
\sum_{\nu\rightarrow{\mu^\nu,m^\nu}} A_{i,\nu}
\frac{4\pi i^l R_{MT}^2}{\sqrt{V}}e^{i(\vk+\vK_\nu)\vr_{\mu}}Y^*_{lm}(R_{\mu}(\vk+\vK))
\left(
\begin{array}{c}
a^{lo}_\nu\\
b^{lo}_\nu\\
c^{lo,j_{lo}}_\nu
\end{array}
\right)\delta(l^\nu-l)\delta(i_{atom}^\nu-i_{atom})\delta(j_{lo}^\nu-j_{lo})
\end{eqnarray}

\end{document}