|
5 | 5 | "source": [ |
6 | 6 | "# Create a Perturbation in a Material\n", |
7 | 7 | "\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", |
9 | 9 | "\n", |
10 | 10 | "<h2 style=\"color:green\">Usage</h2>\n", |
11 | 11 | "\n", |
12 | 12 | "1. Make sure to select Input Materials (in the outer runtime) before running the notebook.\n", |
13 | 13 | "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", |
15 | 14 | "1. Click “Run” > “Run All” to run all cells. \n", |
16 | 15 | "1. Wait for the run to complete (depending on the parameters can take a few min). \n", |
17 | 16 | "1. Scroll down to view results. \n", |
18 | 17 | "\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", |
24 | 18 | "## Notes\n", |
25 | 19 | "\n", |
26 | 20 | "1. For more information, see [Introduction](Introduction.ipynb)\n" |
|
34 | 28 | "cell_type": "markdown", |
35 | 29 | "source": [ |
36 | 30 | "## 1. Prepare the Environment\n", |
37 | | - "### 1.1. Set up supercell parameters " |
| 31 | + "### 1.1. Set up perturbation parameters" |
38 | 32 | ], |
39 | 33 | "metadata": { |
40 | 34 | "collapsed": false |
|
45 | 39 | "cell_type": "code", |
46 | 40 | "outputs": [], |
47 | 41 | "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" |
49 | 53 | ], |
50 | 54 | "metadata": { |
51 | 55 | "collapsed": false |
|
72 | 76 | "\n", |
73 | 77 | "if sys.platform == \"emscripten\":\n", |
74 | 78 | " import micropip\n", |
| 79 | + "\n", |
75 | 80 | " await micropip.install('mat3ra-api-examples', deps=False)\n", |
76 | 81 | " from utils.jupyterlite import install_packages\n", |
| 82 | + "\n", |
77 | 83 | " await install_packages(\"\")" |
78 | 84 | ], |
79 | 85 | "metadata": { |
|
98 | 104 | "outputs": [], |
99 | 105 | "source": [ |
100 | 106 | "from utils.jupyterlite import get_materials\n", |
| 107 | + "\n", |
101 | 108 | "materials = get_materials(globals())" |
102 | 109 | ], |
103 | 110 | "metadata": { |
|
149 | 156 | "cell_type": "code", |
150 | 157 | "outputs": [], |
151 | 158 | "source": [ |
152 | | - "from mat3ra.made.tools.build.perturbation import PerturbationConfiguration, SlabPerturbationBuilder\n", |
| 159 | + "from mat3ra.made.tools.build.perturbation import PerturbationConfiguration, SlabPerturbationBuilder, CellMatchingDistancePreservingSlabPerturbationBuilder\n", |
153 | 160 | "from mat3ra.made.tools.utils.perturbation import SineWavePerturbationFunctionHolder\n", |
154 | 161 | "\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", |
163 | 167 | "\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", |
167 | 172 | "\n", |
168 | | - "builder = SlabPerturbationBuilder()" |
| 173 | + "if PRESERVE_GEODESIC_DISTANCE:\n", |
| 174 | + " builder = CellMatchingDistancePreservingSlabPerturbationBuilder()\n", |
| 175 | + "else:\n", |
| 176 | + " builder = SlabPerturbationBuilder()" |
169 | 177 | ], |
170 | 178 | "metadata": { |
171 | 179 | "collapsed": false |
|
200 | 208 | { |
201 | 209 | "cell_type": "markdown", |
202 | 210 | "source": [ |
203 | | - "### 2.3. Visualize the Material" |
| 211 | + "### 3. Visualize the Result" |
204 | 212 | ], |
205 | 213 | "metadata": { |
206 | 214 | "collapsed": false |
|
216 | 224 | "visualize([{\"material\": supercell, \"title\": \"Original material\"},\n", |
217 | 225 | " {\"material\": material_with_perturbation, \"title\": f\"Material with perturbation\"},\n", |
218 | 226 | " {\"material\": material_with_perturbation, \"title\": f\"Material with perturbation\", \"rotation\": \"-90x\"},\n", |
219 | | - "])" |
| 227 | + " ])" |
220 | 228 | ], |
221 | 229 | "metadata": { |
222 | 230 | "collapsed": false |
223 | 231 | }, |
224 | 232 | "id": "1ee393a7f2ec3bc8", |
225 | 233 | "execution_count": null |
226 | 234 | }, |
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 | | - }, |
309 | 235 | { |
310 | 236 | "cell_type": "markdown", |
311 | 237 | "source": [ |
|
322 | 248 | "source": [ |
323 | 249 | "from utils.jupyterlite import set_materials\n", |
324 | 250 | "\n", |
325 | | - "set_materials([material_with_perturbation, material_with_custom_perturbation])" |
| 251 | + "set_materials(material_with_perturbation)" |
326 | 252 | ], |
327 | 253 | "metadata": { |
328 | 254 | "collapsed": false |
|
0 commit comments