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; }
@Override public Graph apply(Graph g) { Traversal traversal = new Traversal(g); Graph h = new Graph(g.order()); h.addFlags(g.getFlags(0xffffffff)); // copy atom/topology information this is unchanged for (int u = 0; u < g.order(); u++) { h.addAtom(g.atom(u)); h.addTopology(g.topologyOf(u)); } // change edges (only changed added to replacement) for (int u = 0; u < g.order(); u++) { final int d = g.degree(u); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(u, j); if (e.other(u) > u) { if (traversal.acc.containsKey(e)) { h.addEdge(traversal.acc.get(e)); } else { h.addEdge(e); } } } } return h.sort(new Graph.CanOrderFirst()); }
int numAtoms = g.order(); IAtom[] atoms = new IAtom[numAtoms]; IBond[] bonds = new IBond[g.size()]; for (int i = 0; i < g.order(); i++) { checkAtomStereo = checkAtomStereo || g.configurationOf(i).type() != Configuration.Type.None; atoms[i] = toCDKAtom(g.atom(i), g.implHCount(i)); for (int i = 0; i < g.order(); i++) atoms[i] = ac.getAtom(i); for (Edge edge : g.edges()) { for (int u = 0; u < g.order(); u++) { Configuration c = g.configurationOf(u); switch (c.type()) { case Tetrahedral: { IStereoElement se = newTetrahedral(u, g.neighbors(u), atoms, c); IStereoElement se = newSquarePlanar(u, g.neighbors(u), atoms, c); if (se != null) ac.addStereoElement(se); break; IStereoElement se = newTrigonalBipyramidal(u, g.neighbors(u), atoms, c); if (se != null) ac.addStereoElement(se); break; IStereoElement se = newOctahedral(u, g.neighbors(u), atoms, c);
@Test public void benzene_kekule() throws Exception { Graph g = convert(TestMoleculeFactory.makeBenzene(), 0); assertThat(g.toSmiles(), is("C=1C=CC=CC1")); }
/** * * @param ac * @return * @throws CDKException * @throws IOException */ public static String create(IAtomContainer ac) throws CDKException, IOException { EdgeToBondMap bonds = withSpaceFor(ac); int[][] graph = toAdjList(ac, bonds); long[] labels = label(ac, graph, betterInvariants(ac, graph, bonds)); Graph g = CDK2BEAM.toBeamGraph(ac); g = g.permute(toPermutation(labels)); g = g.resonate(); // ensure consistent Kekule form return g.toSmiles(); }
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); } }
for (final Edge e : g.edges()) { } else if (g.degree(v) == 2) { List<Edge> edges = new ArrayList<>(); edges.add(e); Configuration uConf = g.configurationOf(u); Configuration vConf = g.configurationOf(v); if (uConf.type() == Configuration.Type.DoubleBond && vConf.type() == Configuration.Type.DoubleBond) { int[] uNbrs = g.neighbors(u); int[] vNbrs = g.neighbors(v);
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(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); } } }
/** * 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; }
public State(Graph g, int maxidx) { this.g = g; this.visit = new boolean[g.order()]; this.map = new int[maxidx + 1]; this.nMaps = 0; } }
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); }