public final class Smarts extends Object
IAtomContainer
a SMARTS pattern is parsed and new
IQueryAtom
s and
IQueryBond
s are appended
to the connection table. Each query atom/bond contains an Expr
that
describes the predicate to check when matching. This Expr
is also
used for generating SMARTS.
IAtomContainer mol = ...;
if (Smarts.parse(mol, "[aD3]a-a([aD3])[aD3]")) {
String smarts = Smarts.generate(mol);
}
When parsing SMARTS several flavors are available. The flavors affect how
queries are interpreted. The following flavors are available:
FLAVOR_LOOSE
- allows all unambiguous extensions.FLAVOR_DAYLIGHT
- no extensions, as documented in
Daylight theory manual.FLAVOR_CACTVS
- '[#X]' hetero atom, '[#G8]' periodic group 8,
'[G]' or '[i]' means insaturation. '[Z2]' means 2 aliphatic hetero
neighbors, '[z2]' means 2 aliphatic hetero FLAVOR_MOE
- '[#X]' hetero atom, '[#G8]' periodic group 8,
'[i]' insaturation.FLAVOR_OECHEM
- '[R3]' means ring bond count 3 (e.g. [x3])
instead of in 3 rings (problems with SSSR uniqueness). '[^2]' matches
hybridisation (2=Sp2)FLAVOR_CDK
- Same as FLAVOR_LOOSE
FLAVOR_CDK_LEGACY
- '[D3]' means heavy degree 3 instead of
explicit degree 3. '[^2]' means hybridisation (2=Sp2). '[G8]' periodic
group 8[D{2-4}]
means degree 2, 3, or 4. On writing such
ranges are converted to [D2,D3,D4]
.Modifier and Type | Field and Description |
---|---|
static int |
FLAVOR_CACTVS |
static int |
FLAVOR_CDK |
static int |
FLAVOR_CDK_LEGACY |
static int |
FLAVOR_DAYLIGHT |
static int |
FLAVOR_LOOSE |
static int |
FLAVOR_MOE |
static int |
FLAVOR_OECHEM |
static ThreadLocal<org.openscience.cdk.smarts.Smarts.SmartsError> |
lastError |
Constructor and Description |
---|
Smarts() |
Modifier and Type | Method and Description |
---|---|
static String |
generate(IAtomContainer mol)
Generate a SMARTS string from the provided molecule.
|
static String |
generateAtom(Expr expr)
Utility to generate an atom expression.
|
static String |
generateBond(Expr expr)
Utility to generate a bond expression.
|
static String |
getLastErrorLocation()
Access a display of the error position from previously parsed SMARTS
(when
parse(org.openscience.cdk.interfaces.IAtomContainer, java.lang.String, int) =false) |
static String |
getLastErrorMesg()
Access the error message from previously parsed SMARTS (when
parse(org.openscience.cdk.interfaces.IAtomContainer, java.lang.String, int) =false). |
static boolean |
parse(IAtomContainer mol,
String smarts)
Parse the provided SMARTS string appending query atom/bonds to the
provided molecule.
|
static boolean |
parse(IAtomContainer mol,
String smarts,
int flavor)
Parse the provided SMARTS string appending query atom/bonds to the
provided molecule.
|
public static final int FLAVOR_LOOSE
public static final int FLAVOR_DAYLIGHT
public static final int FLAVOR_CACTVS
public static final int FLAVOR_MOE
public static final int FLAVOR_OECHEM
public static final int FLAVOR_CDK
public static final int FLAVOR_CDK_LEGACY
public static ThreadLocal<org.openscience.cdk.smarts.Smarts.SmartsError> lastError
public static String getLastErrorMesg()
parse(org.openscience.cdk.interfaces.IAtomContainer, java.lang.String, int)
=false).public static String getLastErrorLocation()
parse(org.openscience.cdk.interfaces.IAtomContainer, java.lang.String, int)
=false)public static boolean parse(IAtomContainer mol, String smarts, int flavor)
mol
- the molecule to store the query insmarts
- the SMARTS stringflavor
- the SMARTS flavor (e.g. FLAVOR_LOOSE
.Expr
,
IQueryAtom
,
IQueryBond
public static boolean parse(IAtomContainer mol, String smarts)
FLAVOR_LOOSE
.mol
- the molecule to store the query insmarts
- the SMARTS stringExpr
,
IQueryAtom
,
IQueryBond
public static String generateAtom(Expr expr)
Expr expr = new Expr(Expr.Type.DEGREE, 4).and(
new Expr(Expr.Type.IS_AROMATIC));
String aExpr = Smarts.generateAtom(expr);
// aExpr='[D4a]'
expr
- the expressionExpr
public static String generateBond(Expr expr)
Expr expr = new Expr(Expr.Type.TRUE);
String bExpr = Smarts.generateBond(expr);
// bExpr='~'
expr
- the expressionExpr
public static String generate(IAtomContainer mol)
Expr
s stored on the QueryAtom
and QueryBond
instances.
IAtomContainer mol = ...;
QueryAtom qatom1 = new QueryAtom(mol.getBuilder());
QueryAtom qatom2 = new QueryAtom(mol.getBuilder());
QueryBond qbond = new QueryBond(mol.getBuilder());
qatom1.setExpression(new Expr(Expr.Type.IS_AROMATIC));
qatom2.setExpression(new Expr(Expr.Type.IS_AROMATIC));
qbond.setExpression(new Expr(Expr.Type.IS_ALIPHATIC));
qbond.setAtoms(new IAtom[]{qatom1, qatom2});
mol.addAtom(qatom1);
mol.addAtom(qatom2);
mol.addBond(qbond);
String smartsStr = Smarts.generate(mol);
// smartsStr = 'a!:a'
mol
- the query moleculeExpr
,
IQueryAtom
,
IQueryBond
Copyright © 2021. All rights reserved.