Skip to content

Commit

Permalink
Merge pull request #86 from amepproject/issue-85_cluster_single
Browse files Browse the repository at this point in the history
adds single particles to cluster list
  • Loading branch information
kay-ro authored Nov 13, 2024
2 parents 0b08867 + 92442e6 commit 6ac73bc
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions amep/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,8 @@ def identify(
sorted_clusters : list
List of lists, where each list contains the indices of the particles
that belong to the same cluster. The list is sorted by the number of
particles in each cluster.
particles in each cluster. Single particles are also included as
clusters in this list.
idx : numpy.ndarray
Array of shape (N,) containing the cluster ID for each particle. N is
the total number of particles.
Expand Down Expand Up @@ -1036,18 +1037,18 @@ def identify(
particle_idx = set(np.arange(len(coords)))
clustered_idx = set()

n = 0
cluster_id = 0
for cl in sorted_clusters:

for i in cl:
idx[i] = n
idx[i] = cluster_id
clustered_idx.add(i)

n += 1
cluster_id += 1

# add leftover single particles
for k in particle_idx - clustered_idx:
idx[k] = n
n += 1
idx[k] = cluster_id
sorted_clusters.append([k])
cluster_id += 1
idx=np.array(idx, dtype=int)

return sorted_clusters, idx

0 comments on commit 6ac73bc

Please sign in to comment.