Skip to content

Create a Slab with a Custom-Shape Cutout

1. Introduction

Create a slab from a bulk material with a cutout of any shape, given as a condition on the coordinates. The default cutout is an etching pattern: two side walls, two parallel channels at the top and a deeper central cavity.

2. Open the notebook

In JupyterLite, the notebook is made/create_cutout_custom_shape.ipynb, entry 1.4.6 "Custom Shape Cutout. Create a slab with a custom shape cutout" of made/Introduction.ipynb.

3. Set the parameters

The notebook takes the first of the input materials.

Cell 1.2 holds the parameters:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Slab parameters
MILLER_INDICES = (0, 0, 1)
THICKNESS = 6  # unit cell layers
VACUUM = 10.0  # Angstrom
XY_SUPERCELL_MATRIX = [[10, 0], [0, 10]]

# Custom shape parameters in crystal units of the slab
LEFT_WALL_POSITION = 0.2
RIGHT_WALL_POSITION = 0.8
LEFT_CHANNEL_POSITION = 0.25
RIGHT_CHANNEL_POSITION = 0.75
CHANNEL_TOP_Z = 0.8
CAVITY_TOP_Z = 0.5

NAME = "Custom Shape - Etching Pattern"

THICKNESS is the thickness of the slab in unit cell layers. The overview explains MILLER_INDICES, VACUUM and XY_SUPERCELL_MATRIX.

LEFT_WALL_POSITION and RIGHT_WALL_POSITION place the walls along x, LEFT_CHANNEL_POSITION and RIGHT_CHANNEL_POSITION the channels along y, and CHANNEL_TOP_Z and CAVITY_TOP_Z their depths along z, all in crystal coordinates of the slab. NAME is the name of the resulting material.

Cell 1.3 holds the condition on the coordinates:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from typing import List

from mat3ra.made.tools.helpers import CoordinateCondition


# Example of a custom coordinate condition. Adapt coordinate conditions to your needs.
class CustomCoordinateCondition(CoordinateCondition):
    """
    Defines an etched pattern structure with side walls, channels, and a central cavity.
    All dimensions are specified as fractions of the total size (0.0 to 1.0).
    """
    left_wall_position: float = 0.2
    right_wall_position: float = 0.8
    left_channel_position: float = 0.25
    right_channel_position: float = 0.75
    channel_top_z: float = 0.8
    cavity_top_z: float = 0.5

    def condition(self, coordinate: List[float]) -> bool:
        """
        Determines which atoms to filter based on the coordinate.
        Returns True for positions where atoms should be removed.

        The structure consists of:
        1. Side walls: Two vertical walls running along the y-axis
        2. Channels: Two trenches at the top running along the x-axis
        3. Cavity: A deeper central region between the channels
        """
        x, y, z = coordinate

        # Define the structural elements
        is_in_left_wall = x <= self.left_wall_position
        is_in_right_wall = x >= self.right_wall_position

        is_in_left_channel = y <= self.left_channel_position
        is_in_right_channel = y >= self.right_channel_position

        is_in_channel = (
                z < self.channel_top_z and
                (is_in_left_channel or is_in_right_channel)
        )

        is_below_cavity = (
                z < self.cavity_top_z and  # Cavity depth
                self.left_wall_position < x < self.right_wall_position and  # Between walls
                not is_in_left_channel and not is_in_right_channel  # Between channels
        )

        return (
                is_in_left_wall or
                is_in_right_wall or
                is_in_channel or
                is_below_cavity
        )


condition = CustomCoordinateCondition(
    left_wall_position=LEFT_WALL_POSITION,
    right_wall_position=RIGHT_WALL_POSITION,
    left_channel_position=LEFT_CHANNEL_POSITION,
    right_channel_position=RIGHT_CHANNEL_POSITION,
    channel_top_z=CHANNEL_TOP_Z,
    cavity_top_z=CAVITY_TOP_Z,
).condition

CustomCoordinateCondition.condition defines the pattern from these positions; another pattern is set by editing the method.

4. Run and read the result

Run the notebook with Run > Run All. The notebook shows the result from the top, from the side and at an angle, and passes it back with set_materials, as in Structure Notebooks.

5. Interactive JupyterLite notebook

The interactive JupyterLite notebook for creating a custom-shape cutout can be accessed below.