|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "source": [ |
| 6 | + "# Create island defect on a slab\n", |
| 7 | + "\n", |
| 8 | + "Create an island defect on a slab\n", |
| 9 | + "\n", |
| 10 | + "<h2 style=\"color:green\">Usage</h2>\n", |
| 11 | + "\n", |
| 12 | + "1. Make sure to select Input Materials (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. Scroll down to view results. \n", |
| 16 | + "\n", |
| 17 | + "\n", |
| 18 | + "## Notes\n", |
| 19 | + "\n", |
| 20 | + "1. For more information, see [Introduction](Introduction.ipynb)\n", |
| 21 | + "<!-- # TODO: use a hashtag-based anchor link to interface creation documention above -->\n" |
| 22 | + ], |
| 23 | + "metadata": { |
| 24 | + "collapsed": false |
| 25 | + }, |
| 26 | + "id": "f2e1e795020d7b3f" |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "markdown", |
| 30 | + "source": [ |
| 31 | + "## 1. Prepare the Environment\n", |
| 32 | + "### 1.1. Set up defect parameters " |
| 33 | + ], |
| 34 | + "metadata": { |
| 35 | + "collapsed": false |
| 36 | + }, |
| 37 | + "id": "5e43ff288847b784" |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "outputs": [], |
| 42 | + "source": [ |
| 43 | + "# Shape-specific parameters\n", |
| 44 | + "# Choose the island shape: 'cylinder', 'sphere', 'box', or 'triangular_prism'\n", |
| 45 | + "# and the corresponding parameters\n", |
| 46 | + "SHAPE_PARAMETERS = {\n", |
| 47 | + " 'shape': 'cylinder',\n", |
| 48 | + " 'radius': 0.25,\n", |
| 49 | + " 'min_z': 0,\n", |
| 50 | + " 'max_z': 1\n", |
| 51 | + "}\n", |
| 52 | + "\n", |
| 53 | + "# Common parameters\n", |
| 54 | + "CENTER_POSITION = [0.5, 0.5, 0.5] # Center of the island\n", |
| 55 | + "USE_CARTESIAN_COORDINATES = False # Use Cartesian coordinates for the island\n", |
| 56 | + "NUMBER_OF_ADDED_LAYERS = 1 # Number of layers to add to the island\n", |
| 57 | + "\n", |
| 58 | + "# Vacuum parameters for builder\n", |
| 59 | + "AUTO_ADD_VACUUM = True # Automatically add vacuum to the slab\n", |
| 60 | + "VACUUM_THICKNESS = 10.0 # Thickness of the vacuum\n", |
| 61 | + "\n", |
| 62 | + "# Slab parameters for creating a new slab if provided material is not a slab\n", |
| 63 | + "DEFAULT_SLAB_PARAMETERS = {\n", |
| 64 | + " \"miller_indices\": (0,0,1),\n", |
| 65 | + " \"thickness\": 3,\n", |
| 66 | + " \"vacuum\": 5.0,\n", |
| 67 | + " \"use_orthogonal_z\": True,\n", |
| 68 | + " \"xy_supercell_matrix\": [[3, 0], [0, 3]]\n", |
| 69 | + "}\n", |
| 70 | + "\n", |
| 71 | + "\n", |
| 72 | + "# Uncomment and set the parameters for other shapes if needed\n", |
| 73 | + "# SHAPE_PARAMETERS = {\n", |
| 74 | + "# 'shape': 'sphere',\n", |
| 75 | + "# 'radius': 0.25\n", |
| 76 | + "# }\n", |
| 77 | + "# \n", |
| 78 | + "# SHAPE_PARAMETERS = {\n", |
| 79 | + "# 'shape': 'box',\n", |
| 80 | + "# 'min_coordinate': [0.25, 0.25, 0],\n", |
| 81 | + "# 'max_coordinate': [0.75, 0.75, 1]\n", |
| 82 | + "# }\n", |
| 83 | + "# \n", |
| 84 | + "# SHAPE_PARAMETERS = {\n", |
| 85 | + "# 'shape': 'triangular_prism',\n", |
| 86 | + "# 'position_on_surface_1': [0.25, 0.25],\n", |
| 87 | + "# 'position_on_surface_2': [0.75, 0.25],\n", |
| 88 | + "# 'position_on_surface_3': [0.5, 0.75],\n", |
| 89 | + "# 'min_z': 0,\n", |
| 90 | + "# 'max_z': 1\n", |
| 91 | + "# }\n", |
| 92 | + "\n" |
| 93 | + ], |
| 94 | + "metadata": { |
| 95 | + "collapsed": false |
| 96 | + }, |
| 97 | + "id": "9d8b1890b34d850a", |
| 98 | + "execution_count": null |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "markdown", |
| 102 | + "source": [ |
| 103 | + "### 1.2. Install Packages\n", |
| 104 | + "The step executes only in Pyodide environment. For other environments, the packages should be installed via `pip install` (see [README](../../README.ipynb))." |
| 105 | + ], |
| 106 | + "metadata": { |
| 107 | + "collapsed": false |
| 108 | + }, |
| 109 | + "id": "bb64de5ff32649f8" |
| 110 | + }, |
| 111 | + { |
| 112 | + "cell_type": "code", |
| 113 | + "outputs": [], |
| 114 | + "source": [ |
| 115 | + "import sys\n", |
| 116 | + "\n", |
| 117 | + "if sys.platform == \"emscripten\":\n", |
| 118 | + " import micropip\n", |
| 119 | + " await micropip.install('mat3ra-api-examples', deps=False)\n", |
| 120 | + " from utils.jupyterlite import install_packages\n", |
| 121 | + " await install_packages(\"\", \"../../config.yml\")" |
| 122 | + ], |
| 123 | + "metadata": { |
| 124 | + "collapsed": false |
| 125 | + }, |
| 126 | + "id": "ef664b14457530fd", |
| 127 | + "execution_count": null |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "markdown", |
| 131 | + "source": [ |
| 132 | + "### 1.3. Get input material" |
| 133 | + ], |
| 134 | + "metadata": { |
| 135 | + "collapsed": false |
| 136 | + }, |
| 137 | + "id": "919ad7af8dceeedd" |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "outputs": [], |
| 142 | + "source": [ |
| 143 | + "from utils.jupyterlite import get_materials\n", |
| 144 | + "materials = get_materials(globals())" |
| 145 | + ], |
| 146 | + "metadata": { |
| 147 | + "collapsed": false |
| 148 | + }, |
| 149 | + "id": "be38fdda1984c654", |
| 150 | + "execution_count": null |
| 151 | + }, |
| 152 | + { |
| 153 | + "cell_type": "markdown", |
| 154 | + "source": [ |
| 155 | + "### 1.4. Preview Slab or create a new one" |
| 156 | + ], |
| 157 | + "metadata": { |
| 158 | + "collapsed": false |
| 159 | + }, |
| 160 | + "id": "a132fe0ef8bbf0d0" |
| 161 | + }, |
| 162 | + { |
| 163 | + "cell_type": "code", |
| 164 | + "outputs": [], |
| 165 | + "source": [ |
| 166 | + "from mat3ra.made.tools.build.slab import create_slab, SlabConfiguration\n", |
| 167 | + "from utils.visualize import visualize_materials as visualize\n", |
| 168 | + "\n", |
| 169 | + "slab = materials[0]\n", |
| 170 | + "if not slab.metadata or slab.metadata[\"build\"][\"configuration\"][\"type\"] != SlabConfiguration.__name__:\n", |
| 171 | + " print(\"The material is not a slab. Creating a new slab...\")\n", |
| 172 | + " slab_config = SlabConfiguration(\n", |
| 173 | + " bulk=materials[0],\n", |
| 174 | + " miller_indices=DEFAULT_SLAB_PARAMETERS[\"miller_indices\"],\n", |
| 175 | + " thickness=DEFAULT_SLAB_PARAMETERS[\"thickness\"],\n", |
| 176 | + " vacuum= DEFAULT_SLAB_PARAMETERS[\"vacuum\"],\n", |
| 177 | + " use_orthogonal_z=DEFAULT_SLAB_PARAMETERS[\"use_orthogonal_z\"],\n", |
| 178 | + " xy_supercell_matrix=DEFAULT_SLAB_PARAMETERS[\"xy_supercell_matrix\"]\n", |
| 179 | + " )\n", |
| 180 | + " \n", |
| 181 | + " slab = create_slab(slab_config)\n", |
| 182 | + "\n", |
| 183 | + "visualize([{\"material\": slab, \"title\": \"Original material\"}])\n", |
| 184 | + "visualize([{\"material\": slab, \"title\": \"Original material\"}], rotation=\"-90x\")" |
| 185 | + ], |
| 186 | + "metadata": { |
| 187 | + "collapsed": false |
| 188 | + }, |
| 189 | + "id": "7fcb1e02e84c5f35", |
| 190 | + "execution_count": null |
| 191 | + }, |
| 192 | + { |
| 193 | + "cell_type": "markdown", |
| 194 | + "source": [ |
| 195 | + "## 2. Create the Target Material\n", |
| 196 | + "### 2.1. Initialize the defect configuration and builder" |
| 197 | + ], |
| 198 | + "metadata": { |
| 199 | + "collapsed": false |
| 200 | + }, |
| 201 | + "id": "690241d87e7bbbe0" |
| 202 | + }, |
| 203 | + { |
| 204 | + "cell_type": "code", |
| 205 | + "outputs": [], |
| 206 | + "source": [ |
| 207 | + "from mat3ra.made.tools.build.defect import IslandSlabDefectConfiguration\n", |
| 208 | + "\n", |
| 209 | + "\n", |
| 210 | + "island_config = IslandSlabDefectConfiguration.from_dict(\n", |
| 211 | + " crystal=slab,\n", |
| 212 | + " condition=SHAPE_PARAMETERS,\n", |
| 213 | + " number_of_added_layers = NUMBER_OF_ADDED_LAYERS\n", |
| 214 | + ")\n", |
| 215 | + "\n", |
| 216 | + "from mat3ra.made.tools.build.defect import IslandSlabDefectBuilder, SlabDefectBuilderParameters\n", |
| 217 | + "params = SlabDefectBuilderParameters(\n", |
| 218 | + " auto_add_vacuum=AUTO_ADD_VACUUM,\n", |
| 219 | + " vacuum_thickness=VACUUM_THICKNESS,\n", |
| 220 | + ")\n", |
| 221 | + "builder = IslandSlabDefectBuilder(build_parameters=params)" |
| 222 | + ], |
| 223 | + "metadata": { |
| 224 | + "collapsed": false |
| 225 | + }, |
| 226 | + "id": "e2d24109d3068c9e", |
| 227 | + "execution_count": null |
| 228 | + }, |
| 229 | + { |
| 230 | + "cell_type": "markdown", |
| 231 | + "source": [ |
| 232 | + "### 2.2. Create the island" |
| 233 | + ], |
| 234 | + "metadata": { |
| 235 | + "collapsed": false |
| 236 | + }, |
| 237 | + "id": "489b51f0ee122c48" |
| 238 | + }, |
| 239 | + { |
| 240 | + "cell_type": "code", |
| 241 | + "outputs": [], |
| 242 | + "source": [ |
| 243 | + "slab_with_island = builder.get_material(island_config)" |
| 244 | + ], |
| 245 | + "metadata": { |
| 246 | + "collapsed": false |
| 247 | + }, |
| 248 | + "id": "a990fa35742d7269", |
| 249 | + "execution_count": null |
| 250 | + }, |
| 251 | + { |
| 252 | + "cell_type": "markdown", |
| 253 | + "source": [ |
| 254 | + "## 3. Visualize the Result(s)" |
| 255 | + ], |
| 256 | + "metadata": { |
| 257 | + "collapsed": false |
| 258 | + }, |
| 259 | + "id": "462549d016073446" |
| 260 | + }, |
| 261 | + { |
| 262 | + "cell_type": "code", |
| 263 | + "outputs": [], |
| 264 | + "source": [ |
| 265 | + "visualize([{\"material\": slab, \"title\": \"Original material\"},\n", |
| 266 | + " {\"material\": slab_with_island, \"title\": f\"Material with Island Defect ({SHAPE_PARAMETERS['shape']})\"}] ,\n", |
| 267 | + "rotation=\"-90x\")\n", |
| 268 | + "\n", |
| 269 | + "visualize([{\"material\": slab, \"title\": \"Original material\"},\n", |
| 270 | + " {\"material\": slab_with_island, \"title\": f\"Material with Island Defect ({SHAPE_PARAMETERS['shape']})\"}], rotation=\"-90x\")" |
| 271 | + ], |
| 272 | + "metadata": { |
| 273 | + "collapsed": false |
| 274 | + }, |
| 275 | + "id": "509b18661a069e42", |
| 276 | + "execution_count": null |
| 277 | + }, |
| 278 | + { |
| 279 | + "cell_type": "markdown", |
| 280 | + "source": [ |
| 281 | + "## 4. Pass data to the outside runtime" |
| 282 | + ], |
| 283 | + "metadata": { |
| 284 | + "collapsed": false |
| 285 | + }, |
| 286 | + "id": "d381df29a6bbdd82" |
| 287 | + }, |
| 288 | + { |
| 289 | + "cell_type": "code", |
| 290 | + "outputs": [], |
| 291 | + "source": [ |
| 292 | + "from utils.jupyterlite import set_materials\n", |
| 293 | + "\n", |
| 294 | + "set_materials(slab_with_island)" |
| 295 | + ], |
| 296 | + "metadata": { |
| 297 | + "collapsed": false |
| 298 | + }, |
| 299 | + "id": "61daa5afcbc078a9", |
| 300 | + "execution_count": null |
| 301 | + } |
| 302 | + ], |
| 303 | + "metadata": { |
| 304 | + "kernelspec": { |
| 305 | + "display_name": "Python 3", |
| 306 | + "language": "python", |
| 307 | + "name": "python3" |
| 308 | + }, |
| 309 | + "language_info": { |
| 310 | + "codemirror_mode": { |
| 311 | + "name": "ipython", |
| 312 | + "version": 2 |
| 313 | + }, |
| 314 | + "file_extension": ".py", |
| 315 | + "mimetype": "text/x-python", |
| 316 | + "name": "python", |
| 317 | + "nbconvert_exporter": "python", |
| 318 | + "pygments_lexer": "ipython2", |
| 319 | + "version": "2.7.6" |
| 320 | + } |
| 321 | + }, |
| 322 | + "nbformat": 4, |
| 323 | + "nbformat_minor": 5 |
| 324 | +} |
0 commit comments