## Abstract

Coherent x-ray imaging and scattering from accelerator based sources such as synchrotrons continue to impact biology, medicine, technology, and materials science. Many synchrotrons around the world are currently undergoing major upgrades to increase their available coherent x-ray flux by approximately two orders of magnitude. The improvement of synchrotrons may enable imaging of materials *in operando* at the atomic scale which may revolutionize battery and catalysis technologies. Current algorithms used for phase retrieval in coherent x-ray imaging are based on the projection onto sets method. These traditional iterative phase retrieval methods will become more computationally expensive as they push towards atomic resolution and may struggle to converge. Additionally, these methods do not incorporate physical information that may additionally constrain the solution. In this work, we present an algorithm which incorporates molecular dynamics into Bragg coherent diffraction imaging (BCDI). This algorithm, which we call PRAMMol (Phase Retrieval with Atomic Modeling and Molecular Dynamics) combines statistical techniques with molecular dynamics to solve the phase retrieval problem. We present several examples where our algorithm is applied to simulated coherent diffraction from 3D crystals and show convergence to the correct solution at the atomic scale.

### Similar content being viewed by others

## Introduction

Coherent diffraction imaging (CDI) is a lens-less imaging technique that uses diffracted x-rays, electrons, or visible light to image a sample^{1,2,3}. To successfully image a sample, CDI must obtain both the phase and amplitude of the measured photons. During measurement, however, only the signal is recovered and the phase information of the photons is lost^{4,5,6}. This problem, called the phase problem, is not unique to CDI, and occurs in several other areas of physics, imaging, and signal processing^{7,8}.

A particular application of CDI that has potential for near-atomic resolution is Bragg CDI (BCDI)^{9,10,11}. In BCDI, the coherent x-rays scattered from small micron-sized crystals are measured in a three dimensional region around one or more Bragg peaks in reciprocal space. An iterative phase retrieval algorithm can then reconstruct the 3D strain field of the micro-crystal or metallic grain from the measured diffraction intensities^{12,13,14,15,16}. Furthermore, recent advances in BCDI have enabled measurements of multiple Bragg peaks which allows reconstruction of the full strain tensor inside the crystal^{14,16,17,18}. Much of this work has been enabled by complimentary Laue diffraction microscopy that enables the nanocrystal or sample in question to have its crystalline orientation determined and multiple Bragg peaks easily measured^{19,20}.

Most state-of-the-art phase retrieval algorithms use an iterative combination of several methods to solve the phase problem^{2,21,22}. The most fundamental of these methods is an alternating projection method called error reduction (ER)^{22,23,24}. Because ER is equivalent to gradient descent with a sub-optimal step size^{22} and the phase problem is naturally non-convex^{22}, ER alone tends to stagnate in local minima. Several global optimization methods have been developed that allow phase retrieval algorithms to escape local minima, such as hybrid input/output (HIO), charge flipping, and shrinkwrap^{25,26,27}. These phase retrieval methods have been used successfully in recent years to study materials *in operando*, yielding insights into failure mechanisms of battery materials^{28,29,30,31,32} and imaging strain in platinum nanoparticles during reduction of carbon monoxide for automotive exhaust reduction^{33,34,35}.

While many successful phase retrieval algorithms exist, few phase retrieval algorithms incorporate materials models. Materials models, such as density functional theory, molecular dynamics (MD), mesoscale modeling, and finite element models, contain a large amount of information about the materials they imitate. If implemented correctly, adding information from materials models to phase retrieval algorithms would constrain the solution to be physically reasonable and significantly restrict the search space of the phase problem. Recent work has indirectly incorporated materials models through physics-aware algorithms based on machine learning principles^{36,37}. These physics-aware algorithms train machine learning models on data obtained from MD simulations and their corresponding simulated diffraction patterns. However, these algorithms do not explicitly incorporate a physical model during the solving process.

Here, we present a phase retrieval algorithm, called PRAMMol for Phase Retrieval with Atomic Modeling and Molecular Dynamics (see Fig. 1). PRAMMol directly incorporates a physical model during the solving process and was designed with expected diffraction limited storage rings (DLSR) synchrotron upgrades in mind. These synchrotron upgrades will allow for an increase of up to 200 times brightness in coherent x-rays, and may enable sub-Ångstrom resolution^{10,11}. While atomic resolution has routinely been demonstrated with coherent electron sources^{38,39}, atomic resolution from CDI has been more challenging to achieve. Because upgraded synchrotrons could enable atomic scale *in operando* BCDI, PRAMMol was designed to work at the atomic scale and uses MD as its physical model (All LAMMPS^{40,41,42} calculations are run with an Al potential^{42}. However, the methodology presented here is agnostic to the specific potential used and any monoatomic interatomic potential should achieve similar results.).

## Results

### Time integrated photon flux trials

