private Edge findCumulatedEdge(Graph g, int v, Edge e) { Edge res = null; for (Edge f : g.edges(v)) { if (f != e && f.bond() == Bond.DOUBLE) { if (res != null) return null; res = f; } } return res; }
static Configuration.DoubleBond configurationOf(Graph g, int x, int u, int v, int y) { Edge e = g.edge(u, v); if (e.bond() != Bond.DOUBLE) throw new IllegalArgumentException("atoms u,v are not labelled as a double bond"); Edge e1 = g.edge(u, x); Edge e2 = g.edge(v, y); Bond b1 = e1.bond(u); Bond b2 = e2.bond(v); if (b1 == Bond.IMPLICIT || b1 == Bond.SINGLE) return Configuration.DoubleBond.UNSPECIFIED; if (b2 == Bond.IMPLICIT || b2 == Bond.SINGLE) return Configuration.DoubleBond.UNSPECIFIED; return b1 == b2 ? Configuration.DoubleBond.TOGETHER : Configuration.DoubleBond.OPPOSITE; }
private List<Edge> doubleBondLabelledEdges(Graph g) { List<Edge> es = new ArrayList<Edge>(); for (int u = 0; u < g.order(); u++) { for (Edge e : g.edges(u)) { if (e.other(u) > u && e.bond() == Bond.DOUBLE) { es.add(e); } } } return es; }
private int getOtherDb(Graph g, int u, int v) { for (Edge e : g.edges(u)) { if (e.bond() != Bond.DOUBLE) continue; int nbr = e.other(u); if (nbr == v) continue; return nbr; } return -1; }
Edge firstDirectionalLabel(Graph g, int u) { Edge first = null; final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge f = g.edgeAt(u, j); if (f.bond() == Bond.UP || f.bond() == Bond.DOWN) { if (first == null || ordering[f.other(u)] < ordering[first.other(u)]) first = f; } } return first; }
/** * 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; }
/** * 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; }
private boolean hasAdjDirectionalLabels(Graph g, int u) { final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge f = g.edgeAt(u, j); if (f.bond().directional()) return true; } return false; }
private void invertExistingDirectionalLabels(Graph g, BitSet visited, Map<Edge, Edge> replacement, int u) { visited.set(u); if (g.topologyOf(u) == null) return; for (Edge e : g.edges(u)) { int v = e.other(u); if (!visited.get(v)) { Edge f = replacement.get(e); if (f != null && f.bond().directional()) { replacement.put(e, f.inverse()); } else if (e.bond().directional()) { replacement.put(e, e.inverse()); } invertExistingDirectionalLabels(g, visited, replacement, v); } } }
private Atom reducedAtom(Graph g, int u) { Atom a = g.atom(u); int sum = 0; for (Edge e : g.edges(u)) { sum += e.bond().order(); } return ToSubsetAtoms.toSubset(g.atom(u), g, u); }
if (v == p) continue; if (e.bond().order() == 2 && hasAdjDirectionalLabels(g, e)) {
private IStereoElement newExtendedTetrahedral(int u, Graph g, IAtom[] atoms) { int[] terminals = findExtendedTetrahedralEnds(g, u); int[] xs = new int[]{-1, terminals[0], -1, terminals[1]}; int n = 0; for (Edge e : g.edges(terminals[0])) { if (e.bond().order() == 1) xs[n++] = e.other(terminals[0]); } n = 2; for (Edge e : g.edges(terminals[1])) { if (e.bond().order() == 1) xs[n++] = e.other(terminals[1]); } Arrays.sort(xs); Stereo stereo = g.configurationOf(u).shorthand() == Configuration.CLOCKWISE ? Stereo.CLOCKWISE : Stereo.ANTI_CLOCKWISE; return new org.openscience.cdk.stereo.ExtendedTetrahedral(atoms[u], new IAtom[]{atoms[xs[0]], atoms[xs[1]], atoms[xs[2]], atoms[xs[3]]}, stereo); }
if (e.other(u) > u && e.bond() == Bond.DOUBLE) { removeRedundant(g, e, ordering, replacements); dbCentres.add(u);
/** * 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; }
boolean safeToClean(Graph g, int v, Map<Edge,Edge> replacements) { final int d = g.degree(v); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(v, j); if (e.bond().order() == 2) { int w = e.other(v); final int d2 = g.degree(w); for (int j2 = 0; j2 < d2; ++j2) { final Edge f = g.edgeAt(w, j2); if (isDirectional(f, replacements)) return false; } } } return true; }
private Atom asBracketAtom(int u, Graph g) { Atom a = g.atom(u); int sum = a.aromatic() ? 1 : 0; for (Edge e : g.edges(u)) { sum += e.bond().order(); } return new AtomImpl.BracketAtom(-1, a.element(), a.aromatic() ? a.element().aromaticImplicitHydrogens(sum) : a.element().implicitHydrogens(sum), 0, 0, a.aromatic()); }