Realization of a motility-trap for active particles

Trapping of atomic and mesoscopic particles with optical fields is a practical technique employed in many research disciplines. Developing similar trapping methods for self-propelled, i.e. active, particles is, however, challenging due to the typical anisotropic material composition of Janus-type active particles. This renders their trapping with magneto-optical fields to be difficult. Here we present the realization of a motility-trap for active particles, which only exploits their self-propulsion properties. By combining experiments, numerical simulations, and theory, we show that, under appropriate conditions, a force-free rotation of the self-propulsion direction towards the trap's center can be achieved, which results in an exponential localization of active particles. Because this trapping mechanism can be applied to any propulsion scheme, we expect such motility-tweezers to be relevant for fundamental studies of self-driven objects as well as for their applications as autonomous microrobots. An outstanding challenge in active matter physics is to control the motion of active particles. Here, the authors present a motility trap that can be applied to any self-propulsion scheme, and combine experiments, theory, and simulations to demonstrate robust spatio-temporal control of active particles.


Results
Outline of the experimental approach. APs are made from colloidal silica particles with a diameter σ = 3.25 μm, which are half-coated with a 50-nm carbon layer on one hemisphere and afterwards suspended in a critical mixture of water and 2,6-lutidine (lutidine mass fraction 0.286). The temperature of the entire sample cell is kept constant several degrees below its lower critical point T c = 34.1°C 43,44 . Due to gravity, the particles are confined to the bottom of the sample cell where they perform a twodimensional motion. Under laser illumination (λ = 532 nm), light is mainly absorbed at the carbon cap, leading to the preferential heating of the cap. Once the cap temperature exceeds, T c , this results in a local demixing of the adjacent fluid. In our experiments, such conditions are achieved above a threshold intensity of I 0~0 .08 μW μm −2 . Depending on the light intensity, the demixing region is characterized by a single or (at higher intensities) two single-phase droplet(s) that nucleate around the particle. The droplet's asymmetrical shape leads to a propulsive velocity v, which depends on the light intensity in a strongly nonmonotonic fashion (Fig. 1a) 43,45 . While v linearly increases at sufficiently low intensities, it sharply reverses its direction n relative to the cap above a certain intensity threshold I r~0 .58 μW μm −2 when a second droplet covers the uncapped surface (see Fig. 1a and "Methods" for details). Due to the additional presence of rotational diffusion (D r~1 /50 s), the APs perform an unbiased persistent random motion under homogeneous illumination conditions.
In the presence of a light gradient ∇I, the shape of the nucleating droplets around the APs is no longer symmetric relative to n. As a consequence, AP motion becomes strongly biased leading to a phototactic behavior 43 . Depending on whether the illumination intensity is below or above I r , APs will Fig. 1 Light-activated motion. a Measured propulsion velocity v of the active particle (AP) vs. illumination intensity I. Above a threshold intensity I 0~0 .08 μW μm −2 the propulsion mechanism sets in, leading to selfpropulsion. The vector n corresponds to the direction of propulsion and reverses its sign at the critical intensity I r . b Example of measured trajectories of an AP in a static light gradient ∇I. Below I r the AP moves opposite to ∇I (negative phototaxis, blue trajectory and background). Above I r the particle moves along ∇I (positive phototaxis, red trajectory and background). Time evolution of the angle ϕ between the propulsion direction of the AP and the direction of the light gradient, after the AP is suddenly exposed to the light gradient for intensities c below I r and d above I r . Squares denote averaged data, and the full line shows the theoretical fits. In both cases, an identical light gradient of intensity ∇I j j= 0.1 μW μm −3 was used. Inset: Sketch of an AP in a positive and negative light gradient together with the resulting angular velocity ω at which the AP rotates when the light gradient is switched on. Error bars denote the standard deviation.
experience an aligning torque leading to their propulsion opposite (negative phototaxis) or along ∇I (positive phototaxis), respectively (Fig. 1b). To characterize the particle's alignment, we have measured their reorientation dynamics within a light gradient. Experimentally, this was achieved by suddenly turning on a light gradient in x-direction when the particle propulsion direction n was pointing along the positive x-direction (dashed line in the insets of Fig. 1c). As a result of the droplet's asymmetry, the particle will realign until n is antiparallel (negative phototaxis) or parallel (positive phototaxis). This orientation process is shown in Fig. 1c, with ϕ being the angle between n and the x-direction (see inset).
Theoretical model. To describe our experimental findings, we consider the motion of an overdamped self-propelled particle whose propulsion velocity v(x) varies in space and which can align parallel or antiparallel to the local intensity gradient depending on the tactic condition. This leads to the following Langevin equations for the center of mass position r(t) = (x(t), y (t)) and the self-propulsion direction n = (cos(ϕ), sin(ϕ)) expressed by its angle ϕ with the x-axis (see ref. 46 for details) Here with zero mean and unit variance, and D and D r correspond to the translational and rotational diffusion coefficients, respectively. As will be later shown in our experiments, the key mechanism for the motility trap is the active alignment of APs relative to the local intensity gradient. The instantaneous alignment rate ω depends on both the surface-averaged total velocity of the solvent around the AP and its asymmetry relative to the AP orientation 47 . Since the magnitude of the surface-averaged flow velocity also controls the self-propulsion speed 47 , on the one hand, we expect ω ∝ v. On the other hand, the dependence of ω on the flow field asymmetry suggests ω ∝ |∇I| or ω / v 0 x ð Þ ¼ dvðxÞ=dx. This leads to the following overall expression for the phototactic alignment rate ω ϕ; x ð Þ ¼ c σ v x ð Þv 0 x ð Þsin ϕ (see ref. 46 regarding the determination of the coefficients). Here, we have introduced the particle diameter σ occurring in the denominator since alignment competes with the rotational drag, the latter linearly scaling with σ. Finally, the coefficient c, a parameter fixed by experiments, determines if phototaxis is positive (c < 0) or negative (c > 0) (see "Methods" for further details). With this form for the alignment rate, the orientational dynamics, as obtained from the noise-free solution of (1) and (2), is in good agreement with the experimental observations, see Fig. 1c, d.
Realization of an AP motility trap. A motility trap requires a position-dependent AP realignment mechanism, which prevents it from leaving a certain spatial region. In our experiments, this is achieved by a spatial light profile, which is created by periodically scanning a line-shaped laser beam with a mirror across the sample plane (see "Methods"). Synchronization of the mirror motion with an electro-optical intensity modulator yields to illumination of APs with arbitrary one-dimensional illumination profiles (Fig. 2a). Since the scanning frequency of the mirror is set to 200 Hz, this leads to quasi-static illumination conditions for the APs. In our experiments, we created triangular-shaped intensity fields with either an intensity minimum (Fig. 2b) or an intensity maximum (Fig. 2c), each characterized by the width of l v , which has been varied between 8 and 300 µm. The profile in Fig. 2b varies between I = 0.08 and 0.4 µW µm −2 , with the intensity minimum located at x = 0. Since the intensities are below I r , under such conditions APs will always align towards the intensity minimum, that is, opposite to ∇I (see Fig. 1b). Conversely, for the profile shown in Fig. 2c, the intensity varies between I = 0.58 and 0.9 µW µm −2 , with the maximum at x = 0. Because this intensity range is above I r , here APs align towards the intensity maximum, that is. parallel to ∇I (see Fig. 1b).
We start by a qualitative discussion of the experimental results for the conditions shown in Fig. 2b. In addition to affecting the alignment of APs, a position-dependent light field I(x) leadws to a spatial variation of self-propulsion velocity v(x) shown in Fig. 2d. b Spatial intensity profile of a "cooling trap." The blue line describes the intensity profile of a one-dimensional triangle-shaped light field with period length l v = 150 µm. The intensities are within the range where the particle displays negative phototaxis, that is, above the threshold intensity I 0 , but below the critical intensity I r . Superposed are subsequent snapshots of a typical active particle's (AP) dynamics in such a trap, where the blue arrow describes the direction of motion of the particle. c Same as in b but for a "heating trap": the red line describes the intensity profile of the light field, which is in the range of positive phototaxis, that is, above the critical intensity I r . For a cooling trap: d shows the x-component of the active particle's velocity, v(x), for outward motion (empty squares) and inward motion (filled circles); e shows an example of an AP's trajectory relative to the trap center (horizontal line at x = 0), and f its positional probability distribution P(x). For a heating trap, the corresponding (g) inward and outward velocities v(x) (h) AP typical motion relative to the trap center, and i its P(x). Error bars correspond to the standard deviation.
The values of v(x) were obtained from the spatially resolved analysis of the particle's trajectories and agree with the values shown in Fig. 1a considering a piecewise linear intensity profile (Fig. 2b). To rule out the possible influence of optical forces acting on the APs, v(x) was independently determined for the inward (towards x = 0) and outward (away from x = 0) particle motion. The data show the identical results, which confirm the absence of optical gradient forces in our experiment.
The dynamics of the AP within the intensity profile is shown in Fig. 2e. When the particle propels away from the intensity minimum, the light gradient reverses its self-propulsion direction, thus leading to an effective trapping mechanism. Because the AP cannot instantaneously change its orientation but with a rate which is limited by viscous friction, it significantly overshoots the trapping center, which causes the oscillations around the trapping center seen in Fig. 2e. This spatial confinement is confirmed by the corresponding particle probability distribution function (PDF) (Fig. 2f). Since the AP becomes localized around the position where v(x) is smallest, in the remainder we refer to such conditions as a "cooling trap," in analogy to cold atoms remaining in the vicinity of the minimum of an optical trap 48 .
In addition, we also performed similar measurements for the light field shown in Fig. 2c, which features a maximum in the center and where the intensities are above I r . Then, the APs exhibit a positive phototactic response, that is, its swimming motion is biased in the direction of ∇I. As for the cooling trap, the AP's velocity linearly depends on the local light intensity (Fig. 2g), but with the trajectory now being localized around the intensity maximum (Fig. 2h), which spatial confinement is confirmed by its P(x) (Fig. 2i). Since v(x) is largest at these regions, this explains why the oscillations become significantly enhanced compared to Fig. 2e. In the following, we refer to such trapping conditions as a "heating trap." As already discussed, the spatial confinement of APs within a motility trap is governed by their orientational response to the light gradient. We quantify this in Fig. 3a, b by plotting the characteristic alignment time τ, defined as the time needed for a rotation of the AP between ϕ = 0.14 and 3 rad, as a function of ∇I (see "Methods" for further details). The alignment time monotonically decreases with increasing |∇I|. In addition, τ decreases when I increases (apart near I r where the AP motion becomes instable) because of the stronger solvent flow near the particle 46 . This latter dependence also explains why the reorientation dynamics for the cooling trap is slower than that of a heating trap (Fig. 2e, h).
To obtain the relationship between the alignment time and the widths of the particle PDFs within the motility traps, we have varied the intensity profile width l v , which leads to different intensity gradients. The resulting PDF for the cooling and the heating trap both show a maximum at the trap center with exponentially decaying tails at both sides. As expected, the localization becomes more efficient when the alignment time τ becomes faster, that is, when |∇I| increases (symbols in Fig. 3c, d). The observed shape of the PDF is in stark contrast to an AP without active alignment where it simply follows an effective Boltzmann distribution 49 . cosðϕ ω max Þþ1 sinðϕ ωmax Þ , whereC is the fitting parameter and the total rotation ϕ ω max ¼ 3 rad. Experimental data are averaged over 10 repetitions for each curve. c, d Corresponding probability distribution function of the particle's position (x) rescaled by the particle size (σ) in log-lin and (as inset) lin-lin scale. Error bars correspond to the standard deviation.
As a first test of the validity of our theoretical model, we now determine the PDF of APs in the trap by performing Brownian dynamics simulations for an ensemble of particles, initialized in the vicinity of the trapping center, with random initial conditions. As shown in Fig. 3c, d (solid lines), the resulting distributions are in quantitative agreement with our experiments. For positive phototaxis, we obtain a comparatively high propulsion velocity near the trap center ("heating"); in contrast, the velocity is smallest near the trapping center for the "cooling" trap. In both cases, the particle distribution decays exponentially as the distance from the center decreases (Fig. 3c, d ), which leads to a saturation of the mean-square displacement, see Fig. 4a, b.
To further characterize the properties of the motility trap, we also perform analytical calculations to determine the steady-state particle distribution. For weak noise, this yields the following approximate expression for the PDF (see "Methods" for calculation details): Here the B 2 term in the denominator of Eq. (3) is mainly relevant near the trapping center x = 0. Since B(x) decays faster in x for small particle-size (σ) values than for large ones, it follows from Eq. (3) that the tails of the PDF decay faster in x for small particles. This corresponds to the fact that ω ∝ 1/σ in Eq. (2), mirroring the fact that larger APs turn slower in a given gradient than small APs. In addition, Eq. (3) shows that the tails of the PDF decay faster as the slope of the gradient increases. Physically, this is because steep gradients bias the propulsion direction of APs more efficiently towards the trapping center than shallow gradients.
Mean-square displacement and dynamical correlations. To characterize the AP dynamics within a motility trap, we now perform Brownian dynamics simulations of our model (details in "Methods" section) and compare our results with experiments. This leads to a close quantitative agreement without any adjustable fitting parameters (see Fig. 4).
We first discuss the translational and rotational mean-square displacement (Fig. 4). Notice first that there is a plateau occurring in the mean-square displacement x t ð Þ À xð0Þ ð Þ 2 , which represents (permanent) trapping in x direction. That is, we can define (the square of) a length scale corresponding to the confinement length by The confinement length decreases as the depth of the trap V max increases.
In Fig. 4b, we observe peaks preceding the onset of the plateau. These peaks correspond to the average time an AP needs for a "roundtrip" in the trap, which we denote with T osc . Accordingly, the time between t = 0 and the first maximum of x t ð Þ À xð0Þ ð Þ 2 is T osc =2. For example, particles that are close to the trapping center at a given time move ballistically outwards and, afterward, reach their turning point after a characteristic typical time amounting roughly to T osc =2, before they move back towards the trapping center.
The mean-square displacement is comparatively large at the time where most particles are close to their turning point, leading to a local maximum in Fig. 4b. Then, the particles turn and propel back towards the trapping center, leading to a minimum in Fig. 4b. The particles cross the trapping center, moving outwards again and so on, leading to a sequence of further peaks that are smaller than the first one ("damped oscillations"), because particles do not reach the turning point at exactly the same time. This effect is far less pronounced for negative phototaxis (cooling trap), where particles are slow in the vicinity of the trap's center and already reach their first turning point at significantly different times. Therefore, oscillations are barely visible in this case, see Fig. 4a.
Since the APs translate and rotate in unbounded space along the y and ϕ direction, no oscillations occur in the mean-square displacements y t ð Þ À yð0Þ ð Þ 2 (see Fig. 4c, d) and ϕ t ð ÞÀ ð h ϕð0ÞÞ 2 i (see Fig. 4e, f).
To quantify the impact of the light field (trap) on the orientational correlation of the APs, we consider the following correlation function: In the absence of the motility trap orientational correlations decay exponentially at a time scale determined by the inverse rotational diffusion time 1/D r . As shown in Fig. 4g, h, the motility trap induces a faster decorrelation, mirroring the fact that the light gradients that are responsible for phototaxis, and hence for motility trapping, systematically bias the AP's self-propulsion direction towards the trapping center.
Notably, when the orientational correlation time is larger than the oscillation time T osc , we even observe negative correlations (see Fig. 5). To see how such negative correlations can occur, consider a particle which is in the center of the trap at t = 0 (or some other time) and which moves outwards shortly afterward. When the particles reach its turning point around t $ T osc =2, before losing information about its orientation at time t, there is an enhanced probability that it moves back towards the trapping center at times t ≳ T osc =2, leading to negative orientational correlations.
Delocalization vs. weak and strong localization. Let us now further characterize the trapping properties of motility traps by defining a formal classification of localization scenarios, signatures of which we will then associate with APs in motility traps. We therefore consider a trap of length l v and depth Δv ¼ V max À V min in a box of size L (with periodic boundary conditions), leading to a piecewise linear particle velocity v(x) as shown in Fig. 6a. (Note that from here onwards we allow for a nonzero V min , which avoids that particles get stuck at the trap bottom in the noise-free special case.) This trap creates an effective active torque ω(ϕ, x) acting on phototactic APs inside the trap We now define three idealized localization scenarios, which we call (i) delocalization, (ii) weak localization, and (iii) strong localization. To do this, we keep l v constant and explore the behavior of the squared width of the particle distribution around the trap center, 〈x 2 〉, as defined in Eq. (4), in the limit of large L, ∇v. The first scenario, delocalization, is defined by Signatures of delocalization only occur in the absence of an active torque for an ensemble of APs, that is, for cases where the light pattern only affects the speed of the particles. Then, noisefree APs move persistently in the direction of their initial orientation and never turn so that 〈x 2 〉 diverges as L diverges, independently of ∇v. In general, noise additionally contributes to delocalization.
The next scenario, weak localization, is defined by This scenario applies if particles are localized in a single point when Δv ! 1 (then the inner limit on the left side of (7) is zero), but they can leave the trap with a finite probability when Δv is finite. In the latter case, particles that have left the trap can freely explore the available space and hence 〈x 2 〉 diverges as L diverges such that the limit on the right-hand side (r.h.s.) of (7) is infinite.
Signatures of weak localization are expected to occur for APs in a motility trap of finite depths, even in the presence of noise. This is because motility traps create an exponential localization with a localization length that essentially decreases linearly with Δv (see "Methods" section). Thus, 〈x 2 〉 decreases exponentially in Δv as Δv increases, but 〈x 2 〉 increases only as L 2 when L increases. It follows that first increasing Δv and then L exponentially reduces the fraction of particles, which significantly contribute to 〈x 2 〉 compared to the case where L is first increased, such that the two limits in (7) defines "strong localization." This case occurs if particles cannot reach regions beyond l v even in a trap of finite depth. Such a scenario strictly applies only to noise-free APs in a motility trap with a size l v , which is larger than (twice) the distance between the trapping center and the turning point of the trajectories. Note that specifically in the present quasi-1D setup, the distance between the turning point of an AP and the trapping center depends on its initial orientation. Thus, strong localization would only occur for noise-free AP ensembles with initial angles prepared in the interval φ e ≤ ϕ 0 ≤ π À φ e , with φ e ¼ const larger than the critical angle arcsinðe À c j jΔv=σ Þ (see "Methods"), leading to turning points inside the trap.
In our simulations and experiments, where noise is present and traps have a finite depth, we still find notable signatures of these localization scenarios, both for positive and negative phototaxis. A first indication of this can be seen from Fig. 6b, c revealing that the maximum of x 2 P(x) lies outside the trap ( x j j ≥ l v =2) in the absence of an active torque (yielding a signature of "delocalization"), whereas in the presence of an active torque, the maximum of x 2 P(x) typically lies inside the trapping region ( x j j<l v =2). In particular, for steep but finite traps (Δv ¼ 5 μm s À1 , dark shades of blue and red in Fig. 6b, c) typical particle ensembles explore only a small region around the trapping center, but not the vicinity of the trap. Conversely, for Δv ¼ 0:25 μm s À1 (light shades of blue and red in Fig. 6b, c), x 2 P(x) features a significant tail outside the considered trapping region. Only this latter fraction of particles can explore the space outside the trap and provides a major contribution to 〈x 2 〉 when L would increase. To relate these observations to the above-defined localization scenarios, we now systematically study the parameter dependence of 〈x 2 〉.
In Fig. 7a, b, we consider APs in the absence of an active torque. Here 〈x 2 〉 generally gets larger and larger when increasing L, independently of the value of Δv, which is consistent with our definition of delocalization. In contrast, in Fig. 7e, f (deep trap), 〈x 2 〉 decreases to a value near zero as Δv increases and does not notably change when L increases. This can be viewed as a signature of strong localization, occurring for a typical particle ensemble in a sufficiently steep motility trap, which is observed over some typical finite time of a few hundred particle oscillations in the trap. Note that strong localization can of course never strictly apply in the presence of noise, because at any finite trap depth fluctuations would transfer the AP out of the trap after a sufficiently long time; here, far beyond the timescale of our simulations and experiments. Therefore, we view the present findings as signatures of strong localization. Finally, following Fig. 7c, d, when Δv increases first, 〈x 2 〉 decreases to smaller and smaller values and is then largely insensitive to subsequent changes of L. Note that increasing Δv beyond values shown on the y-axis of the middle panels, one reaches the regime shown in Fig. 7e, f, where 〈x 2 〉 does not significantly change when increasing L. Conversely, when first increasing L in Fig. 7c, d, 〈x 2 〉 gets larger and larger and ultimately diverges, as expected for weak localization.
Possible application. Besides the obvious value of motility traps as a novel tool to controllably localize or displace APs, here we discuss how they might also become useful in the future as a new tool to measure coupling coefficients of APs to external field gradients (or phoretic gradients produced by other particles). A direct measurement is not straightforward because the APs response to external fields is a superposition of fluctuations and particle self-propulsion. In particular, active colloids generally respond to external gradients such as a chemical concentration gradient or a temperature field 50,51 . Here, we exploit the close quantitative agreement between our model and experiments for APs in a motility trap to propose a simple inverse method to measure these coefficients.
For that purpose, we determine an analytical formula for the (tails of the) particle distribution in the motility trap, in the presence of an external gradient. Such a gradient couples to the orientation of nonuniform APs, yielding an additional term in Eq. (2), which then reads Here β r is the coupling parameter to the external gradient and C′(x) is the spatial derivative of an external field of the form C(x) = hx + h 0 , which can represent, for example, a quasi one-dimensional external chemical concentration field (or the temperature field). Intuitively, it is clear that such an extra term leads to a bias of the particle distribution in the motility trap. This can also be seen formally, by generalizing our calculation of the particle distribution in the trap to account for the impact of the external field. The resulting distribution has the same form as Eq. (3) but with a different B (see "Methods" for calculation details) This distribution is biased in a way which uniquely depends on β r (see "Methods"). We can now use this result for an indirect measurement of coupling coefficients of APs to external gradients by (i) measuring the particle distribution in a motility trap, in the presence of a known external field C(x) and (ii) matching the theoretically predicted distribution to the measured result. The latter step involves a matching of the flanks of the predicted distribution (Eqs. (3) and (9)) to the measured distribution in order to determine β r .

