Functions { public static Graph canonicalize(final Graph g, final long[] labels) { Integer[] is = new Integer[g.order()]; for (int i = 0; i < is.length; i++) is[i] = i; Arrays.sort(is, new Comparator<Integer>() { @Override public int compare(Integer i, Integer j) { if (labels[i] > labels[j]) return +1; else if (labels[i] < labels[j]) return -1; return 0; } }); int[] p = new int[g.order()]; for (int i = 0; i < is.length; i++) p[is[i]] = i; return g.permute(p); } private  Functions(); static Graph randomise(Graph g); static Graph reverse(Graph g); static Graph atomBasedDBStereo(Graph g); static Graph bondBasedDBStereo(Graph g); static Graph expand(Graph g); static Graph collapse(Graph g); static Graph normaliseDirectionalLabels(Graph g); static Graph canonicalize(final Graph g,
                                     final long[] labels); static Graph renumberAtomMaps(final Graph g);  }
@Test public void canoncalise() throws IOException { Graph g = Graph.fromSmiles("CCOCC"); Graph h = Functions.canonicalize(g, new long[]{56, 67, 3, 67, 56}); assertThat(h.toSmiles(), is("O(CC)CC")); }
@Test public void canoncalise2() throws IOException { Graph g = Graph.fromSmiles("CN1CCC1"); Graph h = Functions.canonicalize(g, new long[]{2, 1, 3, 5, 4}); assertThat(h.toSmiles(), is("N1(C)CCC1")); }