SKILL.md
Version Compatibility
Reference examples tested with: RDKit 2024.03+
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package>thenhelp(module.function)to check signatures
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Molecular I/O
"Load my chemical library into Python" → Parse molecular file formats (SMILES, SDF, MOL2, PDB) into RDKit molecule objects for programmatic access, standardization, and format conversion.
- Python:
Chem.MolFromSmiles(),Chem.SDMolSupplier()(RDKit)
Read, write, and convert molecular file formats with structure standardization.
Supported Formats
| Format | Extension | Use Case |
|---|---|---|
| SMILES | .smi | Text representation, databases |
| SDF/MOL | .sdf, .mol | 3D structures, compound libraries |
| MOL2 | .mol2 | Docking, force field atoms |
| PDB | .pdb | Protein-ligand complexes |
Reading Molecules
Goal: Load molecules from SMILES strings, SDF files, or SMILES files into RDKit molecule objects.
Approach: Use Chem.MolFromSmiles for individual SMILES, SDMolSupplier for multi-molecule SDF files, and file iteration for SMILES files, filtering out parse failures.
from rdkit import Chem
from rdkit.Chem import AllChem
# From SMILES
mol = Chem.MolFromSmiles('CCO')
# From SDF file (single molecule)
mol = Chem.MolFromMolFile('molecule.mol')
# From SDF file (multiple molecules)
supplier = Chem.SDMolSupplier('library.sdf')
molecules = [mol for mol in supplier if mol is not None]
print(f'Loaded {len(molecules)} molecules')
# From SMILES file
with open('compounds.smi') as f:
molecules = []
for line in f:
parts = line.strip().split()
if parts:
mol = Chem.MolFromSmiles(parts[0])
if mol:
mol.SetProp('_Name', parts[1] if len(parts) > 1 else '')
molecules.append(mol)
