Package chemaxon.sss.formula
Class FormulaSearch
java.lang.Object
chemaxon.sss.formula.FormulaSearch
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
Modifier and TypeFieldDescriptionstatic 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
-
Method Summary
Modifier and TypeMethodDescriptiongetQuery()
Gets the chemical formula query string used for searchingint
Gets the formula search type.Gets the chemical formula of the target used to search inboolean
Checks if the query formula matches the target formula according to the formula search type.static boolean
isValidQuery
(String formula) Checks the given formula whether it is a valid query formulastatic boolean
isValidTarget
(String formula) Checks the given formula whether it is a valid target formulavoid
Sets the chemical formula query string used for searchingvoid
setSearchType
(int value) Sets the type of the formula search.void
Sets the chemical formula target string used to search in
-
Field Details
-
NONE
public static final int NONEConstant value specifying the none search type.- See Also:
-
EXACT
public static final int EXACTConstant 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_SUBFORMULAConstant 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 SUBFORMULAConstant 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
Sets the chemical formula query string used for searching- Parameters:
query
- chemical formula of the query- Throws:
IllegalArgumentException
- if encounters some parsing errors
-
getQuery
Gets the chemical formula query string used for searching- Returns:
- the chemical formula string
-
setTarget
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
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
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
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
-