molfeat · diff

v1.3 to v2.0

114 added, 294 removed. Audit A to A.

---
name: molfeat
- description: Molecular featurization for ML (100+ featurizers). ECFP, MACCS, descriptors, pretrained models (ChemBERTa), convert SMILES to features, for QSAR and molecular ML.
+ description: Featurizes small molecules with Molfeat for QSAR/QSPR, chemical similarity, virtual screening, and molecular ML. Covers ECFP/MACCS fingerprints, RDKit descriptors, pharmacophores, pretrained embeddings, configuration persistence, and molecule-to-label alignment.
license: Apache-2.0 license
allowed-tools: Read Write Edit Bash
- compatibility: Requires Python 3.9–3.10 (molfeat 0.11.0 does not support 3.11+). Requires datamol, PyTorch, and optional extras for GNN/transformer models.
+ compatibility: Requires Python 3.11+ and molfeat 1.0.0 (RDKit, datamol, PyTorch). macOS Intel needs Python 3.11–3.12 and upstream platform-specific dependency pins. Optional extras and network access are needed for pretrained models; core fingerprints run offline.
metadata:
- version: "1.3"
+ version: "2.0"
skill-author: K-Dense Inc.
+ last-reviewed: "2026-10-01"
+ upstream-version: "1.0.0"
---
- # Molfeat - Molecular Featurization Hub
-
- ## Overview
-
- Molfeat is a comprehensive Python library for molecular featurization that unifies 100+ pre-trained embeddings and hand-crafted featurizers. Convert chemical structures (SMILES strings or RDKit molecules) into numerical representations for machine learning tasks including QSAR modeling, virtual screening, similarity searching, and deep learning applications. Features fast parallel processing, scikit-learn compatible transformers, and built-in caching.
+ # Molfeat — Small-molecule featurization
- **Version note:** Examples target **molfeat 0.11.0** (PyPI stable, May 2025). Requires **Python 3.9–3.10** (`requires-python` caps below 3.11). Depends on **datamol ≥0.8.0** and **PyTorch ≥1.13**. Since 0.8.7, prefer datamol `Mol` objects over raw `rdkit.Chem.Mol`. Since 0.10.1, fingerprint calculators use RDKit's `rdFingerprintGenerator` API internally. Since 0.11.0, pretrained models load in memory and base models are set to PyTorch evaluation mode automatically.
+ ## When to use
- ## When to Use This Skill
+ Use this skill to turn SMILES or RDKit molecules into fingerprints, descriptors,
+ pharmacophores, or pretrained embeddings for molecular machine learning and similarity
+ search. Compare representations on the same molecular split and assay endpoint.
- This skill should be used when working with:
- - **Molecular machine learning**: Building QSAR/QSPR models, property prediction
- - **Virtual screening**: Ranking compound libraries for biological activity
- - **Similarity searching**: Finding structurally similar molecules
- - **Chemical space analysis**: Clustering, visualization, dimensionality reduction
- - **Deep learning**: Training neural networks on molecular data
- - **Featurization pipelines**: Converting SMILES to ML-ready representations
- - **Cheminformatics**: Any task requiring molecular feature extraction
+ This skill targets **Molfeat 1.0.0**. The previous 0.11 runtime guidance is obsolete:
+ 1.x supports modern Python and removes DGL/DGLLife, legacy Graphormer, and protein
+ adapters. Historical model-store cards can still name removed adapters. The tagged
+ [1.0 migration guide](https://github.com/datamol-io/molfeat/blob/1.0.0/docs/migration.md)
+ and source take precedence over older pages still served at the documentation's
+ `stable` URL.
## Installation
- Use a Python 3.9 or 3.10 environment (molfeat does not install on 3.11+ as of 0.11.0):
+ Create an isolated environment. Core examples were executed on Python 3.13.3/macOS
+ Apple Silicon with Molfeat 1.0.0, datamol 0.13.0, RDKit 2026.03.6, and PyTorch 2.14.1.
```bash
- uv pip install "molfeat==0.11.0"
-
- # With all pip-installable optional dependencies
- uv pip install "molfeat[all]==0.11.0"
- ```
-
- **Optional dependency extras (PyPI):**
- - `molfeat[dgl]` — GNN models (GIN variants); upstream recommends `dgl<=2.0` (graphbolt issues in newer DGL)
- - `molfeat[graphormer]` — Graphormer models
- - `molfeat[transformer]` — ChemBERTa, ChemGPT, MolT5
- - `molfeat[fcd]` — FCD descriptors
- - `molfeat[pyg]` — PyTorch Geometric featurizers
- - `molfeat[viz]` — NGLView visualization widgets
-
- **External featurizers:** MAP4 is not bundled in molfeat extras — install from [reymond-group/map4](https://github.com/reymond-group/map4) separately. Some heavy deps (DGL, dgllife, graphormer-pretrained) are easier via conda-forge; see [optional dependencies](https://molfeat-docs.datamol.io/stable/).
-
- ## Core Concepts
-
- Molfeat organizes featurization into three hierarchical classes:
-
- ### 1. Calculators (`molfeat.calc`)
-
- Callable objects that convert individual molecules into feature vectors. Accept RDKit `Chem.Mol` objects or SMILES strings.
-
- **Use calculators for:**
- - Single molecule featurization
- - Custom processing loops
- - Direct feature computation
-
- **Example:**
- ```python
- from molfeat.calc import FPCalculator
-
- calc = FPCalculator("ecfp", radius=3, fpSize=2048)
- features = calc("CCO") # Returns numpy array (2048,)
- ```
-
- ### 2. Transformers (`molfeat.trans`)
-
- Scikit-learn compatible transformers that wrap calculators for batch processing with parallelization.
-
- **Use transformers for:**
- - Batch featurization of molecular datasets
- - Integration with scikit-learn pipelines
- - Parallel processing (automatic CPU utilization)
-
- **Example:**
- ```python
- from molfeat.trans import MoleculeTransformer
- from molfeat.calc import FPCalculator
-
- transformer = MoleculeTransformer(FPCalculator("ecfp"), n_jobs=-1)
- features = transformer(smiles_list) # Parallel processing
- ```
-
- ### 3. Pretrained Transformers (`molfeat.trans.pretrained`)
-
- Specialized transformers for deep learning models with batched inference and caching.
-
- **Use pretrained transformers for:**
- - State-of-the-art molecular embeddings
- - Transfer learning from large chemical datasets
- - Deep learning feature extraction
-
- **Example:**
- ```python
- from molfeat.trans.pretrained import PretrainedMolTransformer
-
- transformer = PretrainedMolTransformer("ChemBERTa-77M-MLM", n_jobs=-1)
- embeddings = transformer(smiles_list) # Deep learning embeddings
+ uv venv --python 3.13 .venv-molfeat
+ uv pip install --python .venv-molfeat/bin/python "molfeat==1.0.0"
```
- ## Quick Start Workflow
-
- ### Basic Featurization
-
- ```python
- import datamol as dm
- from molfeat.calc import FPCalculator
- from molfeat.trans import MoleculeTransformer
-
- # Load molecular data
- smiles = ["CCO", "CC(=O)O", "c1ccccc1", "CC(C)O"]
-
- # Create calculator and transformer
- calc = FPCalculator("ecfp", radius=3)
- transformer = MoleculeTransformer(calc, n_jobs=-1)
-
- # Featurize molecules
- features = transformer(smiles)
- print(f"Shape: {features.shape}") # (4, 2048)
- ```
+ On Windows use `.venv-molfeat\Scripts\python.exe` as the interpreter path. Upstream
+ supports Python 3.11–3.14; macOS Intel uses Python 3.11–3.12, PyTorch 2.2.x, NumPy<2,
+ and Transformers<5. Other platforms require PyTorch>=2.5. Let Molfeat's platform
+ markers resolve these constraints; do not copy Apple Silicon pins to Intel.
- ### Save and Load Configuration
+ Install only needed extras with the same interpreter: `molfeat[transformer]==1.0.0`
+ for Hugging Face models, `[mordred]` for mordredcommunity, `[pyg]` for graph tensors,
+ `[fcd]` for ChemNet embeddings, `[selfies]` for SELFIES conversion, `[cache]` for
+ HDF5/Parquet, `[viz]` for visualization, and `[cloud]` for S3/GCS stores. DGL and
+ Graphormer extras no longer exist. Pretrained inference may download substantial
+ weights; check model licensing, disk space, and device requirements first.
- ```python
- # Save featurizer configuration for reproducibility
- transformer.to_state_yaml_file("featurizer_config.yml")
+ ## Workflow
- # Reload exact configuration
- loaded = MoleculeTransformer.from_state_yaml_file("featurizer_config.yml")
- ```
+ 1. Preserve source record IDs, labels, original structures, and a declared policy for
+ salts, stereochemistry, tautomers, charge, and duplicate compounds. Standardization
+ changes chemical identity; apply the same policy to training and prediction.
+ 2. Start with an explicit ECFP baseline. A calculator processes one molecule;
+ `MoleculeTransformer` batches it. `datamol.Mol` is RDKit's molecule type.
+ 3. Record rejected positions and align every associated array. Inspect descriptor
+ NaN/Inf separately: successful parsing does not guarantee finite features.
+ 4. Fit any feature selection, imputation, scaling, and model inside the training fold.
+ Prefer scaffold/group or temporal splits appropriate to the scientific question;
+ random splits can leak close analogues or repeated measurements.
+ 5. Save the featurizer state, ordered feature names, package versions, molecular
+ preprocessing policy, and input IDs. Revalidate old state after migrating to 1.x.
- ### Handle Errors Gracefully
+ ### Fingerprint baseline and invalid records
```python
+ import numpy as np
from molfeat.calc import FPCalculator
from molfeat.trans import MoleculeTransformer
- smiles_with_errors = ["CCO", "invalid", "CC(=O)O"]
- transformer = MoleculeTransformer(FPCalculator("ecfp"), n_jobs=1)
- features, valid_ids = transformer(smiles_with_errors, ignore_errors=True)
- valid_smiles = [smiles_with_errors[i] for i in valid_ids]
+ smiles = ["CCO", "invalid", "CC(=O)O", "c1ccccc1"]
+ record_ids = np.array(["ethanol", "rejected", "acetate", "benzene"])
+ y = np.array([0.1, 9.9, 0.2, 0.3]) # toy labels only
+ calc = FPCalculator("ecfp", radius=2, fpSize=2048, includeChirality=True)
+ transformer = MoleculeTransformer(calc, n_jobs=1, dtype=np.float32)
+ X, valid_ids = transformer(smiles, ignore_errors=True)
+ assert X.shape == (3, 2048)
+ X_ids, y_valid = record_ids[valid_ids], y[valid_ids]
+ assert valid_ids == [0, 2, 3]
+ assert np.isfinite(X).all()
```
- Pass `ignore_errors` at call time. `__call__` removes failures and returns
- `(features, valid_ids)`; use those original positions to align labels and identifiers.
- For position-preserving output with `None` failures, use
- `transformer.transform(smiles_with_errors, ignore_errors=True)`.
-
- ## Choosing a Featurizer and Common Workflows
-
- Featurizer choice by task — traditional ML (RF, SVM, XGBoost), deep learning, similarity
- searching, and pharmacophore-based approaches — plus worked workflows for QSAR model
- building, virtual screening, similarity search, scikit-learn pipeline integration, and
- comparing multiple featurizers, are in
- [references/choosing_a_featurizer.md](references/choosing_a_featurizer.md).
-
- The full featurizer list is in
- [references/available_featurizers.md](references/available_featurizers.md); more examples
- are in [references/examples.md](references/examples.md).
-
- ## Discovering Available Featurizers
-
- Use the ModelStore to explore all available featurizers:
-
- ```python
- from molfeat.store.modelstore import ModelStore
-
- store = ModelStore()
-
- # List all available models
- all_models = store.available_models
- print(f"Total featurizers: {len(all_models)}")
-
- # Search for specific models
- chemberta_models = store.search(name="ChemBERTa")
- for model in chemberta_models:
- print(f"- {model.name}: {model.description}")
-
- # Get usage information
- model_card = store.search(name="ChemBERTa-77M-MLM")[0]
- model_card.usage() # Display usage examples
-
- # Load model
- transformer = store.load("ChemBERTa-77M-MLM")
- ```
+ `ignore_errors` belongs on the call, not the constructor. With `True`, `__call__`
+ returns filtered features and original input positions; with `False`, it raises on
+ failed molecules. `transform(..., ignore_errors=True)` preserves positions using
+ `None` for failures. Never filter each feature block independently and then concatenate.
- ## Advanced Features
+ ECFP radius is a bond radius: `radius=2` means ECFP4; radius 3 means ECFP6. In 1.0.0
+ `FPCalculator("ecfp")` defaults to radius 2 and 2048 bits. `FPVecTransformer` has a
+ *different* default length of 2000, so specify `length=2048` when using it.
- ### Custom Preprocessing
+ ### Configuration round trip
```python
- class CustomTransformer(MoleculeTransformer):
- def preprocess(self, mol):
- """Custom preprocessing pipeline"""
- if isinstance(mol, str):
- mol = dm.to_mol(mol)
- mol = dm.standardize_mol(mol)
- mol = dm.remove_salts(mol)
- return mol
-
- transformer = CustomTransformer(FPCalculator("ecfp"), n_jobs=-1)
+ transformer.to_state_yaml_file("featurizer.yml")
+ loaded = MoleculeTransformer.from_state_yaml_file("featurizer.yml")
+ np.testing.assert_array_equal(loaded(["CCO"]), transformer(["CCO"]))
```
- ### Batch Processing Large Datasets
-
- ```python
- import numpy as np
-
- def featurize_in_chunks(smiles_list, transformer, chunk_size=10000):
- """Process large datasets in chunks to manage memory"""
- all_features = []
- for i in range(0, len(smiles_list), chunk_size):
- chunk = smiles_list[i:i+chunk_size]
- features = transformer(chunk)
- all_features.append(features)
- return np.vstack(all_features)
- ```
+ Load only trusted configuration/artifacts. State can identify Python classes and
+ custom serialized callables; YAML/JSON does not make arbitrary third-party state safe.
+ State saves configuration, not assay labels, preprocessing decisions, or a trained QSAR model.
- ### Caching Expensive Embeddings
+ ### Pretrained embeddings
- Prefer molfeat's built-in pretrained-model cache when possible. For custom embedding caches, use NumPy arrays instead of pickle (pickle can execute arbitrary code when loading untrusted files):
+ Illustrative; imports and signatures were checked, but no model weights were downloaded:
```python
- import numpy as np
- from pathlib import Path
-
- cache_file = Path("embeddings_cache.npz") # fixed path under your project
- transformer = PretrainedMolTransformer("ChemBERTa-77M-MLM", n_jobs=-1)
-
- if cache_file.exists():
- embeddings = np.load(cache_file)["embeddings"]
- else:
- embeddings = transformer(smiles_list)
- np.savez(cache_file, embeddings=embeddings)
- ```
-
- ## Performance Tips
-
- 1. **Use parallelization**: Set `n_jobs=-1` to utilize all CPU cores
- 2. **Batch processing**: Process multiple molecules at once instead of loops
- 3. **Choose appropriate featurizers**: Fingerprints are faster than deep learning models
- 4. **Cache pretrained models**: Leverage built-in caching for repeated use
- 5. **Use float32**: Set `dtype=np.float32` when precision allows
- 6. **Handle errors efficiently**: Pass `ignore_errors=True` to the call and retain returned input positions
-
- ## Common Featurizers Reference
-
- **Quick reference for frequently used featurizers:**
-
- | Featurizer | Type | Dimensions | Speed | Use Case |
- |------------|------|------------|-------|----------|
- | `ecfp` | Fingerprint | 2048 | Fast | General purpose |
- | `maccs` | Fingerprint | 167 | Very fast | Scaffold similarity |
- | `desc2D` | Descriptors | 200+ | Fast | Interpretable models |
- | `mordred` | Descriptors | 1800+ | Medium | Comprehensive features |
- | `map4` | Fingerprint | 1024 | Fast | Large-scale screening |
- | `ChemBERTa-77M-MLM` | Deep learning | 768 | Slow* | Transfer learning |
- | `gin-supervised-masking` | GNN | Variable | Slow* | Graph-based models |
-
- *First run is slow; subsequent runs benefit from caching
-
- ## Resources
-
- This skill includes comprehensive reference documentation:
-
- ### references/api_reference.md
- Complete API documentation covering:
- - `molfeat.calc` - All calculator classes and parameters
- - `molfeat.trans` - Transformer classes and methods
- - `molfeat.store` - ModelStore usage
- - Common patterns and integration examples
- - Performance optimization tips
-
- **When to load:** Reference when implementing specific calculators, understanding transformer parameters, or integrating with scikit-learn/PyTorch.
-
- ### references/available_featurizers.md
- Comprehensive catalog of all 100+ featurizers organized by category:
- - Transformer-based language models (ChemBERTa, ChemGPT)
- - Graph neural networks (GIN, Graphormer)
- - Molecular descriptors (RDKit, Mordred)
- - Fingerprints (ECFP, MACCS, MAP4, and 15+ others)
- - Pharmacophore descriptors (CATS, Gobbi)
- - Shape descriptors (USR, ElectroShape)
- - Scaffold-based descriptors
-
- **When to load:** Reference when selecting the optimal featurizer for a specific task, exploring available options, or understanding featurizer characteristics.
+ from molfeat.trans.pretrained import PretrainedHFTransformer
- **Search tip:** Use grep to find specific featurizer types:
- ```bash
- grep -i "chembert" references/available_featurizers.md
- grep -i "pharmacophore" references/available_featurizers.md
+ embedder = PretrainedHFTransformer(
+ kind="ChemBERTa-77M-MLM", pooling="mean", concat_layers=-1,
+ device="cpu", max_length=128, preload=False,
+ )
+ # First inference downloads/loads the model.
+ # embeddings = embedder(["CCO", "c1ccccc1"])
```
- ### references/examples.md
- Practical code examples for common scenarios:
- - Installation and quick start
- - Calculator and transformer examples
- - Pretrained model usage
- - Scikit-learn and PyTorch integration
- - Virtual screening workflows
- - QSAR model building
- - Similarity searching
- - Troubleshooting and best practices
+ `PretrainedMolTransformer` is a base class, not a model-name factory. Use the concrete
+ adapter. Embedding width depends on checkpoint, pooling, and selected layers; do not
+ assume 768. Inspect token lengths: truncation at `max_length` can discard chemical
+ information. Keep the model revision, tokenizer, notation, pooling, and maximum
+ length with every saved embedding cache.
- **When to load:** Reference when implementing specific workflows, troubleshooting issues, or learning molfeat patterns.
+ ## Select and discover representations
- ## Troubleshooting
+ | Need | Starting point | Check |
+ | --- | --- | --- |
+ | Fingerprint baseline | `FPCalculator("ecfp", radius=2, fpSize=2048)` | Chirality, bit collisions, fixed parameters |
+ | Structural keys | `FPCalculator("maccs")` | 167 entries, including unused bit zero |
+ | Named descriptors | `RDKitDescriptors2D()` | Columns depend on RDKit; inspect nonfinite values |
+ | Pharmacophore pairs | `CATS()` | Distance bins determine width; 2D default is 189 |
+ | 3D shape | `USRDescriptors()` / `USRDescriptors("USRCAT")` | Conformer needed; 12 / 60 entries |
+ | Pretrained language model | `PretrainedHFTransformer(...)` | Weights, license, tokenization, pooling |
- ### Invalid Molecules
- Use the call-time error handling shown above. Never pair filtered feature rows with
- unfiltered labels: retain `valid_ids` and record rejected input identifiers.
+ See [available featurizers](references/available_featurizers.md) for valid names and
+ optional backends, [API contracts](references/api_reference.md) for batch/store
+ semantics, [worked examples](references/examples.md) for preprocessing, concatenation,
+ 3D and similarity, and [model selection](references/choosing_a_featurizer.md) for
+ leakage-aware QSAR and bounded-memory screening.
- ### Memory Issues with Large Datasets
- Process in chunks or use streaming approaches for datasets > 100K molecules.
+ For discovery, construct `ModelStore()` and inspect `available_models` or use exact
+ `search(name=...)`. The first discovery call reads public HTTPS metadata. A card's
+ `usage()` returns code as a string; review it rather than execute it automatically.
+ `store.load(...)` returns `(artifact, ModelInfo)`, not a featurizer. Historical cards
+ are not proof that an adapter is supported.
- ### Pretrained Model Dependencies
- Some models require additional packages. Install specific extras (pin version for reproducibility):
- ```bash
- uv pip install "molfeat[transformer]==0.11.0" # For ChemBERTa/ChemGPT
- uv pip install "molfeat[dgl]==0.11.0" # For GIN models
- uv pip install "molfeat[graphormer]==0.11.0" # For Graphormer
- ```
+ ## Performance and reproducibility
- ### Reproducibility
- Save exact configurations and document versions:
- ```python
- transformer.to_state_yaml_file("config.yml")
- import molfeat
- print(f"molfeat version: {molfeat.__version__}")
- ```
+ Use `n_jobs=1` for small jobs and debugging. Benchmark bounded parallelism on the actual
+ workload; `n_jobs=-1` can multiply memory use and nested scikit-learn parallelism.
+ Persist each chunk or score it before moving on; accumulating every chunk and calling
+ `vstack` still requires the full matrix in memory. Cache keys must include molecule
+ identity, preprocessing, all featurizer settings, package/model versions, and row order.
- ## Additional Resources
+ ## Sources and verification
- - **Official Documentation**: https://molfeat-docs.datamol.io/
- - **GitHub Repository**: https://github.com/datamol-io/molfeat
- - **PyPI Package**: https://pypi.org/project/molfeat/
- - **Tutorial**: https://portal.valencelabs.com/datamol/post/types-of-featurizers-b1e8HHrbFMkbun6
+ Reviewed 2026-10-01 against the [release](https://github.com/datamol-io/molfeat/releases/tag/1.0.0),
+ [package metadata](https://pypi.org/project/molfeat/1.0.0/), and
+ [tagged source](https://github.com/datamol-io/molfeat/tree/1.0.0/molfeat).
+ Local tests cover core featurization contracts and small synthetic workflows; they do
+ not establish predictive validity or pretrained/optional-backend inference support.
## Citing Scientific Agent Skills
This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a
manuscript, report, presentation, or code release, add the paper to the references or
software section and tell the user you did so:
> Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent
> Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065.
> https://doi.org/10.48550/arXiv.2609.00065
Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the
latest arXiv version, so never append a version suffix such as `v1`. When network access is
available, fetch https://arxiv.org/abs/2609.00065 (or
http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take
the author list, year, and version from that record. If the record lists a journal reference
or publisher DOI, cite the published version instead.