Class Expr
java.lang.Object
org.openscience.cdk.isomorphism.matchers.Expr
A expression stores a predicate tree for checking properties of atoms
and bonds.
Consider the following expression tree, is matches fluorine, chlorine, or bromine.
Expr expr = new Expr(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(IS_AROMATIC); // matches any aromatic atom new Expr(ELEMENT, 6); // matches any carbon atom (atomic num=6) new Expr(VALENCE, 4); // matches an atom with valence 4 new Expr(DEGREE, 1); // matches a terminal atom, e.g. -OH, =O new Expr(IS_IN_RING); // matches any atom marked as in a ring new Expr(IS_HETERO); // matches anything other than carbon or nitrogen new Expr(TRUE); // any atomLogical internal nodes combine one or two sub-expressions with conjunction (and), disjunction (or), and negation (not).
Consider the following expression tree, is matches fluorine, chlorine, or bromine.
OR
/ \
F OR
/ \
Cl Br
We can construct this tree as follows:
Expr expr = new Expr(ELEMENT, 9) // F
.or(new Expr(ELEMENT, 17)) // Cl
.or(new Expr(ELEMENT, 35)) // Br
A more verbose construction could also be used:
Expr leafF = new Expr(ELEMENT, 9); // F Expr leafCl = new Expr(ELEMENT, 17); // Cl Expr leafBr = new Expr(ELEMENT, 35); // Br Expr node4 = new Expr(OR, leaf2, leaf3); Expr node5 = new Expr(OR, leaf1, node4);Expressions can be used to match bonds. Note some expressions apply to either atoms or bonds.
new Expr(TRUE); // any bond new Expr(IS_IN_RING); // any ring bond new Expr(ALIPHATIC_ORDER, 2); // double bondSee the documentation for
Expr.Types for a detail explanation of
each type.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intSentinel value for indicating the stereochemistry configuration is not yet known. -
Constructor Summary
ConstructorsConstructorDescriptionExpr()Creates an atom expression that will always match (Expr.Type.TRUE).Copy-constructor, creates a shallow copy of the provided expression.Creates an atom expression for the specified primitive.Creates an atom expression for the specified primitive and 'value'.Expr(Expr.Type op, IAtomContainer mol) Creates a recursive atom expression.Creates a logical atom expression for the specified. -
Method Summary
Modifier and TypeMethodDescriptionUtility, combine this expression with another, using conjunction.booleaninthashCode()left()Access the left sub-expression of this atom expression being tested.booleanTest whether this expression matches an atom instance.booleanbooleanbooleannegate()Negate the expression, the expression will not return true only if the condition is not met.Utility, combine this expression with another, using disjunction.right()Access the right sub-expression of this atom expression being tested.voidSet this expression to another (shallow copy).voidsetLogical(Expr.Type type, Expr left, Expr right) Set the logical value of this atom expression.voidsetPrimitive(Expr.Type type) Set the primitive value of this atom expression.voidsetPrimitive(Expr.Type type, int val) Set the primitive value of this atom expression.subquery()Access the sub-query, only applicable to recursive types.toString()type()Access the type of the atom expression.intvalue()Access the value of this atom expression being tested.
-
Field Details
-
UNKNOWN_STEREO
public static final int UNKNOWN_STEREOSentinel value for indicating the stereochemistry configuration is not yet known. Since stereochemistry depends on the ordering of neighbors we can't check this until those neighbors are matched.- See Also:
-
-
Constructor Details
-
Expr
public Expr()Creates an atom expression that will always match (Expr.Type.TRUE). -
Expr
Creates an atom expression for the specified primitive. -
Expr
Creates an atom expression for the specified primitive and 'value'. -
Expr
Creates a logical atom expression for the specified. -
Expr
Creates a recursive atom expression. -
Expr
Copy-constructor, creates a shallow copy of the provided expression.- Parameters:
expr- the expre
-
-
Method Details
-
matches
-
matches
-
matches
Test whether this expression matches an atom instance.- Parameters:
atom- an atom (nullable)- Returns:
- the atom matches
-
matches
-
and
Utility, combine this expression with another, using conjunction. The expression will only match if both conditions are met.- Parameters:
expr- the other expression- Returns:
- self for chaining
-
or
Utility, combine this expression with another, using disjunction. The expression will match if either conditions is met.- Parameters:
expr- the other expression- Returns:
- self for chaining
-
negate
Negate the expression, the expression will not return true only if the condition is not met. Some expressions have explicit types that are more efficient to use, for example: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]- Returns:
- self for chaining
-
setPrimitive
Set the primitive value of this atom expression.- Parameters:
type- the type of expressionval- the value to check
-
setPrimitive
Set the primitive value of this atom expression.- Parameters:
type- the type of expression
-
setLogical
Set the logical value of this atom expression.- Parameters:
type- the type of expressionleft- the left sub-expressionright- the right sub-expression
-
set
Set this expression to another (shallow copy).- Parameters:
expr- the other expression
-
type
Access the type of the atom expression.- Returns:
- the expression type
-
value
public int value()Access the value of this atom expression being tested.- Returns:
- the expression value
-
left
Access the left sub-expression of this atom expression being tested.- Returns:
- the expression value
-
right
Access the right sub-expression of this atom expression being tested.- Returns:
- the expression value
-
subquery
Access the sub-query, only applicable to recursive types.- Returns:
- the sub-query
- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-