/** * 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; }
switch (f2.bond(u)) { case SINGLE: case IMPLICIT: case DOUBLE: case DOUBLE_AROMATIC: if (!f.equals(e)) return Status.COMPLETED; break; if ((f.bond() == Bond.UP || f.bond() == Bond.DOWN) && explicit.bond(u).inverse() != f.bond(u)) { return Status.INVALID; if (explicit.bond(u).inverse() != f2.bond(u)) { acc.put(f, f2.inverse()); BitSet visited = new BitSet(); visited.set(u); invertExistingDirectionalLabels(g, visited, acc, f2 .other(u)); int v = implicit.other(u); Edge existing = acc.put(implicit, new Edge(u, v, explicit.bond(u) .inverse())); if (existing != null && existing.bond(u) != explicit.bond(u).inverse()) { throw new InvalidSmilesException("unable to assign explict type for " + implicit);
@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; } });
if (e.other(u) > u && e.bond() == Bond.DOUBLE) { removeRedundant(g, e, ordering, replacements); dbCentres.add(u); dbCentres.add(e.other(u)); if (dbCentres.contains(e.either()) && dbCentres.contains(e.other(e.either()))) { replacements.remove(e); if (e.other(u) > u) { Edge replacement = replacements.get(e); if (replacement != null)
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); } } }
for (int i = 0; i < es.size(); i++) { Edge e = es.get(i); int v = e.other(u); if (!visited[v]) visit(u, v); ordering[v] = 2 + i; if (e.bond() == Bond.DOUBLE) offset = i; if (ordering[es.get(offset).other(u)] < ordering[u]) { .other(u)]) { j++; Bond label = labels[j++ % 2]; Edge f = new Edge(u, e.other(u), label); Edge existing = replacement.get(e); if (existing != null && existing.bond(u) != label) { BitSet visited = new BitSet(); visited.set(u); invertExistingDirectionalLabels(visited, e.other(u));
/** * 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(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); } } }
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; }
if (e.bond() != Bond.DOUBLE) continue; int u = e.either(); int v = e.other(u); Conformation conformation = first.bond(u) == second.bond(v) ? Conformation.TOGETHER : Conformation.OPPOSITE; ac.getBond(ac.getAtom(u), ac.getAtom(first.other(u))), ac.getBond(ac.getAtom(v), ac.getAtom(second.other(v)))}; while (f != null) { edges.add(f); v = f.other(v); f = findCumulatedEdge(g, v, f); second = findDirectionalEdge(g, v); if (second != null) { int cfg = first.bond(u) == second.bond(v) ? IStereoElement.TOGETHER : 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))), ac.getBond(ac.getAtom(v), ac.getAtom(second.other(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}; }
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 invertExistingDirectionalLabels(Graph g, int prev, BitSet visited, Map<Edge, Edge> replacement, BitSet dbAtoms, int u) { visited.set(u); final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(u, j); int v = e.other(u); if (v == prev) continue; Edge f = replacement.get(e); if (f == null) { replacement.put(e, e.inverse()); if (!visited.get(v)) { if (dbAtoms.get(v)) invertExistingDirectionalLabels(g, u, visited, replacement, dbAtoms, v); } } } }
/** * 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; }
for (Edge edge : g.edges()) { final int u = edge.either(); final int v = edge.other(u); IBond bond = builder.newBond(); bond.setAtoms(new IAtom[]{atoms[u], atoms[v]}); bonds[j++] = bond; switch (edge.bond()) { case SINGLE: bond.setOrder(IBond.Order.SINGLE); break; default: throw new IllegalArgumentException("Edge label " + edge.bond() + "cannot be converted to a CDK bond order");