datamol.cluster
¶
assign_to_centroids(mols, centroids, feature_fn=None, dist_fn=None, n_jobs=1)
¶
Assign molecules to centroids. Each molecule will be assigned to the closest centroid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
List[Mol]
|
a list of molecules to assign to centroids |
required |
centroids |
List[Mol]
|
list of molecules to use as centroid |
required |
feature_fn |
Optional[Callable]
|
A feature function that takes a Mol object
and return molecular features. By default, the |
None
|
dist_fn |
Optional[Callable]
|
A function that takes two indexes (i,j) and return the distance between them. You might use partial to set the fingerprints as input. By default, the Tanimoto similarity will be used. Default to None. |
None
|
n_jobs |
Optional[int]
|
Number of jobs for parallelization. Let to 1 for no parallelization. Set to -1 to use all available cores. |
1
|
Returns:
Name | Type | Description |
---|---|---|
clusters_map |
dict
|
dict of index mapping each centroid index to the molecule index in the cluster |
clusters_list |
list
|
list of all molecules in each cluster. The cluster index follows the index of the centroid. Note that the centroid molecule is not added to the cluster. |
Source code in datamol/cluster.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
cluster_mols(mols, cutoff=0.2, feature_fn=None, n_jobs=1)
¶
Cluster a set of molecules using the butina clustering algorithm and a given threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
Union[Sequence[Mol], pd.Series]
|
a list of molecules. |
required |
cutoff |
float
|
Cuttoff for the clustering. Default to 0.2. |
0.2
|
feature_fn |
Optional[Callable]
|
A feature function that takes a Mol object
and return molecular features. By default, the |
None
|
n_jobs |
Optional[int]
|
Number of jobs for parallelization. Let to 1 for no parallelization. Set to -1 to use all available cores. |
1
|
Source code in datamol/cluster.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
pick_centroids(mols, npick=0, initial_picks=None, threshold=0.5, feature_fn=None, dist_fn=None, seed=42, method='sphere', n_jobs=1)
¶
Pick a set of npick
centroids from a list of molecules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
List[Mol]
|
a list of molecules. |
required |
npick |
int
|
Number of element to pick from mols, including the preselection. |
0
|
threshold |
float
|
Minimum distance between centroids for |
0.5
|
initial_picks |
Optional[List[int]]
|
Starting list of index for molecules that should be in the set of picked molecules. Default to None. |
None
|
feature_fn |
callable
|
A feature function that takes a Mol object
and return molecular features. By default, the |
None
|
dist_fn |
Optional[Callable]
|
A function that takes two indexes (i,j) and return the distance between them. You might use partial to set the fingerprints as input. By default, the Tanimoto similarity will be used. Default to None. |
None
|
seed |
int
|
seed for reproducibility |
42
|
method |
str
|
Picking method to use. One of |
'sphere'
|
n_jobs |
Optional[int]
|
Number of jobs for parallelization. Let to 1 for no parallelization. Set to -1 to use all available cores. |
1
|
Returns:
Name | Type | Description |
---|---|---|
picked_inds |
int
|
index of the molecule that have been selected as centroids |
mols |
list
|
molecules that have been picked |
Source code in datamol/cluster.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
pick_diverse(mols, npick, initial_picks=None, feature_fn=None, dist_fn=None, seed=42, n_jobs=1)
¶
Pick a set of diverse molecules based on they fingerprint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mols |
List[Mol]
|
a list of molecules. |
required |
npick |
int
|
Number of element to pick from mols, including the preselection. |
required |
initial_picks |
Optional[List[int]]
|
Starting list of index for molecules that should be in the set of picked molecules. Default to None. |
None
|
feature_fn |
Optional[Callable]
|
A feature function that takes a Mol object
and return molecular features. By default, the |
None
|
dist_fn |
Optional[Callable]
|
A function that takes two indexes (i,j) and return the distance between them. You might use partial to set the fingerprints as input. By default, the Tanimoto similarity will be used. Default to None. |
None
|
seed |
int
|
seed for reproducibility |
42
|
n_jobs |
Optional[int]
|
Number of jobs for parallelization. Let to 1 for no parallelization. Set to -1 to use all available cores. |
1
|
Returns:
Name | Type | Description |
---|---|---|
picked_inds |
int
|
index of the molecule that have been picked |
mols |
list
|
molecules that have been picked |
Source code in datamol/cluster.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|