Class 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:

     import chemaxon.sss.search.MolSearch;
     import chemaxon.sss.search.SearchException;
     import chemaxon.util.MolHandler;
     import chemaxon.formats.MolInputStream;
     import chemaxon.formats.MolImporter;
     import chemaxon.struc.Molecule;
     
     import java.io.BufferedInputStream;
     import java.io.FileInputStream;
     import java.io.IOException;
     
     public class SearchTest {
     
         public static void main(String[] args) {
             try {
                 MolSearch s = new MolSearch();
     
                 // queryMode = true forces string to be imported as SMARTS
                 // If SMILES import needed, set queryMode = false.
                 MolHandler mh1 = new MolHandler("c1ccccc1Cl", true);
     
                 // The query molecule must be aromatized if it uses the
                 // alternating single/double bonds for the description of
                 // aromaticity.
                 mh1.aromatize();
                 s.setQuery(mh1.getMolecule());
     
                 // use Molfile molecule as target
                 BufferedInputStream tis = null;
                 tis = new BufferedInputStream(new FileInputStream("target.mol"));
                 MolInputStream tmis = new MolInputStream(tis);
                 MolImporter tmolimp = new MolImporter(tmis);
                 Molecule target = tmolimp.read();
     
                 target.aromatize(true);
                 s.setTarget(target);
     
                 // search all matching substructures and print hits
                 int[][] hits = null;
     
                 hits = s.findAll();
                 if (hits == null)
                     System.out.println("No hits");
                 else {
                     for (int i = 0; i < hits.length; i++) {
                         System.out.print("Hit " + (i + 1) + ":  ");
                         int[] hit = hits[i];
                         for (int j = 0; j < hit.length; j++) {
                             System.out.print(hit[j] + " ");
                         }
                         System.out.println();
                     }
                 }// end else
             } catch (IOException e) {
                 e.printStackTrace();
                 System.exit(1);
             } catch (SearchException e) {
                 e.printStackTrace();
                 System.exit(1);
             }// end catch
         }// end main
     }// end searchTest
     
    • Field Detail

      • 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 Detail

      • MolSearch

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

      • 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:
        Search.getSearchOptions()
      • 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
      • getSearcher

        protected final chemaxon.sss.matcher.StructureMatcher getSearcher()
      • 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