First-principles theory of spatial dispersion: Dynamical quadrupoles and flexoelectricity

Density-functional perturbation theory (DFPT) is nowadays the method of choice for the accurate computation of linear and non-linear response properties of materials from first principles. A notable advantage of DFPT over alternative approaches is the possibility of treating incommensurate lattice distortions with an arbitrary wavevector, ${\bf q}$, at essentially the same computational cost as the lattice-periodic case. Here we show that ${\bf q}$ can be formally treated as a perturbation parameter, and used in conjunction with established results of perturbation theory (e.g. the"2n+1"theorem) to perform a long-wave expansion of an arbitrary response function in powers of the wavevector components. This provides a powerful, general framework to accessing a wide range of spatial dispersion effects that were formerly difficult to calculate by means of first-principles electronic-structure methods. In particular, the physical response to the spatial gradient of any external field can now be calculated at negligible cost, by using the response functions to $\mathit{uniform}$ perturbations (electric, magnetic or strain fields) as the only input. We demonstrate our method by calculating the flexoelectric and dynamical quadrupole tensors of selected crystalline insulators and model systems.


I. INTRODUCTION
Spatial dispersion refers to a dependence of a material property (e.g. permittivity, conductivity or phonon frequency) on the wavevector q at which it is probed, or equivalently on the gradients of the perturbation and/or the response in real space. Its origin can be traced back to the nonlocality of the microscopic interactions in condensed-matter systems, where the response to an external field (electromagnetic field or atomic displacement) typically occurs over a neighborhood of the point where the field is applied. While in general such effects are weak and can often be neglected in macroscopic theories, there are several instances where their physical consequences are important, both regarding their fundamental interest and their potential towards practical applications. Indeed, with the ongoing interest in nanoscale phenomena, researchers are increasingly often facing situations where the relevant scalar, vector or tensor quantities (e.g. polarization or strain) display large variations on a very small length scale; this is precisely the regime at which gradient effects can become strong.
Historically, spatial dispersion has been most studied in the context of the optical response. The firstorder wavevector dependence of the dielectric susceptibility tensor, for example, is responsible for the natural optical activity, [1,2] which is the property of some crystals of rotating the plane of polarization of the transmitted light. Manifestations of spatial dispersion are, however, ubiquitous; they can involve magnetism (the magnetoelectric effect can be regarded as the first-order dispersion of the conductivity [1]) or elastic degrees of freedom as well (the counterpart of optical gyrotropy in phononics is known as acoustical activity [3]). In the latter context, flexoelectricity [4] is arguably the most notable example, as it has been intensely explored both experimentally and theoretically in the past ten years or so. [5,6] It describes the polarization response to the gradient of the applied strain, and therefore it can be understood as the spatial dispersion of the piezoelectric tensor. Being it a universal property of all insulators regardless of crystal symmetry, it provides a tantalizing route to novel electromechanical device concepts, [7] and opens the way to many other applications in energy and information technology. [8,9] The long-wavelength regime also occupies a central place in the theory of lattice dynamics in insulators. Indeed, in the q → 0 limit, phonons in insulating crystals are associated with macroscopic electric fields that are due to the long-range electrostatic interactions between atoms. [10] Identifying and correctly treating such longrange contributions is crucial for a meaningful calculation of the interatomic force constants (IFC) from first principles. [11,12] The former are typically written as electrostatic dipole-dipole terms, which are responsible for the well-known frequency splitting between longitudinal (LO) and transverse (TO) optical phonon branches. It is important to note, however, that the dipole-dipole term only captures the leading contribution to the longrange IFCs. (Dipole-dipole terms decay as 1/d 3 as a function of the interatomic distance, d.) Higher orders (1/d 4 and faster) are always present, but are systematically neglected as their physical consequences are much more subtle.
The next lowest order, for example, involves dipolequadrupole interactions and is responsible for a nonanalytic behavior [13] of the force-constant matrix at O(q 1 ); this translates into a 1/d 4 decay in real space of the corresponding contribution to the IFCs. A quadrupolar response to an atomic displacement requires a brokeninversion symmetry environment to be active, and is always (although not exclusively) present in piezoelectric crystals. Interestingly, in his seminal 1972 paper, R.M. Martin predicted [14] that the electronic contribution to the piezoelectric tensor can be written as a sublattice sum of the "dynamical quadrupoles", so we expect these couplings to be important in compounds where electromechanical effects are strong. However, viable methods to compute the quadrupole tensor have been lacking to date; this quantity can be regarded as the first-order spatial dispersion of the Born effective charge tensor, and is therefore characterized by analogous technical challenges as the calculation of the flexoelectric tensor.
Developing a systematic, quantitative theory of such effects would be very desirable to improve their fundamental understanding and support the ongoing experimental efforts. Achieving this goal, however, presents considerable technical difficulties from the point of view of first-principles electronic-structure theory, due to the inherent breakdown of translational periodicity that a spatial gradient entails. In the case of flexoelectricity, [15] for example, several routes have been explored to cope with this issue. Initially, the flexoelectric coefficients were written as real-space moments of the response (either the electronic charge density or the atomic forces) to the displacement of an isolated atom [16,17]. Later, the realspace sums were recast as small-q expansions of the response to a monochromatic displacement pattern at a given wavevector q. [13,18,19] Other subtleties were addressed as well, such as the definition and implementation of the current-density response, [20] which eventually allowed for the calculation of the bulk flexoelectric tensor within a perturbative framework based on a primitive cell of the crystal. [20] While the strategy of Ref. 20 could be, in principle, generalized to other physical properties, it still presents an important drawback. Several linear-response calculations need to be performed at different q-points in a vicinity of the Brillouin zone center, and the secondorder coefficients (corresponding to the flexoelectric tensor components) are then extracted via a numerical fit. This introduces a significant computational overhead (to repeat the same calculations at several values of q), and is a potential source of numerical inaccuracies related to the fit. It would be much cheaper from the computational point of view, and convenient from the point of view of the end user, to directly calculate the desired dispersion coefficients as part of the intrinsic linear-response capabilities of the code. To achieve this goal, however, one needs first to establish a general formalism to describing the long-wavelength limit within the context of DFPT.
Here we provide a comprehensive solution to the above issues by first rewriting the second-order energy at finite q as an unconstrained minimization problem of a variational functional of the first-order wavefunctions. Next, we show that the parametric q-dependence of the secondorder energy can be regarded as a small perturbation of the q = 0 functional; hence, one can apply the standard tools of DFPT to perform an analytic long-wavelength expansion of an arbitrary response property of the crystal in powers of q. Remarkably this strategy, in combination with the "2n + 1" theorem, enables writing ex-plicit formulas for first-order dispersion coefficients that only need the uniform field wavefunction response as an input. Thus, one can take advantage of the already implemented linear-response tools to calculate a wide range of new materials properties, such as flexoelectricity and the natural optical activity, at essentially no cost -and without the need for explicitly implementing or calculating the wavefunction response to a gradient of the external field. Finally, we demonstrate our formalism by implementing the formulas for the clamped-ion flexoelectric coefficients and the dynamical quadrupole tensor (the higher-order multipolar counterpart of the Born dynamical charge tensor). The flexoelectric coefficients calculated for several materials are consistent with previously published results. [19,20] The relationship, established by R. M. Martin in his seminal paper, [14] between the sublattice sum of the quadrupole moments and the clamped-ion piezoelectric coefficients is numerically verified to a high degree of accuracy. Both quantities converge with respect to plane-wave cutoff and k-mesh density comparably fast to "standard" linear-response properties (e.g. the macroscopic dielectric tensor), and can now be obtained in a tiny fraction of the computational burden that was formerly needed.
This work is organized as follows. In Section II we present our method, based on the long-wavelength expansion of DFPT, and provide general formulas for dispersion properties at the lowest orders in q. In Section III we discuss the finite-q generalization of the electric-field response, which we shall use to define and compute the polarization response in the long-wavelength limit. In Sections IV and V we demonstrate our long-wave approach by deriving and calculating the dynamical quadrupole and clamped-ion flexoelectric tensors in selected materials and model systems. Finally, in Section VI we present our conclusions and outlook, e.g. regarding future generalizations of our method to other dispersion properties. The Appendices provide additional analytic support to the formulas reported in the main text.

