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