RDKit
Open-source cheminformatics and machine learning.
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 #include <RDGeneral/export.h>
33 #ifndef __RD_FILTER_MATCHER_BASE_H__
34 #define __RD_FILTER_MATCHER_BASE_H__
35 #include <GraphMol/RDKitBase.h>
37 
38 #ifdef RDK_USE_BOOST_SERIALIZATION
40 #include <boost/archive/text_oarchive.hpp>
41 #include <boost/archive/text_iarchive.hpp>
42 #include <boost/serialization/assume_abstract.hpp>
43 #include <boost/enable_shared_from_this.hpp>
45 #endif // RDK_USE_BOOST_SERIALIZATION
46 
47 namespace RDKit {
48 
49 class FilterMatcherBase; // Forward declaration
50 
51 //! Holds the atomPairs matched by the underlying matcher
53  boost::shared_ptr<FilterMatcherBase> filterMatch;
55 
56  FilterMatch() : filterMatch(), atomPairs() {}
57  FilterMatch(boost::shared_ptr<FilterMatcherBase> filter,
58  MatchVectType atomPairs)
59  : filterMatch(filter), atomPairs(atomPairs) {}
60 
62  : filterMatch(rhs.filterMatch), atomPairs(rhs.atomPairs) {}
63 
64  bool operator==(const FilterMatch &rhs) const {
65  return (filterMatch.get() == rhs.filterMatch.get() &&
66  atomPairs == rhs.atomPairs);
67  }
68 
69  bool operator!=(const FilterMatch &rhs) const {
70  return !(filterMatch.get() == rhs.filterMatch.get() &&
71  atomPairs == rhs.atomPairs);
72  }
73 };
74 
77  : public boost::enable_shared_from_this<FilterMatcherBase> {
78  //------------------------------------
79  //! Virtual API for filter matching
80  std::string d_filterName;
81 
82  public:
84  : boost::enable_shared_from_this<FilterMatcherBase>(),
85  d_filterName(name) {}
86 
88  : boost::enable_shared_from_this<FilterMatcherBase>(),
89  d_filterName(rhs.d_filterName) {}
90 
91  virtual ~FilterMatcherBase() {}
92 
93  virtual bool isValid() const = 0;
94 
95  virtual std::string getName() const { return d_filterName; }
96  //------------------------------------
97  //! getMatches
98  /*!
99  Match the filter against a molecule
100 
101  \param mol readonly const molecule being searched
102  \param matches output vector of atom index matches found in the molecule
103  */
104 
105  virtual bool getMatches(const ROMol &mol,
106  std::vector<FilterMatch> &matchVect) const = 0;
107 
108  //------------------------------------
109  //! hasMatches
110  /*!
111  Does the given molecule contain this filter pattern
112 
113  \param mol readonly const molecule being searched
114  */
115 
116  virtual bool hasMatch(const ROMol &mol) const = 0;
117 
118  //------------------------------------
119  //! Clone - deprecated
120  // Clones the current FilterMatcherBase into one that
121  // can be passed around safely.
122  virtual boost::shared_ptr<FilterMatcherBase> Clone() const {
124  << "FilterMatcherBase::Clone is deprecated, use copy instead"
125  << std::endl;
126  return copy();
127  }
128 
129  //------------------------------------
130  //! copy
131  // copies the current FilterMatcherBase into one that
132  // can be passed around safely.
133  virtual boost::shared_ptr<FilterMatcherBase> copy() const = 0;
134 
135  private:
136 #ifdef RDK_USE_BOOST_SERIALIZATION
137  friend class boost::serialization::access;
138  template <class Archive>
139  void serialize(Archive &ar, const unsigned int version) {
140  RDUNUSED_PARAM(version);
141  ar &d_filterName;
142  }
143 #endif
144 };
145 
146 #ifdef RDK_USE_BOOST_SERIALIZATION
147 BOOST_SERIALIZATION_ASSUME_ABSTRACT(FilterMatcherBase)
148 #endif
149 } // namespace RDKit
150 #endif
BOOST_LOG
#define BOOST_LOG(__arg__)
Definition: RDLog.h:88
RDKit::FilterMatch::filterMatch
boost::shared_ptr< FilterMatcherBase > filterMatch
Definition: FilterMatcherBase.h:53
RDKit::FilterMatch
Holds the atomPairs matched by the underlying matcher.
Definition: FilterMatcherBase.h:52
RDKit::FilterMatch::FilterMatch
FilterMatch(boost::shared_ptr< FilterMatcherBase > filter, MatchVectType atomPairs)
Definition: FilterMatcherBase.h:57
RDKit::FilterMatch::operator==
bool operator==(const FilterMatch &rhs) const
Definition: FilterMatcherBase.h:64
BoostStartInclude.h
RDKit::FilterMatch::FilterMatch
FilterMatch()
Definition: FilterMatcherBase.h:56
RDKit::FilterMatcherBase::getName
virtual std::string getName() const
Definition: FilterMatcherBase.h:95
boost
Definition: RDLog.h:21
RDKit::FilterMatch::FilterMatch
FilterMatch(const FilterMatch &rhs)
Definition: FilterMatcherBase.h:61
RDKit::DEFAULT_FILTERMATCHERBASE_NAME
const RDKIT_FILTERCATALOG_EXPORT char * DEFAULT_FILTERMATCHERBASE_NAME
RDUNUSED_PARAM
#define RDUNUSED_PARAM(x)
Definition: Invariant.h:196
BoostEndInclude.h
RDKit::FilterMatcherBase::FilterMatcherBase
FilterMatcherBase(const FilterMatcherBase &rhs)
Definition: FilterMatcherBase.h:87
RDKit::ROMol
Definition: ROMol.h:171
RDKit::FilterMatch::atomPairs
MatchVectType atomPairs
Definition: FilterMatcherBase.h:54
RDKit::FilterMatcherBase
Definition: FilterMatcherBase.h:76
RDKitBase.h
pulls in the core RDKit functionality
RDKit::FilterMatcherBase::~FilterMatcherBase
virtual ~FilterMatcherBase()
Definition: FilterMatcherBase.h:91
RDKit
Std stuff.
Definition: Atom.h:30
RDKIT_FILTERCATALOG_EXPORT
#define RDKIT_FILTERCATALOG_EXPORT
Definition: export.h:229
RDKit::FilterMatcherBase::Clone
virtual boost::shared_ptr< FilterMatcherBase > Clone() const
Clone - deprecated.
Definition: FilterMatcherBase.h:122
rdWarningLog
RDKIT_RDGENERAL_EXPORT std::shared_ptr< boost::logging::rdLogger > rdWarningLog
RDKit::FilterMatcherBase::FilterMatcherBase
FilterMatcherBase(const std::string &name=DEFAULT_FILTERMATCHERBASE_NAME)
Definition: FilterMatcherBase.h:83
RDKit::FilterMatch::operator!=
bool operator!=(const FilterMatch &rhs) const
Definition: FilterMatcherBase.h:69
RDKit::MatchVectType
std::vector< std::pair< int, int > > MatchVectType
used to return matches from substructure searching, The format is (queryAtomIdx, molAtomIdx)
Definition: FragFPGenerator.h:24
SubstructMatch.h
export.h