|
From: Michael B. <mb...@ya...> - 2009-03-18 07:50:04
|
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...
|