Additionally, the API to work with rendering parameters is now much simpler. The previous posts did not really explain how to tune parameters, so here goes. One important thing to realize, is that a rendering parameter can only be changed if the generator that defines it has been registered. To see what parameters belongs to what generator, for which you can use the script discussed in post #3.
Atom Numbers
In some situations you like to draw atom numbers. This can be done by replacing the BasicAtomGenerator by an AtomNumberGenerator in the script given in post #1:
Listgenerators = new ArrayList (); generators.add(new BasicSceneGenerator()); generators.add(new BasicBondGenerator()); generators.add(new AtomNumberGenerator());
This would result in an image like this:
Now, we also might want to give those numbers a color, to make them stand out a bit. Orange, perhaps :) This is where rendering parameters come in. To the code from post #1, after the instantiation of the renderer, we add:
// tune parameters model = renderer.getRenderer2DModel(); model.set( AtomNumberGenerator.AtomNumberTextColor.class, Color.orange );The output then looks like:
Atom Numbers and Symbols
But you can also render both element symbols and numbers. Then, clearly, you just add both generators:
ListBut, in order to have the label and the symbol not overlap, we define an offset (Thanx to Sebastian, of MetFrag fame, for the feature request!):generators = new ArrayList (); generators.add(new BasicSceneGenerator()); generators.add(new BasicAtomGenerator()); generators.add(new BasicBondGenerator()); generators.add(new AtomNumberGenerator());
model.set( AtomNumberGenerator.Offset.class, new javax.vecmath.Vector2d(10,10) );Then it gets to look like:
This last full example will be available from GitHub shortly.
Update Steffen asked in the comments if it is possible to just color the atoms by element type. CDK-JChemPaint patch 15 does not allow that, but adding that feature is easy enough, and the patch will be part of the next release. Use this configuration:
generators.add(new BasicSceneGenerator()); generators.add(new BasicBondGenerator()); generators.add(new AtomNumberGenerator());And these parameter settings:
model = renderer.getRenderer2DModel(); model.set( AtomNumberGenerator.ColorByType.class, true );This give you for triazole:




But having C in black, N in blue and O in red would be asked too much ?
ReplyDeleteI'd probably have to write an own implementation then.
Yours,
Steffen
Sorry, I meant the *numbers* for C,N,O in colors...
ReplyDeleteSure. One of the powers of the new JChemPaint is that the code base is much easier to work with. See the updates in the blog post for the patch I just hacked up, which I will commit as part of the next release.
ReplyDeleteSure, you would have to make a FancyNumberGenerator (or some such name) that used BasicAtomGenerator.ColorByType to get the color for the atom.
ReplyDeleteI am looking at that enumeration + atom type image and can't help thinking that the numbers should be outside the molecule on all sides instead of just a simple offset. I mean if you put the numbers outside the atoms just like you would with a binding wouldn't that just look so much more awesome?
ReplyDeleteJonathan, how would that work when atoms are buried inside the molecule, as in complexer ring systems?
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteI've just began using jchempaint and find it good. but i was looking for something where i can mark bond angles and torsion angles. i am not very good at coding. but if i am not asking too much, can you guys fix it?
ReplyDelete