liveBook · Manning

Exclusion sphere

As explained in Build AI Drug Discovery Pipelines

An exclusion sphere is the neighborhood around a selected cluster centroid whose flagged members cannot serve as members of another cluster or as another centroid.

An exclusion sphere is the neighborhood around a selected cluster centroid whose flagged compounds cannot become members of another cluster or another centroid. It prevents overlapping assignments while selecting representative compounds. section 7.2.3

Build exclusion-sphere clusters by following this sequence:

  • Define neighbors with a distance threshold equal to 1 minus Tanimoto similarity; smaller thresholds require greater similarity. section 7.2.3
  • Rank potential centroids by neighbor count, then select the highest-ranked unflagged centroid. section 7.2.3
  • Flag its neighbors as cluster members and remove them from every other neighbor list. section 7.2.3
  • Repeat down the unflagged ranking; retain singleton clusters and arbitrate false singletons with linkage criteria when needed. section 7.2.3
Listing 7.9 Taylor-Butina Clustering & Sampling Diverse Compounds
from rdkit import DataStructs
from rdkit.ML.Cluster import Butina
from sklearn.metrics import (
    calinski_harabasz_score, silhouette_score, davies_bouldin_score)
 
def butina_clustering(fingerprints, cutoff=0.2):
    dists = []    #A
    nfps = len(fingerprints)
    for i in range(1, nfps):
        sims = DataStructs.BulkTanimotoSimilarity(
            fingerprints[i], fingerprints[:i])
        dists.extend([1 - x for x in sims])
    return Butina.ClusterData(dists, nfps, cutoff, isDistData=True)
 
ch_scores, silhouette_scores, db_scores = [], [], []
cutoffs = np.arange(0.0, 1.0, 0.2)
cutoffs_to_clusters = {}
for cutoff_ in cutoffs:
    clusters = butina_clustering(rdkit_fps, cutoff=cutoff_)
    cutoffs_to_clusters[cutoff_] = clusters
    cluster_labels = np.zeros(len(new_mols))
    for cluster_id, cluster in enumerate(clusters):
        for mol_id in cluster:
            cluster_labels[mol_id] = cluster_id
    n_labels = len(set(cluster_labels))
    if 2 <= n_labels <= len(new_mols) - 1:    #A
        ch_scores.append(calinski_harabasz_score(fps, cluster_labels))
        silhouette_scores.append(silhouette_score(fps, cluster_labels))
        db_scores.append(davies_bouldin_score(fps, cluster_labels))
    else:
        ch_scores.append(np.nan)    #B
        silhouette_scores.append(np.nan)
        db_scores.append(np.nan)
 
optimal_cutoff = 0.4
clusters = cutoffs_to_clusters[optimal_cutoff]
cluster_labels = np.zeros(len(new_mols))
for cluster_id, cluster in enumerate(clusters):
    for mol_id in cluster:
        cluster_labels[mol_id] = cluster_id
 
butina_sampled_indices = sample_from_clusters(fps, clusters)
butina_sampled_molecules = [new_mols[i] for i in butina_sampled_indices]

Use the Taylor–Butina implementation to convert fingerprint similarities into distances and generate clusters across cutoff values. section 7.2.3

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains neighbor thresholds, centroid ranking, flagging, singleton handling, and tie-breaking, but does not detail the full implementation beyond the algorithm.
Examples
Uses compound neighbor lists, ranked centroids, true and false singletons, and Taylor–Butina clustering across cutoff values.
What it assumes
Assumes fingerprint similarity and clustering vocabulary while defining neighbor distance, centroids, and singleton assignments operationally.
What you can do after
Apply it via RDKit fingerprints and Taylor–Butina clustering to form non-overlapping compound clusters.
How it connects
Connects Tanimoto similarity, cluster centroids, Taylor–Butina clustering, singleton clusters, and linkage methods.

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.