Skip to content

Commit

Permalink
Merge pull request #169 from Exabyte-io/feature/SOF-7494
Browse files Browse the repository at this point in the history
feature/SOF-7494) feat: terrace NB
  • Loading branch information
VsevolodX authored Nov 26, 2024
2 parents b4bf01c + c157d09 commit c37ece6
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 13 deletions.
1 change: 1 addition & 0 deletions other/materials_designer/Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"\n",
"### 3.2. Surface Defects\n",
"#### [3.2.1. Adatom Defect on a Slab](create_adatom_defect.ipynb)\n",
"#### [3.2.2. Terrace Defect on a Slab](create_terrace_defect.ipynb)\n",
"\n",
"### 3.3. Planar Defects\n",
"#### [3.3.1. Grain Boundary in a 3D Crystal](create_grain_boundary_crystal.ipynb)\n",
Expand Down
23 changes: 10 additions & 13 deletions other/materials_designer/create_cutout_box.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,18 @@
"cell_type": "code",
"outputs": [],
"source": [
"from mat3ra.made.tools.build.slab import create_slab, SlabConfiguration\n",
"from mat3ra.made.tools.build.slab import create_slab_if_not, SlabConfiguration\n",
"\n",
"slab = materials[0]\n",
"if not slab.metadata or slab.metadata[\"build\"][\"configuration\"][\"type\"] != SlabConfiguration.__name__:\n",
" print(\"The material is not a slab. Creating a new slab...\")\n",
" slab_config = SlabConfiguration(\n",
" bulk=materials[0],\n",
" miller_indices=DEFAULT_SLAB_PARAMETERS[\"miller_indices\"],\n",
" thickness=DEFAULT_SLAB_PARAMETERS[\"thickness\"],\n",
" vacuum=DEFAULT_SLAB_PARAMETERS[\"vacuum\"],\n",
" use_orthogonal_z=DEFAULT_SLAB_PARAMETERS[\"use_orthogonal_z\"],\n",
" xy_supercell_matrix=DEFAULT_SLAB_PARAMETERS[\"xy_supercell_matrix\"]\n",
" )\n",
"default_slab_config = SlabConfiguration(\n",
" bulk=materials[0],\n",
" miller_indices=DEFAULT_SLAB_PARAMETERS[\"miller_indices\"],\n",
" thickness=DEFAULT_SLAB_PARAMETERS[\"thickness\"],\n",
" vacuum=DEFAULT_SLAB_PARAMETERS[\"vacuum\"],\n",
" use_orthogonal_z=DEFAULT_SLAB_PARAMETERS[\"use_orthogonal_z\"],\n",
" xy_supercell_matrix=DEFAULT_SLAB_PARAMETERS[\"xy_supercell_matrix\"]\n",
")\n",
"\n",
" slab = create_slab(slab_config)"
"slab = create_slab_if_not(materials[0], default_slab_config)"
],
"metadata": {
"collapsed": false
Expand Down
320 changes: 320 additions & 0 deletions other/materials_designer/create_terrace_defect.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Create a Terrace Defect on a Slab\n",
"\n",
"Create a terrace defect by adding layers to a portion of a slab, defined by a cutting plane and number of additional layers.\n",
"\n",
"<h2 style=\"color:green\">Usage</h2>\n",
"\n",
"1. Make sure to select Input Material (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. Wait for the run to complete.\n",
"1. Scroll down to view results.\n",
"\n",
"## Notes\n",
"\n",
"1. The input material must be a Slab, or slab will be generated with provided parameters."
],
"metadata": {
"collapsed": false
},
"id": "f5ca6879c3872454"
},
{
"cell_type": "markdown",
"source": [
"## 1. Prepare the Environment\n",
"### 1.1. Set up the notebook\n",
"The cut direction, pivot coordinate, and number of added layers define the terrace defect, shown in the image below.\n",
"<img src=\"https://i.imgur.com/XA2F55Q.png\" alt=\"Terrace parameters visualized\" width=\"400\"/>"
],
"metadata": {
"collapsed": false
},
"id": "ff0f33c4e6ac1303"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"# Material selection\n",
"MATERIAL_INDEX = 0 # Which material to use from input list\n",
"\n",
"# Terrace parameters\n",
"CUT_DIRECTION = [1, 0, 0] # Normal vector describing a plane that cuts the terrace from added layers (Miller indices)\n",
"PIVOT_COORDINATE = [0.5, 0.5, 0.5] # Point the cutting plane passes through, in crystal coordinates\n",
"NUMBER_OF_ADDED_LAYERS = 1 # Height of terrace in atomic layers\n",
"USE_CARTESIAN_COORDINATES = False # Use cartesian instead of crystal coordinates\n",
"ROTATE_TO_MATCH_PBC = True # Rotate to match periodic boundary conditions\n",
"\n",
"# Slab parameters for creating a new slab if provided material is not a slab\n",
"DEFAULT_SLAB_PARAMETERS = {\n",
" \"miller_indices\": (0, 0, 1),\n",
" \"thickness\": 6,\n",
" \"vacuum\": 10.0,\n",
" \"use_orthogonal_z\": True,\n",
" \"xy_supercell_matrix\": [[5, 0], [0, 5]]\n",
"}\n",
"\n",
"# Visualization parameters\n",
"SHOW_INTERMEDIATE_STEPS = True\n",
"CELL_REPETITIONS_FOR_VISUALIZATION = [3, 3, 1] # Structure repeat in view"
],
"metadata": {
"collapsed": false
},
"id": "dd6ca344ae34a2d6",
"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`."
],
"metadata": {
"collapsed": false
},
"id": "ac4ec25db74d75f4"
},
{
"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(\"\")"
],
"metadata": {
"collapsed": false
},
"id": "38574beae9a769cd",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### 1.3. Load input material"
],
"metadata": {
"collapsed": false
},
"id": "c0eab57550f40708"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from utils.jupyterlite import get_materials\n",
"\n",
"materials = get_materials(globals())"
],
"metadata": {
"collapsed": false
},
"id": "f2479655b99cca48",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### 1.4. Create a slab if the input material is not a slab"
],
"metadata": {
"collapsed": false
},
"id": "4282a853c29a1501"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from mat3ra.made.tools.build.slab import create_slab_if_not, SlabConfiguration\n",
"\n",
"default_slab_config = SlabConfiguration(\n",
" bulk=materials[0],\n",
" miller_indices=DEFAULT_SLAB_PARAMETERS[\"miller_indices\"],\n",
" thickness=DEFAULT_SLAB_PARAMETERS[\"thickness\"],\n",
" vacuum=DEFAULT_SLAB_PARAMETERS[\"vacuum\"],\n",
" use_orthogonal_z=DEFAULT_SLAB_PARAMETERS[\"use_orthogonal_z\"],\n",
" xy_supercell_matrix=DEFAULT_SLAB_PARAMETERS[\"xy_supercell_matrix\"]\n",
")\n",
"\n",
"slab = create_slab_if_not(materials[0], default_slab_config)"
],
"metadata": {
"collapsed": false
},
"id": "80b7b827c2b390c3",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### 1.5. Visualize slab"
],
"metadata": {
"collapsed": false
},
"id": "916c8b16e01f86ff"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from utils.visualize import visualize_materials\n",
"\n",
"if SHOW_INTERMEDIATE_STEPS:\n",
" print(\"Initial slab structure:\")\n",
" visualize_materials(slab, repetitions=CELL_REPETITIONS_FOR_VISUALIZATION)\n",
" visualize_materials(slab, repetitions=CELL_REPETITIONS_FOR_VISUALIZATION, rotation=\"-90x\")"
],
"metadata": {
"collapsed": false
},
"id": "16bb968a93de4b9",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## 2. Create target material\n",
"### 2.1. Set up terrace configuration and builder\n"
],
"metadata": {
"collapsed": false
},
"id": "9edaa3afb28ee0ad"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from mat3ra.made.tools.build.defect.builders import TerraceSlabDefectConfiguration, TerraceSlabDefectBuilder\n",
"\n",
"config = TerraceSlabDefectConfiguration(\n",
" crystal=slab,\n",
" cut_direction=CUT_DIRECTION,\n",
" pivot_coordinate=PIVOT_COORDINATE,\n",
" number_of_added_layers=NUMBER_OF_ADDED_LAYERS,\n",
" use_cartesian_coordinates=USE_CARTESIAN_COORDINATES,\n",
" rotate_to_match_pbc=ROTATE_TO_MATCH_PBC\n",
")\n",
"\n",
"builder = TerraceSlabDefectBuilder()"
],
"metadata": {
"collapsed": false
},
"id": "c318fd03c7e667df",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### 2.2. Generate terrace defect\n"
],
"metadata": {
"collapsed": false
},
"id": "b9df79c67a870181"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"terrace_slab = builder.get_material(config)\n",
"\n",
"print(\"\\nTerrace defect created with:\")\n",
"print(f\"Cut direction: {CUT_DIRECTION}\")\n",
"print(f\"Pivot point: {PIVOT_COORDINATE}\")\n",
"print(f\"Added layers: {NUMBER_OF_ADDED_LAYERS}\")\n",
"print(f\"Number of atoms: {len(terrace_slab.basis.elements.ids)}\")"
],
"metadata": {
"collapsed": false
},
"id": "256bc04ff0aa1810",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## 3. Visualize the result"
],
"metadata": {
"collapsed": false
},
"id": "9bee7a912a90e33c"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"print(\"Final structure with terrace:\")\n",
"visualize_materials(terrace_slab, repetitions=CELL_REPETITIONS_FOR_VISUALIZATION)\n",
"visualize_materials(terrace_slab, repetitions=CELL_REPETITIONS_FOR_VISUALIZATION, rotation=\"-90x\")"
],
"metadata": {
"collapsed": false
},
"id": "4ffdd8589b02de16",
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## 4. Pass data to the outside runtime\n"
],
"metadata": {
"collapsed": false
},
"id": "d65865cbab99478"
},
{
"cell_type": "code",
"outputs": [],
"source": [
"from utils.jupyterlite import set_materials\n",
"\n",
"set_materials(terrace_slab)"
],
"metadata": {
"collapsed": false
},
"id": "e292358fe4803b4f",
"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 c37ece6

Please sign in to comment.