Skip to content

Commit

Permalink
Merge pull request #9 from msa-em/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gvarnavi authored Jul 29, 2024
2 parents 730bbfc + 9bbd538 commit 610e463
Show file tree
Hide file tree
Showing 41 changed files with 3,535 additions and 132 deletions.
23 changes: 22 additions & 1 deletion 02_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,25 @@ numbering:
enumerator: 1.%s
---

text
Python has inarguably become the leading programming language in the scientific community, continually gaining popularity for the past two decades. This is due to Python being friendly for beginners, owing to its less strict language structure (dynamic typing, automatic memory management, non-compiled language) and the plethora of tutorials and examples. It also benefits from being free (this text would be less accessible if it required a licence), with numerous high quality libraries covering a broad range of applications (numeric calculations, image analysis, machine learning, ...), including a number of packages dedicated to S/TEM. The diverse and broad scope of the python ecosystem allows for interoperability between different domains, and file formats as well as easily re-purposing existing implementations algorithms to new domains.

There are a number of codes dedicated to S/TEM:
- *ab*TEM - all-Python S/TEM image simulation
- pyPrismatic - image simulation (Python wrapper to C++ package Prismatic)
- pyMultislice - image simulation
- py4DSTEM - 4D-STEM analysis
- liberTEM - 4D-STEM analysis
- pyxem - 4D-STEM analysis
- Hyperspy - General S/TEM analysis
- ...

The main libraries used in the code examples of this text are:
- NumPy (np) - fast numerical calculations
- CuPy (cp) - drop-in replacement for NumPy to run on GPUs
- Numba - just-in-time Python compiler for scientific and array-oriented computing
- matplotlib - all things plotting
- ipywidgets - making interactive figures
- ASE (Atomic Simulation Environment) - creating and visualizing atomic structures
- ...

Dynamically interpreted languages including Python are particularly attractive for domain experts and scientists trying out new ideas, but the performance of the interpreter can be a barrier to high performance. However, by making appropriate use of Python open-source numerical libraries including NumPy, CuPy, and Numba, it is possible to write a purely Python-based code that performs as well or even better than prior codes based on traditional languages such C++ or Fortran. That is indeed what *ab*TEM has been able to achieve, which has made it one of the fastest-growing and popular tools for S/TEM simulations, and our choice for this text.
93 changes: 7 additions & 86 deletions 04_physics.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ math:
\invFFT: \mathcal{F}^{-1}_{\mathbf{k}\to\mathbf{r}}
\FFT: \mathcal{F}_{\mathbf{r}\to\mathbf{k}}
\angstroms: \text{\normalfont\AA}
bibliography:
- refs
github: https://github.com/msa-eom/guide-tem-simulation
label: physics_page
---

(physical-concepts-ts)=
# Physical Concepts (TS)
(physical-concepts)=
# Physical Concepts

The properties of atoms, molecules and solids are fundamentally determined by quantum mechanics. In this modern theory of physics, some classical concepts such as the electrostatic potential and the propagation of waves are carried over essentially unchanged, whereas many familiar intuitions fail on the level of the very small. In particular, quantum objects including electrons exhibit both wave and particle properties depending on how they are observed — in the context of electron scattering, matter-wave interference is of central importance. Mathematically, both free propagating electrons and those bound into atoms are described mathematically as complex waves, via so-called electron wavefunctions.

