Introduction

Recent advances in the synthesis of materials have led to well-behaved material structures at the nanometer scale. Atomic structure and deformations in these nanomaterials determine their chemical, electronic, and optical properties, affecting their efficiency and performance in their targeted applications. For example, epitaxial growth of optically tunable heterostructures in III–V semiconductors1,2,3 and two-dimensional (2D) materials4,5,6,7,8 can lead to local strain and dislocations, which greatly affect the electronic and optical properties due to changes in the local band structure. Even within nanomaterials comprised of a single crystal, such as structurally designed anisotropic metallic nano-plates or prisms9,10,11, the local bending or deformations also play an important role in determining their optical responses and catalytic behaviors. To study these fine features in the materials, conventional high-resolution transmission electron microscopy and annular dark field scanning transmission electron microscopy (ADF-STEM) have been utilized to reveal the local atomic structure2,3,7. While the limits of the electron microscope resolution are constantly being pushed12, a common restriction on these imaging techniques is the limited field of view in the sample. As studying the overall structural information of the materials is crucial for mass production and large-scale processing for applications in next-generation devices, techniques such as nanobeam electron diffraction13,14,15 that can map large sample areas have attracted tremendous attention for their potential in determining the sample structure on a large scale.

Although nanobeam electron diffraction has been used for decades to acquire electron diffraction patterns from a large sample area, this technique was limited by conventional charge-coupled device detectors, which are too slow to collect detailed structural information across the entire sample. However, the development of fast direct electron detectors16 now allows the collection of a momentum-resolved nanobeam diffraction pattern at each scanning position in a STEM experiment (Fig. 1a), thus generating four-dimensional (4D) data (Fig. 1b). Therefore, the technique enabled by these detectors is often referred to as 4D-STEM17. Among the direct electron detectors, the electron microscope pixel array detector (EMPAD)18 has high dynamic range and sensitivity, capable of recording quantitative diffraction patterns without saturating the center beam or cutting off the weak diffracted spots. Using the EMPAD in scanning nanobeam diffraction mode, strain profiles in 2D materials have been mapped across a micrometer scale with sub-picometer precision19. Although many works14,20,21,22,23 have been reported to further improve accuracy and precision, this approach relies heavily on prior knowledge of the sample structure. For instance, before applying any strain or phase mapping approach, one needs to determine where and how to place masks on the diffraction patterns. This process varies from sample to sample. Acquiring this information from a large quantity of data from diverse samples makes it difficult to generalize 4D-STEM for materials with unexpected lattice deformations, which usually have a large impact on material properties and device performance.

Fig. 1: Schematic of unsupervised learning of 4D-STEM datasets.
figure 1

a Schematic of the EMPAD operation, where a diffraction pattern is recorded at each scanning position. b A 4D dataset that contains a full diffraction pattern at each pixel in the real-space map. Scale bar, 500 nm. c Schematic of the divisive hierarchical clustering workflow on diffraction patterns in the 4D data. d Visualization of the clustering results, where the features are mapped back to real space (top) to determine their distribution, and the diffraction patterns are projected onto a lower-dimensional manifold space (bottom) for visualization.

Recently, machine learning has emerged as a promising method applied in microscopy24,25,26,27,28,29,30 due to its capability in analyzing complex patterns in large datasets. Specifically, unsupervised learning, which does not require training data, has been utilized to identify the stacking order31 and twin boundaries32 in materials. To further extend unsupervised learning for deformation and fine structure study, we utilized a divisive hierarchical unsupervised clustering architecture for rapid and semi-automatic 4D data analysis and feature mapping according to intrinsic characteristics and similarity (Fig. 1c). This approach complements the existing strain mapping approaches by providing a rapid and automatic initial analysis of the 4D data (usually < 10 min), as well as uncovering unexpected but significant fine structures and deformations in the materials.

Results

Architecture of divisive hierarchical clustering

The process’s overall scheme is described in Fig. 1. After the data acquisition, three main steps are used to process the 4D data: preprocessing the diffraction patterns, hierarchical clustering of the data, and visualizing the results.

