Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Molecular featurization for ML (100+ featurizers). ECFP, MACCS, descriptors, pretrained models (ChemBERTa), convert SMILES to features, for QSAR and molecular ML.
.claude/skills/lingxling-molfeat/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-12 | ✗→✓ | ▲ Improved | 126% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 65% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 127% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 136% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 140% | 0% |
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.
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.
This skill should be used when working with:
Use a Python 3.9 or 3.10 environment (molfeat does not install on 3.11+ as of 0.11.0):
bashuv 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 modelsmolfeat[transformer] — ChemBERTa, ChemGPT, MolT5molfeat[fcd] — FCD descriptorsmolfeat[pyg] — PyTorch Geometric featurizersmolfeat[viz] — NGLView visualization widgetsExternal featurizers: MAP4 is not bundled in molfeat extras — install from reymond-group/map4 separately. Some heavy deps (DGL, dgllife, graphormer-pretrained) are easier via conda-forge; see optional dependencies.
Molfeat organizes featurization into three hierarchical classes:
molfeat.calc)Callable objects that convert individual molecules into feature vectors. Accept RDKit Chem.Mol objects or SMILES strings.
Use calculators for:
Example:
pythonfrom molfeat.calc import FPCalculator calc = FPCalculator("ecfp", radius=3, fpSize=2048) features = calc("CCO") # Returns numpy array (2048,)
molfeat.trans)Scikit-learn compatible transformers that wrap calculators for batch processing with parallelization.
Use transformers for:
Example:
pythonfrom molfeat.trans import MoleculeTransformer from molfeat.calc import FPCalculator transformer = MoleculeTransformer(FPCalculator("ecfp"), n_jobs=-1) features = transformer(smiles_list) # Parallel processing
molfeat.trans.pretrained)Specialized transformers for deep learning models with batched inference and caching.
Use pretrained transformers for:
Example:
pythonfrom molfeat.trans.pretrained import PretrainedMolTransformer transformer = PretrainedMolTransformer("ChemBERTa-77M-MLM", n_jobs=-1) embeddings = transformer(smiles_list) # Deep learning embeddings
pythonimport 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)
python# Save featurizer configuration for reproducibility transformer.to_state_yaml_file("featurizer_config.yml") # Reload exact configuration loaded = MoleculeTransformer.from_state_yaml_file("featurizer_config.yml")
python# Process dataset with potentially invalid SMILES transformer = MoleculeTransformer( calc, n_jobs=-1, ignore_errors=True, # Continue on failures verbose=True # Log error details ) features = transformer(smiles_with_errors) # Returns None for failed molecules
Start with fingerprints:
python# ECFP - Most popular, general-purpose FPCalculator("ecfp", radius=3, fpSize=2048) # MACCS - Fast, good for scaffold hopping FPCalculator("maccs") # MAP4 - Efficient for large-scale screening FPCalculator("map4")
For interpretable models:
python# RDKit 2D descriptors (200+ named properties) from molfeat.calc import RDKitDescriptors2D RDKitDescriptors2D() # Mordred (1800+ comprehensive descriptors) from molfeat.calc import MordredDescriptors MordredDescriptors()
Combine multiple featurizers:
pythonfrom molfeat.trans import FeatConcat concat = FeatConcat([ FPCalculator("maccs"), # 167 dimensions FPCalculator("ecfp") # 2048 dimensions ]) # Result: 2215-dimensional combined features
Transformer-based embeddings:
python# ChemBERTa - Pre-trained on 77M PubChem compounds PretrainedMolTransformer("ChemBERTa-77M-MLM") # ChemGPT - Autoregressive language model PretrainedMolTransformer("ChemGPT-1.2B")
Graph neural networks:
python# GIN models with different pre-training objectives PretrainedMolTransformer("gin-supervised-masking") PretrainedMolTransformer("gin-supervised-infomax") # Graphormer for quantum chemistry PretrainedMolTransformer("Graphormer-pcqm4mv2")
python# ECFP - General purpose, most widely used FPCalculator("ecfp") # MACCS - Fast, scaffold-based similarity FPCalculator("maccs") # MAP4 - Efficient for large databases FPCalculator("map4") # USR/USRCAT - 3D shape similarity from molfeat.calc import USRDescriptors USRDescriptors()
python# FCFP - Functional group based FPCalculator("fcfp") # CATS - Pharmacophore pair distributions from molfeat.calc import CATSCalculator CATSCalculator(mode="2D") # Gobbi - Explicit pharmacophore features FPCalculator("gobbi2D")
pythonfrom molfeat.trans import MoleculeTransformer from molfeat.calc import FPCalculator from sklearn.ensemble import RandomForestRegressor from sklearn.model_selection import cross_val_score # Featurize molecules transformer = MoleculeTransformer(FPCalculator("ecfp"), n_jobs=-1) X = transformer(smiles_train) # Train model model = RandomForestRegressor(n_estimators=100) scores = cross_val_score(model, X, y_train, cv=5) print(f"R² = {scores.mean():.3f}") # Save configuration for deployment transformer.to_state_yaml_file("production_featurizer.yml")
pythonfrom sklearn.ensemble import RandomForestClassifier # Train on known actives/inactives transformer = MoleculeTransformer(FPCalculator("ecfp"), n_jobs=-1) X_train = transformer(train_smiles) clf = RandomForestClassifier(n_estimators=500) clf.fit(X_train, train_labels) # Screen large library X_screen = transformer(screening_library) # e.g., 1M compounds predictions = clf.predict_proba(X_screen)[:, 1] # Rank and select top hits top_indices = predictions.argsort()[::-1][:1000] top_hits = [screening_library[i] for i in top_indices]
pythonfrom sklearn.metrics.pairwise import cosine_similarity # Query molecule calc = FPCalculator("ecfp") query_fp = calc(query_smiles).reshape(1, -1) # Database fingerprints transformer = MoleculeTransformer(calc, n_jobs=-1) database_fps = transformer(database_smiles) # Compute similarity similarities = cosine_similarity(query_fp, database_fps)[0] top_similar = similarities.argsort()[-10:][::-1]
pythonfrom sklearn.pipeline import Pipeline from sklearn.ensemble import RandomForestClassifier # Create end-to-end pipeline pipeline = Pipeline([ ('featurizer', MoleculeTransformer(FPCalculator("ecfp"), n_jobs=-1)), ('classifier', RandomForestClassifier(n_estimators=100)) ]) # Train and predict directly on SMILES pipeline.fit(smiles_train, y_train) predictions = pipeline.predict(smiles_test)
pythonfeaturizers = { 'ECFP': FPCalculator("ecfp"), 'MACCS': FPCalculator("maccs"), 'Descriptors': RDKitDescriptors2D(), 'ChemBERTa': PretrainedMolTransformer("ChemBERTa-77M-MLM") } results = {} for name, feat in featurizers.items(): transformer = MoleculeTransformer(feat, n_jobs=-1) X = transformer(smiles) # Evaluate with your ML model score = score_model(X, y) results[name] = score
Use the ModelStore to explore all available featurizers:
pythonfrom 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")
pythonclass 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)
pythonimport 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)
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):
pythonimport 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)
n_jobs=-1 to utilize all CPU coresdtype=np.float32 when precision allowsignore_errors=True for large datasetsQuick 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
This skill includes comprehensive reference documentation:
Complete API documentation covering:
molfeat.calc - All calculator classes and parametersmolfeat.trans - Transformer classes and methodsmolfeat.store - ModelStore usageWhen to load: Reference when implementing specific calculators, understanding transformer parameters, or integrating with scikit-learn/PyTorch.
Comprehensive catalog of all 100+ featurizers organized by category:
When to load: Reference when selecting the optimal featurizer for a specific task, exploring available options, or understanding featurizer characteristics.
Search tip: Use grep to find specific featurizer types:
bashgrep -i "chembert" references/available_featurizers.md grep -i "pharmacophore" references/available_featurizers.md
Practical code examples for common scenarios:
When to load: Reference when implementing specific workflows, troubleshooting issues, or learning molfeat patterns.
Enable error handling to skip invalid SMILES:
pythontransformer = MoleculeTransformer( calc, ignore_errors=True, verbose=True )
Process in chunks or use streaming approaches for datasets > 100K molecules.
Some models require additional packages. Install specific extras (pin version for reproducibility):
bashuv 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
Save exact configurations and document versions:
pythontransformer.to_state_yaml_file("config.yml") import molfeat print(f"molfeat version: {molfeat.__version__}")
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-12 | fail→pass | 19,908 | 20,535 | +3% | 1 | 1 | 0% | 3,732 | 8,423 | +126% | 0 | 0 | — |
case-13 | fail→fail | 20,893 | 12,794 | -39% | 1 | 1 | 0% | 3,252 | 6,303 | +94% | 0 | 0 | — |
case-14 | pass→fail | 15,750 | 18,130 | +15% | 1 | 1 | 0% | 3,137 | 8,005 | +155% | 0 | 0 | — |
case-01 | pass→pass | 25,463 | 20,328 | -20% | 1 | 1 | 0% | 5,158 | 8,590 | +67% | 0 | 0 | — |
case-02 | fail→pass | 42,426 | 15,321 | -64% | 1 | 1 | 0% | 3,839 | 6,350 | +65% | 0 | 0 | — |
case-03 | fail→pass | 17,865 | 9,938 | -44% | 1 | 1 | 0% | 2,814 | 6,378 | +127% | 0 | 0 | — |
case-04 | fail→pass | 14,797 | 11,479 | -22% | 1 | 1 | 0% | 2,522 | 5,940 | +136% | 0 | 0 | — |
case-05 | pass→pass | 12,694 | 7,604 | -40% | 1 | 1 | 0% | 2,331 | 5,787 | +148% | 0 | 0 | — |
case-06 | fail→pass | 18,257 | 16,278 | -11% | 1 | 1 | 0% | 3,153 | 7,555 | +140% | 0 | 0 | — |
case-07 | fail→pass | 27,100 | 5,807 | -79% | 1 | 1 | 0% | 5,198 | 5,430 | +4% | 0 | 0 | — |
case-08 | fail→pass | 14,116 | 6,814 | -52% | 1 | 1 | 0% | 2,756 | 5,670 | +106% | 0 | 0 | — |
case-09 | fail→pass | 24,749 | 6,616 | -73% | 1 | 1 | 0% | 3,588 | 5,698 | +59% | 0 | 0 | — |
case-10 | fail→pass | 26,760 | 4,305 | -84% | 1 | 1 | 0% | 4,047 | 5,095 | +26% | 0 | 0 | — |
case-11 | pass→pass | 6,281 | 4,159 | -34% | 1 | 1 | 0% | 1,128 | 5,029 | +346% | 0 | 0 | — |
case-15 | fail→pass | 17,288 | 10,459 | -40% | 1 | 1 | 0% | 2,854 | 6,057 | +112% | 0 | 0 | — |
case-16 | pass→pass | 12,304 | 7,247 | -41% | 1 | 1 | 0% | 2,211 | 5,562 | +152% | 0 | 0 | — |
case-17 | fail→pass | 22,874 | 8,648 | -62% | 1 | 1 | 0% | 3,479 | 5,644 | +62% | 0 | 0 | — |
case-18 | pass→pass | 21,197 | 6,863 | -68% | 1 | 1 | 0% | 3,115 | 5,271 | +69% | 0 | 0 | — |
case-19 | fail→pass | 10,509 | 4,930 | -53% | 1 | 1 | 0% | 1,569 | 5,247 | +234% | 0 | 0 | — |
case-20 | pass→pass | 14,565 | 12,170 | -16% | 1 | 1 | 0% | 2,606 | 6,173 | +137% | 0 | 0 | — |
case-21 | pass→pass | 16,332 | 10,518 | -36% | 1 | 1 | 0% | 2,286 | 5,983 | +162% | 0 | 0 | — |
case-22 | pass→pass | 5,138 | 6,847 | +33% | 1 | 1 | 0% | 977 | 5,207 | +433% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +50 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.