Hi John,

Thanks for the suggestions. Iíll dig into the first one. As for the second one, that seems to work, but the setProperties(null) call gives me an NPE. It looks like ChemObject.setProperties doesnít check for null before dereferencing that. Is that a mistake or is trying to call setProperties(null) a mistake?



On Mar 27, 2014, at 3:40 AM, John May <john.wilkinsonmay@gmail.com> wrote:

Hi Cyrus,

First, is there a good way to pick reasonable dimensions for the drawing?

Yes, I donít have time to put together and test an example but basically the rendering depends on a zoom and a scale, the paint method youíre using resets these for each molecule there should be another paint() method that doesnít and allows you to:


To order the atoms is really clunky with the AtomContainer but would look something like this in Java: https://gist.github.com/johnmay/9804684

// 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
// clean up
for (IAtom a : m.atoms()) {
if (a.getProperties().isEmpty())


On 26 Mar 2014, at 18:47, Cyrus Harmon <ch-cdk@bobobeach.com> wrote:

Iíve been using the 2D SDG routines recently and have run across a couple of issues.

First, is there a good way to pick reasonable dimensions for the drawing? Drawing something like ethanol in a 512x512 graphics region doesnít work out to well. Or, expressed differently, is there a way to specify, say, a font/atom size and get back an appropriately sized graphic element?

Second, Iíve noticed that isomorphic atom containers with distinct underlying atomic representations (e.g. from reading distinct but equivalent SMILES strings) can yield different 2D structure diagrams. Are there any facilities for canonicalizing an atom container prior to rendering? I suppose I could write and then read back a canonical SMILES string, but that seems like a rather roundabout approach.



Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
Cdk-devel mailing list

Cdk-devel mailing list