本文へ移動
cccskills
無料GitHub で公開

molfeat

Molecular featurization hub with one consistent interface over 100+ featurizers. Fingerprints (ECFP/Morgan, MACCS, atom pair, topological torsion, Avalon, RDKit, ERG), RDKit and Mordred descriptor sets, pharmacophore and 3D shape descriptors, scaffold keys, and pretrained embeddings (ChemBERTa, ChemGPT, MolT5, GIN, Graphormer) through a common transformer API with caching and parallelism. Use this skill to convert SMILES into model-ready feature matrices for QSAR, virtual screening, and molecular ML, and to choose between featurizer families. Also trigger on molfeat, MoleculeTransformer, FPVecTransformer, PretrainedHFTransformer, molfeat model store, or featurizer selection.

インストール方法を見る

含まれるファイル(5)

  • SKILL.md18.3 KB
  • references/api_reference.md16.2 KB
  • references/available_featurizers.md9.9 KB
  • references/choosing_a_featurizer.md8.4 KB
  • references/examples.md14.5 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Molfeat - Molecular Featurization Hub

Overview

Molfeat turns molecules (SMILES strings or RDKit/datamol Mol objects) into numerical representations for machine learning: fingerprints, descriptors, pharmacophores, shape descriptors, and pretrained neural embeddings, all behind one scikit-learn-compatible transformer interface with state serialization and caching.

Current baseline (verified 2026-08-16): molfeat 0.11.0 (May 2025) is still the latest PyPI and GitHub release; the repository has had no commits since. All examples in this skill were executed against 0.11.0 on Python 3.10 with datamol 0.12.5, RDKit 2026.03.5, numpy 2.2.6 and torch 2.13.0. Python 3.11+ is not installable (requires-python = ">=3.9,<3.11").

