Skip to content

Commit 5b07e2d

Browse files
authored
Merge pull request #205 from Exabyte-io/fix/SOF-7353
fix/SOF 7353
2 parents a3ef4be + 10e6d76 commit 5b07e2d

8 files changed

+156
-181
lines changed

config.yml

-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ notebooks:
6767
packages_pyodide:
6868
- mat3ra-esse
6969
- mat3ra-made
70-
- name: create_cluster_custom_shape.ipynb
71-
packages_common:
72-
- icosphere
73-
packages_python:
74-
packages_pyodide:
7570
- name: specific_examples
7671
packages_common:
7772
- mat3ra-standata

other/materials_designer/create_cluster_custom_shape.ipynb

+39-41
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
},
4949
{
5050
"cell_type": "code",
51-
"outputs": [],
5251
"source": [
5352
"import sys\n",
5453
"\n",
@@ -58,12 +57,13 @@
5857
" await micropip.install('mat3ra-api-examples', deps=False)\n",
5958
" from utils.jupyterlite import install_packages\n",
6059
"\n",
61-
" await install_packages(\"create_cluster_custom_shape.ipynb\")"
60+
" await install_packages(\"\")"
6261
],
6362
"metadata": {
6463
"collapsed": false
6564
},
6665
"id": "d9e6be14343d00a1",
66+
"outputs": [],
6767
"execution_count": null
6868
},
6969
{
@@ -78,7 +78,6 @@
7878
},
7979
{
8080
"cell_type": "code",
81-
"outputs": [],
8281
"source": [
8382
"RADIUS = 0.3 # in crystal units\n",
8483
"VACUUM = 10.0 # in Angstroms on each side\n",
@@ -90,6 +89,7 @@
9089
"collapsed": false
9190
},
9291
"id": "9d8b1890b34d850a",
92+
"outputs": [],
9393
"execution_count": null
9494
},
9595
{
@@ -104,41 +104,42 @@
104104
},
105105
{
106106
"cell_type": "code",
107-
"outputs": [],
108107
"source": [
109108
"import numpy as np\n",
109+
"from scipy.spatial import ConvexHull\n",
110110
"from typing import List\n",
111-
"from icosphere import icosphere\n",
112111
"from mat3ra.made.tools.utils.coordinate import CoordinateCondition\n",
113112
"\n",
114113
"\n",
115-
"# Example of a custom coordinate condition (icosahedron). Adapt coordinate conditions to your needs.\n",
116114
"class CustomCoordinateCondition(CoordinateCondition):\n",
117-
" \"\"\"Creates an icosahedron shape using the icosphere module\"\"\"\n",
115+
" \"\"\"Creates a regular polyhedron shape using SciPy's ConvexHull\"\"\"\n",
118116
" radius: float = 1\n",
119-
" frequency: int = 1\n",
120-
" vertices: List[List[float]] = icosphere(1)[0]\n",
121-
" faces: List[List[int]] = icosphere(1)[1]\n",
122117
" center: List[float] = [0.5, 0.5, 0.5]\n",
123118
"\n",
119+
" @property\n",
120+
" def _hull_planes(self):\n",
121+
" t = (1 + np.sqrt(5)) / 2\n",
122+
" vertices = np.array([\n",
123+
" [-1, t, 0], [1, t, 0], [-1, -t, 0], [1, -t, 0],\n",
124+
" [0, -1, t], [0, 1, t], [0, -1, -t], [0, 1, -t],\n",
125+
" [t, 0, -1], [t, 0, 1], [-t, 0, -1], [-t, 0, 1]\n",
126+
" ]) * self.radius / np.sqrt(1 + t*t)\n",
127+
" return ConvexHull(vertices).equations\n",
128+
"\n",
124129
" def condition(self, coordinate: List[float]) -> bool:\n",
125-
" \"\"\"Returns True if point is inside icosahedron\"\"\"\n",
126-
" coordinate = np.array(coordinate) - self.center\n",
127-
" for face in self.faces:\n",
128-
" a, b, c = face\n",
129-
" normal = np.cross(self.vertices[b] - self.vertices[a], self.vertices[c] - self.vertices[a])\n",
130-
" normal = normal / np.linalg.norm(normal)\n",
131-
" if np.dot(normal, coordinate) > self.radius:\n",
132-
" return False\n",
133-
" return True\n",
134-
" \n",
130+
" \"\"\"Returns True if point is inside the polyhedron\"\"\"\n",
131+
" point = np.array(coordinate) - self.center\n",
132+
" return all(np.dot(plane[:3], point) + plane[3] <= 0\n",
133+
" for plane in self._hull_planes)\n",
134+
"\n",
135135
" \n",
136136
"condition = CustomCoordinateCondition(radius=RADIUS).condition"
137137
],
138138
"metadata": {
139139
"collapsed": false
140140
},
141141
"id": "8e382d5ab459e2d",
142+
"outputs": [],
142143
"execution_count": null
143144
},
144145
{
@@ -153,7 +154,6 @@
153154
},
154155
{
155156
"cell_type": "code",
156-
"outputs": [],
157157
"source": [
158158
"from utils.jupyterlite import get_materials\n",
159159
"\n",
@@ -163,6 +163,7 @@
163163
"collapsed": false
164164
},
165165
"id": "be38fdda1984c654",
166+
"outputs": [],
166167
"execution_count": null
167168
},
168169
{
@@ -178,24 +179,21 @@
178179
},
179180
{
180181
"cell_type": "code",
181-
"outputs": [],
182182
"source": [
183-
"from mat3ra.made.tools.build.nanoparticle import ASEBasedNanoparticleConfiguration\n",
184-
"from mat3ra.made.tools.build.nanoparticle.enums import ASENanoparticleShapesEnum\n",
185-
"\n",
183+
"from mat3ra.made.tools.build.nanoparticle import SlabBasedNanoparticleConfiguration\n",
186184
"\n",
187-
"config = ASEBasedNanoparticleConfiguration(\n",
185+
"config = SlabBasedNanoparticleConfiguration(\n",
188186
" material=materials[0],\n",
187+
" condition_builder=condition,\n",
189188
" supercell_size=SUPERCELL_SIZE,\n",
190-
" vacuum=VACUUM,\n",
191-
" z_orientation=Z_ORIENTATION,\n",
192-
" coordinate_condition=condition\n",
193-
")\n"
189+
")"
194190
],
195191
"metadata": {
196192
"collapsed": false
197193
},
198-
"id": "8fbe260fa14db47a"
194+
"id": "8fbe260fa14db47a",
195+
"outputs": [],
196+
"execution_count": null
199197
},
200198
{
201199
"cell_type": "markdown",
@@ -209,14 +207,16 @@
209207
},
210208
{
211209
"cell_type": "code",
212-
"outputs": [],
213210
"source": [
214-
"from mat3ra.made.tools.build.nanoparticle import ASEBasedNanoparticleBuilder"
211+
"from mat3ra.made.tools.build.nanoparticle import create_nanoparticle\n",
212+
"\n",
213+
"cluster = create_nanoparticle(config)"
215214
],
216215
"metadata": {
217216
"collapsed": false
218217
},
219218
"id": "a990fa35742d7269",
219+
"outputs": [],
220220
"execution_count": null
221221
},
222222
{
@@ -231,7 +231,6 @@
231231
},
232232
{
233233
"cell_type": "code",
234-
"outputs": [],
235234
"source": [
236235
"from mat3ra.made.lattice import Lattice\n",
237236
"\n",
@@ -245,6 +244,7 @@
245244
"collapsed": false
246245
},
247246
"id": "4f78c4743b370c3b",
247+
"outputs": [],
248248
"execution_count": null
249249
},
250250
{
@@ -259,18 +259,16 @@
259259
},
260260
{
261261
"cell_type": "code",
262-
"outputs": [],
263262
"source": [
264-
"visualize([{\"material\": slab, \"title\": \"Original material\"},\n",
265-
" {\"material\": cluster, \"title\": f\"Cluster\"}])\n",
266-
"\n",
267-
"visualize([{\"material\": slab, \"title\": \"Original material\"},\n",
268-
" {\"material\": cluster, \"title\": f\"Cluster\"}], rotation=\"-90x\")"
263+
"from utils.visualize import visualize_materials as visualize\n",
264+
"visualize([{\"material\": cluster, \"title\": f\"Cluster\"},\n",
265+
" {\"material\": cluster, \"title\": f\"Cluster\", \"rotation\": \"-90x\"}])"
269266
],
270267
"metadata": {
271268
"collapsed": false
272269
},
273270
"id": "509b18661a069e42",
271+
"outputs": [],
274272
"execution_count": null
275273
},
276274
{
@@ -285,7 +283,6 @@
285283
},
286284
{
287285
"cell_type": "code",
288-
"outputs": [],
289286
"source": [
290287
"from utils.jupyterlite import set_materials\n",
291288
"\n",
@@ -296,6 +293,7 @@
296293
"collapsed": false
297294
},
298295
"id": "61daa5afcbc078a9",
296+
"outputs": [],
299297
"execution_count": null
300298
}
301299
],

other/materials_designer/create_grain_boundary_film.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
" await micropip.install('mat3ra-api-examples', deps=False)\n",
105105
" from utils.jupyterlite import install_packages\n",
106106
"\n",
107-
" await install_packages(\"\", \"../../config.yml\")"
107+
" await install_packages(\"\")"
108108
],
109109
"metadata": {
110110
"collapsed": false

other/materials_designer/custom_transformation.ipynb

+11-8
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@
2323
},
2424
"outputs": [],
2525
"source": [
26-
"# Install packages for JupyterLite\n",
27-
"from mat3ra.utils.jupyterlite.packages import install_packages\n",
2826
"import sys\n",
2927
"\n",
3028
"if sys.platform == \"emscripten\":\n",
3129
" import micropip\n",
3230
"\n",
33-
" # Import the mat3ra api-examples package to allow for relative imports\n",
3431
" await micropip.install('mat3ra-api-examples', deps=False)\n",
32+
" from utils.jupyterlite import install_packages\n",
3533
"\n",
36-
"await install_packages(\"\")"
34+
" await install_packages(\"\")"
3735
]
3836
},
3937
{
@@ -58,7 +56,8 @@
5856
"metadata": {
5957
"collapsed": false
6058
},
61-
"id": "b2fa69b96b195d30"
59+
"id": "b2fa69b96b195d30",
60+
"execution_count": null
6261
},
6362
{
6463
"cell_type": "markdown",
@@ -75,12 +74,14 @@
7574
"outputs": [],
7675
"source": [
7776
"from utils.jupyterlite import get_materials\n",
77+
"\n",
7878
"materials = get_materials(globals())"
7979
],
8080
"metadata": {
8181
"collapsed": false
8282
},
83-
"id": "54e68de6c6cc3e03"
83+
"id": "54e68de6c6cc3e03",
84+
"execution_count": null
8485
},
8586
{
8687
"cell_type": "markdown",
@@ -101,7 +102,8 @@
101102
"metadata": {
102103
"collapsed": false
103104
},
104-
"id": "91069f5712a65dbb"
105+
"id": "91069f5712a65dbb",
106+
"execution_count": null
105107
},
106108
{
107109
"cell_type": "markdown",
@@ -126,7 +128,8 @@
126128
"metadata": {
127129
"collapsed": false
128130
},
129-
"id": "7973f7ee67bdc42a"
131+
"id": "7973f7ee67bdc42a",
132+
"execution_count": null
130133
}
131134
],
132135
"metadata": {

0 commit comments

Comments
 (0)