agentleFS
dtunaidtunai/agent-skills-for-compute/skills/rdkit/SKILL.md

rdkit

Skill8 starsChanged 8 months agoMITView on GitHub

RDKit cheminformatics toolkit — molecular I/O, descriptors, fingerprints, substructure searching, reactions, and 3D conformer generation

  • Installs packages

16 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 16 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Sanitize Once: Don't sanitize multiple times

    line 256
  2. Distinctive:

    Reuse Fingerprint Generators: Create once, use many times

    line 257
  3. Very specific:

    Bulk Operations: Use BulkTanimotoSimilarity for batch calculations

    line 258

“Common” is measured: kept by at least 6 in 10 of the 16 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

RDKit Skill

Cheminformatics and machine learning toolkit for molecular operations, property calculation, and chemical analysis.

Official Sources:

Installation

# Via conda (recommended)
conda install -c conda-forge rdkit

# Via pip
pip install rdkit

# Verify installation
python -c "from rdkit import Chem; print(Chem.__version__)"

Quick Start

from rdkit import Chem
from rdkit.Chem import AllChem, Descriptors, Draw

# Create molecule from SMILES
mol = Chem.MolFromSmiles('CC(=O)Oc1ccccc1C(=O)O')  # Aspirin

# Calculate properties
mw = Descriptors.MolWt(mol)
logp = Descriptors.MolLogP(mol)

# Generate fingerprint
fp = AllChem.GetMorganFingerprintAsBitVect(mol, radius=2, nBits=2048)

# Draw molecule
img = Draw.MolToImage(mol)

Molecular I/O

from rdkit import Chem

# Read/write single molecules
mol = Chem.MolFromSmiles('c1ccccc1')
mol = Chem.MolFromMolFile('input.mol')
smiles = Chem.MolToSmiles(mol)
Chem.MolToMolFile(mol, 'output.mol')

# Read/write multiple molecules
suppl = Chem.SDMolSupplier('molecules.sdf')
mols = [m for m in suppl if m is not None]

with Chem.SDWriter('output.sdf') as w:
    for mol in mols:
        w.write(mol)

Molecular Operations

# Atoms and bonds
for atom in mol.GetAtoms():
    print(atom.GetSymbol(), atom.GetAtomicNum())
atom = mol.GetAtomWithIdx(0)
bond = mol.GetBondWithIdx(0).GetBondType()

# Rings
atom.IsInRing()
atom.IsInRingSize(6)
ssr = Chem.GetSymmSSSR(mol)

# Modify
mol_with_h = Chem.AddHs(mol)
mol_no_h = Chem.RemoveHs(mol)
Chem.Kekulize(mol)
Chem.SanitizeMol(mol)

Molecular Descriptors

from rdkit.Chem import Descriptors, AllChem

# Common descriptors
Descriptors.MolWt(mol)
Descriptors.MolLogP(mol)
Descriptors.TPSA(mol)
Descriptors.NumHDonors(mol)
Descriptors.NumHAcceptors(mol)
Descriptors.NumRotatableBonds(mol)

# All descriptors
all_desc = Descriptors.CalcMolDescriptors(mol)

# Partial charges
AllChem.ComputeGasteigerCharges(mol)
charge = mol.GetAtomWithIdx(0).GetDoubleProp('_GasteigerCharge')

Fingerprints and Similarity

from rdkit.Chem import AllChem, MACCSkeys, rdMolDescriptors
from rdkit import DataStructs

# Morgan (ECFP)
fp1 = AllChem.GetMorganFingerprintAsBitVect(mol1, radius=2, nBits=2048)
fpgen = AllChem.GetMorganGenerator(radius=2, fpSize=2048)
fp = fpgen.GetFingerprint(mol)

# RDKit fingerprint
fpgen = AllChem.GetRDKitFPGenerator()
fp = fpgen.GetFingerprint(mol)

# Atom pair, topological torsion, MACCS
ap = rdMolDescriptors.GetAtomPairFingerprint(mol)
tt = rdMolDescriptors.GetTopologicalTorsionFingerprint(mol)
maccs = MACCSkeys.GenMACCSKeys(mol)

# Similarity
sim = DataStructs.TanimotoSimilarity(fp1, fp2)
sims = DataStructs.BulkTanimotoSimilarity(fp1, [fp2, fp3])

Substructure Searching

# SMARTS pattern matching
pattern = Chem.MolFromSmarts('c1ccccc1')
has_match = mol.HasSubstructMatch(pattern)
match = mol.GetSubstructMatch(pattern)
matches = mol.GetSubstructMatches(pattern)

# With chirality
matches = mol.GetSubstructMatches(pattern, useChirality=True)

# Functional groups
carboxylic_acid = Chem.MolFromSmarts('C(=O)[OH]')
has_acid = mol.HasSubstructMatch(carboxylic_acid)

Chemical Reactions

