Class 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
    • 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.
    • Method Detail

      • 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
      • AtomExpression

        public final org.openscience.cdk.smiles.smarts.parser.ASTAtom AtomExpression()
                                                                              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.
      • 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.