diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 502b3c5..84b1700 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-08-23T01:03:09","documenter_version":"1.6.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.4","generation_timestamp":"2024-08-26T05:40:22","documenter_version":"1.6.0"}} \ No newline at end of file diff --git a/dev/BcdiAtomicExamples/examples/index.html b/dev/BcdiAtomicExamples/examples/index.html index d2ffa82..4b948b5 100644 --- a/dev/BcdiAtomicExamples/examples/index.html +++ b/dev/BcdiAtomicExamples/examples/index.html @@ -1,4 +1,4 @@ -Environment · BcdiDocs

Environment

<!– This one is a work in progress –>

[deps]
+Environment · BcdiDocs

Environment

<!– This one is a work in progress –>

[deps]
 BcdiAtomic = "a97cdeff-3185-4906-97ce-92639738da6c"
-BcdiSimulate = "b133d2d9-b23b-44ee-be6b-5f897f6a3084"
+BcdiSimulate = "b133d2d9-b23b-44ee-be6b-5f897f6a3084"
diff --git a/dev/BcdiCore.jl/.github/workflows/documentation.yml b/dev/BcdiCore.jl/.github/workflows/documentation.yml index b44d1ff..546fad3 100644 --- a/dev/BcdiCore.jl/.github/workflows/documentation.yml +++ b/dev/BcdiCore.jl/.github/workflows/documentation.yml @@ -21,7 +21,7 @@ jobs: version: '1.10' - uses: julia-actions/cache@v1 - name: Install dependencies - run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' + run: julia --project=docs/ -e 'using Pkg; Pkg.add(["Documenter","DocumenterCitations"]); Pkg.develop(url="https://github.com/byu-cxi/BcdiCore.jl.git"); Pkg.instantiate()' - name: Build and deploy env: DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key diff --git a/dev/BcdiCore.jl/README/index.html b/dev/BcdiCore.jl/README/index.html index 985774a..14b994d 100644 --- a/dev/BcdiCore.jl/README/index.html +++ b/dev/BcdiCore.jl/README/index.html @@ -1,2 +1,2 @@ -BcdiCore · BcdiDocs

BcdiCore

<!– Build Status –> <!– –>

About

Bragg Coherent Diffraction Imaging (BCDI) Core implements some of the core functionality used for future projects BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), BcdiMulti.jl (a multiscale BCDI solver), BcdiTrad.jl (a BCDI solver using projection algorithms), and BcdiStrain (a BCDI solver for mesoscale using projection algorithms). BcdiCore.jl implements the loss functions and derivatives of loss functions used in these packages.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

Currently, BcdiCore.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiCore

+BcdiCore · BcdiDocs

BcdiCore

<!– Build Status –> <!– –>

About

Bragg Coherent Diffraction Imaging (BCDI) Core implements some of the core functionality used for future projects BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), BcdiMulti.jl (a multiscale BCDI solver), BcdiTrad.jl (a BCDI solver using projection algorithms), and BcdiStrain (a BCDI solver for mesoscale using projection algorithms). BcdiCore.jl implements the loss functions and derivatives of loss functions used in these packages.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

Currently, BcdiCore.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiCore

diff --git a/dev/BcdiCore.jl/docs/Project.toml b/dev/BcdiCore.jl/docs/Project.toml deleted file mode 100644 index 2f5e0cb..0000000 --- a/dev/BcdiCore.jl/docs/Project.toml +++ /dev/null @@ -1,3 +0,0 @@ -[deps] -BcdiCore = "72eb6a3e-ca63-4742-b260-85b05ca6d9e4" -Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/dev/BcdiCore.jl/docs/make.jl b/dev/BcdiCore.jl/docs/make.jl index 7583153..40d9600 100644 --- a/dev/BcdiCore.jl/docs/make.jl +++ b/dev/BcdiCore.jl/docs/make.jl @@ -1,4 +1,6 @@ -using Documenter, BcdiCore +using Documenter, DocumenterCitations, BcdiCore + +bib = CitationBibliography(joinpath(@__DIR__, "src", "refs.bib")) makedocs( sitename="BcdiCore.jl", @@ -6,8 +8,7 @@ makedocs( prettyurls = get(ENV, "CI", nothing) == "true" ), pages = [ - "BCDI"=>"index.md", - "BcdiCore"=>"main.md", + "BcdiCore"=>"index.md", "Usage"=>[ "Overview"=>"use/overview.md", "Atomic Models"=>"use/atomic.md", @@ -15,7 +16,8 @@ makedocs( "Traditional Models"=>"use/trad.md", "Multiscale Modes"=>"use/multi.md" ] - ] + ], + plugins = [bib] ) deploydocs( diff --git a/dev/BcdiCore.jl/docs/src/index.html b/dev/BcdiCore.jl/docs/src/index.html index ce08bed..20a86f2 100644 --- a/dev/BcdiCore.jl/docs/src/index.html +++ b/dev/BcdiCore.jl/docs/src/index.html @@ -1,2 +1,2 @@ -About/Installation · BcdiDocs

Julia BCDI Documentation

About

The BYU-CXI research group maintains a suite of Julia packages to solve the Bragg Coherent Diffraction Imaging (BCDI) problem in several different regimes and circumstance.

  • BcdiCore.jl implements all of the Fourier transforms for the Julia BCDI packages. In addition, BcdiCore calculates the loss function used (either $L_2$ or the MLE estimator) and derivatives of these loss functions.

  • BcdiTrad.jl implements projection-based BCDI algorithm. Currently, this is limited to ER, HIO, and shrinkwrap.

  • BcdiStrain.jl implements a multi-peak BCDI algorithm developed by the BYU-CXI group. In addition to the alogrithms present in BcdiTrad, BcdiStrain also implements Mount, an operator that switches between peaks.

  • BcdiMeso.jl implements a BCDI algorithm that solves in the mesoscale regime. Instead of using projections, this algorithm uses a gradient-based optimization scheme. Additionally, BcdiMeso does not assume a small measurement distance away from the peak.

  • BcdiAtomic.jl is an upcoming BCDI package that implements a BCDI algorithm that solves at the atomic scale.

  • BcdiMulti.jl is an upcoming BCDI package that implements a multiscale BCDI algorithm that solves at both the mesoscale and the atomic scale.

  • BcdiSimulate.jl is an upcoming BCDI package that simulates the BCDI problem. Currently, this is only implimented at the atomic scale.

+About/Installation · BcdiDocs

BcdiCore Documentation

About

Bragg Coherent Diffraction Imaging (BCDI) Core implements some of the core functionality used for the Julia BCDI packages BcdiCore.jl implements the loss functions and derivatives of loss functions used in these packages.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

BcdiCore.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiCore

diff --git a/dev/BcdiCore.jl/docs/src/main/index.html b/dev/BcdiCore.jl/docs/src/main/index.html deleted file mode 100644 index 00f7f72..0000000 --- a/dev/BcdiCore.jl/docs/src/main/index.html +++ /dev/null @@ -1,2 +0,0 @@ - -BcdiCore Documentation · BcdiDocs

BcdiCore Documentation

About

Bragg Coherent Diffraction Imaging (BCDI) Core implements some of the core functionality used for future projects BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), BcdiMulti.jl (a multiscale BCDI solver), BcdiTrad.jl (a BCDI solver using projection algorithms), and BcdiStrain (a BCDI solver for mesoscale using projection algorithms). BcdiCore.jl implements the loss functions and derivatives of loss functions used in these packages.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

Currently, BcdiCore.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiCore

diff --git a/dev/BcdiCore.jl/docs/src/refs.bib b/dev/BcdiCore.jl/docs/src/refs.bib new file mode 100644 index 0000000..e69de29 diff --git a/dev/BcdiCore.jl/docs/src/use/atomic/index.html b/dev/BcdiCore.jl/docs/src/use/atomic/index.html index dd66aaa..acbbcd6 100644 --- a/dev/BcdiCore.jl/docs/src/use/atomic/index.html +++ b/dev/BcdiCore.jl/docs/src/use/atomic/index.html @@ -1,4 +1,4 @@ -Atomic Models · BcdiDocs

Mathematical Definitions

For the atomic model, $G(u)$ is defined as

\[G(h,k,l) = \sum_j e^{-i (x_j (h+G_h) + y_j (k+G_k) + z_j (l+G_l))} \\\]

where $x_j, y_j, z_j$ are atom positions and $h,k,l$ represent a distance away from some scattering vector $G_h, G_k, G_l$ in reciprocal space. It is important that the $h,k,l$ value are integers and that they range from $-\frac{n}{2} \to \frac{n}{2}-1$, so both real space and reciprocal space positions must be scaled. The $x_j,y_j,z_j$ positions should be shifted to lie between $0 \to 1$ and should be multiplied by $2\pi$ to capture the missing $2 \pi$ scaling in the Fourier transform exponent.

Usage

Calculating the loss function and its derivative for the atomic model is done in three steps. First, the BcdiCore.AtomicState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.

state = AtomicState(lossType, scale, intens, G, h, k, l)
+Atomic Models · BcdiDocs

Mathematical Definitions

For the atomic model, $G(u)$ is defined as

\[G(h,k,l) = \sum_j e^{-i (x_j (h+G_h) + y_j (k+G_k) + z_j (l+G_l))} \\\]

where $x_j, y_j, z_j$ are atom positions and $h,k,l$ represent a distance away from some scattering vector $G_h, G_k, G_l$ in reciprocal space. It is important that the $h,k,l$ value are integers and that they range from $-\frac{n}{2} \to \frac{n}{2}-1$, so both real space and reciprocal space positions must be scaled. The $x_j,y_j,z_j$ positions should be shifted to lie between $0 \to 1$ and should be multiplied by $2\pi$ to capture the missing $2 \pi$ scaling in the Fourier transform exponent.

Usage

Calculating the loss function and its derivative for the atomic model is done in three steps. First, the BcdiCore.AtomicState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.

state = AtomicState(lossType, scale, intens, G, h, k, l)
 setpts!(state, x, y, z, getDeriv)
-lossVal = loss(state, getDeriv, getLoss)

If the derivative is requested with the getDeriv variable, the results are stored in state.xDeriv, state.yDeriv, and state.zDeriv.

+lossVal = loss(state, getDeriv, getLoss)

If the derivative is requested with the getDeriv variable, the results are stored in state.xDeriv, state.yDeriv, and state.zDeriv.

diff --git a/dev/BcdiCore.jl/docs/src/use/meso/index.html b/dev/BcdiCore.jl/docs/src/use/meso/index.html index 0aa17de..f1ad69f 100644 --- a/dev/BcdiCore.jl/docs/src/use/meso/index.html +++ b/dev/BcdiCore.jl/docs/src/use/meso/index.html @@ -1,4 +1,4 @@ -Mesoscale Models · BcdiDocs

Mathematical Definitions

Similar to the atomic model, $G(u)$ is initially defined as

\[G(h,k,l) = \sum_j e^{-i (x'_j (h+G_h) + y'_j (k+G_k) + z'_j (l+G_l))} \\\]

where $x'_j, y'_j, z'_j$ are atom positions and $h,k,l$ represent a distance away from some scattering vector $G_h, G_k, G_l$ in reciprocal space. However, $x'_j, y'_j, z'_j$ can be thought of as an addition of lattice spacings and displacement vectors, i.e. $x_j+ux_j, y_j+uy_j, z_j+uz_j$. Then, if $G_h,G_k,G_l$ are reciprocal lattice vectors, we find that $x \cdot G$ is an integer multiple of $2\pi$, so it does not affect the simulated electric field. We are then left with

\[G(h,k,l) = \sum_j e^{-i (x_j G_h + y_j G_k + uz_j G_l)} e^{-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l))} \\\]

Coarse graining to get a mesoscale model, we get

\[G(h,k,l) = \sum_j \rho_j e^{-i (x_j h + y_j k + uz_j l)} e^{-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l))} \\\]

Again, it is important that the $h,k,l$ value are integers and that they range from $-\frac{n}{2} \to \frac{n}{2}-1$, so both real space and reciprocal space positions must be scaled. The $x'_j,y'_j,z'_j$ positions should be shifted to lie between $0 \to 1$ and should be multiplied by $2\pi$ to capture the missing $2 \pi$ scaling in the Fourier transform exponent.

Usage

Calculating the loss function and its derivative for the mesoscale model is done in three steps. First, the BcdiCore.MesoState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.

state = MesoState(lossType, scale, intens, G, h, k, l)
+Mesoscale Models · BcdiDocs

Mathematical Definitions

Similar to the atomic model, $G(u)$ is initially defined as

\[G(h,k,l) = \sum_j e^{-i (x'_j (h+G_h) + y'_j (k+G_k) + z'_j (l+G_l))} \\\]

where $x'_j, y'_j, z'_j$ are atom positions and $h,k,l$ represent a distance away from some scattering vector $G_h, G_k, G_l$ in reciprocal space. However, $x'_j, y'_j, z'_j$ can be thought of as an addition of lattice spacings and displacement vectors, i.e. $x_j+ux_j, y_j+uy_j, z_j+uz_j$. Then, if $G_h,G_k,G_l$ are reciprocal lattice vectors, we find that $x \cdot G$ is an integer multiple of $2\pi$, so it does not affect the simulated electric field. We are then left with

\[G(h,k,l) = \sum_j e^{-i (x_j G_h + y_j G_k + uz_j G_l)} e^{-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l))} \\\]

Coarse graining to get a mesoscale model, we get

\[G(h,k,l) = \sum_j \rho_j e^{-i (x_j h + y_j k + uz_j l)} e^{-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l))} \\\]

Again, it is important that the $h,k,l$ value are integers and that they range from $-\frac{n}{2} \to \frac{n}{2}-1$, so both real space and reciprocal space positions must be scaled. The $x'_j,y'_j,z'_j$ positions should be shifted to lie between $0 \to 1$ and should be multiplied by $2\pi$ to capture the missing $2 \pi$ scaling in the Fourier transform exponent.

Usage

Calculating the loss function and its derivative for the mesoscale model is done in three steps. First, the BcdiCore.MesoState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.

state = MesoState(lossType, scale, intens, G, h, k, l)
 setpts!(state, x, y, z, rho, ux, uy, uz, getDeriv)
-lossVal = loss(state, getDeriv, getLoss)

If the derivative is requested with the getDeriv variable, the results are stored in state.rhoDeriv, state.uxDeriv, state.uyDeriv, and state.uzDeriv.

+lossVal = loss(state, getDeriv, getLoss)

If the derivative is requested with the getDeriv variable, the results are stored in state.rhoDeriv, state.uxDeriv, state.uyDeriv, and state.uzDeriv.

diff --git a/dev/BcdiCore.jl/docs/src/use/multi/index.html b/dev/BcdiCore.jl/docs/src/use/multi/index.html index 3591100..d2ccdf7 100644 --- a/dev/BcdiCore.jl/docs/src/use/multi/index.html +++ b/dev/BcdiCore.jl/docs/src/use/multi/index.html @@ -1,4 +1,4 @@ -Multiscale Models · BcdiDocs

Mathematical Definitions

The multiscale model is a combination of an atomic scale and a mesoscale model. In this case, $G(h,k,l)$ is defined as

\[G(h,k,l) = G_a(h,k,l) + G_m(h,k,l)\]

where $a$ signifies the atomic model and $m$ signifies the mesoscale model.

Usage

Calculating the loss function and its derivative for the mesoscale model is done in three steps. First, the BcdiCore.MultiState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.

state = MultiState(lossType, scale, intens, G, h, k, l)
+Multiscale Models · BcdiDocs

Mathematical Definitions

The multiscale model is a combination of an atomic scale and a mesoscale model. In this case, $G(h,k,l)$ is defined as

\[G(h,k,l) = G_a(h,k,l) + G_m(h,k,l)\]

where $a$ signifies the atomic model and $m$ signifies the mesoscale model.

Usage

Calculating the loss function and its derivative for the mesoscale model is done in three steps. First, the BcdiCore.MultiState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.

state = MultiState(lossType, scale, intens, G, h, k, l)
 setpts!(state, x, y, z, mx, my, mz, rho, ux, uy, uz, getDeriv)
-lossVal = loss(state, getDeriv, getLoss)

Here x, y, z are atomic positions and mx, my, mz are the real space locations of the mesoscale model.

If the derivative is requested with the getDeriv variable, the results are stored in state.xDeriv, state.yDeriv, and state.zDeriv, state.rhoDeriv, state.uxDeriv, state.uyDeriv, and state.uzDeriv.

+lossVal = loss(state, getDeriv, getLoss)

Here x, y, z are atomic positions and mx, my, mz are the real space locations of the mesoscale model.

If the derivative is requested with the getDeriv variable, the results are stored in state.xDeriv, state.yDeriv, and state.zDeriv, state.rhoDeriv, state.uxDeriv, state.uyDeriv, and state.uzDeriv.

diff --git a/dev/BcdiCore.jl/docs/src/use/overview/index.html b/dev/BcdiCore.jl/docs/src/use/overview/index.html index e97a411..08d8971 100644 --- a/dev/BcdiCore.jl/docs/src/use/overview/index.html +++ b/dev/BcdiCore.jl/docs/src/use/overview/index.html @@ -1,2 +1,2 @@ -Overview · BcdiDocs

In general, BcdiCore.jl will be called by developers of phase retrieval codes, not end users. BcdiCore.jl implements loss functions and derivatives of loss functions for atomic models, mesoscale models, multiscale models, and traditional projection-based methods.

Available loss functions

Currently, BcdiCore.jl implements two types of losses, the average $L_2$ norm and the average log-likelihood.

Explicitly, the average $L_2$ loss is defined as

\[L_2 = \frac{1}{N} \sum_u \left( \lvert G(u) \rvert - \lvert F(u) \rvert \right)^2\]

where $G(u)$ is the simulated electric field, $\lvert F(u) \rvert^2$ is the measured intensity at a point $u$ in reciprocal space, and $N$ is the total number of meaurement points.

The average log-likelihood (for the Poisson distribution) is defined as

\[\ell = \frac{1}{N} \sum_u \lvert G(u) \rvert^2 - \lvert F(u) \rvert^2 \ln{\left(\lvert G(u) \rvert^2 \right)}\]

+Overview · BcdiDocs

In general, BcdiCore.jl will be called by developers of phase retrieval codes, not end users. BcdiCore.jl implements loss functions and derivatives of loss functions for atomic models, mesoscale models, multiscale models, and traditional projection-based methods.

Available loss functions

Currently, BcdiCore.jl implements two types of losses, the average $L_2$ norm and the average log-likelihood.

Explicitly, the average $L_2$ loss is defined as

\[L_2 = \frac{1}{N} \sum_u \left( \lvert G(u) \rvert - \lvert F(u) \rvert \right)^2\]

where $G(u)$ is the simulated electric field, $\lvert F(u) \rvert^2$ is the measured intensity at a point $u$ in reciprocal space, and $N$ is the total number of meaurement points.

The average log-likelihood (for the Poisson distribution) is defined as

\[\ell = \frac{1}{N} \sum_u \lvert G(u) \rvert^2 - \lvert F(u) \rvert^2 \ln{\left(\lvert G(u) \rvert^2 \right)}\]

diff --git a/dev/BcdiCore.jl/docs/src/use/trad/index.html b/dev/BcdiCore.jl/docs/src/use/trad/index.html index 6483b9b..d1d2850 100644 --- a/dev/BcdiCore.jl/docs/src/use/trad/index.html +++ b/dev/BcdiCore.jl/docs/src/use/trad/index.html @@ -1,3 +1,3 @@ -Traditional Models · BcdiDocs

Mathematical Definitions

Similar to the mesoscale model, $G(u)$ is initially defined as

\[G(h,k,l) = \sum_j \rho_j e^{-i (x_j h + y_j k + uz_j l)} e^{-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l))} \\\]

where $x_j, y_j, z_j$ are real space positions, $ux_j, uy_j, uz_j$ are diplacement vectors, and $h,k,l$ represent a distance away from some scattering vector $G_h, G_k, G_l$ in reciprocal space. However, we assume that, because the distance from the scattering vector and the displacement vectors are small, $u \cdot h$ is negligible. So we are left with

\[G(h,k,l) = \sum_j \rho_j e^{-i (x_j h + y_j k + uz_j l)} e^{-i (ux_j G_h + uy_j G_k + uz_j G_l)} \\\]

Then, we combine the entire $\rho_j e^{-i (ux_j G_h + uy_j G_k + uz_j G_l)}$ quantity as one variable and get

\[G(h,k,l) = \sum_j \psi_j e^{-i (x_j h + y_j k + uz_j l)} \\\]

In this case, this is an ordinary Fourier transform, so we put the factor of $2\pi$ back into $G(h,k,l)$ to get

\[G(h,k,l) = \sum_j \psi_j e^{-2 \pi i (x_j h + y_j k + uz_j l)} \\\]

Usage

Calculating the loss function and its derivative for the traditional model is done in two steps. First, the BcdiCore.TradState struct is created. Then, the loss function is calculated with BcdiCore.loss.

state = TradState(losstype, scale, intens, realSpace)
-lossVal = loss(state, getDeriv, getLoss)

If the derivative is requested with the getDeriv variable, the result us stored in state.deriv.

+Traditional Models · BcdiDocs

Mathematical Definitions

Similar to the mesoscale model, $G(u)$ is initially defined as

\[G(h,k,l) = \sum_j \rho_j e^{-i (x_j h + y_j k + uz_j l)} e^{-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l))} \\\]

where $x_j, y_j, z_j$ are real space positions, $ux_j, uy_j, uz_j$ are diplacement vectors, and $h,k,l$ represent a distance away from some scattering vector $G_h, G_k, G_l$ in reciprocal space. However, we assume that, because the distance from the scattering vector and the displacement vectors are small, $u \cdot h$ is negligible. So we are left with