from rdkit.Chem import AllChem

# Reaction SMARTS (amide bond formation)
rxn = AllChem.ReactionFromSmarts('[C:1](=[O:2])-[OD1].[N!H0:3]>>[C:1](=[O:2])[N:3]')
acid = Chem.MolFromSmiles('CC(=O)O')
amine = Chem.MolFromSmiles('CN')
products = rxn.RunReactants((acid, amine))

# From file
rxn = AllChem.ReactionFromRxnFile('reaction.rxn')

# Protect atoms
amide = Chem.MolFromSmarts('[N;$(NC=[O,S])]')
for m in mol.GetSubstructMatches(amide):
    mol.GetAtomWithIdx(m[0]).SetProp('_protected', '1')

2D and 3D Coordinates

from rdkit.Chem import AllChem

# 2D coordinates
AllChem.Compute2DCoords(mol)

# 3D conformers
mol = Chem.AddHs(mol)
AllChem.EmbedMolecule(mol)  # Single conformer
conf_ids = AllChem.EmbedMultipleConfs(mol, numConfs=10)  # Multiple

# Optimize
for conf_id in conf_ids:
    AllChem.UFFOptimizeMolecule(mol, confId=conf_id)

# Align
rms_list = []
AllChem.AlignMolConformers(mol, RMSlist=rms_list)

Drawing Molecules

from rdkit.Chem import Draw
from rdkit.Chem.Draw import rdMolDraw2D

# Basic drawing
img = Draw.MolToImage(mol, size=(300, 300))
Draw.MolToFile(mol, 'molecule.png')
img = Draw.MolsToGridImage(mols, molsPerRow=2, legends=['A', 'B'])

# Highlight substructures
match = mol.GetSubstructMatch(pattern)
d = rdMolDraw2D.MolDraw2DSVG(400, 400)
rdMolDraw2D.PrepareAndDrawMolecule(d, mol, highlightAtoms=list(match))

Molecular Fragmentation

from rdkit.Chem import BRICS, Recap, rdFMCS

# BRICS
fragments = BRICS.BRICSDecompose(mol)
new_mols = BRICS.BRICSBuild(fragments)

# Recap
hierarch = Recap.RecapDecompose(mol)
leaves = hierarch.GetLeaves()

# Maximum common substructure
mcs = rdFMCS.FindMCS([mol1, mol2, mol3], ringMatchesRingOnly=True)
print(mcs.smartsString)

Serialization

import pickle

# Pickle (fast)
pkl = pickle.dumps(mol)
mol2 = pickle.loads(pkl)

# Binary
bin_str = mol.ToBinary()
mol3 = Chem.Mol(bin_str)

# JSON
json_str = Chem.MolToJSON(mol)
mol = Chem.MolFromJSON(json_str)

Performance Tips

  1. Use Suppliers for Large Files: SDMolSupplier instead of loading all molecules
  2. Pickle Molecules: Much faster than reparsing SMILES/SDF
  3. Remove Hydrogens: Smaller molecules, faster operations
  4. Sanitize Once: Don't sanitize multiple times
  5. Reuse Fingerprint Generators: Create once, use many times
  6. Bulk Operations: Use BulkTanimotoSimilarity for batch calculations

Common Patterns

# Virtual screening
query_fp = AllChem.GetMorganFingerprintAsBitVect(query, 2, 2048)
hits = []
for mol in Chem.SDMolSupplier('library.sdf'):
    if mol:
        fp = AllChem.GetMorganFingerprintAsBitVect(mol, 2, 2048)
        if DataStructs.TanimotoSimilarity(query_fp, fp) > 0.7:
            hits.append(mol)

# Lipinski's Rule of Five
def passes_lipinski(mol):
    return (Descriptors.MolWt(mol) <= 500 and Descriptors.MolLogP(mol) <= 5 and
            Descriptors.NumHDonors(mol) <= 5 and Descriptors.NumHAcceptors(mol) <= 10)

# PAINS filtering
pains = [Chem.MolFromSmarts(s) for s in ['C1=CC=CC=C1N=NC1=CC=CC=C1']]
clean = [m for m in mols if not any(m.HasSubstructMatch(p) for p in pains)]

References

  • Molecular I/O - SMILES, SDF, Mol files, suppliers, writers
  • Descriptors and Fingerprints - Molecular properties, fingerprints, similarity
  • Substructure and Reactions - Pattern matching, SMARTS, chemical reactions
  • 3D Conformers - Coordinate generation, conformer optimization, alignment
  • Stereochemistry - Chirality, CIP rules, stereo groups, atropisomers, enumeration
  • Sanitization and Aromaticity - Molecular sanitization, aromaticity models, kekulization
  • Scaffold Analysis - Murcko scaffolds, generic scaffolds, scaffold-based splits
  • Advanced Features - Drawing, fragmentation, serialization, MCS

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.