|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "source": [ |
| 6 | + "# Create a point defect pair in a bulk material\n", |
| 7 | + "\n", |
| 8 | + "Create a pair of point defects: substitution, vacancy, or interstitial in a bulk material.\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) -- to create multiple defects, fill `DEFECT_CONFIGS` with a list of dictionaries. \n", |
| 14 | + "1. Click “Run” > “Run All” to run all cells. \n", |
| 15 | + "1. Scroll down to view results. \n", |
| 16 | + "\n", |
| 17 | + "## Notes\n", |
| 18 | + "\n", |
| 19 | + "1. For more information, see [Introduction](Introduction.ipynb)\n", |
| 20 | + "<!-- # TODO: use a hashtag-based anchor link to interface creation documention above -->\n" |
| 21 | + ], |
| 22 | + "metadata": { |
| 23 | + "collapsed": false |
| 24 | + }, |
| 25 | + "id": "f2e1e795020d7b3f" |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "markdown", |
| 29 | + "source": [ |
| 30 | + "## 1. Prepare the Environment\n", |
| 31 | + "### 1.1. Set up defects parameters \n", |
| 32 | + "Defect Configuration parameters are described in [Defect Configuration](https://github.com/Exabyte-io/made/blob/8196b759242551c77d1791bf5bd2f4150763cfef/src/py/mat3ra/made/tools/build/defect/configuration.py#L102)." |
| 33 | + ], |
| 34 | + "metadata": { |
| 35 | + "collapsed": false |
| 36 | + }, |
| 37 | + "id": "5e43ff288847b784" |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "outputs": [], |
| 42 | + "source": [ |
| 43 | + "DEFECT_TYPE = \"substitution\" # (e.g. \"vacancy\", \"substitution\", \"interstitial\")\n", |
| 44 | + "SITE_ID = None # Site index of the defect\n", |
| 45 | + "COORDINATE = None # Position of the defect in crystal coordinates\n", |
| 46 | + "APPROXIMATE_COORDINATE = None # Approximate coordinates of the defect in crystal coordinates\n", |
| 47 | + "CHEMICAL_ELEMENT = \"C\" # Element to be placed at the site (ignored for vacancy)\n", |
| 48 | + "\n", |
| 49 | + "SUPERCELL_MATRIX = [[3, 0, 0], [0, 3, 0], [0, 0, 3]]\n", |
| 50 | + "\n", |
| 51 | + "# List of dictionaries with defect parameters\n", |
| 52 | + "PRIMARY_DEFECT_CONFIG = {\n", |
| 53 | + " \"defect_type\": \"vacancy\",\n", |
| 54 | + " \"approximate_coordinate\": [0.5, 0.5, 0.5],\n", |
| 55 | + " # \"site_id\": 0,\n", |
| 56 | + " # \"coordinate\": None,\n", |
| 57 | + "}\n", |
| 58 | + "\n", |
| 59 | + "SECONDARY_DEFECT_CONFIG = {\n", |
| 60 | + " \"defect_type\": \"substitution\",\n", |
| 61 | + " \"approximate_coordinate\": [0.55, 0.55, 0.55],\n", |
| 62 | + " \"chemical_element\": \"C\",\n", |
| 63 | + " # \"site_id\": 0,\n", |
| 64 | + " # \"coordinate\": None,\n", |
| 65 | + "}" |
| 66 | + ], |
| 67 | + "metadata": { |
| 68 | + "collapsed": false |
| 69 | + }, |
| 70 | + "id": "9d8b1890b34d850a", |
| 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` (see [README](../../README.ipynb))." |
| 78 | + ], |
| 79 | + "metadata": { |
| 80 | + "collapsed": false |
| 81 | + }, |
| 82 | + "id": "bb64de5ff32649f8" |
| 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(\"create_point_defect.ipynb\", \"../../config.yml\")" |
| 97 | + ], |
| 98 | + "metadata": { |
| 99 | + "collapsed": false |
| 100 | + }, |
| 101 | + "id": "ef664b14457530fd", |
| 102 | + "execution_count": null |
| 103 | + }, |
| 104 | + { |
| 105 | + "cell_type": "markdown", |
| 106 | + "source": [ |
| 107 | + "### 1.3. Get input materials\n", |
| 108 | + "Materials are loaded with `get_materials()`." |
| 109 | + ], |
| 110 | + "metadata": { |
| 111 | + "collapsed": false |
| 112 | + }, |
| 113 | + "id": "919ad7af8dceeedd" |
| 114 | + }, |
| 115 | + { |
| 116 | + "cell_type": "code", |
| 117 | + "outputs": [], |
| 118 | + "source": [ |
| 119 | + "from utils.jupyterlite import get_materials\n", |
| 120 | + "\n", |
| 121 | + "materials = get_materials(globals())" |
| 122 | + ], |
| 123 | + "metadata": { |
| 124 | + "collapsed": false |
| 125 | + }, |
| 126 | + "id": "be38fdda1984c654", |
| 127 | + "execution_count": null |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "markdown", |
| 131 | + "source": [ |
| 132 | + "### 1.4. Create and preview Supercell" |
| 133 | + ], |
| 134 | + "metadata": { |
| 135 | + "collapsed": false |
| 136 | + }, |
| 137 | + "id": "a132fe0ef8bbf0d0" |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "outputs": [], |
| 142 | + "source": [ |
| 143 | + "from utils.visualize import visualize_materials as visualize\n", |
| 144 | + "from mat3ra.made.tools.build.supercell import create_supercell\n", |
| 145 | + "\n", |
| 146 | + "unit_cell = materials[0]\n", |
| 147 | + "supercell = create_supercell(unit_cell, supercell_matrix=SUPERCELL_MATRIX)\n", |
| 148 | + "visualize(supercell, repetitions=[1, 1, 1], rotation=\"0x\")" |
| 149 | + ], |
| 150 | + "metadata": { |
| 151 | + "collapsed": false |
| 152 | + }, |
| 153 | + "id": "e2d24109d3068c9e", |
| 154 | + "execution_count": null |
| 155 | + }, |
| 156 | + { |
| 157 | + "cell_type": "markdown", |
| 158 | + "source": [ |
| 159 | + "## 2. Create the Defect\n", |
| 160 | + "### 2.1. Initialize Configuration and Builder parameters" |
| 161 | + ], |
| 162 | + "metadata": { |
| 163 | + "collapsed": false |
| 164 | + }, |
| 165 | + "id": "5da5b0380583c952" |
| 166 | + }, |
| 167 | + { |
| 168 | + "cell_type": "code", |
| 169 | + "outputs": [], |
| 170 | + "source": [ |
| 171 | + "from mat3ra.made.tools.build.defect.configuration import PointDefectPairConfiguration, PointDefectConfiguration\n", |
| 172 | + "from mat3ra.made.tools.build.defect.builders import PointDefectBuilderParameters\n", |
| 173 | + "\n", |
| 174 | + "primary_defect_configuration = PointDefectConfiguration.from_dict(supercell, PRIMARY_DEFECT_CONFIG)\n", |
| 175 | + "secondary_defect_configuration = PointDefectConfiguration.from_dict(supercell, SECONDARY_DEFECT_CONFIG)\n", |
| 176 | + "\n", |
| 177 | + "point_defect_pair_configuration = PointDefectPairConfiguration(\n", |
| 178 | + " primary_defect_configuration=primary_defect_configuration,\n", |
| 179 | + " secondary_defect_configuration=secondary_defect_configuration\n", |
| 180 | + ")\n", |
| 181 | + "\n", |
| 182 | + "defect_builder_parameters = PointDefectBuilderParameters(center_defect=False)" |
| 183 | + ], |
| 184 | + "metadata": { |
| 185 | + "collapsed": false |
| 186 | + }, |
| 187 | + "id": "e385e50ae11ed2b9", |
| 188 | + "execution_count": null |
| 189 | + }, |
| 190 | + { |
| 191 | + "cell_type": "markdown", |
| 192 | + "source": [ |
| 193 | + "### 2.2. Create the defects" |
| 194 | + ], |
| 195 | + "metadata": { |
| 196 | + "collapsed": false |
| 197 | + }, |
| 198 | + "id": "489b51f0ee122c48" |
| 199 | + }, |
| 200 | + { |
| 201 | + "cell_type": "code", |
| 202 | + "outputs": [], |
| 203 | + "source": [ |
| 204 | + "from mat3ra.made.tools.build.defect.builders import PointDefectPairBuilder\n", |
| 205 | + "\n", |
| 206 | + "material_with_defect = PointDefectPairBuilder(defect_builder_parameters).get_material(point_defect_pair_configuration)" |
| 207 | + ], |
| 208 | + "metadata": { |
| 209 | + "collapsed": false |
| 210 | + }, |
| 211 | + "id": "a990fa35742d7269", |
| 212 | + "execution_count": null |
| 213 | + }, |
| 214 | + { |
| 215 | + "cell_type": "markdown", |
| 216 | + "source": [ |
| 217 | + "## 3. Visualize Result(s)" |
| 218 | + ], |
| 219 | + "metadata": { |
| 220 | + "collapsed": false |
| 221 | + }, |
| 222 | + "id": "462549d016073446" |
| 223 | + }, |
| 224 | + { |
| 225 | + "cell_type": "code", |
| 226 | + "outputs": [], |
| 227 | + "source": [ |
| 228 | + "from utils.visualize import visualize_materials as visualize\n", |
| 229 | + "\n", |
| 230 | + "visualize([{\"material\": supercell, \"title\": \"Original material\"},\n", |
| 231 | + " {\"material\": material_with_defect, \"title\": f\"Material with defect\"}],\n", |
| 232 | + " rotation=\"-90x\")\n", |
| 233 | + "visualize([{\"material\": supercell, \"title\": \"Original material\"},\n", |
| 234 | + " {\"material\": material_with_defect, \"title\": f\"Material with defect\"}])" |
| 235 | + ], |
| 236 | + "metadata": { |
| 237 | + "collapsed": false |
| 238 | + }, |
| 239 | + "id": "509b18661a069e42", |
| 240 | + "execution_count": null |
| 241 | + }, |
| 242 | + { |
| 243 | + "cell_type": "markdown", |
| 244 | + "source": [ |
| 245 | + "## 4. Pass data to the outside runtime" |
| 246 | + ], |
| 247 | + "metadata": { |
| 248 | + "collapsed": false |
| 249 | + }, |
| 250 | + "id": "d381df29a6bbdd82" |
| 251 | + }, |
| 252 | + { |
| 253 | + "cell_type": "code", |
| 254 | + "outputs": [], |
| 255 | + "source": [ |
| 256 | + "from utils.jupyterlite import set_materials\n", |
| 257 | + "\n", |
| 258 | + "set_materials([material_with_defect])" |
| 259 | + ], |
| 260 | + "metadata": { |
| 261 | + "collapsed": false |
| 262 | + }, |
| 263 | + "id": "61daa5afcbc078a9", |
| 264 | + "execution_count": null |
| 265 | + } |
| 266 | + ], |
| 267 | + "metadata": { |
| 268 | + "kernelspec": { |
| 269 | + "display_name": "Python 3", |
| 270 | + "language": "python", |
| 271 | + "name": "python3" |
| 272 | + }, |
| 273 | + "language_info": { |
| 274 | + "codemirror_mode": { |
| 275 | + "name": "ipython", |
| 276 | + "version": 2 |
| 277 | + }, |
| 278 | + "file_extension": ".py", |
| 279 | + "mimetype": "text/x-python", |
| 280 | + "name": "python", |
| 281 | + "nbconvert_exporter": "python", |
| 282 | + "pygments_lexer": "ipython2", |
| 283 | + "version": "2.7.6" |
| 284 | + } |
| 285 | + }, |
| 286 | + "nbformat": 4, |
| 287 | + "nbformat_minor": 5 |
| 288 | +} |
0 commit comments