Sarah, On Wed, Sep 28, 2011 at 7:53 PM, Eddie Cao <cao.yi...@gmail.com> wrote: > I suggest the following alternative: > 1. first make a copy so you don't change the original molecule >>>> from copy import deepcopy >>>> mol2 = deepcopy(mol) > Now set the atoms you'd like to remove to dummy atoms with atomic number 0 >>>> mol2.GetAtomWithIdx(2).SetAtomicNum(0) >>>> mol2.GetAtomWithIdx(3).SetAtomicNum(0) > Now remove dummy atoms using a query >>>> mol3 = Chem.DeleteSubstructs(mol2, Chem.MolFromSmarts('[#0]')) > You get what you are looking for >>>> Chem.MolToSmiles(mol3) > 'CN'
Eddie's solution is a nice one that should work pretty well. Another possible approach is to go ahead and use an EditableMol as you originally started, but to make sure that you remove the atoms starting with the highest numbers first: >>> m = Chem.MolFromSmiles('FCCCl') >>> em1 = Chem.EditableMol(m) >>> atomsToRemove=[0,3] >>> atomsToRemove.sort(reverse=True) >>> for atom in atomsToRemove: ... em1.RemoveAtom(atom) ... >>> m2 = em1.GetMol() >>> Chem.SanitizeMol(m2) >>> Chem.MolToSmiles(m2) 'CC' This should avoid the problem you were encountering. -greg ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 _______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss