\documentclass[12pt,a4paper]{article}
\def\version{6.6}
\def\qe{{\sc Quantum ESPRESSO}}

\usepackage{html}

% BEWARE: don't revert from graphicx for epsfig, because latex2html
% doesn't handle epsfig commands !!!
\usepackage{graphicx}

\textwidth = 17cm
\textheight = 24cm
\topmargin =-1 cm
\oddsidemargin = 0 cm

\def\pwx{\texttt{pw.x}}
\def\phx{\texttt{ph.x}}
\def\configure{\texttt{configure}}
\def\PWscf{\texttt{PWscf}}
\def\PHonon{\texttt{PHonon}}
\def\make{\texttt{make}}

\begin{document} 
\author{}
\date{}

\def\qeImage{../../Doc/quantum_espresso}

\title{
  \includegraphics[width=5cm]{\qeImage} \\
  % title
  \Huge \PHonon\ User's Guide (v. \version)
  \\ \Large (only partially updated)
}

\maketitle

\tableofcontents

\section{Introduction}

This guide covers the usage of the \PHonon\ package, a
part of the \qe\ distribution. 
Further documentation, beyond what is provided 
in this guide, can be found in the directory
\texttt{PHonon/Doc/}, containing a copy of this guide.

{\em Important notice: due to the lack of time and of manpower, this
manual is only partially updated and may contain outdated information.}

