RDKit: FilterCatalog.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

FilterCatalog.h
Go to the documentation of this file.
1 // Copyright (c) 2015, Novartis Institutes for BioMedical Research Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following
12 // disclaimer in the documentation and/or other materials provided
13 // with the distribution.
14 // * Neither the name of Novartis Institutes for BioMedical Research Inc.
15 // nor the names of its contributors may be used to endorse or promote
16 // products derived from this software without specific prior written
17 // permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 //
31
32 #ifndef _RD_FILTER_CATALOG_PARAMS_
33 #define _RD_FILTER_CATALOG_PARAMS_
34
35 #include <Catalogs/Catalog.h>
36 #include <Catalogs/CatalogParams.h>
37 #include "FilterCatalogEntry.h"
38
39 namespace RDKit {
40 class FilterCatalog;
41 class FilterCatalogParams : public RDCatalog::CatalogParams {
42 public:
43 enum FilterCatalogs {
44 PAINS_A = (1u << 1),
45 PAINS_B = (1u << 2),
46 PAINS_C = (1u << 3),
47 PAINS = PAINS_A | PAINS_B | PAINS_C,
48
49 BRENK = (1u << 4),
50 NIH = (1u << 5),
51 ZINC = (1u << 6),
52
53 ALL = PAINS | BRENK | NIH | ZINC
54 };
55
56 FilterCatalogParams() : RDCatalog::CatalogParams() {
57 setTypeStr("Filter Catalog Parameters");
58 }
59
60 FilterCatalogParams(FilterCatalogs catalogs) : RDCatalog::CatalogParams() {
61 setTypeStr("Filter Catalog Parameters");
62 addCatalog(catalogs);
63 }
64
65 FilterCatalogParams(const FilterCatalogParams &other)
66 : RDCatalog::CatalogParams(other), d_catalogs(other.d_catalogs) {}
67
68 virtual ~FilterCatalogParams() {}
69
70 //------------------------------------
71 //! Adds an existing FilterCatalog specification to be used in the
72 // FilterCatalog
73 //
74 /*!
75 Specifies an existing filter catalog to be used.
76
77 \param catalogs One of the enumerated known FilterCatalogs
78 */
79 virtual bool addCatalog(FilterCatalogs catalogs);
80
81 //------------------------------------
82 //! Returns the existing list of FilterCatalogs to be used.
83 const std::vector<FilterCatalogs> &getCatalogs() const { return d_catalogs; }
84 //! Fill a catalog with the appropriate entries
85 virtual void fillCatalog(FilterCatalog &catalog);
86
87 //! serializes (pickles) to a stream
88 virtual void toStream(std::ostream &ss) const;
89 //! returns a string with a serialized (pickled) representation
90 virtual std::string Serialize() const;
91 //! initializes from a stream pickle
92 virtual void initFromStream(std::istream &ss);
93 //! initializes from a string pickle
94 virtual void initFromString(const std::string &text);
95
96 private:
97 std::vector<FilterCatalogs> d_catalogs;
98
99 #ifdef RDK_USE_BOOST_SERIALIZATION
100 friend class boost::serialization::access;
101 template <class Archive>
102 void serialize(Archive &ar, const unsigned int version) {
103 RDUNUSED_PARAM(version);
104 ar &d_catalogs;
105 }
106 #endif
107 };
108
109 typedef RDCatalog::Catalog<FilterCatalogEntry, FilterCatalogParams> FCatalog;
110 class FilterCatalog : public FCatalog {
111 public:
112 // syntactic sugar for getMatch(es) return values.
113 typedef boost::shared_ptr<FilterCatalogEntry> SENTRY;
114
115 #if BOOST_VERSION / 100000 >= 1 && (BOOST_VERSION / 100 % 1000) > 44
116 #define BOOST_PYTHON_SUPPORT_SHARED_CONST
117 #endif
118
119 #ifdef BOOST_PYTHON_SUPPORT_SHARED_CONST
120 // If boost::python can support shared_ptr of const objects
121 // we can enable support for this feature
122 typedef boost::shared_ptr<const entryType_t> CONST_SENTRY;
123 #else
124 typedef boost::shared_ptr<entryType_t> CONST_SENTRY;
125 #endif
126
127 FilterCatalog() : FCatalog(), d_entries() {}
128
129 FilterCatalog(FilterCatalogParams::FilterCatalogs catalogs)
130 : FCatalog(), d_entries() {
131 setCatalogParams(new paramType_t(catalogs));
132 }
133
134 FilterCatalog(const FilterCatalogParams &params) : FCatalog(), d_entries() {
135 setCatalogParams(new paramType_t(params));
136 }
137
138 FilterCatalog(const FilterCatalog &rhs)
139 : FCatalog(rhs), d_entries(rhs.d_entries) {}
140
141 FilterCatalog(const std::string &binStr);
142
143 ~FilterCatalog();
144
145 virtual std::string Serialize() const;
146
147 // Adds a new FilterCatalogEntry to the catalog
148 /*!
149 Adds a new FilterCatalogEntry to the catalog The catalog
150 owns the entry
151
152 \param entry The FilterCatalogEntry to add.
153 \param updateFPLength unused in the FilterCatalog object.
154 */
155
156 virtual unsigned int addEntry(FilterCatalogEntry *entry,
157 bool updateFPLength = true);
158
159 // Adds a new FilterCatalogEntry to the catalog
160 /*!
161 Adds a new FilterCatalogEntry to the catalog The catalog
162 owns the entry
163
164 \param entry The shared_ptr of the FilterCatalogEntry to add.
165 \param updateFPLength unused in the FilterCatalog object.
166 */
167
168 virtual unsigned int addEntry(SENTRY entry, bool updateFPLength = true);
169
170 // Removes a FilterCatalogEntry to the catalog by description
171 /*!
172 Removes a FilterCatalogEntry from the catalog.
173
174 \param idx The FilterCatalogEntry index for the entry to remove.
175 n.b. removing an entry may change the indicies of other entries.
176 To safely remove entries, remove entries with the highest idx
177 first.
178 */
179 bool removeEntry(unsigned int idx);
180 bool removeEntry(CONST_SENTRY entry);
181
182 //------------------------------------
183 //! returns a particular FilterCatalogEntry in the Catalog
184 //! required by Catalog.h API
185 virtual const FilterCatalogEntry *getEntryWithIdx(unsigned int idx) const;
186
187 //------------------------------------
188 //! returns a particular FilterCatalogEntry in the Catalog
189 //! memory safe version of getEntryWithIdx
190 CONST_SENTRY getEntry(unsigned int idx) const;
191
192 //------------------------------------
193 //! returns the idx of the given entry, UINT_MAX if not found.
194
195 unsigned int getIdxForEntry(const FilterCatalogEntry *entry) const;
196 unsigned int getIdxForEntry(CONST_SENTRY entry) const;
197
198 //------------------------------------
199 //! returns the number of entries in the catalog
200 virtual unsigned int getNumEntries() const { return d_entries.size(); }
201
202 //------------------------------------
203 //! Reset the current catalog to match the specified FilterCatalogParameters
204 /*
205 \param params The new FilterCatalogParams specifying the new state of the
206 catalog
207 */
208 virtual void setCatalogParams(FilterCatalogParams *params);
209
210 //------------------------------------
211 //! Returns true if the molecule matches any entry in the catalog
212 /*
213 \param mol ROMol to match against the catalog
214 */
215 bool hasMatch(const ROMol &mol) const;
216
217 //------------------------------------
218 //! Returns the first match against the catalog
219 /*
220 \param mol ROMol to match against the catalog
221 */
222 CONST_SENTRY getFirstMatch(const ROMol &mol) const;
223
224 //------------------------------------
225 //! Returns all matches to the molecule
226 /*
227 \param mol ROMol to match against the catalog
228 */
229 const std::vector<CONST_SENTRY> getMatches(const ROMol &mol) const;
230
231 private:
232 void Clear();
233 std::vector<SENTRY> d_entries;
234 };
235
236 bool FilterCatalogCanSerialize();
237 }
238
239 #endif
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::addEntry
virtual unsigned int addEntry(FilterCatalogEntry *entry, bool updateFPLength=true)
RDKit::FilterCatalog::CONST_SENTRY
boost::shared_ptr< entryType_t > CONST_SENTRY
Definition: FilterCatalog.h:124
RDKit::FilterCatalogParams::BRENK
Definition: FilterCatalog.h:49
RDKit::FilterCatalog::getNumEntries
virtual unsigned int getNumEntries() const
returns the number of entries in the catalog
Definition: FilterCatalog.h:200
RDKit::FilterCatalog::removeEntry
bool removeEntry(unsigned int idx)
RDKit::FilterCatalog::getMatches
const std::vector< CONST_SENTRY > getMatches(const ROMol &mol) const
Returns all matches to the molecule.
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::FilterCatalog::getEntry
CONST_SENTRY getEntry(unsigned int idx) const
RDKit::FilterCatalog::Serialize
virtual std::string Serialize() const
return a serialized form of the Catalog as an std::string
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::FilterCatalog::setCatalogParams
virtual void setCatalogParams(FilterCatalogParams *params)
Reset the current catalog to match the specified FilterCatalogParameters.
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::FilterCatalogParams::toStream
virtual void toStream(std::ostream &ss) const
serializes (pickles) to a stream
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::getFirstMatch
CONST_SENTRY getFirstMatch(const ROMol &mol) const
Returns the first match against the catalog.
RDKit::FilterCatalog::SENTRY
boost::shared_ptr< FilterCatalogEntry > SENTRY
Definition: FilterCatalog.h:113
RDKit::FilterCatalog::getEntryWithIdx
virtual const FilterCatalogEntry * getEntryWithIdx(unsigned int idx) const
RDKit::FilterCatalogParams::Serialize
virtual std::string Serialize() const
returns a string with a serialized (pickled) representation
FilterCatalogEntry.h
RDKit::FilterCatalog::~FilterCatalog
~FilterCatalog()
RDKit::FilterCatalog::getIdxForEntry
unsigned int getIdxForEntry(const FilterCatalogEntry *entry) const
returns the idx of the given entry, UINT_MAX if not found.
CatalogParams.h
RDKit::FilterCatalogParams::FilterCatalogs
FilterCatalogs
Definition: FilterCatalog.h:43
RDKit::FilterCatalog::hasMatch
bool hasMatch(const ROMol &mol) const
Returns true if the molecule matches any entry in the catalog.
RDKit::FilterCatalogCanSerialize
bool FilterCatalogCanSerialize()
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