# Class SmilesMatcher

java.lang.Object
org.jmol.smiles.SmilesMatcher

All Implemented Interfaces:
  `SmilesMatcherInterface`

public class SmilesMatcher extends Object implements SmilesMatcherInterface
Originating author: Nicholas Vervelle A class to handle a variety of SMILES/SMARTS-related functions, including: -- determining if two SMILES strings are equivalent -- determining the molecular formula of a SMILES or SMARTS string -- searching for specific runs of atoms in a 3D model -- searching for specific runs of atoms in a SMILES description -- generating valid (though not canonical) SMILES and bioSMILES strings -- getting atom-atom correlation maps to be used with biomolecular alignment methods

The original SMILES description can been found at the SMILES Home Page. Specification for this implementation can be found in package.html.

    public methods:

    int areEqual  -- checks a SMILES string against a reference (-1 for error; 0 for no finds; >0 for number of finds)

    BitSet[] find  -- finds one or more occurances of a SMILES or SMARTS string within a SMILES string

    int[][] getCorrelationMaps  -- returns correlated arrays of atoms

    String getLastError  -- returns any error that was last encountered.

    String getMolecularFormula   -- returns the MF of a SMILES or SMARTS string

    String getRelationship -- returns isomeric relationship

    String getSmiles  -- returns a standard SMILES string or a
                     Jmol BIOSMILES string with comment header.

    BitSet getSubstructureSet  -- returns a single BitSet with all found atoms included

      in Jmol script:

      string2.find("SMILES", string1)
      string2.find("SMARTS", string1)

      e.g.

        print "CCCC".find("SMILES", "C[C]")

      select search("smartsString")

      All bioSMARTS strings begin with ~ (tilde).

Author:
  Bob Hanson

## Field Summary

Fields
Modifier and Type
Field
Description
`static boolean`
`j2sHeadless`

## Constructor Summary

Constructors
Constructor
Description
`SmilesMatcher()`

## Method Summary

Modifier and Type
Method
Description
`int`
`areEqual(Object smiles1, Object smiles2)`
`boolean`
`areEqualTest(String smiles, SmilesSearch search)`
for JUnit test, mainly
`String`
`cleanSmiles(String smiles)`
`Object`
`compileSearchTarget(Node[] atoms, int atomCount, BS bsSelected)`
`Object`
`compileSmartsPattern(String pattern)`
`int[][]`
`find(Object pattern, Object target, int flags)`
Searches for all matches of a pattern within a SMILES string.
`Node[]`
`getAtoms(Object target)`
`String`
`getAtropisomerKeys(String pattern, Node[] atoms, int ac, BS bsSelected, BS bsAromatic, int flags)`
called by SmilesParser to get nn in ^nn- base on match to actual structure
`int[][]`
`getCorrelationMaps(Object pattern, Node[] atoms, int atomCount, BS bsSelected, int flags)`
Rather than returning bitsets, this method returns the sets of matching atoms in array form so that a direct atom-atom correlation can be made.
`String`
`getLastException()`
`int[][]`
`getMapForJME(String jme, Atom[] at, BS bsAtoms)`
`void`
`getMMFF94AtomTypes(String[] smarts, Node[] atoms, int ac, BS bsSelected, Lst<BS> ret, Lst<BS>[] vRings)`
called by ForceFieldMMFF.setAtomTypes only
`String`
`getMolecularFormula(Object pattern, boolean isSmarts, boolean isEmpirical)`
`String`
`getRelationship(String smiles1, String smiles2)`
`String`
`getSmiles(Node[] atoms, int ac, BS bsSelected, String bioComment, int flags)`
internal to Jmol -- called by org.jmol.Viewer.getSmiles
`String`
`getSmilesFromJME(String jme)`
`BS`
`getSubstructureSet(Object pattern, Object target, int ac, BS bsSelected, int flags)`
Returns a bitset matching the pattern within a set of Jmol atoms.
`BS[]`
`getSubstructureSetArray(Object pattern, Node[] atoms, int ac, BS bsSelected, BS bsAromatic, int flags)`
Returns a vector of bitsets indicating which atoms match the pattern.
`int[]`
`hasStructure(Object pattern, Object[] smilesSet, int flags)`
Look for pattern in each smilesSet string.
`static SmilesSearch`
`jmeToMolecule(String jme)`
`String`
`polyhedronToSmiles(Node center, int[][] faces, int atomCount, P3[] points, int flags, String details)`
Generate a topological SMILES string from a set of faces
`String`
`reverseChirality(String smiles)`
Note, this may be incompatible with [$(select(..))] THIS IS NOT DEPENDABLE.

### Methods inherited from class Object

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

## Field Details

### j2sHeadless

public static boolean j2sHeadless

## Constructor Details

### SmilesMatcher

public SmilesMatcher()

## Method Details

### getLastException

public String getLastException()

Specified by:
  `getLastException` in interface `SmilesMatcherInterface`

### getMolecularFormula

public String getMolecularFormula(Object pattern, boolean isSmarts, boolean isEmpirical) throws Exception

Specified by:
  `getMolecularFormula` in interface `SmilesMatcherInterface`
Throws:
  `Exception`

### getSmiles

public String getSmiles(Node[] atoms, int ac, BS bsSelected, String bioComment, int flags) throws Exception
internal to Jmol -- called by org.jmol.Viewer.getSmiles

Specified by:
  `getSmiles` in interface `SmilesMatcherInterface`
Throws:
  `Exception`

### areEqual

public int areEqual(Object smiles1, Object smiles2) throws Exception

Specified by:
  `areEqual` in interface `SmilesMatcherInterface`
Throws:
  `Exception`

### areEqualTest

