Hi Aaron,

> http://pele.farmbio.uu.se/nightly-1.3.1/cdk-javadoc-1.4.0/

That documentation is very old, note the '1.3.1' in the domain name (probably 
linked from wiki).
        - The correct nightly is 
http://pele.farmbio.uu.se/nightly-1.4.x/cdk-javadoc-1.4.18.git/index.html but 
the address changes per release
        - For a stable address use, 
http://cdk.github.io/cdk/1.4/docs/api/index.html or 
http://cdk.github.io/cdk/1.5/docs/api/index.html

For the rendering you don't need to set the highlight colour, just colour hash. 
Also, many of the casts can be removed if the generics are parameterised.

>       RendererModel model = renderer.getRenderer2DModel();
>         Color highlight = Color.green;
>         Map<IChemObject, Color> colors = Maps.newHashMapWithExpectedSize(3); 
> // guava
>         colors.put(one, highlight);
>         colors.put(two, highlight);
>         colors.put(three, highlight);
>         model.getParameter(RendererModel.ColorHash.class).setValue(colors);


The highlight isn't working because you're not setting the colours on the 
correct atoms.

> IAtomContainer triazole, molecule;
> …
> IAtom one = molecule.getAtom(0);
> …
> renderer.paint(triazole, new AWTDrawVisitor(g2));

This code says, highlight the atoms (0,1,2) of 'molecule' but draw 'triazole'.

> triazole.getAtom(0) == molecule.getAtom(0);  // nope
> colors.get(triazole.getAtom(0));           // nope


You need to put the atoms of the molecule you're rendering (triazole) in the 
colour map. 

> Additionally, I'm unsure how the atom enumeration works. As in, will the 
> first "C" in my SMILES structure always be molecule.getAtom(0)?


Possibly, but not 100% it depends how ring closures etc are handled, generally 
though even if it were the case it's not good to rely on this. 

What precisely do you need if for in this case? If you're trying to have a 
'reference' in which you highlight 'queries' the correct way is to do a 
subgraph isomorphism and get the mappings.

Also I say this everytime but please use 'SilentChemObjectBuilder' instead of 
'DefaultChemObjectBuilder'. The later fires events on changes to the molecule 
which you rarely need.

J

On 12 Jul 2013, at 20:58, Aaron Germuth <[email protected]> wrote:

> Greetings,
> 
> I am currently writing a Java application which is in need of visualizing 2D 
> aromatic hydrocarbons. My application is capable of outputting the graphs 
> into SMILES notation which I then can visualize using a method similiar to 
> this:
> http://sourceforge.net/apps/mediawiki/cdk/index.php?title=Renderer_Tutorial-Single_Molecules
> 
> What I would like in addition, is to be able to highlight 4 or 5 atoms within 
> the structure. These atoms are not necessarily connected, and I do not need 
> to be able to highlight the bonds.
> 
> I found some info on highlighting bonds here:
> 
> http://sourceforge.net/apps/mediawiki/cdk/index.php?title=Renderer_Tutorial-Standard_Generators
> 
> Which at the bottom mentions:
> 
> " Highlighting of atoms and bonds is carried out by the atom and bond 
> highlight generators, not surprisingly. Remember that these should be lower 
> in the list to be rendered in the upper layers of the diagram. The shape and 
> fill of the atom highlights can be controlled through the renderer model. "
> 
> However, when I look here
> http://pele.farmbio.uu.se/nightly-1.3.1/cdk-javadoc-1.4.0/
> 
> in org.openscience.cdk.renderer.generators
> 
> There is no class by the name of Atom or Bond Highlight Generators. 
> Additionally, I can't find it in my source code either (version 1.4.18).
> 
> I then found this website:
> 
> http://chemutils.florida.scripps.edu:8080/cdk-export/
> 
> which takes a SMILES string and displays it in your browser. It has the 
> ability to accept another SMILES string which is contained within the first, 
> and it will highlight it. I looked at their source code and took this:
> 
> "
>            IAtom one = molecule.getAtom(0);
>            IAtom two = molecule.getAtom(1);
>            IAtom three = molecule.getAtom(2);
> 
>            RendererModel model = renderer.getRenderer2DModel();
>            ((RendererModel.ExternalHighlightColor)
>            
> model.getParameter(RendererModel.ExternalHighlightColor.class)).setValue(Color.green);
> 
>            Map colorHash = new HashMap();
>            colorHash.put(one, (Color)((RendererModel.ExternalHighlightColor)
>            
> model.getParameter(RendererModel.ExternalHighlightColor.class)).getValue());
>            colorHash.put(two, (Color)((RendererModel.ExternalHighlightColor)
>            
> model.getParameter(RendererModel.ExternalHighlightColor.class)).getValue());
>            colorHash.put(three, (Color)((RendererModel.ExternalHighlightColor)
>            
> model.getParameter(RendererModel.ExternalHighlightColor.class)).getValue());
> 
>    
> ((RendererModel.ColorHash)model.getParameter(RendererModel.ColorHash.class)).setValue(colorHash);
> "
> which was very close to what to what they had. I believe this should 
> highlight the first 3 atoms of my molecule green, however there is no 
> coloration in the final structure. If you want to see my entire ImageRenderer 
> Class, I have it attached (I believe you should look to 
> jButton1ActionPerformed method ).
> 
> Additionally, I'm unsure how the atom enumeration works. As in, will the 
> first "C" in my SMILES structure always be molecule.getAtom(0)?
> 
> Thank you for your time,
> 
> Aaron Germuth
> University of Northern British Columbia
> <ImageRenderer.java>------------------------------------------------------------------------------
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk_______________________________________________
> Cdk-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cdk-user

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to