II. LONG-WAVE PERTURBATION THEORY
A. Density-functional perturbation theory Here we shall briefly introduce the basic principles of DFPT, both for completeness and in order to support the formal developments of the later sections. Consider an external perturbation to the electronic ground state, which we describe by assuming a parametric dependence of the Hamiltonian operator on a small parameter λ, (1) The linear response of the wavefunctions to the perturbation can be recast in terms of a Sternheimer equation, Eq. (7) and Eq. (9) manifestly coincide if the first-order wavefunctions satisfy the Sternheimer equation, Eq. (2); however, the latter expression has the virtue of being stationary with respect to variations of |ψ (1) m , and such a characteristic will have a key importance in the context of this work, as we shall see shortly.

B. Unconstrained variational formulation
First, recall the definition of the valence-and conduction-band projectors (we have already seen the latter in the previous subsection), We shall now use these definitions to write the linear response problem as an unconstrained variational minimum of the following functional Note the explicit introduction of the band projectors in the first and second line, and implicitly in the third line via a redefinition of the first-order electron density, The parameter a is a constant with the dimension of an energy, whose role is to ensure that the matrix element in the first line of Eq. (12), quadratic in the first-order wavefunctions, is defined positive, and hence that the functional is stable. To see this, consider the mean value of the operator in the round brackets on a valence (v) or conduction (c) state, As n belongs to the valence band, the matrix element on the conduction state is always positive independent of a.
Regarding the valence state, for the value ǫ v + a − ǫ n to be guaranteed to be positive it suffices to set a to any positive energy that is larger than the total valence bandwidth. The insertion of a conduction band projector,Q, in both the charge density and in the second line of Eq. (12) serves to enforcing the parallel-transport gauge, i.e. that at the variational minimum the solutions ψ (1) be strictly orthogonal to the valence manifold. It is easy to see how this works: Thanks to the projectorsQ, the addition of a small valence component to the trial solution ψ (1) leaves the energy unaltered except for the (quadratic) matrix element in the first line of Eq. (12). The latter, in turn, always provides a positive contribution to the energy, whose magnitude depends on the parameter a. Therefore, a has no influence other than preventing the first-order wavefunctions from acquiring arbitrarily large components on the valence manifold, which would lead to runaway solutions.
Following these considerations, it is not difficult to get convinced that the variational solution of this unconstrained energy functional is unique, and corresponds precisely to the constrained minimization procedure described by Gonze [22]. It also leads, by differentiating Eq. (12) with respect to ψ (1) m |, to the form of the Sternheimer equation proposed by Baroni and coworkers [12], Such a form clearly enforcesP |ψ (1) m = 0, and reduces to Eq. (2) once the left-hand side is projected on the conduction manifold.

