Class MolSearch

java.lang.Object
chemaxon.sss.search.Search
chemaxon.sss.search.MolSearch
All Implemented Interfaces:
chemaxon.license.Licensable, SearchConstants, StereoConstants, SimpleSearcher
Direct Known Subclasses:
StandardizedMolSearch

@PublicApi public class MolSearch extends Search implements chemaxon.license.Licensable, SimpleSearcher
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);
 }
 
  • Field Details

    • isOrigTargetMayBeMarkush

      protected boolean isOrigTargetMayBeMarkush
      FS#9166 Should be set to 'false' to indicate that any bonds (Markush components) occurred only after generating generic tautomer of target. Is used only in selectSearchMode()!
  • Constructor Details

    • MolSearch

      public MolSearch()
      Constructs a MolSearch object.
  • Method Details

    • setTarget

      public void setTarget(Molecule mol)
      Description copied from class: Search
      Specifies the target molecule.

      Note: If the molecule is changed, it will need to be reset for the searcher.

      Specified by:
      setTarget in interface SimpleSearcher
      Specified by:
      setTarget in class Search
      Parameters:
      mol - the possibly standardized target molecule. See note on aromatic bonds
    • setTarget

      public void setTarget(Molecule mol, int[] exclude)
      Description copied from class: Search
      Specifies the target molecule with excluded atoms. Excluded atoms are not used during the search procedure. Atoms connected to excluded ones keep their stereo features.

      Note: If the molecule is changed, it will need to be reset for the searcher.

      Specified by:
      setTarget in interface SimpleSearcher
      Specified by:
      setTarget in class Search
      Parameters:
      mol - the standardized target molecule. See note on aromatic bonds
      exclude - index of target atoms to exclude from search
    • getTarget

      public Molecule getTarget()
      Description copied from class: Search
      Retrieves the target molecule.
      Specified by:
      getTarget in class Search
      Returns:
      the target molecule
    • setQuery

      public void setQuery(Molecule mol)
      Description copied from class: Search
      Specifies the query structure to search for. Note: If the molecule is changed, it will need to be reset for the searcher.
      Specified by:
      setQuery in interface SimpleSearcher
      Specified by:
      setQuery in class Search
      Parameters:
      mol - the standardized query structure. See note on aromatic bonds
    • setQuery

      public void setQuery(Molecule mol, int[] exclude)
      Description copied from class: Search
      Specifies the query structure to search for. Excluded atoms are not used during the search procedure. Atoms connected to excluded ones keep their stereo features. Note: If the molecule is changed, it will need to be reset for the searcher.
      Specified by:
      setQuery in interface SimpleSearcher
      Specified by:
      setQuery in class Search
      Parameters:
      mol - the standardized query structure. See note on aromatic bonds
      exclude - index of atoms to exclude from search
    • getQuery

      public Molecule getQuery()
      Description copied from class: Search
      Retrieves the query structure.
      Specified by:
      getQuery in class Search
      Returns:
      the query structure
    • setQuery

      public void setQuery(String queryString)
      Specifies the query structure to search for in String format.
      Parameters:
      queryString - the standardized query structure. See note on aromatic bonds
    • setTransformer

      protected final void setTransformer(Transformer transformer)
      Sets the Transformer to be used for query and target standardization. For internal use only.
      Parameters:
      transformer - the transformer
    • setStandardizer

      public void setStandardizer(Standardizer standardizer)

      Sets the standardizer to be used for query and target molecules and re-standardization of query tautomers in case of tautomer substructure search.

      By default there is no standardization.

      Parameters:
      standardizer - the standardizer, null for no standardization
      Since:
      JChem 5.12
    • setSearchOptions

      public void setSearchOptions(MolSearchOptions options)
      Sets search options. This function makes a copy of the given search options object, thus modification of the original object does not affect future searches unless this method is called again.
      Parameters:
      options - search options. A copy of this object will be stored.
      Since:
      JChem 5.0
      See Also:
    • addComparator

      public void addComparator(MolComparator mc)
      Add a comparator to the search object.
      Parameters:
      mc - comparator to add
      See Also:
    • removeComparator

      public void removeComparator(MolComparator mc)
      Delete a comparator from the search object.
      Parameters:
      mc - comparator to be removed
      See Also:
    • clearComparators

      public void clearComparators()
      Delete all comparator from the search object.
      See Also:
    • isMatching

      public boolean isMatching() throws SearchException
      Description copied from class: Search
      Checks if the query structure matches the target structure with respect to the search options.
      Specified by:
      isMatching in interface SimpleSearcher
      Specified by:
      isMatching in class Search
      Returns:
      true if a match is found.
      Throws:
      SearchException - when an error is encountered.
      See Also:
    • findFirstHit

      public SearchHit findFirstHit() throws SearchException
      Description copied from class: Search
      Looks for the first matching pattern in the target molecule. If the search object was previously used, this method re-initializes the search process, and starts returning the hits from the beginning.

      See SearchHit for more information.

      Specified by:
      findFirstHit in class Search
      Returns:
      the search hit or null if there is not hit
      Throws:
      SearchException - when an error is encountered.
      See Also:
    • findNextHit

      public SearchHit findNextHit() throws SearchException
      Description copied from class: Search
      Searches for the next hit. If the search object was not used previously, it also initializes the search. (So Search.findFirstHit() call is not necessary prior to a Search.findNextHit() call.)

      See SearchHit for more information.

      Specified by:
      findNextHit in interface SimpleSearcher
      Specified by:
      findNextHit in class Search
      Returns:
      the next search hit or null if there is no more hit
      Throws:
      SearchException - when an error is encountered.
      See Also:
    • findAllHits

      public SearchHit[] findAllHits() throws SearchException
      Description copied from class: Search
      Looks for all matching patterns in the molecule.

      See SearchHit for more information.

      Overrides:
      findAllHits in class Search
      Returns:
      the search hits or null if there are no hits.
      Throws:
      SearchException - when an error is encountered.
      See Also:
    • stop

      public void stop()
      Description copied from class: Search
      Tries to stop the running search as fast as possible. (E.g. used in another thread.)
      Specified by:
      stop in class Search
    • setParameters

      protected void setParameters() throws SearchException
      Throws:
      SearchException
    • addMatch

      public void addMatch(int queryAtomIndex, int targetAtomIndex)
      Adds a fixed matching between the given query and target atoms. That is, the query atom can only match the given target atom. If such a hit is not possible, no hits will be returned. The use of this method makes the search more effective than checking the hits afterwards.

      Several addMatch() calls represent conditions connected by boolean operator AND.

      The effect of all addMatch() calls can be canceled by clearMatch().

      Specified by:
      addMatch in interface SimpleSearcher
      Parameters:
      queryAtomIndex - index of the query atom
      targetAtomIndex - index of the target atom
    • addMatch

      public void addMatch(int[] queryAtoms, int[] targetAtoms, int length)
      Description copied from class: Search
      Specifies extra prerequisites of the structure search that queryAtoms[0] must match to targetAtoms[0] only AND queryAtoms[1] must match to targetAtoms[1], etc. If this is impossible, the search methods will report no matching. The use of this method makes the search more effective than checking the hits afterwards.

      Several addMatch() calls represent conditions connected by boolean operator AND.

      The effect of all addMatch() calls can be canceled by clearMatch().

      Overrides:
      addMatch in class Search
      Parameters:
      queryAtoms - the query atom indexes
      targetAtoms - the target atom indexes
      length - the length for which queryAtoms/targetAtoms should be interpreted.
    • clearMatch

      public void clearMatch()
      Description copied from class: Search
      Clears the extra prerequisites of the structure search specified using addMatch calls.
      Overrides:
      clearMatch in class Search
    • checkFilter

      public static void checkFilter(String filteringExpression) throws chemaxon.nfunk.jep.ParseException
      Checks the syntax of the filtering expression. For internal use only.
      Parameters:
      filteringExpression - the expression to be checked
      Throws:
      chemaxon.nfunk.jep.ParseException - if the syntax is not correct
      Since:
      JChem 3.0
    • checkFilter

      public static void checkFilter(String filteringExpression, File config) throws chemaxon.nfunk.jep.ParseException
      Checks the syntax of the filtering expression. For internal use only.
      Parameters:
      filteringExpression - the expression to be checked
      config - the expression evaluator config XML
      Throws:
      chemaxon.nfunk.jep.ParseException - if the syntax is not correct
      Since:
      JChem 3.0
    • setOrigTargetMayBeMarkush

      public void setOrigTargetMayBeMarkush(boolean value)
      Only for internal use!
      Used for indicating that any bonds appeared after generating the generic tautomer of the target.
      Parameters:
      value - if false indicates that any bonds appeared only after tautomer generation.
    • setLicenseEnvironment

      public void setLicenseEnvironment(String env)
      Specified by:
      setLicenseEnvironment in interface chemaxon.license.Licensable
    • isLicensed

      public boolean isLicensed()
      Specified by:
      isLicensed in interface chemaxon.license.Licensable