To demonstrate the power of physics-based phase retrieval and estimate the achieved resolution of PRAMMol across a large range of available photon fluxes, 10 trials were run across 20 values of time integrated photon flux (TIPF)^{10} for a total of 200 trials. As described in “Grain Creation”, a 4679 atom face centered cubic (FCC) crystal of ~6 nm diameter was created with a single vacancy at its center (see Fig. 2). For each trial, three diffraction patterns were simulated at the (−1,1,1),(1,−1,1) and (1,1,−1) peaks (see “Diffraction Pattern Simulation” and Fig. 3). While this choice of peaks is arbitrary, three linearly independent peaks are required to successfully reconstruct any three dimensional sample. To decrease the total computational cost, the initial guess of each reconstruction was a low-resolution reconstruction which can be determined through ER/HIO methods. For this work, we accomplished this by creating a coarse grain model of the true object with a resolution of 5 Å. This low-resolution solution was filled with atoms with an FCC lattice with a lattice constant of 4 Å, which on purpose was initiated to not be the exact correct lattice constant. These atoms were placed randomly (i.e., with respect to the true atom positions) but with the correct orientation. The relative lattice angular orientation and lattice spacing can be ascertained from the locations of the Bragg peaks in reciprocal space.

After all 200 trials were complete, the resolution was calculated as described in “Resolution Calculation”. Figure 4 shows that PRAMMol is able to achieve atomic reolution at a TIPF of about 10^{18} ph μm^{−2}. Additionally, once atomic resolution is achieved, PRAMMol reconstructs at nearly picometer resolution and continues to improve resolution as TIPF increases.

### Material defect trials

This analysis required the lattice information of the crystal to be known in advance. While this information can be easily determined from the measured diffraction pattern, we also show that PRAMMol is able to successfully reconstruct samples without the lattice information. As described in “Grain Creation”, three FCC crystal samples were created: a 4791 atom sample with no defects, a 4679 atom sample with a single vacancy, and an 8777 atom sample with a screw dislocation. For each sample, a diffraction pattern was simulated with a TIPF of ~10^{20} ph μm^{−2} (see “Diffraction Pattern Simulation” and Fig. 3).

PRAMMol started the reconstruction with a random number of atoms and random atom positions. PRAMMol then reconstructed the atom positions of the samples from their simulated diffraction patterns (modulus squared) and a low-resolution reconstruction of the sample. For the crystal with a single vacancy, PRAMMol converged to the correct atomic positions in ~30 iterations. PRAMMol was also able to find the correct number of atoms in the original object and an unknown scaling constant that encompasses the TIPF and several other experimental factors (Fig. 5). For any single atom in the reconstruction the position error was less than 1 pm (see Fig. 6).

Similarly, for the defect-free sample and the screw dislocation, reconstructions resulted in position errors of less than 1 pm for any single atom. The number of iterations to convergence varied based on how complex the samples were (see Fig. 6 and Supplementary Videos). The reconstruction of the bulk crystal converged to the correct object in around 40 iterations, while the sample with the screw dislocation required 200 iterations to converge.

### Temperature trials

In these simulations, x-rays were assumed to scatter off of point particles at a well defined position. For the grains shown in Figs. 2–6, this is a valid assumption because the grains were relaxed and had no temperature dependence (i.e., at 0 K). Experimentally, however, picometer resolution is very unlikely to be achieved for several reasons, one of which is lattice vibrations due to finite temperature. To test the effectiveness of PRAMMol in more realistic experimental conditions, we completed a temperature study with 10 independent reconstruction trials across 10 temperatures for a total of 100 trials. More details can be found in “Temperature-Dependent Diffraction Pattern”. As described in “Grain Creation”, an 8777 atom sample with no defects was created. For each trial, a diffraction pattern with a TIPF of ~10^{20} ph μm^{−2} was created for the sample at the desired temperature as described in “Temperature-Dependent Diffraction Pattern”. Again, the initial guess of each reconstruction was a low-resolution approximation filled with FCC atoms with a lattice constant of 4 Å.

As shown in Fig. 7, PRAMMol was able to reconstruct at sub-Angstrom resolution at or below 400 K. Additionally, the mean average error of the positions of these reconstructions was beneath 0.1 Å. From Fig. 8, we see that PRAMMol is able to successfully reconstruct the interior of the sample, but has some difficulty reconstructing the surface at room temperature. This, however, is somewhat unsurprising because of the unphysical nature of the simulation used to create the diffraction pattern. Because the object is in free space and energy is being continuously added and removed to preserve the correct temperature, there is no guarantee that a nonzero total angular or linear momentum is not introduced. While the object was centered at every iteration, negating the linear momentum, the total angular momentum was allowed to fluctuate, causing the object to rotate more than a sample fixed to a substrate would.

## Discussion