Preprocessing involves aligning and masking the diffraction patterns. Alignment corrects the drift in the diffraction patterns caused by slightly misaligned beam tilt when scanning large areas (Supplementary Fig. 1). To do that, we align the center of mass (CoM) of the center beam. We added a circle mask in the center of each diffraction pattern to select the center beam (Supplementary Fig. 1b). Then, the CoM of the center beam was calculated with sub-pixel precision, followed by moving the diffraction pattern towards the center of the detector (Supplementary Fig. 1a). We repeated these three steps until the standard deviation of the CoM in all scanning positions, as well as the error between the CoM and the center of the detector, becomes smaller than 0.01 pixel. This step avoids the confusion caused by the translational shift of the diffraction patterns due to reasons other than the intrinsic sample structure.

Masking contains two parts, where the first part uses a ring mask to mask out the low-angle scattering as well as the zero-padded regions caused by the alignment. We determined the inner and outer radius through plotting the standard deviation (STD) of diffraction pattern. In the example data (Supplementary Fig. 2a, e), the bright center beams always show highest STD due to the high intensity. From the rotational STD plots (Supplementary Fig. 2b, f), we were able to identify the diffraction area and set the inner/outer radius to block the background and the noise (Supplementary Fig. 2c, g). The second part selects the diffraction regions where the crystal information is stored. In this part, we select the features based on the STD of the intensities in the remaining area. The regions with high STD (30% of the highest) among the ring-masked dataset are selected in each diffraction pattern (Supplementary Fig. 2d, h) and flattened as a feature vector, which is used in the following cluster analysis. The optimal percentage (30%) was determined by experience, as shown in Supplementary Fig. 3. Thus far, this threshold applies for both thin 2D materials (Supplementary Fig. 3b) and thicker nanoprisms (Supplementary Fig. 3e). As a result, the preprocessing step helps organize the 4D datasets so that our method will mainly extract structural information from the datasets, while avoiding any ambiguity caused by the microscope misalignment and background.

The hierarchical clustering architecture is illustrated in Fig. 1c. A single round of clustering is insufficient to determine all the features in the 4D dataset due to features at varying length scales. Initial clustering separates large scale features, typically different materials in the sample, since they cause more noticeable differences in the diffraction pattern. However, diffraction patterns within these initial clusters then have more subtle differences caused by small-scale features, which cannot be separated through a single clustering round. To extract these features at different scales, we employ a divisive hierarchical clustering architecture to cluster the diffraction patterns in the 4D dataset. The divisive architecture is a top-down approach, which starts from the whole dataset, and then clustering is performed recursively when moving down the hierarchy.

In a single round of clustering, we compared different unsupervised learning methods and identified that K-means33 exhibited the optimal performance considering combined accuracy and speed (Supplementary Table 1 and Supplementary Fig. 4). The K-means algorithm is a common clustering method that divides our real-space points, each represented by a feature vector, into K clusters through minimizing the variance (squared Euclidean distance) within each cluster. To automatically determine the number of clusters, or the K, especially when little prior knowledge about the datasets was presented, we utilize the elbow method34 to determine the K number in each round clustering (Supplementary Fig. 5). In the elbow method, we calculated the total within-cluster sum of squares (WSS) and plotted the error curves according to the number of clusters (or K). Since we do not need precise WSS values, we adopted the faster but negligibly less precise Mini-Batch K-means method (Supplementary Fig. 4e) to determine the elbow point.

Finally, since each diffraction pattern represents one pixel in real space, the labels from the clustering results can be mapped back to real space for a better understanding of the material structures. As shown in the top panel of Fig. 1d, the clustering result is visualized in a real-space color-coded map, with each color representing a single structural feature characterized in a cluster of similar diffraction patterns. Alternatively, we can also visualize the data distribution in a low-dimensional manifold structure (Fig. 1d, bottom panel). The manifold structure is the projection of the high dimensional diffraction patterns to 3D space for visualization, which is achieved by the recently developed uniform manifold approximation and projection (UMAP)35. The lower dimensional manifold structures can assist in the visualization of the distribution and variance of the clusters, which can be used to determine the differences in major physical parameters. Through real-space and manifold structure visualization after clustering, we can map the fine deformations to better understand the distribution of structural features in the sample.

Deformations in WS2–WSe2 lateral heterojunction

To test the accuracy of our clustering architecture, we applied our approach to 4D datasets of 2D epitaxial lateral heterojunctions, which contain strain-engineered structures that enable tunable optical properties19. The sample is composed of an outer and inner region of WS2 and a middle region of WSe2, which is not apparent in its ADF-STEM image (Fig. 2a) as the tungsten atoms dominate the ADF contrast. During the clustering, structural features at different scales within the entire flake have been uncovered hierarchically. After three rounds, as shown in the dendrogram (Fig. 2b), fine deformations have been uncovered in the sample.

