From 484a677c77f55c2fc500f2cd10be5bf269bda858 Mon Sep 17 00:00:00 2001
From: VsevolodX <79542055+VsevolodX@users.noreply.github.com>
Date: Fri, 8 Nov 2024 10:40:02 -0800
Subject: [PATCH 1/5] feat: add monolayer nb
---
.../materials_designer/create_monolayer.ipynb | 221 ++++++++++++++++++
1 file changed, 221 insertions(+)
create mode 100644 other/materials_designer/create_monolayer.ipynb
diff --git a/other/materials_designer/create_monolayer.ipynb b/other/materials_designer/create_monolayer.ipynb
new file mode 100644
index 00000000..6752da5f
--- /dev/null
+++ b/other/materials_designer/create_monolayer.ipynb
@@ -0,0 +1,221 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# Create a Monolayer\n",
+ "\n",
+ "Create a Monolayer of the original structure. \n",
+ "\n",
+ "
Usage
\n",
+ "\n",
+ "1. Make sure to select Input Materials (in the outer runtime) before running the notebook.\n",
+ "1. Set notebook parameters in cell 1.1. below (or use the default values).\n",
+ "1. Click “Run” > “Run All” to run all cells. \n",
+ "1. Scroll down to view results. "
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "a79609c9bc772c5c"
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "## 1. Prepare the Environment\n",
+ "### 1.1. Set up transformation parameters "
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "47d31d9834478007"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "SUPERCELL_MATRIX = [\n",
+ " [3, 0, 0], \n",
+ " [0, 3, 0], \n",
+ " [0, 0, 1]\n",
+ "] \n",
+ "\n",
+ "VACUUM = 10.0 # Angstrom"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "a2c8922a4e627887",
+ "execution_count": 0
+ },
+ {
+ "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": "6fab076ea1d7a223"
+ },
+ {
+ "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",
+ " await install_packages(\"\", \"../../config.yml\")"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "b0c332f1c1f451fd",
+ "execution_count": 0
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 1.3. Get input materials"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "3e9934b458d6cb4"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "from utils.jupyterlite import get_materials\n",
+ "\n",
+ "materials = get_materials(globals())\n",
+ "material = materials[0]"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "74cd0d5a3881ab47",
+ "execution_count": 0
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 1.4. Preview the material"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "d4535caf6debb8d4"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "from utils.visualize import visualize_materials as visualize\n",
+ "visualize(material, repetitions=[3,3,1], rotation=\"0x\")\n",
+ "visualize(material, repetitions=[3,3,1], rotation=\"-90x\")"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "d6bea39864c23ab5",
+ "execution_count": 0
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "## 2. Create Monolayer"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "5473c36cd254aa89"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "from mat3ra.made.tools.build.supercell import create_supercell\n",
+ "\n"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "9ab2230316641bd4",
+ "execution_count": 0
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "## 3. Visualize the result"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "527829d64a542d10"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "visualize(supercell, repetitions=[1, 1, 1], rotation=\"0x\")\n",
+ "visualize(supercell, repetitions=[1, 1, 1], rotation=\"-90x\")"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "ee12ab13c210b953",
+ "execution_count": 0
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# 4. Pass material to the outside runtime"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "6ce5f7dd9a919a08"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "from utils.jupyterlite import set_materials\n",
+ "set_materials(supercell)"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "865c71d008d87beb",
+ "execution_count": 0
+ }
+ ],
+ "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 e8bd3152fa28a1666ccb90804836fdf241ddf91e Mon Sep 17 00:00:00 2001
From: VsevolodX <79542055+VsevolodX@users.noreply.github.com>
Date: Fri, 8 Nov 2024 13:29:55 -0800
Subject: [PATCH 2/5] update: cut a single layer of two
---
.../materials_designer/create_monolayer.ipynb | 86 +++++++++++++++----
1 file changed, 68 insertions(+), 18 deletions(-)
diff --git a/other/materials_designer/create_monolayer.ipynb b/other/materials_designer/create_monolayer.ipynb
index 6752da5f..6f2d5a49 100644
--- a/other/materials_designer/create_monolayer.ipynb
+++ b/other/materials_designer/create_monolayer.ipynb
@@ -34,10 +34,9 @@
"cell_type": "code",
"outputs": [],
"source": [
- "SUPERCELL_MATRIX = [\n",
- " [3, 0, 0], \n",
- " [0, 3, 0], \n",
- " [0, 0, 1]\n",
+ "XY_SUPERCELL_MATRIX = [\n",
+ " [3, 0], \n",
+ " [0, 3], \n",
"] \n",
"\n",
"VACUUM = 10.0 # Angstrom"
@@ -46,7 +45,7 @@
"collapsed": false
},
"id": "a2c8922a4e627887",
- "execution_count": 0
+ "execution_count": null
},
{
"cell_type": "markdown",
@@ -76,7 +75,7 @@
"collapsed": false
},
"id": "b0c332f1c1f451fd",
- "execution_count": 0
+ "execution_count": null
},
{
"cell_type": "markdown",
@@ -95,13 +94,13 @@
"from utils.jupyterlite import get_materials\n",
"\n",
"materials = get_materials(globals())\n",
- "material = materials[0]"
+ "material = materials[20]"
],
"metadata": {
"collapsed": false
},
"id": "74cd0d5a3881ab47",
- "execution_count": 0
+ "execution_count": null
},
{
"cell_type": "markdown",
@@ -125,7 +124,7 @@
"collapsed": false
},
"id": "d6bea39864c23ab5",
- "execution_count": 0
+ "execution_count": null
},
{
"cell_type": "markdown",
@@ -137,18 +136,69 @@
},
"id": "5473c36cd254aa89"
},
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 2.1. Create slab configuration\n",
+ "Slab Configuration lets define the slab thickness, vacuum, and the Miller indices of the interfacial plane and get the slabs with possible terminations.\n"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "ee17958872d03410"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "from mat3ra.made.tools.build.slab import SlabConfiguration\n",
+ "\n",
+ "slab_configuration = SlabConfiguration(\n",
+ " bulk=material,\n",
+ " miller_indices=(0,0,1),\n",
+ " thickness=1,\n",
+ " vacuum=VACUUM, \n",
+ " xy_supercell_matrix=XY_SUPERCELL_MATRIX,\n",
+ " use_orthogonal_z=True,\n",
+ " use_conventional_cell=True,\n",
+ ")"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "b8dc56881543c16c",
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 2.2 Create the slab of Single Layer"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "661c76f9bab9f743"
+ },
{
"cell_type": "code",
"outputs": [],
"source": [
- "from mat3ra.made.tools.build.supercell import create_supercell\n",
- "\n"
+ "from mat3ra.made.tools.modify import translate_to_z_level, filter_by_box\n",
+ "from mat3ra.made.tools.build.slab import create_slab\n",
+ "\n",
+ "slab = create_slab(slab_configuration)\n",
+ "\n",
+ "# Get only the top layer of two -- for AB stacked bilayers forming a 3D bulk basis\n",
+ "if any(substring in material.name for substring in [\"3D\", \"Bulk\"]):\n",
+ " centered_slab = translate_to_z_level(slab, z_level=\"center\")\n",
+ " half_filtered_slab = filter_by_box(centered_slab, [0, 0, 0.5], [1, 1, 1])\n",
+ " slab = translate_to_z_level(half_filtered_slab, z_level=\"center\")"
],
"metadata": {
"collapsed": false
},
- "id": "9ab2230316641bd4",
- "execution_count": 0
+ "id": "cf27e53c85adc447",
+ "execution_count": null
},
{
"cell_type": "markdown",
@@ -164,14 +214,14 @@
"cell_type": "code",
"outputs": [],
"source": [
- "visualize(supercell, repetitions=[1, 1, 1], rotation=\"0x\")\n",
- "visualize(supercell, repetitions=[1, 1, 1], rotation=\"-90x\")"
+ "visualize(slab, repetitions=[1, 1, 1], rotation=\"0x\")\n",
+ "visualize(slab, repetitions=[1, 1, 1], rotation=\"-90x\")"
],
"metadata": {
"collapsed": false
},
"id": "ee12ab13c210b953",
- "execution_count": 0
+ "execution_count": null
},
{
"cell_type": "markdown",
@@ -188,13 +238,13 @@
"outputs": [],
"source": [
"from utils.jupyterlite import set_materials\n",
- "set_materials(supercell)"
+ "set_materials(slab)"
],
"metadata": {
"collapsed": false
},
"id": "865c71d008d87beb",
- "execution_count": 0
+ "execution_count": null
}
],
"metadata": {
From e03417b846b1634f239db259aaf0b9e15216e94e Mon Sep 17 00:00:00 2001
From: VsevolodX <79542055+VsevolodX@users.noreply.github.com>
Date: Fri, 8 Nov 2024 13:45:14 -0800
Subject: [PATCH 3/5] update: adjust the intro nb
---
other/materials_designer/Introduction.ipynb | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/other/materials_designer/Introduction.ipynb b/other/materials_designer/Introduction.ipynb
index 82fa6261..8104b46f 100644
--- a/other/materials_designer/Introduction.ipynb
+++ b/other/materials_designer/Introduction.ipynb
@@ -19,6 +19,7 @@
"\n",
"### 1.2. 2D Structures.\n",
"#### [1.2.1. Slabs. Create slabs from bulk materials.](create_slab.ipynb)\n",
+ "#### [1.2.2. Monolayers. Create monolayer from bulk materials.](create_monolayer.ipynb)\n",
"\n",
"### 1.3. 1D Structures.\n",
"#### [1.3.1. Nanoribbons. Create nanoribbons from 2D materials.](create_nanoribbon.ipynb)\n",
@@ -90,6 +91,14 @@
"\n",
"#### [7.1.1. More info about the conventions used](under_the_hood.ipynb)."
]
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [],
+ "metadata": {
+ "collapsed": false
+ }
}
],
"metadata": {
From 7f4d7eb981b29216fb2f43cae67c7ea9586b6911 Mon Sep 17 00:00:00 2001
From: VsevolodX <79542055+VsevolodX@users.noreply.github.com>
Date: Fri, 8 Nov 2024 17:20:59 -0800
Subject: [PATCH 4/5] chore: adjust names
---
other/materials_designer/Introduction.ipynb | 4 ++--
other/materials_designer/create_monolayer.ipynb | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/other/materials_designer/Introduction.ipynb b/other/materials_designer/Introduction.ipynb
index 8104b46f..e5e40941 100644
--- a/other/materials_designer/Introduction.ipynb
+++ b/other/materials_designer/Introduction.ipynb
@@ -18,8 +18,8 @@
"#### [1.1.1. Supercells. Create supercells from 3D crystals.](create_supercell.ipynb)\n",
"\n",
"### 1.2. 2D Structures.\n",
- "#### [1.2.1. Slabs. Create slabs from bulk materials.](create_slab.ipynb)\n",
- "#### [1.2.2. Monolayers. Create monolayer from bulk materials.](create_monolayer.ipynb)\n",
+ "#### [1.2.1. Slabs. Create a slab from a bulk material.](create_slab.ipynb)\n",
+ "#### [1.2.2. Monolayers. Create a monolayer from a bulk material.](create_monolayer.ipynb)\n",
"\n",
"### 1.3. 1D Structures.\n",
"#### [1.3.1. Nanoribbons. Create nanoribbons from 2D materials.](create_nanoribbon.ipynb)\n",
diff --git a/other/materials_designer/create_monolayer.ipynb b/other/materials_designer/create_monolayer.ipynb
index 6f2d5a49..50ad4316 100644
--- a/other/materials_designer/create_monolayer.ipynb
+++ b/other/materials_designer/create_monolayer.ipynb
@@ -192,7 +192,7 @@
"if any(substring in material.name for substring in [\"3D\", \"Bulk\"]):\n",
" centered_slab = translate_to_z_level(slab, z_level=\"center\")\n",
" half_filtered_slab = filter_by_box(centered_slab, [0, 0, 0.5], [1, 1, 1])\n",
- " slab = translate_to_z_level(half_filtered_slab, z_level=\"center\")"
+ " monolayer = translate_to_z_level(half_filtered_slab, z_level=\"center\")"
],
"metadata": {
"collapsed": false
@@ -214,8 +214,8 @@
"cell_type": "code",
"outputs": [],
"source": [
- "visualize(slab, repetitions=[1, 1, 1], rotation=\"0x\")\n",
- "visualize(slab, repetitions=[1, 1, 1], rotation=\"-90x\")"
+ "visualize(monolayer, repetitions=[1, 1, 1], rotation=\"0x\")\n",
+ "visualize(monolayer, repetitions=[1, 1, 1], rotation=\"-90x\")"
],
"metadata": {
"collapsed": false
@@ -238,7 +238,7 @@
"outputs": [],
"source": [
"from utils.jupyterlite import set_materials\n",
- "set_materials(slab)"
+ "set_materials(monolayer)"
],
"metadata": {
"collapsed": false
From f208f5d7896f594179d7cc2148c105adbf3aec50 Mon Sep 17 00:00:00 2001
From: VsevolodX <79542055+VsevolodX@users.noreply.github.com>
Date: Fri, 8 Nov 2024 17:24:30 -0800
Subject: [PATCH 5/5] chore: a typo
---
.../materials_designer/create_monolayer.ipynb | 23 +++++++++++--------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/other/materials_designer/create_monolayer.ipynb b/other/materials_designer/create_monolayer.ipynb
index 50ad4316..6e2cb957 100644
--- a/other/materials_designer/create_monolayer.ipynb
+++ b/other/materials_designer/create_monolayer.ipynb
@@ -35,11 +35,11 @@
"outputs": [],
"source": [
"XY_SUPERCELL_MATRIX = [\n",
- " [3, 0], \n",
- " [0, 3], \n",
- "] \n",
+ " [3, 0],\n",
+ " [0, 3],\n",
+ "]\n",
"\n",
- "VACUUM = 10.0 # Angstrom"
+ "VACUUM = 10.0 # Angstrom"
],
"metadata": {
"collapsed": false
@@ -66,9 +66,10 @@
"\n",
"if sys.platform == \"emscripten\":\n",
" import micropip\n",
- " \n",
+ "\n",
" await micropip.install('mat3ra-api-examples', deps=False)\n",
" from utils.jupyterlite import install_packages\n",
+ "\n",
" await install_packages(\"\", \"../../config.yml\")"
],
"metadata": {
@@ -94,7 +95,7 @@
"from utils.jupyterlite import get_materials\n",
"\n",
"materials = get_materials(globals())\n",
- "material = materials[20]"
+ "material = materials[0]"
],
"metadata": {
"collapsed": false
@@ -117,8 +118,9 @@
"outputs": [],
"source": [
"from utils.visualize import visualize_materials as visualize\n",
- "visualize(material, repetitions=[3,3,1], rotation=\"0x\")\n",
- "visualize(material, repetitions=[3,3,1], rotation=\"-90x\")"
+ "\n",
+ "visualize(material, repetitions=[3, 3, 1], rotation=\"0x\")\n",
+ "visualize(material, repetitions=[3, 3, 1], rotation=\"-90x\")"
],
"metadata": {
"collapsed": false
@@ -155,9 +157,9 @@
"\n",
"slab_configuration = SlabConfiguration(\n",
" bulk=material,\n",
- " miller_indices=(0,0,1),\n",
+ " miller_indices=(0, 0, 1),\n",
" thickness=1,\n",
- " vacuum=VACUUM, \n",
+ " vacuum=VACUUM,\n",
" xy_supercell_matrix=XY_SUPERCELL_MATRIX,\n",
" use_orthogonal_z=True,\n",
" use_conventional_cell=True,\n",
@@ -238,6 +240,7 @@
"outputs": [],
"source": [
"from utils.jupyterlite import set_materials\n",
+ "\n",
"set_materials(monolayer)"
],
"metadata": {