On 4/7/11 4:24 AM, Jalil Zerdani wrote: > Dear fellow developers, > > I am actually developing a software to find the common structure between two > molecules inspired from the "RASCAL" algorithm. > I just happened to wonder if it would possible to use Open Babel to do so by > using the command "obabel -isdf -osmiles" ? > > The only problem I am facing is that we know the id of each atom in the SDF > format but that we lose this information when we transform it into SMILES, in > our project, we need this information. So I thought : "maybe we could > intercept the transformation during the conversion and build a file/table > that would contain the information id for each atom in SMILES according to > their id in SDF". > > Example : > > CN=C=O > 12 3 4 > > So I am writing to you to ask you this question : > > *Is this possible to know the id of the atoms in SMILES from the ids in SDF > using Open Babel as it is now ?* > *If not, would it be possible to work on the project to add this feature ?*
The canonical SMILES generator keeps track of the original order of your atoms, and you can get that information in your own C++ program. Here is a sample of code from src/formats/smilesformat.cpp (starting at line 3979) that appends the X/Y atom coordinates in canonical order to the SMILES. You could use this same trick to write out any property, include the atom's original atom number. The property "SMILES Atom Order" is what you're looking for. if (pConv->IsOption("x") && mol.HasData("SMILES Atom Order")) { vector<string> vs; string canorder = mol.GetData("SMILES Atom Order")->GetValue(); tokenize(vs, canorder); ofs << '\t'; for (int i = 0; i < vs.size(); i++) { int idx = atoi(vs[i].c_str()); OBAtom *atom = mol.GetAtom(idx); if (i > 0) ofs << ","; ofs << atom->GetX() << "," << atom->GetY(); } } If you just want the atom's original atom number, the vector vs[] in the example above is what you want. Note that this works even when you started with an SDF. The atom numbers will correspond to the original order in which they appeared in the SD file. Craig ------------------------------------------------------------------------------ Xperia(TM) PLAY It's a major breakthrough. An authentic gaming smartphone on the nation's most reliable network. And it wants your games. http://p.sf.net/sfu/verizon-sfdev _______________________________________________ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss