RDKit: FilterMatcherBase.h Source File

| RDKit Open-source cheminformatics and machine learning.

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