public boolean areEqualTest(String smiles, SmilesSearch search) throws Exception
for JUnit test, mainly

Parameters:
  `smiles` -
  `search` -
Returns:
  true only if the SMILES strings match and there are no errors
Throws:
  `Exception`

### find

public int[][] find(Object pattern, Object target, int flags) throws Exception
Searches for all matches of a pattern within a SMILES string. If SMILES (not isSmarts), requires that all atoms be part of the match.

Specified by:
  `find` in interface `SmilesMatcherInterface`
Parameters:
  `pattern` - SMILES or SMARTS pattern or SmilesSearch from compiling of a pattern string.
  `target` -
  `flags` -
Returns:
  array of correlations of occurances of pattern within smiles
Throws:
  `Exception`

### getAtoms

public Node[] getAtoms(Object target) throws Exception

Specified by:
  `getAtoms` in interface `SmilesMatcherInterface`
Throws:
  `Exception`

### getRelationship

public String getRelationship(String smiles1, String smiles2) throws Exception

Specified by:
  `getRelationship` in interface `SmilesMatcherInterface`
Throws:
  `Exception`

### reverseChirality

public String reverseChirality(String smiles)
Note, this may be incompatible with [$(select(..))] THIS IS NOT DEPENDABLE. USE /invertStereo/ INSTEAD

Specified by:
  `reverseChirality` in interface `SmilesMatcherInterface`

### getSubstructureSet

public BS getSubstructureSet(Object pattern, Object target, int ac, BS bsSelected, int flags) throws Exception
Returns a bitset matching the pattern within a set of Jmol atoms.

Specified by:
  `getSubstructureSet` in interface `SmilesMatcherInterface`
Parameters:
  `pattern` - SMILES or SMARTS pattern.
  `target` -
  `ac` -
  `bsSelected` -
  `flags` -
Returns:
  BitSet indicating which atoms match the pattern.
Throws:
  `Exception`

### getMMFF94AtomTypes

public void getMMFF94AtomTypes(String[] smarts, Node[] atoms, int ac, BS bsSelected, Lst<BS> ret, Lst<BS>[] vRings) throws Exception
called by ForceFieldMMFF.setAtomTypes only

Specified by:
  `getMMFF94AtomTypes` in interface `SmilesMatcherInterface`
Throws:
  `Exception`

### getSubstructureSetArray

public BS[] getSubstructureSetArray(Object pattern, Node[] atoms, int ac, BS bsSelected, BS bsAromatic, int flags) throws Exception
Returns a vector of bitsets indicating which atoms match the pattern.

Specified by:
  `getSubstructureSetArray` in interface `SmilesMatcherInterface`
Parameters:
  `pattern` - SMILES or SMARTS pattern.
  `atoms` -
  `ac` -
  `bsSelected` -
  `bsAromatic` -
Returns:
  BitSet Array indicating which atoms match the pattern.
Throws:
  `Exception`

### getAtropisomerKeys

public String getAtropisomerKeys(String pattern, Node[] atoms, int ac, BS bsSelected, BS bsAromatic, int flags) throws Exception
called by SmilesParser to get nn in ^nn- base on match to actual structure

Parameters:
  `pattern` -
  `atoms` -
  `ac` -
  `bsSelected` -
  `bsAromatic` -
  `flags` -
Returns:
  string of nn,nn,nn,nn
Throws:
  `Exception`

### polyhedronToSmiles

public String polyhedronToSmiles(Node center, int[][] faces, int atomCount, P3[] points, int flags, String details) throws Exception
Generate a topological SMILES string from a set of faces

Specified by:
  `polyhedronToSmiles` in interface `SmilesMatcherInterface`
Parameters:
  `faces` -
  `atomCount` -
Returns:
  topological SMILES string
Throws:
  `Exception`

### getCorrelationMaps

public int[][] getCorrelationMaps(Object pattern, Node[] atoms, int atomCount, BS bsSelected, int flags) throws Exception
Rather than returning bitsets, this method returns the sets of matching atoms in array form so that a direct atom-atom correlation can be made.

Specified by:
  `getCorrelationMaps` in interface `SmilesMatcherInterface`
Parameters:
  `pattern` - SMILES or SMARTS pattern.
  `atoms` -
  `bsSelected` -
Returns:
  a set of atom correlations
Throws:
  `Exception`

### cleanSmiles

public String cleanSmiles(String smiles)

Specified by:
  `cleanSmiles` in interface `SmilesMatcherInterface`

### getMapForJME

public int[][] getMapForJME(String jme, Atom[] at, BS bsAtoms)

Specified by:
  `getMapForJME` in interface `SmilesMatcherInterface`

### jmeToMolecule

public static SmilesSearch jmeToMolecule(String jme) throws InvalidSmilesException

Throws:
  `InvalidSmilesException`

### getSmilesFromJME

public String getSmilesFromJME(String jme)

Specified by:
  `getSmilesFromJME` in interface `SmilesMatcherInterface`

### compileSmartsPattern

public Object compileSmartsPattern(String pattern) throws Exception

Specified by:
  `compileSmartsPattern` in interface `SmilesMatcherInterface`
Throws:
  `Exception`

### compileSearchTarget

public Object compileSearchTarget(Node[] atoms, int atomCount, BS bsSelected)

Specified by:
  `compileSearchTarget` in interface `SmilesMatcherInterface`

### hasStructure

public int[] hasStructure(Object pattern, Object[] smilesSet, int flags) throws Exception
Look for pattern in each smilesSet string.

Specified by:
  `hasStructure` in interface `SmilesMatcherInterface`
Returns:
  int array of same length as smiles set with 1 = match found, 0 = not found, and -1 meaning a parsing or searching error.
Throws:
  `Exception`