@Override public int compare(Edge e, Edge f) { int u1 = e.either(); int v1 = e.other(u1); int u2 = f.either(); int v2 = f.other(u2); int min1 = Math.min(ordering[u1], ordering[v1]); int min2 = Math.min(ordering[u2], ordering[v2]); int cmp = min1 - min2; if (cmp != 0) return cmp; int max1 = Math.max(ordering[u1], ordering[v1]); int max2 = Math.max(ordering[u2], ordering[v2]); return max1 - max2; } });
/** * Utility for find the first directional edge incident to a vertex. If * there are no directional labels then null is returned. * * @param g graph from Beam * @param u the vertex for which to find * @return first directional edge (or null if none) */ private Edge findDirectionalEdge(Graph g, int u) { List<Edge> edges = g.edges(u); if (edges.size() == 1) return null; Edge first = null; for (Edge e : edges) { Bond b = e.bond(); if (b == Bond.UP || b == Bond.DOWN) { if (first == null) first = e; else if (((first.either() == e.either()) == (first.bond() == b))) return null; } } return first; }
private boolean hasAdjDirectionalLabels(Graph g, Edge e) { int u = e.either(); int v = e.other(u); return hasAdjDirectionalLabels(g, u) && hasAdjDirectionalLabels(g, v); }
/** * Given a double bond edge traverse the neighbors of both endpoints and * accumulate any explicit replacements in the 'acc' accumulator. * * @param g the chemical graph * @param e a edge in the graph ('double bond type') * @param acc accumulator for new edges * @throws uk.ac.ebi.beam.InvalidSmilesException * thrown if the edge could not be converted */ private void removeRedundant(Graph g, Edge e, int[] ordering, Map<Edge, Edge> acc) throws InvalidSmilesException { int u = e.either(), v = e.other(u); replaceImplWithExpl(g, e, u, ordering, acc); replaceImplWithExpl(g, e, v, ordering, acc); }
Iterator<Edge> it = edges.iterator(); Edge explicit = it.next(); int v = explicit.either(); int w = explicit.other(v); acc.put(explicit, new Edge(v,
/** * Given a double bond edge traverse the neighbors of both endpoints and accumulate any explicit * replacements in the 'acc' accumulator. * * @param g the chemical graph * @param e a edge in the graph ('double bond type') * @param acc accumulator for new edges * @throws InvalidSmilesException thrown if the edge could not be converted */ private Status replaceImplWithExpl(Graph g, Edge e, Map<Edge, Edge> acc) throws InvalidSmilesException { int u = e.either(), v = e.other(u); Status ustat = replaceImplWithExpl(g, e, u, acc); Status vstat = replaceImplWithExpl(g, e, v, acc); if (ustat == vstat) return ustat; else if (ustat == Status.INVALID && vstat != Status.WAITING) return Status.INVALID; else if (vstat == Status.INVALID && ustat != Status.WAITING) return Status.INVALID; else return Status.WAITING; }
/** * Given a chemical graph and an edge in that graph, return the explicit * form of that edge. Neither the graph or the edge is modified, if the edge * is already explicit then 'e' is returned. * * @param g chemical graph * @param e an edge of g * @return the edge with specified explicit bond type */ static Edge toExplicitEdge(final Graph g, final Edge e) { final int u = e.either(), v = e.other(u); if (e.bond() == Bond.IMPLICIT) { return new Edge(u, v, type(g.atom(u), g.atom(v))); } return e; }
/** * Given a chemical graph and an edge in that graph, return the implicit * form of that edge. Neither the graph or the edge is modified, if the edge * is already explicit then 'e' is returned. * * @param g chemical graph * @param e an edge of g * @return the edge with specified explicit bond type */ static Edge toImplicitEdge(final Graph g, final Edge e) { final int u = e.either(), v = e.other(u); if (e.bond() == Bond.SINGLE || e.bond() == Bond.AROMATIC) { return new Edge(u, v, type(g.atom(u), g.atom(v), e.bond())); } return e; }
int u = e.either(); int v = e.other(u); final int d = g.degree(u);
private void flip(Graph g, Edge e, BitSet dbAtoms) { int u = e.either(); int v = e.other(u); if (ordering[u] < ordering[v]) { Edge first = firstDirectionalLabel(g, u); if (first != null) { flip(first, u, dbAtoms); } else { first = firstDirectionalLabel(g, v); flip(first, v, dbAtoms); } } else { Edge first = firstDirectionalLabel(g, v); if (first != null) { flip(first, v, dbAtoms); } else { first = firstDirectionalLabel(g, u); flip(first, u, dbAtoms); } } }
int u = e.either(); int v = e.other(u); : IStereoElement.OPPOSITE; Edge middleEdge = edges.get(edges.size()/2); IBond middleBond = ac.getBond(ac.getAtom(middleEdge.either()), ac.getAtom(middleEdge.other(middleEdge.either()))); IBond[] ligands = new IBond[]{ ac.getBond(ac.getAtom(u), ac.getAtom(first.other(u))),
int u = e.either(); int v = e.other(u);
for (Edge edge : g.edges()) { final int u = edge.either(); final int v = edge.other(u); IBond bond = builder.newBond();