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.
//
#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 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),
ALL = PAINS | BRENK | NIH | ZINC
};
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) {}
virtual ~FilterCatalogParams() {}
//------------------------------------
//! 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);
//! serializes (pickles) to a stream
virtual void toStream(std::ostream &ss) const;
//! returns a string with a serialized (pickled) representation
virtual std::string Serialize() const;
//! initializes from a stream pickle
virtual void initFromStream(std::istream &ss);
//! initializes from a string pickle
virtual void initFromString(const std::string &text);
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 FilterCatalog : public FCatalog {
public:
// syntactic sugar for getMatch(es) return values.
typedef boost::shared_ptr<FilterCatalogEntry> SENTRY;
#if BOOST_VERSION / 100000 >= 1 && (BOOST_VERSION / 100 % 1000) > 44
#define BOOST_PYTHON_SUPPORT_SHARED_CONST
#endif
#ifdef BOOST_PYTHON_SUPPORT_SHARED_CONST
// 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;
#else
typedef boost::shared_ptr<entryType_t> CONST_SENTRY;
#endif
FilterCatalog() : FCatalog(), d_entries() {}
FilterCatalog(FilterCatalogParams::FilterCatalogs catalogs)
: FCatalog(), d_entries() {
setCatalogParams(new paramType_t(catalogs));
}
FilterCatalog(const FilterCatalogParams &params) : FCatalog(), d_entries() {
setCatalogParams(new paramType_t(params));
}
FilterCatalog(const FilterCatalog &rhs)
: FCatalog(rhs), d_entries(rhs.d_entries) {}
FilterCatalog(const std::string &binStr);
~FilterCatalog();
virtual std::string Serialize() const;
// 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.
*/
virtual unsigned int addEntry(FilterCatalogEntry *entry,
bool updateFPLength = true);
// 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 indicies 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
virtual const FilterCatalogEntry *getEntryWithIdx(unsigned int idx) const;
//------------------------------------
//! 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
virtual unsigned int getNumEntries() const { return d_entries.size(); }
//------------------------------------
//! Reset the current catalog to match the specified FilterCatalogParameters
/*
\param params The new FilterCatalogParams specifying the new state of the
catalog
*/
virtual void setCatalogParams(FilterCatalogParams *params);
//------------------------------------
//! 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 matches to the molecule
/*
\param mol ROMol to match against the catalog
*/
const std::vector<CONST_SENTRY> getMatches(const ROMol &mol) const;
private:
void Clear();
std::vector<SENTRY> d_entries;
};
bool FilterCatalogCanSerialize();
}
#endif
RDKit::FilterCatalogParams::toStream
virtual void toStream(std::ostream &ss) const
serializes (pickles) to a stream
RDKit::FilterCatalogParams
Definition: FilterCatalog.h:41
RDCatalog::CatalogParams::setTypeStr
void setTypeStr(const std::string &typeStr)
sets our type string
Definition: CatalogParams.h:25
RDCatalog::Catalog::paramType_t
paramType paramType_t
Definition: Catalog.h:42
RDKit::FilterCatalogParams::ALL
Definition: FilterCatalog.h:53
RDKit::FilterCatalog::CONST_SENTRY
boost::shared_ptr< entryType_t > CONST_SENTRY
Definition: FilterCatalog.h:124
RDKit::FilterCatalogParams::BRENK
Definition: FilterCatalog.h:49
RDKit::FilterCatalogParams::getCatalogs
const std::vector< FilterCatalogs > & getCatalogs() const
Returns the existing list of FilterCatalogs to be used.
Definition: FilterCatalog.h:83
RDKit::FilterCatalogParams::initFromString
virtual void initFromString(const std::string &text)
initializes from a string pickle
RDCatalog
Definition: Catalog.h:30
Catalog.h
RDKit::FilterCatalog
Definition: FilterCatalog.h:110
RDKit::FilterCatalogParams::PAINS_B
Definition: FilterCatalog.h:45
RDKit::FilterCatalog::FilterCatalog
FilterCatalog(const FilterCatalog &rhs)
Definition: FilterCatalog.h:138
RDKit::ROMol
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:102
RDKit::FilterCatalogParams::NIH
Definition: FilterCatalog.h:50
RDKit::FCatalog
RDCatalog::Catalog< FilterCatalogEntry, FilterCatalogParams > FCatalog
Definition: FilterCatalog.h:109
RDKit::FilterCatalogParams::fillCatalog
virtual void fillCatalog(FilterCatalog &catalog)
Fill a catalog with the appropriate entries.
RDKit::FilterCatalogParams::ZINC
Definition: FilterCatalog.h:51
RDKit::FilterCatalogParams::addCatalog
virtual bool addCatalog(FilterCatalogs catalogs)
Adds an existing FilterCatalog specification to be used in the.
RDCatalog::Catalog
abstract base class for a catalog object
Definition: Catalog.h:39
RDKit::FilterCatalogParams::PAINS
Definition: FilterCatalog.h:47
RDKit::FilterCatalogParams::FilterCatalogParams
FilterCatalogParams(const FilterCatalogParams &other)
Definition: FilterCatalog.h:65
RDKit
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
RDKit::FilterCatalog::FilterCatalog
FilterCatalog()
Definition: FilterCatalog.h:127
RDUNUSED_PARAM
#define RDUNUSED_PARAM(x)
Definition: Invariant.h:190
RDKit::FilterCatalog::FilterCatalog
FilterCatalog(const FilterCatalogParams &params)
Definition: FilterCatalog.h:134
RDKit::FilterCatalogEntry
Definition: FilterCatalogEntry.h:54
RDKit::FilterCatalog::SENTRY
boost::shared_ptr< FilterCatalogEntry > SENTRY
Definition: FilterCatalog.h:113
FilterCatalogEntry.h
CatalogParams.h
RDKit::FilterCatalogParams::FilterCatalogs
FilterCatalogs
Definition: FilterCatalog.h:43
RDKit::FilterCatalog::getNumEntries
virtual unsigned int getNumEntries() const
returns the number of entries in the catalog
Definition: FilterCatalog.h:200
RDKit::FilterCatalogCanSerialize
bool FilterCatalogCanSerialize()
RDKit::FilterCatalogParams::Serialize
virtual std::string Serialize() const
returns a string with a serialized (pickled) representation
RDKit::FilterCatalogParams::initFromStream
virtual void initFromStream(std::istream &ss)
initializes from a stream pickle
RDKit::FilterCatalogParams::PAINS_A
Definition: FilterCatalog.h:44
RDCatalog::CatalogParams
abstract base class for the container used to create a catalog
Definition: CatalogParams.h:17
RDKit::FilterCatalogParams::FilterCatalogParams
FilterCatalogParams(FilterCatalogs catalogs)
Definition: FilterCatalog.h:60
RDKit::FilterCatalogParams::PAINS_C
Definition: FilterCatalog.h:46
RDKit::FilterCatalogParams::FilterCatalogParams
FilterCatalogParams()
Definition: FilterCatalog.h:56
RDKit::FilterCatalog::FilterCatalog
FilterCatalog(FilterCatalogParams::FilterCatalogs catalogs)
Definition: FilterCatalog.h:129
RDKit::FilterCatalogParams::~FilterCatalogParams
virtual ~FilterCatalogParams()
Definition: FilterCatalog.h:68