The Python cap isolates this skill from the rest of the bundle. Nothing else here needs an interpreter below 3.11, so molfeat requires its own environment and cannot share one with admet-prediction (3.11+), pytdc, or deepchem. That is manageable for a featurisation step that writes a matrix to disk, and painful for anything interactive. For new work where the featuriser is not itself the point, RDKit or datamol fingerprints plus a Chemprop or scikit-learn model reach the same place without the constraint; use molfeat when you specifically want its breadth of featurisers behind one interface. 0.11.0 loads pretrained models in memory, sets base models to eval mode, and moved the model store to a Cloudflare HTTP bucket (PR #115) — that last change broke store downloads for the HuggingFace models (see Pretrained models).

When to Use This Skill

  • Converting SMILES into ML-ready feature matrices (QSAR/QSPR, ADMET, activity prediction)
  • Virtual screening: featurize a library, score it with a trained model
  • Similarity searching and chemical-space analysis (clustering, UMAP/t-SNE)
  • Benchmarking several representations against each other on the same task
  • Building reproducible featurization pipelines that can be serialized and reloaded

For raw cheminformatics control (custom sanitization, reactions, substructures) use rdkit or datamol directly; molfeat is the layer above them that produces feature matrices.

Installation

uv venv --python 3.10 && uv pip install "molfeat==0.11.0"

Optional extras (all pin-able the same way):

ExtraEnablesNote
molfeat[transformer]ChemBERTa, ChemGPT, MolT5, GPT2/Roberta-ZincPins tokenizers<0.13.2, so it resolves to transformers 4.33.x
molfeat[dgl]GIN variants, JTVAENeeds dgl>=1.1.1,<=2.0; conda-forge is easier than PyPI
molfeat[graphormer]pcqm4mv2_graphormer_basegraphormer-pretrained
molfeat[fcd]FCD descriptors
molfeat[pyg]PyTorch Geometric featurizers
molfeat[viz]NGLView widgets

MAP4 is not a molfeat extra. FPCalculator("map4") raises ImportError: Cannot import map4 until you install it from reymond-group/map4.

Three Things to Get Right First

These three calls are where most molfeat scripts go wrong; everything else follows the docs.

import numpy as np
from molfeat.trans import MoleculeTransformer

# 1. Without `dtype`, the transformer returns a LIST of arrays, not a matrix.
#    `features.shape` raises AttributeError. Pass dtype to get an ndarray.
transformer = MoleculeTransformer("ecfp", dtype=np.float32)

# 2. `ignore_errors` is a CALL argument, not a constructor argument. Passing it to
#    the constructor is silently swallowed by **params and does nothing.
features, valid_ids = transformer(smiles, ignore_errors=True)

# 3. With ignore_errors=True, __call__ returns (features, ids) and DROPS failures.
#    Realign the labels with `ids` or the rows no longer match y.
y = np.asarray(y)[valid_ids]

transformer.transform(smiles, ignore_errors=True) is the other half of the pair: it returns a plain list with None in the failed positions instead of dropping them.

Core Concepts

1. Calculators (molfeat.calc)

Callable objects that featurize one molecule. Exported from molfeat.calc: FPCalculator, RDKitDescriptors2D, RDKitDescriptors3D, MordredDescriptors, CATS, Pharmacophore2D, Pharmacophore3D, USRDescriptors, ElectroShapeDescriptors, ScaffoldKeyCalculator, plus the SerializableCalculator base class. Atom- and bond-level calculators for GNN input live one level deeper, in molfeat.calc.atom and molfeat.calc.bond.

from molfeat.calc import FPCalculator, get_calculator

calc = FPCalculator("ecfp", radius=2, fpSize=2048)   # radius 2 is the default (= ECFP4)
fp = calc("CCO")            # numpy uint8 array, shape (2048,)
len(calc)                   # 2048
calc.columns[:3]            # ['fp_0', 'fp_1', 'fp_2']

calc = get_calculator("desc2D")   # factory: any built-in by name

get_calculator accepts every name in FP_FUNCS plus desc2D, desc3D, mordred, cats, cats2D, cats3D, pharm2D, pharm3D, usr*, electroshape, and scaffoldkeys.

2. Transformers (molfeat.trans)

MoleculeTransformer wraps a calculator (or a calculator name) for batch use and plugs into scikit-learn pipelines. FPVecTransformer is the fingerprint-specific shortcut, and unlike MoleculeTransformer it defaults to dtype=np.float32, so it returns an array out of the box.

import numpy as np
from molfeat.trans import MoleculeTransformer, FPVecTransformer, FeatConcat

t = MoleculeTransformer("ecfp", n_jobs=1, dtype=np.float32)
X = t(smiles)                                   # (n, 2048) float32

fp = FPVecTransformer(kind="ecfp:4", length=1024)   # "name:diameter"; length defaults to 2000
X = fp(smiles)                                      # (n, 1024) float32

both = FeatConcat(["maccs", "ecfp"], dtype=np.float32)
X = both(smiles)                                # (n, 2167) — 167 + 2048

FeatConcat is itself a transformer. Do not wrap it in MoleculeTransformer.

3. Pretrained transformers (molfeat.trans.pretrained)

One class per backend — there is no generic "load by name" transformer:

ClassForExample
PretrainedHFTransformerChemBERTa, ChemGPT, MolT5, GPT2/Roberta-ZincPretrainedHFTransformer(kind="ChemBERTa-77M-MLM", notation="smiles")
PretrainedDGLTransformerGIN variants, JTVAEPretrainedDGLTransformer(kind="gin_supervised_masking", dtype=float)
GraphormerTransformerGraphormerGraphormerTransformer(kind="pcqm4mv2_graphormer_base", dtype=float)
FCDTransformerFCD embeddingsFCDTransformer()

PretrainedMolTransformer is the abstract base for these — instantiating it with a model name does not work.

Pretrained models

The 8 HuggingFace models in the model store cannot be downloaded from it. Since 0.11.0 serves artifacts over plain HTTP, HTTPFileSystem.find() reports the artifact directory itself as a file, so datamol's copy_dir tries to write a file over the destination directory:

IsADirectoryError: [Errno 21] Is a directory: '~/Library/Caches/molfeat/ChemBERTa-77M-MLM/model.save'
ModelStoreError: Can't retrieve model ChemBERTa-77M-MLM from the store !

This is not a version-pin problem — it reproduces on fsspec 2024.6.1, 2025.3.0 and 2026.7.0 — and it is open upstream as #119 and #120. It affects only the 8 HuggingFace cards (ChemBERTa x2, ChemGPT x3, MolT5, GPT2-Zinc480M-87M, Roberta-Zinc480M-102M); the 36 other cards are single-file artifacts and download normally.

Load those models from the HuggingFace Hub instead — verified working:

import numpy as np
from molfeat.trans.pretrained.hf_transformers import HFModel, PretrainedHFTransformer

model = HFModel.from_pretrained("DeepChem/ChemBERTa-77M-MLM", "DeepChem/ChemBERTa-77M-MLM")
transformer = PretrainedHFTransformer(kind=model, notation="smiles", dtype=np.float32)
X = transformer(["CCO", "CC(=O)O", "c1ccccc1"])     # (3, 384) float32, mean pooling

Note the width: ChemBERTa-77M is 384-dimensional, not 768. Check X.shape rather than assuming a hidden size.

Pooling defaults to mean; avg, sum, and clf (CLS token) also work. pooling="max" raises RuntimeError: masked_fill_ only supports boolean masks on current PyTorch — molfeat builds a long mask — so avoid it.

Discovering featurizers

from molfeat.store.modelstore import ModelStore

store = ModelStore()
len(store.available_models)        # 44 cards in 0.11.0

card = store.search(name="ChemBERTa-77M-MLM")[0]
print(card.name, card.group, card.inputs, card.description)
print(card.usage())                # returns the canonical snippet as a string

store.load(name) returns a (model, ModelInfo) tuple, not a transformer — use the transformer classes above for featurization, and store.load only when you want the raw artifact. A full name-by-name catalog is in references/available_featurizers.md.

Quick Start

import numpy as np
import datamol as dm
from molfeat.trans import MoleculeTransformer

data = dm.data.freesolv()                       # 642 molecules: iupac, smiles, expt, calc
smiles = data.smiles.tolist()

transformer = MoleculeTransformer("ecfp", n_jobs=1, dtype=np.float32)
X, ids = transformer(smiles, ignore_errors=True)
y = data.expt.values[ids]
print(X.shape, y.shape)                         # (642, 2048) (642,)

Save and reload a configuration

transformer.to_state_yaml_file("featurizer.yml")     # also to_state_json_file
loaded = MoleculeTransformer.from_state_yaml_file("featurizer.yml")

The state file records the molfeat version alongside the featurizer arguments, which is what makes it worth committing next to a trained model.

Standardize before featurizing

preprocess() is a batch hook with the signature preprocess(inputs, labels), and transform never calls it. Overriding it per-molecule does nothing. Standardize explicitly instead:

import datamol as dm

def clean(smi):
    mol = dm.to_mol(smi)
    if mol is None:
        return None
    # dont_remove_everything=True, or a molecule that IS a solvent comes back empty
    mol = dm.remove_salts_solvents(mol, dont_remove_everything=True)
    return dm.to_smiles(dm.standardize_mol(mol, disconnect_metals=True, uncharge=True))

clean_smiles = [s for s in dm.parallelized(clean, smiles, n_jobs=-1) if s]
X = transformer(clean_smiles)

(dm.remove_salts does not exist; the function is dm.remove_salts_solvents.)

Caching expensive featurization

Use molfeat's own cache rather than a hand-rolled dictionary — it hashes molecules canonically, so a re-run hits the cache even when the input SMILES are written differently:

import numpy as np
from molfeat.trans import MoleculeTransformer
from molfeat.trans.base import PrecomputedMolTransformer
from molfeat.utils.cache import FileCache

base = MoleculeTransformer("desc2D", n_jobs=-1, dtype=np.float32)
cache = FileCache(cache_file="features.parquet", file_type="parquet", clear_on_exit=False)

featurizer = PrecomputedMolTransformer(cache=cache, featurizer=base, dtype=np.float32)
X = featurizer(smiles)
cache.save_to_file("features.parquet")

# next run
cache = FileCache.load_from_file("features.parquet", file_type="parquet")
featurizer = PrecomputedMolTransformer(cache=cache, featurizer=base, dtype=np.float32)

molfeat.utils.cache also offers in-memory DataCache, multiprocessing-safe MPDataCache, and CacheList for chaining. Prefer these over pickling feature matrices yourself; if you do persist arrays directly, use np.savez, not pickle, which executes code on load.

Parallelism: measure before setting n_jobs=-1

n_jobs=-1 is not free — molfeat parallelizes with joblib processes, and the pickling overhead exceeds the work for cheap featurizers. Measured on 12 cores:

FeaturizerMoleculesn_jobs=1n_jobs=-1
ecfp6420.03 s0.13 s
ecfp10,2720.43 s0.56 s
desc2D3000.96 s0.23 s
mordred3004.83 s4.21 s

Rule of thumb: keep n_jobs=1 for fingerprints at any scale, use n_jobs=-1 for descriptor and conformer-dependent calculators (desc2D, desc3D, pharmacophores, shape), and don't expect much from it for mordred, which does its own batching through batch_compute.

Choosing a Featurizer and Common Workflows

Featurizer choice by task — traditional ML (RF, SVM, XGBoost), deep learning, similarity searching, pharmacophore-based approaches — plus worked workflows for QSAR model building, virtual screening, similarity search, scikit-learn pipeline integration, and comparing featurizers, are in references/choosing_a_featurizer.md.

The full featurizer catalog with measured output widths is in references/available_featurizers.md; more worked code is in references/examples.md; class-by-class signatures are in references/api_reference.md.

Common Featurizers Reference

Widths below are what molfeat 0.11.0 actually returns for default parameters.

FeaturizerTypeWidthSpeedUse case
ecfpFingerprint2048FastGeneral purpose (radius 2 default)
fcfpFingerprint2048FastPharmacophore-flavored circular FP
maccsFingerprint167Very fastScaffold similarity
avalonFingerprint512FastSimilarity searching
ergReduced graph315FastScaffold hopping
estateDescriptors79FastElectrotopological state
desc2DDescriptors223MediumInterpretable models
desc3DDescriptors639SlowNeeds conformers
mordredDescriptors1613SlowComprehensive descriptor sweep
cats2DPharmacophore189MediumPharmacophore pair distributions
pharm2DPharmacophore2048Mediumfactory="pmapper" by default
usr / usrcatShape12 / 60Fast3D shape similarity (needs conformers)
scaffoldkeysScaffold42FastScaffold-level properties
ChemBERTa-77M-MLMTransformer384SlowTransfer learning (load from HF Hub)
gin_supervised_maskingGNN300SlowGraph embeddings (needs molfeat[dgl])

Troubleshooting

AttributeError: 'list' object has no attribute 'shape' — the transformer has no dtype. Construct it with dtype=np.float32 (or use FPVecTransformer).

ValueError: Cannot transform molecule at index i — an input failed to parse. Pass ignore_errors=True to the call, and use the returned ids to realign labels. Set verbose=True on the constructor to log which molecules failed.

ModelStoreError: Can't retrieve model <name> from the store! — the HuggingFace-artifact download bug above. Load from the HF Hub with HFModel.from_pretrained.

A fingerprint parameter had no effect — FPCalculator logs unknown parameters as an error and then drops them; construction still succeeds. FPCalculator("ecfp", n_bits=1024) returns 2048 dimensions (the key is fpSize). Check len(calc) after passing parameters.

ImportError: Cannot import map4 — MAP4 is external; install it from the reymond-group repository.

Package will not install — check the interpreter first: molfeat 0.11.0 is capped below Python 3.11 and pip/uv will refuse to resolve on 3.11+.

3D featurizers return errors or zeros — desc3D, usr, usrcat, electroshape, cats3D and pharm3D need conformers. Generate them first with dm.conformers.generate(mol, n_confs=1) and pass Mol objects, not SMILES.

Reproducibility — save to_state_yaml_file next to the model, and record molfeat.__version__; state files carry the writing version in _molfeat_version.

Composing with the rest of the bundle

  • rdkit / datamol → before: standardise and desalt first. A featurizer embeds whatever string it is given, so a salt or mixture produces a vector for the wrong species — and no error.
  • chembl → before: curated measured bioactivity is what you want to featurize, not raw rows.
  • pytdc → alongside: the scaffold and cold-start splits. Featurization quality is invisible under a random split, which reports a fantasy R² regardless of the representation you chose.
  • deepchem → after: model fitting, if you want the training loop rather than just the features.
  • admet-prediction → instead: for standard ADMET endpoints, a ready-made model beats featurizing and training from scratch unless you have your own measured data.
  • chemical-space / generative-design → after: features are what a similarity or diversity selection over an enumerated set is computed on.

Try ECFP first. Across most QSAR tasks a count-based Morgan fingerprint with a gradient-boosted model is within noise of a pretrained transformer embedding, at a fraction of the cost. Reach for pretrained embeddings when you have shown ECFP is the bottleneck, not before.

Additional Resources

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

adaptyv

無料

How to use the Adaptyv Bio Foundry API and Python SDK for protein experiment design, submission, and results retrieval. Use this skill whenever the user mentions Adaptyv, Foundry API, protein binding assays, protein screening experiments, BLI/SPR assays, thermostability assays, or wants to submit protein sequences for experimental characterization. Also trigger when code imports `adaptyv`, `adaptyv_sdk`, or `FoundryClient`, or references `foundry-api-public.adaptyvbio.com`.

日本語の概要は準備中です。原文の説明を表示しています。

K-Dense-AI/drug-discovery-agent-skills362026年10月12日 更新

Turn a set of structures into absorption, distribution, metabolism, excretion, and toxicity estimates with ADMET-AI, and read them as a developability verdict rather than a table of numbers. Use this skill to run batch prediction over a library, interpret each endpoint against its DrugBank-approved percentile, and flag the liabilities that stop a series — hERG blockade, CYP inhibition, poor Caco-2 permeability, high clearance, and plasma protein binding. Also trigger on ADMET-AI, admet_ai, Chemprop-RDKit, hERG liability, CYP3A4 inhibition, Caco-2, bioavailability prediction, or developability triage.

日本語の概要は準備中です。原文の説明を表示しています。

K-Dense-AI/drug-discovery-agent-skills362026年10月12日 更新

Number antibody variable domains, annotate CDRs, and assess developability from sequence. Use this skill to apply IMGT, Kabat, Chothia, Martin, or AHo numbering with ANARCI, delimit CDRs and framework regions, scan for chemical liabilities (N-glycosylation sequons, deamidation NG, isomerisation DG, oxidation, unpaired cysteine, fragmentation), compute pI, net charge, extinction coefficient and hydrophobicity, and plan humanisation by CDR grafting. Also trigger on antibody, nanobody, VHH, scFv, Fab, CDR, framework, ANARCI, abnumber, IgBLAST, OAS, SAbDab, humanization, Vernier residues, or developability.

日本語の概要は準備中です。原文の説明を表示しています。

K-Dense-AI/drug-discovery-agent-skills362026年10月12日 更新

Structure-based docking with AutoDock Vina, Vinardo, and AutoDock4 through the Meeko toolchain. Use this skill to define a docking box, prepare receptors and ligands as PDBQT, run single or batch docking, rescore, and interpret affinities, poses, and ligand efficiency. Covers box definition from a reference ligand or pocket residues, protonation and tautomer decisions, flexible side chains, exhaustiveness and seeds, redocking validation, and virtual screening over compound libraries. Also trigger on vina, smina, gnina, mk_prepare_ligand, mk_prepare_receptor, mk_export, scrub.py, PDBQT, autogrid4, docking box, or binding-pose prediction.

日本語の概要は準備中です。原文の説明を表示しています。

K-Dense-AI/drug-discovery-agent-skills362026年10月12日 更新

Decide whether a protein has a pocket worth targeting, and where it is, before committing to a docking or design campaign. Use this skill to run fpocket cavity detection, rank cavities by druggability and volume, compare apo and holo conformations to spot induced fit, identify allosteric and cryptic cavities that only open in simulation, and convert a chosen cavity into the search box coordinates a docking run needs. Also trigger on fpocket, cavity detection, druggability score, alpha sphere, cryptic pocket, allosteric site, pocket volume, hotspot mapping, or undruggable target assessment.

日本語の概要は準備中です。原文の説明を表示しています。

K-Dense-AI/drug-discovery-agent-skills362026年10月12日 更新

boltz

無料

Cofold protein-ligand, protein-protein, and nucleic-acid complexes with Boltz-2, and predict binding affinity with its trained affinity head. Use this skill to build Boltz input YAML, run structure prediction with MSAs, pocket constraints, templates, and modified residues, screen compound libraries by cofolding, and interpret confidence scores (pLDDT, pTM, ipTM, PDE) and affinity output (binder probability and log10 IC50). Also trigger on Boltz, Boltz-1, Boltz-2, cofolding, boltz predict, affinity_pred_value, affinity_probability_binary, ipTM, or open-weights AlphaFold3 alternatives.

日本語の概要は準備中です。原文の説明を表示しています。

K-Dense-AI/drug-discovery-agent-skills362026年10月12日 更新

K-Dense-AI のスキルをすべて見る

このスキルの問題を報告する