Skip to content

Commit 2ba468e

Browse files
authored
Merge pull request #171 from Exabyte-io/feature/SOF-7499
feature/SOF-7499 update: two perturbation notebooks
2 parents dae6f3f + 6789f88 commit 2ba468e

File tree

3 files changed

+352
-108
lines changed

3 files changed

+352
-108
lines changed

other/materials_designer/Introduction.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
"## 5. Perturbations.\n",
7979
"\n",
8080
"### 5.1. Slab Perturbations\n",
81-
"#### [5.1.1. Perturbation using sine wave, custom planar (XY) functions](create_perturbation.ipynb)\n",
81+
"#### [5.1.1. Perturbation using sine wave](create_perturbation.ipynb)\n",
82+
"#### [5.1.2. Perturbation using custom function](create_perturbation_custom.ipynb)\n",
8283
"\n",
8384
"\n",
8485
"## 6. Other.\n",

other/materials_designer/create_perturbation.ipynb

Lines changed: 33 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,16 @@
55
"source": [
66
"# Create a Perturbation in a Material\n",
77
"\n",
8-
"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",
8+
"Create a perturbation in a material with a specified smooth function (SineWave by default)\n",
99
"\n",
1010
"<h2 style=\"color:green\">Usage</h2>\n",
1111
"\n",
1212
"1. Make sure to select Input Materials (in the outer runtime) before running the notebook.\n",
1313
"1. Set notebook parameters in cell 1.1. below (or use the default values).\n",
14-
"1. Set perturbation parameters in cell 2.1. (or use default).\n",
1514
"1. Click “Run” > “Run All” to run all cells. \n",
1615
"1. Wait for the run to complete (depending on the parameters can take a few min). \n",
1716
"1. Scroll down to view results. \n",
1817
"\n",
19-
"## Summary\n",
20-
"1. Prepare the Environment: Set up the notebook and install packages, preview the input materials\n",
21-
"1. Create the Perturbation: Add a smooth perturbation to the material\n",
22-
"2. Visualize the Perturbed Material\n",
23-
"\n",
2418
"## Notes\n",
2519
"\n",
2620
"1. For more information, see [Introduction](Introduction.ipynb)\n"
@@ -34,7 +28,7 @@
3428
"cell_type": "markdown",
3529
"source": [
3630
"## 1. Prepare the Environment\n",
37-
"### 1.1. Set up supercell parameters "
31+
"### 1.1. Set up perturbation parameters"
3832
],
3933
"metadata": {
4034
"collapsed": false
@@ -45,7 +39,17 @@
4539
"cell_type": "code",
4640
"outputs": [],
4741
"source": [
48-
"SUPERCELL_MATRIX = [[30, 0, 0], [0, 30, 0], [0, 0, 1]] "
42+
"# Sine wave perturbation parameters\n",
43+
"AMPLITUDE = 0.5\n",
44+
"WAVELENGTH = 1.0\n",
45+
"PHASE = 0.0\n",
46+
"AXIS = \"y\"\n",
47+
"\n",
48+
"USE_CARTESIAN_COORDINATES = False\n",
49+
"\n",
50+
"SUPERCELL_MATRIX = [[30, 0, 0], [0, 30, 0], [0, 0, 1]]\n",
51+
"\n",
52+
"PRESERVE_GEODESIC_DISTANCE = False"
4953
],
5054
"metadata": {
5155
"collapsed": false
@@ -72,8 +76,10 @@
7276
"\n",
7377
"if sys.platform == \"emscripten\":\n",
7478
" import micropip\n",
79+
"\n",
7580
" await micropip.install('mat3ra-api-examples', deps=False)\n",
7681
" from utils.jupyterlite import install_packages\n",
82+
"\n",
7783
" await install_packages(\"\")"
7884
],
7985
"metadata": {
@@ -98,6 +104,7 @@
98104
"outputs": [],
99105
"source": [
100106
"from utils.jupyterlite import get_materials\n",
107+
"\n",
101108
"materials = get_materials(globals())"
102109
],
103110
"metadata": {
@@ -149,23 +156,24 @@
149156
"cell_type": "code",
150157
"outputs": [],
151158
"source": [
152-
"from mat3ra.made.tools.build.perturbation import PerturbationConfiguration, SlabPerturbationBuilder\n",
159+
"from mat3ra.made.tools.build.perturbation import PerturbationConfiguration, SlabPerturbationBuilder, CellMatchingDistancePreservingSlabPerturbationBuilder\n",
153160
"from mat3ra.made.tools.utils.perturbation import SineWavePerturbationFunctionHolder\n",
154161
"\n",
155-
"amplitude = 0.05\n",
156-
"wavelength = 1\n",
157-
"phase = 0\n",
158-
"axis = \"y\"\n",
159-
"perturbation_function = SineWavePerturbationFunctionHolder(amplitude=amplitude, \n",
160-
" wavelength=wavelength, \n",
161-
" phase=phase,\n",
162-
" axis=axis)\n",
162+
"perturbation_function = SineWavePerturbationFunctionHolder(\n",
163+
" amplitude=AMPLITUDE,\n",
164+
" wavelength=WAVELENGTH,\n",
165+
" phase=PHASE,\n",
166+
" axis=AXIS)\n",
163167
"\n",
164-
"configuration = PerturbationConfiguration(material=supercell, \n",
165-
" perturbation_function_holder=perturbation_function,\n",
166-
" use_cartesian_coordinates=False)\n",
168+
"configuration = PerturbationConfiguration(\n",
169+
" material=supercell,\n",
170+
" perturbation_function_holder=perturbation_function,\n",
171+
" use_cartesian_coordinates=USE_CARTESIAN_COORDINATES)\n",
167172
"\n",
168-
"builder = SlabPerturbationBuilder()"
173+
"if PRESERVE_GEODESIC_DISTANCE:\n",
174+
" builder = CellMatchingDistancePreservingSlabPerturbationBuilder()\n",
175+
"else:\n",
176+
" builder = SlabPerturbationBuilder()"
169177
],
170178
"metadata": {
171179
"collapsed": false
@@ -200,7 +208,7 @@
200208
{
201209
"cell_type": "markdown",
202210
"source": [
203-
"### 2.3. Visualize the Material"
211+
"### 3. Visualize the Result"
204212
],
205213
"metadata": {
206214
"collapsed": false
@@ -216,96 +224,14 @@
216224
"visualize([{\"material\": supercell, \"title\": \"Original material\"},\n",
217225
" {\"material\": material_with_perturbation, \"title\": f\"Material with perturbation\"},\n",
218226
" {\"material\": material_with_perturbation, \"title\": f\"Material with perturbation\", \"rotation\": \"-90x\"},\n",
219-
"])"
227+
" ])"
220228
],
221229
"metadata": {
222230
"collapsed": false
223231
},
224232
"id": "1ee393a7f2ec3bc8",
225233
"execution_count": null
226234
},
227-
{
228-
"cell_type": "markdown",
229-
"source": [
230-
"## 3. Create a Custom Perturbation\n",
231-
"### 3.1. Set custom perturbation parameters\n",
232-
"Provide a SymPy expression for the perturbation function. The expression should be a function of `x`, `y` and `z` variables."
233-
],
234-
"metadata": {
235-
"collapsed": false
236-
},
237-
"id": "6d4adf0d580e0340"
238-
},
239-
{
240-
"cell_type": "code",
241-
"outputs": [],
242-
"source": [
243-
"import sympy as sp\n",
244-
"from mat3ra.made.tools.build.perturbation import CellMatchingDistancePreservingSlabPerturbationBuilder\n",
245-
"from mat3ra.made.tools.utils.perturbation import PerturbationFunctionHolder\n",
246-
"\n",
247-
"x,y = sp.symbols('x y')\n",
248-
"function = amplitude * sp.sin(2 * sp.pi * x / wavelength + phase) * sp.sin(2 * sp.pi * y / wavelength)\n",
249-
"\n",
250-
"custom_perturbation_function = PerturbationFunctionHolder(function=function, variables=[\"x\", \"y\"])\n",
251-
"configuration_custom = PerturbationConfiguration(material=supercell,\n",
252-
" perturbation_function_holder=custom_perturbation_function,\n",
253-
" use_cartesian_coordinates=False)\n",
254-
"distance_preserving_builder = CellMatchingDistancePreservingSlabPerturbationBuilder()"
255-
],
256-
"metadata": {
257-
"collapsed": false
258-
},
259-
"id": "8d90932312c418ee",
260-
"execution_count": null
261-
},
262-
{
263-
"cell_type": "markdown",
264-
"source": [
265-
"### 3.2. Apply perturbation to the material"
266-
],
267-
"metadata": {
268-
"collapsed": false
269-
},
270-
"id": "7695d5d1df6be2e3"
271-
},
272-
{
273-
"cell_type": "code",
274-
"outputs": [],
275-
"source": [
276-
"material_with_custom_perturbation = create_perturbation(configuration_custom, distance_preserving_builder)"
277-
],
278-
"metadata": {
279-
"collapsed": false
280-
},
281-
"id": "69ccc90b8c5c1191",
282-
"execution_count": null
283-
},
284-
{
285-
"cell_type": "markdown",
286-
"source": [
287-
"### 3.3. Visualize the Material"
288-
],
289-
"metadata": {
290-
"collapsed": false
291-
},
292-
"id": "10e7ca8950839991"
293-
},
294-
{
295-
"cell_type": "code",
296-
"outputs": [],
297-
"source": [
298-
"visualize([\n",
299-
" {\"material\": material_with_custom_perturbation, \"title\": f\"Material with custom perturbation\"},\n",
300-
" {\"material\": material_with_custom_perturbation, \"title\": f\"Material with custom perturbation\",\"rotation\": \"-90x\"}\n",
301-
"])"
302-
],
303-
"metadata": {
304-
"collapsed": false
305-
},
306-
"id": "cbfe0878a16f6c83",
307-
"execution_count": null
308-
},
309235
{
310236
"cell_type": "markdown",
311237
"source": [
@@ -322,7 +248,7 @@
322248
"source": [
323249
"from utils.jupyterlite import set_materials\n",
324250
"\n",
325-
"set_materials([material_with_perturbation, material_with_custom_perturbation])"
251+
"set_materials(material_with_perturbation)"
326252
],
327253
"metadata": {
328254
"collapsed": false

0 commit comments

Comments
 (0)