Discussion
Our results suggest that motility-trapping provides a novel and generic scheme for the spatial confinement of APs. By specifically exploiting the flow field gradients around an AP in the presence of a motility gradient, this leads to a position-dependent realignment, which confines the AP close to the extremum of the motility landscape, that is, the trapping center. Importantly, this scheme does not require body forces that are typically used for particle localization. We emphasize that motility trapping, which has been exemplarily demonstrated for light-activated particles, will also apply to diffusiophoretic or thermophoretic APs in the presence of suitable chemical or thermal concentration profiles. It would also be interesting to generalize motility trapping to higher and in particular to three dimensions. This would avoid the additional influence of the substrate, which also modifies their behavior. In addition to the use of motility traps as a "motility tweezer," our work also demonstrates how unknown coupling coefficients of APs to external field gradients (or gradients produced by other APs 50-53 ) can be determined from the measured asymmetric particle probability distribution within a motility trap in the presence of an additional external field (e.g., optical, thermal, or chemical gradient).

Methods
Creation of one-dimensional light patterns. Creation of triangle-shaped light fields is achieved by a line focus (widths of 1 and 2000 μm) of a laser beam (λ = 532 nm), which is scanned within the sample plane with a frequency of 200 Hz. Synchronization of the scanning motion with the input voltage of an electro-optical modulator leads to user-defined one-dimensional illumination fields (see Fig. 2a) 46 .
Particle tracking. Microscope images of the APs were taken with a frame rate of 12 fps and for a duration of at least 3600 s using a CCD camera. Particle positions r = (x, y) were obtained by automated in-house tracking routine developed with Matlab image analysis software, yielding a spatial resolution of ∼100 nm 54 . Because of the optical contrast between the light-absorbing carbon cap and the otherwise transparent silica, the orientation of the cap is obtained from the vector connecting the particle center and the intensity centroid of the particle image. The error of this detection is <5%.
AP reorientational dynamics within light gradients. The AP's reorientation dynamics in an intensity gradient ∇I is (in the absence of noise) described by the differential Eq. (2). Solving this equation gives cos ϕðtÞ ¼ tanhðω max ð t À tÞÞ, where t is the time when ϕ t ð Þ ¼ π=2 and ω max / ∇I is the only fitting parameter used to obtain the theoretical fit in Fig. 3a and which strongly depends on ∇I 46 . From this, one obtains the reorientation time τ ¼ 2 ω max ln cosðϕ ωmax Þþ1 sinðϕ ωmax Þ , where ϕ ω max is the total rotation 46 . The reorientation times given in the paper correspond to the value for ϕ ω max ¼ 3 rad, which is shown in Fig. 3a, b vs. ∇I 46 .
Brownian dynamics simulations. We have solved the equations of motion by using Brownian dynamics computer simulations with periodic boundary condition along x direction. In our simulations, we use the Brownian time τ B = σ 2 /D and the diameter of the particle σ as time and length units. In line with the experiments, we choose l v = 46.15 σ and V max = 12.5, 50, 150, and 250 σ/τ B , and V min = 0. According to our experiments, the prefactor c is chosen to be c = +0.6 and −1.2τ B for negative and positive phototaxis, respectively.
Particle distribution in the trap. Here, we derive a simple analytical expression for the particle distribution function (or its density profile) in the trap. Let us discuss this for motility profiles v(x), which are piecewise linear in x. For negative phototaxis (cooling trap), the self-propulsion speed of the particles, in line with the light-intensity profile in our experiments, is approximated as where l v is the size of the trap, V max − V min defines its depth, and V min < V max is a general background motility. Likewise, for positive phototaxis (heating trap), the profile is inverted such that we assume Neglecting noise in the basic equations of motion (Eq. (1) and Eq. (2)) yields for x (t) and ϕ(t) and By dividing these two equations, we obtain Integration of Eq.(14) yields the relation for any given initial condition x 0 = x(0) and ϕ 0 = ϕ(0). Let us now obtain a condition for the maximal excursion X m of the particle from the trap center. A maximal excursion implies that the particle orientation is exactly π/2, hence ϕ x ¼ X m ð Þ¼ π=2. Plugging this into Eq. (15) we obtain the relation which we can solve for X m as Consequently, the critical initial orientation angle ϕ c needed to reach the size of the trap when starting inside the trap (x 0 = 0) is given implicitly by X m ðϕ c Þ ¼ l v =2, Different colors correspond to different strengths of the gradient, which is expressed in units of The trap length is set to l v = 46.15 σ, and the maximal velocity V max = 5 µm s −1 . τ B is the typical Brownian time and β r is the coupling parameter to the external chemical gradient. a, b Data for negative phototaxis and c, d for positive phototaxis. b, d show the same data as in a, c, but in semi-logarithmic representation and with the analytical noisefree probability distributions (Eq. (22)) superimposed as dotted lines with the same color as the simulation data. which yields Now to obtain the particle distribution P(x) in the trap, we make two assumptions. First, we assume that the particle orientation is almost homogeneously distributed when the particle is in the trap center. This first assumption is reasonable since there is no torque when x 0 = 0 and noise leads to a further smearing of orientations. Moreover, this assumption is found in our simulations to a large extent. Second, we assume that the main weight in the particle distribution P (x) is given by the particle trajectory when it is stationary in x, that is, when it is turning at x = X m . In particular, this is a good approximation for the wings of the particle distribution, which are dominated by the turning events. Consequently, we set PðxÞ %PðX m Þ, wherePðX m Þ is the distribution of the maximal excursions. The homogeneous distribution of initial angles then simply transforms intoP X m ð Þ viã which directly yields Eq. (3). These trapping mechanisms can be used as a sensor of an external field. Specifically, in case of chemotactic rotational motion in the vicinity of the chemical field C(x), the rotational Langevin Eq. (2) goes to where β(r) denotes the rotational chemotactic coupling coefficient. Therefore, in case of vanishing noise, the relation between ϕ(t) and x(t) is obtained as with B(x, h) given by Eq. (9). This probability distribution is biased due to the presence of the external chemical gradient. It can be used for indirect measurements of coupling coefficients of APs to external gradients (or gradients produced by other APs [50][51][52][53] ). This can be done by measuring the AP distribution in a motility trap in the presence of an additional external chemical gradient (or analogously a thermal or intensity gradient). When matching the flanks of the predicted distribution (Eq. (22)), which depend uniquely on β r (Fig. 8) to the measured ones, this allows to determine β r . In Fig. 8, we show the AP distribution for different reduced chemical gradients ∇C j j= C, where

Data availability
The data that support the findings of this study are available from the corresponding author upon reasonable request.

Code availability
The code that supports the findings of this study are available from the corresponding author upon request.