Skip to content

Commit

Permalink
Merge pull request #161 from Exabyte-io/feature/SOF-7490
Browse files Browse the repository at this point in the history
feature/SOF 7490
  • Loading branch information
timurbazhirov authored Nov 10, 2024
2 parents 806f64a + f208f5d commit 9049fc9
Show file tree
Hide file tree
Showing 2 changed files with 284 additions and 1 deletion.
11 changes: 10 additions & 1 deletion other/materials_designer/Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +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.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",
Expand Down Expand Up @@ -92,6 +93,14 @@
"\n",
"#### [7.1.1. More info about the conventions used](under_the_hood.ipynb)."
]
},
{
"cell_type": "code",
"outputs": [],
"source": [],
"metadata": {
"collapsed": false
}
}
],
"metadata": {
Expand Down
274 changes: 274 additions & 0 deletions other/materials_designer/create_monolayer.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Create a Monolayer\n",
"\n",
"Create a Monolayer of the original structure. \n",
"\n",
"<h2 style=\"color:green\">Usage</h2>\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": [
"XY_SUPERCELL_MATRIX = [\n",
" [3, 0],\n",
" [0, 3],\n",
"]\n",
"\n",
"VACUUM = 10.0 # Angstrom"
],
"metadata": {
"collapsed": false
},
"id": "a2c8922a4e627887",
"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": "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",
"\n",
" await install_packages(\"\", \"../../config.yml\")"
],
"metadata": {
"collapsed": false
},
"id": "b0c332f1c1f451fd",
"execution_count": null
},
{
"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": null
},
{
"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",
"\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": null
},
{
"cell_type": "markdown",
"source": [
"## 2. Create Monolayer"
],
"metadata": {
"collapsed": false
},
"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.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",
" monolayer = translate_to_z_level(half_filtered_slab, z_level=\"center\")"
],
"metadata": {
"collapsed": false
},
"id": "cf27e53c85adc447",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## 3. Visualize the result"
],
"metadata": {
"collapsed": false
},
"id": "527829d64a542d10"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"visualize(monolayer, repetitions=[1, 1, 1], rotation=\"0x\")\n",
"visualize(monolayer, repetitions=[1, 1, 1], rotation=\"-90x\")"
],
"metadata": {
"collapsed": false
},
"id": "ee12ab13c210b953",
"execution_count": null
},
{
"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",
"\n",
"set_materials(monolayer)"
],
"metadata": {
"collapsed": false
},
"id": "865c71d008d87beb",
"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
}

0 comments on commit 9049fc9

Please sign in to comment.