While atomic resolution BCDI has yet to be demonstrated experimentally, we have shown through simulation that PRAMMol can achieve atomic resolution on small particles at values of TIPF that will be theoretically possible with synchrotron upgrades. Furthermore, we have shown that the only requirements to achieve atomic resolution besides the necessary photon flux is a low-resolution reconstruction found through traditional BCDI methods and an accurate interatomic potential.

Additionally, we have shown that PRAMMol is still able to achieve atomic resolution at ambient temperatures. This temperature study has shown that PRAMMol is proficient well above room temperature. Additionally, rather than lose fidelity completely at temperatures near melting, PRAMMol effectively returns a reconstruction that resembles the output of traditional phase-retrieval with nanometer resolution.

These results are not exhaustive, but they do give compelling evidence to investigate BCDI methods that directly incorporate a physical model. We have shown that PRAMMol, paired with a low-resolution reconstruction found through traditional BCDI methods, has the potential to achieve atomic resolution with less photon flux than traditional BCDI methods alone and that PRAMMol continues to outperform these methods as photon flux increases. Additionally, PRAMMol has several properties that allow it to perform better than projection based methods in certain situations and could extend BCDI to atomic resolution without the need to measure the small angle x-ray scattering signal.

Traditional reconstructions require a regular grid, not allowing for electron density to be defined between them. PRAMMol, on the other hand, defines atomic positions and allows these to be placed anywhere in space, removing any pixel resolution limit that is inherent in traditional BCDI algorithms. Additionally, because atom positions are well-defined point particles, it is straightforward to solve using multiple, disjoint peaks during the reconstruction. While current multi-peak BCDI algorithms are currently used^{14,16,17}, these methods are not designed for atomic resolution. Also, these algorithms must preprocess the measured data to ensure that the Bragg peaks are centered and that the frame of reference of the data is the same as the frame of reference of the object, introducing errors in the reconstruction.

However, because PRAMMol calculates the discrete Fourier transform explicitly, the computational cost increases to \({{{\mathcal{O}}}}({n}^{2})\). Because of this restriction, the current implementation would have difficulty scaling to larger objects with more than a few hundred thousand atoms. A focus of ongoing work is to combine projection-based iterative phase retrieval methods with PRAMMol. This would allow low-resolution reconstructions to be enhanced at certain voxels with atomic-resolution reconstructions.

Additionally, PRAMMol’s accuracy is highly reliant on the accuracy of the interatomic potential used. Often, embedded atom model (EAM) interatomic potentials have difficulty modeling material properties to high fidelity. Because of this, these potentials may be insufficient to accurately reconstruct samples with PRAMMol. In these cases, machine-learned interatomic potentials (MLIPs) are an effective replacement because they can model material properties to arbitrary precision, albeit with a penalty to computation time.

In summary, this work presents the first practical CDI algorithm that can achieve atomic resolution from a diffraction pattern alone. The previous work by Dietze et al. started with the known phases from their simulated samples and then added noise to determine the effect of limited photon flux^{10}. However, as we show here, PRAMMol is capable of retrieving the correct atomic positions, number of atoms, and scaling factor from the diffraction intensities alone. Additionally, PRAMMol can obtain the atom positions to extreme accuracy (limited by Poisson noise and numerical precision). Physics-based iterative phase retrieval opens the possibilities of imaging materials at the atomic scale at upgraded synchrotron facilities, substantially advancing our ability to take advantage of their unprecedented photon flux in more efficient and powerful ways.

## Methods

### PRAMMol algorithm

PRAMMol assumes that the measured intensity, *I*, of the diffraction pattern, at the position described by the Miller indices *h**k**l* in reciprocal space, is a random variable such that

where

where *n* is the number of atoms in the sample, *F*_{hkl} is the structure factor and is proportional to the electric field at the detector, *C* is an unknown scaling constant that describes the TIPF and several other experimental factors, and (*x*_{j}, *y*_{j}, *z*_{j}) is the *j*^{th} of *n* atomic positions in the material being imaged. In this formulation, the atomic positions and scaling constant become parameters of a family of probability density functions (Table 1).

The simulated diffraction patterns have ignored experimental sampling conditions involving Ewald sphere curvature and the errors that can be introduced in BCDI due to the Fourier slice theorem that have been discussed extensively in the literature^{43,44,45}. We also assume the kinematic diffraction limit, which we feel is a good approximation for such small crystals as simulated here. Because of their size, we do not expect multiple scattering, absorption, or dynamical diffraction effects to have much of an effect on the simulations. We have also neglected effects such as detector pixel size and orientation. While these experimental challenges will need to be addressed in further application of the work, these issues and methods to model and account for them have been discussed extensively in the literature^{17,18,44}.

