[Rdkit-discuss] Keeping only parts of a molecule (a set of atom ids)

2012-03-22 Thread JP
Hi there at RDKit, I have a set of atom indices from a molecule I want to keep, and any atom which is not in this list I want to discard. I thought of implementing this as follows: #!/usr/bin/env python from rdkit import Chem mol = Chem.MolFromSmiles(CCC1CNCC1CC) keep_atoms = [2,3,4] #

Re: [Rdkit-discuss] Keeping only parts of a molecule (a set of atom ids)

2012-03-22 Thread JP
And as a follow up - running this: #!/usr/bin/env python from rdkit import Chem mol = Chem.MolFromSmiles(CCC1CNCC1CC) edit_mol = Chem.EditableMol(mol) edit_mol.RemoveAtom(0) for atom in edit_mol.GetMol().GetAtoms(): print atom.GetIdx() gives seg fault... jp@xxx:~/tmp$ test.py

Re: [Rdkit-discuss] Keeping only parts of a molecule (a set of atom ids)

2012-03-22 Thread Sarah Langdon
I had a similar problem to this when removing atoms from a molecule. When you remove an atom, the atoms IDs change, therefore resulting in a seg fault, or your atoms not being in the correct range. The way I got around this was to sort the IDs of the atoms I want to remove from highest to

Re: [Rdkit-discuss] Keeping only parts of a molecule (a set of atom ids)

2012-03-22 Thread Eddie Cao
Hi JP, Sarah was right on the trick of deleting atoms in the descending order of atom index. Regarding the segment fault, this is very likely to be a memory management issue. Make sure you assign the result of the GetMol() call to a temporary variable to avoid the underlying object being

Re: [Rdkit-discuss] Keeping only parts of a molecule (a set of atom ids)

2012-03-22 Thread JP
Thanks to both of you, nice trick... - Jean-Paul Ebejer Early Stage Researcher On 22 March 2012 16:34, Eddie Cao cao.yi...@gmail.com wrote: Hi JP, Sarah was right on the trick of deleting atoms in the descending order of atom index. Regarding the segment fault, this is very likely to be a