Expand Down Expand Up @@ -220,8 +218,8 @@ f(\Delta k)=\frac{a_0}{2 \varepsilon_0 \Delta k^{2}} \left(1-\frac{1}{\left(1+\p

Hydrogen is the only case that is analytically solvable; in general neither the density nor the atomic form factor can be directly written down. Instead, these have been calculated using various approximations to the true multielectron wavefunctions, and tabulated for isolated atoms of all elements as isolated atomic potentials.

(isolated-atomic-potentials-ts)=
## Isolated Atomic Potentials (TS)
(isolated-atomic-potentials)=
## Isolated Atomic Potentials

Since the Schrödinger equation cannot be solved analytically even for most molecules, let alone solid-state systems, several kinds of approaches have been developed to obtain approximate solutions. These accurate but computationally very expensive techniques have been used to parametrize what are called isolated atomic potentials – or, equivalently in reciprocal space, electron scattering factors – which describe the potential of a specimen as a sum of isolated, non-interacting atom potentials. This approximation is often called the independent atom model.

Expand All @@ -234,8 +232,8 @@ An example of independent atom model scattering factors and potentials for sever
Independent atom model potentials and scattering factors for several elements.
```

(dft-potentials-ts)=
## Density Functional Theory Potentials (TS)
(dft-potentials)=
## Density Functional Theory Potentials

Since the complicated many-body interactions of multiple electrons mean that wavefunction cannot in general be analytically solved, further approximations are needed. Density functional theory (DFT) is the most prominent one, and is widely use for modeling the electronic structure of molecules and solids. In DFT, the combinatorially intractable many-body problem of $N$ electrons with $3N$ spatial coordinates is reduced to a solution for the three spatial coordinates of the electron density that can be variationally reached. This approximation would in principle be exact, but a term that describes electron exchange and correlation is not analytically known and must be approximated.

Expand Down Expand Up @@ -271,80 +269,3 @@ Although IAM potentials are useful for many purposes, they do neglect chemical b
:name: fig:H2_potential
The difference between the indepdendent atom model potential to the DFT potential for the hydrogen molecule as a function of the distance between the H atoms.
```

(numerical-solutions-of-the-schrodinger-equation-co)=
### Numerical Solutions of the Schrödinger Equation (CO)

As discussed previously, the Schrödinger equation typically cannot be solved analytically in complex systems. Therefore, in order to perform electron scattering simulations, we must calculate numerical solutions of [](#eq:Schrodinger_time) for electron waves. First, we define the {cite:t}`debroglie1925recherches` wavelength of a free electrons (corrected for relativistic effects) as

```{math}
:label: eq:wavelength
\lambda = \frac{h \, c}{\sqrt{e \, E_0 (2 \, m \, c^2 + e \, E_0)}},
```

where {math}`h` is the Plank constant, {math}`c` is the speed of light, {math}`e` is the electron charge, and {math}`E_0` is the accelerating voltage applied to the electron. Using SI units for [](#eq:wavelength) will give the wavelength in units of meters. In practice we typically use length units of for all calculations, and therefore multiple this result by {math}`10^{10}`.

Next, we define the electron-potential interaction constant as (the numerical values of these constants can be found in  [](#app:constants))

```{math}
:label: eq:interaction_constant
\sigma = \frac{2 \pi \, m \, e \, \lambda}{h^2}.
```

In our simulations, we will assume the {math}`z`-position coordinate of the wavefunction {math}`\psi(\bm{r})` is alone sufficient to describe its propagation in both time and space, and therefore drop the {math}`t` coordinate. Substituting [](#eq:wavelength) and [](#eq:interaction_constant) into [](#eq:Schrodinger_time), we obtain {cite:p}`kirkland2020`

```{math}
:label: eq:Shrodinger_electron
\frac{\partial }{\partial z} \psi(\bm{r})
=
\frac{\ii \lambda}{4 \pi} {\nabla_{xy}}^2 \psi(\bm{r})
+
\ii \sigma V(\bm{r}) \psi(\bm{r}),
```

where {math}`{\nabla_{xy}}^2 = \partial^2/\partial x^2 + \partial^2/\partial y^2`. This equation shows the overall numerical recipe we will use; when the wavefunction {math}`\psi_0(\bm{r})` is at position {math}`z_0`, we will evaluate the operators on the right hand side over a distance {math}`\Delta z` to calculate the new wavefunction {math}`\psi(\bm{r})` at position {math}`z_0 + \Delta z`. {cite:t}`kirkland2020` gives the formal operator solution to [](#eq:Shrodinger_electron) as

```{math}
:label: eq:Shrodinger_solution
\psi(\bm{r})
=
\exp \left\{
\int_{z_0}^{z_0 + \Delta z}
\left[
\frac{\ii \lambda}{4 \pi} {\nabla_{xy}}^2
+
\ii \sigma V(\bm{r})
\right] dz
\right\}
\psi_0(\bm{r})
```

Assuming {math}`\Delta z` is small, [](#eq:Shrodinger_solution) can be simplified to

```{math}
:label: eq:Shrodinger_simple
\psi(\bm{r})
=
\exp\left[
\frac{\ii \lambda}{4 \pi} \Delta z {\nabla_{xy}}^2
+
\ii \sigma V_{\Delta z}(\bm{r})
\right]
\psi_0(\bm{r})
```

where

```{math}
V_{\Delta z}(\bm{r})
=
\int_{z_0}^{z_0 + \Delta z}
V(\bm{r}) dz,
```

is a thin slice of the potential. Unfortunately, even with the above approximations, [](#eq:Shrodinger_simple) cannot be solved in closed form due to the two non-commuting operators. Instead, we will solve it numerically by using a split-step method, where we calculate solutions for each operator independently, and alternating their application to the electron wavefunction. This solution was introduced by {cite:t}`cowley1957scattering` and is known as the multislice method.
Loading

1 comment on commit 610e463

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curvenote Preview

Directory Preview Checks Updated (UTC)
. 🔍 Inspect 54 checks passed (21 optional) Jul 29, 2024, 1:14 AM

Please sign in to comment.