Loading...
Searching...
No Matches
FilterCatalog.h
Go to the documentation of this file.
// Copyright (c) 2015, Novartis Institutes for BioMedical Research Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Novartis Institutes for BioMedical Research Inc.
// nor the names of its contributors may be used to endorse or promote
// products derived from this software without specific prior written
// permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include <RDGeneral/export.h>
#ifndef _RD_FILTER_CATALOG_PARAMS_
#define _RD_FILTER_CATALOG_PARAMS_
#include <Catalogs/Catalog.h>
#include <Catalogs/CatalogParams.h>
#include "FilterCatalogEntry.h"
namespace RDKit {
class FilterCatalog;
class RDKIT_FILTERCATALOG_EXPORT FilterCatalogParams
: public RDCatalog::CatalogParams {
public:
enum FilterCatalogs {
PAINS_A = (1u << 1),
PAINS_B = (1u << 2),
PAINS_C = (1u << 3),
PAINS = PAINS_A | PAINS_B | PAINS_C,
BRENK = (1u << 4),
NIH = (1u << 5),
ZINC = (1u << 6),
CHEMBL_Glaxo = (1u << 7),
CHEMBL_Dundee = (1u << 8),
CHEMBL_BMS = (1u << 9),
CHEMBL_SureChEMBL = (1u << 10),
CHEMBL_MLSMR = (1u << 11),
CHEMBL_Inpharmatica = (1u << 12),
CHEMBL_LINT = (1u << 13),
CHEMBL = CHEMBL_Glaxo | CHEMBL_Dundee | CHEMBL_BMS | CHEMBL_SureChEMBL |
CHEMBL_MLSMR | CHEMBL_Inpharmatica | CHEMBL_LINT,
ALL = PAINS | BRENK | NIH | ZINC | CHEMBL
};
FilterCatalogParams() : RDCatalog::CatalogParams() {
setTypeStr("Filter Catalog Parameters");
}
FilterCatalogParams(FilterCatalogs catalogs) : RDCatalog::CatalogParams() {
setTypeStr("Filter Catalog Parameters");
addCatalog(catalogs);
}
FilterCatalogParams(const FilterCatalogParams &other)
: RDCatalog::CatalogParams(other), d_catalogs(other.d_catalogs) {}
~FilterCatalogParams() override {}
//------------------------------------
//! Adds an existing FilterCatalog specification to be used in the
/// FilterCatalog
//
/*!
Specifies an existing filter catalog to be used.
\param catalogs One of the enumerated known FilterCatalogs
*/
virtual bool addCatalog(FilterCatalogs catalogs);
//------------------------------------
//! Returns the existing list of FilterCatalogs to be used.
const std::vector<FilterCatalogs> &getCatalogs() const { return d_catalogs; }
//! Fill a catalog with the appropriate entries
virtual void fillCatalog(FilterCatalog &catalog) const;
//! serializes (pickles) to a stream
void toStream(std::ostream &ss) const override;
//! returns a string with a serialized (pickled) representation
std::string Serialize() const override;
//! initializes from a stream pickle
void initFromStream(std::istream &ss) override;
//! initializes from a string pickle
void initFromString(const std::string &text) override;
private:
std::vector<FilterCatalogs> d_catalogs;
#ifdef RDK_USE_BOOST_SERIALIZATION
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive &ar, const unsigned int version) {
RDUNUSED_PARAM(version);
ar &d_catalogs;
}
#endif
};
typedef RDCatalog::Catalog<FilterCatalogEntry, FilterCatalogParams> FCatalog;
class RDKIT_FILTERCATALOG_EXPORT FilterCatalog : public FCatalog {
public:
// syntactic sugar for getMatch(es) return values.
typedef boost::shared_ptr<FilterCatalogEntry> SENTRY;
// If boost::python can support shared_ptr of const objects
// we can enable support for this feature
typedef boost::shared_ptr<const entryType_t> CONST_SENTRY;
FilterCatalog() : FCatalog(), d_entries() {}
FilterCatalog(FilterCatalogParams::FilterCatalogs catalogs)
: FCatalog(), d_entries() {
paramType_t temp_params(catalogs);
setCatalogParams(&temp_params);
}
FilterCatalog(const FilterCatalogParams &params) : FCatalog(), d_entries() {
setCatalogParams(&params);
}
FilterCatalog(const FilterCatalog &rhs)
: FCatalog(rhs), d_entries(rhs.d_entries) {}
FilterCatalog(const std::string &binStr);
~FilterCatalog() override;
std::string Serialize() const override;
// Adds a new FilterCatalogEntry to the catalog
/*!
Adds a new FilterCatalogEntry to the catalog The catalog
owns the entry
\param entry The FilterCatalogEntry to add.
\param updateFPLength unused in the FilterCatalog object.
*/
unsigned int addEntry(FilterCatalogEntry *entry,
bool updateFPLength = true) override;
// Adds a new FilterCatalogEntry to the catalog
/*!
Adds a new FilterCatalogEntry to the catalog The catalog
owns the entry
\param entry The shared_ptr of the FilterCatalogEntry to add.
\param updateFPLength unused in the FilterCatalog object.
*/
virtual unsigned int addEntry(SENTRY entry, bool updateFPLength = true);
// Removes a FilterCatalogEntry to the catalog by description
/*!
Removes a FilterCatalogEntry from the catalog.
\param idx The FilterCatalogEntry index for the entry to remove.
n.b. removing an entry may change the indices of other entries.
To safely remove entries, remove entries with the highest idx
first.
*/
bool removeEntry(unsigned int idx);
bool removeEntry(CONST_SENTRY entry);
//------------------------------------
//! returns a particular FilterCatalogEntry in the Catalog
//! required by Catalog.h API
const FilterCatalogEntry *getEntryWithIdx(unsigned int idx) const override;
//------------------------------------
//! returns a particular FilterCatalogEntry in the Catalog
//! memory safe version of getEntryWithIdx
CONST_SENTRY getEntry(unsigned int idx) const;
//------------------------------------
//! returns the idx of the given entry, UINT_MAX if not found.
unsigned int getIdxForEntry(const FilterCatalogEntry *entry) const;
unsigned int getIdxForEntry(CONST_SENTRY entry) const;
//------------------------------------
//! returns the number of entries in the catalog
unsigned int getNumEntries() const override {
return static_cast<unsigned int>(d_entries.size());
}
//------------------------------------
//! Reset the current catalog to match the specified FilterCatalogParameters
/*
\param params The new FilterCatalogParams specifying the new state of the
catalog
*/
void setCatalogParams(const FilterCatalogParams *params) override;
//------------------------------------
//! Returns true if the molecule matches any entry in the catalog
/*
\param mol ROMol to match against the catalog
*/
bool hasMatch(const ROMol &mol) const;
//------------------------------------
//! Returns the first match against the catalog
/*
\param mol ROMol to match against the catalog
*/
CONST_SENTRY getFirstMatch(const ROMol &mol) const;
//-------------------------------------------
//! Returns all entry matches to the molecule
/*
\param mol ROMol to match against the catalog
*/
const std::vector<CONST_SENTRY> getMatches(const ROMol &mol) const;
//--------------------------------------------
//! Returns all FilterMatches for the molecule
/*
\param mol ROMol to match against the catalog
*/
const std::vector<FilterMatch> getFilterMatches(const ROMol &mol) const;
private:
void Clear();
std::vector<SENTRY> d_entries;
};
RDKIT_FILTERCATALOG_EXPORT bool FilterCatalogCanSerialize();
//! Run a filter catalog on a set of smiles strings
/*
\param smiles vector of smiles strings to analyze
\param nthreads specify the number of threads to use or specify 0 to use all
processors [default 1]
\returns a vector of vectors. For each input smiles string, returns
a vector of shared_ptr::FilterMatchEntry objects.
If a molecule matches no filters, the vector will be empty.
If a smiles can't be parsed, a 'no valid RDKit molecule'
catalog entry is returned.
*/
RDKIT_FILTERCATALOG_EXPORT
std::vector<std::vector<boost::shared_ptr<const FilterCatalogEntry>>>
RunFilterCatalog(const FilterCatalog &filterCatalog,
const std::vector<std::string> &smiles, int numThreads = 1);
} // namespace RDKit
#endif
CatalogParams.h
Catalog.h
FilterCatalogEntry.h
RDUNUSED_PARAM
#define RDUNUSED_PARAM(x)
Definition Invariant.h:196
RDCatalog::CatalogParams
abstract base class for the container used to create a catalog
Definition CatalogParams.h:18
RDCatalog::Catalog
abstract base class for a catalog object
Definition Catalog.h:40
RDCatalog::Catalog::paramType_t
paramType paramType_t
Definition Catalog.h:43
RDKit::FilterCatalogEntry
Definition FilterCatalogEntry.h:57
RDKit::FilterCatalogParams
Definition FilterCatalog.h:43
RDKit::FilterCatalogParams::toStream
void toStream(std::ostream &ss) const override
serializes (pickles) to a stream
RDKit::FilterCatalogParams::FilterCatalogParams
FilterCatalogParams(const FilterCatalogParams &other)
Definition FilterCatalog.h:77
RDKit::FilterCatalogParams::initFromStream
void initFromStream(std::istream &ss) override
initializes from a stream pickle
RDKit::FilterCatalogParams::Serialize
std::string Serialize() const override
returns a string with a serialized (pickled) representation
RDKit::FilterCatalogParams::fillCatalog
virtual void fillCatalog(FilterCatalog &catalog) const
Fill a catalog with the appropriate entries.
RDKit::FilterCatalogParams::FilterCatalogs
FilterCatalogs
Definition FilterCatalog.h:45
RDKit::FilterCatalogParams::initFromString
void initFromString(const std::string &text) override
initializes from a string pickle
RDKit::FilterCatalogParams::FilterCatalogParams
FilterCatalogParams()
Definition FilterCatalog.h:68
RDKit::FilterCatalogParams::getCatalogs
const std::vector< FilterCatalogs > & getCatalogs() const
Returns the existing list of FilterCatalogs to be used.
Definition FilterCatalog.h:95
RDKit::FilterCatalogParams::addCatalog
virtual bool addCatalog(FilterCatalogs catalogs)
RDKit::FilterCatalogParams::FilterCatalogParams
FilterCatalogParams(FilterCatalogs catalogs)
Definition FilterCatalog.h:72
RDKit::FilterCatalogParams::~FilterCatalogParams
~FilterCatalogParams() override
Definition FilterCatalog.h:80
RDKit::FilterCatalog
Definition FilterCatalog.h:122
RDKit::FilterCatalog::FilterCatalog
FilterCatalog(FilterCatalogParams::FilterCatalogs catalogs)
Definition FilterCatalog.h:133
RDKit::FilterCatalog::getMatches
const std::vector< CONST_SENTRY > getMatches(const ROMol &mol) const
Returns all entry matches to the molecule.
RDKit::FilterCatalog::getNumEntries
unsigned int getNumEntries() const override
returns the number of entries in the catalog
Definition FilterCatalog.h:205
RDKit::FilterCatalog::removeEntry
bool removeEntry(CONST_SENTRY entry)
RDKit::FilterCatalog::addEntry
unsigned int addEntry(FilterCatalogEntry *entry, bool updateFPLength=true) override
RDKit::FilterCatalog::CONST_SENTRY
boost::shared_ptr< const entryType_t > CONST_SENTRY
Definition FilterCatalog.h:129
RDKit::FilterCatalog::~FilterCatalog
~FilterCatalog() override
RDKit::FilterCatalog::getEntry
CONST_SENTRY getEntry(unsigned int idx) const
RDKit::FilterCatalog::FilterCatalog
FilterCatalog(const FilterCatalogParams &params)
Definition FilterCatalog.h:139
RDKit::FilterCatalog::getEntryWithIdx
const FilterCatalogEntry * getEntryWithIdx(unsigned int idx) const override
RDKit::FilterCatalog::getIdxForEntry
unsigned int getIdxForEntry(const FilterCatalogEntry *entry) const
returns the idx of the given entry, UINT_MAX if not found.
RDKit::FilterCatalog::getFilterMatches
const std::vector< FilterMatch > getFilterMatches(const ROMol &mol) const
Returns all FilterMatches for the molecule.
RDKit::FilterCatalog::removeEntry
bool removeEntry(unsigned int idx)
RDKit::FilterCatalog::getIdxForEntry
unsigned int getIdxForEntry(CONST_SENTRY entry) const
RDKit::FilterCatalog::FilterCatalog
FilterCatalog(const FilterCatalog &rhs)
Definition FilterCatalog.h:143
RDKit::FilterCatalog::hasMatch
bool hasMatch(const ROMol &mol) const
Returns true if the molecule matches any entry in the catalog.
RDKit::FilterCatalog::setCatalogParams
void setCatalogParams(const FilterCatalogParams *params) override
Reset the current catalog to match the specified FilterCatalogParameters.
RDKit::FilterCatalog::FilterCatalog
FilterCatalog()
Definition FilterCatalog.h:131
RDKit::FilterCatalog::addEntry
virtual unsigned int addEntry(SENTRY entry, bool updateFPLength=true)
RDKit::FilterCatalog::FilterCatalog
FilterCatalog(const std::string &binStr)
RDKit::FilterCatalog::Serialize
std::string Serialize() const override
return a serialized form of the Catalog as an std::string
RDKit::FilterCatalog::SENTRY
boost::shared_ptr< FilterCatalogEntry > SENTRY
Definition FilterCatalog.h:125
RDKit::FilterCatalog::getFirstMatch
CONST_SENTRY getFirstMatch(const ROMol &mol) const
Returns the first match against the catalog.
RDKit::ROMol
Definition ROMol.h:199
export.h
RDKIT_FILTERCATALOG_EXPORT
#define RDKIT_FILTERCATALOG_EXPORT
Definition export.h:169
RDCatalog
Definition Catalog.h:31
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::FCatalog
RDCatalog::Catalog< FilterCatalogEntry, FilterCatalogParams > FCatalog
Definition FilterCatalog.h:121
RDKit::rdvalue_is
bool rdvalue_is(const RDValue_cast_t)
Definition RDValue-doublemagic.h:372
RDKit::RunFilterCatalog
RDKIT_FILTERCATALOG_EXPORT std::vector< std::vector< boost::shared_ptr< const FilterCatalogEntry > > > RunFilterCatalog(const FilterCatalog &filterCatalog, const std::vector< std::string > &smiles, int numThreads=1)
Run a filter catalog on a set of smiles strings.
RDKit::FilterCatalogCanSerialize
RDKIT_FILTERCATALOG_EXPORT bool FilterCatalogCanSerialize()