chemaxon.sss.search
Class MolComparator

java.lang.Object
  extended bychemaxon.sss.search.MolComparator

public class MolComparator
extends java.lang.Object

Interface for comparing atoms, bonds, etc. against different criteria. Its subclasses are used by the search classes. Methods to be overriden: compareAtoms(int, int), compareBonds(int, int), compareHit(int[], int). The comparison methods in this class are empty convenience methods that always return true. The init and unInit methods should call super method if overridden.

Utility methods to get original query and target atom molecular indexes are: getOrigQueryAtom(int), getOrigTargetAtom(int), getOrigQueryNeighbour(int), getOrigTargetNeighbour(int).

Since:
JChem 3.2
Author:
Szabolcs Csepregi Date: Dec 12, 2005

Field Summary
static int MAYBE_USEFUL
          Describes that the MolComparator may be needed with the current search object and the current query, depending on the target.
static int NOT_USEFUL
          Describes that the MolComparator is not needed with the current search object, the current query (and target).
protected  Molecule query
           
protected  chemaxon.sss.search.StructureSearch searcher
           
protected  Molecule target
           
static int USEFUL
          Describes that the MolComparator should be used with the current search object and the current query, regardless of the target.
 
Constructor Summary
MolComparator()
           
 
Method Summary
 boolean compareAtoms(int a1, int a2)
          Compares atoms of indices a1 and a2.
 boolean compareBonds(int b1, int b2)
          Compares bonds of indices b1 and b2.
 boolean compareHit(int[] internalHit, int internalHitLength)
          Checks a partial hit during the search algorithm.
 int getOrigQueryAtom(int a1)
          Converts search internal atom index (in the query) to the original atom index in the query molecule.
 int getOrigQueryAtom1(int bi)
          Returns the index of the first atom (atom index in the query molecule) of the given query bond(search internal bond index in the query).
 int getOrigQueryAtom2(int bi)
          Returns the index of the second atom (atom index in the query molecule) of the given query bond(search internal bond index in the query).
 int getOrigQueryBond(int bi)
          Returns bond index in the query molecule for the given query bond (search internal bond index in the query).
 int getOrigQueryNeighbour(int a)
          For a search internal atom index (in the query), returns a neighbour atom index (original atom index in the query molecule).
 int getOrigTargetAtom(int a1)
          Converts search internal atom index (in the target) to the original atom index in the target molecule.
 int getOrigTargetAtom1(int bi)
          Returns the index of the first atom (atom index in the target molecule) of the given target bond(search internal bond index in the target).
 int getOrigTargetAtom2(int bi)
          Returns the index of the second atom (atom index in the target molecule) of the given target bond(search internal bond index in the target).
 int getOrigTargetBond(int bi)
          Returns bond index in the target molecule for the given target bond (search internal bond index in the target).
 int getOrigTargetNeighbour(int a)
          For a search internal atom index (in the target), returns a neighbour atom index (original atom index in the target molecule).
 void initAll(Molecule q, Molecule t, chemaxon.sss.search.StructureSearch s)
           
 int isUsefulForQuery()
          Decides based on the query and the search object if the comparator should be used or not.
 int isUsefulForTarget()
          Decides based on the query, target and the search object if the comparator should be used or not.
 void setQuery(Molecule q)
           
 void setSearcher(chemaxon.sss.search.StructureSearch s)
           
 void setTarget(Molecule t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

query

protected Molecule query

target

protected Molecule target

searcher

protected chemaxon.sss.search.StructureSearch searcher

USEFUL

public static final int USEFUL
Describes that the MolComparator should be used with the current search object and the current query, regardless of the target.

See Also:
isUsefulForQuery(), Constant Field Values

MAYBE_USEFUL

public static final int MAYBE_USEFUL
Describes that the MolComparator may be needed with the current search object and the current query, depending on the target.

See Also:
isUsefulForQuery(), Constant Field Values

NOT_USEFUL

public static final int NOT_USEFUL
Describes that the MolComparator is not needed with the current search object, the current query (and target).

See Also:
isUsefulForQuery(), Constant Field Values
Constructor Detail

MolComparator

public MolComparator()
Method Detail

setQuery

public void setQuery(Molecule q)

setTarget

public void setTarget(Molecule t)

setSearcher

public void setSearcher(chemaxon.sss.search.StructureSearch s)

initAll

public void initAll(Molecule q,
                    Molecule t,
                    chemaxon.sss.search.StructureSearch s)

compareAtoms

public boolean compareAtoms(int a1,
                            int a2)
Compares atoms of indices a1 and a2. Indices are internal search indices, and not refer to the molecule! This method is called during initial match matrix creation.

Parameters:
a1 - atom in query (search internal index)
a2 - atom in target (search internal index)
Returns:
whether query atom a1 matches target atom a2
See Also:
getOrigQueryAtom(int), getOrigTargetAtom(int)

compareBonds

public boolean compareBonds(int b1,
                            int b2)
Compares bonds of indices b1 and b2. It is called during refining.

Parameters:
b1 - bond index in query
b2 - bond index in target
Returns:
whether the two bonds match

getOrigTargetAtom

public int getOrigTargetAtom(int a1)
Converts search internal atom index (in the target) to the original atom index in the target molecule.

Parameters:
a1 - internal target atom index
Returns:
The atom index in the target molecule or -1 if no corresponding atom exists. (e.g. implicit H. In this case, getOrigTargetNeighbour(int) may be helpful.)

getOrigQueryAtom

public int getOrigQueryAtom(int a1)
Converts search internal atom index (in the query) to the original atom index in the query molecule.

Parameters:
a1 - internal query atom index
Returns:
The atom index in the query molecule or -1 if no corresponding atom exists. (e.g. implicit H. In this case, getOrigQueryNeighbour(int) may be helpful.)

getOrigTargetNeighbour

public int getOrigTargetNeighbour(int a)
For a search internal atom index (in the target), returns a neighbour atom index (original atom index in the target molecule).

Parameters:
a - internal target atom index
Returns:
The neighbour atom index in the molecule or -1 if no neighbour atom exists. (e.g. isolated atom)
See Also:
getOrigTargetAtom(int)

getOrigQueryNeighbour

public int getOrigQueryNeighbour(int a)
For a search internal atom index (in the query), returns a neighbour atom index (original atom index in the query molecule).

Parameters:
a - internal query atom index
Returns:
The neighbour atom index in the molecule or -1 if no neighbour atom exists. (e.g. isolated atom)
See Also:
getOrigTargetAtom(int)

compareHit

public boolean compareHit(int[] internalHit,
                          int internalHitLength)
Checks a partial hit during the search algorithm. Useful if the custom matching criteria must use multiple query or target atoms.

Parameters:
internalHit - the current hit vector from the associated search object that contains atom indices of internal search representation. Strictly read only! The values of this array are incremented by 1 because of algorithmic reasons. This vector may contain only a partial match, so possibly not all query atoms have associated matchings.
You can get original atom indexes by using getOrigQueryAtom(int) (from array indexes) and getOrigTargetAtom(int) (from array values - do not forget to call a decreased value: getOrigTargetAtom(internalHit[i]-1) ).
For efficiency reasons, an array longer than necessary is returned, parameter internalHitLength contains the effective length of the array.
The search algorithm is incremental, so for the call history of this method a (partial) hit vector is preceded by its shorter prefixes of size at least 2. (This means that for a partial hit vector [0, 5, 2, 3], hit vectors [0, 5] and [0, 5, 2] have already been checked.)
internalHitLength - the effective length of internalHit.
Returns:
true if the partial hit describes a correct query-target correspondence.
See Also:
getOrigQueryAtom(int), getOrigTargetAtom(int)

isUsefulForQuery

public int isUsefulForQuery()
Decides based on the query and the search object if the comparator should be used or not. Override to save execution time of the search. If MAYBE_USEFUL is returned by this method, isUsefulForTarget is also called.

Returns:
USEFUL (default), MAYBE_USEFUL or NOT_USEFUL.
See Also:
USEFUL, MAYBE_USEFUL, NOT_USEFUL, isUsefulForTarget()

isUsefulForTarget

public int isUsefulForTarget()
Decides based on the query, target and the search object if the comparator should be used or not. Override to save execution time of the search. It is only used after isUsefulForQuery returned MAYBE_USEFUL

Returns:
USEFUL (default) or NOT_USEFUL.
See Also:
USEFUL, MAYBE_USEFUL, NOT_USEFUL, isUsefulForQuery()

getOrigQueryAtom1

public int getOrigQueryAtom1(int bi)
Returns the index of the first atom (atom index in the query molecule) of the given query bond(search internal bond index in the query).

Parameters:
bi - internal query bond index
Returns:
The atom index in the query molecule or -1 if no corresponding atom exists. (e.g. implicit H.)
Since:
JChem 3.2.3

getOrigQueryAtom2

public int getOrigQueryAtom2(int bi)
Returns the index of the second atom (atom index in the query molecule) of the given query bond(search internal bond index in the query).

Parameters:
bi - internal query bond index
Returns:
The atom index in the query molecule or -1 if no corresponding atom exists. (e.g. implicit H.)
Since:
JChem 3.2.3

getOrigTargetAtom1

public int getOrigTargetAtom1(int bi)
Returns the index of the first atom (atom index in the target molecule) of the given target bond(search internal bond index in the target).

Parameters:
bi - internal target bond index
Returns:
The atom index in the target molecule or -1 if no corresponding atom exists. (e.g. implicit H.)
Since:
JChem 3.2.3

getOrigTargetAtom2

public int getOrigTargetAtom2(int bi)
Returns the index of the second atom (atom index in the target molecule) of the given target bond(search internal bond index in the target).

Parameters:
bi - internal target bond index
Returns:
The atom index in the target molecule or -1 if no corresponding atom exists. (e.g. implicit H.)
Since:
JChem 3.2.3

getOrigQueryBond

public int getOrigQueryBond(int bi)
Returns bond index in the query molecule for the given query bond (search internal bond index in the query).

Parameters:
bi - internal query bond index
Returns:
The bond index in the query molecule or -1 if no corresponding atom exists. (e.g. relating to an implicit H.)
Since:
JChem 3.2.3

getOrigTargetBond

public int getOrigTargetBond(int bi)
Returns bond index in the target molecule for the given target bond (search internal bond index in the target).

Parameters:
bi - internal target bond index
Returns:
The bond index in the target molecule or -1 if no corresponding atom exists. (e.g. relating to an implicit H.)
Since:
JChem 3.2.3