A density functional theory for ecology across scales
Modular components of the DFTe energy functionalThe central ingredient of DFTe is an energy functional E, assembled according to Eq. (1). The methodology of DFTe can be understood by inspecting the dispersal and environmental energies in Eqs. (2) and (3) without interactions. In our first case study, illustrated in Fig. 2 and Supplementary Fig. 2, we demonstrate that equation (3), in conjunction with Eq. (2), can realistically describe the influence of the environment on species’ distributions. Mechanisms that alter the trade-off between dispersal and environment can be introduced as part of Eint. For instance, back reactions on the environment could be modelled with a bifunctional Ebr[Venv, n] that yields the equilibrated modified environment ({V}_{s}^{{{{{{{{rm{env}}}}}}}}}+delta {E}_{{{{{{{{rm{br}}}}}}}}}[{{{{{{{{bf{V}}}}}}}}}^{{{{{{{{rm{env}}}}}}}}},{{{{{{{bf{n}}}}}}}}]/delta {n}_{s}({{{{{{{bf{r}}}}}}}})), cf. Eq. (5).In the following we make explicit the interaction and resource energies that enter Eq. (1) and are used in our case studies of Figs. 2–7. We let Eint[n] include all possible bipartite interactions$${E}_{gamma }[{{{{{{{bf{n}}}}}}}}]=mathop{sum }limits_{{s,{s}^{{prime} }!=!1}atop {{s}^{{prime} }ne s}}^{S}{int}_{A}({{{{{{{rm{d}}}}}}}}{{{{{{{bf{r}}}}}}}})({{{{{{{rm{d}}}}}}}}{{{{{{{{bf{r}}}}}}}}}^{{prime} }){n}_{s}{({{{{{{{bf{r}}}}}}}})}^{{alpha }_{s}},{gamma }_{s{s}^{{prime} }}({{{{{{{bf{r}}}}}}}},, {{{{{{{{bf{r}}}}}}}}}^{{prime} }){n}_{{s}^{{prime} }}{({{{{{{{{bf{r}}}}}}}}}^{{prime} })}^{{beta }_{{s}^{{prime} }}},$$
(6)
which include amensalism, commensalism, mutualism, and so forth. Here, ({alpha }_{s},, {beta }_{{s}^{{prime} }}ge 0), and the interaction kernels ({gamma }_{s{s}^{{prime} }}) are assembled from fitness proxies of species s and ({s}^{{prime} }) (Supplementary Table 1). Higher-order interactions can be introduced, for example, through (i) terms like ({n}_{s},{gamma }_{s{s}^{{prime} }},{n}_{{s}^{{prime} }},{gamma }_{{s}^{{prime} }{s}^{{primeprime} }}^{{prime} },{n}_{{s}^{{primeprime} }}) that build on pairwise interactions or (ii) genuinely multipartite expressions like ({gamma }_{s{s}^{{prime} }{s}^{{primeprime} }}{n}_{s},,{n}_{{s}^{{prime} }},{n}_{{s}^{{primeprime} }}). Multi-partite interactions based on bipartite interactions do not seem to be an uncommon scenario48. However, there may be systems where nonzero coefficients ({gamma }_{s{s}^{{prime} }{s}^{{primeprime} }}) couple all species. This poses a challenge for mechanistic theories in general. Then, ‘simpler subsystems’ that have to be included in the DFTe workflow of Fig. 1a can only refer to situations where other energy components are absent, such as resource terms or complex environments. For example, the coefficients ({gamma }_{s{s}^{{prime} }{s}^{{primeprime} }}) could be extracted in an experiment with a controlled simple environment and then used to model the interacting species in a real-world setting. For (({alpha }_{s},, {beta }_{{s}^{{prime} }})=(1,1)) we identify the contact interaction in physics as ({gamma }_{s{s}^{{prime} }}propto delta ({{{{{{{bf{r}}}}}}}}-{{{{{{{{bf{r}}}}}}}}}^{{prime} })) with the two-dimensional delta function δ( ), while the Coulomb interaction amounts to setting ({gamma }_{s{s}^{{prime} }}propto 1/|{{{{{{{bf{r}}}}}}}}-{{{{{{{{bf{r}}}}}}}}}^{{prime} }|). The mechanistic effect of these interaction kernels on the density distributions is the same in ecology as it is in physics—a mathematical insight that inspired us to build ecological analogues to the phenomenology of quantum gases, which feature functionals of the kind in Eq. (6). Note that we do not introduce any quantum effects into ecology despite the fact that the mathematical structure of DFTe is borrowed in part from quantum physics. While the contact interaction is a suitable candidate for plants and especially microbes52, we expect long-range interactions (for example, repulsion of Coulomb type) to be more appropriate for species with long-range sensors, such as eyes. Both types of interactions feature in describing the ecosystems addressed in this work.In a natural setting the equilibrium abundances are ultimately constrained by the accessible resources. It is within these limits of resource availability that environment as well as intra- and inter-specific interactions can shape the density distributions. An energy term for penalising over- and underconsumption of resources is thus of central importance. Each species consumes resources from some of the K provided resources, indexed by k. A subset of species consumes the locally available resource density ρk(r) according to the resource requirements νks, which represent the absolute amount of resource k consumed by one individual (or aggregated constituent) of species s. The simple quadratic functional$${E}_{{{{{{{{rm{Res}}}}}}}}}[{{{{{{{bf{n}}}}}}}}]={int}_{A}({{{{{{{rm{d}}}}}}}}{{{{{{{bf{r}}}}}}}})mathop{sum }limits_{k=1}^{K}{{{{{{{{mathcal{L}}}}}}}}}_{k}left({{{{{{{bf{n}}}}}}}},, {rho }_{k}right)equiv zeta {int}_{A}({{{{{{{rm{d}}}}}}}}{{{{{{{bf{r}}}}}}}})mathop{sum }limits_{k=1}^{K}{w}_{k}({{{{{{{bf{r}}}}}}}}){left[mathop{sum }limits_{s=1}^{S}{nu }_{ks}{n}_{s}({{{{{{{bf{r}}}}}}}})-{rho }_{k}({{{{{{{bf{r}}}}}}}})right]}^{2}$$
(7)
proves appropriate. Here, νksns is the portion of resource density ρk that is consumed by species s. That is, νks > 0 indicates that s requires resource k. If Eq. (7) is the total energy functional, then a single-species system with a single resource equilibrates with density n1(r) = ρ1(r)/ν11 at every position r, and additional DFTe energy components would modify this equilibrium. Predator–prey relationships are introduced by making species k a resource ({rho }_{k}=left]{n}_{k}right[), where (left]nright[) declares n a constant w.r.t. the functional differentiation of E, that is, the predator tends to align with the prey, not the prey with the predator. In view of the energy minimisation, the quadratic term in Eq. (7) entails that regions of low resource density ρk are less important than regions of high ρk. The different resources k have the same ability to limit the abundances, such that the limiting resource k = l at r has to come with the largest of weights wl(r), irrespective of the absolute amounts of resources at r. For example, the weights wk have to ensure that an essential but scarce mineral has (a priori) the same ability to limit the abundances as a resource like water, which might be abundant in absolute terms. To that end, we specify the weights$${w}_{k}({{{{{{{bf{r}}}}}}}})=frac{1}{{bar{rho }}_{k}^{2}}mathop{sum}limits_{s}eta ({nu }_{ks})exp left[sigma left(frac{{lambda }_{ks}}{{lambda }_{ls}}-1right)right],$$
(8)
which are inspired by the smooth minimum function, where σ λls irrelevant at r. Using ({E}_{{{{{{{{rm{Res}}}}}}}}}), we show that an analytically solvable minimal example of two amensalistically interacting species already exhibits a plethora of resource-dependent equilibrium states (see Supplementary Notes and Supplementary Fig. 1).We specify the DFTe energy functional in Eq. (1) by summing Eqs. (2), (3), (6), and (7) and by (optionally) constraining the abundances to N via Lagrange multipliers μ:$$E[{{{{{{{bf{n}}}}}}}},, {{{{{{{boldsymbol{mu }}}}}}}}]({{{{{{{bf{N}}}}}}}}) equiv E[{{{{{{{bf{n}}}}}}}}]+{E}_{{{{{{{{boldsymbol{mu }}}}}}}}}[{{{{{{{bf{n}}}}}}}}]({{{{{{{bf{N}}}}}}}})\ equiv {E}_{{{{{{{{rm{dis}}}}}}}}}[{{{{{{{bf{n}}}}}}}}]+{E}_{{{{{{{{rm{env}}}}}}}}}[{{{{{{{bf{n}}}}}}}}]+{E}_{gamma }[{{{{{{{bf{n}}}}}}}}]+{E}_{{{{{{{{rm{Res}}}}}}}}}[{{{{{{{bf{n}}}}}}}}]+mathop{sum }limits_{s=1}^{S}{mu }_{s}left({N}_{s}-{int}_{A}({{{{{{{rm{d}}}}}}}}{{{{{{{bf{r}}}}}}}}),{n}_{s}right).$$
(9)
Uniform situations are characterised by spatially constant ingredients ns = Ns/A, ρk = Rk/A, coefficients τs, etc. for the DFTe energy, such that Eq. (9) reduces to a function E(N) with building blocks$${E}_{{{{{{{{rm{dis}}}}}}}}}longrightarrow frac{1}{2,A}mathop{sum }limits_{s=1}^{S}{tau }_{s},{N}_{s}^{2},$$
(10)
$${E}_{{{{{{{{rm{env}}}}}}}}}longrightarrow mathop{sum }limits_{s=1}^{S}{V}_{s}^{{{{{{{{rm{env}}}}}}}}},{N}_{s},$$
(11)
$${E}_{gamma }longrightarrow mathop{sum }limits_{{s,{s}^{{prime} }!=!1}atop {{s}^{{prime} }ne s}}^{S}frac{{N}_{s}^{{alpha }_{s}},{gamma }_{s{s}^{{prime} }},{N}_{{s}^{{prime} }}^{{beta }_{{s}^{{prime} }}}}{{A}^{{alpha }_{s}+{beta }_{{s}^{{prime} }}-1}},$$
(12)
$${E}_{{{{{{{{rm{Res}}}}}}}}}longrightarrow Amathop{sum }limits_{k=1}^{K}{{{{{{{{mathcal{L}}}}}}}}}_{k}left({{{{{{{bf{N}}}}}}}}/A,, {R}_{k}/Aright).$$
(13)
Ecosystem equilibria from the DFTe energy functionalThe general form of Eq. (9) gives rise to two types of minimisers (viz., equilibria): First, we term$${{{{{{{mathcal{H}}}}}}}}({{{{{{{bf{N}}}}}}}})equiv E[tilde{{{{{{{{bf{n}}}}}}}}}]equiv mathop{min }limits_{{{{{{{{bf{n}}}}}}}}}left{E[{{{{{{{bf{n}}}}}}}}],left|,{int}_{A}({{{{{{{rm{d}}}}}}}}{{{{{{{bf{r}}}}}}}}),{{{{{{{bf{n}}}}}}}}({{{{{{{bf{r}}}}}}}})={{{{{{{bf{N}}}}}}}},{{{{{{{rm{(fixed)}}}}}}}}right.right}$$
(14)
the ‘DFTe hypersurface’, with (tilde{{{{{{{{bf{n}}}}}}}}}) the energy-minimising spatial density profiles for given (fixed) N. Second, the ecosystem equilibrium is attained at the equilibrium abundances (hat{{{{{{{{bf{N}}}}}}}}}={int}_{A}({{{{{{{rm{d}}}}}}}}{{{{{{{bf{r}}}}}}}}),hat{{{{{{{{bf{n}}}}}}}}}({{{{{{{bf{r}}}}}}}})), which yield the global energy minimum$${{{{{{{mathcal{H}}}}}}}}(hat{{{{{{{{bf{N}}}}}}}}})=mathop{min }limits_{{{{{{{{bf{N}}}}}}}}},{{{{{{{mathcal{H}}}}}}}}({{{{{{{bf{N}}}}}}}}),$$
(15)
where the minimisation samples all admissible abundances, that is, ({{{{{{{bf{N}}}}}}}}in {left({{mathbb{R}}}_{0}^{+}right)}^{times S}) if no further constraints are imposed.The direct minimisation of E[n] is most practical for uniform systems, which only require us to minimise E(N) over an S-dimensional space of abundances. For the general nonuniform case, we adopt a two-step strategy that reflects Eqs. (14) and (15). First, we obtain the equilibrated density distributions on ({{{{{{{mathcal{H}}}}}}}}) for fixed N from the computational DPFT framework26,27,28,29,30,31. Second, a conjugate gradient descent searches ({{{{{{{mathcal{H}}}}}}}}({{{{{{{bf{N}}}}}}}})) for the global minimiser (hat{{{{{{{{bf{N}}}}}}}}}). Technically, we perform the computationally more efficient descent in μ-space. Local minima are frequently encountered, and we identify the best candidate for the global minimum from many individual runs that are initialised with random μ. Note that system realisations with energies close to the global minimum, especially local minima, are likely observable in reality, assuming that the system can equilibrate at all. There is always an equilibrium if the energy functional is bounded from below, together with the fact that the support (abundances/densities) of the energy functional is finite in any practical application. If some DFTe energy components are chosen (too) negative, the system can be unstable, in which case the energy functional has no minimum and is inappropriate for modelling the equilibrium in question. This means that another energy functional has to be considered, or, in the worst case, that DFTe is incapable of simulating this system. We also caution that no numerical optimisation algorithms for non-convex black-box functions can guarantee to find the global minimum, not even approximately. Without analytically available characteristics of the global minimum, all one may hope for are candidates of the minimiser, and those may not even be local minima—there is no way to be certain that an optimum proposed by a numerical optimisation algorithm is stable.Density-potential functional theory (DPFT) in Thomas–Fermi (TF) approximationDefining$${V}_{s}({{{{{{{bf{r}}}}}}}})={mu }_{s}-frac{delta {E}_{{{{{{{{rm{dis}}}}}}}}}[{{{{{{{bf{n}}}}}}}}]}{delta {n}_{s}({{{{{{{bf{r}}}}}}}})}$$
(16)
for all s, we obtain the reversible Legendre transform$${E}_{{{{{{{{rm{dis}}}}}}}}}^{{{{{{{{rm{L}}}}}}}}}[{{{{{{{bf{V}}}}}}}}-{{{{{{{boldsymbol{mu }}}}}}}}]={E}_{{{{{{{{rm{dis}}}}}}}}}[{{{{{{{bf{n}}}}}}}}]+mathop{sum }limits_{s=1}^{S}{int}_{A}({{{{{{{rm{d}}}}}}}}{{{{{{{bf{r}}}}}}}}),({V}_{s}-{mu }_{s}),{n}_{s}$$
(17)
of the dispersal energy and thereby supplement the total energy with the additional variables V:$$E[{{{{{{{bf{V}}}}}}}},, {{{{{{{bf{n}}}}}}}},, {{{{{{{boldsymbol{mu }}}}}}}}]({{{{{{{bf{N}}}}}}}})={E}_{{{{{{{{rm{dis}}}}}}}}}^{{{{{{{{rm{L}}}}}}}}}[{{{{{{{bf{V}}}}}}}}-{{{{{{{boldsymbol{mu }}}}}}}}]-{int}_{A}({{{{{{{rm{d}}}}}}}}{{{{{{{bf{r}}}}}}}}),{{{{{{{bf{n}}}}}}}}cdot ({{{{{{{bf{V}}}}}}}}-{{{{{{{{bf{V}}}}}}}}}^{{{{{{{{rm{env}}}}}}}}})+{E}_{{{{{{{{rm{int}}}}}}}}}[{{{{{{{bf{n}}}}}}}}]+{{{{{{{boldsymbol{mu }}}}}}}}cdot {{{{{{{bf{N}}}}}}}}.$$
(18)
This density-potential functional is equivalent to (but more flexible than) the density-only functional E[n, μ](N). The minimisers of E[n] are thus among the stationary points of Eq. (18) and are obtained by solving$${n}_{s}[{V}_{s}-{mu }_{s}]({{{{{{{bf{r}}}}}}}})=frac{delta {E}_{{{{{{{{rm{dis}}}}}}}}}^{{{{{{{{rm{L}}}}}}}}}[{V}_{s}-{mu }_{s}]}{delta {V}_{s}({{{{{{{bf{r}}}}}}}})}$$
(19)
and$${V}_{s}[{{{{{{{bf{n}}}}}}}}]({{{{{{{bf{r}}}}}}}})={V}_{s}^{{{{{{{{rm{env}}}}}}}}}({{{{{{{bf{r}}}}}}}})+frac{delta {E}_{{{{{{{{rm{int}}}}}}}}}[{{{{{{{bf{n}}}}}}}}]}{delta {n}_{s}({{{{{{{bf{r}}}}}}}})}$$
(20)
self-consistently for all ns while enforcing ∫A(dr) ns(r) = Ns. Specifically, starting from V(0) = Venv, such that ({n}_{s}^{(0)}={n}_{s}[{V}_{s}^{(0)}-{mu }_{s}^{(0)}]), we iterate$${n}_{s}^{(i)}mathop{longrightarrow }limits^{{{{{{{{rm{equation}}}}}}}},(20)}{V}_{s}^{(i+1)}={V}_{s}[{{{{{{{{bf{n}}}}}}}}}^{(i)}]mathop{longrightarrow }limits^{{{{{{{{rm{equation}}}}}}}},(19)}{n}_{s}^{(i+1)}=(1-{theta }_{s}),{n}_{s}^{(i)}+{theta }_{s},{n}_{s}left[{V}_{s}^{(i+1)}-{mu }_{s}^{(i+1)}right]$$
(21)
until all ns are converged sufficiently. This self-consistent loop establishes a trade-off between dispersal energy and effective environment V by forcing an initial out-of-equilibrium density distribution to equilibrate at fixed N. We adjust ({mu }_{s}^{(i)}) in each iteration i such that ({n}_{s}^{(i)}) integrates to Ns. Small enough density admixtures, with 0 More