Datamol Cheminformatics Skill
Overview
Datamol is a Python library that provides a lightweight, Pythonic abstraction layer over RDKit for molecular cheminformatics. Simplify complex molecular operations with sensible defaults, efficient parallelization, and modern I/O capabilities. All molecular objects are native rdkit.Chem.Mol instances, ensuring full compatibility with the RDKit ecosystem.
Version note: Examples target datamol 0.12.x (PyPI stable: 0.12.5, June 2024). Since 0.10.0, modules are lazy-loaded by default (set DATAMOL_DISABLE_LAZY_LOADING=1 to disable). Since 0.12.2, RDKit is a direct PyPI dependency of datamol. Fingerprints use RDKit's rdFingerprintGenerator API (0.12.5+).
Key capabilities:
- Molecular format conversion (SMILES, SELFIES, InChI)
- Structure standardization and sanitization
- Molecular descriptors and fingerprints
- 3D conformer generation and analysis
- Clustering and diversity selection
- Scaffold and fragment analysis
- Chemical reaction application
- Visualization and alignment
- Batch processing with parallelization
- Cloud storage support via fsspec
Installation and Setup
Guide users to install datamol:
uv pip install datamol
RDKit is installed automatically with datamol. For remote file paths (S3, GCS, HTTP), install the matching fsspec backend:
uv pip install s3fs # AWS S3
uv pip install gcsfs # Google Cloud Storage
Import convention:
import datamol as dm
Core Workflows
Ten workflow areas, each with worked code, are documented in
references/core_workflows.md:
| # |
Area |
Covers |
| 1 |
Basic molecule handling |
to_mol, batch conversion, error handling, canonical and isomeric SMILES, sanitization and full standardization |
| 2 |
Reading and writing files |
SDF, SMILES, CSV, Excel with rendered structures, the universal reader/writer, and cloud or HTTPS paths |
| 3 |
Descriptors and properties |
the standard descriptor set, parallel computation, aromaticity, stereochemistry, flexibility, and filtering |
| 4 |
Fingerprints and similarity |
ECFP4 and other types, pairwise and cross-set distances, nearest-neighbour lookup (Tanimoto distance = 1 − similarity) |
| 5 |
Clustering and diversity |
similarity clustering, diverse subset picking, and cluster centroids |
| 6 |
Scaffold analysis |
Bemis-Murcko scaffolds, grouping and counting, and scaffold-disjoint train/test splits |
| 7 |
Fragmentation |
fragmenting molecules, finding common fragments across a library, and fragment-based scoring |
| 8 |
3D conformers |
generation, access, RMSD clustering, representative selection, and SASA |
| 9 |
Visualization |
grids, files, publication SVG, substructure alignment, atom and bond highlighting, conformer display |
| 10 |
Chemical reactions |
reaction SMARTS, applying to a molecule or a whole library |
Three end-to-end pipelines — load/filter/analyze, SAR by scaffold series, and virtual
screening — are in references/workflow_patterns.md.
Parallelization
Datamol includes built-in parallelization for many operations. Use n_jobs parameter:
n_jobs=1: Sequential (no parallelization)
n_jobs=-1: Use all available CPU cores
n_jobs=4: Use 4 cores
Functions supporting parallelization:
dm.read_sdf(..., n_jobs=-1)
dm.descriptors.batch_compute_many_descriptors(..., n_jobs=-1)
dm.cluster_mols(..., n_jobs=-1)
dm.pdist(..., n_jobs=-1)
dm.conformers.sasa(..., n_jobs=-1)
Progress bars: Many batch operations support progress=True parameter.
Reference Documentation
For detailed API documentation, consult these reference files:
references/core_api.md: Core namespace functions (conversions, standardization, fingerprints, clustering)
references/io_module.md: File I/O operations (read/write SDF, CSV, Excel, remote files)
references/conformers_module.md: 3D conformer generation, clustering, SASA calculations
references/descriptors_viz.md: Molecular descriptors and visualization functions
references/fragments_scaffolds.md: Scaffold extraction, BRICS/RECAP fragmentation
references/reactions_data.md: Chemical reactions and toy datasets
Best Practices
Always standardize molecules from external sources:
mol = dm.standardize_mol(mol, disconnect_metals=True, normalize=True, reionize=True)
Check for None values after molecule parsing:
mol = dm.to_mol(smiles)
if mol is None:
# Handle invalid SMILES
Use parallel processing for large datasets:
result = dm.operation(..., n_jobs=-1, progress=True)
Use cloud I/O only when requested — confirm remote write paths; install s3fs/gcsfs as needed:
df = dm.read_sdf("s3://bucket/compounds.sdf")
Use appropriate fingerprints for similarity:
- ECFP (Morgan): General purpose, structural similarity
- MACCS: Fast, smaller feature space
- Atom pairs: Considers atom pairs and distances
Consider scale limitations:
- Butina clustering: ~1,000 molecules (full distance matrix)
- For larger datasets: Use diversity selection or hierarchical methods
Scaffold splitting for ML: Ensure proper train/test separation by scaffold
Align molecules when visualizing SAR series
Error Handling
# Safe molecule creation
def safe_to_mol(smiles):
try:
mol = dm.to_mol(smiles)
if mol is not None:
mol = dm.standardize_mol(mol)
return mol
except Exception as e:
print(f"Failed to process {smiles}: {e}")
return None
# Safe batch processing
valid_mols = []
for smiles in smiles_list:
mol = safe_to_mol(smiles)
if mol is not None:
valid_mols.append(mol)
Integration with Machine Learning
Datamol ships with scipy and scikit-learn as dependencies. Import them as normal PyPI packages — they are not scripts bundled in this skill.
import numpy as np
# Feature generation
X = np.array([dm.to_fp(mol) for mol in mols])
# Or descriptors
desc_df = dm.descriptors.batch_compute_many_descriptors(mols, n_jobs=-1)
X = desc_df.values
# Train model (scikit-learn PyPI package)
from sklearn.ensemble import RandomForestRegressor # third-party library
model = RandomForestRegressor()
model.fit(X, y_target)
# Predict
predictions = model.predict(X_test)
Troubleshooting
Issue: Molecule parsing fails
- Solution: Use
dm.standardize_smiles() first or try dm.fix_mol()
Issue: Memory errors with clustering
- Solution: Use
dm.pick_diverse() instead of full clustering for large sets
Issue: Slow conformer generation
- Solution: Reduce
n_confs or increase rms_cutoff to generate fewer conformers
Issue: Remote file access fails
- Solution: Install the matching fsspec backend (
uv pip install s3fs or gcsfs) and verify only the provider credentials needed for that backend are set (see Remote file support above)
Additional Resources
1---
2name: datamol
3description: Pythonic wrapper around RDKit with simplified interface and sensible defaults. Preferred for standard drug discovery including SMILES parsing, standardization, descriptors, fingerprints, clustering, 3D conformers, parallel processing. Returns native rdkit.Chem.Mol objects. For advanced control or custom parameters, use rdkit directly.
4license: Apache-2.0 license
5allowed-tools: Read Write Edit Bash
6compatibility: Requires Python 3.8+ and datamol (uv pip install). RDKit is installed automatically as a datamol dependency (since 0.12.2). Optional s3fs/gcsfs for cloud I/O via fsspec.
7metadata:
8 version: "1.1"
9 skill-author: K-Dense Inc.
10---
11
12# Datamol Cheminformatics Skill
13
14## Overview
15
16Datamol is a Python library that provides a lightweight, Pythonic abstraction layer over RDKit for molecular cheminformatics. Simplify complex molecular operations with sensible defaults, efficient parallelization, and modern I/O capabilities. All molecular objects are native `rdkit.Chem.Mol` instances, ensuring full compatibility with the RDKit ecosystem.
17
18**Version note:** Examples target **datamol 0.12.x** (PyPI stable: **0.12.5**, June 2024). Since 0.10.0, modules are lazy-loaded by default (set `DATAMOL_DISABLE_LAZY_LOADING=1` to disable). Since 0.12.2, RDKit is a direct PyPI dependency of datamol. Fingerprints use RDKit's `rdFingerprintGenerator` API (0.12.5+).
19
20**Key capabilities**:
21- Molecular format conversion (SMILES, SELFIES, InChI)
22- Structure standardization and sanitization
23- Molecular descriptors and fingerprints
24- 3D conformer generation and analysis
25- Clustering and diversity selection
26- Scaffold and fragment analysis
27- Chemical reaction application
28- Visualization and alignment
29- Batch processing with parallelization
30- Cloud storage support via fsspec
31
32## Installation and Setup
33
34Guide users to install datamol:
35
36```bash
37uv pip install datamol
38```
39
40RDKit is installed automatically with datamol. For remote file paths (S3, GCS, HTTP), install the matching fsspec backend:
41
42```bash
43uv pip install s3fs # AWS S3
44uv pip install gcsfs # Google Cloud Storage
45```
46
47**Import convention**:
48```python
49import datamol as dm
50```
51
52## Core Workflows
53
54Ten workflow areas, each with worked code, are documented in
55[references/core_workflows.md](references/core_workflows.md):
56
57| # | Area | Covers |
58| --- | --- | --- |
59| 1 | Basic molecule handling | `to_mol`, batch conversion, error handling, canonical and isomeric SMILES, sanitization and full standardization |
60| 2 | Reading and writing files | SDF, SMILES, CSV, Excel with rendered structures, the universal reader/writer, and cloud or HTTPS paths |
61| 3 | Descriptors and properties | the standard descriptor set, parallel computation, aromaticity, stereochemistry, flexibility, and filtering |
62| 4 | Fingerprints and similarity | ECFP4 and other types, pairwise and cross-set distances, nearest-neighbour lookup (Tanimoto distance = 1 − similarity) |
63| 5 | Clustering and diversity | similarity clustering, diverse subset picking, and cluster centroids |
64| 6 | Scaffold analysis | Bemis-Murcko scaffolds, grouping and counting, and scaffold-disjoint train/test splits |
65| 7 | Fragmentation | fragmenting molecules, finding common fragments across a library, and fragment-based scoring |
66| 8 | 3D conformers | generation, access, RMSD clustering, representative selection, and SASA |
67| 9 | Visualization | grids, files, publication SVG, substructure alignment, atom and bond highlighting, conformer display |
68| 10 | Chemical reactions | reaction SMARTS, applying to a molecule or a whole library |
69
70Three end-to-end pipelines — load/filter/analyze, SAR by scaffold series, and virtual
71screening — are in [references/workflow_patterns.md](references/workflow_patterns.md).
72
73## Parallelization
74
75Datamol includes built-in parallelization for many operations. Use `n_jobs` parameter:
76- `n_jobs=1`: Sequential (no parallelization)
77- `n_jobs=-1`: Use all available CPU cores
78- `n_jobs=4`: Use 4 cores
79
80**Functions supporting parallelization**:
81- `dm.read_sdf(..., n_jobs=-1)`
82- `dm.descriptors.batch_compute_many_descriptors(..., n_jobs=-1)`
83- `dm.cluster_mols(..., n_jobs=-1)`
84- `dm.pdist(..., n_jobs=-1)`
85- `dm.conformers.sasa(..., n_jobs=-1)`
86
87**Progress bars**: Many batch operations support `progress=True` parameter.
88
89## Reference Documentation
90
91For detailed API documentation, consult these reference files:
92
93- **`references/core_api.md`**: Core namespace functions (conversions, standardization, fingerprints, clustering)
94- **`references/io_module.md`**: File I/O operations (read/write SDF, CSV, Excel, remote files)
95- **`references/conformers_module.md`**: 3D conformer generation, clustering, SASA calculations
96- **`references/descriptors_viz.md`**: Molecular descriptors and visualization functions
97- **`references/fragments_scaffolds.md`**: Scaffold extraction, BRICS/RECAP fragmentation
98- **`references/reactions_data.md`**: Chemical reactions and toy datasets
99
100## Best Practices
101
1021. **Always standardize molecules** from external sources:
103 ```python
104 mol = dm.standardize_mol(mol, disconnect_metals=True, normalize=True, reionize=True)
105 ```
106
1072. **Check for None values** after molecule parsing:
108 ```python
109 mol = dm.to_mol(smiles)
110 if mol is None:
111 # Handle invalid SMILES
112 ```
113
1143. **Use parallel processing** for large datasets:
115 ```python
116 result = dm.operation(..., n_jobs=-1, progress=True)
117 ```
118
1194. **Use cloud I/O only when requested** — confirm remote write paths; install `s3fs`/`gcsfs` as needed:
120 ```python
121 df = dm.read_sdf("s3://bucket/compounds.sdf")
122 ```
123
1245. **Use appropriate fingerprints** for similarity:
125 - ECFP (Morgan): General purpose, structural similarity
126 - MACCS: Fast, smaller feature space
127 - Atom pairs: Considers atom pairs and distances
128
1296. **Consider scale limitations**:
130 - Butina clustering: ~1,000 molecules (full distance matrix)
131 - For larger datasets: Use diversity selection or hierarchical methods
132
1337. **Scaffold splitting for ML**: Ensure proper train/test separation by scaffold
134
1358. **Align molecules** when visualizing SAR series
136
137## Error Handling
138
139```python
140# Safe molecule creation
141def safe_to_mol(smiles):
142 try:
143 mol = dm.to_mol(smiles)
144 if mol is not None:
145 mol = dm.standardize_mol(mol)
146 return mol
147 except Exception as e:
148 print(f"Failed to process {smiles}: {e}")
149 return None
150
151# Safe batch processing
152valid_mols = []
153for smiles in smiles_list:
154 mol = safe_to_mol(smiles)
155 if mol is not None:
156 valid_mols.append(mol)
157```
158
159## Integration with Machine Learning
160
161Datamol ships with `scipy` and `scikit-learn` as dependencies. Import them as normal PyPI packages — they are not scripts bundled in this skill.
162
163```python
164import numpy as np
165
166# Feature generation
167X = np.array([dm.to_fp(mol) for mol in mols])
168
169# Or descriptors
170desc_df = dm.descriptors.batch_compute_many_descriptors(mols, n_jobs=-1)
171X = desc_df.values
172
173# Train model (scikit-learn PyPI package)
174from sklearn.ensemble import RandomForestRegressor # third-party library
175model = RandomForestRegressor()
176model.fit(X, y_target)
177
178# Predict
179predictions = model.predict(X_test)
180```
181
182## Troubleshooting
183
184**Issue**: Molecule parsing fails
185- **Solution**: Use `dm.standardize_smiles()` first or try `dm.fix_mol()`
186
187**Issue**: Memory errors with clustering
188- **Solution**: Use `dm.pick_diverse()` instead of full clustering for large sets
189
190**Issue**: Slow conformer generation
191- **Solution**: Reduce `n_confs` or increase `rms_cutoff` to generate fewer conformers
192
193**Issue**: Remote file access fails
194- **Solution**: Install the matching fsspec backend (`uv pip install s3fs` or `gcsfs`) and verify only the provider credentials needed for that backend are set (see Remote file support above)
195
196## Additional Resources
197
198- **Datamol Documentation**: https://docs.datamol.io/
199- **RDKit Documentation**: https://www.rdkit.org/docs/
200- **GitHub Repository**: https://github.com/datamol-io/datamol