Finding hit bonds

User f5e6ccf034

26-05-2008 20:49:44

This is again about highlighting search result matches. So-called hit atoms are straightforward but I don't understand the bond part of the code sample posted here:http://www.chemaxon.com/forum/ftopic60.html&highlight=highlight+hits It iterates over non-hit bonds, puts them in the hit set (the 0th set is the non-hit set, the 1st set the hit one) and then proceeds to set the hit bond color to the non-hit atom color! I can't make sense of it and in any case it doesn't do what I want: no bond is ever colored in that way.





The code below seems to do what I want (see attached picture): I tried it on OC as the query and OC1COCC(O)C1 and CC1CC(O)C(C1)C(O)C(C)CO as targets. This code strikes me as rather inefficient, though. Maybe there is a better way? The low-level methods are not well-documented and it is easy to overlook possibilities.


Code:



        search.setQuery(query);


        search.setTarget(mol);


        int[][] hits2 = search.findAll();


        if (hits2 == null) return;


        Set<MolAtom> atoms = new HashSet<MolAtom>();


        mol.setAtomSetSeqs(0);


        mol.setBondSetSeqs(0);


        for (int[] hits1 : hits2) {


            atoms.clear();


            for (int hit : hits1) {


                MolAtom atom = mol.getAtom(hit);


                atoms.add(atom);


                atom.setSetSeq(1); }


            for (int i = 0; i < mol.getBondCount(); i++) {


                MolBond bond = mol.getBond(i);


                if (atoms.contains(bond.getAtom1()) && atoms.contains(bond.getAtom2()))


                    bond.setSetSeq(1); } } }


ChemAxon 7c2d26e5cf

26-05-2008 21:14:55

Please see the following MarvinView applet examples. They demonstrates the usage of bond/atom sets coloring. Although these are applet examples but the concept are similar in beans.


MarvinView Example - Atom coloring


MarvinView Example - Coloring atom and bond sets


By the way, on current UGM (2008), we have talked about atom/bond coloring on the developer training.


If you color a bond, the nodes of the bond is also colored.

ChemAxon e500b51457

27-05-2008 08:59:04

More information and documentation about atom and bond-set handling:


http://www.chemaxon.com/marvin/help/developer/core/sets.html


http://www.chemaxon.com/marvin/examples/core/SetColoring.java.txt

User f5e6ccf034

28-05-2008 14:57:21

Thanks but the question was not about coloring: we covered that already in another thread. The question was: given a substructure defined by a set of atoms, how do I find the bonds that belong to the substructure? Because in practice if I color the atoms in the so-called hit set the corresponding bonds are not automatically colored, too.

ChemAxon 9c0afc9aaf

30-05-2008 07:26:13

Hi,





In principle, you only have 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.





The code in the mentioned topic should work fine (http://www.chemaxon.com/forum/ftopic60.html) - it was taken from a working example.





In your code it seems you are trying to color the hit bonds, which is not the way to go.





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.





Best regards,





Szilard

User f5e6ccf034

02-06-2008 05:02:25

Thanks for the answer. I reread the example and my confusion was due to my not having realized that bond and atom set colors are independant; I will try again. However the whole procedure seems rather convoluted to me: instead of colored atoms automatically and sometimes wrongly "bleeding" onto their adjacent half-bonds, which is then fixed in a second pass in which the incorrectly colored bonds are un-colored, it would be much more straightforward if


* atom and bond coloring were completely independant


* there were symmetrical getHitAtoms and getHitBonds methods





Meanwhile I do not understand what the JChemSearch.getHitsAsMolecule and HitDisplayTool.getHit methods return: do they return


1) the whole molecule, with the hit atoms and bonds already colored as per the option string or


2) the hit subgraph as a new molecule?


In the second case (which is what the name strongly suggests to me), how does that help me concretely? In the first case, then the method name is very confusing IMO: I would have expected a signature more ike


Code:
 void colorHits(Molecule target)

ChemAxon 9c0afc9aaf

02-06-2008 12:13:46

Hi,





Atom coloring cannot be independent of bond coloring, since in some cases you only see the bonds (e.g. a single atom of a carbon chain). The only indication of a colored atom is the colored half-bonds in this case.





Both mentioned methods return the whole target structure, with bonds and toms colored if needed (if set in the options).





We will try to make it more explicit in the API.





Best regards,





Szilard

User f5e6ccf034

04-06-2008 01:53:50

Atom coloring cannot be independent of bond coloring, since in some cases you only see the bonds. True, I hadn't thought of that. But it still surprising that coloring atoms should color bonds as well (or instead!). Maybe it would be preferable in this case to have some sort of halo or any other marker on the atoms themselves?





Also, I wonder if the sample code is really correct in the case of multiple hit groups. Think about it: each int[] hit atom group will "unmark" the bonds that should not be colored for this group but which maybe should be colored for another group. This if you are unlucky you may end up with fewer colored bonds than you should.

ChemAxon 9c0afc9aaf

04-06-2008 08:37:00

Hi,
Quote:
Maybe it would be preferable in this case to have some sort of halo or any other marker on the atoms themselves?
I think the current coloring method is what chemists expect, unless there is popular demand we do not plan to change this (AFAIK so far there were no complaints).
Quote:
Also, I wonder if the sample code is really correct in the case of multiple hit groups.
If the query consists of multiple fragments (and this results in multiple hit regions in the target) it is correct.


If you want to display more than one hit in a single target, you can simply assemble a bigger hit array containing all hit atoms, and pass it to MolHandler.getNonHitBonds() once in the referred code example ( http://www.chemaxon.com/forum/viewpost153.html#153 ).





Best regards,





Szilard

User f5e6ccf034

04-06-2008 20:39:58

I tried merging the hits as you suggested and it looks like I hit a bug in JChem. Run the attached program with


Code:
java Bug42 OC "OC1COCC(O)C1"



and you will get


Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2


        at chemaxon.util.MolHandler.getNonHitBonds(MolHandler.java:632)


        at Bug42.test(Bug42.java:47)


        at Bug42.main(Bug42.java:26)






Regards

ChemAxon 9c0afc9aaf

05-06-2008 08:18:17

Hi,





Could you let us know your JChem version please ?





Thanks,





Szilard

User f5e6ccf034

05-06-2008 10:50:35

JChem version is 5_0_03. Regards.

ChemAxon 9c0afc9aaf

05-06-2008 13:59:59

Hi,





I have examined your code.


This is not a bug, but I gave the wrong advice.


I did not remember correctly how exactly this older method works, I am sorry for the inconvenience.





MolHandler.getNonHitBonds() expects the hit array to correspond to the atoms in the query: the array size must be equal to the number of atoms in the query.


This is because the algorithm checks if there has been a bond between the pair of atoms in query, and decides on target bonds accordingly.


I will make this more explicit in the API.





I haven't carefully thought it over yet, but you could probably get the non-hit bonds for all hits individually, and then color only those bonds to non-hit color which are present in all of the results.





But if it's not really important to color all hits (as discussed in the other thread), getting the hits from JChemSearch is the easiest solution as long as it's fine for your users (most likely it is).





Best regards,





Szilard