## Main

Bacterial communities can produce multicellular interfaces through cooperation and competition15,16. Plants, fungi and animals can establish tissue boundary patterns through developmental programmes using independently evolved yet similar genetic toolkits, organizers and morphogen fields1,3,4,17,18,19. Mathematically, such interface (or boundary) patterns can often be described as tilings or tessellations20,21, which elegantly combine generic algorithmic design principles with functional structure and aesthetic appeal, as exemplified by neuronal self-avoidance tilings22,23, DNA tiling self-assembly24, Islamic architecture25 and the Tetris video game26. Synthetic biology aims to engineer patterned multicellular systems to facilitate applications including programmable biomaterials, artificial tissues and metabolic consortia, and to provide a build-to-understand methodology for natural systems5,6,7,8. Despite recent bioengineering advances5,7, experimentally feasible algorithms and standardized modules for multicellular interface patterning are limited, in part because the design potential of cell–cell adhesion5,7,10,11,12 is underexplored compared with cell–cell signalling13,27,28,29,30.

## Multicellular interface patterns

Here we introduce the engineering, modelling and algorithmic programming of multicellular interface patterns by realizing a synthetic cell–cell adhesin logic with swarming bacteria (Fig. 1). We seeded two synthetic adhesin-expressing Escherichia coli colonies10 a few millimetres apart on soft agar and let them grow, divide and migrate towards each other overnight in pseudo-2D swarms (Fig. 1a, Supplementary Video S1 and Methods). These bacterial-surface-displayed synthetic adhesins were derived from nanobodies (Nb) and their complementary antigens (Ag): Nb2 binds Ag2, Nb3 binds Ag3, but Nb2 does not bind Ag3 etc.10,31 (Fig. 1a). We then discovered that a macroscopically visible interface forms between any two strains expressing complementary heterophilic adhesins, such as Nb2 and Ag2 (Fig. 1b). Seeding more colonies generated further interfaces predictably, for example, seeding six alternating Nb2/Ag2 colonies in a circle produced star-shaped interface patterns (Fig. 1c).

This suggests that complex 2D target patterns P could be generated by specifying suitable adhesin combinations and seed patterns S (Fig. 1d). For example, we asked whether one can program bacterial swarms to generate an Escher-like transmutation32 between triangles, cubes and hexagons (Fig. 1d). Indeed, this can be achieved with just four adhesins by solving the corresponding inverse design problem (Fig. 1e,f, Supplementary Fig. S9, Supplementary Texts S1 and S2 and Supplementary Videos S2 and S3; throughout the paper, see Supplementary Figure S10 for accessible colourings). In the following, we systematically investigate the biophysical mechanisms underlying this interface formation to establish a comprehensive adhesion logic framework for the inverse design of arbitrarily tessellated interface patterns20,21 (Supplementary Text S2).

## Biophysics of interface formation

We first confirmed that swarming E. coli cells form macroscopically visible interfaces if and only if complementary adhesins are present in adjacent cell populations (Fig. 2a and Supplementary Fig. S11). We seeded a pair of colonies with complementary adhesins that cytoplasmically express red and yellow fluorescent proteins (Ag2-RFP|Nb2-YFP) (Fig. 2a, left). We fitted a generalized Hill function to the resulting fluorescence profiles (equation (1)) and determined the width of a transition region for adhesive cell pairings to be 500 ± 10 μm (mean ± standard deviation, n = 3 replicates throughout if not stated otherwise), which was significantly narrower than 1,290 ± 20 μm (p < 0.001, Tukey’s honestly significant difference test) for non-adhesive pairings (Ag2-RFP|Ag2-YFP) (Fig. 2a, left/right). As the interface remains much wider than the size of a single cell (about 2 μm), the narrowing of the transition region suggests that cells are intermixed with incomplete blocking. Furthermore, the total cell density is characteristically increased at the interface, with cell density reductions on either side. Without adhesion, both strains combine to a nearly homogeneous distribution (Fig. 2a, right). Hence, these adhesins mediate a new type of emergent density patterning distinct from previously established mechanisms relying on signalling and motility29 or interstrain competition30.

To quantitatively capture this interface-forming behaviour and larger-scale patterning, we introduced adhesion into a minimal continuum model of bacterial swarming30 (Fig. 2b and Supplementary Text S1). Each strain i is described by a spatio-temporal density ρi(r, t) (r position, t time), which grows to saturation ρmax at rate gi, spreads with effective diffusion constant Di and interacts with a complementary adhesive strain j to form a new phase ρij through adhesion of strength K. In accordance with our previous results10, the adhesion is considered irreversible. Using initial conditions of two spatially localized strains, the model recapitulates the outgrowing wavefronts, as well as the characteristic peak and troughs at the interface, which are absent without the adhesins (Fig. 2c and Supplementary Video S4). Matching simulation and experiment yielded biologically reasonable estimates for all model parameters (D = 47 ± 8 μm2 s−1, g = 14 ± 6 h−1, K = 130 ± 50 h−1) (Fig. 2c).

This model predicts that tuning seeding conditions enables quantitative control over various geometric interface properties, which we confirmed experimentally (Fig. 2d–i and Supplementary Text S1). Decreasing the adhesion binding rate K should widen the interface (Fig. 2d), which we confirmed by adding a small peptide competitive inhibitor (EPEA) against Nb2 (ref. 10) to quantitatively titrate adhesin levels; varying inducer concentration produced equivalent results (Supplementary Fig. S12). Delaying the expansion of one colony by varying the relative initial seeding concentrations (Supplementary Fig. S13) should produce interfaces angled and shifted towards the delayed colony (Fig. 2e versus 2f), which we confirmed over a wide range of seeding ratios (Fig. 2i). Differences in expansion rate D1 versus D2 should lead to interfaces curved towards the slower-growing colony—even engulfing them (Fig. 2g and Supplementary Video S5), which we confirmed by using a slow-growing Nb3 variant, Nb3-1 (ref. 10). The Nb3, Ag3, Ag2 and Nb2 lines all have comparable expansion rates (Supplementary Fig. S14). Non-point-source seeding should behave like a summation of many point sources, which we confirmed by seeding one strain in a line, producing the expected parabola (Fig. 2h and Supplementary Fig. S15). For extensions to the model, see Supplementary Texts S1.6 and S1.7 and Supplementary Video S6.

## Adhesion logic and interface composability

The large width and sparseness of these interfaces suggested that they could discriminate between cells with complementary versus non-complementary adhesins. To test this hypothesis, we performed interface-formation experiments with complementary adhesins as before, but now mixed one of the complementary strains with a third non-binding orthogonal strain expressing Cerulean (CFP). Confocal imaging showed that an orthogonal strain (n-CFP, in which n denotes a null adhesin control) does not bind to adhesive clusters (Fig. 3b), with a characteristic pair-correlation width of 8.46 ± 2.71 μm2 for the adhesive case, and no meaningful fit was possible for the non-adhesive cases (Supplementary Figs. S19 and S23). Epifluorescent imaging similarly showed that a non-complementary strain (Ag3-CFP) infiltrates further than either of the complementary strains (Fig. 3c). Control experiments with various fluorophore and adhesin combinations indicate that these results are not due to potential differences in migration rates between strains (Supplementary Fig. S25). We conclude that these interfaces are semipermeable by selectively filtering complementary cells while allowing non-complementary cells to pass.

