Class MaxCommonSubstructure
- All Implemented Interfaces:
- chemaxon.license.Licensable
- Direct Known Subclasses:
- BuildupMcs,- MaxCliqueMcs
 An instance of the default MCS algorithm implementation can be created using newInstance() or
 newInstance(McsSearchOptions). The provided MCS algorithms are powerful heuristic methods, which typically
 find large common substructures in a short time. However, they do not always provide the exact optimal result due to
 the complexity of the MCS problem (especially for large molecules). Furthermore, as the algorithms perform
 randomized search, different results might be obtained for equivalent molecule representations.
 
 Warning: MCS algorithms do not perform transformations on the input molecules, so you should be aware of
 aromatization (and other standardization actions) before using them.
 
Features: Query and target structures basically play the same role in MCS search except for query features: a query molecule may contain generic query atoms (A, Q, M, X, list atom, not list atom, etc.) and query bonds (any, single or double, etc.), but query properties (e.g., valence, hydrogen count) are ignored. If exact query atom/bond matching is set to true, then generic atoms and bonds are allowed in both molecules, but they are matched in exact manner. Reactions are also supported, but Markush structures are not.
Typical usage:
 MaxCommonSubstructure mcs = MaxCommonSubstructure.newInstance();
 mcs.setMolecules(queryMol, targetMol);
 McsSearchResult result = mcs.find();
 System.out.println("Atoms in MCS: " + result.getAtomCount());
 System.out.println("Bonds in MCS: " + result.getBondCount());
 System.out.println("MCS molecule: " + MolExporter.exportToFormat(result.getAsMolecule(), "smiles"));
 - 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final longDefault random seed.protected static final System.LoggerLogger object.protected com.chemaxon.search.vf2.Vf2MatcherThe matcher object containing the preprocessed query and target molecules.protected MoleculeQuery molecule (it is neither cloned nor modified).protected longRandom seed (0 means using the current time).protected SearchModeSearch mode.protected final McsSearchOptionsSearch options.protected MoleculeTarget molecule (it is neither cloned nor modified).protected longTime limit in milliseconds (-1 means disabled).
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionfinal floatCalculates an upper bound on the similarity of the query and target molecules with respect to the specified search options.final intCalculates an upper bound on the number of bonds the maximum common substructure may contain with respect to the specified search options.final McsSearchResultfind()Performs MCS search according to the specified options.protected abstract McsSearchResultfindMcs()Finds the MCS and all related data (fragments and mappings).final MoleculegetQuery()Gets the query structure.final longGets the random seed value.final SearchModeGets the current search mode.final McsSearchOptionsReturns the search options used by this instance.final MoleculeGets the target structure.final longGets the maximum allowed MCS search time in milliseconds.final booleanReturns whether there are more results available.final booleanReturns information about the licensing of the product.static MaxCommonSubstructureCreates a new instance of MCS search algorithm using the default search options.static MaxCommonSubstructurenewInstance(McsSearchOptions searchOpts) Creates a new instance of MCS search algorithm using the given search options.final McsSearchResultFinds the next MCS search result according to the specified options.final voidSets the license environment.final voidsetMolecules(Molecule query, Molecule target) Sets the two molecular structures to be matched.final voidSets the query structure.final voidsetRandomSeed(long seed) Sets the random seed value.final voidsetSearchMode(SearchMode mode) Sets the search mode that controls the running time and the accuracy of the algorithm.final voidSets the target structure.final voidsetTimeLimit(long maxMilliseconds) Sets the maximum allowed time for MCS search.
- 
Field Details- 
DEFAULT_RANDOM_SEEDpublic static final long DEFAULT_RANDOM_SEEDDefault random seed.- See Also:
 
- 
randomSeedprotected long randomSeedRandom seed (0 means using the current time).
- 
searchModeSearch mode.
- 
timeLimitprotected long timeLimitTime limit in milliseconds (-1 means disabled).
- 
queryMolQuery molecule (it is neither cloned nor modified).
- 
targetMolTarget molecule (it is neither cloned nor modified).
- 
searchOptsSearch options.
- 
LOGLogger object.
- 
matcherprotected com.chemaxon.search.vf2.Vf2Matcher matcherThe matcher object containing the preprocessed query and target molecules.
 
- 
- 
Constructor Details- 
MaxCommonSubstructure
 
- 
- 
Method Details- 
newInstanceCreates a new instance of MCS search algorithm using the default search options.MaxCliqueMcsimplementation is used, which turned out to be the most efficient and robust according to our benchmark tests.- Returns:
- a new instance of the default algorithm implementation
- See Also:
 
- 
newInstanceCreates a new instance of MCS search algorithm using the given search options.MaxCliqueMcsimplementation is used, which turned out to be the most efficient and robust according to our benchmark tests.- Parameters:
- searchOpts- the search options (not null)
- Returns:
- a new instance of the default algorithm implementation
 
- 
isLicensedpublic final boolean isLicensed()Returns information about the licensing of the product.- Specified by:
- isLicensedin interface- chemaxon.license.Licensable
- Returns:
- true if the product is correctly licensed
 
- 
setLicenseEnvironmentSets the license environment.- Specified by:
- setLicenseEnvironmentin interface- chemaxon.license.Licensable
 
- 
setMoleculesSets the two molecular structures to be matched.- Parameters:
- query- query molecule (not null)
- target- target molecule (not null)
 
- 
setQuerySets the query structure.- Parameters:
- query- query molecule (not null)
 
- 
setTargetSets the target structure.- Parameters:
- target- target molecule (not null)
 
- 
getQueryGets the query structure.- Returns:
- the query molecule
 
- 
getTargetGets the target structure.- Returns:
- the target molecule
 
- 
getSearchOptionsReturns the search options used by this instance. For more information, seeMcsSearchOptions.- Returns:
- search options (not null)
 
- 
setSearchModeSets the search mode that controls the running time and the accuracy of the algorithm. The default option isSearchMode.NORMAL. For more information, seeSearchMode.- Parameters:
- mode- search mode (not null)
 
- 
getSearchModeGets the current search mode. For more information, seeSearchMode.- Returns:
- current search mode (not null)
 
- 
setTimeLimitpublic final void setTimeLimit(long maxMilliseconds) Sets the maximum allowed time for MCS search. If the given limit is exceeded, the search process terminates with the best result obtained so far. When searching for multiple results (without changing the input molecules), the time limit is applied only to the first call ofnextResult()(orhasNextResult()).This is an optional limit, which is set to 1 minute by default. You can use a negative parameter value to disable it. If the search process seems to be too slow, consider using FASTsearch mode instead of decreasing the time limit (seesetSearchMode(SearchMode)).- Parameters:
- maxMilliseconds- maximum running time in milliseconds (negative value means disabled)
 
- 
getTimeLimitpublic final long getTimeLimit()Gets the maximum allowed MCS search time in milliseconds. If no such limit is specified, this method returns -1. For more information, seesetTimeLimit().- Returns:
- maximum running time in milliseconds or -1 if no such limit is specified
 
- 
setRandomSeedpublic final void setRandomSeed(long seed) Sets the random seed value. 0 means using the current time.- Parameters:
- seed- random seed
 
- 
getRandomSeedpublic final long getRandomSeed()Gets the random seed value. 0 means using the current time.- Returns:
- seed random seed
 
- 
findPerforms MCS search according to the specified options. This method returns a valid result object even if the MCS is empty or the search time limit is reached.If multiple MCS results are desired, use hasNextResult()andnextResult().- Returns:
- the McsSearchResultobject containing the found common substructure
- Throws:
- IllegalStateException- if the input molecules are not set before calling this method or the method is called more than once for the same input molecules
- CancellationException- if the thread has been interrupted
 
- 
hasNextResultpublic final boolean hasNextResult()Returns whether there are more results available. SeenextResult().- Returns:
- true if nextResult()can be called to obtain a newMcsSearchResultobject
- Throws:
- IllegalStateException- if the input molecules are not set before calling this method
- CancellationException- if the thread has been interrupted
 
- 
nextResultFinds the next MCS search result according to the specified options. The first call to this method always returns a valid result object, even if the MCS is empty or the search time limit is reached.If multiple search results are desired, this method can be called repeatedly. The results typically correspond to equivalent common substructures but with different mappings. (See McsSearchResultfor more information.) When this method is called multiple times,hasNextResult()should be called first to avoid exception.The search state is reset after a call to setQuery(Molecule),setTarget(Molecule)orsetMolecules(Molecule, Molecule).- Returns:
- the McsSearchResultobject containing the found common substructure
- Throws:
- IllegalStateException- if the input molecules are not set before the first call to this method or there are no more results to return
- CancellationException- if the thread has been interrupted
 
- 
calculateUpperBoundpublic final int calculateUpperBound()Calculates an upper bound on the number of bonds the maximum common substructure may contain with respect to the specified search options. The returned value is an upper bound onMcsSearchResult.getBondCount().As this method is much faster than executing the MCS algorithm ( find()), it can be used for pre-filtering.- Returns:
- an upper bound on the size (bond count) of the MCS
- Throws:
- IllegalStateException- if the input molecules are not set
- CancellationException- if the thread has been interrupted
 
- 
calculateSimilarityUpperBoundpublic final float calculateSimilarityUpperBound()Calculates an upper bound on the similarity of the query and target molecules with respect to the specified search options. The returned value is an upper bound onMcsSearchResult.getSimilarity().As this method is much faster than executing the MCS algorithm ( find()), it can be used for pre-filtering.- Returns:
- an upper bound on the (MCS based) similarity of the query and the target
- Throws:
- IllegalStateException- if the input molecules are not set
- CancellationException- if the thread has been interrupted
 
- 
findMcsFinds the MCS and all related data (fragments and mappings). Deriving classes must implement this method to calculate an (approximate) maximum common substructure after internal data structures are properly initialized.For internal use only. 
 
-