Skip to content

Create a Cluster of Custom Shape

1. Introduction

Create a cluster of any shape from a bulk material, with the shape given as a condition on the atomic coordinates and a chosen crystal orientation along the z axis.

2. Open the notebook

In JupyterLite, the notebook is made/create_cluster_custom_shape.ipynb, entry 1.4.3 "Custom Shape Cluster. Create a cluster by cutting it out of a slab" 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
RADIUS = 5.3  # in Angstroms
VACUUM = 10.0  # in Angstroms on each side
Z_ORIENTATION = (0, 0, 1)  # Miller indices of the slab orientation along the z-axis for the cluster
USE_CARTESIAN_COORDINATES = True
NAME = "Icosahedron"  # Name of the cluster

RADIUS is the size of the shape in angstroms, and Z_ORIENTATION the Miller indices of the crystal planes normal to z. NAME is appended to the material's name. The overview explains VACUUM and USE_CARTESIAN_COORDINATES.

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
import numpy as np
from scipy.spatial import ConvexHull
from typing import List
from mat3ra.made.tools.helpers import CoordinateCondition


class CustomCoordinateCondition(CoordinateCondition):
    """Creates a regular polyhedron shape using SciPy's ConvexHull"""
    radius: float = 1
    center_coordinate: List[float] = [0.5, 0.5, 0.5]

    @property
    def _hull_planes(self):
        t = (1 + np.sqrt(5)) / 2
        vertices = np.array([
            [-1, t, 0], [1, t, 0], [-1, -t, 0], [1, -t, 0],
            [0, -1, t], [0, 1, t], [0, -1, -t], [0, 1, -t],
            [t, 0, -1], [t, 0, 1], [-t, 0, -1], [-t, 0, 1]
        ]) * self.radius / np.sqrt(1 + t*t)
        return ConvexHull(vertices).equations

    def condition(self, coordinate: List[float]) -> bool:
        """Returns True if point is inside the polyhedron"""
        point = np.array(coordinate) - self.center_coordinate
        return all(np.dot(plane[:3], point) + plane[3] <= 0
                  for plane in self._hull_planes)


condition = CustomCoordinateCondition(radius=RADIUS)

CustomCoordinateCondition.condition returns whether the atom at a coordinate is kept. The default keeps the atoms inside a regular icosahedron of radius RADIUS; another shape is set by editing the method.

4. Run and read the result

Run the notebook with Run > Run All. The notebook shows the cluster from the top and from the side, names it <material> <NAME> and passes it back with set_materials, as in Structure Notebooks.

5. Interactive JupyterLite notebook

The interactive JupyterLite notebook for creating a cluster of custom shape can be accessed below.