开发工具包

其他 社区

技能解读

当前原文的自动摘译,尚未人工审校。

指纹——使用新的 API

关键:使用rdFingerprintGenerator模块,而不是像GetMorganFingerprint()这样的旧函数。有关完整文档,请参阅references/fingerprints.md。

绘制分子

使用MolDraw2DCairo或MolDraw2DSVG与drawOptions()进行定制。有关完整文档,请参阅references/drawing.md。

相似度

报告相似性时,请务必指定哪个指纹 - 不同的指纹对于同一分子对给出非常不同的值(例如,RDKit FP:0.79 vs Morgan2:0.43)。

酸洗陷阱

酸洗/序列化时,默认情况下属性会丢失:

解析和清理

在解析过程中控制化学感知。详情请参见references/parsing.md。

流狐档案 运行与权限由流狐静态检查推断,不代表作者声明或实际测试结果。
领域
通用
作者声明的智能体
未找到明确声明;不据此推断已兼容或已测试
静态检查
88 / 100 · 启发式扫描,不代表运行安全
运行环境证据
未执行;当前没有隔离运行测试证据
作者 / 版本 / 许可证
@diegosouzapw · 未声明许可证
上下文用量评级
低消耗
接入复杂程度
即装即用
是否需要外部接口密钥
不需要
兼容的系统
未声明(默认跨平台)
运行环境要求
Python
检测到的文件与系统行为
  • 只读
  • 允许写入 / 修改
网络行为
仅限本地
安装命令数
无(仅作为资料)

需要注意: 未声明工具权限范围;实际权限由运行环境决定。

作者说明文件(原文) SKILL.md

# RDKit Skill

This skill provides up-to-date RDKit patterns. **LLMs often have outdated RDKit syntax** — always follow the patterns here.

## Installation

```bash
uv pip install rdkit
```

## Core Imports

```python
from rdkit import Chem
from rdkit.Chem import AllChem, Descriptors, Draw, rdFingerprintGenerator
from rdkit.Chem import rdDepictor
from rdkit import DataStructs
```

## Molecule I/O

```python
# From SMILES
mol = Chem.MolFromSmiles('CCO')

# From file
mol = Chem.MolFromMolFile('molecule.mol')
mols = [m for m in Chem.SDMolSupplier('molecules.sdf') if m is not None]

# To SMILES
smiles = Chem.MolToSmiles(mol)
```

## Fingerprints — USE THE NEW API

**CRITICAL**: Use `rdFingerprintGenerator` module, NOT the old functions like `GetMorganFingerprint()`.

See `references/fingerprints.md` for complete documentation.

### Quick Reference

```python
from rdkit.Chem import rdFingerprintGenerator

# Morgan/ECFP fingerprints (ECFP4 = radius 2)
mfpgen = rdFingerprintGenerator.GetMorganGenerator(radius=2, fpSize=2048)

# RDKit fingerprint
rdkgen = rdFingerprintGenerator.GetRDKitFPGenerator(fpSize=2048)

# Atom pairs
apgen = rdFingerprintGenerator.GetAtomPairGenerator(fpSize=2048)

# Topological torsions
ttgen = rdFingerprintGenerator.GetTopologicalTorsionGenerator(fpSize=2048)

# Generate fingerprints (same API for all types)
fp = mfpgen.GetFingerprint(mol)           # bit vector
cfp = mfpgen.GetCountFingerprint(mol)     # count vector
np_fp = mfpgen.GetFingerprintAsNumPy(mol) # numpy array
```

## Drawing Molecules

**Use `MolDraw2DCairo` or `MolDraw2DSVG`** with `drawOptions()` for customization.

See `references/drawing.md` for complete documentation.

### Quick Reference

```python
from rdkit.Chem import Draw, rdDepictor

# Generate 2D coordinates
rdDepictor.Compute2DCoords(mol)
rdDepictor.StraightenDepiction(mol)

# Simple drawing
img = Draw.MolToImage(mol, size=(300, 300))
img.save('molecule.png')

# Customized drawing
d2d = Draw.MolDraw2DCairo(350, 300)
dopts = d2d.drawOptions()
dopts.addAtomIndices = True  # show atom indices
d2d.DrawMolecule(mol)
d2d.FinishDrawing()
with open('molecule.png', 'wb') as f:
    f.write(d2d.GetDrawingText())

# Grid of molecules
img = Draw.MolsToGridImage(mols, molsPerRow=4, subImgSize=(200, 200))
```

## Molecular Properties

```python
from rdkit.Chem import Descriptors

mw = Descriptors.MolWt(mol)
logp = Descriptors.MolLogP(mol)
hbd = Descriptors.NumHDonors(mol)
hba = Descriptors.NumHAcceptors(mol)
tpsa = Descriptors.TPSA(mol)
rotatable = Descriptors.NumRotatableBonds(mol)
```

## Substructure Search

```python
# SMARTS pattern matching
pattern = Chem.MolFromSmarts('[OH]')
matches = mol.GetSubstructMatches(pattern)  # returns tuple of tuples

# Check if has substructure
has_oh = mol.HasSubstructMatch(pattern)
```

## Similarity

**Always specify which fingerprint** when reporting similarity — different fingerprints give very different values for the same molecule pair (e.g., RDKit FP: 0.79 vs Morgan2: 0.43).

```python
from rdkit import DataStructs

# Tanimoto similarity between two fingerprints
sim = DataStructs.TanimotoSimilarity(fp1, fp2)

# Bulk similarity (one vs many)
sims = DataStructs.BulkTanimotoSimilarity(fp1, [fp2, fp3, fp4])
```

## Molecule Properties

```python
# Get/set/check properties on molecules, atoms, bonds
mol.SetProp('name', 'aspirin')
mol.GetProp('name')
mol.HasProp('name')
mol.ClearProp('name')

# Typed getters/setters
mol.SetDoubleProp('score', 3.14)
mol.GetDoubleProp('score')
mol.SetIntProp('count', 42)

# Get all properties
mol.GetPropsAsDict()  # {key: value, ...}

# Private props (start with _) hidden by default
mol.GetPropsAsDict(includePrivate=True)
```

### Pickling Gotcha

Properties are **lost by default** when pickling/serializing:

```python
from rdkit import Chem

# Enable property preservation
Chem.SetDefaultPickleProperties(Chem.PropertyPickleOptions.AllProps)

# Or per-molecule
binary = mol.ToBinary(Chem.PropertyPickleOptions.AllProps)
```

## Parsing & Sanitization

Control chemistry perception during parsing. See `references/parsing.md` for details.

```python
# Custom parsing without sanitization
params = Chem.SmilesParserParams()
params.sanitize = False
params.removeHs = False
mol = Chem.MolFromSmiles(smiles, params=params)

# Manual sanitization after preprocessing
Chem.SanitizeMol(mol)
Chem.AssignStereochemistry(mol, cleanIt=True, force=True)
```

讨论

基于 GitHub Discussions。登录 GitHub 即可参与讨论、点赞、订阅更新。