Skip to content

A Python toolkit for editing molecular structures by manipulating functional groups using RDKit.

Notifications You must be signed in to change notification settings

IDEA-XL/MolEdit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MolEdit - Molecular Functional Group Editor

A Python toolkit for editing molecular structures by manipulating functional groups using RDKit.

Features

  • Replace functional groups in molecules
  • Remove functional groups from molecules
  • Add functional groups to molecules at specific positions
  • Support for 34+ common functional groups
  • User-friendly interface with functional group names (no SMARTS knowledge required)

Installation

Requires RDKit:

pip install rdkit
# or
conda install -c conda-forge rdkit

Quick Start

from example import ReplaceFunctionalGroup, RemoveFunctionalGroup, AddFunctionalGroup

# Initialize tools
replace_tool = ReplaceFunctionalGroup()
remove_tool = RemoveFunctionalGroup()
add_tool = AddFunctionalGroup()

# Replace hydroxyl with amine in ethanol
result = replace_tool._run_base('CCO', 'hydroxyl', 'primary_amine')
print(result)  # Output: CCN

# Remove hydroxyl from ethanol
result = remove_tool._run_base('CCO', 'hydroxyl') 
print(result)  # Output: CC

# Add carboxyl group to propane at position 0
result = add_tool._run_base('CCC', 'carboxyl', 0)
print(result)  # Output: C(C(=O)O)CC

Available Functional Groups

For Replace & Remove (34 groups):

  • Aromatic: benzene_ring, pyridine, pyrrole, furan
  • Oxygen: hydroxyl, aldehyde, ketone, carboxyl, ester, ether
  • Nitrogen: primary_amine, secondary_amine, tertiary_amine, amide, nitro, nitrile
  • Halogens: halo, chloro, bromo, fluoro, iodo
  • Sulfur: thiol, thioether, disulfide, sulfoxide, sulfone
  • Phosphorus: phosphine, phosphate, phosphonate
  • Others: imine, oxime, hydrazone, isocyanate, anhydride, borane

Additional for Add (10 extra groups):

  • Alkyl chains: methyl, ethyl, propyl, isopropyl, butyl, tert_butyl

API Reference

ReplaceFunctionalGroup

Replace one functional group with another.

result = replace_tool._run_base(base_smiles, old_group_name, new_group_name)

Parameters:

  • base_smiles (str): Input molecule SMILES
  • old_group_name (str): Name of functional group to replace
  • new_group_name (str): Name of replacement functional group

RemoveFunctionalGroup

Remove a functional group from molecule.

result = remove_tool._run_base(base_smiles, group_name)

Parameters:

  • base_smiles (str): Input molecule SMILES
  • group_name (str): Name of functional group to remove

AddFunctionalGroup

Add a functional group at specific atom position.

result = add_tool._run_base(base_smiles, group_name, atom_index)

Parameters:

  • base_smiles (str): Input molecule SMILES
  • group_name (str): Name of functional group to add
  • atom_index (int): 0-based index of atom to attach group to

Examples

# Convert alcohol to amine
replace_tool._run_base('CCO', 'hydroxyl', 'primary_amine')  # → CCN

# Remove halogen from alkyl halide  
remove_tool._run_base('CCCl', 'halo')  # → CC

# Add benzene ring to alkane
add_tool._run_base('CCC', 'benzene_ring', 1)  # → C[CH]C (with benzene attached)

# Convert aldehyde to carboxylic acid
replace_tool._run_base('CC=O', 'aldehyde', 'carboxyl')  # → CC(=O)O

# Add nitro group  
add_tool._run_base('CCC', 'nitro', 0)  # → C(CC)[N+](=O)[O-]

Error Handling

The tools provide informative error messages:

  • Invalid SMILES strings
  • Unknown functional group names
  • Out-of-range atom indices
  • Failed molecular transformations

File Structure

  • constants.py - Functional group definitions (SMARTS patterns and SMILES)
  • example.py - Main tool classes implementing the BaseTool interface
  • test.py - Original functional implementations for reference
  • CLAUDE.md - Development documentation

Notes

  • All functions return SMILES strings or error messages
  • Atom indices are 0-based (first atom is index 0)
  • Some complex transformations may fail due to chemical constraints
  • The tools attempt to sanitize molecules after modifications

About

A Python toolkit for editing molecular structures by manipulating functional groups using RDKit.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages