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:
Belongs to CDK module:
smarts
Keywords:
SMARTS, substructure search
Created on:
2007-04-23
Requires:
ant1.6
  • Field Details

  • Constructor Details

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

    • parse

      public static QueryAtomContainer parse(String smarts, IChemObjectBuilder builder)
      This method parses a Smarts String and returns an instance of QueryAtomContainer
    • 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
      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.
    • enable_tracing

      public final void enable_tracing()
      Enable tracing.
    • disable_tracing

      public final void disable_tracing()
      Disable tracing.