Skip to content

Commit

Permalink
Merge pull request #171 from Exabyte-io/feature/SOF-7499
Browse files Browse the repository at this point in the history
feature/SOF-7499 update: two perturbation notebooks
  • Loading branch information
VsevolodX authored Nov 28, 2024
2 parents dae6f3f + 6789f88 commit 2ba468e
Show file tree
Hide file tree
Showing 3 changed files with 352 additions and 108 deletions.
3 changes: 2 additions & 1 deletion other/materials_designer/Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
140 changes: 33 additions & 107 deletions other/materials_designer/create_perturbation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"<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. 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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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": {
Expand All @@ -98,6 +104,7 @@
"outputs": [],
"source": [
"from utils.jupyterlite import get_materials\n",
"\n",
"materials = get_materials(globals())"
],
"metadata": {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -200,7 +208,7 @@
{
"cell_type": "markdown",
"source": [
"### 2.3. Visualize the Material"
"### 3. Visualize the Result"
],
"metadata": {
"collapsed": false
Expand All @@ -216,96 +224,14 @@
"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
},
"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": [
Expand All @@ -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
Expand Down
Loading

0 comments on commit 2ba468e

Please sign in to comment.