In conjunction with a low-resolution reconstruction, PRAMMol uses maximum likelihood estimation (MLE), cross validation and MD to find estimated atom positions. PRAMMol first finds estimates for atom positions by maximizing the likelihood function (Parameter Estimation: MLE). After maximizing the likelihood, cross validation selects a valid model that results in the highest likelihood on a validation set (Model Selection: Cross Validation). Valid models include any subset of the current atom positions and new atom positions that are generated with MD (Atom Generation). In general, MLE and cross validation alone are not enough to constrain the search space and arrive at the true solution, so this process is performed in conjunction with MD energy minimization (MD Energy Minimization). This three-step process is shown in Fig. 1 and pseudocode is laid out in Algorithm 1. These methods are performed iteratively until no new models are selected during cross validation across 100 iterations.

### Algorithm 1

PRAMMol Algorithm

1: **for** i in 1:NumIter **do**

2: tDiffract ← 0.5% of Diffraction Pattern

3: vDiffract ← 99.5% of Diffraction Pattern

4: x,y,z ← BFGS(x,y,z,tDiffract) ⊳ 10 iters. of BFGS maximizing Eqtn. (6)

5: C ← getScaling ⊳ “Scaling Constant Optimization”

6: newX,newY,newZ ← GenerateAtoms ⊳ “Atom Generation”

7: **while** Object Changes **do ** ⊳ Loop until the object doesn’t change

8: ⊳ “Model Selection: Cross Validation”

9: Sort(x,y,z,vDiffract) ⊳ Sort object atoms by likelihood

10: Sort(newX,newY,newZ,vDiffract) ⊳ Sort new atoms by likelihood

11: ** while** Likelihood Increases **do**

12: AddRemoveAtoms(x,y,z,newX,newY,newZ,vDiffract) ⊳ Fig. 9

13: **end while**

14: ** end while**

15 RunLammps(x,y,z) ⊳ Fix 50% of object and relax the rest

16: **end for**

### Parameter estimation: maximum likelihood estimation

In statistical theory, point estimation methods are a class of methods that estimate the values of parameters given data that has been sampled. MLE is one such point estimation method that has several useful properties. Maximum likelihood estimates (MLEs) are both consistent and efficient estimators, meaning that they are asymptotically unbiased with a variance that matches the Cramer-Rao lower bound^{46}. Because the distribution we wish to estimate is an exponential family and the parameter space contains an open set, the MLE is the minimum variance unbiased estimator. When applied to phase retrieval problems, MLE has been successfully implemented with ptychography^{47,48}, holography^{49}, and speckle imaging^{50}.

Assuming the data is sampled independently and the likelihood function is continuous, the definition of the MLE \(\hat{\theta }\) is

where Θ is the full parameter space and \(\ell (\theta | \overrightarrow{\iota })\) is the likelihood function defined by

where \(f_{I_{{{\mathrm{j}}}}}(\iota_{{{\mathrm{j}}}} \vert \theta)\) is the probability density function of the *j*th data point. Intuitively, the likelihood function quantifies how likely one parameter choice is to fully describe. The supremum of the likelihood is then the most likely value of the parameters given the measured data. In practice, it is often easier to solve the equivalent problem

where \(\ell (\theta | \overrightarrow{\iota })\) is the log of the likelihood.

From equations (1) and (2), it follows that the log-likelihood for our problem is

Note here that ι_{hkl} is an intensity measurement and *λ*_{hkl} is a theoretical value of the intensity at a position described by the Miller indices (*h*, *k*, *l*) in reciprocal space. While it is impossible to find the global maximum of \({\ell }_{\overrightarrow{{{{\bf{I}}}}}}(C,\overrightarrow{{{{\bf{x}}}}},\overrightarrow{{{{\bf{y}}}}},\overrightarrow{{{{\bf{z}}}}}| \overrightarrow{\iota })\) analytically, numerical methods can be used to find maximizers of the log-likelihood. PRAMMol uses BFGS^{51}, a quasi-newton minimization technique to maximize the likelihood function.

However, the likelihood function has many local maxima and BFGS will in general fail to find the global maximum. Additionally, this MLE algorithm does not allow for a changing number of atoms. To overcome local maxima and find the correct number of atoms, PRAMMol uses cross validation as a model selection technique. Thus, BFGS will only be used on a portion of the diffraction pattern and the rest will be held out to be used as a validation set in model selection. Empirically, we have found that the ideal portion of the diffraction pattern to use in the MLE search is around 0.5%, with 99.5% of the diffraction pattern used in cross-validation.

### Model selection: cross-validation

Model selection can be viewed as a complement problem to parameter estimation. In parameter estimation, parameters are selected that are most likely to have generated the data. Model selection attempts to select the most likely model to have generated the data, rather than which parameters. Some common model selection procedures are cross-validation, the likelihood-ratio test, and information criterion, such as the Akaike information criterion (AIC) or the Bayesian information criterion (BIC)^{52}. For PRAMMol, cross-validation is the most applicable model selection method because of the complexity and self-regularization of the models under consideration^{29}.

