| name | rdkit-structure-builder |
| description | Programmatically build, modify, and manipulate chemical structures using RDKit without requiring LLM API calls. Use when you need to: (1) Retrieve common chemical scaffolds (benzene, pyridine, amino acids, etc.), (2) Build molecules from building blocks (chains, rings, functional groups), (3) Manipulate fragments (replace substructures, find disconnections, extract MCS), (4) Validate or canonicalize SMILES strings, (5) Generate molecular series or variants (homologous series, isomers, functional group scans), or (6) Perform any routine structure manipulation for local chat or workspace workflows. |
RDKit Structure Builder
Programmatic molecule creation and manipulation using RDKit. Provides instant, deterministic access to structure building operations without LLM overhead.
Quick start
scaffold = get_scaffold("benzene")
chain = build_chain(carbons=8)
modified = attach_group("c1ccccc1", group="hydroxyl", position="para")
series = generate_series("CCO", extend_by="CH2", count=5)
Core capabilities
1. Scaffold Library
Pre-built common structures for instant retrieval. Located in backend/app/services/rdkit_builder_service.py.
Common rings:
from app.services.rdkit_builder_service import ScaffoldLibrary
scaffold = ScaffoldLibrary()
scaffold.get("benzene")
scaffold.get("naphthalene")
scaffold.get("anthracene")
scaffold.get("pyridine")
scaffold.get("imidazole")
scaffold.get("furan")
scaffold.get("piperidine")
scaffold.get("cyclohexane")
scaffold.get("cyclopentane")
Amino acids:
scaffold.get("alanine")
scaffold.get("phenylalanine")
scaffold.get("glycine")
Functional group carriers:
scaffold.get("ethanol")
scaffold.get("acetone")
scaffold.get("acetic_acid")
Returns: SMILES string ready for workspace placement or further manipulation.
2. Structure Building
Programmatic molecule construction from building blocks.
from app.services.rdkit_builder_service import StructureBuilder
builder = StructureBuilder()
builder.build_chain(carbons=8)
builder.build_chain(carbons=12, chain_type="alkoxy")
builder.build_ring(size=6, ring_type="aromatic")
builder.build_ring(size=5, heteroatoms=["N", "O"])
builder.attach_group(
smiles="c1ccccc1",
group="hydroxyl",
position="para"
)
builder.attach_group(
smiles="CCCC",
group="amine",
position="terminal"
)
builder.link_fragments(
fragment1="c1ccccc1",
fragment2="CCCC",
bond_type="single"
)
Returns: SMILES string + description of what was built.
3. Fragment Operations
Advanced manipulation and retrosynthesis analysis.
from app.services.rdkit_builder_service import FragmentOperations
frag = FragmentOperations()
frag.replace_substructure(
smiles="CCCCNCCCC",
query="[NH2]",
replacement="O"
)
frag.find_disconnections(
smiles="c1ccc(C(=O)Nc2ccccc2)cc1",
max_cuts=2
)
frag.find_mcs(
smiles1="c1ccccc1CCO",
smiles2="c1ccccc1CCC"
)
frag.enumerate_variants(
scaffold="c1ccccc1",
groups=["OH", "NH2", "F"],
max_variants=5
)
Returns: SMILES variants with descriptions.
4. SMILES Utilities
Validation, canonicalization, and property calculation.
from app.services.rdkit_builder_service import SMILESUtilities
utils = SMILESUtilities()
utils.validate("CCO")
utils.validate("INVALID")
utils.canonicalize("C1=CC=CC=C1")
utils.matches_pattern(
smiles="c1ccccc1CCO",
pattern="[OH]"
)
utils.calculate_properties(
smiles="CCO",
properties=["MW", "LogP", "HBA", "HBD"]
)
utils.convert_format(
input_data="CCO",
from_format="smiles",
to_format="molfile"
)
Returns: Validated/transformed SMILES + metadata.
5. Batch Operations
Generate multiple structures for workspace placement or library generation.
from app.services.rdkit_builder_service import BatchOperations
batch = BatchOperations()
batch.generate_series(
base="CCO",
extend_by="CH2",
count=5
)
batch.generate_isomers(
formula="C4H10O",
max_count=10
)
batch.functional_group_scan(
scaffold="c1ccccc1",
positions=["ortho", "meta", "para"],
groups=["OH", "NH2", "NO2"]
)
Returns: List of SMILES strings with descriptions.
Integration with existing services
Leverage existing backend services for additional capabilities:
from app.services.molecule_service import MoleculeService
mol_service = MoleculeService()
mol_service.rotate_molecule(smiles, angle=90)
mol_service.highlight_substructure(smiles, pattern)
from app.services.molecule_analysis_service import MoleculeAnalysisService
analysis = MoleculeAnalysisService()
analysis.detect_functional_groups(smiles)
analysis.analyze_rings(smiles)
from app.services.molecule_highlighting_service import MoleculeHighlightingService
highlight = MoleculeHighlightingService()
highlight.find_common_substructure([smiles1, smiles2, smiles3])
Example workflows
Workflow 1: Build alcohol series for local chat
from app.services.rdkit_builder_service import BatchOperations
batch = BatchOperations()
alcohols = batch.generate_series(
base="CO",
extend_by="CH2",
count=10
)
Workflow 2: Create substituted benzenes for local workspace
from app.services.rdkit_builder_service import BatchOperations
batch = BatchOperations()
variants = batch.functional_group_scan(
scaffold="c1ccccc1",
positions=["para"],
groups=["OH", "NH2", "NO2", "F", "Cl", "Br", "CHO", "COOH"]
)
Workflow 3: Retrosynthesis analysis
from app.services.rdkit_builder_service import FragmentOperations
frag = FragmentOperations()
cuts = frag.find_disconnections(
smiles="c1ccc(C(=O)Nc2ccccc2)cc1",
max_cuts=2
)
Workflow 4: Scaffold hopping
from app.services.rdkit_builder_service import FragmentOperations
frag = FragmentOperations()
new_molecule = frag.replace_substructure(
smiles="c1ccc(CCO)cc1",
query="c1ccccc1",
replacement="c1ccncc1"
)
Workflow 5: Batch property calculation
from app.services.rdkit_builder_service import BatchOperations, SMILESUtilities
batch = BatchOperations()
utils = SMILESUtilities()
library = batch.generate_series("CCO", "CH2", 10)
properties = [
utils.calculate_properties(smi, ["MW", "LogP"])
for smi in library
]
File locations
- Main service:
backend/app/services/rdkit_builder_service.py
- Scaffold library data:
backend/app/services/rdkit_builder_service.py (embedded)
- Existing services:
backend/app/services/molecule_service.py - Visualization, rotation
backend/app/services/molecule_analysis_service.py - Functional groups, rings
backend/app/services/molecule_highlighting_service.py - Substructure, MCS
Key benefits
- No LLM overhead: Instant structure generation (<100ms vs 1-3s)
- Deterministic: Same input always produces same output
- Cost-free: $0 per call vs $0.0001-0.001 per LLM call
- Composable: Chain operations together
- Fast iteration: Try multiple variants quickly
When to use this skill vs LLM tools
Use RDKit skill for:
- Common scaffolds (benzene, pyridine, etc.)
- Systematic modifications (add OH, replace ring, etc.)
- Series generation (homologous series, isomers)
- SMILES validation/canonicalization
- Batch operations on known patterns
Use LLM tools (create_molecule) for:
- Complex natural products with ambiguous IUPAC names
- Structure interpretation from descriptions
- Novel molecule design with constraints
- When user input is ambiguous or requires reasoning
Advanced RDKit capabilities
The skill leverages RDKit's comprehensive toolkit:
Batch processing:
- Supplier objects for efficient SDF/SMILES file reading
- Multithreaded processing for large datasets
- Compressed file support (gzip)
Molecular validation:
- Automatic sanitization (valence, aromaticity, chirality)
- Problem detection and error handling
- Partial sanitization options
Analysis:
- Molecular descriptors (MW, LogP, TPSA, HBD/HBA, rotatable bonds)
- Fingerprints (Morgan/ECFP, RDKit, MACCS, atom pairs)
- Similarity metrics (Tanimoto, Dice, Cosine)
- Chiral center detection
- Ring system analysis (SSSR)
Reactions:
- Reaction SMARTS for transformations
- Product generation from reaction templates
- Common reactions (esterification, amidation)
Usage tips
- Start with scaffolds: Check scaffold library before building from scratch
- Validate early: Use
validate() before expensive operations
- Canonicalize: Always canonicalize SMILES for comparison
- Batch when possible: Use batch operations for multiple structures
- Chain operations: Combine scaffold → modify → validate workflows
- Leverage existing services: Use
MoleculeService for visualization after building
Error handling
All methods return None or empty results on invalid input rather than raising exceptions. Always check return values:
smiles = builder.build_chain(carbons=8)
if smiles:
proceed_with_visualization(smiles)
else:
fallback_to_llm_tool()
Maintained by the ChemIllusion team as part of OpenMolClaw.