Skip to content

Commit b1594d2

Browse files
committed
update: use new made for slab generation
1 parent a673f50 commit b1594d2

File tree

2 files changed

+101
-45
lines changed

2 files changed

+101
-45
lines changed

other/materials_designer/create_slab.ipynb

Lines changed: 100 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
"cell_type": "code",
4343
"source": [
4444
"# Enable interactive selection of terminations via UI prompt\n",
45-
"IS_TERMINATIONS_SELECTION_INTERACTIVE = False \n",
45+
"IS_TERMINATIONS_SELECTION_INTERACTIVE = False\n",
4646
"\n",
47-
"MILLER_INDICES = (0, 0, 1)\n",
47+
"MILLER_INDICES = (0, 1, 1)\n",
4848
"THICKNESS = 3 # in atomic layers\n",
4949
"VACUUM = 10.0 # in angstroms\n",
50-
"XY_SUPERCELL_MATRIX = [[1, 0], [0, 1]]\n",
50+
"XY_SUPERCELL_MATRIX = [[2, 0], [0, 2]]\n",
5151
"USE_ORTHOGONAL_Z = True\n",
5252
"USE_CONVENTIONAL_CELL = True\n",
5353
"\n",
@@ -79,10 +79,11 @@
7979
"\n",
8080
"if sys.platform == \"emscripten\":\n",
8181
" import micropip\n",
82-
" \n",
82+
"\n",
8383
" await micropip.install('mat3ra-api-examples', deps=False)\n",
8484
" await micropip.install('mat3ra-utils')\n",
8585
" from mat3ra.utils.jupyterlite.packages import install_packages\n",
86+
"\n",
8687
" await install_packages(\"\")"
8788
],
8889
"metadata": {
@@ -108,6 +109,7 @@
108109
"from utils.jupyterlite import get_materials\n",
109110
"\n",
110111
"materials = get_materials(globals())\n",
112+
"print(globals()[\"materials_in\"][0])\n",
111113
"material = materials[0]"
112114
],
113115
"metadata": {
@@ -131,6 +133,7 @@
131133
"cell_type": "code",
132134
"source": [
133135
"from utils.visualize import visualize_materials as visualize\n",
136+
"\n",
134137
"visualize(material, repetitions=[3, 3, 1], rotation=\"0x\")\n",
135138
"visualize(material, repetitions=[3, 3, 1], rotation=\"-90x\")"
136139
],
@@ -155,47 +158,35 @@
155158
"id": "6634dae92a6c07b9"
156159
},
157160
{
161+
"metadata": {},
158162
"cell_type": "code",
159163
"source": [
160-
"from mat3ra.made.tools.build.slab import SlabConfiguration\n",
164+
"from mat3ra.made.tools.build.slab.configuration import CrystalLatticePlanes\n",
161165
"\n",
162-
"slab_configuration = SlabConfiguration(\n",
163-
" bulk=material,\n",
166+
"crystal_lattice_planes = CrystalLatticePlanes(\n",
167+
" crystal=material,\n",
164168
" miller_indices=MILLER_INDICES,\n",
165-
" number_of_layers=THICKNESS, # in atomic layers\n",
166-
" vacuum=VACUUM, # in angstroms\n",
167-
" xy_supercell_matrix=XY_SUPERCELL_MATRIX,\n",
168-
" use_orthogonal_z=USE_ORTHOGONAL_Z,\n",
169-
" use_conventional_cell=USE_CONVENTIONAL_CELL,\n",
169+
" use_conventional_cell=USE_CONVENTIONAL_CELL\n",
170170
")"
171171
],
172-
"metadata": {
173-
"collapsed": false
174-
},
175-
"id": "3ad6765249610aa4",
172+
"id": "ec30720293c64ecc",
176173
"outputs": [],
177174
"execution_count": null
178175
},
179176
{
177+
"metadata": {},
180178
"cell_type": "markdown",
181-
"source": [
182-
"### 2.2. Get possible terminations for the slabs"
183-
],
184-
"metadata": {
185-
"collapsed": false
186-
},
187-
"id": "afb4c9bb89c8690b"
179+
"source": "## 2.1. Get terminations",
180+
"id": "eb3aeb119d8726ba"
188181
},
189182
{
183+
"metadata": {},
190184
"cell_type": "code",
191185
"source": [
192-
"from mat3ra.made.tools.build.slab import get_terminations\n",
193-
"slab_terminations = get_terminations(slab_configuration)"
186+
"terminations = crystal_lattice_planes.get_terminations()\n",
187+
"print(\"Available terminations:\", [str(t) for t in terminations])"
194188
],
195-
"metadata": {
196-
"collapsed": false
197-
},
198-
"id": "70bec9d69d58b28a",
189+
"id": "68bb05623903b05c",
199190
"outputs": [],
200191
"execution_count": null
201192
},
@@ -212,11 +203,12 @@
212203
{
213204
"cell_type": "code",
214205
"source": [
215-
"from mat3ra.made.tools.build.slab import create_slab\n",
216-
"\n",
217-
"slabs = [create_slab(slab_configuration, termination) for termination in slab_terminations]\n",
218-
"\n",
219-
"visualize([{\"material\":slab, \"title\": slab.metadata[\"build\"][\"termination\"]} for slab in slabs ], repetitions=[3, 3, 1], rotation=\"-90x\")"
206+
"# from mat3ra.made.tools.build.slab import create_slab\n",
207+
"#\n",
208+
"# slabs = [create_slab(slab_configuration, termination) for termination in slab_terminations]\n",
209+
"#\n",
210+
"# visualize([{\"material\": slab, \"title\": slab.metadata[\"build\"][\"termination\"]} for slab in slabs], repetitions=[3, 3, 1],\n",
211+
"# rotation=\"-90x\")"
220212
],
221213
"metadata": {
222214
"collapsed": false
@@ -239,7 +231,7 @@
239231
"cell_type": "code",
240232
"source": [
241233
"print(\"Terminations\")\n",
242-
"for idx, termination in enumerate(slab_terminations):\n",
234+
"for idx, termination in enumerate(terminations):\n",
243235
" print(f\" {idx}: {termination}\")"
244236
],
245237
"metadata": {
@@ -266,12 +258,13 @@
266258
"\n",
267259
"termination_index = TERMINATION_INDEX\n",
268260
"\n",
269-
"termination = slab_terminations[termination_index]\n",
261+
"termination = terminations[termination_index]\n",
270262
"if IS_TERMINATIONS_SELECTION_INTERACTIVE:\n",
271263
" if sys.platform == \"emscripten\":\n",
272-
" termination = await ui_prompt_select_array_element_by_index_pyodide(slab_terminations, element_name=\"termination\")\n",
264+
" termination = await ui_prompt_select_array_element_by_index_pyodide(terminations,\n",
265+
" element_name=\"termination\")\n",
273266
" else:\n",
274-
" termination = ui_prompt_select_array_element_by_index(slab_terminations, element_name=\"termination\")"
267+
" termination = ui_prompt_select_array_element_by_index(terminations, element_name=\"termination\")\n"
275268
],
276269
"metadata": {
277270
"collapsed": false
@@ -282,20 +275,84 @@
282275
},
283276
{
284277
"cell_type": "markdown",
278+
"source": "## 3. Create Atomic Layers",
279+
"metadata": {
280+
"collapsed": false
281+
},
282+
"id": "143bc82b430b37d5"
283+
},
284+
{
285+
"metadata": {},
286+
"cell_type": "code",
285287
"source": [
286-
"## 3. Create the slab with selected termination"
288+
"from mat3ra.made.tools.build.slab.configuration import AtomicLayersUniqueRepeated\n",
289+
"\n",
290+
"top_termination = termination\n",
291+
"# TODO: should use `from_parameters`\n",
292+
"atomic_layers = AtomicLayersUniqueRepeated(\n",
293+
" crystal=material,\n",
294+
" miller_indices=MILLER_INDICES,\n",
295+
" use_conventional_cell=True,\n",
296+
" number_of_repetitions=THICKNESS,\n",
297+
" termination_top=top_termination,\n",
298+
")"
287299
],
300+
"id": "f08dc6f4372930e4",
301+
"outputs": [],
302+
"execution_count": null
303+
},
304+
{
305+
"metadata": {},
306+
"cell_type": "markdown",
307+
"source": "### 3.1. Specify vacuum",
308+
"id": "c483e6aae37766b1"
309+
},
310+
{
311+
"metadata": {},
312+
"cell_type": "code",
313+
"source": [
314+
"from mat3ra.made.tools.build.slab.configuration import VacuumConfiguration, AxisEnum\n",
315+
"\n",
316+
"vacuum = VacuumConfiguration(direction=AxisEnum.z, size=VACUUM, is_orthogonal=True)"
317+
],
318+
"id": "ca440d1dad2061da",
319+
"outputs": [],
320+
"execution_count": null
321+
},
322+
{
323+
"metadata": {},
324+
"cell_type": "markdown",
325+
"source": "### 3.2. Create slab configuration",
326+
"id": "41066bf389dfd216"
327+
},
328+
{
288329
"metadata": {
289330
"collapsed": false
290331
},
291-
"id": "143bc82b430b37d5"
332+
"cell_type": "code",
333+
"source": [
334+
"from mat3ra.made.tools.build.slab import SlabConfiguration\n",
335+
"\n",
336+
"slab_configuration = SlabConfiguration(\n",
337+
" supercell_xy=XY_SUPERCELL_MATRIX, stack_components=[atomic_layers, vacuum], direction=AxisEnum.z\n",
338+
")"
339+
],
340+
"id": "ee1be3faa5341c70",
341+
"outputs": [],
342+
"execution_count": null
343+
},
344+
{
345+
"metadata": {},
346+
"cell_type": "markdown",
347+
"source": "### 3.3. Create slab",
348+
"id": "7869f1b09ecd62c6"
292349
},
293350
{
294351
"cell_type": "code",
295352
"source": [
296353
"from mat3ra.made.tools.build.slab import create_slab\n",
297354
"\n",
298-
"slab = create_slab(slab_configuration, termination)"
355+
"slab = create_slab(slab_configuration)"
299356
],
300357
"metadata": {
301358
"collapsed": false
@@ -316,9 +373,7 @@
316373
},
317374
{
318375
"cell_type": "code",
319-
"source": [
320-
"visualize(slab, repetitions=[1, 1, 1], rotation=\"0x\")"
321-
],
376+
"source": "visualize(slab, repetitions=[1, 1, 1], rotation=\"0x\", viewer=\"wave\")",
322377
"metadata": {
323378
"collapsed": false
324379
},
@@ -340,6 +395,7 @@
340395
"cell_type": "code",
341396
"source": [
342397
"from utils.jupyterlite import set_materials\n",
398+
"\n",
343399
"set_materials(slab)"
344400
],
345401
"metadata": {

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies = [
1010
"matplotlib>=3.4.1",
1111
"pandas>=1.5.3",
1212
"pymatgen==2024.4.13",
13-
"mat3ra-made>=2025.4.4.post0",
13+
"mat3ra-made @ git+https://github.com/Exabyte-io/made.git@48bf55d105faac1830ad2c3734a2f1c56a9b8a73",
1414
"mat3ra-utils>=2024.6.11.post0",
1515
]
1616

0 commit comments

Comments
 (0)