Heh,

A colleague and I also encountered this bug today.. unfortunately the method named ísetí should really be called Ďaddí or better yet ĎputAll'. Anyways Iíll update that shortly. I think Iíve used that in the main code base under the assumption that setProperties(null) would clear the LinkedHashMap instances that have been created on every atom, definitely needs an update. An alternative sort that doesnít use the properties is possible but leaving the properties as non-null isnít really an issue itís just good practise to tidy up.

// clean up, canít free up empty LinkedHashMap instances :(
for (IAtom a : m.atoms()) {
a.removeProperty("rank");
}


J

On 4 Apr 2014, at 21:47, Cyrus Harmon <ch-cdk@bobobeach.com> wrote:


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?

thanks,

Cyrus

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:

setZoom()
setScale()
calculateDiagramBounds()


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
m.setAtoms(atoms);
m.setBonds(bonds);
 
// clean up
for (IAtom a : m.atoms()) {
a.removeProperty("rank");
if (a.getProperties().isEmpty())
a.setProperties(null);
}

J

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.

thanks,

Cyrus


------------------------------------------------------------------------------
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!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Cdk-devel mailing list
Cdk-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-devel

------------------------------------------------------------------------------
_______________________________________________
Cdk-devel mailing list
Cdk-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-devel

------------------------------------------------------------------------------
_______________________________________________
Cdk-devel mailing list
Cdk-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-devel