diff --git a/other/materials_designer/Introduction.ipynb b/other/materials_designer/Introduction.ipynb
index e2a4f339..d4b5d90a 100644
--- a/other/materials_designer/Introduction.ipynb
+++ b/other/materials_designer/Introduction.ipynb
@@ -78,7 +78,8 @@
"## 5. Perturbations.\n",
"\n",
"### 5.1. Slab Perturbations\n",
- "#### [5.1.1. Perturbation using sine wave, custom planar (XY) functions](create_perturbation.ipynb)\n",
+ "#### [5.1.1. Perturbation using sine wave](create_perturbation.ipynb)\n",
+ "#### [5.1.2. Perturbation using custom function](create_perturbation_custom.ipynb)\n",
"\n",
"\n",
"## 6. Other.\n",
diff --git a/other/materials_designer/create_perturbation.ipynb b/other/materials_designer/create_perturbation.ipynb
index b46c1bb4..acdd8e51 100644
--- a/other/materials_designer/create_perturbation.ipynb
+++ b/other/materials_designer/create_perturbation.ipynb
@@ -5,22 +5,16 @@
"source": [
"# Create a Perturbation in a Material\n",
"\n",
- "Create a perturbation in a material with a specified smooth function or a custom function described with [SymPy](https://docs.sympy.org/latest/tutorials/intro-tutorial/intro.html) expressions. \n",
+ "Create a perturbation in a material with a specified smooth function (SineWave by default)\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. Set perturbation parameters in cell 2.1. (or use default).\n",
"1. Click “Run” > “Run All” to run all cells. \n",
"1. Wait for the run to complete (depending on the parameters can take a few min). \n",
"1. Scroll down to view results. \n",
"\n",
- "## Summary\n",
- "1. Prepare the Environment: Set up the notebook and install packages, preview the input materials\n",
- "1. Create the Perturbation: Add a smooth perturbation to the material\n",
- "2. Visualize the Perturbed Material\n",
- "\n",
"## Notes\n",
"\n",
"1. For more information, see [Introduction](Introduction.ipynb)\n"
@@ -34,7 +28,7 @@
"cell_type": "markdown",
"source": [
"## 1. Prepare the Environment\n",
- "### 1.1. Set up supercell parameters "
+ "### 1.1. Set up perturbation parameters"
],
"metadata": {
"collapsed": false
@@ -45,7 +39,17 @@
"cell_type": "code",
"outputs": [],
"source": [
- "SUPERCELL_MATRIX = [[30, 0, 0], [0, 30, 0], [0, 0, 1]] "
+ "# Sine wave perturbation parameters\n",
+ "AMPLITUDE = 0.5\n",
+ "WAVELENGTH = 1.0\n",
+ "PHASE = 0.0\n",
+ "AXIS = \"y\"\n",
+ "\n",
+ "USE_CARTESIAN_COORDINATES = False\n",
+ "\n",
+ "SUPERCELL_MATRIX = [[30, 0, 0], [0, 30, 0], [0, 0, 1]]\n",
+ "\n",
+ "PRESERVE_GEODESIC_DISTANCE = False"
],
"metadata": {
"collapsed": false
@@ -72,8 +76,10 @@
"\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": {
@@ -98,6 +104,7 @@
"outputs": [],
"source": [
"from utils.jupyterlite import get_materials\n",
+ "\n",
"materials = get_materials(globals())"
],
"metadata": {
@@ -149,23 +156,24 @@
"cell_type": "code",
"outputs": [],
"source": [
- "from mat3ra.made.tools.build.perturbation import PerturbationConfiguration, SlabPerturbationBuilder\n",
+ "from mat3ra.made.tools.build.perturbation import PerturbationConfiguration, SlabPerturbationBuilder, CellMatchingDistancePreservingSlabPerturbationBuilder\n",
"from mat3ra.made.tools.utils.perturbation import SineWavePerturbationFunctionHolder\n",
"\n",
- "amplitude = 0.05\n",
- "wavelength = 1\n",
- "phase = 0\n",
- "axis = \"y\"\n",
- "perturbation_function = SineWavePerturbationFunctionHolder(amplitude=amplitude, \n",
- " wavelength=wavelength, \n",
- " phase=phase,\n",
- " axis=axis)\n",
+ "perturbation_function = SineWavePerturbationFunctionHolder(\n",
+ " amplitude=AMPLITUDE,\n",
+ " wavelength=WAVELENGTH,\n",
+ " phase=PHASE,\n",
+ " axis=AXIS)\n",
"\n",
- "configuration = PerturbationConfiguration(material=supercell, \n",
- " perturbation_function_holder=perturbation_function,\n",
- " use_cartesian_coordinates=False)\n",
+ "configuration = PerturbationConfiguration(\n",
+ " material=supercell,\n",
+ " perturbation_function_holder=perturbation_function,\n",
+ " use_cartesian_coordinates=USE_CARTESIAN_COORDINATES)\n",
"\n",
- "builder = SlabPerturbationBuilder()"
+ "if PRESERVE_GEODESIC_DISTANCE:\n",
+ " builder = CellMatchingDistancePreservingSlabPerturbationBuilder()\n",
+ "else:\n",
+ " builder = SlabPerturbationBuilder()"
],
"metadata": {
"collapsed": false
@@ -200,7 +208,7 @@
{
"cell_type": "markdown",
"source": [
- "### 2.3. Visualize the Material"
+ "### 3. Visualize the Result"
],
"metadata": {
"collapsed": false
@@ -216,7 +224,7 @@
"visualize([{\"material\": supercell, \"title\": \"Original material\"},\n",
" {\"material\": material_with_perturbation, \"title\": f\"Material with perturbation\"},\n",
" {\"material\": material_with_perturbation, \"title\": f\"Material with perturbation\", \"rotation\": \"-90x\"},\n",
- "])"
+ " ])"
],
"metadata": {
"collapsed": false
@@ -224,88 +232,6 @@
"id": "1ee393a7f2ec3bc8",
"execution_count": null
},
- {
- "cell_type": "markdown",
- "source": [
- "## 3. Create a Custom Perturbation\n",
- "### 3.1. Set custom perturbation parameters\n",
- "Provide a SymPy expression for the perturbation function. The expression should be a function of `x`, `y` and `z` variables."
- ],
- "metadata": {
- "collapsed": false
- },
- "id": "6d4adf0d580e0340"
- },
- {
- "cell_type": "code",
- "outputs": [],
- "source": [
- "import sympy as sp\n",
- "from mat3ra.made.tools.build.perturbation import CellMatchingDistancePreservingSlabPerturbationBuilder\n",
- "from mat3ra.made.tools.utils.perturbation import PerturbationFunctionHolder\n",
- "\n",
- "x,y = sp.symbols('x y')\n",
- "function = amplitude * sp.sin(2 * sp.pi * x / wavelength + phase) * sp.sin(2 * sp.pi * y / wavelength)\n",
- "\n",
- "custom_perturbation_function = PerturbationFunctionHolder(function=function, variables=[\"x\", \"y\"])\n",
- "configuration_custom = PerturbationConfiguration(material=supercell,\n",
- " perturbation_function_holder=custom_perturbation_function,\n",
- " use_cartesian_coordinates=False)\n",
- "distance_preserving_builder = CellMatchingDistancePreservingSlabPerturbationBuilder()"
- ],
- "metadata": {
- "collapsed": false
- },
- "id": "8d90932312c418ee",
- "execution_count": null
- },
- {
- "cell_type": "markdown",
- "source": [
- "### 3.2. Apply perturbation to the material"
- ],
- "metadata": {
- "collapsed": false
- },
- "id": "7695d5d1df6be2e3"
- },
- {
- "cell_type": "code",
- "outputs": [],
- "source": [
- "material_with_custom_perturbation = create_perturbation(configuration_custom, distance_preserving_builder)"
- ],
- "metadata": {
- "collapsed": false
- },
- "id": "69ccc90b8c5c1191",
- "execution_count": null
- },
- {
- "cell_type": "markdown",
- "source": [
- "### 3.3. Visualize the Material"
- ],
- "metadata": {
- "collapsed": false
- },
- "id": "10e7ca8950839991"
- },
- {
- "cell_type": "code",
- "outputs": [],
- "source": [
- "visualize([\n",
- " {\"material\": material_with_custom_perturbation, \"title\": f\"Material with custom perturbation\"},\n",
- " {\"material\": material_with_custom_perturbation, \"title\": f\"Material with custom perturbation\",\"rotation\": \"-90x\"}\n",
- "])"
- ],
- "metadata": {
- "collapsed": false
- },
- "id": "cbfe0878a16f6c83",
- "execution_count": null
- },
{
"cell_type": "markdown",
"source": [
@@ -322,7 +248,7 @@
"source": [
"from utils.jupyterlite import set_materials\n",
"\n",
- "set_materials([material_with_perturbation, material_with_custom_perturbation])"
+ "set_materials(material_with_perturbation)"
],
"metadata": {
"collapsed": false
diff --git a/other/materials_designer/create_perturbation_custom.ipynb b/other/materials_designer/create_perturbation_custom.ipynb
new file mode 100644
index 00000000..1fcbde13
--- /dev/null
+++ b/other/materials_designer/create_perturbation_custom.ipynb
@@ -0,0 +1,317 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# Create a Custom Perturbation in a Material\n",
+ "\n",
+ "Create a perturbation in a material with a custom function described with [SymPy](https://docs.sympy.org/latest/tutorials/intro-tutorial/intro.html) expressions. \n",
+ "\n",
+ "Usage
\n",
+ "\n",
+ "1. Make sure to select Input Materials (in the outer runtime) before running the notebook.\n",
+ "1. Set perturbation parameters in cell 1.2. (or use default).\n",
+ "1. Set custom perturbation function with SymPy in cell 1.3.\n",
+ "1. Click “Run” > “Run All” to run all cells. \n",
+ "1. Wait for the run to complete (depending on the parameters can take a few min). \n",
+ "1. Scroll down to view results. \n",
+ "\n",
+ "## Notes\n",
+ "\n",
+ "1. For more information, see [Introduction](Introduction.ipynb)\n"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "367a698b29e22bd7"
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "## 1. Prepare the Environment"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "193a4e6a78fd5bd7"
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 1.1. 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": "f38b2711726e5859"
+ },
+ {
+ "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": "7a6e28cfae1a7b46",
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 1.2. Set Generic Perturbation Parameters"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "11db992e02891067"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "# Set whether to preserve geodesic distance and scale the cell accordingly to match PBC\n",
+ "PRESERVE_GEODESIC_DISTANCE = True\n",
+ "\n",
+ "# Set the supercell matrix to apply to original material\n",
+ "SUPERCELL_MATRIX = [[30, 0, 0], [0, 30, 0], [0, 0, 1]]\n",
+ "\n",
+ "# Set whether to use Cartesian coordinates for the perturbation function\n",
+ "USE_CARTESIAN_COORDINATES = False"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "a40d7b697c413113",
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 1.3. Define Custom Perturbation Function\n",
+ "Provide a [SymPy](https://docs.sympy.org/latest/tutorials/intro-tutorial/intro.html) expression for the perturbation function. The expression should be a function of `x`, `y` and `z` variables."
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "e6a19c741406eafe"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "import sympy as sp\n",
+ "\n",
+ "# Variables for the perturbation function (for SymPy)\n",
+ "variable_names = [\"x\", \"y\", \"z\"]\n",
+ "x, y, z = sp.symbols(variable_names)\n",
+ "\n",
+ "# Set the parameters for your perturbation function\n",
+ "AMPLITUDE = 0.05\n",
+ "WAVELENGTH = 1.0\n",
+ "PHASE = 0.0\n",
+ "\n",
+ "# Define the perturbation function\n",
+ "custom_sympy_function = AMPLITUDE * sp.sin(2 * sp.pi * x / WAVELENGTH + PHASE) * sp.sin(\n",
+ " 2 * sp.pi * y / WAVELENGTH)"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "203911c2413c7447"
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 1.4. Get input materials\n",
+ "Materials are loaded with `get_materials()`."
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "edf02101e27a2742"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "from utils.jupyterlite import get_materials\n",
+ "\n",
+ "materials = get_materials(globals())"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "e0c53233ce728cc1",
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 1.5. Create and preview Supercell"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "cf29b7f6fe114d8f"
+ },
+ {
+ "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 = materials[0]\n",
+ "supercell = create_supercell(unit_cell, supercell_matrix=SUPERCELL_MATRIX)\n",
+ "visualize(supercell, repetitions=[1, 1, 1], rotation=\"0x\")"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "897ba7aa4e402d24",
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "## 2. Create a target material\n",
+ "### 2.1. Set custom perturbation parameters\n"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "6d4adf0d580e0340"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "from mat3ra.made.tools.build.perturbation import CellMatchingDistancePreservingSlabPerturbationBuilder, \\\n",
+ " PerturbationConfiguration, SlabPerturbationBuilder\n",
+ "from mat3ra.made.tools.utils.perturbation import PerturbationFunctionHolder\n",
+ "\n",
+ "custom_perturbation_function = PerturbationFunctionHolder(function=custom_sympy_function,\n",
+ " variables=variable_names)\n",
+ "configuration_custom = PerturbationConfiguration(\n",
+ " material=supercell,\n",
+ " perturbation_function_holder=custom_perturbation_function,\n",
+ " use_cartesian_coordinates=USE_CARTESIAN_COORDINATES)\n",
+ "\n",
+ "if PRESERVE_GEODESIC_DISTANCE:\n",
+ " builder = CellMatchingDistancePreservingSlabPerturbationBuilder()\n",
+ "else:\n",
+ " builder = SlabPerturbationBuilder()"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "8d90932312c418ee",
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 2.2. Apply perturbation to the material"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "7695d5d1df6be2e3"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "from mat3ra.made.tools.build.perturbation import create_perturbation\n",
+ "\n",
+ "material_with_custom_perturbation = create_perturbation(configuration_custom, builder)"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "69ccc90b8c5c1191",
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "### 3. Visualize the Material"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "10e7ca8950839991"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "visualize([\n",
+ " {\"material\": material_with_custom_perturbation, \"title\": f\"Material with custom perturbation\"},\n",
+ " {\"material\": material_with_custom_perturbation, \"title\": f\"Material with custom perturbation\", \"rotation\": \"-90x\"}\n",
+ "])"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "cbfe0878a16f6c83",
+ "execution_count": null
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "## 4. Pass data to the outside runtime"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "9e0b241366592109"
+ },
+ {
+ "cell_type": "code",
+ "outputs": [],
+ "source": [
+ "from utils.jupyterlite import set_materials\n",
+ "\n",
+ "set_materials(material_with_custom_perturbation)"
+ ],
+ "metadata": {
+ "collapsed": false
+ },
+ "id": "29dfa0a329cca2fa",
+ "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
+}