Fig. 2: Clustering results on WS2–WSe2 lateral heterojunction.
figure 2

a ADF-STEM image of the WS2–WSe2 junction. Scale bar, 500 nm. b Dendrogram of the unsupervised learning workflow. ce Real space maps from the unsupervised learning results showing different compositions and deformations in the sample. fh 3D manifold structure displaying the data distribution in each round of the clustering. i Histogram of measured lattice constants of WS2 and WSe2 color-coded with results in the second-round clustering. j Histogram of measured rotation angles of WS2 color-coded with results in the third-round clustering of WS2.

The real space map from the first two rounds of clustering is shown in Fig. 2c, where the method effectively separated the background, WS2, and WSe2 (Supplementary Fig. 6a–c). The crystalline samples are distinguished from the amorphous substrate in the first round of clustering, which is intuitively obvious. In the second round, the WSe2 and WS2 are differentiated by the diffraction spots spacing caused by the lattice mismatch between WS2 and WSe2 (Supplementary Fig. 6d). The real space map from unsupervised learning provides a precise interface between WS2 and WSe2 with defects (Supplementary Fig. 7), which were not recognized in the ADF images. The two separated clusters of WS2 and WSe2 in the manifold structure (Fig. 2f) indicate that the lattice constant changes across the junction are discrete. We measured the lattice constant of each diffraction pattern in the junction sample, and the histogram (Fig. 2i) confirms the discrete change. Using the measured lattice constant as the ground truth, our clustering results provide a 99.9% accuracy for the discrete feature.

In the third round of clustering, the sub-clusters of WS2 and WSe2 from the second round are analyzed to reveal finer features. Our method separates the WS2 cluster into two sub-clusters, where the real space map shows a rotational periodicity of the material with graded interfaces (Fig. 2d). The mean diffraction patterns (Supplementary Fig. 6e, f) of each sub-cluster display a slight rotation in the reciprocal lattice (Supplementary Fig. 6g), which corresponds to different lattice rotations in real space. Unlike the discretely separated WS2 and WSe2 clusters from the previous round, these two clusters are mixed in the manifold representation (Fig. 2g), indicating that the rotation angle changes continuously. We measured the rotation angle of each diffraction pattern in WS2, and the histogram (Fig. 2j) confirms the capability of our method to identify continuous structural distortions in materials. The measured accuracy of clustering this continuous feature is 84%.

Meanwhile, the WSe2 cluster is separated into four clusters, and the real space map is shown in Fig. 2e. The averaged diffraction patterns of each cluster differ in the intensity of the second order spots (Supplementary Fig. 6h–k), caused by lattice tilts (or ripples) in the sample36,37. Specifically, three separate regions in the corners show different directional ripples since the second-order diffraction spots along one direction display a much stronger intensity than the other two directions (Supplementary Fig. 6i–k). In contrast, the area close to the center is a flat region where all the second-order spots have similar intensity (Supplementary Fig. 6h). The 3D manifold structure of the WSe2 cluster (Fig. 2h) shows that the tilts in the ripple area are continuous. The results we achieved here are consistent with literature where the ripples form to relax the strain induced by WS2–WSe2 lattice mismatch19.

Uncovering minor ripples in WS2–WSe2 superlattices

To test how sensitive our method is for minor deformations in materials, we utilized a coherent 2D superlattice sample which contains a much smaller ripple structure with an aspect ratio of ~1/30 in narrow WSe2 stripes8. Using our method on the entire superlattice sample (Fig. 3a), structural features at different scales were uncovered hierarchically. Our method identified different flakes in the first round of clustering (Fig. 3b). Then lattice differences between WS2 and WSe2 were illustrated in the second round (Fig. 3c). The next few rounds unveiled directional uniaxial strain (Fig. 3d and Supplementary Fig. 8a–e), as well as minor ripples hidden in the WSe2 (Fig. 3e and Supplementary Fig. 8f–k). Due to the coherency in the superlattice, the ripples presented here are much smaller than what we observed in the WS2–WSe2 lateral heterojunction sample, indicating the capability of our hierarchical approach for identifying minor deformations in materials. Finally, the manifold structures of the zoomed-in dataset from each round of clustering provide a view of each cluster and subcluster in data space (Supplementary Fig. 9).

Fig. 3: Clustering results on WS2–WSe2 superlattices.
figure 3

