Introduction

Einstein predicted and Perrin verified that, in a gravitational field, the equilibrium (number) density of a dilute dispersion of colloidal particles varied with height z according to

$$\rho (z) = \rho (0)e^{ - z/z_0},$$
(1)

where z0 encodes the equality of diffusive and sedimentation fluxes:

$$z_0 = \frac{{D_0}}{{v_{\mathrm{s}}}},$$
(2)

with vs a particle’s sedimentation speed and D0 its thermal diffusivity. For spheres of radius a in a liquid of viscosity \(\eta _0\) at temperature T with density Δ lower that of the particles \(v_{\mathrm{s}} = 2ga^2{\mathrm{\Delta }}/9\eta _0\) and \(D_0 = k_{\mathrm{B}}T/6\pi \eta _0a\) where kB is Boltzmann’s constant, so that \(z_0 = 3k_{\mathrm{B}}T/4\pi ga^3{\mathrm{\Delta }}\). The verification of Eq. (1) demonstrated the granularity of matter1.

Now suppose \(\eta _0 = \eta _0(z)\), so that the particle dynamics also varies in space: \(D_0 = D_0(z)\). Nevertheless, statistical mechanics stipulates that the spatially dependent dynamical coefficient D0(z) cannot appear in the equilibrium density distribution, and Eq. (1) still holds because the \(\eta\)-dependence cancels out in Eq. (2).

Active colloids2, particles that dissipate energy to propel themselves, form an important class of active matter3,4. Such dissipative states of matter, which include all living organisms, are intrinsically non-equilibrium, and give rise to new physics. Consider a system of run-and-tumble particles (RTPs). An RTP self propels (‘runs’) at velocity v for time \(\tau _{{\mathrm{run}}}\), then changes direction (‘tumbles’) instantaneously to run at v′ such that \(|{\mathbf{v}}\prime | = |{\mathbf{v}}|\) but with randomised direction, so that at times \(\gg\)τrun it behaves as a random walker. Suppose the run speed of such particles is spatially dependent, v(r). Solving a Fokker-Planck equation for the coarse-grained kinetics of RTPs, Tailleur and Cates5,6 predicted that the resulting density distribution should be \(\rho ({\mathbf{r}}) = \rho (0)v(0)/v({\mathbf{r}})\), with 0 an arbitrary origin. A purely mechanical derivation is also possible7. The appearance of the particles’ dynamics, v(r), in this formula contrasts starkly with the sedimentation equilibrium of passive colloids with spatially dependent diffusivity D0(x), for which the D-independent Eq. (1) still holds.

When restricted to 1D, this result becomes

$$\rho (x) = \rho (0)v(0)/v(x),$$
(3)

which was first derived for non-interacting random walkers by Schnitzer8. Later, Tailleur and Cates showed that it is valid for interacting RTPs whose run speed can be expressed as \(v(x) = v[\rho (x)]\)5. Moreover, under quite general conditions, ρv = constant also holds (provided translational diffusion is negligible) for active Brownian particles (ABPs)9, which reorient gradually due to their rotational diffusivity Drot, losing directional memory after a persistence time of ~\(D_{{\mathrm{rot}}}^{ - 1}\). At \(t \gg D_{{\mathrm{rot}}}^{ - 1}\), an ABP is again a random walker.

Qualitatively, Eq. (3) was the basis of recent demonstrations of templated self assembly using light-activated motile bacteria10,11. In a spatially varying illumination pattern, cells accumulate in the darker regions, generating contrast. Quantitatively, however, Eq. (3) has remained unverified by experiments to date. Moreover, its theoretical derivations do not include hydrodynamic interactions, so that its applicability to real systems is open to doubt.

