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.[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,
IChemObjectBuilder builder)
Create a new SMARTS query tool for the specified SMARTS string.
|
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 |
setAromaticity(Aromaticity aromaticity)
Set the aromaticity perception to use.
|
void |
setQueryCacheSize(int maxEntries)
Set the maximum size of the query cache.
|
void |
setSmarts(String smarts)
Set a new SMARTS pattern.
|
void |
useEssentialRings()
Indicates that ring properties should use the Essential Rings (default).
|
void |
useRelevantRings()
Indicates that ring properties should use the Relevant Rings.
|
void |
useSmallestSetOfSmallestRings()
Indicates that ring properties should use the Smallest Set of Smallest
Rings.
|
public SMARTSQueryTool(String smarts, IChemObjectBuilder builder)
IChemObjectBuilder
.smarts
- SMARTS query stringIllegalArgumentException
- if the SMARTS string can not be handledpublic void setQueryCacheSize(int maxEntries)
maxEntries
- The maximum number of entriespublic void useSmallestSetOfSmallestRings()
useEssentialRings()
,
useRelevantRings()
public void useRelevantRings()
public void useEssentialRings()
public void setAromaticity(Aromaticity aromaticity)
SMARTSQueryTool sqt = new SMARTSQueryTool(...); sqt.setAromaticity(new Aromaticity(ElectronDonation.cdk(), Cycles.cdkAromaticSet)); for (IAtomContainer molecule : molecules) { // CDK Aromatic model needs atom types AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); sqt.matches(molecule); }
aromaticity
- the new aromaticity perceptionElectronDonation
,
Cycles
public String getSmarts()
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)
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)
public int countMatches()
matches(org.openscience.cdk.interfaces.IAtomContainer)
. If not, the results may be undefined.public List<List<Integer>> getMatchingAtoms()
public List<List<Integer>> getUniqueMatchingAtoms()
Copyright © 2017. All Rights Reserved.