---
name: molfeat
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.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: "2.0"
  skill-author: K-Dense Inc.
  last-reviewed: "2026-10-01"
  upstream-version: "1.0.0"
title: molfeat
canonical_url: https://skilld.dev/gh/k-dense-ai/scientific-agent-skills/molfeat
last_updated: 2026-10-11T01:07:01.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/api_reference.md](https://skilld.dev/api/skills-raw/k-dense-ai/scientific-agent-skills/molfeat/references/api_reference.md), [references/available_featurizers.md](https://skilld.dev/api/skills-raw/k-dense-ai/scientific-agent-skills/molfeat/references/available_featurizers.md), [references/choosing_a_featurizer.md](https://skilld.dev/api/skills-raw/k-dense-ai/scientific-agent-skills/molfeat/references/choosing_a_featurizer.md), [references/examples.md](https://skilld.dev/api/skills-raw/k-dense-ai/scientific-agent-skills/molfeat/references/examples.md).
>
> If the user asked to install this Skill, run `npx skilld install k-dense-ai/scientific-agent-skills/molfeat`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/molfeat`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/k-dense-ai/scientific-agent-skills/molfeat) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/molfeat`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/molfeat --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/molfeat --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Molfeat — Small-molecule featurization

## When to use

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 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

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 venv --python 3.13 .venv-molfeat
uv pip install --python .venv-molfeat/bin/python "molfeat==1.0.0"
```

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.

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.

## Workflow

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.

### Fingerprint baseline and invalid records

```python
import numpy as np
from molfeat.calc import FPCalculator
from molfeat.trans import MoleculeTransformer

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()
```

`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.

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.

### Configuration round trip

```python
transformer.to_state_yaml_file("featurizer.yml")
loaded = MoleculeTransformer.from_state_yaml_file("featurizer.yml")
np.testing.assert_array_equal(loaded(["CCO"]), transformer(["CCO"]))
```

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.

### Pretrained embeddings

Illustrative; imports and signatures were checked, but no model weights were downloaded:

```python
from molfeat.trans.pretrained import PretrainedHFTransformer

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"])
```

`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.

## Select and discover representations

| 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 |

See [available featurizers](https://skilld.dev/api/skills-raw/k-dense-ai/scientific-agent-skills/molfeat/references/available_featurizers.md) for valid names and
optional backends, [API contracts](https://skilld.dev/api/skills-raw/k-dense-ai/scientific-agent-skills/molfeat/references/api_reference.md) for batch/store
semantics, [worked examples](https://skilld.dev/api/skills-raw/k-dense-ai/scientific-agent-skills/molfeat/references/examples.md) for preprocessing, concatenation,
3D and similarity, and [model selection](https://skilld.dev/api/skills-raw/k-dense-ai/scientific-agent-skills/molfeat/references/choosing_a_featurizer.md) for
leakage-aware QSAR and bounded-memory screening.

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.

## Performance and reproducibility

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.

## Sources and verification

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.
