SmilesParser
Date: 2019-10-22

org.jmol.smiles

## Class SmilesParser

- java.lang.Object
- - org.jmol.smiles.SmilesParser

-     public class SmilesParser
      extends java.lang.Object

  Parses a SMILES string or SMARTS pattern to create a `SmilesSearch`. Currently this parser supports only parts of the SMILES specification.
  An example on how to use it:

       try {
         SmilesParser sp = new SmilesParser();
         SmilesSearch sm = sp.parseSmiles("CC(C)C(=O)O");
         // Use the resulting SmilesSearch
       } catch (InvalidSmilesException e) {
         // Exception management
       }

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private char` | `bioType`
    `private boolean` | `bondDirectionPaired`
    `private int` | `braceCount`
    `private int` | `branchLevel`
    `private int` | `componentCount`
    `private int` | `componentParenCount`
    `private java.util.Map<java.lang.Integer,SmilesBond>` | `connections`
    `private int` | `flags`
    `private java.util.Map<java.lang.String,SmilesMeasure>` | `htMeasures`
    `private boolean` | `ignoreStereochemistry`
    `private boolean` | `isBioSequence`
    `private boolean` | `isSmarts`
    `private boolean` | `isTarget`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SmilesParser(boolean isSmarts, boolean isTarget)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private int` | `checkBioType(java.lang.String pattern, int index)`
    `private boolean` | `checkBrace(SmilesSearch search, char ch, char type)`
    `private int` | `checkCharge(java.lang.String pattern, int index, SmilesAtom newAtom)`
    `private boolean` | `checkLogic(SmilesSearch search, java.lang.String pattern, SmilesAtom atom, SmilesBond bond, SmilesAtom currentAtom, boolean isAND, boolean isBranchAtom, int[] ret)`
    `private void` | `checkNested(SmilesSearch search, SmilesAtom atom, int flags)`
    `(package private) static java.lang.String` | `cleanPattern(java.lang.String pattern)`
    `(package private) static java.lang.String` | `extractFlags(java.lang.String pattern, int[] ret)`
    `private void` | `fixChirality(SmilesSearch search)`
    `(package private) static char` | `getChar(java.lang.String pattern, int i)`
    `(package private) static int` | `getDigits(java.lang.String pattern, int index, int[] ret)`
    `(package private) static int` | `getFlags(java.lang.String pattern)`
    `(package private) static int` | `getRingNumber(java.lang.String pattern, int index, char ch, int[] ret)`
    `(package private) static java.lang.String` | `getSubPattern(java.lang.String pattern, int index, char ch)`
    `(package private) SmilesSearch` | `getSubsearch(SmilesSearch parent, java.lang.String pattern, int flags)`
    `(package private) static SmilesSearch` | `newSearch(java.lang.String pattern, boolean isSmarts, boolean isTarget)`
    `(package private) SmilesSearch` | `parse(java.lang.String pattern)` Parses a SMILES String
    `private SmilesAtom` | `parseAtom(SmilesSearch search, SmilesAtom atomSet, java.lang.String pattern, SmilesAtom atom, SmilesBond bond, boolean isBracketed, boolean isAND, boolean isBranchAtom)` Parses an atom definition
    `private SmilesBond` | `parseBond(SmilesSearch search, SmilesBond bondSet, java.lang.String pattern, SmilesBond bond, SmilesAtom currentAtom, boolean isAND, boolean isBranchAtom, int len, int[] ret)`
    `private void` | `parseConnection(SmilesSearch search, int ringNum, SmilesAtom currentAtom, SmilesBond bond)` Parses a ring definition
    `private void` | `parseMeasure(SmilesSearch search, java.lang.String strMeasure, SmilesAtom currentAtom)`
    `private java.lang.String` | `parseNested(SmilesSearch search, java.lang.String pattern, java.lang.String prefix)`
    `private void` | `parseSmiles(SmilesSearch search, java.lang.String pattern, SmilesAtom currentAtom, boolean isBranchAtom)` Parses a part of a SMILES String
    `private java.lang.String` | `parseVariableLength(java.lang.String pattern)`
    `private java.lang.String` | `parseVariables(java.lang.String pattern)` variables can be defined, as in select within(SMARTS,'$R1="[CH3, NH2]";$R2="[$([$R1]),OH]"; {a}[$R2]') select within(SMARTS,'$R1="[CH3,NH2]";$R2="[OH]"; {a}[$([$R1]),$([$R2])]') "select aromatic atoms bearing CH3, NH2, or OH"
    `private void` | `setBondAtom(SmilesBond bond, SmilesAtom a1, SmilesAtom a2, SmilesSearch search)` set the bond and look for a=a, setting AROMATIC_DOUBLE automatically if found
    `private static int` | `skipTo(java.lang.String pattern, int index, char ch0)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### connections

          private java.util.Map<java.lang.Integer,SmilesBond> connections

    - #### htMeasures

          private java.util.Map<java.lang.String,SmilesMeasure> htMeasures

    - #### flags

          private int flags

    - #### isSmarts

          private boolean isSmarts

    - #### isBioSequence

          private boolean isBioSequence

    - #### bioType

          private char bioType

    - #### braceCount

          private int braceCount

    - #### branchLevel

          private int branchLevel

    - #### componentCount

          private int componentCount

    - #### componentParenCount

          private int componentParenCount

    - #### ignoreStereochemistry

          private boolean ignoreStereochemistry

    - #### bondDirectionPaired

          private boolean bondDirectionPaired

    - #### isTarget

          private boolean isTarget

  - ### Constructor Detail

    - #### SmilesParser

          SmilesParser(boolean isSmarts,
                       boolean isTarget)

  - ### Method Detail

    - #### newSearch

          static SmilesSearch newSearch(java.lang.String pattern,
                                        boolean isSmarts,
                                        boolean isTarget)
                                 throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### parse

          SmilesSearch parse(java.lang.String pattern)
                      throws InvalidSmilesException

      Parses a SMILES String
      Parameters:
        `pattern` - SMILES String
      Returns:
        Molecule corresponding pattern
      Throws:
        `InvalidSmilesException`

    - #### parseVariableLength

          private java.lang.String parseVariableLength(java.lang.String pattern)
                                                throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### getSubsearch

          SmilesSearch getSubsearch(SmilesSearch parent,
                                    java.lang.String pattern,
                                    int flags)
                             throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### checkNested

          private void checkNested(SmilesSearch search,
                                   SmilesAtom atom,
                                   int flags)
                            throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### fixChirality

          private void fixChirality(SmilesSearch search)
                             throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### parseSmiles

          private void parseSmiles(SmilesSearch search,
                                   java.lang.String pattern,
                                   SmilesAtom currentAtom,
                                   boolean isBranchAtom)
                            throws InvalidSmilesException

      Parses a part of a SMILES String
      Parameters:
        `search` - SmilesSearch being built
        `pattern` - SMILES String
        `currentAtom` - Current atom
        `isBranchAtom` - If we are starting a new branch
      Throws:
        `InvalidSmilesException`

    - #### parseConnection

          private void parseConnection(SmilesSearch search,
                                       int ringNum,
                                       SmilesAtom currentAtom,
                                       SmilesBond bond)
                                throws InvalidSmilesException

      Parses a ring definition
      Parameters:
        `search` - Resulting molecule
        `ringNum` -
        `currentAtom` - Current atom
        `bond` -
      Throws:
        `InvalidSmilesException`

    - #### setBondAtom

          private void setBondAtom(SmilesBond bond,
                                   SmilesAtom a1,
                                   SmilesAtom a2,
                                   SmilesSearch search)

      set the bond and look for a=a, setting AROMATIC_DOUBLE automatically if found
      Parameters:
        `bond` -
        `a1` -
        `a2` -
        `search` -

    - #### getRingNumber

          static int getRingNumber(java.lang.String pattern,
                                   int index,
                                   char ch,
                                   int[] ret)
                            throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### checkBioType

          private int checkBioType(java.lang.String pattern,
                                   int index)

    - #### parseMeasure

          private void parseMeasure(SmilesSearch search,
                                    java.lang.String strMeasure,
                                    SmilesAtom currentAtom)
                             throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### checkBrace

          private boolean checkBrace(SmilesSearch search,
                                     char ch,
                                     char type)
                              throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### parseNested

          private java.lang.String parseNested(SmilesSearch search,
                                               java.lang.String pattern,
                                               java.lang.String prefix)
                                        throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### parseVariables

          private java.lang.String parseVariables(java.lang.String pattern)
                                           throws InvalidSmilesException

      variables can be defined, as in select within(SMARTS,'$R1="[CH3, NH2]";$R2="[$([$R1]),OH]"; {a}[$R2]') select within(SMARTS,'$R1="[CH3,NH2]";$R2="[OH]"; {a}[$([$R1]),$([$R2])]') "select aromatic atoms bearing CH3, NH2, or OH"
      Parameters:
        `pattern` -
      Returns:
        substituted pattern
      Throws:
        `InvalidSmilesException`

    - #### parseAtom

          private SmilesAtom parseAtom(SmilesSearch search,
                                       SmilesAtom atomSet,
                                       java.lang.String pattern,
                                       SmilesAtom atom,
                                       SmilesBond bond,
                                       boolean isBracketed,
                                       boolean isAND,
                                       boolean isBranchAtom)
                                throws InvalidSmilesException

      Parses an atom definition
      Parameters:
        `search` - current search
        `atomSet` - upper-level SmilesAtom if from checkLogic
        `pattern` - SMILES or SMARTS String
        `atom` - parent atom or null
        `bond` - null or parent bond
        `isBracketed` - true if a bracketed definition [...]
        `isAND` - being called from checkLogic for & or ;
        `isBranchAtom` -
      Returns:
        New atom
      Throws:
        `InvalidSmilesException`

    - #### checkCharge

          private int checkCharge(java.lang.String pattern,
                                  int index,
                                  SmilesAtom newAtom)
                           throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### parseBond

          private SmilesBond parseBond(SmilesSearch search,
                                       SmilesBond bondSet,
                                       java.lang.String pattern,
                                       SmilesBond bond,
                                       SmilesAtom currentAtom,
                                       boolean isAND,
                                       boolean isBranchAtom,
                                       int len,
                                       int[] ret)
                                throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### checkLogic

          private boolean checkLogic(SmilesSearch search,
                                     java.lang.String pattern,
                                     SmilesAtom atom,
                                     SmilesBond bond,
                                     SmilesAtom currentAtom,
                                     boolean isAND,
                                     boolean isBranchAtom,
                                     int[] ret)
                              throws InvalidSmilesException

      Parameters:
        `search` -
        `pattern` -
        `atom` -
        `bond` -
        `currentAtom` -
        `isAND` -
        `isBranchAtom` -
        `ret` -
      Returns:
        true if we are done
      Throws:
        `InvalidSmilesException`

    - #### getSubPattern

          static java.lang.String getSubPattern(java.lang.String pattern,
                                                int index,
                                                char ch)
                                         throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### getChar

          static char getChar(java.lang.String pattern,
                              int i)

    - #### getDigits

          static int getDigits(java.lang.String pattern,
                               int index,
                               int[] ret)

      Parameters:
        `pattern` -
        `index` -
        `ret` -
      Returns:
        pointer to the character AFTER the digits

    - #### skipTo

          private static int skipTo(java.lang.String pattern,
                                    int index,
                                    char ch0)

    - #### cleanPattern

          static java.lang.String cleanPattern(java.lang.String pattern)

      Parameters:
        `pattern` -
      Returns:
        comments and white space removed, also ^^ to '

    - #### extractFlags

          static java.lang.String extractFlags(java.lang.String pattern,
                                               int[] ret)
                                        throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`

    - #### getFlags

          static int getFlags(java.lang.String pattern)
                       throws InvalidSmilesException

      Throws:
        `InvalidSmilesException`