C. Factorization of the phase
To appreciate the practical advantages of the unconstrained formulation of the previous subsection, we shall now apply it to a monochromatic perturbation in a periodic crystal. This can be expressed as a phase times a cell-periodic part, As customary, we shall work with the cell-periodic part of the Bloch wavefunctions by writing ψ mk (r) = e ik·r u mk (r), which allows one to reabsorb the incommensurate phase e iq·r by performing appropriate shifts of the states and operators in momentum space. For the sake of generality, we shall consider the mixed derivative with respect to two distinct perturbations, λ 1 and λ 2 , whose physical nature will be specified later in this manuscript. (The functional, strictly speaking, is variational only for λ 1 = λ 2 ; yet, even in the mixed case it preserves the stationary character with respect to small variations in the first-order wavefunctions.) We shall implicitly assume that the crystal under study is a timereversal (TR) symmetric insulator. (A generalization of the formulas to TR-broken materials, while not difficult, would have unnecessarily complicated the notation.) The second-order energy can be written then as where the quantity in the first line is given by s = 2 is the spin multiplicity and we have used the following shorthand notation for the Brillouin-zone averages, The last (third) line in Eq. (18) is, as usual, the nonvariational contribution to the second-order energy, while the second line contains the self-consistent energy that depends quadratically on the first-order electron densities [23] n λ q (r) = 2s Note that we have introduced new symbols for the phasecorrected Hxc kernel (we shall specialize to the local density approximation, LDA), the operators in momentum space, and the cell-periodic part of the charge-density response n λ q (r) = e −iq·r n λ (r).
From these formulas, one can now appreciate the most remarkable property of the unconstrained functional: Unlike the original version, where the orthonormality constraint is taken by calculating the scalar products with ground-state valence orbitals at k + q, the present version is written in a manifestly gauge-invariant form, i.e. only operators explicitly depend on q. This is a key advantage when developing a perturbative theory in q, as the derivatives of the operators in momentum space are well-defined mathematical objects, and do not suffer from the phase indeterminacy of the Bloch states. mk,q , which depends parametrically on q. We can then take advantage of the established mathematical tools of perturbation theory to expand E λ * 1 λ2 q in powers of q around q = 0, which has the physical interpretation of a long-wave expansion. This can be pushed, in principle, to any order in q. In particular, in virtue of the "2n + 1" theorem, [24] the knowledge of the q-derivatives of the wavefunctions up to order n is sufficient to calculate response properties up to O(q 2n+1 ). As we shall see in the following, this is especially useful at the lowest orders: The computational tools to calculate the n = 0 (and, sometimes, n = 1) response functions are already available in many public first-principles packages, which implies that many response properties can be, in principle, extracted without even implementing a new response function in the code. (In the following, we shall illustrate this strategy at a formal level, without specifying the physical nature of the perturbations; practical examples will be provided in Sections IV and V.) At first order in q the "2n + 1" theorem reduces to the Hellmann-Feynman theorem and can be summarized as follows, which states that the q-gradients of the response functions |u λ mk,q are not needed to access the q-gradient of the stationary second-order functional. (We specialize our formulas to a neighborhood of q = 0, as such a limit is directly relevant for the macroscopic response properties of the crystal.) In particular, we have where we have used a short-hand notation for the qderivative of the Hartree and exchange-correlation kernel, and the band-resolved contribution reads as Here we have introduced new symbols for the qderivatives of the external perturbation, and for the k-derivatives of the ground-state operators (Hamiltonian or band projectors), e.g., Also, we have removed the q subscript from those quantities (either first-order wave functions, densities or perturbing operators) that are intended to be calculated at q = 0, e.g., Note that we have used the symbolĤ in the second line of Eq. (24) to indicate that the self-consistent (SCF) Hartree and exchange-correlation potential must be included in the first-order Hamiltonian at q = 0. The SCF part ofĤ λ k comes from the Hartree and exchangecorrelation term in Eq. (18) via the partial derivative of the first-order density with respect to q γ , Crucially, the SCF potential needs to be explicitly calculated only at the level of the O(q 0 ) perturbation; the q-gradient of the perturbation, in the third line, only concerns the external potential part,Ĥ. (This is, again, a consequence of the "2n + 1" theorem.) Note also that ∂ γPk only has cross-gap matrix elements, thus it doesn't contribute to the first line of Eq. (24), and that we could omitQ k from the matrix elements in the third line, as it always appeared next to a conduction-band state. The above formulas enable the calculation of the "d/dq γ " response with computational workload that is comparable to the uniform (q = 0) case. Indeed, only the q = 0 first-order wavefunctions are needed as ingredients; the additional burden consists in the implementation of the new operators that appear in Eqs. (22) and (24), but once this is done the evaluation of the corresponding matrix elements proceeds at essentially no cost. Most of these "new" operators are, in fact, well known in the context of band theory, and are standard in most DFPT implementations (e.g. the velocity operator, ∂ γĤ (0) k , or the derivatives of the band projectors). For example, the second line of Eq. (24) might look unusual at first sight, but it can be made more explicit by observing that ∂ γQk = −∂ γPk , and that where |∂ γ u (0) nk are the "covariant derivatives" of the ground-state wavefunctions (also known as "d/dk γ " response functions), and are orthogonal to the valence manifold. Then one immediately obtains which is now a rather familiar expression in the context of DFPT.
The truly new pieces in Eqs. (22) and (24) are the qderivatives of the monochromatic perturbation, and the q-derivative of the SCF kernel. We shall defer the discussion of the former, which depends on the specific perturbation, to Sections IV and V. The latter is particularly simple to evaluate in the framework of the local-density approximation (LDA), where the XC part does not contribute (it is independent of q). As we are only left with electrostatic effects, it is most convenient to work in reciprocal space, where the Coulomb (Hartree) kernel is local, (G and G ′ stand for reciprocal-lattice vectors, and δ is a Kronecker symbol.) The q-gradient (at q = 0) of the above expression is easily computed, The G = 0 term must be, of course, excluded; this corresponds to adopting short-circuit electrical boundary conditions, which is the correct choice for computing materials properties that have a tensorial nature. (A formal justification of this point was provided in Ref. 22 for the uniform electric field problem, and in Ref. 13 for the flexoelectric tensor.)

E. Higher orders
As we said, the "2n + 1" theorem, in principle, provides access to the long-wave expansion terms of a given crystal response to any order in q. In general, the analytic formulas for higher orders in q can become rather cumbersome to derive, as they involve a larger number of terms; plus, they typically require additional response functions to be implemented and calculated. There is, however, an important exception to this statement that is worth discussing, as it is central to the topics that will be presented in the later sections. Indeed, there are some notable cases where a perturbation produces a vanishing response at q = 0, and the interesting physics occurs only at first order in q. A classic example is that of a scalar potential perturbation: At q = 0, the perturbation is a rigid shift of the potential reference, which has obviously no effect on the electronic structure; at first order in q, one obtains the response to a uniform electric field. [22] In such cases, the formula for the O(q 2 ) response simplifies considerably and, in fact, is only marginally more complicated than the first-order formulas, Eqs. (22) and (24).
To be more specific, consider the following mixed derivative, and assume that |u λ2 mk,q=0 = 0. (34) Consistent with the above notation, we shall indicate the response function to a gradient of the perturbation λ 2 as Then we have where the tilded (unsymmetrized) quantities read as and n λ2 δ (r) = 2s (Again, we could drop the conduction-band projector as |u λ2 mk,δ belongs to the conduction band by construction.) The resulting formulas for the second-order energy are essentially identical to those derived in Section II D for the first order in q, with three main differences: (i) the result needs now to be symmetrized with respect to γ and δ; (ii) every occurrence of the response functions and perturbing operators that depend on λ 2 need to be replaced with their next higher-order gradient in q; (iii) there is a new term in Eq. (38) containing the second k-gradient of the band projector, ∂ γδQk . The latter is multiplied bŷ H λ2 k , which we have included to account for cases where the perturbation λ 2 , while yielding a vanishing response at q = 0, may not vanish therein.
Similar considerations can be used in order to push the expansion to O(q 3 ) whenever both perturbations, λ 1 and λ 2 , satisfy Eq. (34).