Here, we investigate Eq. (3) quantitatively with the same light-activated Escherichia coli bacteria used previously to demonstrate templated active self assembly10. Our strain’s rapid response to changes in light intensity allows us to impose well defined changes in local swimming speed. Differential dynamic microscopy (DDM)12 has previously been shown to reliably measure swimming speed and density of motile bacteria on uniform samples10,13. Here we develop and demonstrate a spatially resolved implementation (sDDM) for quantitative analysis of \(\bar v(x,y)\) and ρ(x, y) over larger length scales (~mm) with a resolution of ≈100 μm. We use sDDM to confirm that indeed ρ(x)v(x) = constant, provided that steady state is reached.

Results

Light controlled E. coli and spatially resolved analysis

Each E. coli is an ≈2 × 1 μm spherocylinder with ≈7–10 μm helical flagella powered by rotary motors14. When all flagella rotate counterclockwise (seen from behind), they bundle and propel the cell. Every τrun ~ 1 s or so, one or more flagella reverse and unbundle, causing a change in direction: wild-type (WT) cells are RTPs15. At a typical average speed \(\bar v \gtrsim 10\) μm s−1, they random walk with a persistence length \(l_p \sim \bar v\tau _{{\mathrm{run}}} \sim 10\) μm. Deleting the cheY gene prevents tumbling; cells become ABPs with \(D_{{\mathrm{rot}}}^{ - 1} \sim 10\) s and \(l_p \sim \bar vD_{{\mathrm{rot}}}^{ - 1} \sim 100\) μm16, so that at times \(\gg D_{{\mathrm{rot}}}^{ - 1}\) cells random walk with \(D_{{\mathrm{eff}}} \sim \bar v^2D_{{\mathrm{rot}}}^{ - 1} \sim 10^3\) μm2 s−1.

Our E. coli mutants carried a plasmid expressing proteorhodopsin (PR), which pumps protons when exposed to green light17. Cells suspended in nutrient-free motility buffer were sealed into 20 μm high compartments and imaged using 10× phase contrast microscopy. After some minutes, \(\bar v\) dropped abruptly to zero upon oxygen exhaustion10. Thereafter, cells only swam when illuminated in green10,18,19, with an average speed \(\bar v\) that increased with the light intensity, \({\cal{I}}\), saturating at vmax beyond some \({\cal{I}}_0\)10. These are living analogues of synthetic light-activated active colloids20,21.

We first used a digital mirror device10 to project a binary (bright-dark) spatial intensity pattern \({\cal{I}}(x,y)\) spelling out ‘UoE’ (inset of Fig. 1a) onto a field of cells that had been uniformly illuminated for some time, so \(\bar v\) was initially constant in space. We used sDDM to measure \(\bar v(x,y)\), β(x, y) and ρ(x, y) in 64 × 64 (pixel)2 tiles (see Methods section and Supplementary Note 1 for details). The projected \({\cal{I}}(x,y)\) was rapidly replicated in a pattern of \(\bar v(x,y)\) (Fig. 1a). A similar ρ(x, y) pattern soon forms (Fig. 1b) so that this effect can be used for templated self assembly10,11. Given that higher cell densities occur in darker regions with lower swimming speed, Eq. (3) is clearly qualitatively correct10,11. We now proceed to test it quantitatively.

Fig. 1
figure 1

Demonstration of spatial-resolved differential dynamic microscopy. Projecting light patterns onto a sample of light-powered E. coli AD10 (at OD = 1) leads to a spatial variation of the mean swimming speeds \(\bar v\). a Map of \(\bar v\) as measured by sDDM when the negative ‘UoE’ pattern shown in inset is projected onto the sample. b Phase contrast image about 20 s after applying the pattern, showing accumulation in the darker regions. Magenta lines indicate the square tiles of 64 pixels (90 μm) size used for the sDDM analysis

We projected a quasi-1D stepped illumination pattern

