gnrs.cluster


gnrs.cluster.cluster_task

This module provides the ClusterSelectionTask class for performing cluster selection tasks.

This source code is licensed under the BSD-3-Clause license found in the LICENSE file in the root directory of this source tree.

class gnrs.cluster.cluster_task.ClusterSelectionTask[source]

Bases: TaskABC

Task for performing cluster selection.

Initialize the cluster selection task.

Parameters:
  • comm – MPI communicator

  • config – Config dictionary

  • gnrs_info – Genarris info dictionary

  • cluster – Clustering class name

  • selection – Selection class name

__init__(comm, config, gnrs_info, cluster, selection)[source]

Initialize the cluster selection task.

Parameters:
  • comm (mpi4py.MPI.Comm) – MPI communicator

  • config (dict) – Config dictionary

  • gnrs_info (dict) – Genarris info dictionary

  • cluster (str) – Clustering class name

  • selection (str) – Selection class name

Return type:

None

initialize()[source]

Initialize the cluster selection task.

Return type:

None

pack_settings()[source]

Pack settings needed for cluster selection.

Returns:

Task settings dictionary

Return type:

dict

print_settings(task_set)[source]

Print task settings in a formatted table.

Parameters:

task_set (dict) – Task settings dictionary

Return type:

None

create_folders()[source]

Create folders needed for the task.

Return type:

None

perform_task(task_set)[source]

Execute the cluster selection task.

Parameters:

task_set (dict) – Task settings dictionary

Return type:

None

collect_results()[source]

Collect and save the results of the task.

Return type:

None

analyze()[source]

Analyze the results of the task.

Return type:

None

finalize()[source]

Finalize the task and update runtime settings.

Return type:

None

gnrs.cluster.ap

This module provides the AP clustering algorithm.

This source code is licensed under the BSD-3-Clause license found in the LICENSE file in the root directory of this source tree.

class gnrs.cluster.ap.APCluster[source]

Bases: ClusterABC

Affinity Propagation clustering implementation.

This class implements the Affinity Propagation clustering algorithm with support for distributed computation using MPI.

Initialize the APCluster object.

Parameters:
  • comm – MPI communicator

  • task_settings – Task settings for AP clustering

__init__(comm, task_settings)[source]

Initialize the APCluster object.

Parameters:
  • comm (mpi4py.MPI.Comm) – MPI communicator

  • task_settings (dict) – Task settings for AP clustering

Return type:

None

initialize()[source]

Initialize the clustering by gathering crystal structures and computing similarity matrix.

This method: 1. Gathers structures from all processes 2. Computes or loads feature vectors 3. Computes or loads similarity matrix 4. Sets up preference range for AP clustering 5. Initializes the AP model

Return type:

None

fit()[source]

Fit the clustering model to the data.

Only AP-worker ranks run AP clustering.

Return type:

None

predict()[source]

Assign cluster labels to structures.

Returns:

Final number of clusters

Return type:

int

finalize()[source]

Finalize the clustering process.

Return type:

None

check_convergence(n_clusters_pref, pref_range, n_attempts)[source]

Check if the clustering has converged.

Parameters:
  • n_clusters_pref (list) – List of [num_clusters, preference] pairs from all processes

  • pref_range (list) – List of preference values from all processes

  • n_attempts (int) – Current attempt number

Returns:

  • converged: Whether a suitable clustering was found

  • rank: Rank with suitable clustering

  • pref: preference used for clustering

  • n_cluster: Number of clusters found

  • new_pref_range: New preference range to try

Return type:

Dictionary containing

gnrs.cluster.kmeans

This module provides k-means clustering.

This source code is licensed under the BSD-3-Clause license found in the LICENSE file in the root directory of this source tree.

class gnrs.cluster.kmeans.KMEANSCluster[source]

Bases: ClusterABC

K-means clustering.

Initialize the k-means clustering.

Parameters:
  • comm – MPI communicator

  • task_settings – Task settings

__init__(comm, task_settings)[source]

Initialize the k-means clustering.

Parameters:
  • comm (mpi4py.MPI.Comm) – MPI communicator

  • task_settings (dict) – Task settings

Return type:

None

initialize()[source]

Initialize the k-means clustering.

Return type:

None

fit()[source]

Fit the k-means clustering.

Return type:

None

predict()[source]

Predict the clusters.

Return type:

None

finalize()[source]

Finalize the k-means clustering.

Return type:

None

gnrs.cluster.selection.center

This module provides the CenterSelection class for selecting the center of a cluster.

This source code is licensed under the BSD-3-Clause license found in the LICENSE file in the root directory of this source tree.

class gnrs.cluster.selection.center.CENTERSelection[source]

Bases: SelectionABC

Selection class that identifies and keeps only the center crystals from clusters.

This class can select centers based on either: 1. Crystals marked as centers during clustering 2. Crystals with minimum value of a specified property within each cluster

Initialize the selection algorithm.

Parameters:
  • comm – MPI communicator for parallel computation

  • settings – Selection settings

initialize()[source]

Initialize the center selection process.

Return type:

None

finalize()[source]

Finalize the selection process.

Return type:

None

select(struct_dict)[source]

Select crystals based on configured criteria.

Parameters:

struct_dict (dict) – Crystals dictionary

Return type:

None

gnrs.cluster.selection.window

This module provides the WindowSelection class for selecting structures within a energy window.

This source code is licensed under the BSD-3-Clause license found in the LICENSE file in the root directory of this source tree.

class gnrs.cluster.selection.window.WINDOWSelection[source]

Bases: SelectionABC

Selection class that selects structures within a energy window from clusters.

Initialize the selection algorithm.

Parameters:
  • comm – MPI communicator for parallel computation

  • settings – Selection settings

initialize()[source]

Initialize the window selection process.

Return type:

None

finalize()[source]

Finalize the selection process.

Return type:

None

select(struct_dict)[source]

Select structures within energy window from each cluster.

Parameters:

struct_dict (dict) – Crystals dictionary

Return type:

None

get_energy(idx)[source]

Get energy for structures in the specified cluster.

Parameters:

idx (int) – Cluster index

Returns:

List of [name, energy] pairs for structures in cluster

Return type:

list

get_window_across_ranks(structs)[source]

Get structures within energy window across all ranks.

Parameters:

structs (list) – List of [xtal_id, energy] pairs for structures in a cluster

Returns:

List of xtal ids within energy window

Return type:

list