|
From: Tim V. <tim...@gm...> - 2009-03-18 15:39:27
|
On Wed, Mar 18, 2009 at 4:29 PM, Michael Brunsteiner <mb...@ya...> wrote:
>
>
> 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
Example how to "save" the atoms for deletion:
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();
std::vector<OBAtom*> atomsToDelete;
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
// "save" the in
atomsToDelete.push_back(atom);
}
// delete the atoms
for (std::vector<OBAtom*>::iterator iter = atomsToDelete.begin();
iter != atomsToDelete.end(); ++iter)
mol.DeleteAtom(*iter);
}
}
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...
Tim
|