\[G(h,k,l) = \sum_j \rho_j e^{-i (x_j h + y_j k + uz_j l)} e^{-i (ux_j G_h + uy_j G_k + uz_j G_l)} \\\]

Then, we combine the entire $\rho_j e^{-i (ux_j G_h + uy_j G_k + uz_j G_l)}$ quantity as one variable and get

\[G(h,k,l) = \sum_j \psi_j e^{-i (x_j h + y_j k + uz_j l)} \\\]

In this case, this is an ordinary Fourier transform, so we put the factor of $2\pi$ back into $G(h,k,l)$ to get

\[G(h,k,l) = \sum_j \psi_j e^{-2 \pi i (x_j h + y_j k + uz_j l)} \\\]

Usage

Calculating the loss function and its derivative for the traditional model is done in two steps. First, the BcdiCore.TradState struct is created. Then, the loss function is calculated with BcdiCore.loss.

state = TradState(losstype, scale, intens, realSpace)
+lossVal = loss(state, getDeriv, getLoss)

If the derivative is requested with the getDeriv variable, the result us stored in state.deriv.

diff --git a/dev/BcdiMeso.jl/.github/workflows/CI.yml b/dev/BcdiMeso.jl/.github/workflows/CI.yml index c8ebfc6..70a19d8 100644 --- a/dev/BcdiMeso.jl/.github/workflows/CI.yml +++ b/dev/BcdiMeso.jl/.github/workflows/CI.yml @@ -24,8 +24,6 @@ jobs: matrix: version: - '1.10' - - '1.6' - - 'pre' os: - ubuntu-latest arch: diff --git a/dev/BcdiMeso.jl/.github/workflows/documentation.yml b/dev/BcdiMeso.jl/.github/workflows/documentation.yml index 1f6c52f..4ef1190 100644 --- a/dev/BcdiMeso.jl/.github/workflows/documentation.yml +++ b/dev/BcdiMeso.jl/.github/workflows/documentation.yml @@ -21,7 +21,7 @@ jobs: version: '1.10' - uses: julia-actions/cache@v1 - name: Install dependencies - run: julia --project=docs/ -e 'using Pkg; Pkg.add(["Documenter","BcdiMeso"]); Pkg.instantiate()' + run: julia --project=docs/ -e 'using Pkg; Pkg.add(["Documenter","DocumenterCitations"]); Pkg.develop(url="https://github.com/byu-cxi/BcdiMeso.jl.git"); Pkg.instantiate()' - name: Build and deploy env: DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key diff --git a/dev/BcdiMeso.jl/README/index.html b/dev/BcdiMeso.jl/README/index.html index c73488b..b6da7f0 100644 --- a/dev/BcdiMeso.jl/README/index.html +++ b/dev/BcdiMeso.jl/README/index.html @@ -1,2 +1,2 @@ -BcdiMeso.jl · BcdiDocs

BcdiMeso.jl

<!– Build Status –>

About

Bragg Coherent Diffraction Imaging (BCDI) Meso (Mesoscale) implements phase retrieval for mesoscale models with stochastic gradient descent. Some of the core functionality of this project is implemented in BcdiCore.jl. Additionally, this package is part of a collection of BCDI packages consisting of BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), and BcdiMulti.jl (a multiscale BCDI solver).

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

Currently, BcdiStrain.jl is not registered in the Julia general registry. BcdiTrad.jl can be installed by running in the REPL package manager (]):

add BcdiMeso
+BcdiMeso.jl · BcdiDocs

BcdiMeso.jl

<!– Build Status –>

About

Bragg Coherent Diffraction Imaging (BCDI) Meso (Mesoscale) implements phase retrieval for mesoscale models with stochastic gradient descent. Some of the core functionality of this project is implemented in BcdiCore.jl. Additionally, this package is part of a collection of BCDI packages consisting of BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), and BcdiMulti.jl (a multiscale BCDI solver).

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

Currently, BcdiStrain.jl is not registered in the Julia general registry. BcdiTrad.jl can be installed by running in the REPL package manager (]):