III. TREATMENT OF THE POLARIZATION RESPONSE
Many materials properties (including the flexoelectric tensor, discussed in Section V) involve, in one way or the other, the polarization response to an external perturbation. Correctly treating the long-wavelength limit of the electrical polarization is far from trivial in the framework of density-functional perturbation theory. In presence of a spatial modulation the standard formulas (e.g., based on the Berry-phase approach) are not applicable, since the latter are specialized to the macroscopic response at the Brillouin zone center. To work around this issue, in Ref. 20 the polarization response to some monochromatic external field, λ q , was expressed as the current-density (J) response to the time derivative of the field, In a quantum-mechanical context, this can be expressed [20,25] via the following formula, whereĴ αk,q is the current-density operator at a given value of q, |δu λ mk,q describe the adiabatic wavefunction response [20] to the perturbation velocity in the limit oḟ λ q → 0 and the index m runs over the occupied manifold.
(In other words, if we modulate the perturbation in time with a dynamical phase e −iωt , |δψ q i is related to the first-order term in the low-frequency expansion of the wavefunction response.) Unfortunately, Eq. (41) is not directly useful to our scopes, as it is not explicitly written as a second derivative of the total energy. To circumvent this issue, we shall use the known relationship between the electric field and the polarization, [26] P = −∂E/∂E, to rewrite P as a mixed derivative with respect to the electric field and the external perturbation λ, This strategy recovers the established DFPT formulas [11] for the polarization response in the q = 0 case.
[For instance, if λ is an atomic displacement, Eq.(42) reduces to the standard linear-response expression for the Born effective charge tensor.] It presents, however, a new complication in that we need to generalize the electricfield perturbation to finite values of q. To do that, we shall express the E-field perturbation as the time derivative of the A-field perturbation, again by means of adiabatic perturbation theory. As we shall see shortly, this will allow us to write the polarization response in a variational form, and therefore apply the formalism developed in the previous sections to perform its long-wave expansion.
In the following subsections we shall first discuss the response to a monochromatic vector potential at finite q, which is the fundamental building block of our approach. The electric field response is then defined as the frequency derivative of the vector potential response via a first-order expansion in the frequency. Finally, we shall discuss the simpler case of the scalar potential perturbation and show that, at first order in q, it correctly recovers the electric-field response (as defined via adiabatic perturbation theory) at q = 0.

A. Vector potential
The problem will be broken down into into two separate steps: First, we shall review the coupling of a generic Hamiltonian to an external A-field in the linear regime, following the guidelines of Ref. 20. Next, we shall discuss the response to such a perturbation with special attention to the lowest orders in q. In particular we shall see that, at first order in q, the wave function response can be written in terms of second k-gradients of the ground-state orbitals, plus the orbital response to a uniform magnetic field.

Coupling to a vector potential field
The coupling of a generic Hamiltonian to a vector potential field can be written as [27,28], where the line integral is assumed to be taken along the straight path connecting r ′ to r, Q is the particle charge (Q = −e for electrons), and we use atomic units, i.e. we have seth = c = 1. The linear expansion of the above expression in powers of the vector potential components to first order yieldŝ We shall consider a monochromatic A-field, written as a real constant times a complex phase of wavevector q, After taking the line integral, one obtains a closed expression for the first-order Hamiltonian in a coordinate representation, Note that the first-order Hamiltonian is related to the current-density operator aŝ which stems from the thermodynamic relationship J(r) = −δE/δA(r).
In the long-wavevelength context of this work, it is useful to expand the fraction on the right-hand side in powers of q, and to move the incommensurate phase factor to the left, The above expansion clarifies that the fraction simplifies to unity in the q = 0 limit, where the first-order Hamiltonian reads asĤ This provides a first "sanity check" of the present formalism: In the q = 0 limit the current-density operator as defined in Eq. (47) correctly reduces to the velocity operator times the particle charge, To make further progress towards a practical formalism, it is useful to consider the cell-periodic part of the first-order Hamiltonian in momentum space, This is a self-adjoint operator at any q, and can be conveniently written aŝ where the individual terms in the summation stem from the k-expansion of the unperturbed Hamiltonian, It is instructive to consider the special case of a local Hamiltonian, where all expansion terms vanish except the lowest two,Ĥ

