Skip to content

Commit fc6fd64

Browse files
authored
Merge pull request #26 from pyscal/fix_clustering
fix largest clustering
2 parents 6c69d45 + ed2555b commit fc6fd64

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/pyscal3/operations/identify.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,17 @@ def find_largest_cluster(system):
340340

341341
clusterlist = [x for x in system.atoms["cluster"] if x != -1]
342342
xx, xxcounts = np.unique(clusterlist, return_counts=True)
343-
arg = np.argsort(xxcounts)[-1]
344-
largest_cluster_size = xxcounts[arg]
345-
largest_cluster_id = xx[arg]
346343

347-
system.atoms["largest_cluster"] = [True if system.atoms["cluster"][x]==largest_cluster_id else False for x in range(len(system.atoms["cluster"]))]
348-
344+
if len(xx)>0:
345+
arg = np.argsort(xxcounts)[-1]
346+
largest_cluster_size = xxcounts[arg]
347+
largest_cluster_id = xx[arg]
348+
349+
system.atoms["largest_cluster"] = [True if system.atoms["cluster"][x]==largest_cluster_id else False for x in range(len(system.atoms["cluster"]))]
350+
else:
351+
system.atoms["largest_cluster"] = [False for x in range(len(system.atoms["cluster"]))]
352+
largest_cluster_size = 0
353+
349354
mapdict = {}
350355
mapdict["cluster"] = {}
351356
mapdict["cluster"]["largest"] = "largest_cluster"

0 commit comments

Comments
 (0)