Skip to content

Create an Island of Custom Shape on a Slab

1. Introduction

Create a slab with an island on its surface, within a shape given as a condition on the coordinates.

2. Open the notebook

In JupyterLite, the notebook is made/create_island_defect_custom.ipynb, entry 3.1.5 "Custom Shape Island Defect on a Slab" of made/Introduction.ipynb.

3. Set the parameters

Cell 1.2 holds the condition on the coordinates:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import numpy as np
from mat3ra.made.tools.helpers import CoordinateCondition

# Custom Coordinate Condition for a torus shape
class CustomCoordinateCondition(CoordinateCondition):
    center: List[float] = [0.5, 0.5, 0.0]
    major_radius: float = 0.5
    minor_radius: float = 0.1

    def condition(self, coordinate: List[float]) -> bool:
        coord = np.array(coordinate)
        # Calculate the distance from the center in the xy-plane
        xy_distance = np.linalg.norm(coord[:2] - self.center[:2])
        # Calculate the distance from the torus surface
        distance_to_torus = np.sqrt((xy_distance - self.major_radius) ** 2 + (coord[2] - self.center[2]) ** 2)
        return distance_to_torus <= self.minor_radius

CustomCoordinateCondition.condition returns whether the atom at a coordinate belongs to the island. The default is a torus; another shape is set by editing the method.

Cell 1.3 holds the parameters:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
CENTER_POSITION = [0.5, 0.5, 0.5]  # Center of the torus in crystal coordinates
MAJOR_RADIUS = 0.3  # Major radius of the torus
MINOR_RADIUS = 0.1  # Minor radius of the torus
USE_CARTESIAN_COORDINATES = False # Use Cartesian coordinates for the condition

NUMBER_OF_ADDED_LAYERS = 3  # Number of layers to add to the defect


# Create slab with default parameters if imported material is not a slab
DEFAULT_SLAB_PARAMETERS = {
    "miller_indices": (0,0,1),
    "thickness": 3,
    "vacuum": 5.0,
    "use_orthogonal_c": True,
    "xy_supercell_matrix": [[10, 0], [0, 10]]
}

The island holds the atoms within MINOR_RADIUS of a ring of radius MAJOR_RADIUS around CENTER_POSITION, in the coordinates that USE_CARTESIAN_COORDINATES selects. NUMBER_OF_ADDED_LAYERS is the number of atomic layers the island adds.

DEFAULT_SLAB_PARAMETERS applies when the first input material is not a slab.

4. Run and read the result

Run the notebook with Run > Run All. The notebook shows the slab before and after the island is added and passes it back with set_materials, as in Structure Notebooks.

5. Interactive JupyterLite notebook

The interactive JupyterLite notebook for creating a custom shape island defect can be accessed below.