Here's another very simple test program. It starts with [AlH3], delete the
hydrogens, then adds hydrogens back one by one. It will never print less
than three hydrogens, but will print correctly once you exceed the original
three hydrogens. A program is attached below; here is its output.
molecule starts with 4 atoms.
delete H, idx = 4
delete H, idx = 3
delete H, idx = 2
molecule now has 1 atoms.
[AlH3]
add H, idx = 2, molecule now has 2 atoms.
[AlH3]
add H, idx = 3, molecule now has 3 atoms.
[AlH3]
add H, idx = 4, molecule now has 4 atoms.
[AlH3]
add H, idx = 5, molecule now has 5 atoms.
[AlH4]
add H, idx = 6, molecule now has 6 atoms.
[AlH5]
Note that for H0, H1, H2 and H3, it incorrectly prints H3.
Now edit the program, change Aluminum to Cadmium, and it works perfectly,
printing the correct number of hydrogens, like this:
molecule starts with 4 atoms.
delete H, idx = 4
delete H, idx = 3
delete H, idx = 2
molecule now has 1 atoms.
[Ca]
add H, idx = 2, molecule now has 2 atoms.
[CaH]
add H, idx = 3, molecule now has 3 atoms.
[CaH2]
add H, idx = 4, molecule now has 4 atoms.
[CaH3]
add H, idx = 5, molecule now has 5 atoms.
[CaH4]
add H, idx = 6, molecule now has 6 atoms.
[CaH5]
Anyone know why?
Thanks,
Craig
#include <sstream>
#include <openbabel/babelconfig.h>
#include <openbabel/mol.h>
#include <openbabel/obconversion.h>
using namespace std;
using namespace OpenBabel;
static string test_mol
(
"\n"
" OpenBabel03191316172D\n"
"\n"
" 4 3 0 0 0 0 0 0 0 0999 V2000\n"
" 0.0000 0.0000 0.0000 Al 0 0 0 0 0 0 0 0 0 0 0 0\n"
" 0.0000 0.0000 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n"
" 0.0000 0.0000 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n"
" 0.0000 0.0000 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n"
" 1 2 1 0 0 0 0\n"
" 1 3 1 0 0 0 0\n"
" 1 4 1 0 0 0 0\n"
"M END\n"
"$$$$\n"
);
static void remove_explicit_hydrogen(OBMol *pmol)
{
}
int main(int argc,char **argv)
{
OBAtom *atom;
vector<OBAtom*> delete_h;
vector<OBAtom*>::iterator ai;
OBMol *pmol = new OBMol;
OBConversion conv(&cin, &cout);
conv.SetInAndOutFormats("sdf", "smi");
pmol->Clear();
conv.ReadString(pmol, test_mol);
pmol->BeginModify();
cout << "molecule starts with " << pmol->NumAtoms() << " atoms.\n";
for (atom = pmol->BeginAtom(ai); atom; atom = pmol->NextAtom(ai)) {
if (atom->GetAtomicNum() == 1)
delete_h.push_back(atom);
}
for (ai = delete_h.end() - 1; ai >= delete_h.begin(); ai--) {
atom = *ai;
cout << "delete H, idx = " << atom->GetIdx() << "\n";
pmol->DeleteAtom(atom);
}
cout << "molecule now has " << pmol->NumAtoms() << " atoms.\n";
pmol->EndModify();
conv.Write(pmol);
for (int i = 2; i <= 6; i++) {
pmol->BeginModify();
atom = pmol->NewAtom(i);
atom->SetAtomicNum(1);
pmol->AddBond(1, i, 1);
pmol->EndModify();
cout << "add H, idx = " << i <<", molecule now has " <<
pmol->NumAtoms() << " atoms.\n";
conv.Write(pmol);
}
}
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel