Class SMARTSParser
- java.lang.Object
-
- org.openscience.cdk.smiles.smarts.parser.SMARTSParser
-
- All Implemented Interfaces:
SMARTSParserConstants
,SMARTSParserTreeConstants
public class SMARTSParser extends Object implements SMARTSParserTreeConstants, SMARTSParserConstants
This parser implements a nearly complete subset of the SMARTS syntax as defined on the Daylight website.Example code using SMARTS substructure search looks like:
SmilesParser sp = new SmilesParser(); AtomContainer atomContainer = sp.parseSmiles("CC(=O)OC(=O)C"); QueryAtomContainer query = SMARTSParser.parse("C*C"); boolean queryMatch = UniversalIsomorphismTester.isSubgraph(atomContainer, query);
See the cdk.test.smiles.smarts.parser.ParserTest for examples of the implemented subset. This parser is based on JJTree and it generates an AST (Abstract Syntax Tree)
To get the AST, the code looks like:
SMARTSParser parser = new SMARTSParser(new java.io.StringReader("C*C")); ASTStart = parser.start();
- Author:
- Dazhi Jiao
- See Also:
SMARTSAtom
- Belongs to CDK module:
- smarts
- Keywords:
- SMARTS, substructure search
- Created on:
- 2007-04-23
- Requires:
- ant1.6
-
-
Field Summary
Fields Modifier and Type Field Description Token
jj_nt
Next token.protected JJTSMARTSParserState
jjtree
Token
token
Current token.SMARTSParserTokenManager
token_source
Generated Token Manager.-
Fields inherited from interface org.openscience.cdk.smiles.smarts.parser.SMARTSParserConstants
a, A, AC, AG, AL, AM, ANY_BOND, AR, AR_BOND, as, AS, AT, ATOM_EXPRESSION, AU, B, BA, BE, BI, BK, BR, c, C, CA, CARET, CD, CE, CF, CL, CM, CO, CR, CS, CU, D, D_BOND, DEFAULT, DIGIT, DN_OR_UNSPECIFIED_S_BOND, DN_S_BOND, DOLLAR, DY, EOF, ER, ES, EU, F, FE, FM, FR, G, GA, GD, GE, h, H, H_AND, HE, HF, HG, HO, HX, I, IN, IR, K, KR, L_AND, L_BRACKET, L_PAREN, LA, LI, LR, LU, MD, MG, MN, MO, n, N, NA, NB, ND, NE, NI, NO, NOT, NP, o, O, OR, OS, p, P, PA, PB, PD, PLUS, PM, PO, PR, PT, PU, Q_MARK, r, R, R_BOND, R_BRACKET, R_PAREN, RA, RB, RE, RH, RN, RU, s, S, S_BOND, SB, SC, se, SE, SI, SM, SN, SR, T_BOND, TA, TB, TC, TE, TH, TI, TL, TM, tokenImage, U, UP_OR_UNSPECIFIED_S_BOND, UP_S_BOND, v, V, W, WILDCARD, WS, x, X, XE, Y, YB, ZN, ZR
-
Fields inherited from interface org.openscience.cdk.smiles.smarts.parser.SMARTSParserTreeConstants
JJTALIPHATIC, JJTANYATOM, JJTAROMATIC, JJTATOM, JJTATOMICMASS, JJTATOMICNUMBER, JJTCHARGE, JJTCHIRALITY, JJTELEMENT, JJTEXPLICITATOM, JJTEXPLICITCONNECTIVITY, JJTEXPLICITHIGHANDBOND, JJTEXPLICITHIGHANDEXPRESSION, JJTGROUP, JJTHYBRDIZATIONNUMBER, JJTIMPLICITHCOUNT, JJTIMPLICITHIGHANDBOND, JJTIMPLICITHIGHANDEXPRESSION, JJTLOWANDBOND, JJTLOWANDEXPRESSION, jjtNodeName, JJTNONCHHEAVYATOM, JJTNOTBOND, JJTNOTEXPRESSION, JJTORBOND, JJTOREXPRESSION, JJTPERIODICGROUPNUMBER, JJTREACTION, JJTRECURSIVESMARTSEXPRESSION, JJTRINGCONNECTIVITY, JJTRINGIDENTIFIER, JJTRINGMEMBERSHIP, JJTSIMPLEBOND, JJTSMALLESTRINGSIZE, JJTSMARTS, JJTSTART, JJTTOTALCONNECTIVITY, JJTTOTALHCOUNT, JJTVALENCE, JJTVOID
-
-
Constructor Summary
Constructors Constructor Description SMARTSParser(InputStream stream)
Constructor with InputStream.SMARTSParser(InputStream stream, String encoding)
Constructor with InputStream and supplied encodingSMARTSParser(Reader stream)
Constructor.SMARTSParser(SMARTSParserTokenManager tm)
Constructor with generated Token Manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
Aliphatic()
void
AnyAtom()
void
Aromatic()
org.openscience.cdk.smiles.smarts.parser.ASTAtom
AtomExpression()
void
AtomicMass()
void
AtomicNumber()
void
Charge()
void
Chirality()
void
disable_tracing()
Disable tracing.void
enable_tracing()
Enable tracing.void
ExplicitAtomExpression()
void
ExplicitConnectivity()
void
ExplicitHighAndBond()
void
ExplicitHighAndExpression()
ParseException
generateParseException()
Generate ParseException.Token
getNextToken()
Get the next Token.Token
getToken(int index)
Get the specific Token.void
GroupExpression()
void
HybridizationNumber()
void
ImplicitHCount()
void
ImplicitHighAndBond()
void
ImplicitHighAndExpression()
void
LowAndBond()
void
LowAndExpression()
void
NoHydrogenElement()
void
NonCHHeavyAtom()
void
NotBond()
void
NotExpression()
void
OrBond()
void
OrExpression()
static QueryAtomContainer
parse(String smarts, IChemObjectBuilder builder)
This method parses a Smarts String and returns an instance ofQueryAtomContainer
void
PeriodicGroupNumber()
void
PrimitiveAtomExpression()
void
ReactionExpression()
void
RecursiveSmartsExpression()
void
ReInit(InputStream stream)
Reinitialise.void
ReInit(InputStream stream, String encoding)
Reinitialise.void
ReInit(Reader stream)
Reinitialise.void
ReInit(SMARTSParserTokenManager tm)
Reinitialise.void
RingConnectivity()
void
RingIdentifier()
void
RingMembership()
void
SimpleBond()
void
SmallestRingSize()
void
SmartsExpression()
org.openscience.cdk.smiles.smarts.parser.ASTStart
Start()
Start ::= <ReactionExpression> <#_WS> ReactionExpression ::= <GroupExpression>? (">" <GroupExpression>? ">" <GroupExpression>?)? GroupExpression ::= ["("] <SmartsExpresion> [")"] ( "." ["("] <SmartsExpression> [")"] )* SmartsExpression ::= <AtomExpression> ( ( [ <LowAndBond> ] ( <Digit> | <AtomExpression> ) ) | ( "(" [ <LowAndBond> ] <SmartsExpression> ")" ) )* AtomExpression ::= ( "[" [ <AtomicMass> ] <LowAndExpression> [:<Digit>+] "]" ) | <ExplicitAtomExpression> LowAndBond ::= <OrBond> [ ";" <AndBond> ] OrBond ::= <ExplicitHighAndBond> [ "," <OrBond> ] ExplicitHighAndBond ::= <ImplicitHighAndBond> [ "&" <ExplicitHighAndBond> ] ImplicitHighAndBond ::= <NotBond> [ <ImplicitHighAndBond> ] NotBond ::= [ "!" ] <SimpleBond> SimpleBond ::= "/" | "\\" | "/?" | "\\?" | "=" | "#" | "~" | "@" ExplicitAtomExpression ::= [ "B" | "C" | "N" | "O" | "P" | "S" | "F" | "CL" | "BR" | "I" | "c" | "o" | "n" | "*" | "A" | "a" | "p" | "as" | "se" ] LowAndExpression ::= <OrExpression> ( ";" <LowAndExpression> )? OrExpression ::= <ExplicitHighAndExpression> ( "," <OrExpression> ) ? ExplicitHighAndExpression ::= <ImplicitHighAndExpression> ( "&" <ExplicitHighAndExpression> )? ImplicitHighAndExpression ::= <NotExpression> ( <ImplicitHighAndExpression> ) ? NotExpression ::= "!" ( <PrimitiveAtomExpression> | <RecursiveSmartsExpression> ) RecursiveSmartsExpression ::= "$" "(" <SmartsExpression> ")" PrimitiveAtomExpression ::= <AtomicMass> | <NonHydrogenElement> | "*" | "A" | "a" | "D" (<Digits>)? | "H" (<Digits>)? | "h" (<Digits>)? | "R" (<Digit>+)? | "r" (<Digit>+)? | "v" (<Digit>+)? | "#X" | "G" (<DIGIT>+) | "X" (<Digit>+)? | "x" (<Digit>+)? | "^" (<DIGIT>) | ("+" | "-") (<Digit>+)? | "#" (<Digit>+) | "@" | "@@" | <Digit>+ Digit ::= ( "0" - "9") NonHydrogenElement ::= [ "HE" | "LI" | "BE" | "NE" | "NA" | "MG" | "AL" | "SI" | "AR" | "CA" | "SC" | "TI" | "CR" | "MN" | "FE" | "CO" | "NI" | "CU" | "ZN" | "GA" | "GE" | "AS" | "SE" | "BR" | "KR" | "RB" | "SR" | "ZR" | "NB" | "MO" | "TC" | "RU" | "RH" | "PD" | "AG" | "CD" | "IN" | "SN" | "SB" | "TE" | "XE" | "CS" | "BA" | "LA" | "HF" | "TA" | "RE" | "OS" | "IR" | "PT" | "AU" | "HG" | "TL" | "PB" | "BI" | "PO" | "AT" | "RN" | "FR" | "RA" | "AC" | "TH" | "PA" | "B" | "C" | "N" | "O" | "F" | "P" | "S" | "K" | "V" | "Y" | "I" | "U" | "c" | "o" | "n" | "p" | "as" | "se" ]
void
TotalConnectivity()
void
TotalHCount()
boolean
trace_enabled()
Trace enabled.void
Valence()
-
-
-
Field Detail
-
jjtree
protected JJTSMARTSParserState jjtree
-
token_source
public SMARTSParserTokenManager token_source
Generated Token Manager.
-
token
public Token token
Current token.
-
jj_nt
public Token jj_nt
Next token.
-
-
Constructor Detail
-
SMARTSParser
public SMARTSParser(InputStream stream)
Constructor with InputStream.
-
SMARTSParser
public SMARTSParser(InputStream stream, String encoding)
Constructor with InputStream and supplied encoding
-
SMARTSParser
public SMARTSParser(Reader stream)
Constructor.
-
SMARTSParser
public SMARTSParser(SMARTSParserTokenManager tm)
Constructor with generated Token Manager.
-
-
Method Detail
-
parse
public static QueryAtomContainer parse(String smarts, IChemObjectBuilder builder)
This method parses a Smarts String and returns an instance ofQueryAtomContainer
-
Start
public final org.openscience.cdk.smiles.smarts.parser.ASTStart Start() throws ParseException
Start ::= <ReactionExpression> <#_WS> ReactionExpression ::= <GroupExpression>? (">" <GroupExpression>? ">" <GroupExpression>?)? GroupExpression ::= ["("] <SmartsExpresion> [")"] ( "." ["("] <SmartsExpression> [")"] )* SmartsExpression ::= <AtomExpression> ( ( [ <LowAndBond> ] ( <Digit> | <AtomExpression> ) ) | ( "(" [ <LowAndBond> ] <SmartsExpression> ")" ) )* AtomExpression ::= ( "[" [ <AtomicMass> ] <LowAndExpression> [:<Digit>+] "]" ) | <ExplicitAtomExpression> LowAndBond ::= <OrBond> [ ";" <AndBond> ] OrBond ::= <ExplicitHighAndBond> [ "," <OrBond> ] ExplicitHighAndBond ::= <ImplicitHighAndBond> [ "&" <ExplicitHighAndBond> ] ImplicitHighAndBond ::= <NotBond> [ <ImplicitHighAndBond> ] NotBond ::= [ "!" ] <SimpleBond> SimpleBond ::= "/" | "\\" | "/?" | "\\?" | "=" | "#" | "~" | "@" ExplicitAtomExpression ::= [ "B" | "C" | "N" | "O" | "P" | "S" | "F" | "CL" | "BR" | "I" | "c" | "o" | "n" | "*" | "A" | "a" | "p" | "as" | "se" ] LowAndExpression ::= <OrExpression> ( ";" <LowAndExpression> )? OrExpression ::= <ExplicitHighAndExpression> ( "," <OrExpression> ) ? ExplicitHighAndExpression ::= <ImplicitHighAndExpression> ( "&" <ExplicitHighAndExpression> )? ImplicitHighAndExpression ::= <NotExpression> ( <ImplicitHighAndExpression> ) ? NotExpression ::= "!" ( <PrimitiveAtomExpression> | <RecursiveSmartsExpression> ) RecursiveSmartsExpression ::= "$" "(" <SmartsExpression> ")" PrimitiveAtomExpression ::= <AtomicMass> | <NonHydrogenElement> | "*" | "A" | "a" | "D" (<Digits>)? | "H" (<Digits>)? | "h" (<Digits>)? | "R" (<Digit>+)? | "r" (<Digit>+)? | "v" (<Digit>+)? | "#X" | "G" (<DIGIT>+) | "X" (<Digit>+)? | "x" (<Digit>+)? | "^" (<DIGIT>) | ("+" | "-") (<Digit>+)? | "#" (<Digit>+) | "@" | "@@" | <Digit>+ Digit ::= ( "0" - "9") NonHydrogenElement ::= [ "HE" | "LI" | "BE" | "NE" | "NA" | "MG" | "AL" | "SI" | "AR" | "CA" | "SC" | "TI" | "CR" | "MN" | "FE" | "CO" | "NI" | "CU" | "ZN" | "GA" | "GE" | "AS" | "SE" | "BR" | "KR" | "RB" | "SR" | "ZR" | "NB" | "MO" | "TC" | "RU" | "RH" | "PD" | "AG" | "CD" | "IN" | "SN" | "SB" | "TE" | "XE" | "CS" | "BA" | "LA" | "HF" | "TA" | "RE" | "OS" | "IR" | "PT" | "AU" | "HG" | "TL" | "PB" | "BI" | "PO" | "AT" | "RN" | "FR" | "RA" | "AC" | "TH" | "PA" | "B" | "C" | "N" | "O" | "F" | "P" | "S" | "K" | "V" | "Y" | "I" | "U" | "c" | "o" | "n" | "p" | "as" | "se" ]
- Throws:
ParseException
-
ReactionExpression
public final void ReactionExpression() throws ParseException
- Throws:
ParseException
-
GroupExpression
public final void GroupExpression() throws ParseException
- Throws:
ParseException
-
SmartsExpression
public final void SmartsExpression() throws ParseException
- Throws:
ParseException
-
AtomExpression
public final org.openscience.cdk.smiles.smarts.parser.ASTAtom AtomExpression() throws ParseException
- Throws:
ParseException
-
LowAndBond
public final void LowAndBond() throws ParseException
- Throws:
ParseException
-
OrBond
public final void OrBond() throws ParseException
- Throws:
ParseException
-
ExplicitHighAndBond
public final void ExplicitHighAndBond() throws ParseException
- Throws:
ParseException
-
ImplicitHighAndBond
public final void ImplicitHighAndBond() throws ParseException
- Throws:
ParseException
-
NotBond
public final void NotBond() throws ParseException
- Throws:
ParseException
-
SimpleBond
public final void SimpleBond() throws ParseException
- Throws:
ParseException
-
ExplicitAtomExpression
public final void ExplicitAtomExpression() throws ParseException
- Throws:
ParseException
-
LowAndExpression
public final void LowAndExpression() throws ParseException
- Throws:
ParseException
-
OrExpression
public final void OrExpression() throws ParseException
- Throws:
ParseException
-
ExplicitHighAndExpression
public final void ExplicitHighAndExpression() throws ParseException
- Throws:
ParseException
-
ImplicitHighAndExpression
public final void ImplicitHighAndExpression() throws ParseException
- Throws:
ParseException
-
NotExpression
public final void NotExpression() throws ParseException
- Throws:
ParseException
-
RecursiveSmartsExpression
public final void RecursiveSmartsExpression() throws ParseException
- Throws:
ParseException
-
PrimitiveAtomExpression
public final void PrimitiveAtomExpression() throws ParseException
- Throws:
ParseException
-
TotalHCount
public final void TotalHCount() throws ParseException
- Throws:
ParseException
-
ImplicitHCount
public final void ImplicitHCount() throws ParseException
- Throws:
ParseException
-
ExplicitConnectivity
public final void ExplicitConnectivity() throws ParseException
- Throws:
ParseException
-
AtomicNumber
public final void AtomicNumber() throws ParseException
- Throws:
ParseException
-
HybridizationNumber
public final void HybridizationNumber() throws ParseException
- Throws:
ParseException
-
Charge
public final void Charge() throws ParseException
- Throws:
ParseException
-
RingConnectivity
public final void RingConnectivity() throws ParseException
- Throws:
ParseException
-
PeriodicGroupNumber
public final void PeriodicGroupNumber() throws ParseException, ParseException
- Throws:
ParseException
-
TotalConnectivity
public final void TotalConnectivity() throws ParseException
- Throws:
ParseException
-
Valence
public final void Valence() throws ParseException
- Throws:
ParseException
-
RingMembership
public final void RingMembership() throws ParseException
- Throws:
ParseException
-
SmallestRingSize
public final void SmallestRingSize() throws ParseException
- Throws:
ParseException
-
Aliphatic
public final void Aliphatic() throws ParseException
- Throws:
ParseException
-
NonCHHeavyAtom
public final void NonCHHeavyAtom() throws ParseException
- Throws:
ParseException
-
Aromatic
public final void Aromatic() throws ParseException
- Throws:
ParseException
-
AnyAtom
public final void AnyAtom() throws ParseException
- Throws:
ParseException
-
AtomicMass
public final void AtomicMass() throws ParseException
- Throws:
ParseException
-
RingIdentifier
public final void RingIdentifier() throws ParseException
- Throws:
ParseException
-
Chirality
public final void Chirality() throws ParseException
- Throws:
ParseException
-
NoHydrogenElement
public final void NoHydrogenElement() throws ParseException
- Throws:
ParseException
-
ReInit
public void ReInit(InputStream stream)
Reinitialise.
-
ReInit
public void ReInit(InputStream stream, String encoding)
Reinitialise.
-
ReInit
public void ReInit(Reader stream)
Reinitialise.
-
ReInit
public void ReInit(SMARTSParserTokenManager tm)
Reinitialise.
-
getNextToken
public final Token getNextToken()
Get the next Token.
-
getToken
public final Token getToken(int index)
Get the specific Token.
-
generateParseException
public ParseException generateParseException()
Generate ParseException.
-
trace_enabled
public final boolean trace_enabled()
Trace enabled.
-
enable_tracing
public final void enable_tracing()
Enable tracing.
-
disable_tracing
public final void disable_tracing()
Disable tracing.
-
-