|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "source": [ |
| 6 | + "# Import materials from Standata\n", |
| 7 | + "\n", |
| 8 | + "This notebook uses Mat3ra Standata package to import materials.\n", |
| 9 | + "\n", |
| 10 | + "<h2 style=\"color:green\">Usage</h2>\n", |
| 11 | + "\n", |
| 12 | + "1. Run the first cell to import the required libraries.\n", |
| 13 | + "2. Run the second cell to get the list of available materials.\n", |
| 14 | + "3. Run the third cell to select a material by name.\n", |
| 15 | + "4. Run the fourth cell to select materials by categories\n" |
| 16 | + ], |
| 17 | + "metadata": { |
| 18 | + "collapsed": false |
| 19 | + }, |
| 20 | + "id": "ffad30f04755fde0" |
| 21 | + }, |
| 22 | + { |
| 23 | + "cell_type": "markdown", |
| 24 | + "source": [ |
| 25 | + "## 1. Install the required libraries" |
| 26 | + ], |
| 27 | + "metadata": { |
| 28 | + "collapsed": false |
| 29 | + }, |
| 30 | + "id": "3a21510793fa71f1" |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "code", |
| 34 | + "outputs": [], |
| 35 | + "source": [ |
| 36 | + "import sys\n", |
| 37 | + "\n", |
| 38 | + "if sys.platform == \"emscripten\":\n", |
| 39 | + " import micropip\n", |
| 40 | + " \n", |
| 41 | + " await micropip.install('mat3ra-api-examples', deps=False)\n", |
| 42 | + " await micropip.install('mat3ra-standata')\n", |
| 43 | + " from utils.jupyterlite import install_packages\n", |
| 44 | + " await install_packages(\"\", \"../../config.yml\")" |
| 45 | + ], |
| 46 | + "metadata": { |
| 47 | + "collapsed": false |
| 48 | + }, |
| 49 | + "id": "7a8c49f4612498a6", |
| 50 | + "execution_count": null |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "markdown", |
| 54 | + "source": [ |
| 55 | + "## 2. Get materials\n", |
| 56 | + "### 2.1. List the names of available materials" |
| 57 | + ], |
| 58 | + "metadata": { |
| 59 | + "collapsed": false |
| 60 | + }, |
| 61 | + "id": "bd6a3ff0c7b23744" |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "code", |
| 65 | + "outputs": [], |
| 66 | + "source": [ |
| 67 | + "from mat3ra.standata.materials import Materials\n", |
| 68 | + "Materials.get_names()" |
| 69 | + ], |
| 70 | + "metadata": { |
| 71 | + "collapsed": false |
| 72 | + }, |
| 73 | + "id": "494aa9dceabed0e1", |
| 74 | + "execution_count": null |
| 75 | + }, |
| 76 | + { |
| 77 | + "cell_type": "markdown", |
| 78 | + "source": [ |
| 79 | + "### 2.2. Select a material by name\n", |
| 80 | + "A partial name match can be used to select a material." |
| 81 | + ], |
| 82 | + "metadata": { |
| 83 | + "collapsed": false |
| 84 | + }, |
| 85 | + "id": "c29a8101462297ad" |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "outputs": [], |
| 90 | + "source": [ |
| 91 | + "from mat3ra.made.material import Material\n", |
| 92 | + "from utils.visualize import visualize_materials\n", |
| 93 | + "\n", |
| 94 | + "# use colloquial name, formula, dimensionality to select a material\n", |
| 95 | + "# returned material is a JSON object and needs to be converted to Material object\n", |
| 96 | + "material_by_name = Material(Materials.get_by_name(\"Graphene\")[0])\n", |
| 97 | + "material_by_name_first_match = Material(Materials.get_by_name_first_match(\"Graphene\"))\n", |
| 98 | + "visualize_materials([material_by_name, material_by_name_first_match])" |
| 99 | + ], |
| 100 | + "metadata": { |
| 101 | + "collapsed": false |
| 102 | + }, |
| 103 | + "id": "a570e2668e86dfab", |
| 104 | + "execution_count": null |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "markdown", |
| 108 | + "source": [ |
| 109 | + "### 2.3. Select materials by categories" |
| 110 | + ], |
| 111 | + "metadata": { |
| 112 | + "collapsed": false |
| 113 | + }, |
| 114 | + "id": "456456a81a911d66" |
| 115 | + }, |
| 116 | + { |
| 117 | + "cell_type": "code", |
| 118 | + "outputs": [], |
| 119 | + "source": [ |
| 120 | + "materials_2d_jsons = Materials.get_by_categories(\"2D\")\n", |
| 121 | + "materials_2d = [Material(material_json) for material_json in materials_2d_jsons]\n", |
| 122 | + "\n", |
| 123 | + "materials_3d_insulator_jsons = Materials.get_by_categories(\"3D\", \"Insulator\")\n", |
| 124 | + "materials_3d_insulator = [Material(material_json) for material_json in materials_3d_insulator_jsons]\n", |
| 125 | + "\n", |
| 126 | + "visualize_materials(materials_2d)\n", |
| 127 | + "visualize_materials(materials_3d_insulator)" |
| 128 | + ], |
| 129 | + "metadata": { |
| 130 | + "collapsed": false |
| 131 | + }, |
| 132 | + "id": "5f192496ce7776af", |
| 133 | + "execution_count": null |
| 134 | + }, |
| 135 | + { |
| 136 | + "cell_type": "markdown", |
| 137 | + "source": [ |
| 138 | + "## 3. Pass data to the outside runtime" |
| 139 | + ], |
| 140 | + "metadata": { |
| 141 | + "collapsed": false |
| 142 | + }, |
| 143 | + "id": "937e08e1120711f0" |
| 144 | + }, |
| 145 | + { |
| 146 | + "cell_type": "code", |
| 147 | + "outputs": [], |
| 148 | + "source": [ |
| 149 | + "from utils.jupyterlite import set_materials\n", |
| 150 | + "\n", |
| 151 | + "set_materials(materials_2d + materials_3d_insulator)" |
| 152 | + ], |
| 153 | + "metadata": { |
| 154 | + "collapsed": false |
| 155 | + }, |
| 156 | + "id": "dcb45a2daead9d55", |
| 157 | + "execution_count": null |
| 158 | + } |
| 159 | + ], |
| 160 | + "metadata": { |
| 161 | + "kernelspec": { |
| 162 | + "display_name": "Python 3", |
| 163 | + "language": "python", |
| 164 | + "name": "python3" |
| 165 | + }, |
| 166 | + "language_info": { |
| 167 | + "codemirror_mode": { |
| 168 | + "name": "ipython", |
| 169 | + "version": 2 |
| 170 | + }, |
| 171 | + "file_extension": ".py", |
| 172 | + "mimetype": "text/x-python", |
| 173 | + "name": "python", |
| 174 | + "nbconvert_exporter": "python", |
| 175 | + "pygments_lexer": "ipython2", |
| 176 | + "version": "2.7.6" |
| 177 | + } |
| 178 | + }, |
| 179 | + "nbformat": 4, |
| 180 | + "nbformat_minor": 5 |
| 181 | +} |
0 commit comments