structuretoolkit.analyse.spatial.get_layers

Contents

structuretoolkit.analyse.spatial.get_layers#

structuretoolkit.analyse.spatial.get_layers(structure: Atoms, distance_threshold: float = 0.01, id_list: list[int] | None = None, wrap_atoms: bool = True, planes: ndarray | None = None, cluster_method: Any | None = None) ndarray[source]#

Get an array of layer numbers.

Parameters:
  • distance_threshold (float) – Distance below which two points are considered to belong to the same layer. For detailed description: sklearn.cluster.AgglomerativeClustering

  • id_list (list/numpy.ndarray) – List of atoms for which the layers should be considered.

  • wrap_atoms (bool) – Whether to consider periodic boundary conditions according to the box definition or not. If set to False, atoms lying on opposite box boundaries are considered to belong to different layers, regardless of whether the box itself has the periodic boundary condition in this direction or not. If planes is not None and wrap_atoms is True, this tag has the same effect as calling get_layers() after calling center_coordinates_in_unit_cell()

  • planes (list/numpy.ndarray) – Planes along which the layers are calculated. Planes are given in vectors, i.e. [1, 0, 0] gives the layers along the x-axis. Default planes are orthogonal unit vectors: [[1, 0, 0], [0, 1, 0], [0, 0, 1]]. If you have a tilted box and want to calculate the layers along the directions of the cell vectors, use planes=np.linalg.inv(structure.cell).T. Whatever values are inserted, they are internally normalized, so whether [1, 0, 0] is entered or [2, 0, 0], the results will be the same.

  • cluster_method (scikit-learn cluster algorithm) – if given overrides the clustering method used, must be an instance of a cluster algorithm from scikit-learn (or compatible interface)

Returns: Array of layer numbers (same shape as structure.positions)

Example I - how to get the number of layers in each direction:

>>> structure = Project('.').create_structure('Fe', 'bcc', 2.83).repeat(5)
>>> print('Numbers of layers:', np.max(structure.analyse.get_layers(), axis=0)+1)

Example II - get layers of only one species:

>>> print('Iron layers:', structure.analyse.get_layers(
...       id_list=structure.select_index('Fe')))

The clustering algorithm can be changed with the cluster_method argument

>>> from sklearn.cluster import DBSCAN
>>> layers = structure.analyse.get_layers(cluster_method=DBSCAN())