/** * Get all paths of lengths 0 to the specified length. * * This method will find all paths up to length N starting from each * atom in the molecule and return the unique set of such paths. * * @param container The molecule to search * @param searchDepth The maximum path length desired * @return A Map of path strings, keyed on themselves * @deprecated Use {@link #encodePaths(IAtomContainer, int, BitSet, int)} */ @Deprecated protected int[] findPathes(IAtomContainer container, int searchDepth) throws CDKException { Set<Integer> hashes = new HashSet<>(); Map<IAtom, List<IBond>> cache = new HashMap<>(); StringBuilder buffer = new StringBuilder(); for (IAtom startAtom : container.atoms()) { List<List<IAtom>> p = PathTools.getLimitedPathsOfLengthUpto(container, startAtom, searchDepth, pathLimit); for (List<IAtom> path : p) { if (hashPseudoAtoms || !hasPseudoAtom(path)) hashes.add(encodeUniquePath(container, cache, path, buffer)); } } int pos = 0; int[] result = new int[hashes.size()]; for (Integer hash : hashes) result[pos++] = hash; return result; }
private void traversePaths(State state, IAtom beg, IBond prev) throws CDKException { if (!hashPseudoAtoms && isPseudo(beg)) return; state.push(beg, prev); state.addHash(encodeUniquePath(state.apath, state.bpath, state.buffer)); if (state.numPaths > pathLimit) throw new CDKException("Too many paths! Structure is likely a cage, reduce path length or increase path limit"); if (state.apath.size() < state.maxDepth) { for (IBond bond : state.getBonds(beg)) { if (bond.equals(prev)) continue; final IAtom nbr = bond.getOther(beg); if (state.visit(nbr)) { traversePaths(state, nbr, bond); state.unvisit(nbr); // traverse all paths } } } state.pop(); }