RemoveUpDownBonds extends AbstractFunction<Graph,Graph> { public Graph apply(final Graph g) throws InvalidSmilesException { Graph h = new Graph(g.order()); for (int u = 0; u < g.order(); u++) { h.addAtom(g.atom(u)); h.addTopology(g.topologyOf(u)); } int[] ordering = new DepthFirstOrder(g).visited; Map<Edge, Edge> replacements = new HashMap<Edge, Edge>(); Set<Integer> dbCentres = new TreeSet<Integer>(); for (int u = 0; u < g.order(); u++) { for (final Edge e : g.edges(u)) { if (e.other(u) > u && e.bond() == Bond.DOUBLE) { removeRedundant(g, e, ordering, replacements); dbCentres.add(u); dbCentres.add(e.other(u)); } } } for (Edge e : new HashSet<Edge>(replacements.keySet())) { if (dbCentres.contains(e.either()) && dbCentres.contains(e.other(e.either()))) { replacements.remove(e); } } 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; }  Graph apply(final Graph g);  }
@Test public void e_e_hexadiene_permute() throws Exception { String input = "C\\C(=C(\\C(=C(/[H])\\C)\\[H])/[H])\\[H]"; int[] p = new int[]{7, 2, 4, 1, 3, 6, 8, 9, 0, 5}; Graph g = Parser.parse(input); Assert.assertThat(Generator.generate(g.permute(p)), CoreMatchers .is("[H]\\C(\\C(=C(/[H])\\C)\\[H])=C(\\[H])/C")); Assert.assertThat(Generator.generate(new RemoveUpDownBonds().apply(g.permute(p))), CoreMatchers.is("[H]\\C(\\C(=C(/[H])C)[H])=C(\\[H])C")); }