a ADF-STEM images of the 2D multi-junction superlattice with a zoomed-in area shown in the inset. The ADF contrast is dominated by heavy tungsten atoms, thus no superlattice structure appears. Scale bar, 500 nm. b Real-space map of the clustering results from the 4D dataset of the WS2–WSe2 multi-junction sample, where different flakes are identified from the substrate. c Zoomed-in real-space maps of the multi-junction sample area shown in the red box in (a). d Real-space map of the sub-clustering results in WSe2 with two colors indicating different strain profiles. e Real-space map of another clustering round on each subcluster in (d), providing more structural details of lattice ripples in WSe2 due to the strain.

Uncovering bending contours in silver nanoprisms

Unlike 2D materials, thicker samples usually present more complex deformations and lattice distortions, which result in more challenges in understanding their local structure. We use our method to investigate the deformations in silver nanoprisms, which have been widely studied due to their optical properties that show great potential in many applications9,10,11. The silver nanoprisms were drop casted on an amorphous carbon supporting film followed by air drying, which introduced internal deformations due to the surface tension. The ADF-STEM (Fig. 4a) shows an entire flake of a micrometer-sized silver nanoprism, which is known to be single crystal with the [111] zone axis perpendicular to the flat surfaces. Here, we show that our machine learning approach can elucidate deformations in nanoprism flakes in a facile and semi-automated way (Supplementary Fig. 10).

Fig. 4: Clustering results of silver nanoprisms.
figure 4

a ADF-STEM image of a silver nanoprism placed on amorphous SiNx supporting film. Scale bar, 500 nm. b Zoomed-in ADF image from the white box in (a). Scale bar, 200 nm. c Real space map of the final cluster and sub-cluster results. df Manifold structure of the data in each hierarchical clustering process.

First, the same preprocessing of 4D data was performed on the nanoprism datasets (Supplementary Fig. 11). Focusing on a corner of the nanoprism (Fig. 4b), the first round of clustering distinguishes the sample from the amorphous supporting film (Supplementary Fig. 12a) due to the obvious difference between the amorphous film (Supplementary Fig. 12b) and the nanoprism (Supplementary Fig. 12c) in the diffraction patterns. The following round of clustering identify the contours in the nanoprism flake (Supplementary Fig. 12d–f). To further investigate the deformation, we clustered the contour data into smaller sub-clusters and identified the two sides of the contour (yellow and orange in Fig. 4c), which is consistent with the general structure of a bending contour. From the averaged diffraction patterns (Supplementary Fig. 12h, i), the difference between the two sides of the bending contour in diffraction space is the intensity variation in the conjugate diffraction spots, which can be explained as the incident electron beam approaching the atomic planes at different angles at two different bending sides. On each side, the Bragg condition in one direction is fulfilled, and the diffraction of the incident beam would result in strong corresponding diffraction peaks (Supplementary Fig. 13a). By placing masks on the conjugate diffraction spots to form virtual dark-field (DF) images (Supplementary Fig. 13b), the high contrast contours in the virtual DF images are consistent with the previously reported experimental DF-TEM images in silver nanoprisms. In addition, our simulated diffraction patterns (Supplementary Fig. 14) suggest that the thickness variations can be detected due to the distinct diffraction intensity, confirming the uniformity of the thickness in our Ag nanoprism (10 nm from previous publication11).

In the manifold structure (Fig. 4d–f), the data is first segmented into two main clusters (Fig. 4d), amorphous background (black) and nanoprism (dark purple). Further sub-clustering on the nanoprism cluster separated the ring-like appendage (bending contour) from the original sample manifold as the new-subcluster (Fig. 4e). The thin asymmetric shape of the bending contour manifold (Fig. 4f) indicates a continuous deformation, which is shown in the diffraction pattern as an intensity change in the two conjugate diffraction spots.

Clustering real space images for virtual imaging

Conventionally, we represent 4D-STEM datasets in real-space major order (x, y, kx, ky). However, we can also view the data in momentum-space major order (kx, ky, x, y). Instead of a 2D array of diffraction patterns, we can visualize the 4D dataset as a 2D array of real-space images generated from diffraction pattern intensities at a single momentum-space coordinate (Fig. 5a). Due to this property of 4D datasets, our hierarchical method could also be extended to clustering these real-space images (Fig. 5b), aimed at analyzing the data from a different dimension. However, the quantitative intensity of real-space images varies dramatically across the diffraction space. Consequently, the clustering results are dominated by the intensity effect, overpowering the actual feature information shown in the contrast (Supplementary Fig. 15a). To uncover the actual features, we normalized the real space image as an additional preprocessing step before clustering (Supplementary Fig. 15b), which provides similar intensity in the real space images for better recognition of sample features using our method. Followed by the hierarchical method, the real-space features in different momentum-space pixels can be uncovered.

