diff --git a/clusttraj/io.py b/clusttraj/io.py index 947d06f..1f50473 100644 --- a/clusttraj/io.py +++ b/clusttraj/io.py @@ -81,7 +81,13 @@ def __str__(self) -> str: return_str += f"Method: {self.method}\n" if self.silhouette_score: return_str += "\nUsing silhouette score\n" - return_str += f"RMSD criterion found by silhouette: {self.optimal_cut[0]}\n" + if isinstance(self.optimal_cut, (np.ndarray, list)): + scut = self.optimal_cut[0] + elif isinstance(self.optimal_cut, (float, np.float32, np.float64)): + scut = self.optimal_cut + else: + raise ValueError("optimal_cut must be a float or np.ndarray") + return_str += f"RMSD criterion found by silhouette: {scut}\n" else: return_str += f"RMSD criterion: {self.min_rmsd}\n" return_str += f"Ignoring hydrogens?: {self.no_hydrogen}\n" diff --git a/clusttraj/plot.py b/clusttraj/plot.py index 4b1b1f3..e13e5d1 100644 --- a/clusttraj/plot.py +++ b/clusttraj/plot.py @@ -50,11 +50,12 @@ def plot_dendrogram(clust_opt: ClustOptions, Z: np.ndarray) -> None: # Add a horizontal line at the minimum RMSD value if clust_opt.silhouette_score: - if isinstance(clust_opt.optimal_cut, np.ndarray): + if isinstance(clust_opt.optimal_cut, (np.ndarray, list)): plt.axhline(clust_opt.optimal_cut[0], linestyle="--") - - if isinstance(clust_opt.optimal_cut, (float, np.float32, np.float64)): + elif isinstance(clust_opt.optimal_cut, (float, np.float32, np.float64)): plt.axhline(clust_opt.optimal_cut, linestyle="--") + else: + raise ValueError("optimal_cut must be a float or np.ndarray") else: plt.axhline(clust_opt.min_rmsd, linestyle="--")