Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:9804684
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// 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 = Longs.compare(Math.min(a1, a2), Math.min(b1, b2));
return cmp != 0 ? cmp : Longs.compare(Math.max(a1, a2), Math.max(b1, b2));
}
});
 
// set the new orderings
m.setAtoms(atoms);
m.setBonds(bonds);
 
// clean up
for (IAtom a : m.atoms()) {
a.removeProperty("rank");
if (a.getProperties().isEmpty())
a.setProperties(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.