Skip to content

Commit

Permalink
Merge pull request #1823 from jamesmkrieger/kmedoids
Browse files Browse the repository at this point in the history
add kmedoid clustering
  • Loading branch information
jamesmkrieger authored Feb 8, 2024
2 parents 18388b4 + 9435e6a commit 12c555a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion prody/utilities/catchall.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
__all__ = ['calcTree', 'clusterMatrix', 'showLines', 'showMatrix',
'reorderMatrix', 'findSubgroups', 'getCoords',
'getLinkage', 'getTreeFromLinkage', 'clusterSubfamilies',
'calcRMSDclusters', 'calcGromosClusters', 'calcGromacsClusters']
'calcRMSDclusters', 'calcGromosClusters', 'calcGromacsClusters',
'calcKmedoidClusters']

class LinkageError(Exception):
pass
Expand Down Expand Up @@ -1032,3 +1033,15 @@ def calcRMSDclusters(rmsd_matrix, c, labels=None):

calcGromosClusters = calcRMSDclusters
calcGromacsClusters = calcRMSDclusters

def calcKmedoidClusters(coordsets, nClusters):
try:
from sklearn_extra.cluster import KMedoids
except ImportError:
raise ImportError('Please install scikit-learn-extra to run this function')

X = coordsets.reshape(coordsets.shape[0], -1)
c = KMedoids(n_clusters=nClusters, random_state=0).fit(X)
labels = c.labels_
_, counts = np.unique(labels, return_counts=True)
return c.medoid_indices_, labels, counts

0 comments on commit 12c555a

Please sign in to comment.