This guide assumes that you know the contents of 
the general User's Guide for \qe\ and of the User's 
Guide for \PWscf. It also assumes that you have
already installed \qe\ (\PHonon\ is not a stand-alone
package: it requires \PWscf\ to be compiled and used).
If not, please locate the general User's Guide in directory 
\texttt{Doc/} two levels above the one containing this guide,
and the User's Guide for \PWscf\ in \texttt{PW/Doc/};
or consult the web site:\\
\texttt{http://www.quantum-espresso.org}.
It is also assumed that you know the physics behind \qe,
the methods it implements, and in particular the physics
and the methods of \PHonon.

% People who want to modify or contribute to \PHonon\ should read 
% the Developer Manual: \texttt{Doc/developer\_man.pdf}.

\PHonon\ has the following directory structure,
contained in a subdirectory \texttt{PHonon/}
of the main \qe\ tree:

\begin{tabular}{ll}
\texttt{Doc/} & : contains the user\_guide and input data description \\
\texttt{examples/} & : some running examples \\
\texttt{PH/}      & : source files for phonon calculations 
                   and analysis\\
\texttt{Gamma/}  & : source files for Gamma-only phonon calculation\\
\end{tabular}\\
{\em Important Notice:} since v.5.4, many modules and routines that were
common to all linear-response \qe\ codes are moved into the new 
\texttt{LR\_Modules} subdirectory of the main tree. Since v.6.0, the
\texttt{D3} code for anharmonic force constant calculations has been 
superseded by the \texttt{D3Q} coda, available on 
\texttt{http://www.qe-forge.org/gf/project/d3q/}.

The codes available in the \PHonon\ package can perform the following 
types of calculations:
\begin{itemize}
  \item phonon frequencies and eigenvectors at a generic wave vector,
  using Density-Functional Perturbation Theory;
  \item effective charges and dielectric tensors;
  \item electron-phonon interaction coefficients for metals;
  \item interatomic force constants in real space;
  \item Infrared and Raman (nonresonant) cross section.
\end{itemize}

Phonons can be plotted using the \texttt{PlotPhon} package.
Calculations of the vibrational free energy in the Quasi-Harmonic 
approximations can be performed using the \texttt{QHA}  package.
{\em Note:} since v.5.4, these two packages are separately distributed
and no longer bundled with \PHonon. Their latest version can be 
found in the tarballs of \PHonon\ v.5.3.

\section{People}
The \PHonon\ package
was originally developed by Stefano Baroni, Stefano
de Gironcoli, Andrea Dal Corso (SISSA), Paolo Giannozzi (Univ. Udine), 
and many others.
We quote in particular:
\begin{itemize}
  \item Michele Lazzeri (Univ.Paris VI) for the 2n+1 code and Raman 
  cross section calculation with 2nd-order response;
 \item Andrea Dal Corso for the implementation of Ultrasoft, PAW,
  noncolinear, spin-orbit extensions to \PHonon;
  \item Mitsuaki Kawamura (U.Tokyo) for implementation of the optimized
  tetrahedron method in phonon and electron-phonon calculations;
  \item Thibault Sohier, Matteo Calandra, Francesco Mauri, for 
	phonons in two-dimensional systems;
  \item Andrea Floris, Iurii Timrov, Burak Himmetoglu, Nicola Marzari, 
        Stefano de Gironcoli, and Matteo Cococcioni, for phonons using 
        Hubbard-corrected DFPT (DFPT+$U$).
\end{itemize}

The \texttt{PlotPhon} and \texttt{QHA} packages were contribute by the
late Prof. Eyvaz Isaev.

Other contributors include: Lorenzo Paulatto (Univ. Paris VI) for
PAW, 2n+1 code; William Parker (Argonne) for phonon terms in dielectric
tensor; Tobias Wassmann (Univ. Paris VI) for third-order derivatives of GGA 
potential. Weicheng Bao (Nanjing University) and Norge Cruz Hernandez
(Universidad de Sevilla) helped debugging the phonon code.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input ../../Doc/quote.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Installation}

\PHonon\ is a package tightly bound to \qe.
For instruction on how to download and compile \qe, please refer
to the general Users' Guide, available in file \texttt{Doc/user\_guide.pdf}
under the main \qe\ directory, or in web site
\texttt{http://www.quantum-espresso.org}.

Once \qe\ is correctly configured, \PHonon\ can be automatically
downloaded, unpacked and compiled by
just typing \texttt{make ph}, from the main \qe\ directory.

\subsection{Compilation}

Typing \texttt{make ph} from the root \qe\ directory, or \texttt{make} 
from the \PHonon\ directory, produces the following codes:
\begin{itemize}
  \item \texttt{PH/ph.x}: Calculates phonon frequencies and displacement patterns,
    dielectric tensors, effective charges (uses data produced by \pwx). 
  \item \texttt{PH/dynmat.x}: applies various kinds of Acoustic Sum Rule (ASR),
    calculates LO-TO splitting at ${\bf q} = 0$ in insulators, IR and Raman
    cross sections (if the coefficients have been properly calculated),
    from the dynamical matrix produced by \phx
  \item \texttt{PH/q2r.x}: calculates Interatomic Force Constants (IFC) in real space
    from dynamical matrices produced by \phx\ on a regular {\bf q}-grid 
 \item \texttt{PH/matdyn.x}: produces phonon frequencies at a generic wave vector
    using the IFC file calculated by \texttt{q2r.x}; may also calculate phonon DOS, 
    the electron-phonon coefficient $\lambda$, the function $\alpha^2F(\omega)$
\item \texttt{PH/lambda.x}: also calculates $\lambda$ and $\alpha^2F(\omega)$,
   plus $T_c$ for  superconductivity using the McMillan formula
\item \texttt{PH/alpha2f.x}: also calculates $\lambda$ and $\alpha^2F(\omega)$.
  It is used together with the optimized tetrahedron method
  (\verb|occupations="tetrahedra_opt"| in \pwx) and shifted {\it q}-grid
  (\verb|lshiftq=.true.| in \phx).
\item \texttt{PH/fqha.x}: a simple code to calculate vibrational entropy with
   the quasi-harmonic approximation
\item \texttt{PH/dvscf\_q2r.x}: performs inverse Fourier transformation of phonon
   potential from a regular {\bf q} grid to real space.
\item \texttt{Gamma/phcg.x}:
  a version of \phx\ that calculates phonons at ${\bf q} = 0$ using
  conjugate-gradient minimization of the density functional expanded to
  second-order. Only the $\Gamma$ (${\bf k} = 0$) point is used for
  Brillouin zone integration. It is faster and takes less memory than
  \phx, but does not support spin polarization, USPP and PAW.
\end{itemize}
Links to the main \qe\ \texttt{bin/} directory are automatically generated.
   
\section{Using \PHonon}

Phonon calculation is presently a two-step process.
First, you have to find the ground-state atomic and electronic configuration;
Second, you can calculate phonons using Density-Functional Perturbation Theory.
Further processing to calculate Interatomic Force Constants, to add macroscopic
electric field and impose Acoustic Sum Rules at ${\bf q}=0$ may be needed.
In the following, we will indicate by ${\bf q}$ the phonon wavevectors, 
while ${\bf k}$ will indicate Bloch vectors used for summing over the 
Brillouin Zone.

The main code \phx\ can be used whenever \PWscf\ can be used, 
with the exceptions of DFT+U, hybrid functionals, external electric fields,
constraints on magnetization, nonperiodic boundary conditions.
USPP and PAW are not implemented for higher-order response calculations.
See the header of file \texttt{PHonon/PH/phonon.f90} for a complete and
updated list of what \PHonon\ can and cannot do.

Since version 4.0 it is possible to safely stop execution of \phx\ code using
the same mechanism of the \pwx\ code, i.e. by creating a file 
\texttt{prefix.EXIT} in the working directory. Execution can be resumed by 
setting \texttt{recover=.true.} in the subsequent input data.
Moreover the execution can be (cleanly) stopped after a given time is elapsed,
using variable \texttt{max\_seconds}. See \texttt{example/Recover\_example/}.

\subsection{Single-{\bf q} calculation}

The phonon code \phx\ calculates normal modes at a given {\bf q}-vector, 
starting from data files produced by \pwx\ with a simple SCF calculation.
NOTE: the alternative procedure in which a band-structure calculation 
with \texttt{calculation='phonon'} was performed as an intermediate step is no
longer implemented since version 4.1. It is also no longer needed to
specify \texttt{lnscf=.true.} for ${\bf q}\ne 0$.

The output data files appear in the directory specified by the
variable {\tt outdir}, with names specified by the variable 
{\tt prefix}. After the output file(s) has been produced (do not remove 
any of the files, unless you know which are used and which are not), 
you can run \phx.
    
The first input line of \phx\ is a job identifier. At the second line the
namelist {\tt \&INPUTPH} starts. The meaning of the variables in the namelist
(most of them having a default value) is described in file 
\texttt{Doc/INPUT\_PH.*}. Variables \texttt{outdir} and \texttt{prefix} 
must be the same as in the input data of \pwx. Presently
you can specify \texttt{amass(i)} (a real variable) the atomic mass 
of atomic type $i$ or you can use the default one deduced from the
periodic table on the basis of the element name. If 
{\tt amass(i)} is not given as input of \phx, the one given as
input in \pwx\ is used. When this is {\tt 0} the default one is used.

After the namelist you must specify the {\bf q}-vector of the phonon mode,
in Cartesian coordinates and in units of $2\pi/a$.
    
Notice that the dynamical matrix calculated by \phx\ at ${\bf q}=0$ does not
contain the non-analytic term occurring in polar materials, i.e. there is no
LO-TO splitting in insulators. Moreover no Acoustic Sum Rule (ASR) is
applied. In order to have the complete dynamical matrix at ${\bf q}=0$ 
including the non-analytic terms, you need to calculate effective charges 
by specifying option \texttt{epsil=.true.} to \phx. This is however not 
possible (because not physical!) for metals (i.e. any system subject to 
a broadening).

At ${\bf q}=0$, use program \texttt{dynmat.x} to calculate the correct LO-TO 
splitting, IR cross sections, and to impose various forms of ASR. 
If \phx\ was instructed to calculate Raman coefficients, 
\texttt{dynmat.x} will also calculate Raman cross sections
for a typical experimental setup.
Input documentation in the header of \texttt{PHonon/PH/dynmat.f90}.

See Example 01 for a simple phonon calculations in Si, Example 06 for 
fully-relativistic calculations (LDA) on Pt, Example 07 for 
fully-relativistic GGA calculations.

\subsection{Calculation of interatomic force constants in real space}

First, dynamical matrices are calculated and saved for a suitable uniform 
grid of {\bf q}-vectors (only those in the Irreducible Brillouin Zone of the
crystal are needed). Although this can be done one {\bf q}-vector at the 
time, a
simpler procedure is to specify variable \texttt{ldisp=.true.} and to set 
variables \texttt{nq1}, \texttt{nq2}, \texttt{nq3} to some suitable 
Monkhorst-Pack grid, that will be automatically generated, centered at 
${\bf q}=0$. 
    
Second, code \texttt{q2r.x} reads the dynamical matrices produced in the
preceding step and Fourier-transform them, writing a file of Interatomic Force
Constants in real space, up to a distance that depends on the size of the grid
of {\bf q}-vectors. Input documentation in the header of \texttt{PHonon/PH/q2r.f90}.

Program \texttt{matdyn.x} may be used to produce phonon modes and
frequencies at any {\bf q} using the Interatomic Force Constants file as input.
Input documentation in the header of \texttt{PHonon/PH/matdyn.f90}.

See Example 02 for a complete calculation of phonon dispersions in AlAs.

\subsection{Calculation of electron-phonon interaction coefficients}

Since v.5.0, there are two ways of calculating electron-phonon
coefficients, distinguished according to the value of variable 
\texttt{electron\_phonon}. The following holds for the case 
\texttt{electron\_phonon=} {\tt'interpolated'} (see also Example 03).

The calculation of electron-phonon coefficients in metals is made difficult 
by the slow convergence of the sum at the Fermi energy. It is convenient to 
use a coarse {\bf k}-point grid to calculate phonons on a suitable 
wavevector grid;
a dense {\bf k}-point grid to calculate the sum at the Fermi energy. 
The calculation
proceeds in this way:
\begin{enumerate}
\item a scf calculation for the dense ${\bf k}$-point grid (or a scf calculation 
followed by a non-scf one on the dense ${\bf k}$-point grid); specify 
option \texttt{la2f=.true.} to \pwx\ in order to save a file with 
the eigenvalues on the dense {\bf k}-point grid. The latter MUST contain 
all ${\bf k}$ and ${\bf k}+{\bf q}$ grid points used in the subsequent 
electron-phonon 
calculation. All grids MUST be unshifted, i.e. include ${\bf k}=0$.
\item a normal scf + phonon dispersion calculation on the coarse {\bf k}-point
grid, specifying option \texttt{electron\_phonon='interpolated'}, and 
the file name where
the self-consistent first-order variation of the potential is to be 
stored: variable \texttt{fildvscf}).
The electron-phonon coefficients are calculated using several
values of Gaussian broadening (see \texttt{PHonon/PH/elphon.f90}) 
because this quickly
shows whether results are converged or not with respect to the 
{\bf k}-point grid and Gaussian broadening.
\item Finally, you can use \texttt{matdyn.x} and \texttt{lambda.x} 
(input documentation in the header of \texttt{PHonon/PH/lambda.f90})
to get the $\alpha^2F(\omega)$ function, the electron-phonon coefficient
$\lambda$, and an estimate of the critical temperature $T_c$.
\end{enumerate}

See the appendix for the relevant formulae.
{\bf Important notice}: the $q\rightarrow 0$ limit of the contribution 
to the electron-phonon coefficient diverges for optical modes! please 
be very careful, consult the relevant literature.

\subsection{DFPT with the tetrahedron method}

In order to use the tetrahedron method for phonon calculations,
you should run \pwx\ and \phx\ as follows:
\begin{enumerate}
  \item Run \pwx\ with \verb|occupation = "tetrahedra_opt"| and \verb|K_POINT automatic|.
  \item Run \phx.
\end{enumerate}

There is an example in \verb|PHonon/example/tetra_example/|.

\subsection{Calculation of electron-phonon interaction coefficients with the tetrahedron method}

When you perform a calculation of electron-phonon interaction coefficients 
with the tetrahedron method,
you have to use an offset $q$-point grid in order to avoid a singularity 
at $q=\Gamma$; you can perform this calculation as follows:

\begin{enumerate}
  \item Run \pwx\ with \verb|occupation = "tetrahedra_opt"| and \verb|K_POINT automatic|.
  \item Run \phx\ with \verb|lshift_q = .true.| and \verb|electron_phonon = ""| (or unset it)
    to generate the dynamical matrix and
    the deformation potential (in \verb|_ph*/{prefix}_q*/|) of each $q$.
  \item Run \phx\ with \verb|electron_phonon = "lambda_tetra"|.
    You should use a denser $k$ grid by setting \verb|nk1|, \verb|nk2|, and \verb|nk3|.
    Then \verb|lambda*.dat| are generated; they contain $\lambda_{q \nu}$.
  \item Run \verb|alpha2f.x| with an input file as follows:
\begin{verbatim}
&INPUTPH
! The same as that for the electron-phonon calculation with ph.x
 :
/
&INPUTA2F
  nfreq = Number of frequency-points for a2F(omega), 
/
\end{verbatim}
Then $\lambda$, and $\omega_{\ln}$ are computed and they are printed to the standard output.
$\alpha^2F(\omega)$ and (partial) phonon-DOS are also computed;
they are printed to a file \textit{prefix}\verb|.a2F.dat|.
\end{enumerate}

There is an example in \verb|PHonon/example/tetra_example/|.

\subsection{Phonons for two-dimensional crystals}

The extension of DFPT to two dimensional crystals,
in particular gated two-dimensional heterostructure,
s described in the following paper:

T. Sohier, M. Calandra, and F. Mauri, Phys. Rev. B {\bf 96}, 075448 (2017),
https://doi.org/10.1103/PhysRevB.96.075448

See example  \verb|PHonon/example/example17/|.

\subsection{Phonons from DFPT+$U$}

The extension of DFPT to inlcude Hubbard $U$ correction is described
in the following papers:

A.~Floris, S.~de~Gironcoli, E.~K.~U.~Gross, M.~Cococcioni, Phys. Rev. B {\bf 84}, 
161102(R), (2011);

A.~Floris, I.~Timrov, B.~Himmetoglu, N.~Marzari, S.~de~Gironcoli, and M.~Cococcioni, 
Phys. Rev. B {\bf 101}, 064305 (2020).

See example  \verb|PHonon/example/example18/|.

\subsection{Fourier interpolation of phonon potential}

The potential perturbation caused by the displacement of a single atom is
spatially localized. Hence, the phonon potential can be interpolated from
$q$ points on a coarse grid to other $q$ points using Fourier interpolation.
To use this functionality, first, one shoud run a \phx\ calculation for $q$
points on a regular coarse grid.
Then, a \texttt{dvscf\_q2r.x} run performs an inverse Fourier
transformation of the phonon potentials from a $q$ grid to a real-space
supercell. Finally, by specifying \texttt{ldvscf\_interpolation=.true.} in
\phx, the phonon potentials are Fourier transformed to given $q$ points.

For insulators, the nonanalytic long-ranged dipole part of the potential needs
to be subtracted and added before and after the interpolation, respectively.
This treatment is activated by specifying \texttt{do\_long\_range=.true.} in the
input files of \texttt{dvscf\_q2r.x} and \phx.

Due to numerical inaccuracies, the calculated Born effective charges may not
add up to zero, violating the charge neutrality condition. This error may lead
to nonphysical polar divergence of the phonon potential for $q$ points close
to $\Gamma$, even in IR-inactive materials. To avoid this problem, one can
specify \texttt{do\_charge\_neutral=.true.} in the input files of
\texttt{dvscf\_q2r.x} and \phx. Then, the phonon potentials and the Born
effective charges are renormalized by enforcing the charge neutrality condition,
following the scheme of S.~ Ponce et al, J. Chem. Phys. (2015).

The Fourier interpolation of phonon potential is proposed and described in the
following papers:

A.~Eiguren and C.~Ambrosch-Draxl, Phys. Rev. B {\bf 78}, 045124 (2008);

S.~ Ponce et al, J. Chem. Phys. {\bf 143}, 102813 (2015);

X.~Gonze et al, Comput. Phys. Commun., {\bf 248}, 107042 (2020).

\subsection{Calculation of phonon-renormalization of electron bands}
The phonon-induced renormalization of electron bands can be computed using \PHonon.
After SCF, PHONON, and NSCF calculations, one can run \phx\ with the
\texttt{electron\_phonon=`ahc'} option, which generates binary files containing
quantities required for the calculation of electron self-energy.
Then, a \texttt{postahc.x} run reads these binary files and compute the
phonon-induced electron self-energy at a given temperature.

For more details, see the \verb|PHonon/Doc/dfpt_self_energy.pdf| file.

Also, there is an example in \verb|PHonon/example/example19/|.

Implementation of this functionality in \qe\ is described in the following
paper:

J.-M.~Lihm and C.-H.~Park, Phys. Rev. B {\bf 101}, 121102 (2020).


\section{Parallelism}
\label{Sec:para}

We refer to the corresponding section of the \PWscf\ guide for
an explanation of how parallelism works. 

\phx\ may take advantage of MPI parallelization on images, plane waves (PW) 
and on {\bf k}-points (``pools''). Currently all other MPI and explicit 
OpenMP parallelizations have very limited to nonexistent implementation.
\texttt{phcg.x} implements only PW parallelization.
All other codes may be launched in parallel, but will execute 
on a single processor.

In  ``image'' parallelization, processors can be divided into different 
``images", corresponding to one (or more than one) ``irrep'' or {\bf q}
vectors. Images are loosely coupled: processors communicate
between different images only once in a while, so image parallelization
is suitable for cheap communication hardware (e.g. Gigabit Ethernet).
Image parallelization is activated by specifying the option 
\texttt{-nimage N} to \phx. Inside an image, PW and {\bf k}-point 
parallelization can be performed: for instance,
\begin{verbatim}
   mpirun -np 64 ph.x -ni 8 -nk 2 ...
\end{verbatim}
will run $8$ images on $8$ processors each, subdivided into $2$ pools 
of $4$ processors for {\bf k}-point parallelization. In order 
to run the \phx\ code with these flags the \pwx\ run has to be run with:
\begin{verbatim}
   mpirun -np 8 pw.x -nk 2 ...
\end{verbatim}
without any {\tt -nimage} flag. 
After the phonon calculation with images the dynmical matrices of 
{\bf q}-vectors calculated in different images are not present in the
working directory. To obtain them you need to run 
\phx\ again with:
\begin{verbatim}
   mpirun -np 8 ph.x -nk 2 ...
\end{verbatim}
and the {\tt recover=.true.} flag. This scheme is quite automatic and
does not require any additional work by the user, but it wastes some 
CPU time because all images stops when the image that requires the 
largest amount of time finishes the calculation. Load balancing 
between images is still at
an experimental stage. You can look into the routine {\tt image\_q\_irr} 
inside {\tt PHonon/PH/check\_initial\_status} to see the present
algorithm for work distribution and modify it if you think that
you can improve the load balancing.

A different paradigm is the usage of the GRID concept, instead of MPI,
to achieve parallelization over irreps and  {\bf q} vectors.
Complete phonon dispersion calculation can be quite long and
expensive, but it can be split into a number of semi-independent
calculations, using options \texttt{start\_q}, \texttt{last\_q},
\texttt{start\_irr}, \texttt{last\_irr}. An example on how to
distribute the calculations and collect the results can be found
in \texttt{examples/GRID\_example}. Reference:\\
{\it Calculation of Phonon Dispersions on the GRID using Quantum
     ESPRESSO},
     R. di Meo, A. Dal Corso, P. Giannozzi, and S. Cozzini, in
     {\it Chemistry and Material Science Applications on Grid Infrastructures},
     editors: S. Cozzini, A. Lagan\`a, ICTP Lecture Notes Series,
     Vol. 24, pp.165-183 (2009).


\section{Troubleshooting}

\paragraph{ph.x stops with {\em error reading file}}
The data file produced by \pwx\ is bad or incomplete or produced
by an incompatible version of the code.

\paragraph{ph.x mumbles something like {\em cannot recover} or {\em error
  reading recover file}} 
You have a bad restart file from a preceding failed execution.
Remove all files \texttt{recover*} in \texttt{outdir}.

\paragraph{ph.x says {\em occupation numbers probably wrong} and
 continues} You have a
metallic or spin-polarized system but occupations are not set to 
\texttt{`smearing'}.

\paragraph{ph.x does not yield acoustic modes with zero frequency at 
${\bf q}=0$}
This may not be an error: the Acoustic Sum Rule (ASR) is never exactly
verified, because the system is never exactly translationally
invariant as it should be.  The calculated frequency of the acoustic
mode is typically less than 10 cm$^{-1}$, but in some cases it may be
much higher, up to 100 cm$^{-1}$. The ultimate test is to diagonalize
the dynamical matrix with program \texttt{dynmat.x}, imposing the ASR. If you
obtain an acoustic mode with a much smaller $\omega$ (let us say 
$< 1 \mbox{cm}^{-1}$ ) 
with all other modes virtually unchanged, you can trust your results.

``The problem is [...] in the fact that the XC 
energy is computed in real space on a discrete grid and hence the
total energy is invariant (...) only for translation in the FFT
grid. Increasing the charge density cutoff increases the grid density
thus making the integral more exact thus reducing the problem,
unfortunately rather slowly...This problem is usually more severe for
GGA  than with LDA because the GGA functionals have functional forms
that vary more strongly with the position; particularly so for
isolated molecules or system with significant portions of ``vacuum''
because in the exponential tail of the charge density a) the finite
cutoff  (hence there is an effect due to cutoff) induces oscillations
in rho and b) the reduced gradient is diverging.''(info by Stefano de
Gironcoli, June 2008) 

