OEShortestPath

The overloaded versions of the OEShortestPath function

Link

Description

OEShortestPath(atomA, atomB)

find shortest path between two atoms

OEShortestPath(atomA, atomB, atompred)

find shortest path between two atoms (excluding certain atoms)

OEShortestPath(atomA, atomB, bondpred)

find shortest path between two atoms (excluding certain bonds)

OESystem::OEIterBase<OEAtomBase> *
    OEShortestPath(const OEAtomBase *a, const OEAtomBase *b)

Returns a shortest path between the two given atoms. If no path exists the OEShortestPath function returns an empty iterator.

Example

OEGraphMol mol;
OESmilesToMol(mol, "c1ccc2c(c1)cccn2");

const OEAtomBase* atomA = mol.GetAtom(OEHasAtomIdx(2u));
const OEAtomBase* atomB = mol.GetAtom(OEHasAtomIdx(8u));

cout << "shortest path = ";
for (OEIter<OEAtomBase> atom = OEShortestPath(atomA, atomB); atom; ++atom)
  cout << atom->GetIdx() << ' ' << OEGetAtomicSymbol(atom->GetAtomicNum()) << " ";
cout << endl;
../../_images/OEShortestPath.png

Example of shortest path between atom 2 and 8

Note

The shortest path returned by the OEShortestPath function is non-unique. There are more than one valid shortest path can exist between two atoms. The OEShortestPath only returns one of them. For example, there are three valid six atoms long shortest path exist between atom 1 and 7 in the example above: 1, 2, 3, 9, 8, 7, 1, 0, 5, 4, 6, 7, and 1, 2, 3, 4, 6, 7.

OESystem::OEIterBase<OEAtomBase> *
    OEShortestPath(const OEAtomBase *a, const OEAtomBase *b,
                   const OESystem::OEUnaryPredicate<OEAtomBase> &excludeatoms)

Returns a shortest path between the two given atoms. The returned path will exclude any atom that satisfies the given atom predicate. If no path exists the OEShortestPath function returns an empty iterator.

Example

OEGraphMol mol;
OESmilesToMol(mol, "c1ccc2c(c1)cccn2");

const OEAtomBase* atomA = mol.GetAtom(OEHasAtomIdx(2u));
const OEAtomBase* atomB = mol.GetAtom(OEHasAtomIdx(8u));

cout << "shortest path = ";
for (OEIter<OEAtomBase> atom = OEShortestPath(atomA, atomB, OEIsNitrogen()); atom; ++atom)
  cout << atom->GetIdx() << ' ' << OEGetAtomicSymbol(atom->GetAtomicNum()) << " ";
cout << endl;
../../_images/OEShortestPath_AtomPredicate.png

Example of shortest path between atom 2 and 8 without traversing any nitrogen atom

OESystem::OEIterBase<OEAtomBase> *
    OEShortestPath(const OEAtomBase *a, const OEAtomBase *b,
                   const OESystem::OEUnaryPredicate<OEBondBase> &excludebonds)

Returns a shortest path between the two given atoms. The returned path will exclude any bond that satisfies the given bond predicate. If no path exists, the OEShortestPath function returns an empty iterator.

See also