diff --git a/AUTHORS b/AUTHORS index 62c4522fd6..9d94f7e9e5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,6 +6,7 @@ Asmit Bhowmick Benjamin Williams Billy Poon Daniel Paley +Daniel Tchon David Waterman Derek Mendez Graeme Winter diff --git a/newsfragments/2311.bugfix b/newsfragments/2311.bugfix new file mode 100644 index 0000000000..0561a77435 --- /dev/null +++ b/newsfragments/2311.bugfix @@ -0,0 +1 @@ +``dials.combine_experiments``: Prevent default ``clustering.max_clusters=None`` from raising error when clustering. diff --git a/src/dials/command_line/combine_experiments.py b/src/dials/command_line/combine_experiments.py index ac18992d00..f8e2fd13f3 100644 --- a/src/dials/command_line/combine_experiments.py +++ b/src/dials/command_line/combine_experiments.py @@ -745,6 +745,8 @@ def save_in_batches( # cluster the resulting experiments if requested if params.clustering.use and len(experiments) > 1: + if params.clustering.max_clusters == 0: + sys.exit("Error: max_clusters must be None or >0") clustered = do_unit_cell_clustering( experiments, reflections, @@ -752,9 +754,9 @@ def save_in_batches( threshold=params.clustering.threshold, ) n_clusters = len(clustered) - clusters = sorted(clustered.clusters, key=len, reverse=True)[ - : min(params.clustering.max_clusters, n_clusters) - ] + clusters = sorted(clustered.clusters, key=len, reverse=True) + if params.clustering.max_clusters is not None: + clusters = clusters[: params.clustering.max_clusters] if params.clustering.exclude_single_crystal_clusters: clusters = [c for c in clusters if len(c) > 1] clustered_experiments = [