Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// compute labelling (others are available)
final long[] labels = Canon.label(m, GraphUtil.toAdjList(m));
IAtom[] atoms = AtomContainerManipulator.getAtomArray(m);
IBond[] bonds = AtomContainerManipulator.getBondArray(m);
// atoms don't know their index
for (int i = 0; i < labels.length; i++)
atoms[i].setProperty("rank", labels);
// sort atoms and bonds (ensure neighbours are provided in the same order)
Arrays.sort(atoms, new Comparator<IAtom>() {
@Override public int compare(IAtom a, IAtom b) {
return a.getProperty("rank", Long.class)
.compareTo(a.getProperty("rank", Long.class));
Arrays.sort(bonds, new Comparator<IBond>() {
@Override public int compare(IBond a, IBond b) {
long a1 = a.getAtom(0).getProperty("rank");
long a2 = a.getAtom(1).getProperty("rank");
long b1 = b.getAtom(0).getProperty("rank");
long b2 = b.getAtom(1).getProperty("rank");
int cmp =, a2), Math.min(b1, b2));
return cmp != 0 ? cmp :, a2), Math.max(b1, b2));
// set the new orderings
// clean up
for (IAtom a : m.atoms()) {
if (a.getProperties().isEmpty())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment