RDKit: FilterMatcherBase.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

FilterMatcherBase.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_MATCHER_BASE_H__
33 #define __RD_FILTER_MATCHER_BASE_H__
34 #include <GraphMol/RDKitBase.h>
35 #include <GraphMol/Substruct/SubstructMatch.h>
36
37 #ifdef RDK_USE_BOOST_SERIALIZATION
38 #include <RDGeneral/BoostStartInclude.h>
39 #include <boost/archive/text_oarchive.hpp>
40 #include <boost/archive/text_iarchive.hpp>
41 #include <boost/serialization/assume_abstract.hpp>
42 #include <boost/enable_shared_from_this.hpp>
43 #include <RDGeneral/BoostEndInclude.h>
44 #endif // RDK_USE_BOOST_SERIALIZATION
45
46 namespace RDKit {
47
48 class FilterMatcherBase; // Forward declaration
49
50 //! Holds the atomPairs matched by the underlying matcher
51 struct FilterMatch {
52 boost::shared_ptr<FilterMatcherBase> filterMatch;
53 MatchVectType atomPairs;
54
55 FilterMatch(boost::shared_ptr<FilterMatcherBase> filter,
56 MatchVectType atomPairs)
57 : filterMatch(filter), atomPairs(atomPairs) {}
58
59 FilterMatch(const FilterMatch &rhs)
60 : filterMatch(rhs.filterMatch), atomPairs(rhs.atomPairs) {}
61
62 bool operator==(const FilterMatch &rhs) {
63 return (filterMatch.get() == rhs.filterMatch.get() &&
64 atomPairs == rhs.atomPairs);
65 }
66 };
67
68 extern const char *DEFAULT_FILTERMATCHERBASE_NAME;
69 class FilterMatcherBase
70 : public boost::enable_shared_from_this<FilterMatcherBase> {
71 //------------------------------------
72 //! Virtual API for filter matching
73 std::string d_filterName;
74
75 public:
76 FilterMatcherBase(const std::string &name = DEFAULT_FILTERMATCHERBASE_NAME)
77 : boost::enable_shared_from_this<FilterMatcherBase>(),
78 d_filterName(name) {}
79
80 FilterMatcherBase(const FilterMatcherBase &rhs)
81 : boost::enable_shared_from_this<FilterMatcherBase>(),
82 d_filterName(rhs.d_filterName) {}
83
84 virtual ~FilterMatcherBase() {}
85
86 virtual bool isValid() const = 0;
87
88 virtual std::string getName() const { return d_filterName; }
89 //------------------------------------
90 //! getMatches
91 /*!
92 Match the filter against a molecule
93
94 \param mol readonly const molecule being searched
95 \param matches output vector of atom index matches found in the molecule
96 */
97
98 virtual bool getMatches(const ROMol &mol,
99 std::vector<FilterMatch> &matchVect) const = 0;
100
101 //------------------------------------
102 //! hasMatches
103 /*!
104 Does the given molecule contain this filter pattern
105
106 \param mol readonly const molecule being searched
107 */
108
109 virtual bool hasMatch(const ROMol &mol) const = 0;
110
111 //------------------------------------
112 //! Clone
113 // Clones the current FilterMatcherBase into one that
114 // can be passed around safely.
115 virtual boost::shared_ptr<FilterMatcherBase> Clone() const = 0;
116
117 private:
118 #ifdef RDK_USE_BOOST_SERIALIZATION
119 friend class boost::serialization::access;
120 template <class Archive>
121 void serialize(Archive &ar, const unsigned int version) {
122 RDUNUSED_PARAM(version);
123 ar &d_filterName;
124 }
125 #endif
126 };
127
128 #ifdef RDK_USE_BOOST_SERIALIZATION
129 BOOST_SERIALIZATION_ASSUME_ABSTRACT(FilterMatcherBase)
130 #endif
131 }
132 #endif
RDKit::FilterMatcherBase::getName
virtual std::string getName() const
Definition: FilterMatcherBase.h:88
RDKit::FilterMatcherBase::isValid
virtual bool isValid() const =0
BoostStartInclude.h
boost
Definition: RDLog.h:18
RDKit::DEFAULT_FILTERMATCHERBASE_NAME
const char * DEFAULT_FILTERMATCHERBASE_NAME
RDKit::FilterMatcherBase::FilterMatcherBase
FilterMatcherBase(const std::string &name=DEFAULT_FILTERMATCHERBASE_NAME)
Definition: FilterMatcherBase.h:76
RDKit::MatchVectType
std::vector< std::pair< int, int > > MatchVectType
used to return matches from substructure searching, The format is (queryAtomIdx, molAtomIdx) ...
Definition: FragFPGenerator.h:23
RDKit::FilterMatch
Holds the atomPairs matched by the underlying matcher.
Definition: FilterMatcherBase.h:51
RDKit::FilterMatch::filterMatch
boost::shared_ptr< FilterMatcherBase > filterMatch
Definition: FilterMatcherBase.h:52
RDKit::FilterMatch::operator==
bool operator==(const FilterMatch &rhs)
Definition: FilterMatcherBase.h:62
SubstructMatch.h
RDKitBase.h
pulls in the core RDKit functionality
RDKit::ROMol
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:102
RDKit::FilterMatch::atomPairs
MatchVectType atomPairs
Definition: FilterMatcherBase.h:53
RDKit::FilterMatcherBase
Definition: FilterMatcherBase.h:69
BoostEndInclude.h
RDKit::FilterMatch::FilterMatch
FilterMatch(const FilterMatch &rhs)
Definition: FilterMatcherBase.h:59
RDKit::FilterMatcherBase::FilterMatcherBase
FilterMatcherBase(const FilterMatcherBase &rhs)
Definition: FilterMatcherBase.h:80
RDKit::FilterMatcherBase::Clone
virtual boost::shared_ptr< FilterMatcherBase > Clone() const =0
Clone.
RDKit::FilterMatch::FilterMatch
FilterMatch(boost::shared_ptr< FilterMatcherBase > filter, MatchVectType atomPairs)
Definition: FilterMatcherBase.h:55
RDKit
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
RDUNUSED_PARAM
#define RDUNUSED_PARAM(x)
Definition: Invariant.h:190
RDKit::FilterMatcherBase::hasMatch
virtual bool hasMatch(const ROMol &mol) const =0
hasMatches
RDKit::FilterMatcherBase::getMatches
virtual bool getMatches(const ROMol &mol, std::vector< FilterMatch > &matchVect) const =0
getMatches
RDKit::FilterMatcherBase::~FilterMatcherBase
virtual ~FilterMatcherBase()
Definition: FilterMatcherBase.h:84