|
From: Michael B. <mb...@ya...> - 2009-03-18 15:29:08
|
Thanks you for the swift reply!
I am not sure though what to do with your advice.
Do you mean save ALL atoms of the molecule as an array of atoms
and then create a new molecule from only those atoms
that I don't want to delete (thereby trusting OB to correctly
assign all bonds, hybridization, etc)
Otherwise if I just "save" each atom before deleting it, e.g., by copying
the atom to a new instance of OBAtom the indices would still get
messed up once I delete the original atom, wouldn't they??
I am not sure what you mean when you say "save the actual atom"...
sorry I keep bothering you!
cheers,
mic
----- Original Message ----
From: Fredrik Wallner <fr...@wa...>
To: Michael Brunsteiner <mb...@ya...>
Cc: openbabel mailinglist <ope...@li...>
Sent: Wednesday, March 18, 2009 3:12:08 AM
Subject: Re: [Open Babel] Deleting atoms given their indices-> unexpected result
Hi,
You are correct that the problem is that the indices change at each deletion. Instead you should save the actual atom corresponding to each index and then delete them.
Kind regards,
Fredrik
18 mar 2009 kl. 08.49 skrev Michael Brunsteiner:
>
>
> Dear all,
>
> Given an OBmol molecule I would like to delete part of its atoms,
> that I previously identified by a smarts pattern match.
> Problem is that the wrong atoms end up being deleted.
> When i check which atoms have been identified by smarts.Match()
> using atom->GetIdx() the returned numbers and the serial numbers
> of the atoms in the mol2 file that correspond to the smarts pattern agree.
> But when i then use DeleteAtom(mol.GetAtom(index)) and look at the
> remainder of the molecule after the atoms have been deleted it turns out
> that a number of atoms were deleted that had indices different from
> those I originally used to identify the atoms i want to remove.
>
> I am confused about the indices. Maybe the problem
> is also that after each OBmol.DeleteAtom(atom) the
> indices are reassigned in part (are they?). To test that
> I used DestroyAtom instead, which gave me a Segmentation fault
> once i tried to remove and then reassign hydrogens to clean
> up the chopped molecule.
>
> In the docu on OBmol.GetAtom() it says:
> "Atom indexing will change. Use iterator methods instead"
> i am not sure how to do that in this context, or if it would help ...
>
> a rough "symbolic" outline of what i tried is below.
> (the code assumes that there is only one unique
> match per molecule which is always true in my case)
>
> I'd appreciate any help, TIA!
> Michael
>
> === code:
>
> OBmol mymol;
> conv.Read(&mymol); // define mymol by reading a mol2 file.
> OBAtom *atom;
>
> smarts.Init(<smarts patttern provided as string>);
>
> if (smarts.Match(mymol)) {
>
> maplist = smarts.GetUMapList();
>
> for (matches = maplist.begin(); matches != maplist.end(); matches++) {
>
> for(int nat=0;nat<smarts.NumAtoms();nat++) {
> atom = mymol.GetAtom((*matches)[nat]); // at this point both (*matches)[nat] and atom.GetIdx() agree
> // and the numbers are as expected
> mymol.DeleteAtom(atom);
> }
> }
> }
>
> mymol.DeleteHydrogens();
> mymol.AddHydrogens(false,true,7.4);
> conv.Write(&mymol); // upon visual inspection of the output molecule
> // i see that in part wrong atoms have been deleted...
>
>
>
>
> ------------------------------------------------------------------------------
> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
> _______________________________________________
> OpenBabel-discuss mailing list
> Ope...@li...
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
|