@mat3ra/made 2024.10.24-0 → 2024.10.29-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mat3ra/made",
3
- "version": "2024.10.24-0",
3
+ "version": "2024.10.29-0",
4
4
  "description": "MAterials DEsign library",
5
5
  "scripts": {
6
6
  "lint": "eslint --cache src/js tests/js && prettier --write src/js tests/js",
@@ -1,4 +1,4 @@
1
- from typing import Callable, List, Literal, Optional, Union
1
+ from typing import Callable, List, Literal, Optional, Tuple, Union
2
2
 
3
3
  import numpy as np
4
4
  from mat3ra.made.material import Material
@@ -209,6 +209,32 @@ def filter_by_layers(
209
209
  return filter_by_condition_on_coordinates(material, condition, invert_selection=invert_selection)
210
210
 
211
211
 
212
+ def get_default_min_max(material: Material, use_cartesian_coordinates: bool) -> Tuple[List[float], List[float]]:
213
+ """
214
+ Get default min and max coordinates for the material based on the coordinate system (crystal or cartesian).
215
+
216
+ Args:
217
+ material (Material): The material object.
218
+ use_cartesian_coordinates (bool): Whether to use Cartesian coordinates.
219
+
220
+ Returns:
221
+ Tuple[List[float], List[float]]: Default min and max coordinates.
222
+ """
223
+ axes: List[Literal["x", "y", "z"]] = ["x", "y", "z"]
224
+ min_coords = []
225
+ max_coords = []
226
+ for axis in axes:
227
+ min_val = get_atomic_coordinates_extremum(
228
+ material, "min", axis, use_cartesian_coordinates=use_cartesian_coordinates
229
+ )
230
+ max_val = get_atomic_coordinates_extremum(
231
+ material, "max", axis, use_cartesian_coordinates=use_cartesian_coordinates
232
+ )
233
+ min_coords.append(min_val)
234
+ max_coords.append(max_val)
235
+ return min_coords, max_coords
236
+
237
+
212
238
  def filter_by_sphere(
213
239
  material: Material,
214
240
  center_coordinate: List[float] = [0, 0, 0],
@@ -270,9 +296,9 @@ def filter_by_circle_projection(
270
296
 
271
297
  def filter_by_cylinder(
272
298
  material: Material,
273
- center_position: List[float] = [0.5, 0.5],
274
- min_z: float = 0,
275
- max_z: float = 1,
299
+ center_position: Optional[List[float]] = None,
300
+ min_z: Optional[float] = None,
301
+ max_z: Optional[float] = None,
276
302
  radius: float = 0.25,
277
303
  use_cartesian_coordinates: bool = False,
278
304
  invert_selection: bool = False,
@@ -282,16 +308,27 @@ def filter_by_cylinder(
282
308
 
283
309
  Args:
284
310
  material (Material): The material object to filter.
285
- center_position (List[float]): The coordinates of the center position.
311
+ center_position (List[float], optional): The center position of the cylinder. Defaults to material's center.
312
+ min_z (float, optional): Lower limit of z-coordinate. Defaults to material's min z.
313
+ max_z (float, optional): Upper limit of z-coordinate. Defaults to material's max z.
286
314
  radius (float): The radius of the cylinder.
287
- min_z (float): Lower limit of z-coordinate.
288
- max_z (float): Upper limit of z-coordinate.
289
- use_cartesian_coordinates (bool): Whether to use cartesian coordinates
315
+ use_cartesian_coordinates (bool): Whether to use cartesian coordinates.
290
316
  invert_selection (bool): Whether to invert the selection.
291
317
 
292
318
  Returns:
293
319
  Material: The filtered material object.
294
320
  """
321
+ if center_position is None:
322
+ default_min, default_max = get_default_min_max(material, use_cartesian_coordinates)
323
+ center_position = [(min_c + max_c) / 2 for min_c, max_c in zip(default_min, default_max)]
324
+
325
+ if min_z is None or max_z is None:
326
+ min_z = get_atomic_coordinates_extremum(
327
+ material, "min", "z", use_cartesian_coordinates=use_cartesian_coordinates
328
+ )
329
+ max_z = get_atomic_coordinates_extremum(
330
+ material, "max", "z", use_cartesian_coordinates=use_cartesian_coordinates
331
+ )
295
332
 
296
333
  def condition(coordinate):
297
334
  return is_coordinate_in_cylinder(coordinate, center_position, radius, min_z, max_z)
@@ -321,8 +358,10 @@ def filter_by_rectangle_projection(
321
358
  Returns:
322
359
  Material: The filtered material object.
323
360
  """
324
- min_coordinate = min_coordinate[:2] + [0]
325
- max_coordinate = max_coordinate[:2] + [1]
361
+ min_z = get_atomic_coordinates_extremum(material, "min", "z", use_cartesian_coordinates=use_cartesian_coordinates)
362
+ max_z = get_atomic_coordinates_extremum(material, "max", "z", use_cartesian_coordinates=use_cartesian_coordinates)
363
+ min_coordinate = min_coordinate[:2] + [min_z]
364
+ max_coordinate = max_coordinate[:2] + [max_z]
326
365
 
327
366
  def condition(coordinate):
328
367
  return is_coordinate_in_box(coordinate, min_coordinate, max_coordinate)
@@ -334,14 +373,28 @@ def filter_by_rectangle_projection(
334
373
 
335
374
  def filter_by_box(
336
375
  material: Material,
337
- min_coordinate: List[float] = [0.0, 0.0, 0.0],
338
- max_coordinate: List[float] = [1.0, 1.0, 1.0],
376
+ min_coordinate: Optional[List[float]] = None,
377
+ max_coordinate: Optional[List[float]] = None,
339
378
  use_cartesian_coordinates: bool = False,
340
379
  invert_selection: bool = False,
341
380
  ) -> Material:
342
381
  """
343
382
  Get material with atoms that are within or outside an XYZ box.
383
+
384
+ Args:
385
+ material (Material): The material to filter.
386
+ min_coordinate (List[float], optional): The minimum coordinate of the box. Defaults to material's min.
387
+ max_coordinate (List[float], optional): The maximum coordinate of the box. Defaults to material's max.
388
+ use_cartesian_coordinates (bool): Whether to use cartesian coordinates.
389
+ invert_selection (bool): Whether to invert the selection.
390
+
391
+ Returns:
392
+ Material: The filtered material object.
344
393
  """
394
+ if min_coordinate is None or max_coordinate is None:
395
+ default_min, default_max = get_default_min_max(material, use_cartesian_coordinates)
396
+ min_coordinate = min_coordinate if min_coordinate is not None else default_min
397
+ max_coordinate = max_coordinate if max_coordinate is not None else default_max
345
398
 
346
399
  def condition(coordinate):
347
400
  return is_coordinate_in_box(coordinate, min_coordinate, max_coordinate)
@@ -353,30 +406,44 @@ def filter_by_box(
353
406
 
354
407
  def filter_by_triangle_projection(
355
408
  material: Material,
356
- coordinate_1: List[float] = [0, 0],
357
- coordinate_2: List[float] = [0, 1],
358
- coordinate_3: List[float] = [1, 0],
359
- min_z: float = 0,
360
- max_z: float = 1,
409
+ coordinate_1: Optional[List[float]] = None,
410
+ coordinate_2: Optional[List[float]] = None,
411
+ coordinate_3: Optional[List[float]] = None,
412
+ min_z: Optional[float] = None,
413
+ max_z: Optional[float] = None,
361
414
  use_cartesian_coordinates: bool = False,
362
415
  invert_selection: bool = False,
363
416
  ) -> Material:
364
417
  """
365
- Get material with atoms that are within or outside a prism formed by triangle projection.
418
+ Get material with atoms that are within or outside a triangular prism.
366
419
 
367
420
  Args:
368
421
  material (Material): The material object to filter.
369
- coordinate_1 (List[float]): The coordinate of the first vertex.
370
- coordinate_2 (List[float]): The coordinate of the second vertex.
371
- coordinate_3 (List[float]): The coordinate of the third vertex.
372
- min_z (float): Lower limit of z-coordinate.
373
- max_z (float): Upper limit of z-coordinate.
374
- use_cartesian_coordinates (bool): Whether to use cartesian coordinates
422
+ coordinate_1 (List[float], optional): First vertex of the triangle. Defaults to material's corner.
423
+ coordinate_2 (List[float], optional): Second vertex of the triangle. Defaults to material's corner.
424
+ coordinate_3 (List[float], optional): Third vertex of the triangle. Defaults to material's corner.
425
+ min_z (float, optional): Lower z-limit. Defaults to material's min z.
426
+ max_z (float, optional): Upper z-limit. Defaults to material's max z.
427
+ use_cartesian_coordinates (bool): Whether to use cartesian coordinates.
375
428
  invert_selection (bool): Whether to invert the selection.
376
429
 
377
430
  Returns:
378
431
  Material: The filtered material object.
379
432
  """
433
+ if coordinate_1 is None or coordinate_2 is None or coordinate_3 is None:
434
+ default_min, default_max = get_default_min_max(material, use_cartesian_coordinates)
435
+ coordinate_1 = coordinate_1 if coordinate_1 is not None else [default_min[0], default_min[1]]
436
+ coordinate_2 = coordinate_2 if coordinate_2 is not None else [default_min[0], default_max[1]]
437
+ coordinate_3 = coordinate_3 if coordinate_3 is not None else [default_max[0], default_min[1]]
438
+
439
+ if min_z is None:
440
+ min_z = get_atomic_coordinates_extremum(
441
+ material, "min", "z", use_cartesian_coordinates=use_cartesian_coordinates
442
+ )
443
+ if max_z is None:
444
+ max_z = get_atomic_coordinates_extremum(
445
+ material, "max", "z", use_cartesian_coordinates=use_cartesian_coordinates
446
+ )
380
447
 
381
448
  def condition(coordinate):
382
449
  return is_coordinate_in_triangular_prism(coordinate, coordinate_1, coordinate_2, coordinate_3, min_z, max_z)