You're looking for a breadth-first search (BFS), which is available in OB. See the Python code at http://baoilleach.blogspot.com/2008/07/calculate-circular-fingerprints-with.html to get some idea of how to use it.
You just need to start the BFS at atom1, and stop it when it comes to atom2. The value of depth will give you the answer. - Noel On 1 August 2011 10:24, Pascal Muller <pascal.jm.mul...@gmail.com> wrote: > Hi, > > I would to know the number of bonds between two atoms within a > molecule (i.e. the shortest path). > Is there a function giving this information? > > I only found this thread > http://forums.openbabel.org/OB-GetDistance-function-td959922.html > with a piece of code... but I still don't understand C++, especially > the "_name" and "->" stuff. > > and this one, where the function seems to do what I want: > http://forums.openbabel.org/code-for-GenerateTopologicalDistanceMatrix-function-td960170.html > > but I didn't found any mention of the > GenerateTopologicalDistanceMatrix or distancematrix functions in the > documentation. > Is it already implemented? > Should I paste this code somewhere in the OpenBabel source code and recompile? > > > Or if I just translate in my pybel script this piece of code > > distancematrix.clear(); > FOR_ATOMS_OF_MOL(a, mol) { > for(OBMolAtomBFSIter b(mol, a->GetIdx()); b; ++b ){ > distancematrix[a->GetIdx()][b->GetIdx()]=b.CurrentDepth()-1; > } > } > > it should work? > > Many thanks, > Pascal > > ------------------------------------------------------------------------------ > Got Input? Slashdot Needs You. > Take our quick survey online. Come on, we don't ask for help often. > Plus, you'll get a chance to win $100 to spend on ThinkGeek. > http://p.sf.net/sfu/slashdot-survey > _______________________________________________ > OpenBabel-discuss mailing list > OpenBabel-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/openbabel-discuss > ------------------------------------------------------------------------------ Got Input? Slashdot Needs You. Take our quick survey online. Come on, we don't ask for help often. Plus, you'll get a chance to win $100 to spend on ThinkGeek. http://p.sf.net/sfu/slashdot-survey _______________________________________________ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss