Class MolSearch

All Implemented Interfaces:
Licensable, SearchConstants, StereoConstants
Direct Known Subclasses:
StandardizedMolSearch

@PublicApi public class MolSearch extends AbstractSearch implements Licensable
Atom-by-atom structure search.

Features:

  • Determines whether a target structure contains a query structure.
  • Specifies the matching atoms in the target structure in order of the corresponding query atoms. (When the returning match is larger than the original query atoms, eg. in link node queries, the extra target atom indexes appear at the end.)
  • Generic query atoms (Any, Q), atom properties (A, a, R<n>, H<n> etc.) , atom lists (e.g.: "[C,N,F]"), generic bonds (any bond) are evaluated. For full details of JChem substructure features, see the JChem Query Guide
  • Stereo specific search: chiral and cis/trans stereo isomers are recognized.
  • R-groups: If the query is an RgMolecule with R-groups defined, R-group search is performed. In this case hits of the root atoms are returned. Specifying excluded atoms for setQuery() is not implemented yet for RgMolecules either.
  • Filtering expression: filters search hits by chemical feasibility. For details of the expression syntax, see the Chemical Terms Evaluator Guide.
For correct behaviour of the MolSearch class, both the query and target molecules has to be standardized prior to searching. See note on aromatic bonds. Alternatively, you can use the StandardizedMolSearch class.

Please note that similarity search is not supported in MolSearch.

Example:

 try {
     // The molecules must be aromatized if they use Kekulé representation
     query.aromatize();
     target.aromatize();

     // Init MolSearch
     MolSearch s = new MolSearch();
     s.setQuery(query);
     s.setTarget(target);

     // Search all matching substructures and print hits
     int[][] hits = s.findAll();
     if (hits == null)
         System.out.println("No hits");
     else {
         for (int i = 0; i < hits.length; i++) {
             System.out.println("Hit " + (i + 1) + ":  " + Arrays.toString(hits[i]));
         }
     }
 } catch (SearchException e) {
     throw new RuntimeException(e);
 }