Class FormulaSearch

java.lang.Object
chemaxon.sss.formula.FormulaSearch

@PublicApi public class FormulaSearch extends Object
Chemical formula based search class.

Features:

  • case insensitive notation, upper case letters however define a new atom for the formula parser
  • no Hill notation is required
  • parentheses can be used for: multiplication - (C2H6)3, polymers - (C4H6)n, combinatorical groups - (Br + I + F)4
  • interval definition: N-M - at least N, at most M
  • multiple components are separated with a period (.), in case of multiple components a coefficient can be set for each component. Coefficient examples: x - any, 2 - two, 2 - 4 - interval between two and four, use 1 / 5 for fractions.
  • isotope handling is available using brackets [12C]. Trivial abbreviations are also accepted D = [2H], T = [3H].

Search types:

  • Exact search - The result list contains molecular formulas equal to the given search criteria, atoms with differing numbers and other atom types are not allowed to be present.
  • Exact subformula search - The result list contains molecular formulas equal to the given search criteria, atoms with differing numbers will not, but other atom types may be present. E.g. query formula C6 H6 O6 matches C6 H6 O6 S but does not match C4 H6 O6
  • Subformula search - The result list contains molecular formulas matching at least the given search criteria but higher number of atoms and other atom types may also be present. E.g. query formula C6 H6 O2 matches C6 H12 O6, C6 H6 O2 S but does not match C4 H6 O6 or C2 H6 O N. According to search rules, in subformula search the query formula can match polymer formula as well.

Example code:

 FormulaSearch formulaSearch = new FormulaSearch();

 String queryFormula;
 ... // obtain chemical formula of the query
 String targetFormula;
 ... // obtain chemical formula of the target

 formulaSearch.setSearchType(FormulaSearch.EXACT); // see search types
 formulaSearch.setQuery(queryFormula); // set query formula
 formulaSearch.setTarget(targetFormula); // set target formula

 return formulaSearch.isMatching();
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Constant value specifying the exact search type.
    static final int
    Constant value specifying the exact sub formula search type.
    static final int
    Constant value specifying the none search type.
    static final int
    Constant value specifying the sub formula search type.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the chemical formula query string used for searching
    int
    Gets the formula search type.
    Gets the chemical formula of the target used to search in
    boolean
    Checks if the query formula matches the target formula according to the formula search type.
    static boolean
    Checks the given formula whether it is a valid query formula
    static boolean
    Checks the given formula whether it is a valid target formula
    void
    Sets the chemical formula query string used for searching
    void
    setSearchType(int value)
    Sets the type of the formula search.
    void
    setTarget(String target)
    Sets the chemical formula target string used to search in

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NONE

      public static final int NONE
      Constant value specifying the none search type.
      See Also:
    • EXACT

      public static final int EXACT
      Constant value specifying the exact search type. The target needs to match the query exactly for all atoms and cannot contain other atoms.
      See Also:
    • EXACT_SUBFORMULA

      public static final int EXACT_SUBFORMULA
      Constant value specifying the exact sub formula search type. The target needs to match the query exactly for all atoms but can contain unmentioned atoms as well.
      See Also:
    • SUBFORMULA

      public static final int SUBFORMULA
      Constant value specifying the sub formula search type. The target needs to contain at least the specified number of atoms given in the query.
      See Also:
  • Constructor Details

    • FormulaSearch

      public FormulaSearch()
  • Method Details

    • setSearchType

      public void setSearchType(int value)
      Sets the type of the formula search.
      Parameters:
      value - the search type
      See Also:
    • getSearchType

      public int getSearchType()
      Gets the formula search type.
      Returns:
      the type of the search
      See Also:
    • setQuery

      public void setQuery(String query) throws IllegalArgumentException
      Sets the chemical formula query string used for searching
      Parameters:
      query - chemical formula of the query
      Throws:
      IllegalArgumentException - if encounters some parsing errors
    • getQuery

      public String getQuery()
      Gets the chemical formula query string used for searching
      Returns:
      the chemical formula string
    • setTarget

      public void setTarget(String target) throws IllegalArgumentException
      Sets the chemical formula target string used to search in
      Parameters:
      target - chemical formula of the target
      Throws:
      IllegalArgumentException - if encounters some parsing errors
    • getTarget

      public String getTarget()
      Gets the chemical formula of the target used to search in
      Returns:
      the chemical formula string
    • isMatching

      public boolean isMatching()
      Checks if the query formula matches the target formula according to the formula search type.
      Returns:
      true if query matches the target, false if query or target was not supplied correctly, or no match is possible
      See Also:
    • isValidQuery

      public static boolean isValidQuery(String formula)
      Checks the given formula whether it is a valid query formula
      Parameters:
      formula - the formula to be checked
      Returns:
      true if the formula is valid
    • isValidTarget

      public static boolean isValidTarget(String formula)
      Checks the given formula whether it is a valid target formula
      Parameters:
      formula - the formula to be checked
      Returns:
      true if the formula is valid