@TestClass(value="org.openscience.cdk.smiles.smarts.SMARTSQueryToolTest") public class SMARTSQueryTool extends Object
SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer atomContainer = sp.parseSmiles("CC(=O)OC(=O)C"); SMARTSQueryTool querytool = new SMARTSQueryTool("O=CO"); boolean status = querytool.matches(atomContainer); if (status) { int nmatch = querytool.countMatches(); List mappings = querytool.getMatchingAtoms(); for (int i = 0; i < nmatch; i++) { List atomIndices = (List) mappings.get(i); } }
Symbol | Meaning | Default | Notes |
---|---|---|---|
Gx | Periodic group number | None | x must be specified and must be a number between 1 and 18. This symbol is supported by the MOE SMARTS implementation |
#X | Any non-carbon heavy element | None | This symbol is supported by the MOE SMARTS implementation |
^x | Any atom with the a specified hybridization state | None | x must be specified and should be between 1 and 8 (inclusive), corresponding to SP1, SP2, SP3, SP3D1, SP3D2 SP3D3, SP3D4 and SP3D5. Supported by the OpenEye SMARTS implementation |
h<n>
SMARTS pattern should not be used. It was included in the Daylight spec
for backwards compatibility. To match hydrogens, use the H<n> pattern.
*
) will not match hydrogens (explicit or implicit) unless an isotope is specified. In other
words, *
gives two hits against C[2H]
but 1 hit against C[H]
. This also means
that it gives no hits against [H][H]
. This is contrary to what is shown by Daylights depictmatch service, but is based on this discussion. A
work around to get *
to match [H][H]
is to write it in the form [1H][1H]
.
It's not entirely clear what the behavior of * should be with respect to hydrogens. it is possible that the code will
be updated so that *
will not match any hydrogen in the future.CDKHueckelAromaticityDetector
only considers single rings and two fused non-spiro
rings. As a result, it does not properly detect aromaticity in polycyclic systems such as
[O-]C(=O)c1ccccc1c2c3ccc([O-])cc3oc4cc(=O)ccc24
. Thus SMARTS patterns that depend on proper aromaticity
detection may not work correctly in such polycyclic systemsConstructor and Description |
---|
SMARTSQueryTool(String smarts) |
Modifier and Type | Method and Description |
---|---|
int |
countMatches()
Returns the number of times the pattern was found in the target molecule.
|
List<List<Integer>> |
getMatchingAtoms()
Get the atoms in the target molecule that match the query pattern.
|
String |
getSmarts()
Returns the current SMARTS pattern being used.
|
List<List<Integer>> |
getUniqueMatchingAtoms()
Get the atoms in the target molecule that match the query pattern.
|
boolean |
matches(IAtomContainer atomContainer)
Perform a SMARTS match and check whether the query is present in the target molecule.
|
boolean |
matches(IAtomContainer atomContainer,
boolean forceInitialization)
Perform a SMARTS match and check whether the query is present in the target molecule.
|
void |
setQueryCacheSize(int maxEntries)
Set the maximum size of the query cache.
|
void |
setSmarts(String smarts)
Set a new SMARTS pattern.
|
public SMARTSQueryTool(String smarts) throws CDKException
CDKException
public void setQueryCacheSize(int maxEntries)
maxEntries
- The maximum number of entries@TestMethod(value="testQueryTool") public String getSmarts()
@TestMethod(value="testQueryTool, testQueryToolResetSmart") public void setSmarts(String smarts) throws CDKException
smarts
- The new SMARTS patternCDKException
- if there is an error in parsing the patternpublic boolean matches(IAtomContainer atomContainer) throws CDKException
atomContainer
- The target moleculoeCDKException
- if there is an error in ring, aromaticity or isomorphism perceptiongetMatchingAtoms()
,
countMatches()
,
matches(org.openscience.cdk.interfaces.IAtomContainer, boolean)
@TestMethod(value="testQueryTool, testQueryToolSingleAtomCase, testQuery") public boolean matches(IAtomContainer atomContainer, boolean forceInitialization) throws CDKException
atomContainer
- The target moleculoeforceInitialization
- If true, then the molecule is initialized (ring perception, aromaticity etc). If
false, the molecule is only initialized if it is different (in terms of object
reference) than one supplied in a previous call to this method.CDKException
- if there is an error in ring, aromaticity or isomorphism perceptiongetMatchingAtoms()
,
countMatches()
,
matches(org.openscience.cdk.interfaces.IAtomContainer)
@TestMethod(value="testQueryTool") public int countMatches()
matches(org.openscience.cdk.interfaces.IAtomContainer)
. If not, the results may be undefined.@TestMethod(value="testQueryTool") public List<List<Integer>> getMatchingAtoms()
@TestMethod(value="testUniqueQueries") public List<List<Integer>> getUniqueMatchingAtoms()