\paragraph{ph.x yields really lousy phonons, with bad or ``negative''
  frequencies or wrong symmetries or gross ASR violations} 
Possible reasons:
\begin{itemize}
\item if this happens only for acoustic modes at ${\bf q}=0$ that should
  have $\omega=0$: Acoustic Sum Rule violation, see the item before
  this one.
\item wrong data file read.
\item wrong atomic masses given in input will yield wrong frequencies
  (but the content of file fildyn should be valid, since the force
  constants, not the dynamical matrix, are written to file). 
\item convergence threshold for either SCF (\texttt{conv\_thr}) or phonon
  calculation (\texttt{tr2\_ph}) too large: try to reduce them. 
\item maybe your system does have negative or strange phonon
  frequencies, with the approximations you used. A negative frequency
  signals a mechanical instability of the chosen structure. Check that
  the structure is reasonable, and check the following parameters: 
\begin{itemize}
\item The cutoff for wavefunctions, \texttt{ecutwfc}
\item For USPP and PAW: the cutoff for the charge density, \texttt{ecutrho}
\item The {\bf k}-point grid, especially for metallic systems.
\end{itemize}
\item For metallic systems: it has been observed that the convergence with
  respect to the k-point grid and smearing is very slow in presence of
  semicore states, and for phonon wave-vectors that are not commensurate i
  with the k-point grid (that is, ${\bf q}\ne {\bf k}_i-{\bf k}_j$)