The observation that introducing a third non-complementary adhesive strain does not interfere with interface formation (Fig. 3c) suggests that multistrain mixtures in general could show composability7. A library of two adhesin pairs can be combined into 16 possible ‘elements’ at each seeding position, corresponding to 4 bits of information, and in which nine elements are of practical use here (Fig. 3d and Supplementary Text S2): a ‘null’ element Σ0 = {n} without any adhesin, a subset of four ‘singlet’ elements Σ1 = {Nb2, Ag2, Nb3, Ag3} and a subset of four ‘doublet’ elements Σ2 = {Nb2 + Nb3, Nb2 + Ag3, Nb3 + Ag2, Ag2 + Ag3}. Any other combination is not of practical interest here owing to self-interaction but might have applications in future patterning processes. We prepared these four doublet mixtures and performed interface-formation experiments as before. As expected, we found that a visible interface between two doublet elements is formed if and only if they are different (Fig. 3e). We also introduce the term ‘hidden’ interfaces for cases in which no visible interfaces form, which will become conceptually useful later in the paper. We also experimentally tested various pairings of singlet versus doublet elements, which all followed the expected interface-formation logic (Supplementary Fig. S25). Thus, these orthogonal adhesins and the corresponding composable sets and subsets of strains10 (Fig. 3d) provide a cell–cell adhesion logic for generating visible and hidden interfaces (Fig. 3e).

## Universal interface and tessellation patterns

Equipped with this combinatorial cell–cell adhesion logic, we can tackle the inverse design problem of finding suitable seed conditions S to achieve a desired target pattern P (Fig. 1d). Conceptually, this inverse design problem is closely related to long-standing patterning questions in developmental biology, as initial seeding conditions and swarming cells represent adhesion-based bacterial analogues to the well-established concepts of developmental ‘organizers’ and morphogen ‘fields’, respectively1,2,3,17,18. Central questions are: what is the design space of programmable patterns P? How many unique adhesins are minimally required to program P? What are efficient algorithms for identifying the necessary adhesin combinations and seeding positions S? Using this adhesion logic platform, we found that all three regular periodic tilings20 can be created by seeding cells at the tile circumcentres, in which triangular and square tilings require just one adhesin pair from the singlet set, whereas hexagonal tilings require two adhesin pairs combined into doublets (Fig. 4a and Supplementary Fig. S26). Moreover, different seeds can generate the same pattern (Supplementary Text S2).

We also found that any arbitrary tessellation and straight-interface pattern in a 2D plane can be generated with just four adhesins (two adhesin pairs), representing 4 bits (Fig. 3d and Supplementary Text S2.3). To outline the necessary algorithmic procedure, we first note that the interface pattern generated from growth-matched swarming strains seeded at different points is equivalent to the Voronoi tessellation of the seeded points21,33. The four-colour theorem34 guarantees that one can seed four doublets (Fig. 3d,e) such that adjacent tiles always contain a different doublet, ensuring that all interfaces of the Voronoi tessellation will form (Fig. 4b, Supplementary Fig. S27 and Video S8). If the desired interface pattern does not correspond to a Voronoi tessellation, we can use algorithms that solve the generalized inverse Voronoi problem21, which guarantees that any interface pattern can be mapped onto a Voronoi tessellation and provides the necessary seeding positions. This will typically require introducing further interfaces and subtiles. However, by seeding all subtiles within an original tile with the same doublet, all further interfaces within a subtile become ‘hidden’ (Figs. 3e and 4c), and the four-colour theorem applies as before. More generally, any interface pattern can be generated even when one or both ends of some interfaces are not connected to another visible interface (Fig. 4d). The ends of such ‘open’ interfaces can always be isolated by also using the null element in addition to the four doublets. This most general case can then be solved as before (Fig. 4d). These algorithms thus provide a universal design framework for generating an arbitrary pattern P by determining the sufficient seeding conditions S while using at most four adhesins.

