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