\end{itemize}
Note that ``negative'' frequencies are actually imaginary: the negative
sign flags eigenvalues of the dynamical matrix for which $\omega^2 <
0$. 

\paragraph{{\em Wrong degeneracy} error in star\_q}
Verify the {\bf q}-vector for which you are calculating phonons. In order to
check whether a symmetry operation belongs to the small group of ${\bf q}$,
the code compares ${\bf q}$ and the rotated ${\bf q}$, with an acceptance tolerance of  
$10^{-5}$ (set in routine \texttt{PW/src/eqvect.f90}). You may run into trouble if
your {\bf q}-vector differs from a high-symmetry point by an amount in that
order of magnitude.

\paragraph{Mysterious symmetry-related errors} 
Symmetry-related errors like {\em symmetry operation is non orthogonal}, 
or {\em Wrong representation}, or {\em Wrong degeneracy}, are almost 
invariably a consequence of atomic positions that are close to, 
but not sufficiently close to, symmetry positions. If such errors occur,
set the Bravais lattice using the correct \texttt{ibrav} value (i.e. do
not use \texttt{ibrav=0}), use Wyckoff positions if known. This must be
done in the self-consistent calculation.

\appendix
\section{Appendix: Electron-phonon coefficients}

\def\r{{\bf r}}
\def\d{{\bf d}}
\def\k{{\bf k}}
\def\q{{\bf q}}
\def\G{{\bf G}}
\def\R{{\bf R}}

