  We give a detailed presentation of the theory and numerical implementation of
an expression for the adiabatic energy flux in extended systems, derived from
density-functional theory. This expression can be used to estimate the heat
conductivity from equilibrium ab initio molecular dynamics, using the
Green-Kubo linear response theory of transport coefficients. Our expression is
implemented in an open-source component of the QE suite of computer codes for
quantum mechanical materials modelling, which is being made publicly available.
