Skip to content

Commit

Permalink
combine_experiments: Handle default max_clusters (dials#2311)
Browse files Browse the repository at this point in the history
Prevent dials.combine_experiments from raising TypeError in cases
where clustering.use=True but the default clustering.max_clusters=None.

Instead, interpret max_clusters=None as requesting all of the clusters.
  • Loading branch information
Baharis authored Jan 23, 2023
1 parent 995d6c2 commit d74643b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Asmit Bhowmick
Benjamin Williams
Billy Poon
Daniel Paley
Daniel Tchon
David Waterman
Derek Mendez
Graeme Winter
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2311.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``dials.combine_experiments``: Prevent default ``clustering.max_clusters=None`` from raising error when clustering.
8 changes: 5 additions & 3 deletions src/dials/command_line/combine_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,16 +745,18 @@ 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,
dendrogram=params.clustering.dendrogram,
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 = [
Expand Down

0 comments on commit d74643b

Please sign in to comment.