Fig. 5: Clustering results on real space images in 4D-STEM datasets.
figure 5

a Visualizing 4D data in a momentum-major order, where each pixel in diffraction pattern can be considered as a real-space image. Scale bar, 500 nm. b Schematic of the divisive hierarchical clustering architecture on real space images. c Map of hierarchical clustering results in diffraction space on a WS2–WSe2 superlattice. dg Mean real-space images of the superlattice in each cluster. d Displays the image from dark blue area in (c), which represents a virtual BF image; e, f are the images from light blue and yellow portions in (c), corresponding to DF images for different flakes. g Sums all other areas in (c), indicating a thickness variation in the sample. h Map of hierarchical clustering results in diffraction space on a cross-sectional InGaP/GaAs crystal, with an ADF image displayed in the inset. Scale bar, 200 nm. in Mean real-space images of the sample in each cluster. i corresponds to the center beam, the green area in (h), and shows a virtual BF image; j, k are from the dark blue and cyan area in respect, which are from the amorphous carbon and thickness effect in the sample; ln are virtual DF images for the cross-section, showing strain effects and twin grains.

We re-investigate 4D data of the WS2–WSe2 superlattices using this clustering approach to segment the diffraction space into multiple clusters (Fig. 5c). This method works by effectively placing virtual objective apertures in the diffraction space, which can accurately select the diffraction coordinates based on their generated real-space image similarity. In each cluster, the averaged real-space image shows results equivalent to different modes in STEM, including virtual bright-field (BF) (Fig. 5d) and DF (Fig. 5e, f) images. The DF images of different flakes are separated (Fig. 5e, f) according to their different lattice orientations (cyan and yellow in Fig. 5c). Compared with the hierarchical clustering on diffraction patterns (Fig. 3), the results from clustering real-space images provide crystal information that is stored in momentum-space. However, we observed striping in the BF image (Fig. 5d) generated from pixels in the center beam. Upon further investigation of the data (Supplementary Fig. 15c, d), we found the stripes are caused by the center beam alignment in the pre-processing of the 4D data, which indicates the importance of more accurate alignment of the beam tilt for 4D nanobeam electron diffraction mode in STEM.

The virtual imaging through unsupervised learning can not only be used on 2D materials but also bulk materials. We investigated the epitaxial InGaP grown on GaAs, where the complexity of strain and dislocations in the InGaP layer create challenges to quantitatively understand the material structure from conventional methods (ADF-STEM image in inset of Fig. 5h). As the strain profile in the material dramatically affects its properties and performance, uncovering the complicated crystalline structure in the film becomes crucial. For such complex materials, our real-space clustering approach segments the reciprocal space into six parts. A BF image (Fig. 5i) is generated from the segment where the center beam is located (green part in Fig. 5h). A low-angle ADF (LAADF) image (Fig. 5j) is reconstructed from low scattering angles between the center beam and first order diffraction spots (dark blue part in Fig. 5h), which highlights the amorphous carbon protecting layer on top of the film due to the amorphous scattering ring formed at this low angle. In addition, higher angle areas that exclude the diffraction spots (light blue part of Fig. 5h) display elastically scattered electrons that roughly represent the thickness of the sample (Fig. 5k). The remaining three clusters indicate the crystallinity of the thin film, providing virtual DF images of three lattice orientations (Fig. 5l–n). From the diffraction map (Fig. 5h), we conclude that Fig. 5l, m show small tilts possibly caused by the lattice strain in InGaP, while Fig. 5n displays a twin domain formed in the film.

Discussion

We intend to compare different dimension reduction methods and determine the most efficient one for our application. The EMPAD records 128 × 128 diffraction patterns so each pattern has 16834 pixels. However, the useful structural information is concentrated only in the diffraction spots, which is a small part in the whole pattern. A condensed representation of the data significantly improves computational speed and feature selection. In the preprocessing step, we chose to place STD masks on diffraction patterns to reduce the data size. However, there are more elegant approaches to reduce the dimension of the data such as Principal Component Analysis (PCA) and UMAP, but they are not desirable for our hierarchical clustering method.