add BcdiMeso
diff --git a/dev/BcdiMeso.jl/docs/Project.toml b/dev/BcdiMeso.jl/docs/Project.toml deleted file mode 100644 index dfa65cd..0000000 --- a/dev/BcdiMeso.jl/docs/Project.toml +++ /dev/null @@ -1,2 +0,0 @@ -[deps] -Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/dev/BcdiMeso.jl/docs/make.jl b/dev/BcdiMeso.jl/docs/make.jl index 754b7a7..8e8c693 100644 --- a/dev/BcdiMeso.jl/docs/make.jl +++ b/dev/BcdiMeso.jl/docs/make.jl @@ -1,4 +1,6 @@ -using Documenter, BcdiMeso +using Documenter, DocumenterCitations, BcdiMeso + +bib = CitationBibliography(joinpath(@__DIR__, "src", "refs.bib")) makedocs( sitename="BcdiMeso.jl", @@ -7,8 +9,10 @@ makedocs( ), pages = [ "BcdiMeso"=>"index.md", - "Usage"=>"use.md" - ] + "Usage"=>"use.md", + "References"=>"refs.md" + ], + plugins = [bib] ) deploydocs( diff --git a/dev/BcdiMeso.jl/docs/src/index.html b/dev/BcdiMeso.jl/docs/src/index.html index 7860121..c5d83ac 100644 --- a/dev/BcdiMeso.jl/docs/src/index.html +++ b/dev/BcdiMeso.jl/docs/src/index.html @@ -1,2 +1,2 @@ -About/Installation · BcdiDocs

BcdiMeso.jl Documentation

About

Bragg Coherent Diffraction Imaging (BCDI) Meso (Mesoscale) implements phase retrieval for mesoscale models with stochastic gradient descent.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

BcdiStrain.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiMeso
+About/Installation · BcdiDocs

BcdiMeso.jl Documentation

About

Bragg Coherent Diffraction Imaging (BCDI) Meso (Mesoscale) implements phase retrieval for mesoscale models with stochastic gradient descent.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

BcdiStrain.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiMeso
diff --git a/dev/BcdiMeso.jl/docs/src/refs.bib b/dev/BcdiMeso.jl/docs/src/refs.bib new file mode 100644 index 0000000..962bc83 --- /dev/null +++ b/dev/BcdiMeso.jl/docs/src/refs.bib @@ -0,0 +1,18 @@ +@article{carnis_towards_2019, + title = {Towards a quantitative determination of strain in {Bragg} {Coherent} {X}-ray {Diffraction} {Imaging}: artefacts and sign convention in reconstructions}, + volume = {9}, + copyright = {2019 The Author(s)}, + issn = {2045-2322}, + shorttitle = {Towards a quantitative determination of strain in {Bragg} {Coherent} {X}-ray {Diffraction} {Imaging}}, + abstract = {Bragg coherent X-ray diffraction imaging (BCDI) has emerged as a powerful technique to image the local displacement field and strain in nanocrystals, in three dimensions with nanometric spatial resolution. However, BCDI relies on both dataset collection and phase retrieval algorithms that can induce artefacts in the reconstruction. Phase retrieval algorithms are based on the fast Fourier transform (FFT). We demonstrate how to calculate the displacement field inside a nanocrystal from its reconstructed phase depending on the mathematical convention used for the FFT. We use numerical simulations to quantify the influence of experimentally unavoidable detector deficiencies such as blind areas or limited dynamic range as well as post-processing filtering on the reconstruction. We also propose a criterion for the isosurface determination of the object, based on the histogram of the reconstructed modulus. Finally, we study the capability of the phasing algorithm to quantitatively retrieve the surface strain (i.e., the strain of the surface voxels). This work emphasizes many aspects that have been neglected so far in BCDI, which need to be understood for a quantitative analysis of displacement and strain based on this technique. It concludes with the optimization of experimental parameters to improve throughput and to establish BCDI as a reliable 3D nano-imaging technique.}, + number = {1}, + journal = {Scientific Reports}, + author = {Carnis, Jérôme and Gao, Lu and Labat, Stéphane and Kim, Young Yong and Hofmann, Jan P. and Leake, Steven J. and Schülli, Tobias U. and Hensen, Emiel J. M. and Thomas, Olivier and Richard, Marie-Ingrid}, + month = nov, + year = {2019}, + note = {Publisher: Nature Publishing Group}, + keywords = {Imaging techniques, Nanoparticles}, + pages = {17357}, + file = {Full Text PDF:/Users/jmeziere/Zotero/storage/B6NNU39A/Carnis et al. - 2019 - Towards a quantitative determination of strain in .pdf:application/pdf}, +} + diff --git a/dev/BcdiMeso.jl/docs/src/refs/index.html b/dev/BcdiMeso.jl/docs/src/refs/index.html new file mode 100644 index 0000000..465894b --- /dev/null +++ b/dev/BcdiMeso.jl/docs/src/refs/index.html @@ -0,0 +1,2 @@ + +References · BcdiDocs
diff --git a/dev/BcdiMeso.jl/docs/src/use/index.html b/dev/BcdiMeso.jl/docs/src/use/index.html index 2764b89..80d11f1 100644 --- a/dev/BcdiMeso.jl/docs/src/use/index.html +++ b/dev/BcdiMeso.jl/docs/src/use/index.html @@ -1,5 +1,5 @@ -Usage · BcdiDocs

Overview

BcdiMeso implements phase retrieval in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:

state = State(intens, gVecs, recSupport, x, y, z, rho, ux, uy, uz)
+Usage · BcdiDocs

Overview

BcdiMeso implements phase retrieval in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:

state = State(intens, gVecs, recSupport, x, y, z, rho, ux, uy, uz)
 optimizeState = OptimizeState(state, primitiveRecipLattice, numPeaks)
 
-optimizeState^100 * state

This short script applies 100 stochastic gradient descent iterations iterations. This makes it easy to implement very complex recipes for phase retrieval algorithms.

API

BcdiMeso.StateType

Create an object that performs an iteration of stochastic gradient descent.

Create the reconstruction state.

source
BcdiMeso.OptimizeStateType
OptimizeState(state, primitiveRecipLattice, numPeaks)

Create an object that performs an iteration of stochastic gradient descent.

source
+optimizeState^100 * state

This short script applies 100 stochastic gradient descent iterations iterations. This makes it easy to implement very complex recipes for phase retrieval algorithms.

API

BcdiMeso.StateType

State(intensities, gVecs, recSupport, x, y, z, rho, ux, uy, uz)

Create the reconstruction state. intensities is a vector of fully measured diffraction peaks, gVecs is a vector of peak locations, and recSupport is a vector of masks over the intensities that removes those intenities from the reconstruction process. The positions of real space points (x, y, and z) must be passed in as well as the magnitude of the electron density rho and the displacement field (ux, uy, and uz).

The initialization process shifts each peak to be centered (i.e. the center of mass of the peak is moved to the center of the image).

source
BcdiMeso.OptimizeStateType
OptimizeState(state, primitiveRecipLattice, numPeaks)

Create an object that performs an iteration of stochastic gradient descent. numPeaks number of peaks are selected randomly. One step of gradient descent is taken using the More-Thuente linesearch.

This implimentation takes into account effects of small angle measurement usually ignored in the BCDI problem. This is described in [4] although this implimentation will be faster because a NUFFT is used instead of many FFTs.

source
diff --git a/dev/BcdiMeso.jl/src/Operators.jl b/dev/BcdiMeso.jl/src/Operators.jl index 760cab4..122cb0d 100644 --- a/dev/BcdiMeso.jl/src/Operators.jl +++ b/dev/BcdiMeso.jl/src/Operators.jl @@ -54,6 +54,13 @@ end OptimizeState(state, primitiveRecipLattice, numPeaks) Create an object that performs an iteration of stochastic gradient descent. +`numPeaks` number of peaks are selected randomly. One step of gradient descent +is taken using the More-Thuente linesearch. + +This implimentation takes into account effects of small angle measurement +usually ignored in the BCDI problem. This is described in [carnis_towards_2019](@cite) +although this implimentation will be faster because a NUFFT is used instead of +many FFTs. """ struct OptimizeState <: Operator numPeaks::Int64 diff --git a/dev/BcdiMeso.jl/src/State.jl b/dev/BcdiMeso.jl/src/State.jl index 2ef84d0..40ae0a3 100644 --- a/dev/BcdiMeso.jl/src/State.jl +++ b/dev/BcdiMeso.jl/src/State.jl @@ -1,7 +1,14 @@ """ - Create an object that performs an iteration of stochastic gradient descent. + State(intensities, gVecs, recSupport, x, y, z, rho, ux, uy, uz) -Create the reconstruction state. +Create the reconstruction state. `intensities` is a vector of fully measured diffraction +peaks, `gVecs` is a vector of peak locations, and `recSupport` is a vector of masks over +the intensities that removes those intenities from the reconstruction process. The +positions of real space points (`x`, `y`, and `z`) must be passed in as well as the +magnitude of the electron density `rho` and the displacement field (`ux`, `uy`, and `uz`). + +The initialization process shifts each peak to be centered (i.e. the center of +mass of the peak is moved to the center of the image). """ struct State x::CuArray{Float64, 1, CUDA.Mem.DeviceBuffer} @@ -14,14 +21,14 @@ struct State cores::Vector{BcdiCore.MesoState} shifts::Vector{Tuple{Int64,Int64,Int64}} - function State(intens, gVecs, recSupport, x, y, z, rho, ux, uy, uz) - s = size(intens[1]) + function State(intensities, gVecs, recSupport, x, y, z, rho, ux, uy, uz) + s = size(intensities[1]) h,k,l = BcdiCore.generateRecSpace(s) cores = BcdiCore.MesoState[] shifts = Tuple{Int64,Int64,Int64}[] - for i in 1:length(intens) - currIntens, currRecSupport, shift = BcdiCore.centerPeak(intens[i], recSupport[i], "center") + for i in 1:length(intensities) + currIntens, currRecSupport, shift = BcdiCore.centerPeak(intensities[i], recSupport[i], "center") push!(cores, BcdiCore.MesoState("L2", true, currIntens, gVecs[i], h, k, l, currRecSupport)) push!(shifts, shift) end diff --git a/dev/BcdiMesoExamples/README/index.html b/dev/BcdiMesoExamples/README/index.html index 7f6d1b2..88ed675 100644 --- a/dev/BcdiMesoExamples/README/index.html +++ b/dev/BcdiMesoExamples/README/index.html @@ -1,2 +1,2 @@ -- · BcdiDocs
+- · BcdiDocs
diff --git a/dev/BcdiMesoExamples/examples/index.html b/dev/BcdiMesoExamples/examples/index.html index 29eee56..25d3578 100644 --- a/dev/BcdiMesoExamples/examples/index.html +++ b/dev/BcdiMesoExamples/examples/index.html @@ -1,5 +1,5 @@ -Examples · BcdiDocs

Example 1

Environment

[deps]
+Examples · BcdiDocs

Example 1

Environment

[deps]
 BcdiCore = "72eb6a3e-ca63-4742-b260-85b05ca6d9e4"
 BcdiStrain = "3abd092d-e7bc-4ec6-94c6-c6851986118d"
 BcdiMeso = "1ffc817a-885e-4a73-a887-574cb954c7d7"
@@ -109,4 +109,4 @@
     mov(a, "../results/recon.webm", fps=250)
 end
 
-phase()

Output

+phase()

Output

diff --git a/dev/BcdiSimulate.jl/.github/dependabot.yml b/dev/BcdiSimulate.jl/.github/dependabot.yml new file mode 100644 index 0000000..700707c --- /dev/null +++ b/dev/BcdiSimulate.jl/.github/dependabot.yml @@ -0,0 +1,7 @@ +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/dev/BcdiSimulate.jl/.github/workflows/CI.yml b/dev/BcdiSimulate.jl/.github/workflows/CI.yml new file mode 100644 index 0000000..70a19d8 --- /dev/null +++ b/dev/BcdiSimulate.jl/.github/workflows/CI.yml @@ -0,0 +1,39 @@ +name: CI +on: + push: + branches: + - main + tags: ['*'] + pull_request: + workflow_dispatch: +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created + actions: write + contents: read + strategy: + fail-fast: false + matrix: + version: + - '1.10' + os: + - ubuntu-latest + arch: + - x64 + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/cache@v2 + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 diff --git a/dev/BcdiSimulate.jl/.github/workflows/CompatHelper.yml b/dev/BcdiSimulate.jl/.github/workflows/CompatHelper.yml new file mode 100644 index 0000000..cba9134 --- /dev/null +++ b/dev/BcdiSimulate.jl/.github/workflows/CompatHelper.yml @@ -0,0 +1,16 @@ +name: CompatHelper +on: + schedule: + - cron: 0 0 * * * + workflow_dispatch: +jobs: + CompatHelper: + runs-on: ubuntu-latest + steps: + - name: Pkg.add("CompatHelper") + run: julia -e 'using Pkg; Pkg.add("CompatHelper")' + - name: CompatHelper.main() + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} + run: julia -e 'using CompatHelper; CompatHelper.main()' diff --git a/dev/BcdiSimulate.jl/.github/workflows/TagBot.yml b/dev/BcdiSimulate.jl/.github/workflows/TagBot.yml new file mode 100644 index 0000000..0cd3114 --- /dev/null +++ b/dev/BcdiSimulate.jl/.github/workflows/TagBot.yml @@ -0,0 +1,31 @@ +name: TagBot +on: + issue_comment: + types: + - created + workflow_dispatch: + inputs: + lookback: + default: "3" +permissions: + actions: read + checks: read + contents: write + deployments: read + issues: read + discussions: read + packages: read + pages: read + pull-requests: read + repository-projects: read + security-events: read + statuses: read +jobs: + TagBot: + if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' + runs-on: ubuntu-latest + steps: + - uses: JuliaRegistries/TagBot@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + ssh: ${{ secrets.DOCUMENTER_KEY }} diff --git a/dev/BcdiSimulate.jl/.github/workflows/documentation.yml b/dev/BcdiSimulate.jl/.github/workflows/documentation.yml new file mode 100644 index 0000000..2239394 --- /dev/null +++ b/dev/BcdiSimulate.jl/.github/workflows/documentation.yml @@ -0,0 +1,28 @@ +name: Documentation + +on: + push: + branches: + - main # update to match your development branch (master, main, dev, trunk, ...) + tags: '*' + pull_request: + +jobs: + build: + permissions: + contents: write + pull-requests: read + statuses: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: '1.10' + - uses: julia-actions/cache@v1 + - name: Install dependencies + run: julia --project=docs/ -e 'using Pkg; Pkg.add(["Documenter","DocumenterCitations"]); Pkg.develop(url="https://github.com/byu-cxi/BcdiSimulate.jl.git"); Pkg.instantiate()' + - name: Build and deploy + env: + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key + run: julia --project=docs/ docs/make.jl diff --git a/dev/BcdiSimulate.jl/.gitignore b/dev/BcdiSimulate.jl/.gitignore new file mode 100644 index 0000000..29126e4 --- /dev/null +++ b/dev/BcdiSimulate.jl/.gitignore @@ -0,0 +1,24 @@ +# Files generated by invoking Julia with --code-coverage +*.jl.cov +*.jl.*.cov + +# Files generated by invoking Julia with --track-allocation +*.jl.mem + +# System-specific files and directories generated by the BinaryProvider and BinDeps packages +# They contain absolute paths specific to the host computer, and so should not be committed +deps/deps.jl +deps/build.log +deps/downloads/ +deps/usr/ +deps/src/ + +# Build artifacts for creating documentation generated by the Documenter package +docs/build/ +docs/site/ + +# File generated by Pkg, the package manager, based on a corresponding Project.toml +# It records a fixed state of all packages used by the project. As such, it should not be +# committed for packages, but should be committed for applications that require a static +# environment. +Manifest.toml diff --git a/dev/BcdiSimulate.jl/LICENSE b/dev/BcdiSimulate.jl/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/dev/BcdiSimulate.jl/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/dev/BcdiSimulate.jl/Project.toml b/dev/BcdiSimulate.jl/Project.toml new file mode 100644 index 0000000..ee73f22 --- /dev/null +++ b/dev/BcdiSimulate.jl/Project.toml @@ -0,0 +1,24 @@ +name = "BcdiSimulate" +uuid = "b133d2d9-b23b-44ee-be6b-5f897f6a3084" +authors = ["Jason Meziere"] +version = "1.0.0-DEV" + +[deps] +BcdiCore = "72eb6a3e-ca63-4742-b260-85b05ca6d9e4" +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +LAMMPS = "ee2e13b9-eee9-4449-aafa-cfa6a2dbe14d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[compat] +julia = "1.10" +BcdiCore = "0" +CUDA = "5.4.3" +Distributions = "0.25.110" +LAMMPS = "0.7.0" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/dev/BcdiSimulate.jl/README/index.html b/dev/BcdiSimulate.jl/README/index.html new file mode 100644 index 0000000..5a50595 --- /dev/null +++ b/dev/BcdiSimulate.jl/README/index.html @@ -0,0 +1,2 @@ + +BcdiSimulate · BcdiDocs
diff --git a/dev/BcdiSimulate.jl/docs/make.jl b/dev/BcdiSimulate.jl/docs/make.jl new file mode 100644 index 0000000..7b28a24 --- /dev/null +++ b/dev/BcdiSimulate.jl/docs/make.jl @@ -0,0 +1,21 @@ +using Documenter, DocumenterCitations, BcdiSimulate + +bib = CitationBibliography(joinpath(@__DIR__, "src", "refs.bib")) + +makedocs( + sitename="BcdiSimulate.jl", + format = Documenter.HTML( + prettyurls = get(ENV, "CI", nothing) == "true" + ), + pages = [ + "BcdiSimulate"=>"index.md", + "Usage"=>[ + "Atomic"=>"usage/atom.md" + ] + ], + plugins = [bib] +) + +deploydocs( + repo = "github.com/byu-cxi/BcdiSimulate.jl.git", +) diff --git a/dev/BcdiSimulate.jl/docs/src/.main.md.swp b/dev/BcdiSimulate.jl/docs/src/.main.md.swp new file mode 100644 index 0000000..a2245fa Binary files /dev/null and b/dev/BcdiSimulate.jl/docs/src/.main.md.swp differ diff --git a/dev/BcdiSimulate.jl/docs/src/index.html b/dev/BcdiSimulate.jl/docs/src/index.html new file mode 100644 index 0000000..fa384c0 --- /dev/null +++ b/dev/BcdiSimulate.jl/docs/src/index.html @@ -0,0 +1,2 @@ + +About/Installation · BcdiDocs

BcdiSimulate.jl Documentation

About

Bragg Coherent Diffraction Imaging (BCDI) Simulate implements methods to simulate the BCDI problem. Currently, BcdiSimulate only implements atomic scale methods, we may expand these capabilities.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

BcdiSimulate.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add https://github.com/byu-cxi/BcdiMeso.jl.git
diff --git a/dev/BcdiSimulate.jl/docs/src/refs.bib b/dev/BcdiSimulate.jl/docs/src/refs.bib new file mode 100644 index 0000000..e69de29 diff --git a/dev/BcdiSimulate.jl/docs/src/usage/atom/index.html b/dev/BcdiSimulate.jl/docs/src/usage/atom/index.html new file mode 100644 index 0000000..ea79bfc --- /dev/null +++ b/dev/BcdiSimulate.jl/docs/src/usage/atom/index.html @@ -0,0 +1,2 @@ + +Atomic Simulation · BcdiDocs

API

BcdiSimulate.atomSimulateElectricFieldMethod
atomSimulateElectricField(x, y, z, hRanges, kRanges, lRanges)

Simulate the electric field for a group of atoms (x, y, and z) on a sequence of grids in reciprocal space (hRanges, kRanges, lRanges). More concretely, calculate

$F_{hkl} = e^{- 2 \pi i (x h + y k + z l)}}$

x, y, and z do not have to lie on any grid and are assumed to be Vector{Real}. 'hRanges', 'kRanges' and 'lRanges' are not individual points, but are Vector{StepRangeLen}, that together, define the grid to sample reciprocal space over. In general, this will be faster than a full discrete Fourier transform (with $O(n^2)$ operations) because it uses an NUFFT.

source
BcdiSimulate.atomSimulateDiffractionMethod
atomSimulateDiffraction(x, y, z, hRanges, kRanges, lRanges, numPhotons; seed=nothing)

Simulate diffraction patterns for a group of atoms (x, y, and z) on a sequence of grids in reciprocal space (hRanges, kRanges, lRanges). More concretely, obtain samples from a Poisson distribution that satisfy

$I_hkl} \overset{ind}{\sim} Pois(F_{hkl})$

where

$F_{hkl} = e^{- 2 \pi i (x h + y k + z l)}}$

x, y, and z do not have to lie on any grid and are assumed to be Vector{Real}. 'hRanges', 'kRanges' and 'lRanges' are not individual points, but are Vector{StepRangeLen}, that together, define the grid to sample reciprocal space over. numPhotons defines the number of photons that will, on average, be simulated, and seed is the rng seed. In general, this will be faster than a full discrete Fourier transform (with $O(n^2)$ operations) because it uses an NUFFT.

source
BcdiSimulate.relaxCrystalMethod
relaxCrystal(x, y, z, lmpOptions, potentialName)

Use LAMMPS to relax the supplied atom positions (x, y, and z). lmpOptions defines command line options to pass to LAMMPS and the potentialName defines the interatomic potential used in the LAMMPS relaxation.

source
diff --git a/dev/BcdiSimulate.jl/src/AtomicSimulate.jl b/dev/BcdiSimulate.jl/src/AtomicSimulate.jl new file mode 100644 index 0000000..edd1aa6 --- /dev/null +++ b/dev/BcdiSimulate.jl/src/AtomicSimulate.jl @@ -0,0 +1,143 @@ +""" + atomSimulateElectricField(x, y, z, hRanges, kRanges, lRanges) + +Simulate the electric field for a group of atoms (`x`, `y`, and `z`) on +a sequence of grids in reciprocal space (`hRanges`, `kRanges`, `lRanges`). +More concretely, calculate + +``F_{hkl} = e^{- 2 \\pi i (x h + y k + z l)}}`` + +`x`, `y`, and `z` do not have to lie on any grid and are assumed to be `Vector{Real}`. +'hRanges', 'kRanges' and 'lRanges' are not individual points, but are `Vector{StepRangeLen}`, +that together, define the grid to sample reciprocal space over. In general, this will be +faster than a full discrete Fourier transform (with ``O(n^2)`` operations) because it uses +an NUFFT. +""" +function atomSimulateElectricField(x, y, z, hRanges, kRanges, lRanges) + x = CuArray{Float64}(x) + y = CuArray{Float64}(y) + z = CuArray{Float64}(z) + + elecFields = Array{ComplexF64, 3}[] + recSupport = Array{Float64, 3}[] + Gs = Vector{Float64}[] + boxSize = 1.0/Float64(hRanges[1].step) + for i in 1:length(hRanges) + Gh = Float64((hRanges[i].ref + hRanges[i].step * div(hRanges[i].len, 2)) / hRanges[i].step) + Gk = Float64((kRanges[i].ref + kRanges[i].step * div(kRanges[i].len, 2)) / kRanges[i].step) + Gl = Float64((lRanges[i].ref + lRanges[i].step * div(lRanges[i].len, 2)) / lRanges[i].step) + h = zeros(0,0,0) + k = zeros(0,0,0) + l = zeros(0,0,0) + G = [Gh, Gk, Gl] + state = BcdiCore.AtomicState( + "L2", false, + zeros(hRanges[i].len,kRanges[i].len,lRanges[i].len), + G, h, k, l, trues(0,0,0) + ) + BcdiCore.setpts!( + state, + x .* Float64(hRanges[i].step) .* 2 .* pi, + y .* Float64(kRanges[i].step) .* 2 .* pi, + z .* Float64(lRanges[i].step) .* 2 .* pi, + false + ) + BcdiCore.forwardProp(state, true) + push!(elecFields, Array(state.recipSpace)) + push!(recSupport, ones(Bool, size(elecFields[end]))) + push!(Gs, G) + end + return elecFields, recSupport, Gs, boxSize +end + +""" + atomSimulateDiffraction(x, y, z, hRanges, kRanges, lRanges, numPhotons; seed=nothing) + +Simulate diffraction patterns for a group of atoms (`x`, `y`, and `z`) on +a sequence of grids in reciprocal space (`hRanges`, `kRanges`, `lRanges`). +More concretely, obtain samples from a Poisson distribution that satisfy + +``I_hkl} \\overset{ind}{\\sim} Pois(F_{hkl})`` + +where + +``F_{hkl} = e^{- 2 \\pi i (x h + y k + z l)}}`` + +`x`, `y`, and `z` do not have to lie on any grid and are assumed to be `Vector{Real}`. +'hRanges', 'kRanges' and 'lRanges' are not individual points, but are `Vector{StepRangeLen}`, +that together, define the grid to sample reciprocal space over. `numPhotons` defines the +number of photons that will, on average, be simulated, and `seed` is the rng seed. In general, +this will be faster than a full discrete Fourier transform (with ``O(n^2)`` operations) +because it uses an NUFFT. +""" +function atomSimulateDiffraction(x, y, z, hRanges, kRanges, lRanges, numPhotons; seed=nothing) + elecFields, recSupport, Gs, boxSize = simulateElectricField(x, y, z, hRanges, kRanges, lRanges) + intens = Array{Int64, 3}[] + if seed != nothing + Random.seed!(seed) + end + for i in 1:length(elecFields) + c = numPhotons[i] / mapreduce(abs2, +, elecFields[i]) + push!(intens, rand.(Poisson.(Array(c .* abs2.(elecFields[i]))))) + end + return intens, recSupport, Gs, boxSize +end + +""" + relaxCrystal(x, y, z, lmpOptions, potentialName) + +Use LAMMPS to relax the supplied atom positions (`x`, `y`, and `z`). `lmpOptions` +defines command line options to pass to `LAMMPS` and the `potentialName` defines +the interatomic potential used in the `LAMMPS` relaxation. +""" +function relaxCrystal(x, y, z, lmpOptions, potentialName) + lo = min(minimum(x), minimum(y), minimum(z)) - 1 + hi = max(maximum(x), maximum(y), maximum(z)) + 1 + commandsInit = [ + "units metal", + "dimension 3", + "boundary f f f", + "atom_style atomic", + "atom_modify map array", + "region box block $(lo) $(hi) $(lo) $(hi) $(lo) $(hi)", + "create_box 1 box" + ] + commandsRun = [ + "change_box all boundary s s s", + "pair_style eam/alloy", + "pair_coeff * * $(potentialName)", + "neighbor 2.0 bin", + "neigh_modify every 1 delay 0 check yes", + "min_style cg", + "minimize 1e-25 1e-25 5000 10000", + ] + + numAtoms = length(x) + + lmp = LMP(lmpOptions) + indices = Int32.(collect(1:numAtoms)) + types = ones(Int32, numAtoms) + lammpsPositions = zeros(Float64, 3, numAtoms) + lammpsPositions[1,:] .= x + lammpsPositions[2,:] .= y + lammpsPositions[3,:] .= z + + for com in commandsInit + LAMMPS.command(lmp, com) + end + + LAMMPS.create_atoms(lmp, lammpsPositions, indices, types, bexpand=true) + + for com in commandsRun + LAMMPS.command(lmp, com) + end + + indsPerm = invperm(Int64.(LAMMPS.extract_atom(lmp, "id", LAMMPS.LAMMPS_INT))) + newPos = Float64.(LAMMPS.extract_atom( + lmp, "x", LAMMPS.LAMMPS_DOUBLE_2D + )) + + @views x .= newPos[1, indsPerm] + @views y .= newPos[2, indsPerm] + @views z .= newPos[3, indsPerm] +end diff --git a/dev/BcdiSimulate.jl/src/BcdiSimulate.jl b/dev/BcdiSimulate.jl/src/BcdiSimulate.jl new file mode 100644 index 0000000..41ecf2e --- /dev/null +++ b/dev/BcdiSimulate.jl/src/BcdiSimulate.jl @@ -0,0 +1,9 @@ +module BcdiSimulate + using CUDA + using LAMMPS + using Random + using Distributions + using BcdiCore + + include("AtomicSimulate.jl") +end diff --git a/dev/BcdiSimulate.jl/test/Project.toml b/dev/BcdiSimulate.jl/test/Project.toml new file mode 100644 index 0000000..3d5a6d5 --- /dev/null +++ b/dev/BcdiSimulate.jl/test/Project.toml @@ -0,0 +1,5 @@ +[deps] +BcdiSimulate = "b133d2d9-b23b-44ee-be6b-5f897f6a3084" +Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/dev/BcdiSimulate.jl/test/runtests.jl b/dev/BcdiSimulate.jl/test/runtests.jl new file mode 100644 index 0000000..1192936 --- /dev/null +++ b/dev/BcdiSimulate.jl/test/runtests.jl @@ -0,0 +1,37 @@ +using BcdiSimulate +using Test +using Random +using Distributions + +@testset "BcdiSimulate.jl" begin + n = 20 + + x = 100 .* rand(n) + y = 100 .* rand(n) + z = 100 .* rand(n) + + hStart = 20 * (rand() - 0.5) + hRange = (hStart:0.005:hStart+0.02) + kStart = 20 * (rand() - 0.5) + kRange = (kStart:0.005:kStart+0.02) + lStart = 20 * (rand() - 0.5) + lRange = (lStart:0.005:lStart+0.02) + + numPhotons = 1e6 + + Random.seed!(1) + elecFieldTester = zeros(ComplexF64, length(hRange), length(kRange), length(lRange)) + for i in 1:length(hRange), j in 1:length(kRange), k in 1:length(lRange), l in 1:length(x) + elecFieldTester[i,j,k] += exp(-1im * 2 * pi * (x[l] * hRange[i] + y[l] * kRange[j] + z[l] * lRange[k])) + end + c = numPhotons / mapreduce(abs2, +, elecFieldTester) + intensTester = rand.(Poisson.(c .* abs2.(elecFieldTester))) + + tmp, _, _, _ = BcdiSimulate.simulateElectricField(x, y, z, [hRange], [kRange], [lRange]) + elecFieldTestee = tmp[1] + tmp, _, _, _ = BcdiSimulate.simulateDiffraction(x, y, z, [hRange], [kRange], [lRange], [numPhotons], seed=1) + intensTestee = tmp[1] + + @test all(isapprox.(elecFieldTester, elecFieldTestee, rtol=1e-6)) + @test all(isapprox.(intensTester, intensTestee, rtol=1e-6)) +end diff --git a/dev/BcdiStrain.jl/.github/workflows/CI.yml b/dev/BcdiStrain.jl/.github/workflows/CI.yml index c8ebfc6..70a19d8 100644 --- a/dev/BcdiStrain.jl/.github/workflows/CI.yml +++ b/dev/BcdiStrain.jl/.github/workflows/CI.yml @@ -24,8 +24,6 @@ jobs: matrix: version: - '1.10' - - '1.6' - - 'pre' os: - ubuntu-latest arch: diff --git a/dev/BcdiStrain.jl/.github/workflows/documentation.yml b/dev/BcdiStrain.jl/.github/workflows/documentation.yml index e80a75f..bf8ed9e 100644 --- a/dev/BcdiStrain.jl/.github/workflows/documentation.yml +++ b/dev/BcdiStrain.jl/.github/workflows/documentation.yml @@ -21,7 +21,7 @@ jobs: version: '1.10' - uses: julia-actions/cache@v1 - name: Install dependencies - run: julia --project=docs/ -e 'using Pkg; Pkg.add("Documenter"); Pkg.develop(path="./"); Pkg.instantiate()' + run: julia --project=docs/ -e 'using Pkg; Pkg.add(["Documenter","DocumenterCitations"]); Pkg.develop(url="https://github.com/byu-cxi/BcdiStrain.jl.git"); Pkg.instantiate()' - name: Build and deploy env: DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key diff --git a/dev/BcdiStrain.jl/README/index.html b/dev/BcdiStrain.jl/README/index.html index 7b2483b..cda9222 100644 --- a/dev/BcdiStrain.jl/README/index.html +++ b/dev/BcdiStrain.jl/README/index.html @@ -1,2 +1,2 @@ -BcdiStrain · BcdiDocs
+BcdiStrain · BcdiDocs
diff --git a/dev/BcdiStrain.jl/docs/make.jl b/dev/BcdiStrain.jl/docs/make.jl index 9c771e8..fd41da0 100644 --- a/dev/BcdiStrain.jl/docs/make.jl +++ b/dev/BcdiStrain.jl/docs/make.jl @@ -1,4 +1,6 @@ -using Documenter, BcdiStrain +using Documenter, DocumenterCitations, BcdiStrain + +bib = CitationBibliography(joinpath(@__DIR__, "src", "refs.bib")) makedocs( sitename="BcdiStrain.jl", @@ -7,8 +9,10 @@ makedocs( ), pages = [ "BcdiStrain"=>"index.md", - "Usage"=>"use.md" - ] + "Usage"=>"use.md", + "References"=>"refs.md" + ], + plugins = [bib] ) deploydocs( diff --git a/dev/BcdiStrain.jl/docs/src/index.html b/dev/BcdiStrain.jl/docs/src/index.html index b7c5353..91b48c4 100644 --- a/dev/BcdiStrain.jl/docs/src/index.html +++ b/dev/BcdiStrain.jl/docs/src/index.html @@ -1,2 +1,2 @@ -About/Installation · BcdiDocs

BcdiStrain.jl Documentation

About

Bragg Coherent Diffraction Imaging (BCDI) Strain implements projection-based phase retrieval algorithms.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

Currently, BcdiStrain.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiStrain
+About/Installation · BcdiDocs

BcdiStrain.jl Documentation

About

Bragg Coherent Diffraction Imaging (BCDI) Strain implements projection-based phase retrieval algorithms.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

BcdiStrain.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiStrain
diff --git a/dev/BcdiStrain.jl/docs/src/refs.bib b/dev/BcdiStrain.jl/docs/src/refs.bib new file mode 100644 index 0000000..5f1b4fc --- /dev/null +++ b/dev/BcdiStrain.jl/docs/src/refs.bib @@ -0,0 +1,32 @@ +@article{Fienup1978, +author = {Fienup, J R}, +file = {:Users/rls62/Documents/Mendeley Desktop/Fienup/Opt. Lett/1978/Fienup - 1978 - Reconstruction of an object from the modulus of its Fourier transform.pdf:pdf}, +journal = {Opt. Lett.}, +pages = {27--29}, +title = {{Reconstruction of an object from the modulus of its Fourier transform}}, +volume = {3}, +year = {1978} +} + +@article{Marchesini2007, +abstract = {Iterative projection algorithms are successfully being used as a substitute of lenses to recombine, numerically rather than optically, light scattered by illuminated objects. Images obtained computationally allow aberration-free diffraction-limited imaging and the possibility of using radiation for which no lenses exist. The challenge of this imaging technique is transferred from the lenses to the algorithms. We evaluate these new computational “instruments” developed for the phase-retrieval problem, and discuss acceleration strategies.}, +author = {Marchesini, S}, +file = {:Users/rls62/Documents/Mendeley Desktop/Marchesini/Review of Scientific Instruments/2007/Marchesini - 2007 - Invited Article A unified evaluation of iterative projection algorithms for phase retrieval.pdf:pdf}, +journal = {Rev. Sci. Instrum.}, +keywords = {image reconstruction,iterative methods,light diffraction,light scattering}, +pages = {11301}, +title = {{Invited Article: A unified evaluation of iterative projection algorithms for phase retrieval}}, +volume = {78}, +year = {2007} +} + +@article{Marchesini2003a, +abstract = {A solution to the inversion problem of scattering would offer aberration-free diffraction-limited three-dimensional images without the resolution and depth-of-field limitations of lens-based tomographic systems. Powerful algorithms are increasingly being used to act as lenses to form such images. Current image reconstruction methods, however, require the knowledge of the shape of the object and the low spatial frequencies unavoidably lost in experiments. Diffractive imaging has thus previously been used to increase the resolution of images obtained by other means. Here we experimentally demonstrate an inversion method, which reconstructs the image of the object without the need for any such prior knowledge.}, +author = {Marchesini, S and others}, +file = {:Users/rls62/Documents/Mendeley Desktop/Marchesini et al/Physical Review B/2003/PhysRevB.68.140101.pdf:pdf}, +journal = {Phys. Rev. B}, +pages = {140101}, +title = {{X-ray image reconstruction from a diffraction pattern alone}}, +volume = {68}, +year = {2003} +} diff --git a/dev/BcdiStrain.jl/docs/src/refs/index.html b/dev/BcdiStrain.jl/docs/src/refs/index.html new file mode 100644 index 0000000..ca83ec5 --- /dev/null +++ b/dev/BcdiStrain.jl/docs/src/refs/index.html @@ -0,0 +1,2 @@ + +References · BcdiDocs
diff --git a/dev/BcdiStrain.jl/docs/src/use/index.html b/dev/BcdiStrain.jl/docs/src/use/index.html index 7ef84f5..d0d6dc7 100644 --- a/dev/BcdiStrain.jl/docs/src/use/index.html +++ b/dev/BcdiStrain.jl/docs/src/use/index.html @@ -1,6 +1,10 @@ -Usage · BcdiDocs

Overview

BcdiStrain implements projection-based algorithms in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:

er = BcdiTrad.ER()
+Usage · BcdiDocs

Overview

BcdiStrain implements projection-based algorithms in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:

er = BcdiTrad.ER()
 hio = BcdiTrad.HIO(0.9)
 state = BcdiTrad.State(intensities, trues(size(intensities)))
 
-(er * hio^20)^5 * state

This short script applies 20 HIO iterations and one ER iterations for a total of 5 times. This makes it easy to implement very complex recipes for phase retrieval algorithms.

API

BcdiStrain.StateType
State(intensities, recSupport)

Create a reconstruction object. The intensities and a mask over reciprocal space indicating trusted intensities need to be passed in.

source
BcdiStrain.MountType
Mount(beta, state, primitiveRecipLattice)

Create an object that switches between peaks.

source
+(er * hio^20)^5 * state

This short script applies 20 HIO iterations and one ER iterations for a total of 5 times. This makes it easy to implement very complex recipes for phase retrieval algorithms.

API

BcdiStrain.StateType
State(intensities, gVecs, recSupport)
+State(intensities, gVecs, recSupport, support)

Create a reconstruction object. intensities is a vector of fully measured diffraction peaks, gVecs is a vector of peak locations, and recSupport is a vector of masks over the intensities that removes those intenities from the reconstruction process.

The initialization process shifts each peak to be centered in the Fourier sense (i.e. the center of mass of the peak is moved to the edge of the image, or the zero frequency). If the support is not passed in, an initial guess of the support is created by taking an IFFT of the intensities and including everything above 0.1 times the maximum value.

source
BcdiStrain.ERType
ER()

Create an object that applies one iteration of Error Reduction (ER) to the currently Mounted peak. ER is an iterative projection algorithm that enforces two constraints, (1) the modulus constraint and (2) the support constraint:

  1. When moved to reciprocal space, the reconstructed object must match the diffraction pattern.
  2. The reconstructed object must fully lie within the support.

One iteration of ER first applies the modulus constraint, then the support constraint to the object, then returnns.

Gradient descent is an alternate way to view the ER algorithm becausee ER is equivalent to gradient descent with a step size of 0.5.

More information about the ER algorithm can be found in [1, 2].

source
BcdiStrain.HIOType
HIO(beta)

Create an object that applies an iteration of hybrid input-output (HIO) to the currently Mounted peak. On the interior of the support, HIO is equivalent to applying the modulus constraint as described in the ER algorithm, and on the exterior of the support, HIO is equal to the current reconstruction minus a fraction of the output after applying the modulus constraint, that is,

\[\rho_{i+1} = \begin{cases} +ER(\rho_i) & \rho \in support \\ +\rho_i - \beta * ER(\rho_i) & \rho \notin support +\end{cases}\]

Marchesini [2] has shown that the HIO algorithm is equivalent to a mini-max problem.

More information about the HIO algorithm can be found in [1, 2].

source
BcdiStrain.ShrinkType
Shrink(threshold, sigma, state::State)

Create an object that applies one iteration of the shrinkwrap algorithm to the current real space object. Shrinkwrap first applies a Gaussian blur to the current reconstruction using sigma as the width of the Gaussian. The support is then created from everything above the threshold times maximum value of the blurred object.

Further information about the shrinkwrap algorithm can be found in [3].

source
BcdiStrain.CenterType
Center(state)

Create an object that centers the current real space object. The center of mass of the support is calculated and the object is moved so the center of mass is centered in the Fourier transform sense. In other words, the center of mass is moved to the zeroth frequency, or the bottom left corner of the image.

source
BcdiStrain.MountType
Mount(beta, state, primitiveRecipLattice)

Create an object that mounts a new peak. The current real space object is projected back to update the magnitude of the electron density and the displacement field. A new peak is selected at random and the current solution is projected out to this peak.

The paper that describes this algorithm is currently in submission.

source
diff --git a/dev/BcdiStrain.jl/src/Operators.jl b/dev/BcdiStrain.jl/src/Operators.jl index cdb0dd8..8041182 100644 --- a/dev/BcdiStrain.jl/src/Operators.jl +++ b/dev/BcdiStrain.jl/src/Operators.jl @@ -14,7 +14,21 @@ end """ ER() -Create an object that applies an iteration of ER +Create an object that applies one iteration of Error Reduction (ER) +to the currently [`Mount`](@ref)ed peak. ER is an iterative projection +algorithm that enforces two constraints, (1) the modulus constraint +and (2) the support constraint: + +1. When moved to reciprocal space, the reconstructed object must match the diffraction pattern. +2. The reconstructed object must fully lie within the support. + +One iteration of ER first applies the modulus constraint, then the +support constraint to the object, then returnns. + +Gradient descent is an alternate way to view the ER algorithm becausee +ER is equivalent to gradient descent with a step size of 0.5. + +More information about the ER algorithm can be found in [Fienup1978,Marchesini2007](@cite). """ struct ER{T} <: Operator er::T @@ -32,7 +46,24 @@ end """ HIO(beta) -Create an object that applies an iteration of HIO +Create an object that applies an iteration of hybrid input-output (HIO) +to the currently [`Mount`](@ref)ed peak. On the interior of the support, +HIO is equivalent to applying the modulus constraint as described in the +[`ER`](@ref) algorithm, and on the exterior of the support, HIO is equal +to the current reconstruction minus a fraction of the output after applying +the modulus constraint, that is, + +```math +\\rho_{i+1} = \\begin{cases} +ER(\\rho_i) & \\rho \\in support \\\\ +\\rho_i - \\beta * ER(\\rho_i) & \\rho \\notin support +\\end{cases} +``` + +Marchesini [Marchesini2007](@cite) has shown that the HIO algorithm is +equivalent to a mini-max problem. + +More information about the HIO algorithm can be found in [Fienup1978,Marchesini2007](@cite). """ struct HIO{T} <: Operator hio::T @@ -48,9 +79,15 @@ function operate(hio::HIO, state) end """ - Shrink(threshold, sigma, state) + Shrink(threshold, sigma, state::State) -Create an object that applies shrinkwrap +Create an object that applies one iteration of the shrinkwrap algorithm +to the current real space object. Shrinkwrap first applies a Gaussian +blur to the current reconstruction using `sigma` as the width of the Gaussian. +The support is then created from everything above the `threshold` times +maximum value of the blurred object. + +Further information about the shrinkwrap algorithm can be found in [Marchesini2003a](@cite). """ struct Shrink{T} <: Operator shrink::T @@ -68,7 +105,11 @@ end """ Center(state) -Create an object that centers the current state +Create an object that centers the current real space object. +The center of mass of the support is calculated and the object +is moved so the center of mass is centered in the Fourier transform +sense. In other words, the center of mass is moved to the zeroth +frequency, or the bottom left corner of the image. """ struct Center{T} <: Operator center::T @@ -104,7 +145,12 @@ end """ Mount(beta, state, primitiveRecipLattice) -Create an object that switches between peaks. +Create an object that mounts a new peak. The current real space +object is projected back to update the magnitude of the electron +density and the displacement field. A new peak is selected at +random and the current solution is projected out to this peak. + +The paper that describes this algorithm is currently in submission. """ struct Mount <: Operator beta::Float64 diff --git a/dev/BcdiStrain.jl/src/State.jl b/dev/BcdiStrain.jl/src/State.jl index 2fe2977..ad36590 100644 --- a/dev/BcdiStrain.jl/src/State.jl +++ b/dev/BcdiStrain.jl/src/State.jl @@ -1,8 +1,16 @@ """ - State(intensities, recSupport) + State(intensities, gVecs, recSupport) + State(intensities, gVecs, recSupport, support) -Create a reconstruction object. The intensities and a mask over reciprocal space -indicating trusted intensities need to be passed in. +Create a reconstruction object. `intensities` is a vector of fully measured diffraction +peaks, `gVecs` is a vector of peak locations, and `recSupport` is a vector of masks over +the intensities that removes those intenities from the reconstruction process. + +The initialization process shifts each peak to be centered in the Fourier sense +(i.e. the center of mass of the peak is moved to the edge of the image, or the +zero frequency). If the support is not passed in, an initial guess of the support +is created by taking an IFFT of the intensities and including everything above +0.1 times the maximum value. """ struct State rho::CuArray{Float64, 3, CUDA.Mem.DeviceBuffer} @@ -25,18 +33,16 @@ struct State invInt = CUFFT.ifft(CuArray{Float64, 3, CUDA.Mem.DeviceBuffer}(intens[1])) support = abs.(invInt) .> 0.1 * maximum(abs.(invInt)) - s = size(support) + State(intens, gVecs, recSupports, support) + end + + function State(intens, gVecs, recSupports, support) + s = size(intens[1]) rho = CUDA.zeros(Float64, s) ux = CUDA.zeros(Float64, s) uy = CUDA.zeros(Float64, s) uz = CUDA.zeros(Float64, s) - State(intens, gVecs, recSupports, rho, ux, uy, uz, support) - end - - function State(intens, gVecs, recSupports, rho, ux, uy, uz, support) - s = size(intens[1]) - emptyCore = BcdiCore.TradState("L2", false, CUDA.zeros(Float64, s), CUDA.zeros(Float64, s), CUDA.zeros(Float64, s)) traditionals = [BcdiTrad.State(intens[i], recSupports[i], support, emptyCore) for i in 1:length(intens)] currTrad = Ref(rand(1:length(intens))) diff --git a/dev/BcdiStrainExamples/README/index.html b/dev/BcdiStrainExamples/README/index.html index 100c29f..ea6db11 100644 --- a/dev/BcdiStrainExamples/README/index.html +++ b/dev/BcdiStrainExamples/README/index.html @@ -1,2 +1,2 @@ -- · BcdiDocs
+- · BcdiDocs
diff --git a/dev/BcdiStrainExamples/examples/index.html b/dev/BcdiStrainExamples/examples/index.html index 8d2cea9..5a406f8 100644 --- a/dev/BcdiStrainExamples/examples/index.html +++ b/dev/BcdiStrainExamples/examples/index.html @@ -1,5 +1,5 @@ -Examples · BcdiDocs

Example 1

Environment

[deps]
+Examples · BcdiDocs

Example 1

Environment

[deps]
 BcdiStrain = "3abd092d-e7bc-4ec6-94c6-c6851986118d"
 FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
 Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

Code

using BcdiStrain
@@ -62,4 +62,4 @@
     mov(a, "../results/recon.webm", fps=250)
 end
 
-phase()

Output

+phase()

Output

diff --git a/dev/BcdiTrad.jl/.github/workflows/documentation.yml b/dev/BcdiTrad.jl/.github/workflows/documentation.yml index f3a9f96..a2386e1 100644 --- a/dev/BcdiTrad.jl/.github/workflows/documentation.yml +++ b/dev/BcdiTrad.jl/.github/workflows/documentation.yml @@ -21,7 +21,7 @@ jobs: version: '1.10' - uses: julia-actions/cache@v1 - name: Install dependencies - run: julia --project=docs/ -e 'using Pkg; Pkg.add(["Documenter","BcdiTrad"]); Pkg.instantiate()' + run: julia --project=docs/ -e 'using Pkg; Pkg.add(["Documenter","DocumenterCitations"]); Pkg.develop(url="https://github.com/byu-cxi/BcdiTrad.jl.git"); Pkg.instantiate()' - name: Build and deploy env: DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key diff --git a/dev/BcdiTrad.jl/README/index.html b/dev/BcdiTrad.jl/README/index.html index 0f9058e..038755b 100644 --- a/dev/BcdiTrad.jl/README/index.html +++ b/dev/BcdiTrad.jl/README/index.html @@ -1,2 +1,2 @@ -BcdiTrad · BcdiDocs

BcdiTrad

<!– Build Status –>

About

Bragg Coherent Diffraction Imaging (BCDI) Trad (Traditional) implements projection-based phase retrieval algorithms. Some of the core functionality of this project is implemented in BcdiCore.jl. Additionally, this package is part of a collection of BCDI packages consisting of BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), and BcdiMulti.jl (a multiscale BCDI solver).

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

Currently, BcdiTrad.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiTrad
+BcdiTrad · BcdiDocs

BcdiTrad

<!– Build Status –>

About

Bragg Coherent Diffraction Imaging (BCDI) Trad (Traditional) implements projection-based phase retrieval algorithms. Some of the core functionality of this project is implemented in BcdiCore.jl. Additionally, this package is part of a collection of BCDI packages consisting of BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), and BcdiMulti.jl (a multiscale BCDI solver).

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

Currently, BcdiTrad.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiTrad
diff --git a/dev/BcdiTrad.jl/docs/Project.toml b/dev/BcdiTrad.jl/docs/Project.toml deleted file mode 100644 index 450f6a9..0000000 --- a/dev/BcdiTrad.jl/docs/Project.toml +++ /dev/null @@ -1,3 +0,0 @@ -[deps] -BcdiTrad = "b788224a-5de6-46e5-9aeb-ad1a5171efd9" -Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/dev/BcdiTrad.jl/docs/make.jl b/dev/BcdiTrad.jl/docs/make.jl index dcbf2fe..857ad61 100644 --- a/dev/BcdiTrad.jl/docs/make.jl +++ b/dev/BcdiTrad.jl/docs/make.jl @@ -1,5 +1,6 @@ -using Documenter -using BcdiTrad +using Documenter, DocumenterCitations, BcdiTrad + +bib = CitationBibliography(joinpath(@__DIR__, "src", "refs.bib")) makedocs( sitename="BcdiTrad.jl", @@ -8,8 +9,10 @@ makedocs( ), pages = [ "BcdiTrad"=>"index.md", - "Usage"=>"use.md" + "Usage"=>"use.md", + "References"=>"refs.md", ], + plugins = [bib] ) deploydocs( diff --git a/dev/BcdiTrad.jl/docs/src/index.html b/dev/BcdiTrad.jl/docs/src/index.html index 9daf62b..7cf68f1 100644 --- a/dev/BcdiTrad.jl/docs/src/index.html +++ b/dev/BcdiTrad.jl/docs/src/index.html @@ -1,2 +1,2 @@ -About/Installation · BcdiDocs

BcdiTrad.jl Documentation

About

Bragg Coherent Diffraction Imaging (BCDI) Trad (Traditional) implements projection-based phase retrieval algorithms.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

BcdiTrad.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiTrad
+About/Installation · BcdiDocs

BcdiTrad.jl Documentation

About

Bragg Coherent Diffraction Imaging (BCDI) Trad (Traditional) implements projection-based phase retrieval algorithms.

While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.

Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.

Installation

BcdiTrad.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):

add BcdiTrad
diff --git a/dev/BcdiTrad.jl/docs/src/refs.bib b/dev/BcdiTrad.jl/docs/src/refs.bib new file mode 100644 index 0000000..5f1b4fc --- /dev/null +++ b/dev/BcdiTrad.jl/docs/src/refs.bib @@ -0,0 +1,32 @@ +@article{Fienup1978, +author = {Fienup, J R}, +file = {:Users/rls62/Documents/Mendeley Desktop/Fienup/Opt. Lett/1978/Fienup - 1978 - Reconstruction of an object from the modulus of its Fourier transform.pdf:pdf}, +journal = {Opt. Lett.}, +pages = {27--29}, +title = {{Reconstruction of an object from the modulus of its Fourier transform}}, +volume = {3}, +year = {1978} +} + +@article{Marchesini2007, +abstract = {Iterative projection algorithms are successfully being used as a substitute of lenses to recombine, numerically rather than optically, light scattered by illuminated objects. Images obtained computationally allow aberration-free diffraction-limited imaging and the possibility of using radiation for which no lenses exist. The challenge of this imaging technique is transferred from the lenses to the algorithms. We evaluate these new computational “instruments” developed for the phase-retrieval problem, and discuss acceleration strategies.}, +author = {Marchesini, S}, +file = {:Users/rls62/Documents/Mendeley Desktop/Marchesini/Review of Scientific Instruments/2007/Marchesini - 2007 - Invited Article A unified evaluation of iterative projection algorithms for phase retrieval.pdf:pdf}, +journal = {Rev. Sci. Instrum.}, +keywords = {image reconstruction,iterative methods,light diffraction,light scattering}, +pages = {11301}, +title = {{Invited Article: A unified evaluation of iterative projection algorithms for phase retrieval}}, +volume = {78}, +year = {2007} +} + +@article{Marchesini2003a, +abstract = {A solution to the inversion problem of scattering would offer aberration-free diffraction-limited three-dimensional images without the resolution and depth-of-field limitations of lens-based tomographic systems. Powerful algorithms are increasingly being used to act as lenses to form such images. Current image reconstruction methods, however, require the knowledge of the shape of the object and the low spatial frequencies unavoidably lost in experiments. Diffractive imaging has thus previously been used to increase the resolution of images obtained by other means. Here we experimentally demonstrate an inversion method, which reconstructs the image of the object without the need for any such prior knowledge.}, +author = {Marchesini, S and others}, +file = {:Users/rls62/Documents/Mendeley Desktop/Marchesini et al/Physical Review B/2003/PhysRevB.68.140101.pdf:pdf}, +journal = {Phys. Rev. B}, +pages = {140101}, +title = {{X-ray image reconstruction from a diffraction pattern alone}}, +volume = {68}, +year = {2003} +} diff --git a/dev/BcdiTrad.jl/docs/src/refs/index.html b/dev/BcdiTrad.jl/docs/src/refs/index.html new file mode 100644 index 0000000..f006e15 --- /dev/null +++ b/dev/BcdiTrad.jl/docs/src/refs/index.html @@ -0,0 +1,2 @@ + +References · BcdiDocs

References

[1]
J. R. Fienup. Reconstruction of an object from the modulus of its Fourier transform. Opt. Lett. 3, 27–29 (1978).
[2]
S. Marchesini. Invited Article: A unified evaluation of iterative projection algorithms for phase retrieval. Rev. Sci. Instrum. 78, 11301 (2007).
[3]
S. Marchesini and others. X-ray image reconstruction from a diffraction pattern alone. Phys. Rev. B 68, 140101 (2003).
[4]
J. Carnis, L. Gao, S. Labat, Y. Y. Kim, J. P. Hofmann, S. J. Leake, T. U. Schülli, E. J. Hensen, O. Thomas and M.-I. Richard. Towards a quantitative determination of strain in Bragg Coherent X-ray Diffraction Imaging: artefacts and sign convention in reconstructions. Scientific Reports 9, 17357 (2019). Publisher: Nature Publishing Group.
diff --git a/dev/BcdiTrad.jl/docs/src/use/index.html b/dev/BcdiTrad.jl/docs/src/use/index.html index 187ce7c..30a096a 100644 --- a/dev/BcdiTrad.jl/docs/src/use/index.html +++ b/dev/BcdiTrad.jl/docs/src/use/index.html @@ -1,6 +1,10 @@ -Usage · BcdiDocs

Overview

Similar to pynx and others?, BcdiTrad implements projection-based algorithms in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:

er = BcdiTrad.ER()
+Usage · BcdiDocs

Overview

Similar to pynx and others?, BcdiTrad implements projection-based algorithms in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:

er = BcdiTrad.ER()
 hio = BcdiTrad.HIO(0.9)
 state = BcdiTrad.State(intensities, trues(size(intensities)))
 
-(er * hio^20)^5 * state

This short script applies 20 HIO iterations and one ER iterations for a total of 5 times. This makes it easy to implement very complex recipes for phase retrieval algorithms.

API

BcdiTrad.StateType
State(intensities, recSupport)

Create a reconstruction object. The intensities and a mask over reciprocal space indicating trusted intensities need to be passed in.

source
+(er * hio^20)^5 * state

This short script applies 20 HIO iterations and one ER iterations for a total of 5 times. This makes it easy to implement very complex recipes for phase retrieval algorithms.

API

BcdiTrad.StateType
State(intensities, recSupport)
+State(intensities, recSupport, support)

Create a reconstruction object. intensities is one fully measured diffraction peak and recSupport is a mask over the intensities that remove those intensities from the reconstruction process.

The initialization process shifts the peak to be centered in the Fourier sense (i.e. the center of mass of the peak is moved to the edge of the image, or the zero frequency). If the support is not passed in, an initial guess of the support is created by taking an IFFT of the intensities and including everything above 0.1 times the maximum value.

source
BcdiTrad.ERType
ER()

Create an object that applies one iteration of Error Reduction (ER). ER is an iterative projection algorithm that enforces two constraints, (1) the modulus constraint and (2) the support constraint:

  1. When moved to reciprocal space, the reconstructed object must match the diffraction pattern.
  2. The reconstructed object must fully lie within the support.

One iteration of ER first applies the modulus constraint, then the support constraint to the object, then returnns.

Gradient descent is an alternate way to view the ER algorithm becausee ER is equivalent to gradient descent with a step size of 0.5.

More information about the ER algorithm can be found in [1, 2].

source
BcdiTrad.HIOType
HIO(beta)

Create an object that applies an iteration of hybrid input-output (HIO). On the interior of the support, HIO is equivalent to applying the modulus constraint as described in the ER algorithm, and on the exterior of the support, HIO is equal to the current reconstruction minus a fraction of the output after applying the modulus constraint, that is,

\[\rho_{i+1} = \begin{cases} +ER(\rho_i) & \rho \in support \\ +\rho_i - \beta * ER(\rho_i) & \rho \notin support +\end{cases}\]

Marchesini [2] has shown that the HIO algorithm is equivalent to a mini-max problem.

More information about the HIO algorithm can be found in [1, 2].

source
BcdiTrad.ShrinkType
Shrink(threshold, sigma, state::State)

Create an object that applies one iteration of the shrinkwrap algorithm. Shrinkwrap first applies a Gaussian blur to the current reconstruction using sigma as the width of the Gaussian. The support is then created from everything above the threshold times maximum value of the blurred object.

Further information about the shrinkwrap algorithm can be found in [3].

source
BcdiTrad.CenterType
Center(state)

Create an object that centers the current state. The center of mass of the support is calculated and the object is moved so the center of mass is centered in the Fourier transform sense. In other words, the center of mass is moved to the zeroth frequency, or the bottom left corner of the image.

source
diff --git a/dev/BcdiTrad.jl/src/Operators.jl b/dev/BcdiTrad.jl/src/Operators.jl index f1d3c6e..7513c27 100644 --- a/dev/BcdiTrad.jl/src/Operators.jl +++ b/dev/BcdiTrad.jl/src/Operators.jl @@ -18,7 +18,20 @@ end """ ER() -Create an object that applies an iteration of ER +Create an object that applies one iteration of Error Reduction (ER). +ER is an iterative projection algorithm that enforces two constraints, +(1) the modulus constraint and (2) the support constraint: + +1. When moved to reciprocal space, the reconstructed object must match the diffraction pattern. +2. The reconstructed object must fully lie within the support. + +One iteration of ER first applies the modulus constraint, then the +support constraint to the object, then returnns. + +Gradient descent is an alternate way to view the ER algorithm becausee +ER is equivalent to gradient descent with a step size of 0.5. + +More information about the ER algorithm can be found in [Fienup1978,Marchesini2007](@cite). """ struct ER <: Operator end @@ -32,7 +45,23 @@ end """ HIO(beta) -Create an object that applies an iteration of HIO +Create an object that applies an iteration of hybrid input-output (HIO). +On the interior of the support, HIO is equivalent to applying the modulus +constraint as described in the [`ER`](@ref) algorithm, and on the exterior +of the support, HIO is equal to the current reconstruction minus a +fraction of the output after applying the modulus constraint, that is, + +```math +\\rho_{i+1} = \\begin{cases} +ER(\\rho_i) & \\rho \\in support \\\\ +\\rho_i - \\beta * ER(\\rho_i) & \\rho \\notin support +\\end{cases} +``` + +Marchesini [Marchesini2007](@cite) has shown that the HIO algorithm is +equivalent to a mini-max problem. + +More information about the HIO algorithm can be found in [Fienup1978,Marchesini2007](@cite). """ struct HIO <: Operator beta::Float64 @@ -46,9 +75,15 @@ function operate(hio::HIO, state::State) end """ - Shrink(threshold, sigma, state) + Shrink(threshold, sigma, state::State) + +Create an object that applies one iteration of the shrinkwrap algorithm. +Shrinkwrap first applies a Gaussian blur to the current reconstruction +using `sigma` as the width of the Gaussian. The support is then created +from everything above the `threshold` times maximum value of the blurred +object. -Create an object that applies shrinkwrap +Further information about the shrinkwrap algorithm can be found in [Marchesini2003a](@cite). """ struct Shrink{T} <: Operator threshold::Float64 @@ -90,7 +125,11 @@ end """ Center(state) -Create an object that centers the current state +Create an object that centers the current state. +The center of mass of the support is calculated and the object +is moved so the center of mass is centered in the Fourier transform +sense. In other words, the center of mass is moved to the zeroth +frequency, or the bottom left corner of the image. """ struct Center <: Operator xArr::CuArray{Int64, 3, CUDA.Mem.DeviceBuffer} diff --git a/dev/BcdiTrad.jl/src/State.jl b/dev/BcdiTrad.jl/src/State.jl index a79d50e..7351d5c 100644 --- a/dev/BcdiTrad.jl/src/State.jl +++ b/dev/BcdiTrad.jl/src/State.jl @@ -1,8 +1,16 @@ """ State(intensities, recSupport) + State(intensities, recSupport, support) -Create a reconstruction object. The intensities and a mask over reciprocal space -indicating trusted intensities need to be passed in. +Create a reconstruction object. `intensities` is one fully measured diffraction +peak and `recSupport` is a mask over the intensities that remove those intensities +from the reconstruction process. + +The initialization process shifts the peak to be centered in the Fourier sense +(i.e. the center of mass of the peak is moved to the edge of the image, or the +zero frequency). If the support is not passed in, an initial guess of the support +is created by taking an IFFT of the intensities and including everything above +0.1 times the maximum value. """ struct State{T} realSpace::CuArray{ComplexF64, 3, CUDA.Mem.DeviceBuffer} diff --git a/dev/BcdiTradExamples/README/index.html b/dev/BcdiTradExamples/README/index.html index ed246d1..438969c 100644 --- a/dev/BcdiTradExamples/README/index.html +++ b/dev/BcdiTradExamples/README/index.html @@ -1,2 +1,2 @@ -- · BcdiDocs
+- · BcdiDocs
diff --git a/dev/BcdiTradExamples/examples/index.html b/dev/BcdiTradExamples/examples/index.html index 5d370b8..89464c2 100644 --- a/dev/BcdiTradExamples/examples/index.html +++ b/dev/BcdiTradExamples/examples/index.html @@ -1,5 +1,5 @@ -Examples · BcdiDocs

Example 1

Environment

[deps]
+Examples · BcdiDocs

Example 1

Environment

[deps]
 BcdiTrad = "b788224a-5de6-46e5-9aeb-ad1a5171efd9"
 FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
 Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

Code

using BcdiTrad
@@ -39,4 +39,4 @@
     mov(a, "../results/recon.webm", fps=250)
 end
 
-phase()

Output

+phase()

Output

diff --git a/dev/README/index.html b/dev/README/index.html index 44bf889..b0dad89 100644 --- a/dev/README/index.html +++ b/dev/README/index.html @@ -1,2 +1,2 @@ -BcdiExamples · BcdiDocs
+BcdiExamples · BcdiDocs
diff --git a/dev/index.html b/dev/index.html index fb51d97..c39423e 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Julia BCDI · BcdiDocs

Julia BCDI Documentation

About

The BYU-CXI research group maintains a suite of Julia packages to solve the Bragg Coherent Diffraction Imaging (BCDI) problem in several different regimes and circumstance.

  • BcdiCore.jl implements all of the Fourier transforms for the Julia BCDI packages. In addition, BcdiCore calculates the loss function used (either $L_2$ or the MLE estimator) and derivatives of these loss functions.

  • BcdiTrad.jl implements projection-based BCDI algorithm. Currently, this is limited to ER, HIO, and shrinkwrap.

  • BcdiStrain.jl implements a multi-peak BCDI algorithm developed by the BYU-CXI group. In addition to the alogrithms present in BcdiTrad, BcdiStrain also implements Mount, an operator that switches between peaks.

  • BcdiMeso.jl implements a BCDI algorithm that solves in the mesoscale regime. Instead of using projections, this algorithm uses a gradient-based optimization scheme. Additionally, BcdiMeso does not assume a small measurement distance away from the peak.

  • BcdiAtomic.jl is an upcoming BCDI package that implements a BCDI algorithm that solves at the atomic scale.

  • BcdiMulti.jl is an upcoming BCDI package that implements a multiscale BCDI algorithm that solves at both the mesoscale and the atomic scale.

  • BcdiSimulate.jl is an upcoming BCDI package that simulates the BCDI problem. Currently, this is only implimented at the atomic scale.

+Julia BCDI · BcdiDocs

Julia BCDI Documentation

About

The BYU-CXI research group maintains a suite of Julia packages to solve the Bragg Coherent Diffraction Imaging (BCDI) problem in several different regimes and circumstance.

  • BcdiCore.jl (github repo) implements all of the Fourier transforms for the Julia BCDI packages. In addition, BcdiCore calculates the loss function used (either $L_2$ or the MLE estimator) and derivatives of these loss functions.

  • BcdiTrad.jl (github repo) implements projection-based BCDI algorithm. Currently, this is limited to ER, HIO, and shrinkwrap.

  • BcdiStrain.jl (github repo) implements a multi-peak BCDI algorithm developed by the BYU-CXI group. In addition to the alogrithms present in BcdiTrad, BcdiStrain also implements Mount, an operator that switches between peaks.

  • BcdiMeso.jl (github repo) implements a BCDI algorithm that solves in the mesoscale regime. Instead of using projections, this algorithm uses a gradient-based optimization scheme. Additionally, BcdiMeso does not assume a small measurement distance away from the peak.

  • BcdiAtomic.jl is an upcoming BCDI package that implements a BCDI algorithm that solves at the atomic scale.

  • BcdiMulti.jl is an upcoming BCDI package that implements a multiscale BCDI algorithm that solves at both the mesoscale and the atomic scale.

  • BcdiSimulate.jl (github repo) implements algorithms that simulate the BCDI problem. Currently, this is only implimented at the atomic scale.

diff --git a/dev/objects.inv b/dev/objects.inv index 0e39479..d28ffdd 100644 Binary files a/dev/objects.inv and b/dev/objects.inv differ diff --git a/dev/refs.bib b/dev/refs.bib new file mode 100644 index 0000000..69b8292 --- /dev/null +++ b/dev/refs.bib @@ -0,0 +1,51 @@ +@article{Fienup1978, +author = {Fienup, J R}, +file = {:Users/rls62/Documents/Mendeley Desktop/Fienup/Opt. Lett/1978/Fienup - 1978 - Reconstruction of an object from the modulus of its Fourier transform.pdf:pdf}, +journal = {Opt. Lett.}, +pages = {27--29}, +title = {{Reconstruction of an object from the modulus of its Fourier transform}}, +volume = {3}, +year = {1978} +} + +@article{Marchesini2007, +abstract = {Iterative projection algorithms are successfully being used as a substitute of lenses to recombine, numerically rather than optically, light scattered by illuminated objects. Images obtained computationally allow aberration-free diffraction-limited imaging and the possibility of using radiation for which no lenses exist. The challenge of this imaging technique is transferred from the lenses to the algorithms. We evaluate these new computational “instruments” developed for the phase-retrieval problem, and discuss acceleration strategies.}, +author = {Marchesini, S}, +file = {:Users/rls62/Documents/Mendeley Desktop/Marchesini/Review of Scientific Instruments/2007/Marchesini - 2007 - Invited Article A unified evaluation of iterative projection algorithms for phase retrieval.pdf:pdf}, +journal = {Rev. Sci. Instrum.}, +keywords = {image reconstruction,iterative methods,light diffraction,light scattering}, +pages = {11301}, +title = {{Invited Article: A unified evaluation of iterative projection algorithms for phase retrieval}}, +volume = {78}, +year = {2007} +} + +@article{Marchesini2003a, +abstract = {A solution to the inversion problem of scattering would offer aberration-free diffraction-limited three-dimensional images without the resolution and depth-of-field limitations of lens-based tomographic systems. Powerful algorithms are increasingly being used to act as lenses to form such images. Current image reconstruction methods, however, require the knowledge of the shape of the object and the low spatial frequencies unavoidably lost in experiments. Diffractive imaging has thus previously been used to increase the resolution of images obtained by other means. Here we experimentally demonstrate an inversion method, which reconstructs the image of the object without the need for any such prior knowledge.}, +author = {Marchesini, S and others}, +file = {:Users/rls62/Documents/Mendeley Desktop/Marchesini et al/Physical Review B/2003/PhysRevB.68.140101.pdf:pdf}, +journal = {Phys. Rev. B}, +pages = {140101}, +title = {{X-ray image reconstruction from a diffraction pattern alone}}, +volume = {68}, +year = {2003} +} + +@article{carnis_towards_2019, + title = {Towards a quantitative determination of strain in {Bragg} {Coherent} {X}-ray {Diffraction} {Imaging}: artefacts and sign convention in reconstructions}, + volume = {9}, + copyright = {2019 The Author(s)}, + issn = {2045-2322}, + shorttitle = {Towards a quantitative determination of strain in {Bragg} {Coherent} {X}-ray {Diffraction} {Imaging}}, + abstract = {Bragg coherent X-ray diffraction imaging (BCDI) has emerged as a powerful technique to image the local displacement field and strain in nanocrystals, in three dimensions with nanometric spatial resolution. However, BCDI relies on both dataset collection and phase retrieval algorithms that can induce artefacts in the reconstruction. Phase retrieval algorithms are based on the fast Fourier transform (FFT). We demonstrate how to calculate the displacement field inside a nanocrystal from its reconstructed phase depending on the mathematical convention used for the FFT. We use numerical simulations to quantify the influence of experimentally unavoidable detector deficiencies such as blind areas or limited dynamic range as well as post-processing filtering on the reconstruction. We also propose a criterion for the isosurface determination of the object, based on the histogram of the reconstructed modulus. Finally, we study the capability of the phasing algorithm to quantitatively retrieve the surface strain (i.e., the strain of the surface voxels). This work emphasizes many aspects that have been neglected so far in BCDI, which need to be understood for a quantitative analysis of displacement and strain based on this technique. It concludes with the optimization of experimental parameters to improve throughput and to establish BCDI as a reliable 3D nano-imaging technique.}, + number = {1}, + journal = {Scientific Reports}, + author = {Carnis, Jérôme and Gao, Lu and Labat, Stéphane and Kim, Young Yong and Hofmann, Jan P. and Leake, Steven J. and Schülli, Tobias U. and Hensen, Emiel J. M. and Thomas, Olivier and Richard, Marie-Ingrid}, + month = nov, + year = {2019}, + note = {Publisher: Nature Publishing Group}, + keywords = {Imaging techniques, Nanoparticles}, + pages = {17357}, + file = {Full Text PDF:/Users/jmeziere/Zotero/storage/B6NNU39A/Carnis et al. - 2019 - Towards a quantitative determination of strain in .pdf:application/pdf}, +} + diff --git a/dev/refs/index.html b/dev/refs/index.html new file mode 100644 index 0000000..a8cb46f --- /dev/null +++ b/dev/refs/index.html @@ -0,0 +1,2 @@ + +References · BcdiDocs
diff --git a/dev/search_index.js b/dev/search_index.js index df42ae4..40c761f 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"BcdiCore.jl/docs/src/#Julia-BCDI-Documentation","page":"About/Installation","title":"Julia BCDI Documentation","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/#About","page":"About/Installation","title":"About","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"The BYU-CXI research group maintains a suite of Julia packages to solve the Bragg Coherent Diffraction Imaging (BCDI) problem in several different regimes and circumstance. ","category":"page"},{"location":"BcdiCore.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"BcdiCore.jl implements all of the Fourier transforms for the Julia BCDI packages. In addition, BcdiCore calculates the loss function used (either L_2 or the MLE estimator) and derivatives of these loss functions.\nBcdiTrad.jl implements projection-based BCDI algorithm. Currently, this is limited to ER, HIO, and shrinkwrap. \nBcdiStrain.jl implements a multi-peak BCDI algorithm developed by the BYU-CXI group. In addition to the alogrithms present in BcdiTrad, BcdiStrain also implements Mount, an operator that switches between peaks.\nBcdiMeso.jl implements a BCDI algorithm that solves in the mesoscale regime. Instead of using projections, this algorithm uses a gradient-based optimization scheme. Additionally, BcdiMeso does not assume a small measurement distance away from the peak.\nBcdiAtomic.jl is an upcoming BCDI package that implements a BCDI algorithm that solves at the atomic scale.\nBcdiMulti.jl is an upcoming BCDI package that implements a multiscale BCDI algorithm that solves at both the mesoscale and the atomic scale.\nBcdiSimulate.jl is an upcoming BCDI package that simulates the BCDI problem. Currently, this is only implimented at the atomic scale.","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/#Overview","page":"Usage","title":"Overview","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiMeso implements phase retrieval in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/","page":"Usage","title":"Usage","text":"state = State(intens, gVecs, recSupport, x, y, z, rho, ux, uy, uz)\noptimizeState = OptimizeState(state, primitiveRecipLattice, numPeaks)\n\noptimizeState^100 * state","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/","page":"Usage","title":"Usage","text":"This short script applies 100 stochastic gradient descent iterations iterations. This makes it easy to implement very complex recipes for phase retrieval algorithms.","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/#API","page":"Usage","title":"API","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiMeso.State\nBcdiMeso.OptimizeState","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/#BcdiMeso.State","page":"Usage","title":"BcdiMeso.State","text":"Create an object that performs an iteration of stochastic gradient descent.\n\nCreate the reconstruction state.\n\n\n\n\n\n","category":"type"},{"location":"BcdiMeso.jl/docs/src/use/#BcdiMeso.OptimizeState","page":"Usage","title":"BcdiMeso.OptimizeState","text":"OptimizeState(state, primitiveRecipLattice, numPeaks)\n\nCreate an object that performs an iteration of stochastic gradient descent.\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/README/#BcdiStrain","page":"BcdiStrain","title":"BcdiStrain","text":"","category":"section"},{"location":"BcdiStrain.jl/README/","page":"BcdiStrain","title":"BcdiStrain","text":" (Image: )","category":"page"},{"location":"BcdiTradExamples/examples/#Example-1","page":"Examples","title":"Example 1","text":"","category":"section"},{"location":"BcdiTradExamples/examples/#Environment","page":"Examples","title":"Environment","text":"","category":"section"},{"location":"BcdiTradExamples/examples/","page":"Examples","title":"Examples","text":"[deps]\nBcdiTrad = \"b788224a-5de6-46e5-9aeb-ad1a5171efd9\"\nFFTW = \"7a1cc6ca-52ef-59f5-83cd-3a7055c09341\"\nPlots = \"91a5bcdd-55d7-5caf-9e0b-520d859cae80\"","category":"page"},{"location":"BcdiTradExamples/examples/#Code","page":"Examples","title":"Code","text":"","category":"section"},{"location":"BcdiTradExamples/examples/","page":"Examples","title":"Examples","text":"using BcdiTrad\nusing Plots\nusing FFTW\n\nfunction saveAn(state, a)\n p1 = heatmap(fftshift(Array(abs.(state.realSpace)))[50,:,:])\n p2 = heatmap(fftshift(Array(angle.(state.realSpace)))[50,:,:])\n frame(a, plot(p1,p2,layout=2,size=(600,200)))\nend\n\nfunction phase()\n intensities = round.(Int64, reshape(parse.(Float64, split(readlines(\"../data/intensities.txt\")[1], \",\")), 100, 100, 100))\n\n state = BcdiTrad.State(intensities, trues(size(intensities)))\n er = BcdiTrad.ER()\n hio = BcdiTrad.HIO(0.9)\n shrink = BcdiTrad.Shrink(0.1, 1.0, state)\n center = BcdiTrad.Center(state)\n\n a = Animation()\n # We could run the commands this way, but we want to plot in the middle\n # center * er^500 * (center * er^20 * (shrink * hio)^80)^20 * state\n for i in 1:1600\n hio * state\n saveAn(state, a)\n shrink * state\n end\n for i in 1:100\n er * state\n saveAn(state, a)\n end\n center * state\n saveAn(state, a)\n\n mov(a, \"../results/recon.webm\", fps=250)\nend\n\nphase()","category":"page"},{"location":"BcdiTradExamples/examples/#Output","page":"Examples","title":"Output","text":"","category":"section"},{"location":"BcdiTradExamples/examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"BcdiMeso.jl/README/#BcdiMeso.jl","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"","category":"section"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":" (Image: )","category":"page"},{"location":"BcdiMeso.jl/README/#About","page":"BcdiMeso.jl","title":"About","text":"","category":"section"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"Bragg Coherent Diffraction Imaging (BCDI) Meso (Mesoscale) implements phase retrieval for mesoscale models with stochastic gradient descent. Some of the core functionality of this project is implemented in BcdiCore.jl. Additionally, this package is part of a collection of BCDI packages consisting of BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), and BcdiMulti.jl (a multiscale BCDI solver).","category":"page"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.","category":"page"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiMeso.jl/README/#Installation","page":"BcdiMeso.jl","title":"Installation","text":"","category":"section"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"Currently, BcdiStrain.jl is not registered in the Julia general registry. BcdiTrad.jl can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"add BcdiMeso","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/#Mathematical-Definitions","page":"Atomic Models","title":"Mathematical Definitions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"For the atomic model, G(u) is defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"G(hkl) = sum_j e^-i (x_j (h+G_h) + y_j (k+G_k) + z_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"where x_j y_j z_j are atom positions and hkl represent a distance away from some scattering vector G_h G_k G_l in reciprocal space. It is important that the hkl value are integers and that they range from -fracn2 to fracn2-1, so both real space and reciprocal space positions must be scaled. The x_jy_jz_j positions should be shifted to lie between 0 to 1 and should be multiplied by 2pi to capture the missing 2 pi scaling in the Fourier transform exponent.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/#Usage","page":"Atomic Models","title":"Usage","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"Calculating the loss function and its derivative for the atomic model is done in three steps. First, the BcdiCore.AtomicState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"state = AtomicState(lossType, scale, intens, G, h, k, l)\nsetpts!(state, x, y, z, getDeriv)\nlossVal = loss(state, getDeriv, getLoss)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"If the derivative is requested with the getDeriv variable, the results are stored in state.xDeriv, state.yDeriv, and state.zDeriv.","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/#Overview","page":"Usage","title":"Overview","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/use/","page":"Usage","title":"Usage","text":"Similar to pynx and others?, BcdiTrad implements projection-based algorithms in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/","page":"Usage","title":"Usage","text":"er = BcdiTrad.ER()\nhio = BcdiTrad.HIO(0.9)\nstate = BcdiTrad.State(intensities, trues(size(intensities)))\n\n(er * hio^20)^5 * state","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/","page":"Usage","title":"Usage","text":"This short script applies 20 HIO iterations and one ER iterations for a total of 5 times. This makes it easy to implement very complex recipes for phase retrieval algorithms.","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/#API","page":"Usage","title":"API","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiTrad.State\nBcdiTrad.ER\nBcdiTrad.HIO\nBcdiTrad.Shrink\nBcdiTrad.Center","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.State","page":"Usage","title":"BcdiTrad.State","text":"State(intensities, recSupport)\n\nCreate a reconstruction object. The intensities and a mask over reciprocal space indicating trusted intensities need to be passed in.\n\n\n\n\n\n","category":"type"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.ER","page":"Usage","title":"BcdiTrad.ER","text":"ER()\n\nCreate an object that applies an iteration of ER\n\n\n\n\n\n","category":"type"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.HIO","page":"Usage","title":"BcdiTrad.HIO","text":"HIO(beta)\n\nCreate an object that applies an iteration of HIO\n\n\n\n\n\n","category":"type"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.Shrink","page":"Usage","title":"BcdiTrad.Shrink","text":"Shrink(threshold, sigma, state)\n\nCreate an object that applies shrinkwrap\n\n\n\n\n\n","category":"type"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.Center","page":"Usage","title":"BcdiTrad.Center","text":"Center(state)\n\nCreate an object that centers the current state\n\n\n\n\n\n","category":"type"},{"location":"BcdiMesoExamples/examples/#Example-1","page":"Examples","title":"Example 1","text":"","category":"section"},{"location":"BcdiMesoExamples/examples/#Environment","page":"Examples","title":"Environment","text":"","category":"section"},{"location":"BcdiMesoExamples/examples/","page":"Examples","title":"Examples","text":"[deps]\nBcdiCore = \"72eb6a3e-ca63-4742-b260-85b05ca6d9e4\"\nBcdiStrain = \"3abd092d-e7bc-4ec6-94c6-c6851986118d\"\nBcdiMeso = \"1ffc817a-885e-4a73-a887-574cb954c7d7\"\nFFTW = \"7a1cc6ca-52ef-59f5-83cd-3a7055c09341\"\nLinearAlgebra = \"37e2e46d-f89d-539d-b4ee-838fcccc9c8e\"\nPlots = \"91a5bcdd-55d7-5caf-9e0b-520d859cae80\"","category":"page"},{"location":"BcdiMesoExamples/examples/#Code","page":"Examples","title":"Code","text":"","category":"section"},{"location":"BcdiMesoExamples/examples/","page":"Examples","title":"Examples","text":"using BcdiCore\nusing BcdiStrain\nusing BcdiMeso\nusing Plots\nusing FFTW\nusing LinearAlgebra\n\nfunction saveAn(rho, ux, uy, uz, inSupp, plotArr, a)\n plotArr[inSupp] .= Array(rho)\n p1 = heatmap(plotArr[50,:,:])\n plotArr[inSupp] .= Array(ux)\n p2 = heatmap(plotArr[50,:,:])\n plotArr[inSupp] .= Array(uy)\n p3 = heatmap(plotArr[50,:,:])\n plotArr[inSupp] .= Array(uz)\n p4 = heatmap(plotArr[50,:,:])\n frame(a, plot(p1,p2,p3,p4,layout=4))\nend\n\nfunction phase()\n intens = Array{Float64, 3}[]\n gVecs = [[-1.,1,1],[1.,-1,1],[1.,1,-1]]\n primLatt = [-1. 1 1 ; 1 -1 1; 1 1 -1]\n for i in 1:3\n push!(intens, round.(Int64, reshape(parse.(Float64, split(readlines(\"../data/intensities$(i).txt\")[1], \",\")), 100, 100, 100)))\n end\n recSupport = [trues(size(intens[1])) for i in 1:length(intens)]\n\n strainState = BcdiStrain.State(intens, gVecs, recSupport)\n er = BcdiStrain.ER()\n hio = BcdiStrain.HIO(0.9)\n shrink = BcdiStrain.Shrink(0.1, 1.0, strainState)\n center = BcdiStrain.Center(strainState)\n mount = BcdiStrain.Mount(0.5, strainState, primLatt)\n\n a = Animation()\n # We could run the commands this way, but we want to plot in the middle\n (mount * center * er^20)^200 *\n (mount * center * (shrink * hio)^80)^80 * strainState\n\n A = zeros(3,3)\n for i in 1:3\n _, _, peakLoc = BcdiCore.centerPeak(intens[i], recSupport[i], \"corner\")\n peakLoc = collect(peakLoc) .+ [1,1,1]\n peakLoc = Int64.(peakLoc)\n h = reshape(parse.(Float64, split(readlines(\"../data/h$(i).txt\")[1], \",\")), 100, 100, 100)\n k = reshape(parse.(Float64, split(readlines(\"../data/k$(i).txt\")[1], \",\")), 100, 100, 100)\n l = reshape(parse.(Float64, split(readlines(\"../data/l$(i).txt\")[1], \",\")), 100, 100, 100)\n peak = [h[peakLoc...],k[peakLoc...],l[peakLoc...]]\n peak ./= [h[1,1,2]-h[1,1,1],k[1,2,1]-k[1,1,1],l[2,1,1]-l[1,1,1]]\n gVecs[i] .= peak\n A[i,:] .= peak\n end\n\n inSupp = Array(findall(fftshift(strainState.traditionals[1].support)))\n B = zeros(3, reduce(+, strainState.traditionals[1].support))\n B[1,:] .= Array(-fftshift(strainState.ux)[inSupp] .+ fftshift(strainState.uy)[inSupp] .+ fftshift(strainState.uz)[inSupp])\n B[2,:] .= Array(fftshift(strainState.ux)[inSupp] .- fftshift(strainState.uy)[inSupp] .+ fftshift(strainState.uz)[inSupp])\n B[3,:] .= Array(fftshift(strainState.ux)[inSupp] .+ fftshift(strainState.uy)[inSupp] .- fftshift(strainState.uz)[inSupp])\n\n s = size(intens[1])\n x = zeros(length(inSupp))\n y = zeros(length(inSupp))\n z = zeros(length(inSupp))\n for i in 1:length(inSupp)\n x[i] = 2*pi*(inSupp[i][1]-1)/s[1]\n y[i] = 2*pi*(inSupp[i][2]-1)/s[2]\n z[i] = 2*pi*(inSupp[i][3]-1)/s[3]\n end\n\n newStrain = A \\ B\n\n support = strainState.traditionals[1].support\n plotArr = zeros(size(support))\n rho = Array(fftshift(strainState.rho)[inSupp])\n ux = -newStrain[1,:]\n uy = -newStrain[2,:]\n uz = -newStrain[3,:]\n\n mesoState = BcdiMeso.State(\n intens, gVecs, recSupport, x, y, z,\n Array(fftshift(strainState.rho)[inSupp]),\n newStrain[1,:], newStrain[2,:], newStrain[3,:]\n )\n optimizeState1 = BcdiMeso.OptimizeState(mesoState, primLatt, 1)\n optimizeState2 = BcdiMeso.OptimizeState(mesoState, primLatt, 2)\n optimizeState3 = BcdiMeso.OptimizeState(mesoState, primLatt, 3)\n\n for i in 1:100\n saveAn(mesoState.rho, mesoState.ux, mesoState.uy, mesoState.uz, inSupp, plotArr, a)\n optimizeState1 * mesoState\n end\n for j in 1:100\n saveAn(mesoState.rho, mesoState.ux, mesoState.uy, mesoState.uz, inSupp, plotArr, a)\n optimizeState2 * mesoState\n end\n for k in 1:100\n saveAn(mesoState.rho, mesoState.ux, mesoState.uy, mesoState.uz, inSupp, plotArr, a)\n optimizeState3 * mesoState\n end\n\n mov(a, \"../results/recon.webm\", fps=250)\nend\n\nphase()","category":"page"},{"location":"BcdiMesoExamples/examples/#Output","page":"Examples","title":"Output","text":"","category":"section"},{"location":"BcdiMesoExamples/examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"BcdiAtomicExamples/examples/#Environment","page":"Environment","title":"Environment","text":"","category":"section"},{"location":"BcdiAtomicExamples/examples/","page":"Environment","title":"Environment","text":"","category":"page"},{"location":"BcdiAtomicExamples/examples/","page":"Environment","title":"Environment","text":"[deps]\nBcdiAtomic = \"a97cdeff-3185-4906-97ce-92639738da6c\"\nBcdiSimulate = \"b133d2d9-b23b-44ee-be6b-5f897f6a3084\"","category":"page"},{"location":"BcdiCore.jl/README/#BcdiCore","page":"BcdiCore","title":"BcdiCore","text":"","category":"section"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":" (Image: ) ","category":"page"},{"location":"BcdiCore.jl/README/#About","page":"BcdiCore","title":"About","text":"","category":"section"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"Bragg Coherent Diffraction Imaging (BCDI) Core implements some of the core functionality used for future projects BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), BcdiMulti.jl (a multiscale BCDI solver), BcdiTrad.jl (a BCDI solver using projection algorithms), and BcdiStrain (a BCDI solver for mesoscale using projection algorithms). BcdiCore.jl implements the loss functions and derivatives of loss functions used in these packages.","category":"page"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.","category":"page"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiCore.jl/README/#Installation","page":"BcdiCore","title":"Installation","text":"","category":"section"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"Currently, BcdiCore.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"add BcdiCore","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/#Mathematical-Definitions","page":"Multiscale Models","title":"Mathematical Definitions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"The multiscale model is a combination of an atomic scale and a mesoscale model. In this case, G(hkl) is defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"G(hkl) = G_a(hkl) + G_m(hkl)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"where a signifies the atomic model and m signifies the mesoscale model.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/#Usage","page":"Multiscale Models","title":"Usage","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"Calculating the loss function and its derivative for the mesoscale model is done in three steps. First, the BcdiCore.MultiState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"state = MultiState(lossType, scale, intens, G, h, k, l)\nsetpts!(state, x, y, z, mx, my, mz, rho, ux, uy, uz, getDeriv)\nlossVal = loss(state, getDeriv, getLoss)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"Here x, y, z are atomic positions and mx, my, mz are the real space locations of the mesoscale model.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"If the derivative is requested with the getDeriv variable, the results are stored in state.xDeriv, state.yDeriv, and state.zDeriv, state.rhoDeriv, state.uxDeriv, state.uyDeriv, and state.uzDeriv.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/#Mathematical-Definitions","page":"Traditional Models","title":"Mathematical Definitions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"Similar to the mesoscale model, G(u) is initially defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"G(hkl) = sum_j rho_j e^-i (x_j h + y_j k + uz_j l) e^-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"where x_j y_j z_j are real space positions, ux_j uy_j uz_j are diplacement vectors, and hkl represent a distance away from some scattering vector G_h G_k G_l in reciprocal space. However, we assume that, because the distance from the scattering vector and the displacement vectors are small, u cdot h is negligible. So we are left with","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"G(hkl) = sum_j rho_j e^-i (x_j h + y_j k + uz_j l) e^-i (ux_j G_h + uy_j G_k + uz_j G_l) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"Then, we combine the entire rho_j e^-i (ux_j G_h + uy_j G_k + uz_j G_l) quantity as one variable and get","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"G(hkl) = sum_j psi_j e^-i (x_j h + y_j k + uz_j l) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"In this case, this is an ordinary Fourier transform, so we put the factor of 2pi back into G(hkl) to get","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"G(hkl) = sum_j psi_j e^-2 pi i (x_j h + y_j k + uz_j l) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/#Usage","page":"Traditional Models","title":"Usage","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"Calculating the loss function and its derivative for the traditional model is done in two steps. First, the BcdiCore.TradState struct is created. Then, the loss function is calculated with BcdiCore.loss.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"state = TradState(losstype, scale, intens, realSpace)\nlossVal = loss(state, getDeriv, getLoss)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"If the derivative is requested with the getDeriv variable, the result us stored in state.deriv.","category":"page"},{"location":"BcdiTrad.jl/docs/src/#BcdiTrad.jl-Documentation","page":"About/Installation","title":"BcdiTrad.jl Documentation","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/#About","page":"About/Installation","title":"About","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Bragg Coherent Diffraction Imaging (BCDI) Trad (Traditional) implements projection-based phase retrieval algorithms.","category":"page"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.","category":"page"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiTrad.jl/docs/src/#Installation","page":"About/Installation","title":"Installation","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"BcdiTrad.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"add BcdiTrad","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/#Overview","page":"Usage","title":"Overview","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiStrain implements projection-based algorithms in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/","page":"Usage","title":"Usage","text":"er = BcdiTrad.ER()\nhio = BcdiTrad.HIO(0.9)\nstate = BcdiTrad.State(intensities, trues(size(intensities)))\n\n(er * hio^20)^5 * state","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/","page":"Usage","title":"Usage","text":"This short script applies 20 HIO iterations and one ER iterations for a total of 5 times. This makes it easy to implement very complex recipes for phase retrieval algorithms.","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/#API","page":"Usage","title":"API","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiStrain.State\nBcdiStrain.ER\nBcdiStrain.HIO\nBcdiStrain.Shrink\nBcdiStrain.Center\nBcdiStrain.Mount","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.State","page":"Usage","title":"BcdiStrain.State","text":"State(intensities, recSupport)\n\nCreate a reconstruction object. The intensities and a mask over reciprocal space indicating trusted intensities need to be passed in.\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.ER","page":"Usage","title":"BcdiStrain.ER","text":"ER()\n\nCreate an object that applies an iteration of ER\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.HIO","page":"Usage","title":"BcdiStrain.HIO","text":"HIO(beta)\n\nCreate an object that applies an iteration of HIO\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.Shrink","page":"Usage","title":"BcdiStrain.Shrink","text":"Shrink(threshold, sigma, state)\n\nCreate an object that applies shrinkwrap\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.Center","page":"Usage","title":"BcdiStrain.Center","text":"Center(state)\n\nCreate an object that centers the current state\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.Mount","page":"Usage","title":"BcdiStrain.Mount","text":"Mount(beta, state, primitiveRecipLattice)\n\nCreate an object that switches between peaks.\n\n\n\n\n\n","category":"type"},{"location":"BcdiMeso.jl/docs/src/#BcdiMeso.jl-Documentation","page":"About/Installation","title":"BcdiMeso.jl Documentation","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/#About","page":"About/Installation","title":"About","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Bragg Coherent Diffraction Imaging (BCDI) Meso (Mesoscale) implements phase retrieval for mesoscale models with stochastic gradient descent.","category":"page"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.","category":"page"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiMeso.jl/docs/src/#Installation","page":"About/Installation","title":"Installation","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"BcdiStrain.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"add BcdiMeso","category":"page"},{"location":"BcdiStrain.jl/docs/src/#BcdiStrain.jl-Documentation","page":"About/Installation","title":"BcdiStrain.jl Documentation","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/#About","page":"About/Installation","title":"About","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Bragg Coherent Diffraction Imaging (BCDI) Strain implements projection-based phase retrieval algorithms.","category":"page"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.","category":"page"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiStrain.jl/docs/src/#Installation","page":"About/Installation","title":"Installation","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Currently, BcdiStrain.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"add BcdiStrain","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/#Mathematical-Definitions","page":"Mesoscale Models","title":"Mathematical Definitions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"Similar to the atomic model, G(u) is initially defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"G(hkl) = sum_j e^-i (x_j (h+G_h) + y_j (k+G_k) + z_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"where x_j y_j z_j are atom positions and hkl represent a distance away from some scattering vector G_h G_k G_l in reciprocal space. However, x_j y_j z_j can be thought of as an addition of lattice spacings and displacement vectors, i.e. x_j+ux_j y_j+uy_j z_j+uz_j. Then, if G_hG_kG_l are reciprocal lattice vectors, we find that x cdot G is an integer multiple of 2pi, so it does not affect the simulated electric field. We are then left with","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"G(hkl) = sum_j e^-i (x_j G_h + y_j G_k + uz_j G_l) e^-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"Coarse graining to get a mesoscale model, we get","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"G(hkl) = sum_j rho_j e^-i (x_j h + y_j k + uz_j l) e^-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"Again, it is important that the hkl value are integers and that they range from -fracn2 to fracn2-1, so both real space and reciprocal space positions must be scaled. The x_jy_jz_j positions should be shifted to lie between 0 to 1 and should be multiplied by 2pi to capture the missing 2 pi scaling in the Fourier transform exponent.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/#Usage","page":"Mesoscale Models","title":"Usage","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"Calculating the loss function and its derivative for the mesoscale model is done in three steps. First, the BcdiCore.MesoState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"state = MesoState(lossType, scale, intens, G, h, k, l)\nsetpts!(state, x, y, z, rho, ux, uy, uz, getDeriv)\nlossVal = loss(state, getDeriv, getLoss)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"If the derivative is requested with the getDeriv variable, the results are stored in state.rhoDeriv, state.uxDeriv, state.uyDeriv, and state.uzDeriv.","category":"page"},{"location":"README/#BcdiExamples","page":"BcdiExamples","title":"BcdiExamples","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/#Example-1","page":"Examples","title":"Example 1","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/#Environment","page":"Examples","title":"Environment","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/","page":"Examples","title":"Examples","text":"[deps]\nBcdiStrain = \"3abd092d-e7bc-4ec6-94c6-c6851986118d\"\nFFTW = \"7a1cc6ca-52ef-59f5-83cd-3a7055c09341\"\nPlots = \"91a5bcdd-55d7-5caf-9e0b-520d859cae80\"","category":"page"},{"location":"BcdiStrainExamples/examples/#Code","page":"Examples","title":"Code","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/","page":"Examples","title":"Examples","text":"using BcdiStrain\nusing Plots\nusing FFTW\n\nfunction saveAn(state, a)\n p1 = heatmap(fftshift(Array(state.rho)[1,:,:]))\n p2 = heatmap(fftshift(Array(state.ux)[1,:,:]))\n p3 = heatmap(fftshift(Array(state.uy)[1,:,:]))\n p4 = heatmap(fftshift(Array(state.uy)[1,:,:]))\n p5 = heatmap(fftshift(Array(abs.(state.traditionals[1].realSpace))[1,:,:]))\n p6 = heatmap(fftshift(Array(angle.(state.traditionals[1].realSpace))[1,:,:]))\n frame(a, plot(p1,p2,p5,p3,p4,p6,layout=6,size=(900,400)))\nend\n\nfunction phase()\n intens = Array{Float64, 3}[]\n gVecs = [[-1.,1,1],[1.,-1,1],[1.,1,-1]]\n primLatt = [-1. 1 1 ; 1 -1 1; 1 1 -1]\n for i in 1:3\n push!(intens, round.(Int64, reshape(parse.(Float64, split(readlines(\"../data/intensities$(i).txt\")[1], \",\")), 100, 100, 100)))\n end\n recSupport = [trues(size(intens[1])) for i in 1:length(intens)]\n\n state = BcdiStrain.State(intens, gVecs, recSupport)\n er = BcdiStrain.ER()\n hio = BcdiStrain.HIO(0.9)\n shrink = BcdiStrain.Shrink(0.1, 1.0, state)\n center = BcdiStrain.Center(state)\n mount = BcdiStrain.Mount(0.5, state, primLatt)\n\n a = Animation()\n # We could run the commands this way, but we want to plot in the middle\n # (mount * center * er^20)^200 *\n # (mount * center * (shrink * hio)^80)^20 * state\n\n for i in 1:20\n for j in 1:80\n hio * state\n saveAn(state, a)\n shrink * state\n end\n center * state\n saveAn(state, a)\n mount * state\n saveAn(state, a)\n end\n for i in 1:200\n for j in 1:20\n er * state\n saveAn(state, a)\n end\n center * state\n saveAn(state, a)\n mount * state\n saveAn(state, a)\n end\n saveAn(state, a)\n mov(a, \"../results/recon.webm\", fps=250)\nend\n\nphase()","category":"page"},{"location":"BcdiStrainExamples/examples/#Output","page":"Examples","title":"Output","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"BcdiTrad.jl/README/#BcdiTrad","page":"BcdiTrad","title":"BcdiTrad","text":"","category":"section"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":" (Image: )","category":"page"},{"location":"BcdiTrad.jl/README/#About","page":"BcdiTrad","title":"About","text":"","category":"section"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"Bragg Coherent Diffraction Imaging (BCDI) Trad (Traditional) implements projection-based phase retrieval algorithms. Some of the core functionality of this project is implemented in BcdiCore.jl. Additionally, this package is part of a collection of BCDI packages consisting of BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), and BcdiMulti.jl (a multiscale BCDI solver).","category":"page"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.","category":"page"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiTrad.jl/README/#Installation","page":"BcdiTrad","title":"Installation","text":"","category":"section"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"Currently, BcdiTrad.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"add BcdiTrad","category":"page"},{"location":"BcdiCore.jl/docs/src/main/#BcdiCore-Documentation","page":"BcdiCore Documentation","title":"BcdiCore Documentation","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/main/#About","page":"BcdiCore Documentation","title":"About","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/main/","page":"BcdiCore Documentation","title":"BcdiCore Documentation","text":"Bragg Coherent Diffraction Imaging (BCDI) Core implements some of the core functionality used for future projects BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), BcdiMulti.jl (a multiscale BCDI solver), BcdiTrad.jl (a BCDI solver using projection algorithms), and BcdiStrain (a BCDI solver for mesoscale using projection algorithms). BcdiCore.jl implements the loss functions and derivatives of loss functions used in these packages.","category":"page"},{"location":"BcdiCore.jl/docs/src/main/","page":"BcdiCore Documentation","title":"BcdiCore Documentation","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.","category":"page"},{"location":"BcdiCore.jl/docs/src/main/","page":"BcdiCore Documentation","title":"BcdiCore Documentation","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiCore.jl/docs/src/main/#Installation","page":"BcdiCore Documentation","title":"Installation","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/main/","page":"BcdiCore Documentation","title":"BcdiCore Documentation","text":"Currently, BcdiCore.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiCore.jl/docs/src/main/","page":"BcdiCore Documentation","title":"BcdiCore Documentation","text":"add BcdiCore","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"In general, BcdiCore.jl will be called by developers of phase retrieval codes, not end users. BcdiCore.jl implements loss functions and derivatives of loss functions for atomic models, mesoscale models, multiscale models, and traditional projection-based methods.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/#Available-loss-functions","page":"Overview","title":"Available loss functions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"Currently, BcdiCore.jl implements two types of losses, the average L_2 norm and the average log-likelihood. ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"Explicitly, the average L_2 loss is defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"L_2 = frac1N sum_u left( lvert G(u) rvert - lvert F(u) rvert right)^2","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"where G(u) is the simulated electric field, lvert F(u) rvert^2 is the measured intensity at a point u in reciprocal space, and N is the total number of meaurement points.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"The average log-likelihood (for the Poisson distribution) is defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"ell = frac1N sum_u lvert G(u) rvert^2 - lvert F(u) rvert^2 lnleft(lvert G(u) rvert^2 right)","category":"page"},{"location":"#Julia-BCDI-Documentation","page":"Julia BCDI","title":"Julia BCDI Documentation","text":"","category":"section"},{"location":"#About","page":"Julia BCDI","title":"About","text":"","category":"section"},{"location":"","page":"Julia BCDI","title":"Julia BCDI","text":"The BYU-CXI research group maintains a suite of Julia packages to solve the Bragg Coherent Diffraction Imaging (BCDI) problem in several different regimes and circumstance. ","category":"page"},{"location":"","page":"Julia BCDI","title":"Julia BCDI","text":"BcdiCore.jl implements all of the Fourier transforms for the Julia BCDI packages. In addition, BcdiCore calculates the loss function used (either L_2 or the MLE estimator) and derivatives of these loss functions.\nBcdiTrad.jl implements projection-based BCDI algorithm. Currently, this is limited to ER, HIO, and shrinkwrap. \nBcdiStrain.jl implements a multi-peak BCDI algorithm developed by the BYU-CXI group. In addition to the alogrithms present in BcdiTrad, BcdiStrain also implements Mount, an operator that switches between peaks.\nBcdiMeso.jl implements a BCDI algorithm that solves in the mesoscale regime. Instead of using projections, this algorithm uses a gradient-based optimization scheme. Additionally, BcdiMeso does not assume a small measurement distance away from the peak.\nBcdiAtomic.jl is an upcoming BCDI package that implements a BCDI algorithm that solves at the atomic scale.\nBcdiMulti.jl is an upcoming BCDI package that implements a multiscale BCDI algorithm that solves at both the mesoscale and the atomic scale.\nBcdiSimulate.jl is an upcoming BCDI package that simulates the BCDI problem. Currently, this is only implimented at the atomic scale.","category":"page"}] +[{"location":"BcdiStrain.jl/README/#BcdiStrain","page":"BcdiStrain","title":"BcdiStrain","text":"","category":"section"},{"location":"BcdiStrain.jl/README/","page":"BcdiStrain","title":"BcdiStrain","text":" (Image: )","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/#Overview","page":"Usage","title":"Overview","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiMeso implements phase retrieval in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/","page":"Usage","title":"Usage","text":"state = State(intens, gVecs, recSupport, x, y, z, rho, ux, uy, uz)\noptimizeState = OptimizeState(state, primitiveRecipLattice, numPeaks)\n\noptimizeState^100 * state","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/","page":"Usage","title":"Usage","text":"This short script applies 100 stochastic gradient descent iterations iterations. This makes it easy to implement very complex recipes for phase retrieval algorithms.","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/#API","page":"Usage","title":"API","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiMeso.State\nBcdiMeso.OptimizeState","category":"page"},{"location":"BcdiMeso.jl/docs/src/use/#BcdiMeso.State","page":"Usage","title":"BcdiMeso.State","text":"State(intensities, gVecs, recSupport, x, y, z, rho, ux, uy, uz)\n\nCreate the reconstruction state. intensities is a vector of fully measured diffraction peaks, gVecs is a vector of peak locations, and recSupport is a vector of masks over the intensities that removes those intenities from the reconstruction process. The positions of real space points (x, y, and z) must be passed in as well as the magnitude of the electron density rho and the displacement field (ux, uy, and uz).\n\nThe initialization process shifts each peak to be centered (i.e. the center of mass of the peak is moved to the center of the image). \n\n\n\n\n\n","category":"type"},{"location":"BcdiMeso.jl/docs/src/use/#BcdiMeso.OptimizeState","page":"Usage","title":"BcdiMeso.OptimizeState","text":"OptimizeState(state, primitiveRecipLattice, numPeaks)\n\nCreate an object that performs an iteration of stochastic gradient descent. numPeaks number of peaks are selected randomly. One step of gradient descent is taken using the More-Thuente linesearch.\n\nThis implimentation takes into account effects of small angle measurement usually ignored in the BCDI problem. This is described in [4] although this implimentation will be faster because a NUFFT is used instead of many FFTs.\n\n\n\n\n\n","category":"type"},{"location":"BcdiTradExamples/examples/#Example-1","page":"Examples","title":"Example 1","text":"","category":"section"},{"location":"BcdiTradExamples/examples/#Environment","page":"Examples","title":"Environment","text":"","category":"section"},{"location":"BcdiTradExamples/examples/","page":"Examples","title":"Examples","text":"[deps]\nBcdiTrad = \"b788224a-5de6-46e5-9aeb-ad1a5171efd9\"\nFFTW = \"7a1cc6ca-52ef-59f5-83cd-3a7055c09341\"\nPlots = \"91a5bcdd-55d7-5caf-9e0b-520d859cae80\"","category":"page"},{"location":"BcdiTradExamples/examples/#Code","page":"Examples","title":"Code","text":"","category":"section"},{"location":"BcdiTradExamples/examples/","page":"Examples","title":"Examples","text":"using BcdiTrad\nusing Plots\nusing FFTW\n\nfunction saveAn(state, a)\n p1 = heatmap(fftshift(Array(abs.(state.realSpace)))[50,:,:])\n p2 = heatmap(fftshift(Array(angle.(state.realSpace)))[50,:,:])\n frame(a, plot(p1,p2,layout=2,size=(600,200)))\nend\n\nfunction phase()\n intensities = round.(Int64, reshape(parse.(Float64, split(readlines(\"../data/intensities.txt\")[1], \",\")), 100, 100, 100))\n\n state = BcdiTrad.State(intensities, trues(size(intensities)))\n er = BcdiTrad.ER()\n hio = BcdiTrad.HIO(0.9)\n shrink = BcdiTrad.Shrink(0.1, 1.0, state)\n center = BcdiTrad.Center(state)\n\n a = Animation()\n # We could run the commands this way, but we want to plot in the middle\n # center * er^500 * (center * er^20 * (shrink * hio)^80)^20 * state\n for i in 1:1600\n hio * state\n saveAn(state, a)\n shrink * state\n end\n for i in 1:100\n er * state\n saveAn(state, a)\n end\n center * state\n saveAn(state, a)\n\n mov(a, \"../results/recon.webm\", fps=250)\nend\n\nphase()","category":"page"},{"location":"BcdiTradExamples/examples/#Output","page":"Examples","title":"Output","text":"","category":"section"},{"location":"BcdiTradExamples/examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"BcdiMeso.jl/README/#BcdiMeso.jl","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"","category":"section"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":" (Image: )","category":"page"},{"location":"BcdiMeso.jl/README/#About","page":"BcdiMeso.jl","title":"About","text":"","category":"section"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"Bragg Coherent Diffraction Imaging (BCDI) Meso (Mesoscale) implements phase retrieval for mesoscale models with stochastic gradient descent. Some of the core functionality of this project is implemented in BcdiCore.jl. Additionally, this package is part of a collection of BCDI packages consisting of BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), and BcdiMulti.jl (a multiscale BCDI solver).","category":"page"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.","category":"page"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiMeso.jl/README/#Installation","page":"BcdiMeso.jl","title":"Installation","text":"","category":"section"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"Currently, BcdiStrain.jl is not registered in the Julia general registry. BcdiTrad.jl can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiMeso.jl/README/","page":"BcdiMeso.jl","title":"BcdiMeso.jl","text":"add BcdiMeso","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/#Mathematical-Definitions","page":"Atomic Models","title":"Mathematical Definitions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"For the atomic model, G(u) is defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"G(hkl) = sum_j e^-i (x_j (h+G_h) + y_j (k+G_k) + z_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"where x_j y_j z_j are atom positions and hkl represent a distance away from some scattering vector G_h G_k G_l in reciprocal space. It is important that the hkl value are integers and that they range from -fracn2 to fracn2-1, so both real space and reciprocal space positions must be scaled. The x_jy_jz_j positions should be shifted to lie between 0 to 1 and should be multiplied by 2pi to capture the missing 2 pi scaling in the Fourier transform exponent.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/#Usage","page":"Atomic Models","title":"Usage","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"Calculating the loss function and its derivative for the atomic model is done in three steps. First, the BcdiCore.AtomicState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"state = AtomicState(lossType, scale, intens, G, h, k, l)\nsetpts!(state, x, y, z, getDeriv)\nlossVal = loss(state, getDeriv, getLoss)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/atomic/","page":"Atomic Models","title":"Atomic Models","text":"If the derivative is requested with the getDeriv variable, the results are stored in state.xDeriv, state.yDeriv, and state.zDeriv.","category":"page"},{"location":"BcdiTrad.jl/docs/src/refs/#References","page":"References","title":"References","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/refs/","page":"References","title":"References","text":"J. R. Fienup. Reconstruction of an object from the modulus of its Fourier transform. Opt. Lett. 3, 27–29 (1978).\n\n\n\nS. Marchesini. Invited Article: A unified evaluation of iterative projection algorithms for phase retrieval. Rev. Sci. Instrum. 78, 11301 (2007).\n\n\n\nS. Marchesini and others. X-ray image reconstruction from a diffraction pattern alone. Phys. Rev. B 68, 140101 (2003).\n\n\n\nJ. Carnis, L. Gao, S. Labat, Y. Y. Kim, J. P. Hofmann, S. J. Leake, T. U. Schülli, E. J. Hensen, O. Thomas and M.-I. Richard. Towards a quantitative determination of strain in Bragg Coherent X-ray Diffraction Imaging: artefacts and sign convention in reconstructions. Scientific Reports 9, 17357 (2019). Publisher: Nature Publishing Group.\n\n\n\n","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/#Overview","page":"Usage","title":"Overview","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/use/","page":"Usage","title":"Usage","text":"Similar to pynx and others?, BcdiTrad implements projection-based algorithms in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/","page":"Usage","title":"Usage","text":"er = BcdiTrad.ER()\nhio = BcdiTrad.HIO(0.9)\nstate = BcdiTrad.State(intensities, trues(size(intensities)))\n\n(er * hio^20)^5 * state","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/","page":"Usage","title":"Usage","text":"This short script applies 20 HIO iterations and one ER iterations for a total of 5 times. This makes it easy to implement very complex recipes for phase retrieval algorithms.","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/#API","page":"Usage","title":"API","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiTrad.State\nBcdiTrad.ER\nBcdiTrad.HIO\nBcdiTrad.Shrink\nBcdiTrad.Center","category":"page"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.State","page":"Usage","title":"BcdiTrad.State","text":"State(intensities, recSupport)\nState(intensities, recSupport, support)\n\nCreate a reconstruction object. intensities is one fully measured diffraction peak and recSupport is a mask over the intensities that remove those intensities from the reconstruction process.\n\nThe initialization process shifts the peak to be centered in the Fourier sense (i.e. the center of mass of the peak is moved to the edge of the image, or the zero frequency). If the support is not passed in, an initial guess of the support is created by taking an IFFT of the intensities and including everything above 0.1 times the maximum value.\n\n\n\n\n\n","category":"type"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.ER","page":"Usage","title":"BcdiTrad.ER","text":"ER()\n\nCreate an object that applies one iteration of Error Reduction (ER). ER is an iterative projection algorithm that enforces two constraints, (1) the modulus constraint and (2) the support constraint:\n\nWhen moved to reciprocal space, the reconstructed object must match the diffraction pattern.\nThe reconstructed object must fully lie within the support.\n\nOne iteration of ER first applies the modulus constraint, then the support constraint to the object, then returnns.\n\nGradient descent is an alternate way to view the ER algorithm becausee ER is equivalent to gradient descent with a step size of 0.5.\n\nMore information about the ER algorithm can be found in [1, 2].\n\n\n\n\n\n","category":"type"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.HIO","page":"Usage","title":"BcdiTrad.HIO","text":"HIO(beta)\n\nCreate an object that applies an iteration of hybrid input-output (HIO). On the interior of the support, HIO is equivalent to applying the modulus constraint as described in the ER algorithm, and on the exterior of the support, HIO is equal to the current reconstruction minus a fraction of the output after applying the modulus constraint, that is,\n\nrho_i+1 = begincases\nER(rho_i) rho in support \nrho_i - beta * ER(rho_i) rho notin support\nendcases\n\nMarchesini [2] has shown that the HIO algorithm is equivalent to a mini-max problem.\n\nMore information about the HIO algorithm can be found in [1, 2].\n\n\n\n\n\n","category":"type"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.Shrink","page":"Usage","title":"BcdiTrad.Shrink","text":"Shrink(threshold, sigma, state::State)\n\nCreate an object that applies one iteration of the shrinkwrap algorithm. Shrinkwrap first applies a Gaussian blur to the current reconstruction using sigma as the width of the Gaussian. The support is then created from everything above the threshold times maximum value of the blurred object.\n\nFurther information about the shrinkwrap algorithm can be found in [3].\n\n\n\n\n\n","category":"type"},{"location":"BcdiTrad.jl/docs/src/use/#BcdiTrad.Center","page":"Usage","title":"BcdiTrad.Center","text":"Center(state)\n\nCreate an object that centers the current state. The center of mass of the support is calculated and the object is moved so the center of mass is centered in the Fourier transform sense. In other words, the center of mass is moved to the zeroth frequency, or the bottom left corner of the image. \n\n\n\n\n\n","category":"type"},{"location":"BcdiMeso.jl/docs/src/refs/#References","page":"References","title":"References","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/refs/","page":"References","title":"References","text":"","category":"page"},{"location":"BcdiSimulate.jl/README/#BcdiSimulate","page":"BcdiSimulate","title":"BcdiSimulate","text":"","category":"section"},{"location":"BcdiSimulate.jl/README/","page":"BcdiSimulate","title":"BcdiSimulate","text":"","category":"page"},{"location":"BcdiStrain.jl/docs/src/refs/#References","page":"References","title":"References","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/refs/","page":"References","title":"References","text":"","category":"page"},{"location":"BcdiMesoExamples/examples/#Example-1","page":"Examples","title":"Example 1","text":"","category":"section"},{"location":"BcdiMesoExamples/examples/#Environment","page":"Examples","title":"Environment","text":"","category":"section"},{"location":"BcdiMesoExamples/examples/","page":"Examples","title":"Examples","text":"[deps]\nBcdiCore = \"72eb6a3e-ca63-4742-b260-85b05ca6d9e4\"\nBcdiStrain = \"3abd092d-e7bc-4ec6-94c6-c6851986118d\"\nBcdiMeso = \"1ffc817a-885e-4a73-a887-574cb954c7d7\"\nFFTW = \"7a1cc6ca-52ef-59f5-83cd-3a7055c09341\"\nLinearAlgebra = \"37e2e46d-f89d-539d-b4ee-838fcccc9c8e\"\nPlots = \"91a5bcdd-55d7-5caf-9e0b-520d859cae80\"","category":"page"},{"location":"BcdiMesoExamples/examples/#Code","page":"Examples","title":"Code","text":"","category":"section"},{"location":"BcdiMesoExamples/examples/","page":"Examples","title":"Examples","text":"using BcdiCore\nusing BcdiStrain\nusing BcdiMeso\nusing Plots\nusing FFTW\nusing LinearAlgebra\n\nfunction saveAn(rho, ux, uy, uz, inSupp, plotArr, a)\n plotArr[inSupp] .= Array(rho)\n p1 = heatmap(plotArr[50,:,:])\n plotArr[inSupp] .= Array(ux)\n p2 = heatmap(plotArr[50,:,:])\n plotArr[inSupp] .= Array(uy)\n p3 = heatmap(plotArr[50,:,:])\n plotArr[inSupp] .= Array(uz)\n p4 = heatmap(plotArr[50,:,:])\n frame(a, plot(p1,p2,p3,p4,layout=4))\nend\n\nfunction phase()\n intens = Array{Float64, 3}[]\n gVecs = [[-1.,1,1],[1.,-1,1],[1.,1,-1]]\n primLatt = [-1. 1 1 ; 1 -1 1; 1 1 -1]\n for i in 1:3\n push!(intens, round.(Int64, reshape(parse.(Float64, split(readlines(\"../data/intensities$(i).txt\")[1], \",\")), 100, 100, 100)))\n end\n recSupport = [trues(size(intens[1])) for i in 1:length(intens)]\n\n strainState = BcdiStrain.State(intens, gVecs, recSupport)\n er = BcdiStrain.ER()\n hio = BcdiStrain.HIO(0.9)\n shrink = BcdiStrain.Shrink(0.1, 1.0, strainState)\n center = BcdiStrain.Center(strainState)\n mount = BcdiStrain.Mount(0.5, strainState, primLatt)\n\n a = Animation()\n # We could run the commands this way, but we want to plot in the middle\n (mount * center * er^20)^200 *\n (mount * center * (shrink * hio)^80)^80 * strainState\n\n A = zeros(3,3)\n for i in 1:3\n _, _, peakLoc = BcdiCore.centerPeak(intens[i], recSupport[i], \"corner\")\n peakLoc = collect(peakLoc) .+ [1,1,1]\n peakLoc = Int64.(peakLoc)\n h = reshape(parse.(Float64, split(readlines(\"../data/h$(i).txt\")[1], \",\")), 100, 100, 100)\n k = reshape(parse.(Float64, split(readlines(\"../data/k$(i).txt\")[1], \",\")), 100, 100, 100)\n l = reshape(parse.(Float64, split(readlines(\"../data/l$(i).txt\")[1], \",\")), 100, 100, 100)\n peak = [h[peakLoc...],k[peakLoc...],l[peakLoc...]]\n peak ./= [h[1,1,2]-h[1,1,1],k[1,2,1]-k[1,1,1],l[2,1,1]-l[1,1,1]]\n gVecs[i] .= peak\n A[i,:] .= peak\n end\n\n inSupp = Array(findall(fftshift(strainState.traditionals[1].support)))\n B = zeros(3, reduce(+, strainState.traditionals[1].support))\n B[1,:] .= Array(-fftshift(strainState.ux)[inSupp] .+ fftshift(strainState.uy)[inSupp] .+ fftshift(strainState.uz)[inSupp])\n B[2,:] .= Array(fftshift(strainState.ux)[inSupp] .- fftshift(strainState.uy)[inSupp] .+ fftshift(strainState.uz)[inSupp])\n B[3,:] .= Array(fftshift(strainState.ux)[inSupp] .+ fftshift(strainState.uy)[inSupp] .- fftshift(strainState.uz)[inSupp])\n\n s = size(intens[1])\n x = zeros(length(inSupp))\n y = zeros(length(inSupp))\n z = zeros(length(inSupp))\n for i in 1:length(inSupp)\n x[i] = 2*pi*(inSupp[i][1]-1)/s[1]\n y[i] = 2*pi*(inSupp[i][2]-1)/s[2]\n z[i] = 2*pi*(inSupp[i][3]-1)/s[3]\n end\n\n newStrain = A \\ B\n\n support = strainState.traditionals[1].support\n plotArr = zeros(size(support))\n rho = Array(fftshift(strainState.rho)[inSupp])\n ux = -newStrain[1,:]\n uy = -newStrain[2,:]\n uz = -newStrain[3,:]\n\n mesoState = BcdiMeso.State(\n intens, gVecs, recSupport, x, y, z,\n Array(fftshift(strainState.rho)[inSupp]),\n newStrain[1,:], newStrain[2,:], newStrain[3,:]\n )\n optimizeState1 = BcdiMeso.OptimizeState(mesoState, primLatt, 1)\n optimizeState2 = BcdiMeso.OptimizeState(mesoState, primLatt, 2)\n optimizeState3 = BcdiMeso.OptimizeState(mesoState, primLatt, 3)\n\n for i in 1:100\n saveAn(mesoState.rho, mesoState.ux, mesoState.uy, mesoState.uz, inSupp, plotArr, a)\n optimizeState1 * mesoState\n end\n for j in 1:100\n saveAn(mesoState.rho, mesoState.ux, mesoState.uy, mesoState.uz, inSupp, plotArr, a)\n optimizeState2 * mesoState\n end\n for k in 1:100\n saveAn(mesoState.rho, mesoState.ux, mesoState.uy, mesoState.uz, inSupp, plotArr, a)\n optimizeState3 * mesoState\n end\n\n mov(a, \"../results/recon.webm\", fps=250)\nend\n\nphase()","category":"page"},{"location":"BcdiMesoExamples/examples/#Output","page":"Examples","title":"Output","text":"","category":"section"},{"location":"BcdiMesoExamples/examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"refs/#References","page":"References","title":"References","text":"","category":"section"},{"location":"refs/","page":"References","title":"References","text":"","category":"page"},{"location":"BcdiAtomicExamples/examples/#Environment","page":"Environment","title":"Environment","text":"","category":"section"},{"location":"BcdiAtomicExamples/examples/","page":"Environment","title":"Environment","text":"","category":"page"},{"location":"BcdiAtomicExamples/examples/","page":"Environment","title":"Environment","text":"[deps]\nBcdiAtomic = \"a97cdeff-3185-4906-97ce-92639738da6c\"\nBcdiSimulate = \"b133d2d9-b23b-44ee-be6b-5f897f6a3084\"","category":"page"},{"location":"BcdiCore.jl/README/#BcdiCore","page":"BcdiCore","title":"BcdiCore","text":"","category":"section"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":" (Image: ) ","category":"page"},{"location":"BcdiCore.jl/README/#About","page":"BcdiCore","title":"About","text":"","category":"section"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"Bragg Coherent Diffraction Imaging (BCDI) Core implements some of the core functionality used for future projects BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), BcdiMulti.jl (a multiscale BCDI solver), BcdiTrad.jl (a BCDI solver using projection algorithms), and BcdiStrain (a BCDI solver for mesoscale using projection algorithms). BcdiCore.jl implements the loss functions and derivatives of loss functions used in these packages.","category":"page"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.","category":"page"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiCore.jl/README/#Installation","page":"BcdiCore","title":"Installation","text":"","category":"section"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"Currently, BcdiCore.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiCore.jl/README/","page":"BcdiCore","title":"BcdiCore","text":"add BcdiCore","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/#Mathematical-Definitions","page":"Multiscale Models","title":"Mathematical Definitions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"The multiscale model is a combination of an atomic scale and a mesoscale model. In this case, G(hkl) is defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"G(hkl) = G_a(hkl) + G_m(hkl)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"where a signifies the atomic model and m signifies the mesoscale model.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/#Usage","page":"Multiscale Models","title":"Usage","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"Calculating the loss function and its derivative for the mesoscale model is done in three steps. First, the BcdiCore.MultiState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"state = MultiState(lossType, scale, intens, G, h, k, l)\nsetpts!(state, x, y, z, mx, my, mz, rho, ux, uy, uz, getDeriv)\nlossVal = loss(state, getDeriv, getLoss)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"Here x, y, z are atomic positions and mx, my, mz are the real space locations of the mesoscale model.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/multi/","page":"Multiscale Models","title":"Multiscale Models","text":"If the derivative is requested with the getDeriv variable, the results are stored in state.xDeriv, state.yDeriv, and state.zDeriv, state.rhoDeriv, state.uxDeriv, state.uyDeriv, and state.uzDeriv.","category":"page"},{"location":"BcdiSimulate.jl/docs/src/usage/atom/#API","page":"Atomic Simulation","title":"API","text":"","category":"section"},{"location":"BcdiSimulate.jl/docs/src/usage/atom/","page":"Atomic Simulation","title":"Atomic Simulation","text":"BcdiSimulate.atomSimulateElectricField(x, y, z, hRanges, kRanges, lRanges)\nBcdiSimulate.atomSimulateDiffraction(x, y, z, hRanges, kRanges, lRanges, numPhotons; seed=nothing)\nBcdiSimulate.relaxCrystal(x, y, z, lmpOptions, potentialName)","category":"page"},{"location":"BcdiSimulate.jl/docs/src/usage/atom/#BcdiSimulate.atomSimulateElectricField-NTuple{6, Any}","page":"Atomic Simulation","title":"BcdiSimulate.atomSimulateElectricField","text":"atomSimulateElectricField(x, y, z, hRanges, kRanges, lRanges)\n\nSimulate the electric field for a group of atoms (x, y, and z) on a sequence of grids in reciprocal space (hRanges, kRanges, lRanges). More concretely, calculate\n\nF_hkl = e^- 2 pi i (x h + y k + z l)\n\nx, y, and z do not have to lie on any grid and are assumed to be Vector{Real}. 'hRanges', 'kRanges' and 'lRanges' are not individual points, but are Vector{StepRangeLen}, that together, define the grid to sample reciprocal space over. In general, this will be faster than a full discrete Fourier transform (with O(n^2) operations) because it uses an NUFFT.\n\n\n\n\n\n","category":"method"},{"location":"BcdiSimulate.jl/docs/src/usage/atom/#BcdiSimulate.atomSimulateDiffraction-NTuple{7, Any}","page":"Atomic Simulation","title":"BcdiSimulate.atomSimulateDiffraction","text":"atomSimulateDiffraction(x, y, z, hRanges, kRanges, lRanges, numPhotons; seed=nothing)\n\nSimulate diffraction patterns for a group of atoms (x, y, and z) on a sequence of grids in reciprocal space (hRanges, kRanges, lRanges). More concretely, obtain samples from a Poisson distribution that satisfy\n\nI_hkl oversetindsim Pois(F_hkl)\n\nwhere \n\nF_hkl = e^- 2 pi i (x h + y k + z l)\n\nx, y, and z do not have to lie on any grid and are assumed to be Vector{Real}. 'hRanges', 'kRanges' and 'lRanges' are not individual points, but are Vector{StepRangeLen}, that together, define the grid to sample reciprocal space over. numPhotons defines the number of photons that will, on average, be simulated, and seed is the rng seed. In general, this will be faster than a full discrete Fourier transform (with O(n^2) operations) because it uses an NUFFT.\n\n\n\n\n\n","category":"method"},{"location":"BcdiSimulate.jl/docs/src/usage/atom/#BcdiSimulate.relaxCrystal-NTuple{5, Any}","page":"Atomic Simulation","title":"BcdiSimulate.relaxCrystal","text":"relaxCrystal(x, y, z, lmpOptions, potentialName)\n\nUse LAMMPS to relax the supplied atom positions (x, y, and z). lmpOptions defines command line options to pass to LAMMPS and the potentialName defines the interatomic potential used in the LAMMPS relaxation.\n\n\n\n\n\n","category":"method"},{"location":"BcdiSimulate.jl/docs/src/#BcdiSimulate.jl-Documentation","page":"About/Installation","title":"BcdiSimulate.jl Documentation","text":"","category":"section"},{"location":"BcdiSimulate.jl/docs/src/#About","page":"About/Installation","title":"About","text":"","category":"section"},{"location":"BcdiSimulate.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Bragg Coherent Diffraction Imaging (BCDI) Simulate implements methods to simulate the BCDI problem. Currently, BcdiSimulate only implements atomic scale methods, we may expand these capabilities. ","category":"page"},{"location":"BcdiSimulate.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiSimulate.jl/docs/src/#Installation","page":"About/Installation","title":"Installation","text":"","category":"section"},{"location":"BcdiSimulate.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"BcdiSimulate.jl is not registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiSimulate.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"add https://github.com/byu-cxi/BcdiMeso.jl.git","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/#Mathematical-Definitions","page":"Traditional Models","title":"Mathematical Definitions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"Similar to the mesoscale model, G(u) is initially defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"G(hkl) = sum_j rho_j e^-i (x_j h + y_j k + uz_j l) e^-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"where x_j y_j z_j are real space positions, ux_j uy_j uz_j are diplacement vectors, and hkl represent a distance away from some scattering vector G_h G_k G_l in reciprocal space. However, we assume that, because the distance from the scattering vector and the displacement vectors are small, u cdot h is negligible. So we are left with","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"G(hkl) = sum_j rho_j e^-i (x_j h + y_j k + uz_j l) e^-i (ux_j G_h + uy_j G_k + uz_j G_l) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"Then, we combine the entire rho_j e^-i (ux_j G_h + uy_j G_k + uz_j G_l) quantity as one variable and get","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"G(hkl) = sum_j psi_j e^-i (x_j h + y_j k + uz_j l) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"In this case, this is an ordinary Fourier transform, so we put the factor of 2pi back into G(hkl) to get","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"G(hkl) = sum_j psi_j e^-2 pi i (x_j h + y_j k + uz_j l) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/#Usage","page":"Traditional Models","title":"Usage","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"Calculating the loss function and its derivative for the traditional model is done in two steps. First, the BcdiCore.TradState struct is created. Then, the loss function is calculated with BcdiCore.loss.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"state = TradState(losstype, scale, intens, realSpace)\nlossVal = loss(state, getDeriv, getLoss)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/trad/","page":"Traditional Models","title":"Traditional Models","text":"If the derivative is requested with the getDeriv variable, the result us stored in state.deriv.","category":"page"},{"location":"BcdiTrad.jl/docs/src/#BcdiTrad.jl-Documentation","page":"About/Installation","title":"BcdiTrad.jl Documentation","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/#About","page":"About/Installation","title":"About","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Bragg Coherent Diffraction Imaging (BCDI) Trad (Traditional) implements projection-based phase retrieval algorithms.","category":"page"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.","category":"page"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiTrad.jl/docs/src/#Installation","page":"About/Installation","title":"Installation","text":"","category":"section"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"BcdiTrad.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiTrad.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"add BcdiTrad","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/#Overview","page":"Usage","title":"Overview","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiStrain implements projection-based algorithms in operator-style format. This means that the multiplication (*) and power (^) operators are used to apply operators to some current state. This may look like the following:","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/","page":"Usage","title":"Usage","text":"er = BcdiTrad.ER()\nhio = BcdiTrad.HIO(0.9)\nstate = BcdiTrad.State(intensities, trues(size(intensities)))\n\n(er * hio^20)^5 * state","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/","page":"Usage","title":"Usage","text":"This short script applies 20 HIO iterations and one ER iterations for a total of 5 times. This makes it easy to implement very complex recipes for phase retrieval algorithms.","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/#API","page":"Usage","title":"API","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/use/","page":"Usage","title":"Usage","text":"BcdiStrain.State\nBcdiStrain.ER\nBcdiStrain.HIO\nBcdiStrain.Shrink\nBcdiStrain.Center\nBcdiStrain.Mount","category":"page"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.State","page":"Usage","title":"BcdiStrain.State","text":"State(intensities, gVecs, recSupport)\nState(intensities, gVecs, recSupport, support)\n\nCreate a reconstruction object. intensities is a vector of fully measured diffraction peaks, gVecs is a vector of peak locations, and recSupport is a vector of masks over the intensities that removes those intenities from the reconstruction process.\n\nThe initialization process shifts each peak to be centered in the Fourier sense (i.e. the center of mass of the peak is moved to the edge of the image, or the zero frequency). If the support is not passed in, an initial guess of the support is created by taking an IFFT of the intensities and including everything above 0.1 times the maximum value.\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.ER","page":"Usage","title":"BcdiStrain.ER","text":"ER()\n\nCreate an object that applies one iteration of Error Reduction (ER) to the currently Mounted peak. ER is an iterative projection algorithm that enforces two constraints, (1) the modulus constraint and (2) the support constraint:\n\nWhen moved to reciprocal space, the reconstructed object must match the diffraction pattern.\nThe reconstructed object must fully lie within the support.\n\nOne iteration of ER first applies the modulus constraint, then the support constraint to the object, then returnns.\n\nGradient descent is an alternate way to view the ER algorithm becausee ER is equivalent to gradient descent with a step size of 0.5.\n\nMore information about the ER algorithm can be found in [1, 2].\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.HIO","page":"Usage","title":"BcdiStrain.HIO","text":"HIO(beta)\n\nCreate an object that applies an iteration of hybrid input-output (HIO) to the currently Mounted peak. On the interior of the support, HIO is equivalent to applying the modulus constraint as described in the ER algorithm, and on the exterior of the support, HIO is equal to the current reconstruction minus a fraction of the output after applying the modulus constraint, that is,\n\nrho_i+1 = begincases\nER(rho_i) rho in support \nrho_i - beta * ER(rho_i) rho notin support\nendcases\n\nMarchesini [2] has shown that the HIO algorithm is equivalent to a mini-max problem.\n\nMore information about the HIO algorithm can be found in [1, 2].\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.Shrink","page":"Usage","title":"BcdiStrain.Shrink","text":"Shrink(threshold, sigma, state::State)\n\nCreate an object that applies one iteration of the shrinkwrap algorithm to the current real space object. Shrinkwrap first applies a Gaussian blur to the current reconstruction using sigma as the width of the Gaussian. The support is then created from everything above the threshold times maximum value of the blurred object.\n\nFurther information about the shrinkwrap algorithm can be found in [3].\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.Center","page":"Usage","title":"BcdiStrain.Center","text":"Center(state)\n\nCreate an object that centers the current real space object. The center of mass of the support is calculated and the object is moved so the center of mass is centered in the Fourier transform sense. In other words, the center of mass is moved to the zeroth frequency, or the bottom left corner of the image.\n\n\n\n\n\n","category":"type"},{"location":"BcdiStrain.jl/docs/src/use/#BcdiStrain.Mount","page":"Usage","title":"BcdiStrain.Mount","text":"Mount(beta, state, primitiveRecipLattice)\n\nCreate an object that mounts a new peak. The current real space object is projected back to update the magnitude of the electron density and the displacement field. A new peak is selected at random and the current solution is projected out to this peak.\n\nThe paper that describes this algorithm is currently in submission.\n\n\n\n\n\n","category":"type"},{"location":"BcdiMeso.jl/docs/src/#BcdiMeso.jl-Documentation","page":"About/Installation","title":"BcdiMeso.jl Documentation","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/#About","page":"About/Installation","title":"About","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Bragg Coherent Diffraction Imaging (BCDI) Meso (Mesoscale) implements phase retrieval for mesoscale models with stochastic gradient descent.","category":"page"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.","category":"page"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiMeso.jl/docs/src/#Installation","page":"About/Installation","title":"Installation","text":"","category":"section"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"BcdiStrain.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiMeso.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"add BcdiMeso","category":"page"},{"location":"BcdiStrain.jl/docs/src/#BcdiStrain.jl-Documentation","page":"About/Installation","title":"BcdiStrain.jl Documentation","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/#About","page":"About/Installation","title":"About","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Bragg Coherent Diffraction Imaging (BCDI) Strain implements projection-based phase retrieval algorithms.","category":"page"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval package.","category":"page"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiStrain.jl/docs/src/#Installation","page":"About/Installation","title":"Installation","text":"","category":"section"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"BcdiStrain.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiStrain.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"add BcdiStrain","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/#Mathematical-Definitions","page":"Mesoscale Models","title":"Mathematical Definitions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"Similar to the atomic model, G(u) is initially defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"G(hkl) = sum_j e^-i (x_j (h+G_h) + y_j (k+G_k) + z_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"where x_j y_j z_j are atom positions and hkl represent a distance away from some scattering vector G_h G_k G_l in reciprocal space. However, x_j y_j z_j can be thought of as an addition of lattice spacings and displacement vectors, i.e. x_j+ux_j y_j+uy_j z_j+uz_j. Then, if G_hG_kG_l are reciprocal lattice vectors, we find that x cdot G is an integer multiple of 2pi, so it does not affect the simulated electric field. We are then left with","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"G(hkl) = sum_j e^-i (x_j G_h + y_j G_k + uz_j G_l) e^-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"Coarse graining to get a mesoscale model, we get","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"G(hkl) = sum_j rho_j e^-i (x_j h + y_j k + uz_j l) e^-i (ux_j (h+G_h) + uy_j (k+G_k) + uz_j (l+G_l)) ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"Again, it is important that the hkl value are integers and that they range from -fracn2 to fracn2-1, so both real space and reciprocal space positions must be scaled. The x_jy_jz_j positions should be shifted to lie between 0 to 1 and should be multiplied by 2pi to capture the missing 2 pi scaling in the Fourier transform exponent.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/#Usage","page":"Mesoscale Models","title":"Usage","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"Calculating the loss function and its derivative for the mesoscale model is done in three steps. First, the BcdiCore.MesoState struct is created. Then, the atom positions are set by calling BcdiCore.setpts!. Finally, the loss function is calculated with BcdiCore.loss.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"state = MesoState(lossType, scale, intens, G, h, k, l)\nsetpts!(state, x, y, z, rho, ux, uy, uz, getDeriv)\nlossVal = loss(state, getDeriv, getLoss)","category":"page"},{"location":"BcdiCore.jl/docs/src/use/meso/","page":"Mesoscale Models","title":"Mesoscale Models","text":"If the derivative is requested with the getDeriv variable, the results are stored in state.rhoDeriv, state.uxDeriv, state.uyDeriv, and state.uzDeriv.","category":"page"},{"location":"README/#BcdiExamples","page":"BcdiExamples","title":"BcdiExamples","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/#Example-1","page":"Examples","title":"Example 1","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/#Environment","page":"Examples","title":"Environment","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/","page":"Examples","title":"Examples","text":"[deps]\nBcdiStrain = \"3abd092d-e7bc-4ec6-94c6-c6851986118d\"\nFFTW = \"7a1cc6ca-52ef-59f5-83cd-3a7055c09341\"\nPlots = \"91a5bcdd-55d7-5caf-9e0b-520d859cae80\"","category":"page"},{"location":"BcdiStrainExamples/examples/#Code","page":"Examples","title":"Code","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/","page":"Examples","title":"Examples","text":"using BcdiStrain\nusing Plots\nusing FFTW\n\nfunction saveAn(state, a)\n p1 = heatmap(fftshift(Array(state.rho)[1,:,:]))\n p2 = heatmap(fftshift(Array(state.ux)[1,:,:]))\n p3 = heatmap(fftshift(Array(state.uy)[1,:,:]))\n p4 = heatmap(fftshift(Array(state.uy)[1,:,:]))\n p5 = heatmap(fftshift(Array(abs.(state.traditionals[1].realSpace))[1,:,:]))\n p6 = heatmap(fftshift(Array(angle.(state.traditionals[1].realSpace))[1,:,:]))\n frame(a, plot(p1,p2,p5,p3,p4,p6,layout=6,size=(900,400)))\nend\n\nfunction phase()\n intens = Array{Float64, 3}[]\n gVecs = [[-1.,1,1],[1.,-1,1],[1.,1,-1]]\n primLatt = [-1. 1 1 ; 1 -1 1; 1 1 -1]\n for i in 1:3\n push!(intens, round.(Int64, reshape(parse.(Float64, split(readlines(\"../data/intensities$(i).txt\")[1], \",\")), 100, 100, 100)))\n end\n recSupport = [trues(size(intens[1])) for i in 1:length(intens)]\n\n state = BcdiStrain.State(intens, gVecs, recSupport)\n er = BcdiStrain.ER()\n hio = BcdiStrain.HIO(0.9)\n shrink = BcdiStrain.Shrink(0.1, 1.0, state)\n center = BcdiStrain.Center(state)\n mount = BcdiStrain.Mount(0.5, state, primLatt)\n\n a = Animation()\n # We could run the commands this way, but we want to plot in the middle\n # (mount * center * er^20)^200 *\n # (mount * center * (shrink * hio)^80)^20 * state\n\n for i in 1:20\n for j in 1:80\n hio * state\n saveAn(state, a)\n shrink * state\n end\n center * state\n saveAn(state, a)\n mount * state\n saveAn(state, a)\n end\n for i in 1:200\n for j in 1:20\n er * state\n saveAn(state, a)\n end\n center * state\n saveAn(state, a)\n mount * state\n saveAn(state, a)\n end\n saveAn(state, a)\n mov(a, \"../results/recon.webm\", fps=250)\nend\n\nphase()","category":"page"},{"location":"BcdiStrainExamples/examples/#Output","page":"Examples","title":"Output","text":"","category":"section"},{"location":"BcdiStrainExamples/examples/","page":"Examples","title":"Examples","text":"(Image: )","category":"page"},{"location":"BcdiTrad.jl/README/#BcdiTrad","page":"BcdiTrad","title":"BcdiTrad","text":"","category":"section"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":" (Image: )","category":"page"},{"location":"BcdiTrad.jl/README/#About","page":"BcdiTrad","title":"About","text":"","category":"section"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"Bragg Coherent Diffraction Imaging (BCDI) Trad (Traditional) implements projection-based phase retrieval algorithms. Some of the core functionality of this project is implemented in BcdiCore.jl. Additionally, this package is part of a collection of BCDI packages consisting of BcdiAtomic.jl (an atomic scale BCDI solver), BcdiMeso.jl (a mesoscale BCDI Solver), and BcdiMulti.jl (a multiscale BCDI solver).","category":"page"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.","category":"page"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiTrad.jl/README/#Installation","page":"BcdiTrad","title":"Installation","text":"","category":"section"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"Currently, BcdiTrad.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiTrad.jl/README/","page":"BcdiTrad","title":"BcdiTrad","text":"add BcdiTrad","category":"page"},{"location":"#Julia-BCDI-Documentation","page":"Julia BCDI","title":"Julia BCDI Documentation","text":"","category":"section"},{"location":"#About","page":"Julia BCDI","title":"About","text":"","category":"section"},{"location":"","page":"Julia BCDI","title":"Julia BCDI","text":"The BYU-CXI research group maintains a suite of Julia packages to solve the Bragg Coherent Diffraction Imaging (BCDI) problem in several different regimes and circumstance. ","category":"page"},{"location":"","page":"Julia BCDI","title":"Julia BCDI","text":"BcdiCore.jl (github repo) implements all of the Fourier transforms for the Julia BCDI packages. In addition, BcdiCore calculates the loss function used (either L_2 or the MLE estimator) and derivatives of these loss functions.\nBcdiTrad.jl (github repo) implements projection-based BCDI algorithm. Currently, this is limited to ER, HIO, and shrinkwrap. \nBcdiStrain.jl (github repo) implements a multi-peak BCDI algorithm developed by the BYU-CXI group. In addition to the alogrithms present in BcdiTrad, BcdiStrain also implements Mount, an operator that switches between peaks.\nBcdiMeso.jl (github repo) implements a BCDI algorithm that solves in the mesoscale regime. Instead of using projections, this algorithm uses a gradient-based optimization scheme. Additionally, BcdiMeso does not assume a small measurement distance away from the peak.\nBcdiAtomic.jl is an upcoming BCDI package that implements a BCDI algorithm that solves at the atomic scale.\nBcdiMulti.jl is an upcoming BCDI package that implements a multiscale BCDI algorithm that solves at both the mesoscale and the atomic scale.\nBcdiSimulate.jl (github repo) implements algorithms that simulate the BCDI problem. Currently, this is only implimented at the atomic scale.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"In general, BcdiCore.jl will be called by developers of phase retrieval codes, not end users. BcdiCore.jl implements loss functions and derivatives of loss functions for atomic models, mesoscale models, multiscale models, and traditional projection-based methods.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/#Available-loss-functions","page":"Overview","title":"Available loss functions","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"Currently, BcdiCore.jl implements two types of losses, the average L_2 norm and the average log-likelihood. ","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"Explicitly, the average L_2 loss is defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"L_2 = frac1N sum_u left( lvert G(u) rvert - lvert F(u) rvert right)^2","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"where G(u) is the simulated electric field, lvert F(u) rvert^2 is the measured intensity at a point u in reciprocal space, and N is the total number of meaurement points.","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"The average log-likelihood (for the Poisson distribution) is defined as","category":"page"},{"location":"BcdiCore.jl/docs/src/use/overview/","page":"Overview","title":"Overview","text":"ell = frac1N sum_u lvert G(u) rvert^2 - lvert F(u) rvert^2 lnleft(lvert G(u) rvert^2 right)","category":"page"},{"location":"BcdiCore.jl/docs/src/#BcdiCore-Documentation","page":"About/Installation","title":"BcdiCore Documentation","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/#About","page":"About/Installation","title":"About","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Bragg Coherent Diffraction Imaging (BCDI) Core implements some of the core functionality used for the Julia BCDI packages BcdiCore.jl implements the loss functions and derivatives of loss functions used in these packages.","category":"page"},{"location":"BcdiCore.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"While this package is marked as BCDI specific, the methods are more general and can be used in many phase retrieval problems. In the future, this package may be incorporated into a more general phase retrieval core package.","category":"page"},{"location":"BcdiCore.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"Currently, this entire package must be run with access to GPUs. This may change in the future (especially if Issues requesting it are opened), but for our research group, using GPUs is a necessity.","category":"page"},{"location":"BcdiCore.jl/docs/src/#Installation","page":"About/Installation","title":"Installation","text":"","category":"section"},{"location":"BcdiCore.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"BcdiCore.jl is registered in the Julia general registry and can be installed by running in the REPL package manager (]):","category":"page"},{"location":"BcdiCore.jl/docs/src/","page":"About/Installation","title":"About/Installation","text":"add BcdiCore","category":"page"}] }