org.jmol.smiles
Class SmilesMatcher

java.lang.Object
  extended by org.jmol.smiles.SmilesMatcher
All Implemented Interfaces:
SmilesMatcherInterface

public class SmilesMatcher
extends java.lang.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 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
private static int MODE_ARRAY
           
private static int MODE_BITSET
           
private static int MODE_MAP
           
 
Constructor Summary
SmilesMatcher()
           
 
Method Summary
 boolean areEqual(java.lang.String smiles, SmilesSearch molecule)
          for JUnit test, mainly
 int areEqual(java.lang.String smiles1, java.lang.String smiles2)
           
private  java.util.BitSet[] find(java.lang.String pattern, SmilesSearch search, boolean isSmarts, boolean matchAllAtoms, boolean firstMatchOnly)
           
 java.util.BitSet[] find(java.lang.String pattern, java.lang.String smiles, boolean isSmarts, boolean firstMatchOnly)
          Searches for all matches of a pattern within a SMILES string.
 int[][] getCorrelationMaps(java.lang.String pattern, JmolNode[] atoms, int atomCount, java.util.BitSet bsSelected, boolean isSmarts, boolean firstMatchOnly)
          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.
 java.lang.String getLastException()
           
 java.lang.String getMolecularFormula(java.lang.String pattern, boolean isSmarts)
           
 java.lang.String getSmiles(JmolNode[] atoms, int atomCount, java.util.BitSet bsSelected, boolean asBioSmiles, boolean allowUnmatchedRings, boolean addCrossLinks, java.lang.String comment)
           
 java.util.BitSet getSubstructureSet(java.lang.String pattern, JmolNode[] atoms, int atomCount, java.util.BitSet bsSelected, boolean isSmarts, boolean firstMatchOnly)
          Returns a bitset matching the pattern within atoms.
 java.util.BitSet[] getSubstructureSetArray(java.lang.String pattern, JmolNode[] atoms, int atomCount, java.util.BitSet bsSelected, java.util.BitSet bsAromatic, boolean isSmarts, boolean firstMatchOnly)
          Returns a vector of bitsets indicating which atoms match the pattern.
private  java.lang.Object match(java.lang.String pattern, JmolNode[] atoms, int atomCount, java.util.BitSet bsSelected, java.util.BitSet bsAromatic, boolean isSmarts, boolean matchAllAtoms, boolean firstMatchOnly, int mode)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_BITSET

private static final int MODE_BITSET
See Also:
Constant Field Values

MODE_ARRAY

private static final int MODE_ARRAY
See Also:
Constant Field Values

MODE_MAP

private static final int MODE_MAP
See Also:
Constant Field Values
Constructor Detail

SmilesMatcher

public SmilesMatcher()
Method Detail

getLastException

public java.lang.String getLastException()
Specified by:
getLastException in interface SmilesMatcherInterface

getMolecularFormula

public java.lang.String getMolecularFormula(java.lang.String pattern,
                                            boolean isSmarts)
Specified by:
getMolecularFormula in interface SmilesMatcherInterface

getSmiles

public java.lang.String getSmiles(JmolNode[] atoms,
                                  int atomCount,
                                  java.util.BitSet bsSelected,
                                  boolean asBioSmiles,
                                  boolean allowUnmatchedRings,
                                  boolean addCrossLinks,
                                  java.lang.String comment)
Specified by:
getSmiles in interface SmilesMatcherInterface

areEqual

public int areEqual(java.lang.String smiles1,
                    java.lang.String smiles2)
Specified by:
areEqual in interface SmilesMatcherInterface

areEqual

public boolean areEqual(java.lang.String smiles,
                        SmilesSearch molecule)
for JUnit test, mainly

Parameters:
smiles -
molecule -
Returns:
true only if the SMILES strings match and there are no errors

find

public java.util.BitSet[] find(java.lang.String pattern,
                               java.lang.String smiles,
                               boolean isSmarts,
                               boolean firstMatchOnly)
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.
smiles -
isSmarts - TRUE for SMARTS strings, FALSE for SMILES strings
firstMatchOnly -
Returns:
number of occurances of pattern within smiles

getSubstructureSet

public java.util.BitSet getSubstructureSet(java.lang.String pattern,
                                           JmolNode[] atoms,
                                           int atomCount,
                                           java.util.BitSet bsSelected,
                                           boolean isSmarts,
                                           boolean firstMatchOnly)
Returns a bitset matching the pattern within atoms.

Specified by:
getSubstructureSet in interface SmilesMatcherInterface
Parameters:
pattern - SMILES or SMARTS pattern.
atoms -
atomCount -
bsSelected -
isSmarts -
firstMatchOnly -
Returns:
BitSet indicating which atoms match the pattern.

getSubstructureSetArray

public java.util.BitSet[] getSubstructureSetArray(java.lang.String pattern,
                                                  JmolNode[] atoms,
                                                  int atomCount,
                                                  java.util.BitSet bsSelected,
                                                  java.util.BitSet bsAromatic,
                                                  boolean isSmarts,
                                                  boolean firstMatchOnly)
Returns a vector of bitsets indicating which atoms match the pattern.

Specified by:
getSubstructureSetArray in interface SmilesMatcherInterface
Parameters:
pattern - SMILES or SMARTS pattern.
atoms -
atomCount -
bsSelected -
bsAromatic -
isSmarts -
firstMatchOnly -
Returns:
BitSet Array indicating which atoms match the pattern.

getCorrelationMaps

public int[][] getCorrelationMaps(java.lang.String pattern,
                                  JmolNode[] atoms,
                                  int atomCount,
                                  java.util.BitSet bsSelected,
                                  boolean isSmarts,
                                  boolean firstMatchOnly)
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 -
atomCount -
bsSelected -
isSmarts -
firstMatchOnly -
Returns:
a set of atom correlations

find

private java.util.BitSet[] find(java.lang.String pattern,
                                SmilesSearch search,
                                boolean isSmarts,
                                boolean matchAllAtoms,
                                boolean firstMatchOnly)

match

private java.lang.Object match(java.lang.String pattern,
                               JmolNode[] atoms,
                               int atomCount,
                               java.util.BitSet bsSelected,
                               java.util.BitSet bsAromatic,
                               boolean isSmarts,
                               boolean matchAllAtoms,
                               boolean firstMatchOnly,
                               int mode)