The specific cross-validation fitness metric PRAMMol uses is again the likelihood. For every model under consideration, the one considered the most optimal has the largest likelihood over the validation set. To create multiple possible models for cross-validation to consider, new atom positions are generated with MD as described in the Atom Generation (Atom Generation). These new atom positions are combined with the atom positions found via MLE. The set of models that PRAMMol considers during cross-validation is then any subset of this combined set of atom positions. This is an extremely large set of models that grows exponentially as the number of atoms increases, so cross-validation is only able to compare a subset of all models. To effectively search the space of possible models, PRAMMol uses a grid search algorithm.

The grid search method used in PRAMMol considers two sets, the atom positions in the current object and the atom positions out of the object. The set of atom positions in the object are ordered according to their effect on the likelihood when removed from the object and the set of atom positions out of the object are ordered according to their effect on the likelihood when added to the object. This gives an estimate of which atoms lead to a larger likelihood.

The grid search then attempts to increase the likelihood by removing the worst performing atom in the object, adding the highest performing atom, doing both, or doing nothing. The option with the highest likelihood is chosen and the process is repeated, except that the grid search allows for previous options to be undone. As Fig. 9 shows, this can be thought of as moving across a two dimensional grid and the position is allowed to move one space in any direction. The position on one axis is where to split the set of atoms in the object, with one side of the split staying in the object and the other being removed. The position on the other axis is where to split the atoms out of the object, with one side of the split staying out of the object and the other being added.

When the grid search finds that the best option changes nothing during the search, the grid search terminates and atoms are removed from and added to the object. Then, the new sets of atoms in the object are again ordered by their individual effect on the likelihood, and the grid search is performed again. This process is repeated until the grid search cannot find any improvements after restarting.

### MD energy minimization

While the combination of cross-validation and MLE is an effective way to search the parameter space for the correct atomic positions, additional knowledge about the physical system can be added to make the search more effective. To do this, energy minimization using LAMMPS^{40,41,42} is applied to a portion of the object keeping all other atoms constant. To choose atoms for energy minimization, PRAMMol first selects all atoms above a user defined energy cutoff. Specific values of an energy cutoff are relative and subject to experimental conditions. For our examples, the cutoff energy used is half the energy per atom of a tetrahedron in free space.

After the high energy atoms are selected, PRAMMol then randomly selects a large fraction of the total number of atoms. A good fraction to choose is around 50% of the object. These atoms then have their energies minimized with MD. This energy minimization process ensures that the current set of atoms remains physically reasonable, but does not enforce this condition too strongly by operating only on a portion of the object. This allows the algorithm to escape local maxima in the likelihood landscape.

### Atom generation

The purpose of atom generation in PRAMMol is to generate all possible atom positions that may increase the likelihood of the current atom positions and be physically realistic. To generate atoms for use in cross-validation, PRAMMol uses three methods: Delaunay triangulation, force calculations, and random placement. After these three methods of generation, the atoms are filtered, removing any that are too close to each other or that do not fall in the support of a low-resolution reconstruction. Then, one by one, these atoms are combined with the current object and the energy of these atoms is minimized keeping the current object fixed. After this, the atoms are again filtered for any that are too close to each other or that do not fall in the support of a low-resolution reconstruction.

PRAMMol uses Delaunay triangulation to test atoms positions to potentially add. In a triangulation of three dimensions, each tetrahedron will connect four points. A Delaunay triangulation ensures that a sphere passing through these four points will not encompass any other point of the triangulation. For a given tetrahedron in a Delaunay triangulation, we are then guaranteed that the distance between the sphere’s center and any point in the triangulation is no smaller than the radius of the sphere.

For a metal with a predictably repeating pattern of atom locations, the radius of the circumcenter can be used to locate missing atoms or deviations from the usual arrangement of atoms. For an infinitely large crystal with no defects, the radius of every sphere in a Delaunay triangulation will be exactly the same. If, however, there is a missing atom, the radius will be significantly larger. This gives an excellent way to locate empty spaces in the current object and fill them with prospective new atom positions. Additionally, it will effectively cover most of the object in atom positions without having to search over a large space.

Another way to find missing atoms inside or outside of the object is to look at the atomic forces on each atom. After finding a local maximizer of the likelihood, the atoms will generally not be in a physically realistic location but rather will move to locations where the atoms will be most likely to create the diffraction pattern. This means that there will be atomic forces on the atoms, and in many cases, these forces will be in the direction of the location of the missing atoms. For example, if one atom is missing from the true object in the middle of a perfect crystal, then it is likely that the local maximum of the likelihood will place atoms around the missing one on the lattice positions themselves. This will then create a force on the atoms pointing at the location of the missing one.