The above algorithms can be readily generalized to implement extra constraints, as commonly encountered in many natural and engineered systems. As an example, we considered the task of generating arbitrary interface patterns on a triangular lattice on which seeding positions are restricted to the centre of each triangle (Fig. 4e). We then identified an efficient algorithm that sequentially assigns adhesins to first generate all non-horizontal interfaces (even and odd rows) and subsequently all horizontal interfaces (between rows) (Fig. 4e, Supplementary Fig. S8, Supplementary Text S2 and Supplementary Video S9). As before, this algorithm only requires four adhesins. An initial investigation into other lattice types suggests trade-offs between seeding restrictions, number of available adhesins and achievable pattern complexity, which then pose a range of new and interesting constrained tessellation problems, especially with regards to the selective formation or omittance of interfaces20,34 (Supplementary Fig. S28 and Supplementary Text S2). The patterning space can also be extended to include curved interfaces; for example, using expansion rate differences (Fig. 2g,h) enables threefold floral arrangements (Fig. 4f) that differ strikingly from the sixfold ray pattern in Fig. 1c despite identical seeding positions. The continuum model (Figs. 2b and 4f) allows for cost-efficient quantitative pattern exploration before experimental implementation (Supplementary Text S2.2).

## Applications of self-growing bacterial materials

To explore the potential application space of this bacterial adhesion logic, we sought to spatially pattern the properties of such self-growing bacterial materials. Patterned agar sheets that are approximately 2-mm-thin can be cut out (Fig. 4g and Supplementary Fig. S21), setting the basis for free-standing biomaterials5. The wettability of the surface can be spatially controlled, that is, the flow of 1× phosphate-buffered saline (PBS) is hindered at visible Nb3|Ag3 interfaces (Fig. 4h, Supplementary Fig. S29 and Supplementary Video S10), whereas it is not hindered for hidden Nb2|Ag3 or Nb3|Ag2 interfaces (Supplementary Fig. S29). This phenomenon could be used to localize liquid droplets (Fig. 4i and Supplementary Fig. S29) and support open-surface microfluidics14. The control over interface width using antagonistic antigens (Fig. 2d) suggests molecular diagnostics that translate molecular concentrations into switchable visual interface patterns (Fig. 4j). Such diagnostics could be manufactured without the need for protein purification and should generalize to any molecule against which a nanobody can be formed (Supplementary Text S3). Other applications include human-readable digital displays35 (Fig. 4k, Supplementary Fig. S27 and Supplementary Video S8), precision biofiltering36 on the basis of selective interfaces (Fig. 3b,c) and build-to-understand approaches for synthetic microbial communities6,7,8.

## Methods

### Plasmids and strains

Plasmids were transformed into chemically competent cells following standard protocol10. Plasmids were sourced from our earlier work10 and are deposited in Addgene (Supplementary Table S1). To better match the metabolic load between cells, all strains used here expressed at most a single adhesin. However, it is possible to use strains expressing several adhesins. For example, instead of mixing two cell types expressing Ag2 and Ag3, one could use one strain expressing both adhesins10. Doing so produces the expected logical interactions that dictate interface formation but with greater variance in growth rates.

### Cell culture

