/scientific-agent-skills:openbabelfrom scientific-agent-skills
Converts between 110+ chemical file formats (SDF, PDB, SMILES, CIF, Gaussian), generates 3D structures from 2D, performs substructure searching with SMARTS, and runs force field minimizations (UFF, GAFF, MMFF94).
Ships in scientific-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Open Babel (and its Python wrapper pybel) is the essential tool for chemical data interoperability. It allows researchers to seamlessly move data between formats like SMILES, PDB, SDF, CIF, and Gaussian input/output.
Official docs: https://openbabel.org/docs/dev/
Python API (Pybel): https://openbabel.org/docs/dev/UseTheLibrary/Python_Pybel.html
Search patterns: openbabel.OBMol, pybel.readfile, pybel.readstring, mol.make3D
Open Babel работает как конвейер: Input Format -> Internal OBMol -> Output Format. Вы можете добавлять фильтры и трансформации (удаление солей, добавление водородов) прямо в процессе конвертации.
# Recommended via conda/mamba
conda install -c conda-forge openbabel
from openbabel import openbabel as ob
from openbabel import pybel
from openbabel import pybel
# 1. Read molecule (from string or file)
mol = pybel.readstring("smi", "CC(=O)Oc1ccccc1C(=O)O") # Aspirin
# 2. Add metadata
mol.title = "Aspirin_001"
# 3. Write to a different format
output_pdb = mol.write("pdb")
# Or write to file
# mol.write("sdf", "aspirin.sdf", overwrite=True)
mol.OBMol.AddHydrogens() or mol.addh() before generating 3D coordinates.pybel.readfile instead of reading molecules into a list to save memory.list(pybel.readfile(...)) or properly iterate to ensure file handles are managed.@ or / will lose stereocenter information during conversion.from openbabel import pybel
# ❌ BAD: Loading millions of molecules into a list
# mols = list(pybel.readfile("sdf", "huge_database.sdf")) # Crashes RAM
# ✅ GOOD: Iterator-based processing
for mol in pybel.readfile("sdf", "huge_database.sdf"):
# process one by one
pass
# ❌ BAD: Generating 3D without hydrogens
mol = pybel.readstring("smi", "C1CCCCC1")
mol.make3D() # ❌ Resulting structure will be distorted/incorrect
# ✅ GOOD: Add H first
mol = pybel.readstring("smi", "C1CCCCC1")
mol.addh()
mol.make3D()
mol.optimize("mmff94")
# ❌ BAD: Manual string manipulation to change format
# pdb_str = sdf_str.replace(...) # ❌ Never works reliably
mol = pybel.readstring("smi", "c1ccccc1O") # Phenol
print(f"Formula: {mol.formula}")
print(f"Weight: {mol.molwt:.2f}")
# Iterate over atoms
for atom in mol.atoms:
print(f"Atom: {atom.type}, Coords: {atom.coords}")
# Get data as a dictionary
data = mol.data # Access SDF tags/metadata
# Search for carboxylic acid group
smarts = pybel.Smarts("C(=O)[OH]")
mol = pybel.readstring("smi", "CC(=O)O") # Acetic acid
if smarts.findall(mol):
print("Molecule contains a carboxylic acid!")
mol = pybel.readstring("smi", "CN1C=NC2=C1C(=O)N(C(=O)N2C)C") # Caffeine
# 1. Prepare for 3D
mol.addh()
# 2. Generate initial 3D (Distance Geometry)
mol.make3D(forcefield='mmff94', steps=50)
# 3. Fine-tune with a local optimizer
# Options: uff, gaff, mmff94, ghemical
mol.optimize(forcefield='mmff94', steps=500)
print(f"3D Energy: {mol.energy:.2f} kJ/mol")
from openbabel import openbabel as ob
# Access the internal OBMol object from a pybel molecule
obmol = mol.OBMol
# Manual atom addition
new_atom = obmol.NewAtom()
new_atom.SetAtomicNum(6) # Carbon
new_atom.SetVector(1.0, 1.0, 1.0)
# Bond information
for i in range(obmol.NumBonds()):
bond = obmol.GetBond(i)
print(f"Bond between {bond.GetBeginAtomIdx()} and {bond.GetEndAtomIdx()}")
# Fingerprints
# Standard types: FP2 (path-based), FP3 (SMARTS patterns), FP4 (functional groups)
fps = mol.calcfp("FP2")
print(f"Fingerprint bits: {fps.bits}")
# Similarity
mol2 = pybel.readstring("smi", "c1ccccc1")
fps2 = mol2.calcfp("FP2")
similarity = fps | fps2 # Tanimoto coefficient
def batch_convert(input_file, in_fmt, output_file, out_fmt, add_h=False):
"""Converts large files with optional hydrogen addition."""
writer = pybel.Outputfile(out_fmt, output_file, overwrite=True)
for mol in pybel.readfile(in_fmt, input_file):
if add_h:
mol.addh()
writer.write(mol)
writer.close()
# batch_convert("library.smi", "smi", "library.sdf", "sdf", add_h=True)
def prepare_ligand(smi_str, output_name):
"""Basic prep for AutoDock Vina."""
mol = pybel.readstring("smi", smi_str)
mol.addh()
mol.make3D()
mol.optimize("gaff")
# Open Babel has a dedicated pdbqt format
mol.write("pdbqt", f"{output_name}.pdbqt", overwrite=True)
def strip_salts(mol):
"""Removes smaller fragments (salts/solvents) from a molecule."""
if len(mol.reversesmi.split(".")) > 1:
# Get the largest fragment by number of atoms
fragments = mol.OBMol.Separate()
largest = max(fragments, key=lambda x: x.NumAtoms())
return pybel.Molecule(largest)
return mol
Before doing expensive 3D or SMARTS matching on millions of molecules, use fingerprint screening (Tanimoto) to filter candidates.
If you only need to convert formats and don't need to manipulate atoms, using the raw OBConversion class is faster than creating pybel.Molecule objects.
obconv = ob.OBConversion()
obconv.SetInAndOutFormats("smi", "sdf")
obconv.ConvertFile("in.smi", "out.sdf")
# ❌ Problem: pybel.readstring("smi", "invalid_smiles") returns a blank molecule
# ✅ Solution: Always check for atom count
mol = pybel.readstring("smi", some_input)
if len(mol.atoms) == 0:
print("Error: Invalid molecule data")
On some systems, Open Babel cannot find its data files (force field parameters).
# ✅ Solution: Manually set BABEL_DATADIR if needed
import os
# os.environ['BABEL_DATADIR'] = '/path/to/openbabel/data'
Sometimes make3D can invert a stereocenter if the input SMILES isn't specific.
# ✅ Solution: Use 'gen3d' operation instead of simple make3D
# which is more robust for preserving stereochemistry.
obconv = ob.OBConversion()
obconv.AddOption("gen3d", ob.OBConversion.GENOPTIONS)
@ and / when needed..close() to ensure data is written.Open Babel is the "glue" of the chemical world. While it may not have the sophisticated 2D-rendering of RDKit or the high-level math of PySCF, its ability to handle any format and generate 3D starting points makes it a mandatory tool in every computational chemist's belt.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub tondevrel/scientific-agent-skills --plugin scientific-agent-skills70 skills in this plugin
/aseAtomic Simulation Environment - a set of tools for setting up, manipulating, running, visualizing, and analyzing atomistic simulations. Acts as a universal interface between Python and numerous quantum chemical and molecular dynamics codes. Use for building atomic structures, geometry optimization, molecular dynamics simulations, transition state searches (NEB), file format conversion (CIF, XYZ, POSCAR, PDB), electronic property calculations (DOS, band structures), and automating simulation workflows with DFT/MD codes like VASP, GPAW, Quantum ESPRESSO, LAMMPS./astropyThe core library for Astronomy and Astrophysics in Python. Provides data structures for coordinates, time, units, FITS files, and cosmological models. Essential for observational data reduction and theoretical astrophysics. Use when working with astronomical coordinates (RA/Dec), physical units, FITS files, time scales, WCS, cosmology, or astronomical tables./biopythonOther plugins' skills for the same job