For both Delaunay triangulation and force calculation atom generation, the placement schemes are effective but not perfect. To supplement this, atoms are placed randomly close to the object. This allows, over time, for any locations that Delaunay triangulation and force calculations do not reach to be sampled. The combination of these three methods efficiently searches the full range of physically realistic locations for cross-validation.

### Scaling constant optimization

Throughout this paper, the positions of the atoms have been thought of as parameters in a probability density function from which the intensity values are sampled. While this is true of the scaling constant as well, an analytical form of the optimal scaling constant can be found when attempting to minimize the squared error of the simulated diffraction pattern rather than maximize the likelihood. Because of this, we do not treat the scaling constant as a parameter to be solved for in MLE and instead use an analytical form that minimizes the mean squared error, *E*, which is defined as

where ι_{hkl}, *F*_{hkl}, and *h*, *k*, *l* are all defined as in equation (2). *E* can then be minimized with respect to the scaling constant by taking a derivative and setting this equal to zero, as follows.

where

The scaling constant is calculated once per iteration after the MLE step.

### Grain creation

In this work, three samples were generated, a sample with no defects, a sample with a single vacancy, and a sample with a screw dislocation. All of these samples were simulated with atomsk^{53} using the polycrystal tutorial on the atomsk website and deleting all but one grain. The sample with a single vacancy was then modified by removing one atom at the center and the sample with the screw dislocation was created using the screw dislocation tutorial on the atomsk website. After these grains were created, energy minimization was run in LAMMPS^{40,41,42} to bring the samples to an equilibrium state (see Fig. 2).

### Diffraction pattern simulation

For all reconstructions performed, the diffraction pattern was simulated over three peaks: the \(\left(\bar{1},1,1\right)\), the \(\left(1,\bar{1},1\right)\) and the \(\left(1,1,\bar{1}\right)\) peaks. For each of these peaks the absolute value of the miller indices sampled ranged from 0.4 to 1.6 in *h*, *k* and *l* with 50 measurement points in each direction. Each *h**k**l* value sampled was drawn from a Poisson distribution as defined in Equation (1) (see Fig. 3).

### Resolution calculation

