Skip to content

Commit

Permalink
Added STO supercell widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaSusi committed Sep 3, 2024
1 parent 6b476a4 commit b68eab1
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 6 deletions.
6 changes: 5 additions & 1 deletion appendix.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ numbering:

+++ {"part":"appendix"}
(app:constants)=
### numerical values of constants

### Unit conventions
*ab*TEM and ASE uses the same [unit conventions](https://wiki.fysik.dtu.dk/ase/ase/units.html), as defined in the `ase.units` module. Thus, electron volts (eV), Ångström (Å), and atomic mass units are defined as 1.0. For convenience, user-defined input angles are in mrad.

### Numerical values of constants

The values of commonly used constants in SI units are

Expand Down
43 changes: 40 additions & 3 deletions inputs.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
---
title: Inputs and Simulation Parameters
title: Simulation Inputs
numbering:
enumerator: 1.%s
label : sim_inputs_page
---

text

(atomic-models)=
### Building atomic models
(specimen-models)=
## Specimen models

This chapter introduces the Atomic Simulation Environment ([ASE](https://wiki.fysik.dtu.dk/ase/)) for creating specimen models for use in TEM image simulation.

ASE is a set of tools and Python modules for setting up, manipulating and visualizing atomic structures, which is used in conjunction with a large number of atomistic simulation codes, for example [GPAW](https://wiki.fysik.dtu.dk/gpaw/) for running DFT simulations. In this notebook, ASE is introduced in the context of running electron microscopy image simulations with [*ab*TEM](https://abtem.github.io/doc/intro.html).

### The `Atoms` object

The `Atoms` object defines a collection of atoms. To define `Atoms` from scratch, we need to specify at least three things:

* atomic positions,
* atomic numbers (or chemical symbols),
* a periodic cell.

For example, to create a basic model of the N<sub>2</sub> molecule, we could define:

`atoms = ase.Atoms("N2", positions=[(0.0, 0.0, 0.0), (1.0, 0.0, 0.0)], cell=[6, 6, 6])`

All these attributes of the `Atoms` object are stored in underlying NumPy arrays, which can be directly modified if desired. Convenient arithmetic operations also directly work for the `Atoms` object, so structures can be easily combined to create more complex specimens.

#### Importing structures from files

ASE can import all common atomic-structure formats (full list [here](https://wiki.fysik.dtu.dk/ase/ase/io/io.html)). Below we import a `.cif`-file defining a unit cell of strontium titanate (SrTiO<sub>3</sub>) that we provide with this text and will use in further examples.

`srtio3 = ase.io.read("srtio3.cif")`

### Manipulating atoms
*ab*TEM always assumes that the imaging electrons propagate along the $z$-axis in the direction from _negative to positive_ coordinate values. Hence, to choose the zone axis, we need to manipulate the atoms so they are properly aligned.

ASE has many tools for manipulating structures, but one particularly useful one is the `surface` function, which can be used for creating a periodic surface (aligned with the $z$-axis) for a given set of Miller indices.

In the widget below, we have oriented the strontium titanate structure along the (110)-direction, and interactively create supercells out of it, with 2 Å of vacuum added at the top and bottom surfaces.

```{figure} #app:sto_supercell
:name: fig_sto_supercell
:placeholder: ./static/sto_supercell.png
**Interactive widget showing supercell construction for the STO(110) supercell.
```
144 changes: 142 additions & 2 deletions notebooks/06.1_Atoms_STO-LTO.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 108,
"id": "95c10e75-d7d3-40fa-a127-142d5f84438d",
"metadata": {},
"outputs": [],
Expand All @@ -36,7 +36,147 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 103,
"id": "95f90081-91d8-4eb2-9dd9-b56742137669",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib ipympl\n",
"from IPython.display import display\n",
"import ipywidgets\n",
"\n",
"# widget figure generation\n",
"with plt.ioff():\n",
" dpi = 72\n",
" fig, (ax1,ax2) = plt.subplots(1,2,figsize=(675/dpi, 300/dpi), dpi=dpi)\n",
"\n",
"supercell = srtio3_110.copy()\n",
"supercell.center(2, axis=2)\n",
"\n",
"top = abtem.show_atoms(supercell, ax=ax1, show_periodic=True)\n",
"beam = abtem.show_atoms(supercell, ax=ax2, plane='xz', show_periodic=True, legend=True)\n",
"ax1.set_title(\"Top view\")\n",
"ax2.set_title(\"Beam view\")\n",
"\n",
"fig.tight_layout()\n",
"\n",
"fig.canvas.resizable = False\n",
"fig.canvas.header_visible = False\n",
"fig.canvas.footer_visible = False\n",
"fig.canvas.toolbar_visible = True\n",
"fig.canvas.layout.width = '675px'\n",
"fig.canvas.layout.height = '330px'\n",
"fig.canvas.toolbar_position = 'bottom'"
]
},
{
"cell_type": "code",
"execution_count": 104,
"id": "5d0aeebf-ee62-40fb-a9ed-80f18db8343c",
"metadata": {},
"outputs": [],
"source": [
"def update_atoms(x, y, z):\n",
" ax1.cla()\n",
" ax2.cla()\n",
" supercell = srtio3_110*(x,y,z)\n",
" supercell.center(2, axis=2)\n",
" top = abtem.show_atoms(supercell, ax=ax1, show_periodic=True)\n",
" beam = abtem.show_atoms(supercell, ax=ax2, plane='xz', show_periodic=True, legend=True)\n",
" fig.canvas.draw_idle()\n",
" return None"
]
},
{
"cell_type": "code",
"execution_count": 105,
"id": "ad7fa665-3417-4c8d-ac8b-9a4f2cb445af",
"metadata": {},
"outputs": [],
"source": [
"style = {\n",
" 'description_width': 'initial',\n",
"}\n",
"\n",
"sliderx = ipywidgets.IntSlider(\n",
" orientation='horizontal',\n",
" description='x repetitions: ',\n",
" value=1,\n",
" min=1,\n",
" max=10,\n",
" style = style,\n",
")\n",
"\n",
"slidery = ipywidgets.IntSlider(\n",
" orientation='horizontal',\n",
" description='y repetitions: ',\n",
" value=1,\n",
" min=1,\n",
" max=10,\n",
" style = style,\n",
")\n",
"\n",
"sliderz = ipywidgets.IntSlider(\n",
" orientation='horizontal',\n",
" description='z repetitions: ',\n",
" value=1,\n",
" min=1,\n",
" max=10,\n",
" style = style,\n",
")\n",
"\n",
"ipywidgets.interactive_output(\n",
" update_atoms, \n",
" {\n",
" 'x':sliderx,\n",
" 'y':slidery,\n",
" 'z':sliderz,\n",
" },\n",
")\n",
"None"
]
},
{
"cell_type": "code",
"execution_count": 106,
"id": "f7da1ef3-9a6a-4726-b9b8-da3938e02a11",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cb3eaaca2eb4430083cdee3cd89c6dcb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Canvas(footer_visible=False, header_visible=False, layout=Layout(height='330px', width='675px')…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#| label: app:sto_supercell\n",
"\n",
"widget = ipywidgets.VBox(\n",
" [\n",
" fig.canvas,\n",
" ipywidgets.VBox([\n",
" sliderx,\n",
" slidery,\n",
" sliderz,\n",
" ]),\n",
" ],\n",
")\n",
"\n",
"display(widget);"
]
},
{
"cell_type": "code",
"execution_count": 107,
"id": "ceddcd58-e901-4ad8-b599-2a616854d072",
"metadata": {},
"outputs": [],
Expand Down
Binary file added static/sto_supercell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit b68eab1

@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 57 checks passed (22 optional) Sep 3, 2024, 4:44 PM

Please sign in to comment.