Skip to content

Commit c37ece6

Browse files
authored
Merge pull request #169 from Exabyte-io/feature/SOF-7494
feature/SOF-7494) feat: terrace NB
2 parents b4bf01c + c157d09 commit c37ece6

File tree

3 files changed

+331
-13
lines changed

3 files changed

+331
-13
lines changed

other/materials_designer/Introduction.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"\n",
6060
"### 3.2. Surface Defects\n",
6161
"#### [3.2.1. Adatom Defect on a Slab](create_adatom_defect.ipynb)\n",
62+
"#### [3.2.2. Terrace Defect on a Slab](create_terrace_defect.ipynb)\n",
6263
"\n",
6364
"### 3.3. Planar Defects\n",
6465
"#### [3.3.1. Grain Boundary in a 3D Crystal](create_grain_boundary_crystal.ipynb)\n",

other/materials_designer/create_cutout_box.ipynb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,18 @@
131131
"cell_type": "code",
132132
"outputs": [],
133133
"source": [
134-
"from mat3ra.made.tools.build.slab import create_slab, SlabConfiguration\n",
134+
"from mat3ra.made.tools.build.slab import create_slab_if_not, SlabConfiguration\n",
135135
"\n",
136-
"slab = materials[0]\n",
137-
"if not slab.metadata or slab.metadata[\"build\"][\"configuration\"][\"type\"] != SlabConfiguration.__name__:\n",
138-
" print(\"The material is not a slab. Creating a new slab...\")\n",
139-
" slab_config = SlabConfiguration(\n",
140-
" bulk=materials[0],\n",
141-
" miller_indices=DEFAULT_SLAB_PARAMETERS[\"miller_indices\"],\n",
142-
" thickness=DEFAULT_SLAB_PARAMETERS[\"thickness\"],\n",
143-
" vacuum=DEFAULT_SLAB_PARAMETERS[\"vacuum\"],\n",
144-
" use_orthogonal_z=DEFAULT_SLAB_PARAMETERS[\"use_orthogonal_z\"],\n",
145-
" xy_supercell_matrix=DEFAULT_SLAB_PARAMETERS[\"xy_supercell_matrix\"]\n",
146-
" )\n",
136+
"default_slab_config = SlabConfiguration(\n",
137+
" bulk=materials[0],\n",
138+
" miller_indices=DEFAULT_SLAB_PARAMETERS[\"miller_indices\"],\n",
139+
" thickness=DEFAULT_SLAB_PARAMETERS[\"thickness\"],\n",
140+
" vacuum=DEFAULT_SLAB_PARAMETERS[\"vacuum\"],\n",
141+
" use_orthogonal_z=DEFAULT_SLAB_PARAMETERS[\"use_orthogonal_z\"],\n",
142+
" xy_supercell_matrix=DEFAULT_SLAB_PARAMETERS[\"xy_supercell_matrix\"]\n",
143+
")\n",
147144
"\n",
148-
" slab = create_slab(slab_config)"
145+
"slab = create_slab_if_not(materials[0], default_slab_config)"
149146
],
150147
"metadata": {
151148
"collapsed": false
Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"source": [
6+
"# Create a Terrace Defect on a Slab\n",
7+
"\n",
8+
"Create a terrace defect by adding layers to a portion of a slab, defined by a cutting plane and number of additional layers.\n",
9+
"\n",
10+
"<h2 style=\"color:green\">Usage</h2>\n",
11+
"\n",
12+
"1. Make sure to select Input Material (in the outer runtime) before running the notebook.\n",
13+
"1. Set notebook parameters in cell 1.1. below (or use the default values).\n",
14+
"1. Click \"Run\" > \"Run All\" to run all cells.\n",
15+
"1. Wait for the run to complete.\n",
16+
"1. Scroll down to view results.\n",
17+
"\n",
18+
"## Notes\n",
19+
"\n",
20+
"1. The input material must be a Slab, or slab will be generated with provided parameters."
21+
],
22+
"metadata": {
23+
"collapsed": false
24+
},
25+
"id": "f5ca6879c3872454"
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"source": [
30+
"## 1. Prepare the Environment\n",
31+
"### 1.1. Set up the notebook\n",
32+
"The cut direction, pivot coordinate, and number of added layers define the terrace defect, shown in the image below.\n",
33+
"<img src=\"https://i.imgur.com/XA2F55Q.png\" alt=\"Terrace parameters visualized\" width=\"400\"/>"
34+
],
35+
"metadata": {
36+
"collapsed": false
37+
},
38+
"id": "ff0f33c4e6ac1303"
39+
},
40+
{
41+
"cell_type": "code",
42+
"outputs": [],
43+
"source": [
44+
"# Material selection\n",
45+
"MATERIAL_INDEX = 0 # Which material to use from input list\n",
46+
"\n",
47+
"# Terrace parameters\n",
48+
"CUT_DIRECTION = [1, 0, 0] # Normal vector describing a plane that cuts the terrace from added layers (Miller indices)\n",
49+
"PIVOT_COORDINATE = [0.5, 0.5, 0.5] # Point the cutting plane passes through, in crystal coordinates\n",
50+
"NUMBER_OF_ADDED_LAYERS = 1 # Height of terrace in atomic layers\n",
51+
"USE_CARTESIAN_COORDINATES = False # Use cartesian instead of crystal coordinates\n",
52+
"ROTATE_TO_MATCH_PBC = True # Rotate to match periodic boundary conditions\n",
53+
"\n",
54+
"# Slab parameters for creating a new slab if provided material is not a slab\n",
55+
"DEFAULT_SLAB_PARAMETERS = {\n",
56+
" \"miller_indices\": (0, 0, 1),\n",
57+
" \"thickness\": 6,\n",
58+
" \"vacuum\": 10.0,\n",
59+
" \"use_orthogonal_z\": True,\n",
60+
" \"xy_supercell_matrix\": [[5, 0], [0, 5]]\n",
61+
"}\n",
62+
"\n",
63+
"# Visualization parameters\n",
64+
"SHOW_INTERMEDIATE_STEPS = True\n",
65+
"CELL_REPETITIONS_FOR_VISUALIZATION = [3, 3, 1] # Structure repeat in view"
66+
],
67+
"metadata": {
68+
"collapsed": false
69+
},
70+
"id": "dd6ca344ae34a2d6",
71+
"execution_count": null
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"source": [
76+
"### 1.2. Install packages\n",
77+
"The step executes only in Pyodide environment. For other environments, the packages should be installed via `pip install`."
78+
],
79+
"metadata": {
80+
"collapsed": false
81+
},
82+
"id": "ac4ec25db74d75f4"
83+
},
84+
{
85+
"cell_type": "code",
86+
"outputs": [],
87+
"source": [
88+
"import sys\n",
89+
"\n",
90+
"if sys.platform == \"emscripten\":\n",
91+
" import micropip\n",
92+
"\n",
93+
" await micropip.install('mat3ra-api-examples', deps=False)\n",
94+
" from utils.jupyterlite import install_packages\n",
95+
"\n",
96+
" await install_packages(\"\")"
97+
],
98+
"metadata": {
99+
"collapsed": false
100+
},
101+
"id": "38574beae9a769cd",
102+
"execution_count": null
103+
},
104+
{
105+
"cell_type": "markdown",
106+
"source": [
107+
"### 1.3. Load input material"
108+
],
109+
"metadata": {
110+
"collapsed": false
111+
},
112+
"id": "c0eab57550f40708"
113+
},
114+
{
115+
"cell_type": "code",
116+
"outputs": [],
117+
"source": [
118+
"from utils.jupyterlite import get_materials\n",
119+
"\n",
120+
"materials = get_materials(globals())"
121+
],
122+
"metadata": {
123+
"collapsed": false
124+
},
125+
"id": "f2479655b99cca48",
126+
"execution_count": null
127+
},
128+
{
129+
"cell_type": "markdown",
130+
"source": [
131+
"### 1.4. Create a slab if the input material is not a slab"
132+
],
133+
"metadata": {
134+
"collapsed": false
135+
},
136+
"id": "4282a853c29a1501"
137+
},
138+
{
139+
"cell_type": "code",
140+
"outputs": [],
141+
"source": [
142+
"from mat3ra.made.tools.build.slab import create_slab_if_not, SlabConfiguration\n",
143+
"\n",
144+
"default_slab_config = SlabConfiguration(\n",
145+
" bulk=materials[0],\n",
146+
" miller_indices=DEFAULT_SLAB_PARAMETERS[\"miller_indices\"],\n",
147+
" thickness=DEFAULT_SLAB_PARAMETERS[\"thickness\"],\n",
148+
" vacuum=DEFAULT_SLAB_PARAMETERS[\"vacuum\"],\n",
149+
" use_orthogonal_z=DEFAULT_SLAB_PARAMETERS[\"use_orthogonal_z\"],\n",
150+
" xy_supercell_matrix=DEFAULT_SLAB_PARAMETERS[\"xy_supercell_matrix\"]\n",
151+
")\n",
152+
"\n",
153+
"slab = create_slab_if_not(materials[0], default_slab_config)"
154+
],
155+
"metadata": {
156+
"collapsed": false
157+
},
158+
"id": "80b7b827c2b390c3",
159+
"execution_count": null
160+
},
161+
{
162+
"cell_type": "markdown",
163+
"source": [
164+
"### 1.5. Visualize slab"
165+
],
166+
"metadata": {
167+
"collapsed": false
168+
},
169+
"id": "916c8b16e01f86ff"
170+
},
171+
{
172+
"cell_type": "code",
173+
"outputs": [],
174+
"source": [
175+
"from utils.visualize import visualize_materials\n",
176+
"\n",
177+
"if SHOW_INTERMEDIATE_STEPS:\n",
178+
" print(\"Initial slab structure:\")\n",
179+
" visualize_materials(slab, repetitions=CELL_REPETITIONS_FOR_VISUALIZATION)\n",
180+
" visualize_materials(slab, repetitions=CELL_REPETITIONS_FOR_VISUALIZATION, rotation=\"-90x\")"
181+
],
182+
"metadata": {
183+
"collapsed": false
184+
},
185+
"id": "16bb968a93de4b9",
186+
"execution_count": null
187+
},
188+
{
189+
"cell_type": "markdown",
190+
"source": [
191+
"## 2. Create target material\n",
192+
"### 2.1. Set up terrace configuration and builder\n"
193+
],
194+
"metadata": {
195+
"collapsed": false
196+
},
197+
"id": "9edaa3afb28ee0ad"
198+
},
199+
{
200+
"cell_type": "code",
201+
"outputs": [],
202+
"source": [
203+
"from mat3ra.made.tools.build.defect.builders import TerraceSlabDefectConfiguration, TerraceSlabDefectBuilder\n",
204+
"\n",
205+
"config = TerraceSlabDefectConfiguration(\n",
206+
" crystal=slab,\n",
207+
" cut_direction=CUT_DIRECTION,\n",
208+
" pivot_coordinate=PIVOT_COORDINATE,\n",
209+
" number_of_added_layers=NUMBER_OF_ADDED_LAYERS,\n",
210+
" use_cartesian_coordinates=USE_CARTESIAN_COORDINATES,\n",
211+
" rotate_to_match_pbc=ROTATE_TO_MATCH_PBC\n",
212+
")\n",
213+
"\n",
214+
"builder = TerraceSlabDefectBuilder()"
215+
],
216+
"metadata": {
217+
"collapsed": false
218+
},
219+
"id": "c318fd03c7e667df",
220+
"execution_count": null
221+
},
222+
{
223+
"cell_type": "markdown",
224+
"source": [
225+
"### 2.2. Generate terrace defect\n"
226+
],
227+
"metadata": {
228+
"collapsed": false
229+
},
230+
"id": "b9df79c67a870181"
231+
},
232+
{
233+
"cell_type": "code",
234+
"outputs": [],
235+
"source": [
236+
"terrace_slab = builder.get_material(config)\n",
237+
"\n",
238+
"print(\"\\nTerrace defect created with:\")\n",
239+
"print(f\"Cut direction: {CUT_DIRECTION}\")\n",
240+
"print(f\"Pivot point: {PIVOT_COORDINATE}\")\n",
241+
"print(f\"Added layers: {NUMBER_OF_ADDED_LAYERS}\")\n",
242+
"print(f\"Number of atoms: {len(terrace_slab.basis.elements.ids)}\")"
243+
],
244+
"metadata": {
245+
"collapsed": false
246+
},
247+
"id": "256bc04ff0aa1810",
248+
"execution_count": null
249+
},
250+
{
251+
"cell_type": "markdown",
252+
"source": [
253+
"## 3. Visualize the result"
254+
],
255+
"metadata": {
256+
"collapsed": false
257+
},
258+
"id": "9bee7a912a90e33c"
259+
},
260+
{
261+
"cell_type": "code",
262+
"outputs": [],
263+
"source": [
264+
"print(\"Final structure with terrace:\")\n",
265+
"visualize_materials(terrace_slab, repetitions=CELL_REPETITIONS_FOR_VISUALIZATION)\n",
266+
"visualize_materials(terrace_slab, repetitions=CELL_REPETITIONS_FOR_VISUALIZATION, rotation=\"-90x\")"
267+
],
268+
"metadata": {
269+
"collapsed": false
270+
},
271+
"id": "4ffdd8589b02de16",
272+
"execution_count": null
273+
},
274+
{
275+
"cell_type": "markdown",
276+
"source": [
277+
"## 4. Pass data to the outside runtime\n"
278+
],
279+
"metadata": {
280+
"collapsed": false
281+
},
282+
"id": "d65865cbab99478"
283+
},
284+
{
285+
"cell_type": "code",
286+
"outputs": [],
287+
"source": [
288+
"from utils.jupyterlite import set_materials\n",
289+
"\n",
290+
"set_materials(terrace_slab)"
291+
],
292+
"metadata": {
293+
"collapsed": false
294+
},
295+
"id": "e292358fe4803b4f",
296+
"execution_count": null
297+
}
298+
],
299+
"metadata": {
300+
"kernelspec": {
301+
"display_name": "Python 3",
302+
"language": "python",
303+
"name": "python3"
304+
},
305+
"language_info": {
306+
"codemirror_mode": {
307+
"name": "ipython",
308+
"version": 2
309+
},
310+
"file_extension": ".py",
311+
"mimetype": "text/x-python",
312+
"name": "python",
313+
"nbconvert_exporter": "python",
314+
"pygments_lexer": "ipython2",
315+
"version": "2.7.6"
316+
}
317+
},
318+
"nbformat": 4,
319+
"nbformat_minor": 5
320+
}

0 commit comments

Comments
 (0)