To assess the effectiveness of PRAMMol, the sample with one vacancy was reconstructed 10 times across 20 values of TIPF. For one value of TIPF, the reconstructed diffraction patterns of the 10 trials were averaged over constant shells of ∣*q*∣. Similar to ref. ^{10}, the resolution is defined as *π*/*q*_{c}, where *q*_{c} is the smallest value of *q* where the mean absolute error of the phase prediction along the shell of constant ∣*q*∣ is greater than 0.5.

### Temperature-dependent diffraction pattern

To simulate a diffraction pattern from a sample at a finite temperature, the sample first underwent a canonical (NVT) ensemble simulation at the temperature of interest for 110,000 iterations. After 10,000 iterations had run, snapshots were collected every 100 iterations for a total of 1000 snapshots. After this, the measured intensity, *I*, is assumed to be a random variable such that

where

where *s* corresponds to one of the 1000 snapshots.

## Data availability

All data that was simulated for this paper is available on the BYU CIG https://github.com/byu-cig/AtomicResolutionBCDI in the “Examples” directory of the AtomicResolutionBCDI.

## Code availability

All code developed for this paper is available at the BYU CIG https://github.com/byu-cig/AtomicResolutionBCDI in the src directory. Additional scripts that simulate samples using atomsk are in the atomsk directory.

## References

Miao, J., Sandberg, R. L. & Song, C. Coherent X-ray diffraction imaging.

*IEEE J. Sel. Top. Quantum Electron.***18**, 399–410 (2012).Miao, J., Ishikawa, T., Robinson, I. K. & Murnane, M. M. Beyond crystallography: diffractive imaging using coherent x-ray light sources.

*Science***348**, 530–535 (2015).Shechtman, Y. et al. Phase retrieval with application to optical imaging: a contemporary overview.

*IEEE Signal Process. Mag.***32**, 87–109 (2015).Burge, R. E., Fiddy, M. A., Greenaway, A. H. & Ross, G. The phase problem.

*Proc. R. Soc. Lond. A. Math. Phys. Sci.***350**, 191–212 (1976).Kim, S. H., Bulmer, R. H. & Campbell, D. J. The phase problem of X-ray crystallography.

*Rep. Prog. Phys.***54**, 1427 (1991).Karamazov, M. et al. A method for the solution of the phase problem in electron microscopy.

*J. Phys. D Appl. Phys.***6**, 6 (1973).Sayre, D. Some implications of a theorem due to Shannon.

*Acta Crystallogr.***5**, 843 (1952).Miao, J., Sayre, D. & Chapman, H. N. Phase retrieval from the magnitude of the Fourier transforms of nonperiodic objects.

*J. Opt. Soc. Am. A***15**, 1662–1669 (1998).Robinson, I. & Harder, R. Coherent X-ray diffraction imaging of strain at the nanoscale.

*Nat. Mater.***8**, 291–298 (2009).Dietze, S. H., Shpyrko, O. G. & IUCr. Coherent diffractive imaging: towards achieving atomic resolution.

*J. Synchrotron Radiat.***22**, 1498–1508 (2015).Gulden, J., Yefanov, O. M., Weckert, E. & Vartanyants, I. A. Imaging of nanocrystals with atomic resolution using high-energy coherent X-rays.

*AIP Conf. Proc.***1365**, 42 (2011).Robinson, I. K., Vartanyants, I. A., Williams, G. J., Pfeifer, M. A. & Pitney, J. A. Reconstruction of the shapes of gold nanocrystals using coherent x-ray diffraction.

*Phys. Rev. Lett.***87**, 195505 (2001).Newton, M. C., Leake, S. J., Harder, R. & Robinson, I. K. Three-dimensional imaging of strain in a single ZnO nanorod.

*Nat. Mater.***9**, 120–124 (2009).Hofmann, F. et al. 3D lattice distortions and defect structures in ion-implanted nano-crystals.

*Sci. Rep.***7**, 45993 (2017).Cherukara, M. J. et al. Three-dimensional x-ray diffraction imaging of dislocations in polycrystalline metals under tensile loading.

*Nat. Commun.***9**, 3776 (2018).Wilkin, M. J. et al. Experimental demonstration of coupled multi-peak Bragg coherent diffraction imaging with genetic algorithms.

*Phys. Rev. B***103**, 214103 (2021).Gao, Y., Huang, X., Yan, H. & Williams, G. J. Bragg coherent diffraction imaging by simultaneous reconstruction of multiple diffraction peaks.

*Phys. Rev. B***103**, 14102 (2021).Maddali, S. et al. Concurrent multi-peak Bragg coherent x-ray diffraction imaging of 3D nanocrystal lattice displacement via global optimization.

*Npj Comput. Mater.***9**, 1–12 (2023).Pateras, A. et al. Combining Laue diffraction with Bragg coherent diffraction imaging at 34-ID-C.

*J. Synchrotron Radiat.***27**, 1430–1437 (2020).Zhang, Y. et al. Mapping nanocrystal orientations via scanning Laue diffraction microscopy for multi-peak Bragg coherent diffraction imaging.

*J. Synchrotron Radiat.***30**, 796–806 (2023).Fienup, J. R. Reconstruction of an object from the modulus of its Fourier transform.

*Opt. Lett.***3**, 27–29 (1978).Marchesini, S. Invited article: a unified evaluation of iterative projection algorithms for phase retrieval.

*Rev. Sci. Instrum.***78**, 11301 (2007).Gerchberg, R. W. & Saxton, W. O. Practical algorithm for determination of phase from image and diffraction plane pictures.

*Optik***35**, 237 (1972).Fienup, J. R. Reconstruction of a complex-valued object from the modulus of its Fourier transform using a support constraint.

*J. Opt. Soc. Am. A Opt. Image Sci. Vis.***4**, 118–123 (1987).Marchesini, S. et al. X-ray image reconstruction from a diffraction pattern alone.

*Phys. Rev. B***68**, 140101 (2003).Oszlányi, G. & Süto, A. Ab initio structure solution by charge flipping.

*Acta Cryst. A***60**, 134–141 (2004).Fienup, J. R. Phase retrieval algorithms: a comparison.

*Appl. Opt.***21**, 2758–2769 (1982).Ulvestad, A. et al. Single particle nanomechanics in operando batteries via lensless strain mapping.

*Nano Lett.***14**, 5123–5127 (2014).Arlot, S. & Celisse, A. A survey of cross-validation procedures for model selection.

*Stat. Surv.***4**, 40–79 (2010).Singer, A. et al. Nucleation of dislocations and their dynamics in layered oxide cathode materials during battery charging.

*Nat. Energy***3**, 641–647 (2018).Martens, I. et al. Imaging voids and defects inside Li-ion cathode LiNi0.6Mn0.2Co0.2O2 single crystals.

*ACS Appl.Mater. Interfaces.***15**, 59319–59328 (2023).Gorobtsov, O. Y. et al. Operando interaction and transformation of metastable defects in layered oxides for na-ion batteries.

*Adv. Energy Mater.***13**, 2203654 (2023).Carnis, J. et al. Twin boundary migration in an individual platinum nanocrystal during catalytic co oxidation.

*Nat. Commun.***12**, 1–10 (2021).Dupraz, M. et al. Imaging the facet surface strain state of supported multi-faceted pt nanoparticles during reaction.

*Nat. Commun.***13**, 1–10 (2022).Atlan, C. et al. Imaging the strain evolution of a platinum nanoparticle under electrochemical control.

*Nat. Mater.***22**, 754–761 (2023).Yao, Y. et al. AutoPhaseNN: unsupervised physics-aware deep learning of 3D nanoscale Bragg coherent diffraction imaging.

*Npj Comput. Mater.***8**, 1–8 (2022).Chan, H. et al. Rapid 3D nanoscale coherent imaging via physics-aware deep learning.

*Appl. Phys. Rev.***8**, 021407 (2021).Yang, Y. et al. Deciphering chemical order/disorder and material properties at the single-atom level.

*Nature***542**, 75–79 (2017).Chen, Z. et al. Electron ptychography achieves atomic-resolution limits set by lattice vibrations.

*Science***372**, 826–831 (2021).Thompson, A. P. et al. LAMMPS - a flexible simulation tool for particle-based materials modeling at the atomic, meso, and continuum scales.

*Comput. Phys. Commun.***271**, 108171 (2022).Plimpton, S. J. & Thompson, A. P. Computational aspects of many-body potentials.

*MRS Bull.***37**, 513–521 (2012).Mishin, Y., Farkas, D., Mehl, M. J. & Papaconstantopoulos, D. A. Interatomic potentials for monoatomic metals from experimental data and ab initio calculations.

*Phys. Rev. B***59**, 3393–3407 (1999).Cha, W. et al. Three dimensional variable-wavelength x-ray Bragg coherent diffraction imaging.

*Phys. Rev. Lett.***117**, 225501 (2016).Hruszkewycz, S. O. et al. High-resolution three-dimensional structural microscopy by single-angle bragg ptychography.

*Nat. Mater.***16**, 244–251 (2017).Li, P. et al. General approaches for shear-correcting coordinate transformations in Bragg coherent diffraction imaging. Part II.

*J. Appl. Crystallogr.***53**, 404–418 (2020).Pratt, J. W. F. Y. Edgeworth and R. A. Fisher on the efficiency of maximum likelihood estimation.

*Ann. Stat.***4**, 501–514 (1976).Chang, H., Enfedaque, P. & Marchesini, S. Blind ptychographic phase retrieval via convergent alternating direction method of multipliers.

*SIAM J. Imaging Sci.***12**, 153–185 (2019).Wei, X., Urbach, H. P. & Coene, W. M. J. Cramér-Rao lower bound and maximum-likelihood estimation in ptychography with Poisson noise.

*Phys. Rev. A***102**, 043516 (2020).Barmherzig, D. A. & Sun, J. Towards practical holographic coherent diffraction imaging via maximum likelihood estimation.

*Opt. Express***30**, 6886–6906 (2022).Olson, D.F., Landesman, B.T. Maximum-likelihood estimation technique for the registration of coherent speckle images in the presence of noise. In:

*Digital Image Recovery and Synthesis III*Vol. 2827, 110–120 (SPIE, 1996).Quasi-Newton Methods. In

*Numerical Optimization. Springer Series in Operations Research and Financial Engineering*(eds. Nocedal, J., Wright, S.J.) 135–163 (Springer, 2006).Ding, J., Tarokh, V. & Yang, Y. Model selection techniques: an overview.

*IEEE Signal Process. Mag.***35**, 16–34 (2018).Hirel, P. Atomsk: a tool for manipulating and converting atomic data files.

*Comput. Phys. Commun.***197**, 212–219 (2015).

## Acknowledgements

This work was supported by the DOE Office of Science (Office of Basic Energy Sciences)(Award number DE-SC0022133) and Argonne National Laboratory operated by DOE Office of Science User Facility operated under Contract No. AC02-06CH11357.

## Author information

### Authors and Affiliations

### Contributions

Jason Meziere: Conceptualization, Methodology, Formal analysis and investigation, Writing—original draft preparation, Writing—review and editing. Abi Mae Hardy: Methodology: Temperature Study, Formal analysis and investigation: Temperature Study. Anastasios Pateras: Conceptualization, Methodology, Writing—review and editing. Ross Harder: Conceptualization, Methodology, Writing—review and editing, Supervision. Richard L. Sandberg: Conceptualization, Methodology, Writing—review and editing, Funding acquisition, Resources, Supervision.

### Corresponding author

## Ethics declarations

### Competing interests

The authors declare no competing interests.

## Additional information

**Publisher’s note** Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

## Supplementary information

## Rights and permissions

**Open Access** This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article’s Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article’s Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.

## About this article

### Cite this article

Meziere, J., Carpenter, A.H., Pateras, A. *et al.* Atomic resolution coherent x-ray imaging with physics-based phase retrieval.
*npj Comput Mater* **10**, 167 (2024). https://doi.org/10.1038/s41524-024-01340-4

Received:

Accepted:

Published:

DOI: https://doi.org/10.1038/s41524-024-01340-4