How to highlight and align substructure hits ?

ChemAxon 9c0afc9aaf

04-06-2004 09:40:01

[quoted from a user's e-mail]





"When you do a substructure search, is it possible to highlight the substructure when you view the molecule in MarvinView (I have seen that there are ways to select atoms when you view molecules using the Marvin applets, but can it be done using MarvinBeans).


Also if you do a search on a library of molecules can you orientate/rotate each molecule so that the substructure in each molecule is in the same orientation."

ChemAxon 9c0afc9aaf

04-06-2004 10:04:26

Both of these features are demonstrated in this simple example.


The full source is also at: <jchem_dir>\examples\java\HitAlignmentAndColoringExample.java





Code:






        //Using MolSearch to search for contained substructure:


        MolSearch ms=new MolSearch();


        ms.setHitIncludesRNodes(true);


        ms.setQuery(query);


        ms.setTarget(target);


        int[] hit=ms.findFirst();


       


        if (hit==null) {


            System.err.println("Substructure not found");


            return; //exits


        }


       


        MolHandler mh=new MolHandler(query);


        //rotating structure:


        mh.align(target, hit);


       


        MViewPane mpan=new MViewPane();


        // atomset 1 represents hit atoms, 0 all the others:


        mpan.setAtomSetColor(0, Color.black);


        mpan.setAtomSetColor(1, Color.red);


       


        //hit atoms will be in set 1, others remain in default set 0


        for (int x=0; x<hit.length; x++) {


            if (hit[x]>=0) {    //not implicit H


                target.getAtom(hit[x]).setSetSeq(1);


            }


        }


       


        //Using bond coloring to clear unwanted half bond colors:


        ArrayList nhb=MolHandler.getNonHitBonds(query, target, hit);


        for (int x=0; x<nhb.size(); x++) {


            MolBond bond=(MolBond)nhb.get(x);


            bond.setSetSeq(1);


        }


        mpan.setBondSetColor(1, Color.black);


       


        //putting the structure into Marvin:


        mpan.setM(0, target);





User 65339aced8

17-07-2004 22:03:04

Hi Szilard,


Will That be possible with JSP as well?


Sincerely,


Niels.

ChemAxon 9c0afc9aaf

18-07-2004 07:32:14

Hi Niels,





It is already possible, as demonstrated at :





http://www.jchem.com/examples/jsp1_x/index.jsp





(check the " Substructure hit coloring" and "Hit alignment" options on the query page)





The source of this example is included in the JChem package, with installation instructions (under jchem\examples\jsp1_x).





The source of this example is maybe a bit complex, but the coloring part very similar to the Java example.


The only difference is that you have to specify the coloring for Marvin by applet parameters, and not by Java calls.


(the atoms / bonds to be colored are computed the same way)





Please see





http://www.chemaxon.com/marvin/doc/dev/example-view6.html





for a working example for atom and bond coloring, together with the source code.

ChemAxon 9c0afc9aaf

30-05-2008 07:40:07

Some additional information and new API methods for this:








In principle, one only has to color the atoms to the hit color (e.g. red) when displaying a hit. When coloring an atom the connecting half of all its bonds are also colored. In fact it may be too much, as two neighboring hit atoms with no connection between them in the query can fully color the bond between them unnecessarily. The trick is to set non-hit bonds to the non-hit color (e.g. black) explicitly (set 1) , we leave the hit bonds to neutral color (set 0), so they get the color from the hit atoms.





Since JChem 5.0 we provide some higher-level API for displaying hits.





If you want to display the hits of a database search it's easiest to use JChemSearch.getHitsAsMolecules() :





http://www.chemaxon.com/jchem/doc/api/chemaxon/jchem/db/JChemSearch.html#getHitsAsMolecules(int[],%20chemaxon.util.HitColoringAndAlignmentOptions,%20java.util.ArrayList,%20java.util.ArrayList)





In case of two Molecule objects I recommend to use HitDisplayTool:





http://www.chemaxon.com/jchem/doc/api/chemaxon/util/HitDisplayTool.html





Both of them are using this options class as a parameter, where you can set display features like colors, rotating to substructure, partial clean to substructure and how to display Markush structures:





http://www.chemaxon.com/jchem/doc/api/chemaxon/util/HitColoringAndAlignmentOptions.html





You can either set the colored structures to an MViewPane in a GUI application, or use the Marvin Documnts ("mrv") format to display them on the web in a Marvin View applet.

User a11e9761d6

20-08-2013 19:02:01

Hi ChemAxon,


I'm updating some older hit highlighting code to use the HitDisplayTool and HitColoringAndAlignmentOptions. Unfortunately it appears that the HitColoringAndAlignmentOptions do not allow you to preserve non-hit atom colors while highlighting the hit. In other words, I want to highlight the hit portion of the molecule (e.g. bright green), while maintaining the default colors of the rest of the molecule: black for carbon, red for oxygen, blue for nitrogen...


Do the higher-level APIs not support this?


Thanks,


Krishna

ChemAxon abe887c64e

22-08-2013 09:02:15

Hi Krishna,


Sorry to say, but at present we don't provide opportunity for coloring the non-hit parts of the hit structure by the default colors.


Best regards,


Krisztine