Linear response to A
At this point, one could write a variational functional of the first-order wavefunction response to a monochromatic A-field, and follow the strategies outlined earlier in this work to calculate, e.g. the magnetic susceptibility of the crystal. As our main focus here is on the electric field response, however, we shall skip this topic and directly focus on the wavefunction response to an A-field -this is the crucial ingredient for what follows. The wavefunction response can be written in terms of the following Sternheimer equation , (Note the absence of the SCF potential contribution, as a static vector potential field leaves the charge density of the crystal unaltered in the linear regime by time reversal symmetry.) In the context of this work, we shall only need the zero-th and first orders in the q-expansion of |u Aα mk,q . Regarding the q = 0 limit, it is easy to show that (since we are dealing with electrons we shall assume where the "∂" sign is a shortcut for the gradient in kspace, and the tilde indicates covariant derivation in the language of band theory. Regarding the first order in q, we shall report here the final result (a detailed derivation is reported in the Appendix) The first term on the right-hand side is symmetric in βγ; the second and the third are both antisymmetric and describe the response to a uniform magnetic field, B.
In particular, the second contribution has only valenceband components and is related to the Berry curvature; the third is a cross-gap (CG) contribution that obeys the following Sternheimer equation, This corresponds precisely to the linear response of the wavefunctions to a uniform B-field as derived in Ref. 28.

B. Electric field
The standard treatment of the electric-field perturbation is based on the long-wavelength limit of a scalar potential perturbation. [22] Such an approach, which we shall discuss in Sec. III C, is appealing for its simplicity; however, when pushed to higher orders in q, it has the disadvantage of limiting the scopes of the theory to the longitudinal components of many dispersion-related tensors. (The transverse components of the flexoelectric tensor, for example, require a current-density response theory, [20] while the scalar potential is only sensitive to the charge-density response.) Instead, here we shall work in an electromagnetic gauge where the scalar potential vanishes, and the electric field is provided by a vector potential that is slowly varying over time, To achieve this goal, we need to establish a timedependent framework, where the external perturbation (in this case, the vector potential discussed in the previous subsection) is applied dynamically.
The adequate formalism to attack this problem is provided by first-order adiabatic perturbation theory, which relates the adiabatic wavefunctions, |δn , to the static response functions |∂ λ n via a Sternheimer equation, Here |∂ λ n and |δn describe the first-order response to λ andλ, respectively. In the context of the electric field response, this translates into where we have incorporated charge self-consistency via the usual SCF potential contribution, V Eα q . Remarkably, the A-field response functions play now the role of external perturbation in the context of the E-field response, This allows us to write the mixed derivative with respect to an electric field and a second perturbation λ as the following stationary functional of |u Eα mk,q and |u λ mk,q , (we have neglected the nonvariational term, as it is generally absent in the case of the E-field response), where Note that Eq. (63) is not a variational function of the A-field response wavefunctions, |iu Aα mk,q . Consequently, when calculating q-derivatives of E E * α λ q , one needs to explicitly derive the functions |iu Aα mk,q as one would do for a "standard" external potential operator (e.g., corresponding to a phonon or a "metric" [25] perturbation, as in the flexoelectric case of Sec. V). Note also that at q = 0 the above formulas trivially reduce to the standard treatment of the uniform electric field perturbation, [11] of which they constitute the desired generalization to arbitrary qvectors.
Before closing this subsection, it is interesting to verify where the variational formulas derived here stand compared to the existing treatment of the polarization response [20] via Eq. (41). By imposing the stationary condition Eq. (61) to Eq. (63), we obtain the following nonstationary formula for the polarization response, iu Aα mk,q |u λ mk,q .
(65) It is not difficult to show that Eq. (65) exactly matches Eq. (41). One just needs to recall the relationship between the current-density operator and the vector potential perturbation, Eq. (47), and the sum-over-states expression of the adiabatic wavefunctions [a consequence of Eq. (60)], To go from Eq. (41) to Eq. (65) it suffices then to incorporate Eq. (66) into Eq. (41), and subsequently move the energy denominator and the factor of i from the right (λresponse) to the left (A-response) matrix element. This derivation shows that, apart from irrelevant differences in the notation, Eq. (41) can be regarded as the nonstationary [11] counterpart of the variational functional, Eq. (63).

C. Scalar potential
A monochromatic scalar potential perturbation simply involves adding ϕe iq·r to the local electrostatic potential; thus, in the language of this work, the external perturbation is the unity operator at any q, where Q is the electron charge. The mixed derivative functional involving a scalar potential and a second perturbation λ then reads as (note, as in the electric field case, the disappearance of the nonvariational term) where Differentiation with respect to |u λ mk,q yields the Sternheimer equation for the first-order wavefunctions, whereV ϕ q is, as usual, the SCF contribution to the perturbation.
As we mentioned earlier, the scalar potential response vanishes at q = 0, and any mixed derivative involving ϕ identically vanishes at q = 0 as well. (Note that the perturbation doesn't vanish at q = 0, as it is a constant equal to −1 at any value of the wavevector.) At first order in q one recovers the standard treatment of the uniform electric field, [22] with the following relationship between the corresponding first-order wave functions, Then, by combining Eq. (71) with our higher-order formula, Eq. (37), one can obtain useful information about the dispersion of the charge-density response of the system to an arbitrary perturbation. To see the relationship between the scalar potential and the first-order charge density, one can insert Eq. (70) into Eq. (68) to obtain a nonstationary expression for the mixed derivative, which provides a direct link to the electronic contribution to the charge-density response, Note thatρ λ el,q , the cell-averaged electronic charge density induced by the perturbation λ, differs from the cell average of n λ q (r) by a minus sign, which stems from the negative electron charge.

D. Relationship to the continuity equation
The fact that E ϕ * λ q and −E E * α λ q correspond, respectively (modulo a factor of 2/Ω), to the charge-density and polarization response to the perturbation λ implies that they must satisfy the continuity equation, ∇ · P = −ρ. In reciprocal space, this means that the following must be true, The correctness of this result can be, of course, verified at the level of the finite-q functionals, respectively Eq. (63) and Eq. (68). In the context of the present work, however, it is perhaps more insightful to verify Eq. (74) in the long-wave limit, and use it as a "sanity check" of the formalism. At the lowest orders in q, Eq. (74) leads to the following relationships,

IV. DYNAMICAL QUADRUPOLE TENSOR
A. Theory Following the notation of Ref. 13, we can define the cell-integrated charge response to a monochromatic atomic displacement as where Z κ is the pseudopotential charge, and 2E ϕ * τ κβ q is the mixed derivative of the energy with respect to a scalar potential [see Sec. III C, Eq. (68) in particular] and an atomic displacement pattern of the type (l and κ are cell and sublattice indices, respectively; R 0 lκ indicates the unperturbed atomic position; note that this perturbation differs from the standard implementations of DFPT [12,22] by a phase factor, see Appendix B 1 for details.) In the long-wave limit, Q q κβ can be written as a multipole expansion of the charge density induced by an atomic displacement, where the dots stand for higher-order terms that we will not discuss in this work. The first-order term corresponds to the Born effective charge tensor, where the electronic contribution reads as thus recovering the already established result. [11,12] [We have applied the Hellmann Feynman theorem to the q derivative of the functional of Eq. (68), combined with the fact that the ϕ-response wavefunctions vanish at q = 0.] The quadrupole tensor elements can be written as the second q-gradients of Q q κβ , By using Eq. (76) we arrive at the following expression, (83) The first q-gradient of the mixed response to an electric field and to an atomic displacement can then be calculated by applying Eq. (22) and Eq. (24) to Eq. (63) and Eq. (64), respectively, with Since the response functions need to be symmetrized according to Eq. (83), we can simplify the expression of |u A δ mk,γ , Eq. (57), and set where ∂ γδPk is the second k-gradient of the valenceband projector described in Appendix A. [Other terms in Eq. (57) vanish as they are antisymmetric in the two indices.] The explicit formula for the q-derivative of the atomic displacement perturbation,Ĥ τ κβ k,γ , is reported in Appendix B 1.
Note that we could have obtained the exact same result by directly applying the higher-order formula Eq. (37) to Eq. (68), instead of using Eq. (83). The above procedure has the advantage that the intermediate quantity E has also a well-defined physical meaning, as it relates to the P (1) -tensors discussed in Refs. 6 and 13, (87) These quantities can be interpreted as the first spatial moment of the polarization field induced by an atomic displacement, and are required for the calculation of the so-called "mixed" contribution to the flexoelectric tensor. Their in-depth discussion would bring us out of our main topic, and we defer it to a forthcoming publication.

B. Computational parameters
The computation of the quadrupole tensor has been implemented in the ABINIT [29] package as a postprocessing of the DFPT response functions calculation. We relax the unit cell until the forces are smaller than 1. × 10 −6 Ha/bohr, obtaining an aspect ratio of c/a = 1.046 (a = 7.275 bohr) and a spontaneous polarization P S = 0.78 C/m 2 . These structural data are in excellent agreement with earlier calculations of the same system. [26] C. Numerical results We first study bulk Si as a testcase. The quadrupolar tensor is defined by a single material constant, Q, via the following expression, ε βγδ is the Levi-Civita tensor. In order to benchmark the formalism, we first perform a calculation of Q via an independent real-space method, which does not rely on Eq. (82). To this end, we calculate the charge-density response to an atomic displacement along [111], by using a Brillouin-zone unfolding procedure [31] applied to the 6atoms hexagonal cell. In particular, we consider a stripe of 22 equidistant q-points (q=0 included), spanning the entire Brillouin zone along the crystallographic [111] direction, and calculate the first-order densities associated with a phonon perturbation at each q. (In practice, the number of independent q-points reduces to 12 due to time-reversal symmetry.) After unfolding, we readily obtain the induced charge density that corresponds to a displacement of an isolated atom. (In practice, this approach corresponds to studying the displacement of a plane of atoms in a supercell where the hexagonal unit is repeated 22 times along [111].) We report the plane averages of the first-order density in Fig. 1, where we also show its decomposition into the antisymmetric and symmetric contributions. A fast decay of the induced density is clearly observed, which allows us to calculate the desired real-space moments with high numerical accuracy. The dipole moment correctly reproduces the pseudopotential charge, as expected. The second real-space moment of the first-order charge is then related to Q via where the superscript rs stands for "real space", and ǫ ∞ is the calculated electronic dielectric constant.
Our calculated values areQ (2) [111] = 1.178 and ǫ ∞ = 13.103, which via Eq. (89) yield a value of Q rs = 13.367 e · Bohr. With an equivalent choice of the computational parameters, by using our new method, Eq. (82) and the primitive 2-atom cell we obtain Q = 13.368 e · Bohr. The matching between the two approaches is essentially perfect, which demonstrates the soundness of our implementation.
To better illustrate the plane-wave and k-point mesh requirements of our new method, we have also performed a convergence study, where we compare the behavior of the quadrupole tensor components (alongside with the flexoelectric response, which we will comment on in Section V) to that of a "standard" linear-response quantity, the electronic dielectric constant. The numerical results are plotted in Fig. 2(a-b) as a function of the plane-waves energy cutoff and the number of k-points employed to sample the Brillouin zone. One can clearly appreciate from the figure that the quadrupoles (panel a) and the dielectric constant (panel b) converge equally fast with respect to both computational parameters. Moreover, the agreement between Q and Q rs becomes better and better as the energy cutoff is increased. Both observations concur to put our new method, based on Eq. (82), on very firm grounds. Note that the calculation via Eq. (82) is about an order of magnitude more efficient than the alternative real-space method, as the latter requires calculating the phonon response at many q-points, while the former only requires Γ-point response functions as prerequisites.
Next, as a more ambitious test of our method, we carry out a numerical verification of Martin's formula [14] relating the proper [34] clamped-ion piezoelectric tensor e αβγ to the sublattice sum of the dynamical quadrupoles.
[Here, the first subscript (α) of the piezoelectric tensor in the left-hand side indicates the polarization direction, whereas the other two indices (βγ) refer to the strain tensor components.] In particular, we shall benchmark the value of e αβγ computed from Eq. (90) via the  quadrupoles, against its value obtained as the mixed derivative of the energy with respect to components of the strain and the electric field. The latter is a standard DFPT quantity that we obtain by means of the metric tensor formulation by Hamann et al. [33] as implemented in the ABINIT package. We focus on a well-known piezoelectric system, the tetragonal phase of PbTiO 3 . The quadrupole moments of each atom in the unit cell are shown in Tab. I. As for the three independent PbTiO 3 piezoelectric tensor elements, they are reported in Tab. II. The comparison between the coefficients from the two methods demonstrates an exceptionally good agreement, which improves up to the fifth decimal digit by increasing the density of k-points to 14 × 14 × 14. Our results also qualitatively agree with those of Ref. 32, wherein a different set of lattice parameters, pseudopotentials and exchange-correlation functionals were employed.

A. Theory
From the point of view of atomistic calculations, flexoelectricity can be decomposed into three distinct contributions: [13] lattice-mediated, mixed and electronic. In principle, all three can be written, by using the formalism developed in this work, in terms of few basic ingredients. These are the mixed response to an electric field, atomic displacement or metric-wave perturbation taken at first or second order in q. We defer the detailed implementation and test of the full flexoelectric tensor to a forthcoming publication, and focus here on the purely electronic response only.
The electronic flexoelectric tensor can be written as the second derivative with respect to q of the currentdensity that is adiabatically induced by a "clamped-ion" acoustic phonon perturbation, [20] i.e. to a displacement pattern of the type Note the absence of the basis index on the perturbation parameter; this implies that all atoms in the primitive cell should be displaced simultaneously with equal amplitude, u. Thus, a calculation of the flexoelectric tensor can be, in principle, carried out by regarding Eq. (91) as the sublattice sum of Eq. (78), which leads to the following practical scheme. First, one writes the polarization response to the displacement of an individual sublattice at finite q; then, a second-order expansion in the wavevector q is performed; finally, the clamped-ion flexoelectric tensor is written as a sublattice sum of the result [13]. This was indeed the strategy adopted in Ref. 20.
In the context of this work, however, such an approach is impractical -the phonon perturbation of Eq. (78) does not vanish in the q = 0 limit. Therefore, Eq. (37) cannot be directly applied to calculate expansion to second order in q of the corresponding polarization response. To work around this obstacle, we shall follow Refs. 25 and 35 and recast the acoustic phonon as a "metric wave" perturbation by operating a coordinate transformation to the curvilinear co-moving frame. We shall then write the polarization response to the acoustic phonon at finite q as (following the notation of Ref. 25) where E E * α (β) q refers to the mixed derivative of Eq. (63) specialized to the case λ = (β), and (β) indicates a met-ric wave with the displacement field oriented along the Cartesian direction β. (The overline implies cell averaging, and the prime indicates that we have implicitly discarded the magnetic-like contribution from rotation gradients, following the arguments of Refs. 20, 25, and 35.) It is useful, at this stage, to recall [25] two crucial properties of the metric wave: (i) both the perturbation and the response vanish at q = 0, (ii) at first-order in q, the metric wave reduces to the uniform strain perturbation, η βγ , by Hamann et al. [33], As we shall see shortly, properties (i) and (ii) will allow us to write down a closed expression for the clamped-ion flexoelectric tensor by using the second-order formula, Eq. (37). Before doing that, it is useful to perform a consistency check of Eq. (92) by showing that it correctly recovers the piezoelectric tensor at first order in q The clamped-ion piezoelectric tensor can be defined as By applying Hellmann-Feynman theorem to Eq. (63) and by using Eq. (93) and Eq. (94) we readily obtain which matches the established result. [11,33] The type-I clamped-ion flexoelectric tensor can now be written in terms of the following formula, where the mixed derivative is, as above, taken with respect to an electric field and the metric-wave perturbation. By taking again into account the relationships existing between the metric (β) and the strain perturbations η βδ , the formulas for the second gradient , Eq. (37) and Eq. (38), are as follow, Here we have labeled, for later reference, the five different terms of the band-and k-resolved contribution as T 1−5 , and the term deriving from the self-consistent energy via the gradient of the Coulomb kernel as T elst . Most of the symbols are self-explanatory, as we have already encountered them in the formula for the quadrupolar response. Similarly to the quadrupole case, we shall use Eq. (86) to simplify T 5 ; this is justified here because all our tests are performed on cubic materials, where T 5 must be symmetric with respect to αγ. The formulas for the q-derivatives of metric perturbation,Ĥ k,γδ , are elaborated in Appendix B 2.
In the following subsection, we shall present our numerical results in type-II form by using In practice, the transformation Eq. (100) needs to be performed explicitly only on T 4 , since all the other terms are most naturally written in type-II form. (The explicit formula is reported in Appendix B 2.) As we shall be dealing with cubic crystals only, we shall adopt the short-hand notation µ L = µ II 11,11 , µ T = µ II 11,22 and µ S = µ II 12,12 for the three independent components, respectively: longitudinal (L), transverse (T) and shear(S). We shall drop the "II" superscript and assume that the flexoelectric tensor is in type-II form henceforth.

B. Computational parameters
The computation of the clamped-ion flexoelectric tensor has also been implemented in the ABINIT [29] package. The numerical results have been obtained with the same type of pseudopotentials and XC functional as in the Section IV B. For our calculations on noble gas atoms He, Ar and Kr, we use a large cell of 14×14×14 a.u., with a plane-wave cut-off of 90 Ha and a 2 × 2 × 2 (4 × 4 × 4) mesh of k-points to sample the Brillouin zone of He and Ar (of Kr). For our calculations on SrTiO 3 , we used a cubic 5-atoms unit cell with an optimized cell parameter of a 0 =7.267 Bohr, with a plane-wave cut-off of 70 Ha and a 8 × 8 × 8 mesh of k-points. Regarding Si, we use the 2-atom primitive cell with the same computational parameters as described in the Section IV B. We have also  performed a convergence study of the calculated Si flexoelectric tensor by varying the cut-off and k-point mesh resolution.

C. Numerical results
In order to test our method, we first study a simple cubic crystal lattice consisting of isolated noble-gas atoms, as already investigated in Refs. 6, 18, 20, 25, and 35. This toy model presents the advantage that its flexoelectric coefficients can be determined analytically, based on the macroscopic electric tensor and the second real-space moment of the unperturbed atomic charge. In particular, the three independent flexoelectric coefficients as calculated from a metric-wave perturbation, must fulfill the conditions [25,35] Tab. III shows the flexoelectric coefficients calculated for He, Ar and Kr. It is clear from the reported data that the expected relationships, Eq. (101), are satisfied to a high degree of accuracy, and our coefficients are in excellent agreement with those obtained in previous works. [25] The largest deviation is shown by Kr: being it a larger atom, the overlap between neighboring images is likely to be more pronounced than in the other cases, which justifies the discrepancies we observe with respect to the expectations of the isolated atom model.
At this stage, it is worth emphasizing that such test is by no means trivial; on the contrary, it represents a very stringent benchmark for our formalism. To demonstrate this point, in Tab. IV we show a breakdown of the three independent coefficients of the Ar-based crystal into the contributions of the individual terms appearing in Eqs. (98)  µ S = 0 are not fulfilled by any of the individual terms (an exception is T 2 , but it only contributes a tiny fraction of the final value); instead, the cancellation of the shear component and the equality between the transverse and longitudinal ones both result from a subtle balance between all the terms. Since each term involves a different combination of the input response functions and of the perturbations, such an accurate compensation clearly demonstrates the robustness of the numerical implementation.
We have also calculated the electronic contribution to the flexoelectric tensor of two real materials, Si and SrTiO 3 . The converged values of the flexoelectric coefficients are shown in Tab. V, where we also compare them to the relevant literature data [19,20,25]. Again, the excellent agreement with the published values is clear. Nevertheless, we stress that our results are obtained with a small fraction of the computational effort that was formerly needed.
As a final benchmark, we study the convergence of the flexoelectric coefficients of Si as a function of the k-point mesh resolution and of the plane-wave cutoff. The results for µ L are shown in Fig. 2(c). (The convergence of the two other independent components is qualitatively similar to the longitudinal one.) Analogously to the case of the quadrupoles, the flexoelectric coefficients converge at the same rate as the dielectric tensor. This means that all the spatial dispersion properties that we have calculated in this work require a computational effort that is comparable to the study of other standard linear-response quantities, such as the electronic dielectric tensor.

VI. CONCLUSIONS AND OUTLOOK
We have established a general method to perform a systematic study of spatial dispersion effects in the framework of density-functional perturbation theory. As a practical demonstration, we have implemented the dynamical quadrupole tensor and the clamped-ion flexoelectric tensor in the ABINIT package, and performed extensive numerical tests. This work opens a number of exciting avenues for future research, which we shall briefly sketch hereafter.
First, we expect that the knowledge of the dynamical quadrupoles will allow for an improved description of the interatomic force constants, thereby enabling a more ac-curate computation of the phonon band structures. This might be important for certain material classes, such as piezoelectrics, where the treatment of long-range electrostatics is crucial for reproducing the correct sound velocity. [36] On a different note, our theory might also prove itself very helpful in establishing higher-order multipolar generalizations [37] of the Berry-phase theory of polarization [38]. Indeed, our expressions for the dynamical quadrupole and flexoelectric tensors can be regarded as the linear variation of the "bulk quadrupolization" [39] with respect to a zone-center lattice distortion or uniform strain, respectively. There are intriguing parallels to the theory of multipolar magnetic orders [40,41] as well, which will certanly stimulate further studies.
Second, the treatment of flexoelectric effects beyond the clamped-ion level should be relatively straightforward by following the same guidelines as we did here. Both the "mixed" and "lattice-mediated" contributions involve first or second derivatives of the polarization response to a phonon, or the force-constant matrix, just like the electronic contribution. These additional pieces involve similar formulas, only with a slightly different combination of the basic response functions (electric field, atomic displacement or uniform strain). Thus, the calculation of the full flexoelectric tensor for an insulating crystal or nanostructure of arbitrary symmetry looks now well within reach. We expect that, once implemented, it will involve a computational effort that is comparable to the calculation of the piezoelectric tensor.
Third, the method can be easily adapted to compute other spatial dispersion effects, for example the natural optical rotation tensor. (The latter can be written as the first gradient with respect to the wavevector of the dielectric tensor.) First-principles calculations of natu-ral gyrotropy are starting to appear; [42] we expect that, by bringing it within the scopes of DFPT, the formalism presented here will greatly simplify the calculation of this interesting quantity as well. In the context of ferroic materials, we also expect our method to facilitate the development of first-principles based continuum models [43] and effective Hamiltonians [44], where gradient-mediated couplings often play an important role.
More generally, our work has revealed a profound connection between spatial dispersion and orbital magnetism that, in our opinion, deserves further attention. Whenever the polarization response to a perturbation is needed at first order in the wavevector q, one of the contributions necessarily involves the wave-function response to a gradient of A, and hence to a uniform magnetic field. This can be tentatively interpreted as a "gyrotropic" contribution to the response, and is only present in certain crystal classes; we were unable to discuss it here because of space limitations, but we regard it as yet another interesting topic for future studies.

(B14)
Appendix C: Treatment of the electrostatic divergence at G = 0 The local potential diverges at G = 0 because of the Coulomb singularity, [22] v loc κ (q) ∼ − 4π where Z κ is the bare pseudopotential charge. This means that the q-derivatives of the local potential contribution to the first-order Hamiltonians discussed in the previous sections must be calculated with some care regarding the G = 0 component. To see this, it is useful to rewrite Eq. (C1) as follows, v loc κ (q) = where we have introduced the auxiliary function Regarding the atomic displacement perturbation, the above definitions lead to the following small-q expansion of the local potential part at G = 0, V loc,τ κβ q Because of the assumption of short-circuit electrical boundary conditions we shall drop the divergent term.
This leaves us with a constant multiplied by q β , which vanishes in the q → 0 limit. The q-derivative does not vanish, and we should in principle take it into account in the calculation of the quadrupolar tensor. However, in Eq. (85) the operatorĤ τ κβ kγ only appears between a conductionband bra and a valence-band ket. By orthogonality, the above constant contribution is irrelevant and can be safely discarded.
Regarding the metric perturbation, recall that it vanishes in the q → 0 limit, as the aforementioned divergence in the local potential contribution exactly cancels with an opposite divergence in the "H0" term. [25] Within the present notation conventions, one has where in the last line we have taken into account that F κ (q = 0) = 4πZ κ [22], that n (0) (G = 0) = κ Zκ Ω and that odd terms in the Taylor expansion of F κ (q) vanish due to the spherical symmetry of the local atomic potentials. The first q-derivative of the above yields a well-defined constant, Recall that the first q-derivative of the metric-wave perturbation coincides (modulo a factor of i) with the uniform strain perturbation. Hence, we conclude that to calculate the clamped-ion flexoelectric tensor the G = 0 component of the local potential of the first-order strain Hamiltonian has to be corrected as, (C8) This correction is important in the calculation of the flexoelectric tensor, since the uniform strain operator in Eq. (99) appears sandwiched between two unperturbed valence states.