public final class Expr extends Object
Expr expr = new Expr(ExprType.ELEMENT, 6); if (expr.matches(atom)) { // expression matches if atom is a carbon! }An expression is composed of an
Expr.Type
, an optional 'value', and
optionally one or more 'sub-expressions'. Each expr can either be a leaf or
an intermediate (logical) node. The simplest expression trees contain a
single leaf node:
new Expr(ExprType.IS_AROMATIC; // matches any aromatic atom new Expr(ExprType.ELEMENT, 6); // matches any carbon atom (atomic num=6) new Expr(ExprType.VALENCE, 4); // matches an atom with valence 4 new Expr(ExprType.DEGREE, 1); // matches a terminal atom, e.g. -OH, =O new Expr(ExprType.IS_IN_RING); // matches any atom marked as in a ring new Expr(ExprType.IS_HETERO); // matches anything other than carbon or nitrogen new Expr(ExprType.TRUE); // any atomLogical internal nodes combine one or two sub-expressions with conjunction (and), disjunction (or), and negation (not).
OR / \ F OR / \ Cl BrWe can construct this tree as follows:
Expr expr = new Expr(ExprType.ELEMENT, 35) // Br .or(new Expr(ExprType.ELEMENT, 17)) // Cl .or(new Expr(ExprType.ELEMENT, 9)) // FA more verbose construction could also be used:
Expr leafF = new Expr(ExprType.ELEMENT, 9); // F Expr leafCl = new Expr(ExprType.ELEMENT, 17); // Cl Expr leafBr = new Expr(ExprType.ELEMENT, 35); // Br Expr node4 = new Expr(ExprType.OR, leaf2, leaf3); Expr node5 = new Expr(ExprType.OR, leaf1, node4);Expressions can be used to match bonds. Note some expressions apply to either atoms or bonds.
new Expr(ExprType.TRUE); // any bond new Expr(ExprType.IS_IN_RING); // any ring bond new Expr(ExprType.ALIPHATIC_ORDER, 2); // double bondSee the documentation for
Expr.Type
s for a detail explanation of
each type.Modifier and Type | Class and Description |
---|---|
static class |
Expr.Type
Types of expression, for use in the
Expr tree object. |
Modifier and Type | Field and Description |
---|---|
static int |
UNKNOWN_STEREO
Sentinel value for indicating the stereochemistry configuration
is not yet known.
|
Constructor and Description |
---|
Expr()
Creates an atom expression that will always match (
Expr.Type.TRUE ). |
Expr(Expr.Type op)
Creates an atom expression for the specified primitive.
|
Expr(Expr.Type op,
Expr left,
Expr right)
Creates a logical atom expression for the specified.
|
Expr(Expr.Type op,
IAtomContainer mol)
Creates a recursive atom expression.
|
Expr(Expr.Type op,
int val)
Creates an atom expression for the specified primitive and 'value'.
|
Expr(Expr expr)
Copy-constructor, creates a shallow copy of the provided expression.
|
Modifier and Type | Method and Description |
---|---|
Expr |
and(Expr expr)
Utility, combine this expression with another, using conjunction.
|
boolean |
equals(Object o) |
int |
hashCode() |
Expr |
left()
Access the left sub-expression of this atom expression being
tested.
|
boolean |
matches(IAtom atom)
Test whether this expression matches an atom instance.
|
boolean |
matches(IAtom atom,
int stereo) |
boolean |
matches(IBond bond) |
boolean |
matches(IBond bond,
int stereo) |
Expr |
negate()
Negate the expression, the expression will not return true only if
the condition is not met.
|
Expr |
or(Expr expr)
Utility, combine this expression with another, using disjunction.
|
Expr |
right()
Access the right sub-expression of this atom expression being
tested.
|
void |
set(Expr expr)
Set this expression to another (shallow copy).
|
void |
setLogical(Expr.Type type,
Expr left,
Expr right)
Set the logical value of this atom expression.
|
void |
setPrimitive(Expr.Type type)
Set the primitive value of this atom expression.
|
void |
setPrimitive(Expr.Type type,
int val)
Set the primitive value of this atom expression.
|
IAtomContainer |
subquery()
Access the sub-query, only applicable to recursive types.
|
String |
toString() |
Expr.Type |
type()
Access the type of the atom expression.
|
int |
value()
Access the value of this atom expression being
tested.
|
public static final int UNKNOWN_STEREO
public Expr()
Expr.Type.TRUE
).public Expr(Expr.Type op)
public Expr(Expr.Type op, int val)
public Expr(Expr.Type op, Expr left, Expr right)
public Expr(Expr.Type op, IAtomContainer mol)
public Expr(Expr expr)
expr
- the exprepublic boolean matches(IBond bond, int stereo)
public boolean matches(IBond bond)
public boolean matches(IAtom atom)
atom
- an atom (nullable)public boolean matches(IAtom atom, int stereo)
public Expr and(Expr expr)
expr
- the other expressionpublic Expr or(Expr expr)
expr
- the other expressionpublic Expr negate()
IS_IN_RING => NOT(IS_IN_RING) => IS_IN_CHAIN
. This
negation method will use the more efficient type where possible.
Expr e = new Expr(ELEMENT, 8); // SMARTS: [#8]
e.negate(); // SMARTS: [!#8]
public void setPrimitive(Expr.Type type, int val)
type
- the type of expressionval
- the value to checkpublic void setPrimitive(Expr.Type type)
type
- the type of expressionpublic void setLogical(Expr.Type type, Expr left, Expr right)
type
- the type of expressionleft
- the left sub-expressionright
- the right sub-expressionpublic void set(Expr expr)
expr
- the other expressionpublic Expr.Type type()
public int value()
public Expr left()
public Expr right()
public IAtomContainer subquery()
Expr.Type.RECURSIVE
Copyright © 2018. All Rights Reserved.