The MG1655 E. coli strain obtained from E. Coli Genetic Stock Center (CGSC #6300) was used for all experiments in this study. For overnight growth, cells were shaken at 37 °C and 300 rpm with antibiotics in Luria broth (LB) media. No ATc was added for overnight growth. Cell stocks were stored in glycerol at −80 °C. For experiments, single colonies were inoculated from agar plates containing antibiotics streaked out from frozen stocks.

### Soft agar

To prepare soft agar gels, 20 g l−1 of LB broth powder (Affymetrix #75852) and 0.225% w/v Bacto Agar (BD 214050) was added to distilled water. This mixture was autoclaved and allowed to cool to 50 °C before adding antibiotics or ATc inducer as needed. This mixture was then pipetted into Petri dishes, at 10 ml for 10-cm dishes, 5 ml for 60-mm dishes, 2 ml for 35-mm dishes and six-well plates, and 25 ml for 15-cm dishes. The plates were covered and allowed to cool at room temperature for at least 2 h and used on the day of preparation. For confocal imaging, the soft agar percentage was increased to 0.25% w/v for greater imaging stability.

To seed cells for experiments, 1 μl of overnight culture was pipetted onto the surface of the gel without puncturing the surface using low-adhesion tips (VWR 89174-520). For interface-formation experiments, a multichannel pipette was used to ensure consistent 9-mm spacing between the colonies. For experiments needing greater patterning complexity, stencils were cut out of 4.5-mm acrylic sheets (TAP Plastics) using a laser cutter (Dremel LC40). The stencils were designed so that the pipette tips were just above the surface of the agar by using shims and varying the radii of laser-cut holes.

Soft agar plates were placed in a 37 °C incubator right side up, with the lid on and no circulating air. Cells were typically grown for 18 h on soft agar before imaging. Note that E. coli transitions to a swarming phenotype in swarming agar, resulting in greater expansion compared with the agar concentrations most commonly used in labs for various purposes. When specified in the text, cells were incubated at room temperature for 48 h, with all other conditions kept constant.

### Small peptide inhibitors

Small peptide inhibitor EPEA and the scrambled PEAE were synthesized by GenScript10. Frozen aliquots were stored at −80 °C. To create gels with a specific concentration of inhibitor, aliquots of peptide were first thawed and diluted in distilled water to a 10× working concentration. Soft agar gel solutions were prepared at 1.1× concentration to account for the liquid volume in the 10× peptide solution and kept warm in a 50 °C bath before pouring.

### Titrating cell seeding concentration

For experiments needing variable cell concentrations such as the delayed growth experiment, cells were grown in a shaking incubator to stationary phase overnight and diluted in LB media to the desired concentration immediately before seeding.

### Mixed cell populations

For experiments that required seeding mixed populations of different types, cells were first separately grown in a shaking incubator to stationary phase. Immediately before seeding, cells were pipetted from the stationary cultures and mixed in polymerase chain reaction tubes.

### Imaging

#### Fluorescence stereomicroscopy

Fluorescence stereomicroscopy images were obtained using a Leica M205 fluorescent microscope, with a Planapo 2.0× objective (10450030, Leica Biosystems) and DSR (10447412, Leica Biosystems), YFP (10447410, Leica Biosystems) and CFP (10447409, Leica Biosystems) filter sets. Oblique illumination was used for non-fluorescent channels.

#### Confocal images

Confocal images were captured using an inverted Zeiss LSM700 using 405-nm, 488-nm and 555-nm laser lines and a 63× 1.4-NA (0.19 mm FWD) Plan-Apochromat objective (44 07 62, Carl Zeiss AG). Soft agar plates were allowed to equilibrate to room temperature for at least an hour before imaging. Immediately before imaging, a no. 1.5 glass coverslip was carefully placed on the surface of the agar. The soft agar plates were then mounted upside down using a custom laser-cut stage. Images in a tiled set were taken within a few minutes, owing to viscoelastic creep over time. Confocal stacks were acquired at 2-μm slices up to a depth of approximately 20 μm, at which point soft agar undergoes displacement. Furthermore, low-viscosity immersion oil (Resolve M2000, Epredia) was used to minimize the effects of drag on agar as the stage moved around.

#### Epifluorescent wide-field time lapses

Epifluorescent wide-field time lapses were captured using an inverted Zeiss LSM700, with a 20× Plan-Apochromat objective (440640-9903, Carl Zeiss AG), a 1.4-MP CCD monochrome camera (Zeiss AxioCam MRm, Carl Zeiss AG) and a light-emitting diode (LED) lamp (X-Cite XYLIS, Excelitas Technologies Corp.). Plates were mounted as described above and frames were captured every 2 min.

#### Macroscopic images

Macroscopic images were captured using a DSLR camera (D5600, Nikon). Samples were illuminated using oblique illumination from LED ring lights. To correct for the uneven brightness inherent in oblique illumination, a Gaussian blur filter was applied to a copy of the image and this image was then subtracted from the original image using ImageJ42. Subsequently, image contrast was adjusted using ImageJ. These corrections were applied in an unbiased manner solely for the purpose of enhancing visually clarity, and no quantifications were made on these images. Specifically, the following panels in this paper were processed this way: Figs. 1b,c,d, 2a,e,f,g,h, 3e and 4a,b,e,f,g,h.

#### Time-lapse macroscopic images

Time-lapse macroscopic images were captured using a Raspberry Pi Camera V2 controlled by a Raspberry Pi Zero. The sample was placed in a small humidified chamber and an LED ring light was used for intermittent illumination. A custom Python script was written to control the Raspberry Pi Camera V2 and ring light activation. Frames were captured every 5 min.

### Measuring interface profiles

To measure the fluorescence profile along an interface, the fluorescence intensity was measured in raw images along a 6-mm line aligned with the axis connecting the initial seeding points. The fluorescence intensity was binned across a width approximately 1.5 mm thick. These profiles were fit using equation (1).

### Measuring interface angles

To measure the interface angles between seeds, the interface was first manually traced using ImageJ. The angle between each leg of the interface and the line connecting the two starting seeding points was calculated using linear regression in Python.

### Image processing for confocal images

Confocal images were cropped to remove smearing caused by the viscoelastic response of the soft agar to stage motion during imaging. The cropped region was always the top 128 × 2,048 pixels, in an image of 2,048 × 2,048 pixels.

For pair-correlation analysis, confocal images were segmented using DeepCell43. Cell positions were defined by the centroids of segmentation results. To calculate the mixed-species pair-correlation function, a custom Python script was used. Briefly, for each cell, the script counted the number of cells in a ring r + dr away. This count was normalized to the area of the ring, as well as the overall cell density. Area corrections were made for rings cut off by the image edges.

### Fitting interface profiles and calculating interface widths

The transition profiles measured using fluorescent microscopy (such as in the graphs at the bottom of Fig. 2a,c, which were measured from the bottom half of the composite images on top) were fitted using the following heuristic equation:

$$f(x)=z/(1+{({k}_{a}/x)}^{n})+y+a{{\rm{e}}}^{(-{x}^{2}/b)}$$
(1)

Here n is the Hill coefficient, ka is the x-position at half the maximum value along the transition and z weights the contribution of the Hill function. The variable a weights the contribution of the Gaussian distribution and b is the standard deviation of the distribution. y is a vertical offset for the overall curve.

The rationale for fitting the profiles to this equation is as follows: equation (1) is a sum of a Hill function and a Gaussian. The Hill function is primarily responsible for fitting the transition region, whereas the Gaussian compensates for any slope in the plateau region of the measured curve.

The width of the transition w is then defined as the distance between the two points of maximum curvature κ, calculated using:

$$\kappa =\frac{| {f}^{{\prime\prime} }(x)| }{{(1+{f}^{{\prime} }{(x)}^{2})}^{\frac{3}{2}}}$$
(2)

### Free-standing patterned sheets

To produce a free-standing patterned material, patterned agar was covered with 10 ml 1× PBS before a scalpel was used to cut out a rectangular section. For smaller sections, gentle agitation of the PBS by shaking allowed the cut-out patterned sheet to lift off from the Petri dish. For larger sheets, a thin object such as a scalpel or coverslip was slid under the agar to separate it from the Petri dish. Alternatively, a glass slide or coverslip was placed in the bottom of the Petri dish before pouring the agar. In this case, covering with PBS and using a scalpel to cut along the edge of the glass was sufficient for the patterned sheet to lift off without any further agitation or manipulation.

Sheets up to a few centimetres in length could be transferred between dishes by pouring the PBS, and sheets up to a centimetre in length could be lifted out of the PBS on the edge of a coverslip, scalpel or tweezer.

### Patterned wetting

For wetting experiments, strains were seeded and grown on soft agar at room temperature for 48 h to produce strong interfaces. Then, 1× PBS was poured at one end of the plate and allowed to flow. The shape of the PBS front demonstrates the effect of bacterial patterning on surface wetting. For droplet capture in square patterns, 1× PBS was gradually added to the square using a pipette.