multiple queries in logical conditions

ChemAxon a3d59b832c

14-10-2006 07:38:32

Quote:
I am testing Jchem. I wonder if I can query one structure which conain a fragment AND do not contain another fragment?
You can do this with the help of Chemical Terms.





For example, if you would like to search for molecules which contain a hydroxyl group but not a carbonyl group, you can use this expression:





Code:
$ evaluate -e 'match("CO") && !match("C=O")' CCCCO CCCCC O=CCCO


1


0


0






In the above case, I used command-line program evaluate, but Chemical Terms language can be used in different environments as well, like searching in the database with JChem Base or Cartridge, as filter or reactivity condition in Reactor, filter for the jcsearch program, used within Java programs, etc.





When using for querying in the database, it is more efficient if you use the carbonyl as the query and use "!match("C=O")" as the filter.





There are further ways you can combine multiple queries, but they do not apply for this particular case. (Recursive smarts, --and, --or options of jcsearch, alternative queries in the Cartridge, etc.) Let me know if you are interested in any of them.





Best regards,


Szabolcs

ChemAxon a3d59b832c

23-10-2006 20:38:26

Quote:
thank you very much for your reply. I come cross another question:





I currently use Jchemsearch class to do substructure search. Only one parameter is passed to the Jchemsearch object. I wonder if I can implement the chemical term you mentioned below into our Jchemsearch functinality.


Quote:
evaluate -e 'match("CO") && !match("C=O")' CCCCO CCCCC O=CCCO








thanks again,


Yes. Use the following methods of JChemSearch:





Code:
    searcher.setQueryStructure("CO");


    searcher.setFilter("!match("C=O")");


ChemAxon a3d59b832c

23-10-2006 21:16:25

If you are searching on large database tables and high performance is important, it may be beneficial to do subsequent searches for each fragment to be searched for. (The filter Chemical Terms expressions donĀ“t use the rapid fingerprint screening that makes database searching very fast.)





These methods of JChemSearch are useful:





setResultTable()


setReturnsNonHits()





And these to use the previous results:





setFilterQuery() http://www.chemaxon.com/jchem/doc/api/chemaxon/jchem/db/JChemSearch.html#setFilterQuery(java.lang.String)


setFilterIDList() http://www.chemaxon.com/jchem/doc/api/chemaxon/jchem/db/JChemSearch.html#setFilterIDList(int[])


setFilterIDNotList() http://www.chemaxon.com/jchem/doc/api/chemaxon/jchem/db/JChemSearch.html#setFilterIDNotList(int[])





We plan to improve the performance of match() expressions in Chemical Terms filters also, but that is not our highest priority at the moment.

ChemAxon a3d59b832c

25-10-2006 11:27:21

Quote:
I see how I can input one parameter for not matching now. I want to ask more for this. I want to search two parameters at the same time, say ! match (C=O) && ! match (S=O), can I do this using searcher.setFilter() function? or more generally, can I put 'match("CO") && !match("C=O")' into setQueryStructure() directly? say, setQueryStructure('match("CO") && !match("C=O"))?
setQueryStructure expects a molecule, And setFilter() expects a Chemical Terms expression.


To achive " !match (C=O) && !match (S=O) ", one possibility is the following (the easiest to write):





Code:
jchemsearch.setQueryStructure("");  // empty query matches everything


jchemsearch.setFilter("!match (\"C=O\") && !match (\"S=O\") ");





In general, you can interpret that the query structure is in AND relation with the filter, so these are equivalent:





Code:
jchemsearch.setQueryStructure(QUERY);


jchemsearch.setFilter(FILTER EXPRESSION);








Code:
jchemsearch.setQueryStructure("");


jchemsearch.setFilter(match(QUERY) && FILTER EXPRESSION);






When setReturnsNonHits(true) is also set, these two are equivalent:





Code:
jchemsearch.setReturnsNonHits(true);


jchemsearch.setQueryStructure(QUERY);


jchemsearch.setFilter(FILTER EXPRESSION);






Code:
jchemsearch.setReturnsNonHits(false);


jchemsearch.setQueryStructure("");


jchemsearch.setFilter(   !( match(QUERY) && FILTER EXPRESSION)  );






Where "!" is the Chemical Terms equivalent for NOT.