crystal_torture.cluster.Cluster

class crystal_torture.cluster.Cluster(nodes: set[Node])[source]

Bases: object

Cluster class: group of connected nodes within graph.

grow_cluster() None[source]

Grow cluster by adding all connected neighbours.

Uses breadth-first search to find all nodes connected to the current cluster and adds them to the cluster. This expands the cluster to include the full connected component in the graph.

property halo_nodes: set[Node]

Return halo nodes (is_halo=True).

is_neighbour(other_cluster: Cluster) bool[source]

Check if one cluster of nodes is connected to another.

Parameters:

other_cluster – Cluster to check for connection.

Returns:

True if clusters share any nodes, False otherwise.

merge(other_cluster: Cluster) Cluster[source]

Merge two clusters into one.

Parameters:

other_cluster – Cluster to be joined.

Returns:

New cluster containing nodes from both clusters.

return_index_node(index: int) Node[source]

Return the node with the specified index.

Parameters:

index – Index of the node to return.

Returns:

Node with the specified index.

Raises:

ValueError – If no node with the specified index is found.

set_periodic() None[source]

Set the periodicity of the cluster by counting UC nodes with same UC_index.

Determines cluster periodicity by counting how many periodic images of the same unit cell site are connected in the cluster.

Sets:

self.periodic: 0=isolated, 1=1D periodic, 2=2D periodic, 3=3D periodic

torture_fort() None[source]

Perform tortuosity analysis on nodes in cluster using BFS in Fortran90 and OpenMP.

Significantly faster than the Python version above for large systems. Calculates the integer number of node-node steps it requires to get from a node to its periodic image.

Sets: node.tortuosity: Tortuosity for each node. self.tortuosity: Average tortuosity for cluster.

Raises:
  • FortranNotAvailableError – If Fortran extensions are not available.

  • RuntimeError – If Fortran nodes have not been allocated.

torture_py() None[source]

Perform tortuosity analysis on nodes in cluster in pure Python using BFS.

Calculates the integer number of node-node steps it requires to get from a node to its periodic image.

Sets: node.tortuosity: Tortuosity for each node. self.tortuosity: Average tortuosity for cluster.

property uc_indices: set[int]

Return the unit-cell indices of nodes in a cluster.

property uc_nodes: set[Node]

Return unit cell nodes (is_halo=False).