Anyhoo, that's enough background. Let's suppose we want to hydrogenate all instances of C=C and C=O. Just copy and paste the following into the end of plugindefines.txt:
OpTransform hydrogenate # ID used for commandline option * # Asterisk means "no datafile specified" Hydrogenate C=C and C=O double bonds TRANSFORM [C:1]=[C:2] >> [C:1][C:2] TRANSFORM [C:1]=[O:2] >> [C:1][O:2]This gives a new obabel option, --hydrogenate, that will do the job:
C:\Tools\tmp>obabel -L ops ... hydrogenate Hydrogenate C=C and C=O double bonds ... C:\Tools\tmp>obabel -:C=C -osmi --hydrogenate CC C:\Tools\tmp>obabel -:O=CSC=CC=S -osmi --hydrogenate OCSCCC=SNotes:
(1) This works best in the latest SVN as Chris sorted out some longstanding bugs.
(2) I've just enabled this in Python where it works as follows:
import pybel transform = pybel.ob.OBChemTsfm() success = transform.Init("[C:1]=[C:2]", "[C:1][C:2]") assert success mol = pybel.readstring("smi", "C=C") transform.Apply(mol.OBMol) assert mol.write("smi").rstrip() == "CC"