public class SMARTSParser extends Object implements SMARTSParserTreeConstants, SMARTSParserConstants
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();
SMARTSAtom
Modifier and Type | Field and Description |
---|---|
Token |
jj_nt
Next token.
|
protected JJTSMARTSParserState |
jjtree |
Token |
token
Current token.
|
SMARTSParserTokenManager |
token_source
Generated Token Manager.
|
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
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
Constructor and Description |
---|
SMARTSParser(InputStream stream)
Constructor with InputStream.
|
SMARTSParser(InputStream stream,
String encoding)
Constructor with InputStream and supplied encoding
|
SMARTSParser(Reader stream)
Constructor.
|
SMARTSParser(SMARTSParserTokenManager tm)
Constructor with generated Token Manager.
|
Modifier and Type | Method and 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 of
QueryAtomContainer |
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 ::= <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() |
void |
Valence() |
protected JJTSMARTSParserState jjtree
public SMARTSParserTokenManager token_source
public Token token
public Token jj_nt
public SMARTSParser(InputStream stream)
public SMARTSParser(InputStream stream, String encoding)
public SMARTSParser(Reader stream)
public SMARTSParser(SMARTSParserTokenManager tm)
public static QueryAtomContainer parse(String smarts, IChemObjectBuilder builder)
QueryAtomContainer
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 ::= <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" ]
ParseException
public final void ReactionExpression() throws ParseException
ParseException
public final void GroupExpression() throws ParseException
ParseException
public final void SmartsExpression() throws ParseException
ParseException
public final org.openscience.cdk.smiles.smarts.parser.ASTAtom AtomExpression() throws ParseException
ParseException
public final void LowAndBond() throws ParseException
ParseException
public final void OrBond() throws ParseException
ParseException
public final void ExplicitHighAndBond() throws ParseException
ParseException
public final void ImplicitHighAndBond() throws ParseException
ParseException
public final void NotBond() throws ParseException
ParseException
public final void SimpleBond() throws ParseException
ParseException
public final void ExplicitAtomExpression() throws ParseException
ParseException
public final void LowAndExpression() throws ParseException
ParseException
public final void OrExpression() throws ParseException
ParseException
public final void ExplicitHighAndExpression() throws ParseException
ParseException
public final void ImplicitHighAndExpression() throws ParseException
ParseException
public final void NotExpression() throws ParseException
ParseException
public final void RecursiveSmartsExpression() throws ParseException
ParseException
public final void PrimitiveAtomExpression() throws ParseException
ParseException
public final void TotalHCount() throws ParseException
ParseException
public final void ImplicitHCount() throws ParseException
ParseException
public final void ExplicitConnectivity() throws ParseException
ParseException
public final void AtomicNumber() throws ParseException
ParseException
public final void HybridizationNumber() throws ParseException
ParseException
public final void Charge() throws ParseException
ParseException
public final void RingConnectivity() throws ParseException
ParseException
public final void PeriodicGroupNumber() throws ParseException, ParseException
ParseException
public final void TotalConnectivity() throws ParseException
ParseException
public final void Valence() throws ParseException
ParseException
public final void RingMembership() throws ParseException
ParseException
public final void SmallestRingSize() throws ParseException
ParseException
public final void Aliphatic() throws ParseException
ParseException
public final void NonCHHeavyAtom() throws ParseException
ParseException
public final void Aromatic() throws ParseException
ParseException
public final void AnyAtom() throws ParseException
ParseException
public final void AtomicMass() throws ParseException
ParseException
public final void RingIdentifier() throws ParseException
ParseException
public final void Chirality() throws ParseException
ParseException
public final void NoHydrogenElement() throws ParseException
ParseException
public void ReInit(InputStream stream)
public void ReInit(InputStream stream, String encoding)
public void ReInit(Reader stream)
public void ReInit(SMARTSParserTokenManager tm)
public final Token getNextToken()
public final Token getToken(int index)
public ParseException generateParseException()
public final void enable_tracing()
public final void disable_tracing()
Copyright © 2017. All Rights Reserved.