32 #ifndef __RD_FILTER_MATCHER_H__ 33 #define __RD_FILTER_MATCHER_H__ 42 std::string getArgName(
const boost::shared_ptr<FilterMatcherBase> &arg) {
43 if (arg.get())
return arg->getName();
44 return "<nullmatcher>";
48 namespace FilterMatchOps {
50 boost::shared_ptr<FilterMatcherBase> arg1;
51 boost::shared_ptr<FilterMatcherBase> arg2;
63 And(
const boost::shared_ptr<FilterMatcherBase> &arg1,
64 const boost::shared_ptr<FilterMatcherBase> &arg2)
72 getArgName(arg2) +
")";
76 return arg1.get() && arg2.get() && arg1->isValid() && arg2->isValid();
81 "FilterMatchOps::And is not valid, null arg1 or arg2");
82 return arg1->hasMatch(mol) && arg2->hasMatch(mol);
87 "FilterMatchOps::And is not valid, null arg1 or arg2");
88 std::vector<FilterMatch> matches;
89 if (arg1->getMatches(mol, matches) && arg2->getMatches(mol, matches)) {
96 boost::shared_ptr<FilterMatcherBase>
copy()
const {
97 return boost::shared_ptr<FilterMatcherBase>(
new And(*
this));
101 #ifdef RDK_USE_BOOST_SERIALIZATION 102 friend class boost::serialization::access;
103 template <
class Archive>
104 void serialize(Archive &ar,
const unsigned int version) {
106 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
115 boost::shared_ptr<FilterMatcherBase> arg1;
116 boost::shared_ptr<FilterMatcherBase> arg2;
127 Or(
const boost::shared_ptr<FilterMatcherBase> &arg1,
128 const boost::shared_ptr<FilterMatcherBase> &arg2)
135 getArgName(arg2) +
")";
139 return arg1.get() && arg2.get() && arg1->isValid() && arg2->isValid();
144 return arg1->hasMatch(mol) || arg2->hasMatch(mol);
149 "FilterMatchOps::Or is not valid, null arg1 or arg2");
152 bool res1 = arg1->getMatches(mol, matchVect);
153 bool res2 = arg2->getMatches(mol, matchVect);
157 boost::shared_ptr<FilterMatcherBase>
copy()
const {
158 return boost::shared_ptr<FilterMatcherBase>(
new Or(*
this));
161 #ifdef RDK_USE_BOOST_SERIALIZATION 162 friend class boost::serialization::access;
163 template <
class Archive>
164 void serialize(Archive &ar,
const unsigned int version) {
166 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
174 boost::shared_ptr<FilterMatcherBase> arg1;
187 Not(
const boost::shared_ptr<FilterMatcherBase> &arg1)
196 bool isValid()
const {
return arg1.get() && arg1->isValid(); }
200 return !arg1->hasMatch(mol);
207 std::vector<FilterMatch> matchVect;
208 return !arg1->getMatches(mol, matchVect);
211 boost::shared_ptr<FilterMatcherBase>
copy()
const {
212 return boost::shared_ptr<FilterMatcherBase>(
new Not(*
this));
216 #ifdef RDK_USE_BOOST_SERIALIZATION 217 friend class boost::serialization::access;
218 template <
class Archive>
219 void serialize(Archive &ar,
const unsigned int version) {
221 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
231 unsigned int d_min_count;
232 unsigned int d_max_count;
240 d_max_count(UINT_MAX) {}
253 unsigned int maxCount = UINT_MAX);
268 unsigned int minCount = 1,
unsigned int maxCount = UINT_MAX);
281 SmartsMatcher(
const std::string &name,
const std::string &smarts,
282 unsigned int minCount = 1,
unsigned int maxCount = UINT_MAX);
296 unsigned int minCount = 1,
unsigned int maxCount = UINT_MAX);
301 bool isValid()
const {
return d_pattern.get(); }
306 void setPattern(
const std::string &smarts);
308 void setPattern(
const ROMol &mol);
322 std::vector<FilterMatch> &matchVect)
const;
324 virtual boost::shared_ptr<FilterMatcherBase>
copy()
const {
325 return boost::shared_ptr<FilterMatcherBase>(
new SmartsMatcher(*
this));
329 #ifdef RDK_USE_BOOST_SERIALIZATION 330 friend class boost::serialization::access;
331 template <
class Archive>
332 void save(Archive &ar,
const unsigned int version)
const {
334 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
341 template <
class Archive>
342 void load(Archive &ar,
const unsigned int version) {
343 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
348 d_pattern = boost::shared_ptr<ROMol>(
new ROMol(res));
353 BOOST_SERIALIZATION_SPLIT_MEMBER();
371 std::vector<boost::shared_ptr<FilterMatcherBase> > d_offPatterns;
385 const std::vector<boost::shared_ptr<FilterMatcherBase> > &offPatterns)
391 for (
size_t i = 0; i < d_offPatterns.size(); ++i) {
392 res +=
" " + d_offPatterns[i]->getName();
399 for (
size_t i = 0; i < d_offPatterns.size(); ++i)
400 if (!d_offPatterns[i]->
isValid())
return false;
406 d_offPatterns.push_back(base.
copy());
410 const std::vector<boost::shared_ptr<FilterMatcherBase> > &offPatterns) {
411 d_offPatterns = offPatterns;
416 "ExclusionList: one of the exclusion pattens is invalid");
418 for (
size_t i = 0; i < d_offPatterns.size() && result; ++i) {
419 result &= !d_offPatterns[i]->hasMatch(mol);
427 "ExclusionList: one of the exclusion pattens is invalid");
429 for (
size_t i = 0; i < d_offPatterns.size() && result; ++i) {
430 result &= !d_offPatterns[i]->hasMatch(mol);
436 virtual boost::shared_ptr<FilterMatcherBase>
copy()
const {
437 return boost::shared_ptr<FilterMatcherBase>(
new ExclusionList(*
this));
441 #ifdef RDK_USE_BOOST_SERIALIZATION 442 friend class boost::serialization::access;
443 template <
class Archive>
444 void serialize(Archive &ar,
const unsigned int version) {
446 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
453 std::vector<boost::shared_ptr<FilterHierarchyMatcher> > d_children;
454 boost::shared_ptr<FilterMatcherBase> d_matcher;
472 d_matcher(matcher.
copy()) {
477 if (d_matcher.get()) {
478 return d_matcher->getName();
480 return "FilterMatcherHierarchy root";
485 return d_matcher->isValid();
494 d_matcher = matcher.
copy();
504 boost::shared_ptr<FilterHierarchyMatcher>
addChild(
506 PRECONDITION(hierarchy.d_matcher.get() && hierarchy.d_matcher->isValid(),
507 "Only one root node is allowed in a FilterHierarchyMatcher");
509 d_children.push_back( boost::shared_ptr<FilterHierarchyMatcher>(
511 return d_children.back();
519 virtual bool getMatches(
const ROMol &mol, std::vector<FilterMatch> &matches)
const;
526 std::vector<FilterMatch> temp;
531 virtual boost::shared_ptr<FilterMatcherBase>
copy()
const {
535 #ifdef RDK_USE_BOOST_SERIALIZATION 536 friend class boost::serialization::access;
537 template <
class Archive>
538 void serialize(Archive &ar,
const unsigned int version) {
540 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
548 #ifdef RDK_USE_BOOST_SERIALIZATION 550 template <
class Archive>
551 void registerFilterMatcherTypes(Archive &ar) {
552 ar.register_type(static_cast<FilterMatchOps::And *>(NULL));
553 ar.register_type(static_cast<FilterMatchOps::Or *>(NULL));
554 ar.register_type(static_cast<FilterMatchOps::Not *>(NULL));
555 ar.register_type(static_cast<SmartsMatcher *>(NULL));
556 ar.register_type(static_cast<ExclusionList *>(NULL));
557 ar.register_type(static_cast<FilterHierarchyMatcher *>(NULL));
562 #ifdef RDK_USE_BOOST_SERIALIZATION virtual std::string getName() const
virtual std::string getName() const
virtual bool isValid() const =0
static void pickleMol(const ROMol *mol, std::ostream &ss)
pickles a molecule and sends the results to stream ss
virtual boost::shared_ptr< FilterMatcherBase > copy() const
copy
virtual std::string getName() const
FilterHierarchyMatcher(const FilterMatcherBase &matcher)
bool getMatches(const ROMol &mol, std::vector< FilterMatch > &matchVect) const
getMatches
bool hasMatch(const ROMol &mol) const
hasMatches
bool getMatches(const ROMol &mol, std::vector< FilterMatch > &) const
getMatches
unsigned int getMinCount() const
Get the minimum match count for the pattern to be true.
bool hasMatch(const ROMol &mol) const
hasMatches
void setPattern(const ROMOL_SPTR &pat)
Set the shared query molecule for the matcher.
boost::shared_ptr< FilterHierarchyMatcher > addChild(const FilterHierarchyMatcher &hierarchy)
And(const FilterMatcherBase &arg1, const FilterMatcherBase &arg2)
void addPattern(const FilterMatcherBase &base)
virtual std::string getName() const
pulls in the core RDKit functionality
ROMol is a molecule class that is intended to have a fixed topology.
void setPattern(const FilterMatcherBase &matcher)
Set a new FilterMatcherBase for this node.
bool getMatches(const ROMol &mol, std::vector< FilterMatch > &matchVect) const
getMatches
virtual std::string getName() const
Not(const FilterMatcherBase &arg1)
void setMaxCount(unsigned int val)
Set the maximum match count for the pattern to be true.
virtual std::string getName() const
Return the name for this node (from the underlying FilterMatcherBase)
virtual bool getMatches(const ROMol &mol, std::vector< FilterMatch > &) const
getMatches
boost::shared_ptr< FilterMatcherBase > copy() const
copy
bool hasMatch(const ROMol &mol) const
hasMatches
boost::shared_ptr< ROMol > ROMOL_SPTR
unsigned int getMaxCount() const
Get the maximum match count for the pattern to be true.
virtual boost::shared_ptr< FilterMatcherBase > copy() const
copy
boost::shared_ptr< FilterMatcherBase > copy() const
copy
ExclusionList(const std::vector< boost::shared_ptr< FilterMatcherBase > > &offPatterns)
Or(const FilterMatcherBase &arg1, const FilterMatcherBase &arg2)
#define RDUNUSED_PARAM(x)
const ROMOL_SPTR & getPattern() const
Return the shared_ptr to the underlying query molecule.
Not(const boost::shared_ptr< FilterMatcherBase > &arg1)
boost::shared_ptr< FilterMatcherBase > copy() const
copy
void setMinCount(unsigned int val)
Set the minimum match count for the pattern to be true.
virtual boost::shared_ptr< FilterMatcherBase > copy() const =0
copy
bool isValid() const
returns true if this node has a valid matcher
const char * SMARTS_MATCH_NAME_DEFAULT
Or(const boost::shared_ptr< FilterMatcherBase > &arg1, const boost::shared_ptr< FilterMatcherBase > &arg2)
#define PRECONDITION(expr, mess)
bool isValid() const
Returns True if the Smarts pattern is valid.
And(const boost::shared_ptr< FilterMatcherBase > &arg1, const boost::shared_ptr< FilterMatcherBase > &arg2)
SmartsMatcher(const std::string &name=SMARTS_MATCH_NAME_DEFAULT)
Construct a SmartsMatcher.
void setExclusionPatterns(const std::vector< boost::shared_ptr< FilterMatcherBase > > &offPatterns)
virtual bool hasMatch(const ROMol &mol) const
Does this node match the molecule.
virtual boost::shared_ptr< FilterMatcherBase > copy() const
copys the FilterHierarchyMatcher into a FilterMatcherBase
virtual bool hasMatch(const ROMol &mol) const
hasMatches