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; }
private void visit(int u) { visited[u] = i++; for (Edge e : g.edges(u)) { int v = e.other(u); if (visited[v] < 0) { visit(v); } } } }
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; }
private void invertExistingDirectionalLabels(BitSet visited, 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) { replacement.put(e, f.inverse()); } invertExistingDirectionalLabels(visited, v); } } }
private int[] findExtendedTetrahedralEnds(Graph g, int focus) { List<Edge> es = g.edges(focus); int prevEnd1 = focus; int prevEnd2 = focus; int end1 = es.get(0).other(prevEnd2); int end2 = es.get(1).other(prevEnd2); int tmp; while (end1 >= 0 && end2 >= 0) { tmp = getOtherDb(g, end1, prevEnd1); prevEnd1 = end1; end1 = tmp; tmp = getOtherDb(g, end2, prevEnd2); prevEnd2 = end2; end2 = tmp; } return new int[]{prevEnd1, prevEnd2}; }
/** * 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 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); }
List<Edge> es = g.edges(u); for (int i = 0; i < es.size(); i++) { Edge e = es.get(i);
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); }
private static void traverse(State s, int idx) { s.visit[idx] = true; int mapIdx = s.g.atom(idx).atomClass(); if (mapIdx != 0) { if (s.map[mapIdx] == 0) s.map[mapIdx] = ++s.nMaps; mapIdx = s.map[mapIdx]; s.g.setAtom(idx, AtomBuilder.fromExisting(s.g.atom(idx)).atomClass(mapIdx).build()); } for (Edge e : s.g.edges(idx)) { int nbr = e.other(idx); if (!s.visit[nbr]) traverse(s, nbr); } }
private Topology toTrigonal(Graph g, Edge e, int u) { List<Edge> es = g.edges(u); int offset = es.indexOf(e);
public Graph apply(Graph g) { Graph h = new Graph(g.order()); for (int u = 0; u < g.order(); u++) { h.addAtom(fromSubset(g.atom(u), g.bondedValence(u), g.degree(u))); h.addTopology(g.topologyOf(u)); } // edges are unchanged for (Edge e : g.edges()) h.addEdge(e); return h; }
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()); }
public Graph apply(Graph g) { Graph h = new Graph(g.order()); for (int u = 0; u < g.order(); u++) { // only attempt subset conversion if no known topology Topology t = g.topologyOf(u); if (t.type() == None) { h.addAtom(toSubset(g.atom(u), g, u)); } else { h.addAtom(g.atom(u)); h.addTopology(t); } } // edges are unchanged for (Edge e : g.edges()) h.addEdge(e); return h; }
/** * Transform all explicit to implicit bonds. The original graph is * unmodified. * * @param g a chemical graph * @return new chemical graph but with all explicit bonds */ public Graph apply(final Graph g) { Graph h = new Graph(g.order()); // atom/topology information doesn't change for (int u = 0; u < g.order(); u++) { h.addAtom(g.atom(u)); h.addTopology(g.topologyOf(u)); } // transform edges for (int u = 0; u < g.order(); u++) { for (final Edge e : g.edges(u)) { if (e.other(u) > u) h.addEdge(toImplicitEdge(g, e)); } } return h; }
public Graph apply(Graph g) { Graph h = new Graph(g.order()); // copy atom/topology information this is unchanged for (int u = 0; u < g.order(); u++) { if (g.topologyOf(u).type() == DoubleBond) { h.addAtom(reducedAtom(g, u)); } else { h.addAtom(g.atom(u)); h.addTopology(g.topologyOf(u)); } } Map<Edge, Edge> replacements = new Traversal(g).replacement; // append the edges, replacing any which need to be changed for (int u = 0; u < g.order(); u++) { for (Edge e : g.edges(u)) { if (e.other(u) > u) { Edge replacement = replacements.get(e); if (replacement != null) e = replacement; h.addEdge(e); } } } return h; }
/** * Transform all implicit to explicit bonds. The original graph is * unmodified * * @param g a chemical graph * @return new chemical graph but with all explicit bonds */ public Graph apply(final Graph g) { Graph h = new Graph(g.order()); // copy atom/topology information for (int u = 0; u < g.order(); u++) { h.addAtom(g.atom(u)); h.addTopology(g.topologyOf(u)); } // apply edges for (int u = 0; u < g.order(); u++) { for (final Edge e : g.edges(u)) { if (e.other(u) > u) h.addEdge(toExplicitEdge(g, e)); } } return h; }