OEFPDatabase¶
class OEFPDatabase
The OEFPDatabase class is designed to perform rapid in-memory fingerprint searches. Each OEFPDatabase object is associated with a fingerprint type (OEFPTypeBase) that is specified when the database is constructed. An OEFPDatabase object can only store fingerprints (OEFingerPrint) with this specified type.
See also
OEFastFPDatabase class
Constructors¶
OEFPDatabase(unsigned int fptype)
Creates an OEFPDatabase object that can store OEFingerPrint objects with a given type.
- fptype
The type of the OEFingerPrint object stored in the OEFPDatabase. This value has to be from the
OEFPType
namespace.
OEFPDatabase(const OEGraphSim::OEFPTypeBase *)
Creates an OEFPDatabase object that can store OEFingerPrint objects with OEFPTypeBase type.
Note
By default, an OEFPDatabase object is constructed with:
no cutoff value
Tanimoto
similarity measuredescending order to return scores when calling the
OEFPDatabase::GetSortedScores
method
These default values can be altered by the following methods:
AddFP¶
unsigned int AddFP(const OEChem::OEMolBase &mol)
Generates an OEFingerPrint object from the
OEMolBase molecule with the fingerprint type of
the OEFPDatabase.
The generated OEFingerPrint object is then
inserted into the database returning its index.
This method will return -1
, if the fingerprint generation
was unsuccessful.
unsigned int AddFP(const OEGraphSim::OEFingerPrint &fp)
Creates a copy of the OEFingerPrint object,
inserts it into the database, and then returns its index.
If the type of the passed fingerprint was different from the
type of the database, than the insertion is unsuccessful and
this method will return -1
.
Note
The index returned by the
OEFPDatabase::AddFP
method is a unique
number starting from zero.
This index can be used as a reference number to associate
the fingerprint with the molecule from which is it generated.
ClearCutoff¶
void ClearCutoff()
Removes the cutoff value previously set by the
OEFPDatabase::SetCutoff
method.
After clearing the cutoff value
OEFPDatabase::HasCutoff
method
will return false
.
GetCutoff¶
float GetCutoff() const
Returns the cutoff value previously set by the
OEFPDatabase::SetCutoff
method.
GetDescendingOrder¶
bool GetDescendingOrder() const
Returns the order in which the calculated scores are returned by
the OEFPDatabase::GetSortedScores
method.
See also
GetFPTypeBase¶
const OEGraphSim::OEFPTypeBase *GetFPTypeBase() const
Returns the fingerprint type of the OEFPDatabase object.
GetFingerPrints¶
OESystem::OEIterBase<const OEGraphSim::OEFingerPrint> *GetFingerPrints() const
Returns an iterator pointer over fingerprints (OEFingerPrint) stored in the OEFPDatabase object. The returned OEFingerPrint objects can only be accessed by const methods or functions, i.e., they can not be modified.
GetScores¶
Link |
Description |
---|---|
returns similarities for a molecule |
|
returns similarities for a fingerprint |
|
returns similarities for a molecule with the given options |
|
returns similarities for a fingerprint with the given options |
Similarity calculation:
OESystem::OEIterBase<OEGraphSim::OESimScore> * GetScores(const OEChem::OEMolBase &mol, unsigned int bgn=0, unsigned int end=0) constOESystem::OEIterBase<OEGraphSim::OESimScore> * GetScores(const OEGraphSim::OEFingerPrint &fp, unsigned int bgn=0, unsigned int end=0) constPerforms similarity calculation between a given molecule or a fingerprint and the fingerprints stored in the OEFPDatabase object. It returns an iterator over the calculated similarity scores (OESimScore). Each OESimScore holds a similarity score and index of the corresponding fingerprint of the database.
- mol
If the method is called with an OEMolBase object, then a fingerprint is generated from this molecule before looping over the fingerprints of the database and calculating similarities.
- fp
If the method is called with an OEFingerPrint object, then its type has to match with the type of the OEFPDatabase.
- bgn, end
The
bgn
andend
arguments define the segment of the database on which the similarity calculation will take place. If both of these parameters are omitted (or set to zero), then the similarity calculation is performed on the entire fingerprint database.Note
By default, the
OEFPDatabase::GetScores
methods calculatesTanimoto
similarity scores and will always return these scores in the order in which the corresponding OEFingerPrint objects are added to the database.By using the
OEFPDatabase::SetSimFunc
method, similarity measures other than the default can be performed.The behavior of
OEFPDatabase::GetSortedScores
is also influenced by the cutoff value (OEFPDatabase::SetCutoff
) of the database and the order of the scores specified by theOEFPDatabase::SetSimFunc
method. If a cutoff value was set, then theOEFPDatabase::GetScores
method:
return scores that are equal to or larger than the specified cutoff value if the order is descending
return scores that are equal to or smaller than the specified cutoff value if the order is ascending
See also
OEFPDatabase::SetSimFunc
method
OEFPDatabase::SetCutoff
methodExamples:
Calculates the
Tanimoto
similarity on the first 100 entries of the database and returns scores that are equal to or larger than0.1
.bool descending = true; fpdb.SetSimFunc(OESimMeasure::Tanimoto, descending); fpdb.SetCutoff(0.1f); for (OEIter<const OESimScore> score = fpdb.GetScores(qfp, 0u, 100u); score; ++score) std::cout << score->GetScore() << std::endl;Calculates the
Tversky
similarity (with \(\alpha=0.9\) and \(\beta=0.1\)) on the entire database and returns all scores.fpdb.SetSimFunc(OETverskySim(0.9f)); for (OEIter<const OESimScore> score = fpdb.GetScores(qfp); score; ++score) std::cout << score->GetScore() << std::endl;Calculates the
Dice
similarity beginning at the 100th entry of the database and returns scores that are equal to or smaller than0.5
.descending = true; fpdb.SetSimFunc(OESimMeasure::Dice, !descending); fpdb.SetCutoff(0.5f); for (OEIter<const OESimScore> score = fpdb.GetScores(qfp, 100u); score; ++score) std::cout << score->GetScore() << std::endl;
Similarity calculation with an option class:
Performs similarity calculation between a given molecule or a fingerprint and the fingerprints stored in the OEFPDatabase object. It returns an iterator over the calculated similarity scores (OESimScore). Each OESimScore holds a similarity score and index of the corresponding fingerprint of the database.
- mol
If the method is called with an OEMolBase object, then a fingerprint is generated from this molecule before looping over the fingerprints of the database and calculating similarities.
- fp
If the method is called with an OEFingerPrint object, then its type has to match with the type of the OEFPDatabase.
- opts
The OEFPDatabaseOptions object controls all the parameters that determine the sorted search. For example, similarity measure, score cutoff, descending or ascending order etc.
See also
OEFPDatabaseOptions class
Example:
Calculates the
Cosine
similarity on the entire database and returns scores that are equal to or larger than 0.3.OEFPDatabaseOptions opts; opts.SetCutoff(0.3f); opts.SetSimFunc(OESimMeasure::Cosine); for (OEIter<const OESimScore> score = fpdb.GetScores(qfp, opts); score; ++score) std::cout << score->GetScore() << std::endl;
GetSortedScores¶
Link |
Description |
---|---|
returns sorted similarities for a molecule |
|
returns sorted similarities for a fingerprint |
|
returns sorted similarities for a molecule with the given options |
|
returns similarities for a fingerprint with the given options |
Similarity calculation:
OESystem::OEIterBase<OEGraphSim::OESimScore> * GetSortedScores(const OEChem::OEMolBase &mol, unsigned int limit=0, unsigned int bgn=0, unsigned int end=0) constOESystem::OEIterBase<OEGraphSim::OESimScore> * GetSortedScores(const OEGraphSim::OEFingerPrint &fp, unsigned int limit=0, unsigned int bgn=0, unsigned int end=0) constPerforms similarity calculations between a molecule or a fingerprint and the fingerprints stored in the OEFPDatabase object. It returns an iterator over the calculated similarity scores (OESimScore) in sorted order. Each OESimScore holds a similarity score and index of the corresponding fingerprint of the database.
- mol
If the method is called with an OEMolBase object, then a fingerprint is generated from this molecule before looping over the fingerprints of the database and calculating similarities.
- fp
If the method is called with an OEFingerPrint object, then its type has to match with the type of the OEFPDatabase.
- bgn, end
The
bgn
andend
arguments define the segment of the database on which the similarity calculation will take place. If both of these parameters are omitted (or set to zero), then the similarity calculation is performed on the entire fingerprint database.- limit
The value that defines the number of similarity scores returned by the
OEFPDatabase::GetSortedScores
method. If it is omitted (or set to zero) then all of the similarity scores are returned.Note
By default, the
OEFPDatabase::GetSortedScores
method calculatesTanimoto
similarity scores and returns them in descending order.By using the
OEFPDatabase::SetSimFunc
method, similarity measures other than the default can be performed.The behavior of
OEFPDatabase::GetSortedScores
is also influenced by the cutoff value (OEFPDatabase::SetCutoff
) of the database and the order of the scores specified by theOEFPDatabase::SetSimFunc
method. If a cutoff value was set, then theOEFPDatabase::GetSortedScores
method:
return scores that are equal to or larger than the specified cutoff value if the order is descending
return scores that are equal to or smaller than the specified cutoff value if the order is ascending
See also
OEFPDatabase::SetSimFunc
method
OEFPDatabase::SetCutoff
methodExamples:
Calculates the
Tanimoto
similarity on the entire database and returns the 10 best scores in descending order.for (OEIter<const OESimScore> score = fpdb.GetSortedScores(qfp, 10u); score; ++score) std::cout << score->GetScore() << std::endl;Calculates the
Dice
similarity on the first 100 entries of the database and returns scores that are equal to or larger than0.5
in descending order.descending = true; fpdb.SetSimFunc(OESimMeasure::Dice, descending); fpdb.SetCutoff(0.5); for (OEIter<const OESimScore> score = fpdb.GetSortedScores(qfp, 0u, 0u, 100u); score; ++score) std::cout << score->GetScore() << std::endl;Calculates
Manhattan
similarity beginning at the 100th entry of the database and returns the “worst” 5 scores that are equal to or smaller than0.3
in ascending order.descending = true; fpdb.SetSimFunc(OESimMeasure::Manhattan, !descending); fpdb.SetCutoff(0.3f); for (OEIter<const OESimScore> score = fpdb.GetSortedScores(qfp, 5u, 100u); score; ++score) std::cout << score->GetScore() << std::endl;
Sorted similarity calculation with an option class:
OESystem::OEIterBase<OEGraphSim::OESimScore> * GetSortedScores(const OEChem::OEMolBase &mol, const OEFPDatabaseOption &opts) constOESystem::OEIterBase<OEGraphSim::OESimScore> * GetSortedScores(const OEGraphSim::OEFingerPrint &fp, const OEFPDatabaseOption &opts) constPerforms similarity calculations between a molecule or a fingerprint and the fingerprints stored in the OEFPDatabase object. It returns an iterator over the calculated similarity scores (OESimScore) in sorted order. Each OESimScore holds a similarity score and index of the corresponding fingerprint of the database.
- mol
If the method is called with an OEMolBase object, then a fingerprint is generated from this molecule before looping over the fingerprints of the database and calculating similarities.
- fp
If the method is called with an OEFingerPrint object, then its type has to match with the type of the OEFPDatabase.
- opts
The OEFPDatabaseOptions object controls all the parameters that determine the sorted search. For example, similarity measure, score cutoff, descending or ascending order etc.
See also
OEFPDatabaseOptions class
Example:
Calculates
Tversky
similarity on the entire database and returns the best10
scores that are equal to or larger than0.3
in descending order.OEFPDatabaseOptions opts; opts.SetDescendingOrder(true); opts.SetCutoff(0.3f); opts.SetSimFunc(OESimMeasure::Tversky); opts.SetTverskyCoeffs(0.9f, 0.1f); opts.SetLimit(10); for (OEIter<const OESimScore> score = fpdb.GetSortedScores(qfp, opts); score; ++score) std::cout << score->GetScore() << std::endl;
HasCutoff¶
bool HasCutoff() const
Returns whether the cutoff value of the
OEFPDatabase object has been set by the
OEFPDatabase::SetCutoff
method.
NumFingerPrints¶
unsigned int NumFingerPrints() const
Returns the number of OEFingerPrint objects stored in the database.
SetCutoff¶
void SetCutoff(float)
Sets the cutoff value of the OEFPDatabase object.
The cutoff value influences the behavior of both the
OEFPDatabase::GetScores
and the
OEFPDatabase::GetSortedScores
methods.
SetDescendingOrder¶
void SetDescendingOrder(bool descending)
Sets the order in which the calculated scores are returned by
the OEFPDatabase::GetSortedScores
method.
See also
SetSimFunc¶
Sets the method used to evaluate fingerprint similarity
when calling either the OEFPDatabase::GetScores
or the OEFPDatabase::GetSortedScores
methods.
void SetSimFunc(unsigned int simtype, bool descending=true)
Sets the similarity calculation by specifying a similarity method
with a constant from the OESimMeasure
namespace.
The second argument defines the order in which the calculated
scores are returned by the
OEFPDatabase::GetSortedScores
method.
void SetSimFunc(const OEGraphSim::OESimFuncBase &, bool descending=true)
Creates a copy of the OESimFuncBase object
and uses its OESimFuncBase::operator()
method to evaluate similarity between two OEFingerPrint
objects.
The second argument defines the order in which the calculated
scores are returned by the
OEFPDatabase::GetSortedScores
method.
Note
By default, both the OEFPDatabase::GetScores
and the OEFPDatabase::GetSortedScores
methods calculate Tanimoto
similarity scores.
While the OEFPDatabase::GetScores
always returns these scores in the order in which the corresponding
OEFingerPrint objects are added to the
database, the latter method returns them in descending order,
by default.
See also
User-defined Similarity Measures section
OESimMeasure
namespaceOETanimotoSim class
OETverskySim class