PCA computes the principal components based on matrix factorization but since it is applied to the whole dataset, only the main difference is captured while the minor differences are ignored. For example, when applying the hierarchical clustering on the PCA components of the WSe2–WS2 junction in Fig. 2, the WSe2 and WS2 samples can be separated in the first two rounds (Supplementary Fig. 16b). However, in the next round of clustering, the rotations cannot be captured (Supplementary Fig. 16c) unless we re-apply PCA on each sub-cluster before each round clustering, which takes more time and memory. The need to re-apply dimension reduction on each sub-cluster makes PCA undesirable for our clustering method.

The other feature extraction method we tested was UMAP, which approximates the features in low-dimensional manifold space. Compared with PCA, UMAP can capture both the major and minor features in the sample. However, the clustering results show striping artifacts (Supplementary Fig. 16d), while the real deformation features are hidden. Due to this artifact, we do not use UMAP as a dimension reduction method but only as a visualization method.

In addition, there are alternative clustering methods besides K-Means, including Agglomerative clustering, BIRCH clustering, Spectral clustering, etc. To quantitively compare the efficiency and performance of different clustering methods, we created the ground truth label on the WS2 cluster from the manually measured rotation map (Supplementary Fig. 4a). We set the positive rotation angle as label 1 and the negative rotation angle as label 2. Then we cluster this dataset with different methods, record the time and calculate the accuracy. Based on the results shown in Supplementary Fig. 4, the Mini-batch K-means method is the fastest. However, due to the random initialization of this algorithm, the clustering results are not stable. The spectral clustering provides the best accuracy but takes a much longer time. Considering the tradeoff between time and performance, K-means was chosen as the clustering method in each round of the hierarchical clustering architecture.

Here, we summarize the combination of different dimension reduction and clustering methods on the WS2 dataset. The time and accuracy of each method are shown in Supplementary Table 1, which proved the STD selection and K-means are suitable for our hierarchical clustering architecture.

Finally, Our method demonstrates a quick initial analysis of 4D-STEM data and allows for easier and quicker discovery of unexpected deformations in a crystalline sample. However, our approach does not focus on providing highly accurate maps of such deformations, due to the limitation of clustering data. The method provided high accuracy (>99%) for discrete features, but only showed a reasonable accuracy (>80%) to distinguish a continuous deformation (Supplementary Table 1). Nevertheless, it is sufficient to inform users of the existence of such continuous features and provide a quick initial analysis of the 4D data, but further processing of the 4D data is required to quantitatively map them.

We also evaluate the precision (or consistency) of the K-means approach by running the algorithm 100 times on the same dataset with random initial clustering centers. The testing datasets contain continuous features. The result (Supplementary Fig. 17) shows that 88% of the total runs possess an accuracy above 75% for this continuous feature, indicating the reliability of the approach.

In summary, we have demonstrated a method using divisive hierarchical unsupervised machine learning to perform initial analysis of 4D-STEM datasets, which may accelerate and automate the study of lattice deformations in materials. We have applied this method to extract such features from different 2D lateral heterojunctions, thicker 3D materials, and cross-sectional crystals. The purely data-driven analysis uncovers different types of material deformations in the samples, such as strain, lattice distortion, bending contour, etc. Combined with highly accurate mapping techniques, our method may lead to a crucial step towards a fully autonomous method for the analysis of subtle lattice deformations. In addition, this approach may be potentially expanded to broader material systems or other imaging techniques that generate large and multidimensional datasets, benefiting the development of future materials, techniques, and applications.

Methods

EMPAD data acquisition

All 4D-STEM datasets were acquired on an aberration-corrected Thermo Fisher Titan Themis. The 4D datasets of the 2D lateral heterojunction were acquired at 80 kV. A 1.6 mrad convergence angle was used, leading to a ~3 nm probe size. More experimental details can be found in our previous work19. The 4D datasets collected on the silver nanoprism sample and cross-sectional semiconductors were acquired at 300 kV. For 80 kV electron beam, 151 analog-to-digital units (ADUs) correspond to one microscope electron per pixel, while for 300 kV electron beam, 579 ADUs represent one electron per pixel18. For all the datasets, an exposure time of 1.86 ms (1 ms acquisition time along with 0.86 ms readout time) was employed when acquiring the EMPAD 4D datasets. The estimated dose rate is ~105 e Å−2 s−1. The scan size in real space (the number of pixels the beam scan across) can be set from 64 × 64 to 512 × 512. The scan size of the data used in this paper was 256 × 256.