$${\cal{I}}(x,y) = \left\{ {\begin{array}{*{20}{l}} {{\cal{I}}_ + < {\cal{I}}_0,} \hfill & {x < 0} \hfill \\ {{\cal{I}}_ - < {\cal{I}}_ + ,} \hfill & {x > 0} \hfill \end{array}} \right.$$
(4)

on a field of these cells. This generated a spatial pattern of swimming speed, \(\bar v(x,y)\), and cell density, ρ(x, y), which we quantified using sDDM. Averaging over y gives \(\bar v(x)\) and ρ(x), which allows a direct test of Eq. (3), provided that this light pattern (Eq. (4)) generates a corresponding sharp pattern of cell run speeds:

$$\bar v(x) = \left\{ {\begin{array}{*{20}{l}} {\bar v_ + ,} \hfill & {x < 0} \hfill \\ {\bar v_ - < \bar v_ + ,} \hfill & {x > 0} \hfill \end{array}} \right..$$
(5)

This requires cells that respond rapidly to changes in \({\cal{I}}\), which was found not to be the case10 for previous PR-expressing mutants with otherwise intact metabolism18. Indeed, a recent attempt to verify Eq. (3) using PR-bearing E. coli found instead (in our notation) \(\rho = (a/\bar v) + b\) with positive constants a and b. The latter was ascribed to a long τstop, which led to memory effects11.

We achieved rapid response by deleting the unc gene cluster encoding the F1Fo-ATPase membrane protein complex from a parent K12-derived ΔcheY mutant, giving a fast-responding smooth-swimmer, AD1010. In fully-oxygenated phosphate motility buffer (MB) at optical density OD = 1, \(\bar v \approx 30\) μm s−1 and a fraction \(\beta \lesssim 20\%\) of cells were non-motile. When illuminated anaerobically, \(\bar v_{{\mathrm{max}}} = 28\) μm s−1 and \(\tau _{{\mathrm{stop}}} \ll 1\) s, compared with a τstop of many minutes in the parent strain without unc deletion10. (Details of other strains we used are given in the methods section.)

Strictly speaking, a non-interacting limit does not exist for bacterial suspensions22. Cells interact hydrodynamically at any concentration, although simulations show that swimmers behave effectively as non-interacting when ρ/\(\rho _c \lesssim 0.1\), where ρc is the density for the onset of collective behaviour. We observed collective motion in our E. coli suspension at \({\mathrm{OD}} \gtrsim 10\), corresponding to a cell body volume fraction of \(\phi \gtrsim 1.4\%\), consistent with a previous estimate of 2%22,23, so that a quasi-non-interacting limit is reached at \({\mathrm{OD}} \lesssim 1\). It was not possible to work below this limit because of an increasing fraction of cells trapped in circular trajectories (due to hydrodynamic interactions with walls of the sample chamber24) that did not explore the whole sample compartment, hindering relaxation towards a steady state. We therefore worked at OD ≥ 1. We report first data for OD = 5 (ρ ≈ 5 × 109 cells/ml; \(\phi \approx 0.7\%\)) before discussing OD = 1, where the data are noisier due to lower cell numbers.

Stepped light pattern at OD = 5

A field of AD10 cells rendered stationary by oxygen exhaustion was uniformly illuminated for ≈20 min to achieve saturation speed10. The light was then attenuated to \({\cal{I}}_ -\), the level of the darker half of the target pattern (Eq. (4)) for 5 min to determine \(\bar v_ - = 6.5(2)\) μm s−1. Returning the intensity to its initial level, we waited another 5 min for the swimming speed to return to \(\bar v_ + = 13.2(2)\) μm s−1. We measured the cell density ρ0 and non-motile fraction β0 of this high-speed uniform sample, and then switched on a stepped pattern (Eq. (4)) by reducing the intensity in the x > 0 half plane.

Figure 2a shows the mean swimming speed averaged over y tiles, \(\langle \bar v(x,y)\rangle _y = \bar v(x)\), normalised to the whole-sample-averaged speed, \(\langle \bar v\rangle\), plotted against x at 30 min after switching on the stepped pattern. A stepped speed pattern was developed (Fig. 2a, black circles).

Fig. 2
figure 2

Response of AD10 at OD = 5.3 to a stepped intensity pattern. a Normalised quantities as indicated vs. x after ≈30 min of stepped illumination, and predictions for normalised ρs based on two speeds (dotted line) and complete measured \(\bar v(x)\) profile (dashed line). Error bars are s.e.m. of the y-averaged values. b Time dependence of normalised \(\rho^{\mathrm{s}} \bar v\) at various x (see legend). The sample was uniformly illuminated before the halves pattern was switched on at \(t = 0\). In both plots the grey area corresponds to the standard deviation in experimental values for uniform illumination (\(t < 0\))

If Eq. (3) is valid, we expect the swimmer density to obey

$$\rho _ + ^{\mathrm{s}}(x)\bar v_ + (x) = \rho _ - ^{\mathrm{s}}(x)\bar v_ - (x),$$
(6)

where ‘±’ subscripts having their obvious meanings. If the density of non-motile cells is constant throughout the experiment (see Supplementary Note 2 for justification), i.e.

$$\rho _ \pm ^{{\mathrm{nm}}} = \beta _0\rho _0,$$
(7)

we can write the total cell density on the two sides of x = 0 as

$$\rho _ \pm = \rho _ \pm ^{\mathrm{s}} + \rho _ \pm ^{{\mathrm{nm}}} = \rho _ \pm ^{\mathrm{s}} + \beta _0\rho _0.$$
(8)

Finally, the average cell density is

$$\rho _0 = \frac{1}{2}(\rho _ + + \rho _ - ).$$
(9)

Equations (6)–(9) together predict the density of motile cells in the two half-planes:

$$\rho _ \pm ^{\mathrm{s}} = \frac{{2\rho _0(1 - \beta _0)}}{{1 + {\textstyle{{v_ \pm } \over {v_ \mp }}}}}.$$
(10)

We calculated the swimmer density in our experiments from the measured total cell density ρ(x) and non-motile fraction β(x) using \(\rho ^{\mathrm{s}}(x) = \rho (x)[1 - \beta (x)]\), and normalised it by the whole-sample-averaged swimmer density. This function 30 min after the imposition of the stepped intensity pattern is also stepped (Fig. 2a, blue squares), with the theoretical predictions from Eq. (10), using the measured average v± as inputs (Fig. 2a, dotted line), giving a reasonable account of the step amplitude. A more sophisticated version of this model which takes the measured shape of \(\bar v(x)\) into account (see Supplementary Note 2 for details) is able to capture the amplitude of the jump in ρs(x) at x = 0 even more precisely (Fig. 2a, dashed line).

The product \(\rho ^{\mathrm{s}}\bar v(x)\) normalised to the whole sample average (Fig. 2a, red x’s), is indeed constant for \(|x| \lesssim 200\) μm, verifying Eq. (6), which is the application of Eq. (3) to our conditions. However, there are systematic deviations from constancy at \(|x| \gtrsim 200\) μm. One possible explanation is the emergence of collective motion with associated local nematic ordering25, which would invalidate the derivation of Eq. (3). However, we only observed collective motion at \({\mathrm{OD}} \gg 10\). Instead, the deviation of \(\rho ^{\mathrm{s}}\bar v\) from constancy at \(|x| \gtrsim 200\) μm is a kinetic effect. Figure 2b shows the time evolution of the normalised \(\rho ^{\mathrm{s}}\bar v(x)\) at different x. Steady state was reached rapidly for \(|x| \lesssim 200\) μm, but was not reached by 30 min at the extremes of our observation window, \(|x| \gtrsim 600\) μm. Given their effective diffusivity Deff ~ 103 μm2 s−1, cells at the extremities of our compartment take \(\gg\)30 min to sufficiently sample both speed regions, preventing the attainment of steady state within our observational time window. This leads to the deviations between observed and predicted ρs(x) away from x = 0. Nevertheless, Fig. 2b suggests that \(\rho ^{\mathrm{s}}\bar v\) = constant should be attained at all x in the long-time limit.

Stepped pattern at other cell densities

Measurements and model predictions for the lower OD = 1 are shown in Fig. 3. The data are noisier, but show the same trends. In the vicinity of x = 0, \(\rho ^{\mathrm{s}}\bar v\) ≈ constant. To highlight the behaviour in the two 90 μm-wide stripes of tiles bordering x = 0, we plot \(\rho ^{\mathrm{s}}\bar v(x)\) at t = 30 min for these two stripes against each other for a number of independent experiments (Fig. 4, black solid circles). In all cases, \(\rho ^{\mathrm{s}}\bar v(x)\) = constant for these central stripes to within experimental uncertainties. The ratio of \(\rho ^{\mathrm{s}}\bar v(x)\) in these two stripes plotted against the ratio of the swimming speed on the two half-planes (Fig. 4 inset, black solid circles) is consistent with this claim.

Fig. 3
figure 3

Response of AD10 at OD = 1 to a stepped intensity pattern. The same quantities as in Fig. 2 are shown. Qualitatively the behaviour is the same as for the higher density, but the data are noisier due to the overall weaker signal. See Supplementary Figs. 4 and 5 for spatial maps and time evolutions, respectively

Fig. 4
figure 4

\(\rho ^{\mathrm{s}}\bar v\) either side of an intensity step for various sample densities and speed ratios. The main plot shows \(\rho ^{\mathrm{s}}\bar v\) for the first tile on the slow (–) side vs. the same quantity for the first tile on the fast (+) side for several independent datasets. For both low density (filled symbols) as well as higher-density datasets (open symbols) Eq. (6) holds. This is also demonstrated in the inset, which shows (\(\rho _ - ^{\mathrm{s}}\bar v_ -\)/(\(\rho _ + ^{\mathrm{s}}\bar v_ +\)) vs. \(\bar v_ -\)/\(\bar v_ +\) for the same datasets. Error bars show s.d.

We performed experiments using the stepped light pattern at other cell densities and also using an additional smooth swimming strain (DM1). In all cases up to OD = 8, we find that \(\rho ^{\mathrm{s}}\bar v (x)\) is constant across the two central stripe of tiles on either side of x = 0 (Fig. 4), where we are certain that a steady state has been reached, verifying Eq. (3) up to ρ ≈ 8 × 109 cells/ml. Spatial maps and time evolution of spatial profiles for our highest density sample (OD = 8) are shown in Supplementary Figs. 6 and 7, respectively.

Measurements using a periodic light pattern

The complicating factor so far is the slow global convergence towards ρs(x)v(x) = const, so that steady state will only be reached in approximately hours. Experiments on such time scales are impractical due to mechanical and biological stability issues. Thus, we only have direct evidence for the validity of Eq. (3) in the vicinity of the intensity step at x = 0. This suggests that the use of a series of thin stripes would give more clear-cut results unencumbered by kinetic issues. We found that this was indeed the case.

In response to the imposition of a one-dimensional square-wave illumination pattern of brighter-darker stripes with 540 μm repeat generated by a digital mirror device10, the swimming speed of bacteria changed from a uniform distribution to a square-wave distribution almost instantaneously (in \(\lesssim\)1 s) (Fig. 5a). This in turn modified the cell density (initially uniform at OD = 1), which approached a steady state much more quickly. This is possible not only because of the length scale reduction, but also because swimmers can enter (say) a high-intensity region from low-intensity regions on both the left and right.

Fig. 5
figure 5

Response of bacteria to the imposition of a 1D square wave with 270 μm wide stripes. a The evolution of the speed profile normalised to its (time) average, with time increasing from red to violet (legend gives t in minutes): initially illumination is uniform, with the intensity getting increased from low to high at t = −7 min, then the pattern is applied at t = 0 for 15 min. b The spatial profiles of various normalised quantities as indicated in the legend after 15 min of patterned illumination. Error bars represent s.d. Dashed line (and grey area) is the average (±1 s.d.) over all tiles for the uniform case (t < 0). Error bars show propagated s.e.m.

Figure 5b shows the normalised swimmer density \(\rho ^{\mathrm{s}}(x)\)/\(\langle \rho ^{\mathrm{s}}\rangle\) after 15 min of patterned illumination, together with \(\bar v(x)\)/\(\langle v\rangle\) and their product. While the data are again somewhat noisy because of the low average cell density (OD = 1), it is clear that \(\rho ^{\mathrm{s}}\bar v (x)\) = constant to within one standard deviation, which directly verifies Eq. (3).

Experiments with β(I) dependency

Interestingly, experiments using low light intensities (which gave low swimming speeds) proved less successful, because at very low intensities we found a noticeably higher percentage of non-motile cells in the sample than at high light intensities (Supplementary Fig. 8). This led to a spatial variation in the non-motile density (Supplementary Fig. 9), which considerably complicates the interpretation and analysis of such experiments (see Supplementary Note 3 for details).

Experiments using light-powered run-and-tumble strain

We end by explaining why we did not use motility wild-type (run and tumble) strains for our experiments. Their motion randomises much more rapidly than smooth swimming mutants, which would have significantly alleviated the non-steady-state issue for the stepped intensity pattern. However, we found that AD4, a PR-bearing motility wild type, gathered near x = 0, on the darker side of the intensity step (see Supplementary Figs. 10 and 11 and Supplementary Note 4 for details). From the q-dependence of our DDM data13 we can deduce that the tumbling rate increases noticeably as cells swim from light to dark, whereas cells swimming from dark to light do not show any obvious change in their tumbling behaviour. This may be due to ‘energy taxis’26. The validity of Eq. (3) depends on the assumption that the tumbling rate is independent of swimming direction5,8, so that motility wild types cannot be used to test this result.

Discussion

Equation (3) is one of only a handful of exact predictions to date on the statistical mechanics of active particle systems. Its ‘weak’ form, for non-interacting systems was derived for RTPs8, while its ‘strong’ form was later derived both for RTPs5 and ABPs9. Taken together, our experiments using stepped and stripped light patterns give strong evidence that Eq. (3) holds at 1 ≤ OD ≤ 8 (\(0.15\% \lesssim \phi \lesssim 1.2\%\)) for smooth swimming E. coli whenever we can be sure that steady state has been reached, either in the vicinity of x = 0 in the stepped pattern or throughout the stripped pattern. Our swimmers are interacting throughout our concentration range22, even though collective motion is not observed until OD >> 10. Thus, our results verify the ‘strong’ form of Eq. (3) for ABPs.

The qualitative validity of Eq. (3), viz., that cells gather where they swim slower, or, equivalently for our cells, where the light intensity is lower, has already been assumed and utilised in recent work deploying such cells in smart (or reconfigurable) templated self assembly, or ‘painting with bacteria’10,11. Indeed, in a recent demonstration of how to perform bacterial painting with multiple shades of graded intensity levels11, there was attempt at checking the correctness of Eq. (3) en passant, which, however, was unsuccessful because of a high number of non-motile cells and the long stopping time of their strain, the latter producing memory effects. Our success in verifying Eq. (3) shows that carefully quantifying and subtracting the non-motile fraction and the use of a strain of bacteria with very short stopping time are essential ingredients in such an experiment. Indeed, without careful design most ‘real’ active systems are likely to display dynamic behaviour that is too complex to fulfil the assumptions leading to Eq. (3), as evidenced by our findings for the wild type strain with illumination-dependent tumbling rate. Note, however, that ‘smart templated active self assembly’10 using photo-activated swimmers is possible for any relationship of ρv in which the increase in one variable necessitates the decrease in the other.

Our experiments would not have been possible without spatially resolved differential dynamic microscopy (sDDM), which can reliably quantify swimming speed and relative density (along with many other parameters) over a wide range of length scales and cell concentrations. Its adoption can therefore provide new insights into a variety of systems displaying spatially varying dynamics, from biological taxis27 to collective motion.

Throughout, we have focussed on steady-state effects, although the consideration of time dependence proved crucial in interpreting apparent systematic deviations from the prediction of Eq. (3) for imposed stepped intensity patterns. Time-dependent effects are, of course, interesting in their own right. Thus, the response of active particles to a time-dependent topographic landscape that is self-assembled by the cells themselves9 has yet to be explored experimentally. On the other hand, it has recently been suggested theoretically28 and demonstrated experimentally29 that travelling-wave light fields can be exploited for transporting and rectifying light-activated swimmers. Exploitation of these and other opportunities should open up new fields of fundamental studies and applications.

Methods

Strains and sample preparation

We constructed three different strains of E. coli using plasmids expressing SAR86 γ-proteorhodopsin (a gift from Jan Liphardt, UC Berkley). These strains were designed to exhibit a fast response to changes in light intensity. This was achieved by deleting the unc gene cluster, so that the F1F0-ATPase membrane protein complex cannot work in reverse in the dark to generate proton motive force to power swimming. The detailed molecular biology and strain characterisation have been reported before10. AD4 is a WT (run-and-tumble) swimmer derived from AB1157, whereas DM1 and AD10 are smooth swimming strains derived from RP437 and AB1157, respectively (see Supplementary Table 1). The two smooth swimming strains behaved similarly, although AD10 achieved a much higher swimming speed than DM1 and was also more efficiently powered by light. Therefore we mostly used AD10, with some additional data acquired using DM1.

Overnight cultures were grown aerobically in 10 mL Luria-Bertani Broth (LB) using an orbital shaker at 30 °C and 200 rpm. A fresh culture was inoculated as 1:100 dilution of overnight grown cells in 35 ml tryptone broth (TB) and grown for 4 h to an optical density of OD600 ≈ 0.2. The production of proteorhodopsin (PR) was induced by adding arabinose to a concentration of 1 mM as well as the necessary cofactor all-trans-retinal to 10 μM to the growth medium. Cells were incubated under the same conditions for a further hour to allow protein expression to take place and then transferred to motility buffer (MB, pH = 7.0, 6.2 mM K2HPO4, 3.8 mM KH2PO4, 67 mM NaCl and 0.1 mM EDTA). Single filtration (0.45 μm HATF filter, Millipore) was used to prepare high density stock solutions (OD ≈ 8) which were diluted with MB to the desired cell concentration.

The samples were loaded into commercial 2 μL sample chambers (SC-20-01-08-B, Leja, NL) of dimensions ≈ 6 × 10 mm × 20 μm, where cells predominantly swim in the (x, y) (imaging) plane, but have enough room to ‘overtake’ each other in all three spatial dimensions. The chamber was then sealed using vaseline to stop air flow, so that swimming stopped once dissolved oxygen was exhausted19. This happened within 10 min at OD ≈ 1 (≈109 cells/ml or 0.2% volume fraction of cell bodies). Thereafter, we controlled the activity of the cells by illuminating with green light of various intensities10.

Experimental setup

The samples were observed using a Nikon TE2000 inverted microscope with a PF 10×, N.A. 0.3 phase contrast objective. Time series of movies (~40 s duration at 100 frames per second) were recorded using a CMOS camera (MC 1362, Mikrotron). A long-pass filter (RG630, Schott Glass) in the bright-field light path ensured that the imaging light did not activate PR. The light controlling bacterial swimming was provided by an LED (Sola SE II, Lumencor) whose intensity was set via a computer interface. The LED light was filtered to a green wavelength range (510–560 nm) overlapping with the absorption peak of our PR18 and illuminated the sample in a trans-illumination geometry. By illuminating an area much larger than the field of view of the objective, we minimised the loss of swimmers over time. If only a small region of the sample is illuminated, the density of swimmers continuously drops, because they reach the illumination boundaries and accumulate there (no light = no swimming). For the stepped pattern experiment we uniformly illuminated a ≈7 mm diameter circle, covering almost all of the sample chamber. Under these conditions the cell density is conserved, thus simplifying theoretical modelling. We used a thin sheet polariser imaged onto the sample plane to attenuate the intensity on half of the sample. A digital mirror device10 projected the periodic pattern onto a ≈2.9 mm diameter area of the sample.

Differential dynamic microscopy

DDM measures \((\bar v,\beta )\) averaged over 104–105 cells under our conditions13,19,30. From ≈40 s of wide-field, low-magnification movies, one extracts the power spectrum of the difference between pairs of images delayed by time τ, \(g(\vec q,\tau )\), where \(\vec q\) is the spatial frequency vector. Under suitable conditions and for isotropic motion, the intermediate scattering function f(q, τ), the qth mode of the density autocorrelation function, is given by

$$g(q,\tau ) = A(q)[1 - f(q,\tau )] + B(q).$$
(11)

Here, B(q) relates to the background noise and A(q) is the signal amplitude. Fitting f(q, τ) to a suitable swimming model of E. coli yields four key motility parameters: the mean \(\bar v(q)\), and width σ(q) of the speed distribution P(v), the non-motile fraction β(q), and the diffusion coefficient of non-motile cells D(q), as a function of q. All of these should, ideally, be q-independent. In practice, there is some q-variation. We typically averaged the fitting parameters over \(0.5 < q < 2.2\,\upmu {\mathrm{m}}^{ - 1}\) to give, e.g. \(\bar v = \langle v(q)\rangle _q\) and \(\beta = \langle \beta (q)\rangle _q\).

In a dilute system whose structure factor \(S(q) \approx 1\), A(q) is proportional to the sample density31,32 and can therefore be used to determine relative densities by \(\rho _1/\rho _0 = \langle A_1(q)/A_0(q)\rangle _q\)10. Note that ratioing the A(q)s removes their strong q-dependence.

Spatially resolved DDM (sDDM) is in principle straightforward: the above algorithm simply needs to be implemented on p × p (pixel)2 sub-movies. In practice, care is required in choosing the minimum p for which meaningful results can be obtained. We do this by illuminating a field of cells uniformly, measuring \((\bar v,\beta ,\rho ,\rho ^{\mathrm{s}}v)\) from individual p × p tiles in the steady state, and obtaining the probability distribution of these parameters. Under our imaging conditions, we found that these distributions became p-independent when \(p \ge 64\). We therefore chose \(p = 64\), corresponding to 90 μm in the sample (see Supplementary Note 1 for details).

A full 512 × 512 movie yields g(q, τ)s at 512/2 = 256 distinct q values. We divide it into 64 sub-movies of size 64 × 64 (pixel)2. This yields 8 × 8 × (64/2) = 2048 g(q, τ)s to be fitted to give for each sub-movie \(v_{x,y}(q)\), \(\beta _{x,y}(q)\) and \(\rho _{x,y}(q)/\rho _0 = A(q)_{x,y}/A_0(q)\), where A0(q) is measured from the same sample under uniform illumination (i.e. just before switching to a structured light pattern). These were averaged over \(0.5 \le q \le 1.5\,\upmu {\mathrm{m}}^{ - 1}\). The upper q limit is somewhat lower than what is typical for whole-movie analysis13 due to non-systematic failure of fitting at higher q values, presumably due to noise or windowing artefacts33.