\noindent The electron-phonon coefficients $g$
are defined as
\begin{equation}
g_{\q\nu}(\k,i,j) =\left({\hbar\over 2M\omega_{\q\nu}}\right)^{1/2}
\langle\psi_{i,\k}| {dV_{SCF}\over d {\hat u}_{\q\nu} }\cdot
                   \hat \epsilon_{\q\nu}|\psi_{j,\k+\q}\rangle.
\end{equation}
The phonon linewidth $\gamma_{\q\nu}$ is defined by
\begin{equation}
\gamma_{\q\nu} = 2\pi\omega_{\q\nu} \sum_{ij}
                \int {d^3k\over \Omega_{BZ}}  |g_{\q\nu}(\k,i,j)|^2
                    \delta(e_{\q,i} - e_F)  \delta(e_{\k+\q,j} - e_F), 
\end{equation}
while the electron-phonon coupling constant $\lambda_{\q\nu}$ for
mode $\nu$ at wavevector $\q$ is defined as
\begin{equation}
\lambda_{\q\nu} ={\gamma_{\q\nu} \over \pi\hbar N(e_F)\omega^2_{\q\nu}}
\end{equation}
where $N(e_F)$ is the DOS at the Fermi level.
The spectral function is defined as
\begin{equation}
\alpha^2F(\omega) = {1\over 2\pi N(e_F)}\sum_{\q\nu} 
                    \delta(\omega-\omega_{\q\nu})
                    {\gamma_{\q\nu}\over\hbar\omega_{\q\nu}}.
\end{equation}
The electron-phonon mass enhancement parameter $\lambda$
can also be defined as the first reciprocal momentum of 
the spectral function:
\begin{equation}
\lambda = \sum_{\q\nu} \lambda_{\q\nu} = 
2 \int {\alpha^2F(\omega) \over \omega} d\omega.
\end{equation}

Note that a factor $M^{-1/2}$ is hidden in the definition of
normal modes as used in the code.

McMillan:
\begin{equation}
T_c = {\Theta_D \over 1.45} \mbox{exp} \left [ 
         {-1.04(1+\lambda)\over \lambda(1-0.62\mu^*)-\mu^*}\right ]
\end{equation}
or (better?)
\begin{equation}
T_c = {\omega_{log}\over 1.2} \mbox{exp} \left [ 
         {-1.04(1+\lambda)\over \lambda(1-0.62\mu^*)-\mu^*}\right ]
\end{equation}
where
\begin{equation}
\omega_{log} = \mbox{exp} \left [ {2\over\lambda} \int {d\omega\over\omega}
                                  \alpha^2F(\omega) \mbox{log}\omega \right ]
\end{equation}


\end{document}
