From 51a135421f709cbd9e7fcb5c2bcb6d71b0848d65 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 26 Nov 2024 18:53:05 -0800 Subject: [PATCH 1/4] feat: add nb for GaN-Mg tutorial --- .../defect_point_pair_gallium_nitride.ipynb | 270 ++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb diff --git a/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb b/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb new file mode 100644 index 00000000..ddb41a40 --- /dev/null +++ b/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb @@ -0,0 +1,270 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Vacancy and Substitutional defect pair in GaN\n", + "\n", + "Focusing on recreating the defect pair in GaN from the Figure 1. c) in the publication:\n", + "\n", + "" + ], + "metadata": { + "collapsed": false + }, + "id": "4f901763903359e6" + }, + { + "cell_type": "markdown", + "source": [ + "## 1. Prepare the Environment\n", + "### 1.1. Set up defects parameters \n", + "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)." + ], + "metadata": { + "collapsed": false + }, + "id": "7863267c827cfbc2" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "\n", + "SUPERCELL_MATRIX = [[3, 0, 0], [0, 3, 0], [0, 0, 2]]\n", + "\n", + "# List of dictionaries with defect parameters\n", + "PRIMARY_DEFECT_CONFIG = {\n", + " \"defect_type\": \"substitution\",\n", + " \"approximate_coordinate\": [0.5, 0.5, 0.5],\n", + " \"chemical_element\": \"Mg\",\n", + "}\n", + "\n", + "SECONDARY_DEFECT_CONFIG = {\n", + " \"defect_type\": \"vacancy\",\n", + " \"approximate_coordinate\": [0.5, 0.5, 0.65],\n", + "}" + ], + "metadata": { + "collapsed": false + }, + "id": "2719b1a0b211ce20", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "### 1.2. Install Packages\n", + "The step executes only in Pyodide environment. For other environments, the packages should be installed via `pip install` (see [README](../../README.ipynb))." + ], + "metadata": { + "collapsed": false + }, + "id": "5626829bece625b" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "import sys\n", + "\n", + "if sys.platform == \"emscripten\":\n", + " import micropip\n", + "\n", + " await micropip.install('mat3ra-api-examples', deps=False)\n", + " from utils.jupyterlite import install_packages\n", + "\n", + " await install_packages(\"create_point_defect.ipynb\")" + ], + "metadata": { + "collapsed": false + }, + "id": "f4994342ac9f2cbd", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "### 1.3. Get input materials\n", + "Materials are loaded with `get_materials()`." + ], + "metadata": { + "collapsed": false + }, + "id": "683ce558645b4465" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "from mat3ra.standata.materials import Materials\n", + "from mat3ra.made.material import Material\n", + "\n", + "material = Material(Materials.get_by_name_first_match(\"GaN\"))" + ], + "metadata": { + "collapsed": false + }, + "id": "4a6bab14f63024d1", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "### 1.4. Create and preview Supercell" + ], + "metadata": { + "collapsed": false + }, + "id": "acfef1aa207eb977" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "from utils.visualize import visualize_materials as visualize\n", + "from mat3ra.made.tools.build.supercell import create_supercell\n", + "\n", + "unit_cell = material\n", + "supercell = create_supercell(unit_cell, supercell_matrix=SUPERCELL_MATRIX)\n", + "visualize(supercell, repetitions=[1, 1, 1], rotation=\"0x\")" + ], + "metadata": { + "collapsed": false + }, + "id": "4580fda63efa927e", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "## 2. Create the Defect\n", + "### 2.1. Initialize Configuration and Builder parameters" + ], + "metadata": { + "collapsed": false + }, + "id": "4391a0f444f4b64a" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "from mat3ra.made.tools.build.defect.configuration import PointDefectPairConfiguration, PointDefectConfiguration\n", + "from mat3ra.made.tools.build.defect.builders import PointDefectBuilderParameters\n", + "\n", + "primary_defect_configuration = PointDefectConfiguration.from_dict(supercell, PRIMARY_DEFECT_CONFIG)\n", + "secondary_defect_configuration = PointDefectConfiguration.from_dict(supercell, SECONDARY_DEFECT_CONFIG)\n", + "\n", + "point_defect_pair_configuration = PointDefectPairConfiguration(\n", + " primary_defect_configuration=primary_defect_configuration,\n", + " secondary_defect_configuration=secondary_defect_configuration\n", + ")\n", + "\n", + "defect_builder_parameters = PointDefectBuilderParameters(center_defect=False)" + ], + "metadata": { + "collapsed": false + }, + "id": "c686498fc4419e3c", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "### 2.2. Create the defects" + ], + "metadata": { + "collapsed": false + }, + "id": "358ae5cd995c821f" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "from mat3ra.made.tools.build.defect.builders import PointDefectPairBuilder\n", + "\n", + "material_with_defect = PointDefectPairBuilder(defect_builder_parameters).get_material(point_defect_pair_configuration)" + ], + "metadata": { + "collapsed": false + }, + "id": "7a584be241ab1548", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "## 3. Visualize Result(s)" + ], + "metadata": { + "collapsed": false + }, + "id": "f99753a31e0123a" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "from utils.visualize import visualize_materials as visualize\n", + "\n", + "visualize([{\"material\": supercell, \"title\": \"Original material\"},\n", + " {\"material\": material_with_defect, \"title\": f\"Material with defect\"}],\n", + " rotation=\"-90x\")\n", + "visualize([{\"material\": supercell, \"title\": \"Original material\"},\n", + " {\"material\": material_with_defect, \"title\": f\"Material with defect\"}])" + ], + "metadata": { + "collapsed": false + }, + "id": "951f0cffe9389d5e", + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "## 4. Pass data to the outside runtime" + ], + "metadata": { + "collapsed": false + }, + "id": "1c5d8e66b5b105ee" + }, + { + "cell_type": "code", + "outputs": [], + "source": [ + "from utils.jupyterlite import set_materials\n", + "\n", + "set_materials([material_with_defect])" + ], + "metadata": { + "collapsed": false + }, + "id": "b9e1aba13faf1bf0", + "execution_count": null + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From cd38310ed952218c35456c50236b05620f6378c9 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:11:13 -0800 Subject: [PATCH 2/4] update: remove unused params --- other/materials_designer/create_point_defect_pair.ipynb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/other/materials_designer/create_point_defect_pair.ipynb b/other/materials_designer/create_point_defect_pair.ipynb index 7c4cadbd..647fe88c 100644 --- a/other/materials_designer/create_point_defect_pair.ipynb +++ b/other/materials_designer/create_point_defect_pair.ipynb @@ -40,12 +40,6 @@ "cell_type": "code", "outputs": [], "source": [ - "DEFECT_TYPE = \"substitution\" # (e.g. \"vacancy\", \"substitution\", \"interstitial\")\n", - "SITE_ID = None # Site index of the defect\n", - "COORDINATE = None # Position of the defect in crystal coordinates\n", - "APPROXIMATE_COORDINATE = None # Approximate coordinates of the defect in crystal coordinates\n", - "CHEMICAL_ELEMENT = \"C\" # Element to be placed at the site (ignored for vacancy)\n", - "\n", "SUPERCELL_MATRIX = [[3, 0, 0], [0, 3, 0], [0, 0, 3]]\n", "\n", "# List of dictionaries with defect parameters\n", From be8fdcf39508a6989fc89a4cd7c1cd99d65cec92 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:11:41 -0800 Subject: [PATCH 3/4] update: correct the defects --- .../defect_point_pair_gallium_nitride.ipynb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb b/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb index ddb41a40..8aaf09fe 100644 --- a/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb +++ b/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb @@ -30,18 +30,17 @@ "cell_type": "code", "outputs": [], "source": [ - "\n", "SUPERCELL_MATRIX = [[3, 0, 0], [0, 3, 0], [0, 0, 2]]\n", "\n", "# List of dictionaries with defect parameters\n", "PRIMARY_DEFECT_CONFIG = {\n", - " \"defect_type\": \"substitution\",\n", + " \"defect_type\": \"substitution\",\n", " \"approximate_coordinate\": [0.5, 0.5, 0.5],\n", " \"chemical_element\": \"Mg\",\n", "}\n", "\n", "SECONDARY_DEFECT_CONFIG = {\n", - " \"defect_type\": \"vacancy\",\n", + " \"defect_type\": \"vacancy\",\n", " \"approximate_coordinate\": [0.5, 0.5, 0.65],\n", "}" ], From 48a6b4bd20cd59fd668e8e6df5fb7a3d948da25e Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:18:18 -0800 Subject: [PATCH 4/4] update: save material to folder --- .../specific_examples/defect_point_pair_gallium_nitride.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb b/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb index 8aaf09fe..916fa9b0 100644 --- a/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb +++ b/other/materials_designer/specific_examples/defect_point_pair_gallium_nitride.ipynb @@ -234,9 +234,9 @@ "cell_type": "code", "outputs": [], "source": [ - "from utils.jupyterlite import set_materials\n", + "from utils.jupyterlite import download_content_to_file\n", "\n", - "set_materials([material_with_defect])" + "download_content_to_file(material_with_defect, \"Mg substitution and vacancy in GaN.json\")" ], "metadata": { "collapsed": false