33 #ifndef __RD_FILTER_MATCHER_H__ 34 #define __RD_FILTER_MATCHER_H__ 43 std::string getArgName(
const boost::shared_ptr<FilterMatcherBase> &arg) {
44 if (arg.get())
return arg->getName();
45 return "<nullmatcher>";
49 namespace FilterMatchOps {
51 boost::shared_ptr<FilterMatcherBase> arg1;
52 boost::shared_ptr<FilterMatcherBase> arg2;
64 And(
const boost::shared_ptr<FilterMatcherBase> &arg1,
65 const boost::shared_ptr<FilterMatcherBase> &arg2)
73 getArgName(arg2) +
")";
77 return arg1.get() && arg2.get() && arg1->isValid() && arg2->isValid();
82 "FilterMatchOps::And is not valid, null arg1 or arg2");
83 return arg1->hasMatch(mol) && arg2->hasMatch(mol);
88 "FilterMatchOps::And is not valid, null arg1 or arg2");
89 std::vector<FilterMatch> matches;
90 if (arg1->getMatches(mol, matches) && arg2->getMatches(mol, matches)) {
97 boost::shared_ptr<FilterMatcherBase>
copy()
const {
98 return boost::shared_ptr<FilterMatcherBase>(
new And(*
this));
102 #ifdef RDK_USE_BOOST_SERIALIZATION 103 friend class boost::serialization::access;
104 template <
class Archive>
105 void serialize(Archive &ar,
const unsigned int version) {
107 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
116 boost::shared_ptr<FilterMatcherBase> arg1;
117 boost::shared_ptr<FilterMatcherBase> arg2;
128 Or(
const boost::shared_ptr<FilterMatcherBase> &arg1,
129 const boost::shared_ptr<FilterMatcherBase> &arg2)
136 getArgName(arg2) +
")";
140 return arg1.get() && arg2.get() && arg1->isValid() && arg2->isValid();
144 PRECONDITION(isValid(),
"Or is not valid, null arg1 or arg2");
145 return arg1->hasMatch(mol) || arg2->hasMatch(mol);
150 "FilterMatchOps::Or is not valid, null arg1 or arg2");
153 bool res1 = arg1->getMatches(mol, matchVect);
154 bool res2 = arg2->getMatches(mol, matchVect);
158 boost::shared_ptr<FilterMatcherBase>
copy()
const {
159 return boost::shared_ptr<FilterMatcherBase>(
new Or(*
this));
162 #ifdef RDK_USE_BOOST_SERIALIZATION 163 friend class boost::serialization::access;
164 template <
class Archive>
165 void serialize(Archive &ar,
const unsigned int version) {
167 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
175 boost::shared_ptr<FilterMatcherBase> arg1;
188 Not(
const boost::shared_ptr<FilterMatcherBase> &arg1)
197 bool isValid()
const {
return arg1.get() && arg1->isValid(); }
200 PRECONDITION(isValid(),
"FilterMatchOps::Not: arg1 is null");
201 return !arg1->hasMatch(mol);
205 PRECONDITION(isValid(),
"FilterMatchOps::Not: arg1 is null");
208 std::vector<FilterMatch> matchVect;
209 return !arg1->getMatches(mol, matchVect);
212 boost::shared_ptr<FilterMatcherBase>
copy()
const {
213 return boost::shared_ptr<FilterMatcherBase>(
new Not(*
this));
217 #ifdef RDK_USE_BOOST_SERIALIZATION 218 friend class boost::serialization::access;
219 template <
class Archive>
220 void serialize(Archive &ar,
const unsigned int version) {
222 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
232 unsigned int d_min_count;
233 unsigned int d_max_count;
241 d_max_count(UINT_MAX) {}
254 unsigned int maxCount = UINT_MAX);
269 unsigned int minCount = 1,
unsigned int maxCount = UINT_MAX);
282 SmartsMatcher(
const std::string &name,
const std::string &smarts,
283 unsigned int minCount = 1,
unsigned int maxCount = UINT_MAX);
297 unsigned int minCount = 1,
unsigned int maxCount = UINT_MAX);
302 bool isValid()
const {
return d_pattern.get(); }
307 void setPattern(
const std::string &smarts);
309 void setPattern(
const ROMol &mol);
322 virtual bool getMatches(
const ROMol &mol,
323 std::vector<FilterMatch> &matchVect)
const;
324 virtual bool hasMatch(
const ROMol &mol)
const;
325 virtual boost::shared_ptr<FilterMatcherBase>
copy()
const {
326 return boost::shared_ptr<FilterMatcherBase>(
new SmartsMatcher(*
this));
330 #ifdef RDK_USE_BOOST_SERIALIZATION 331 friend class boost::serialization::access;
332 template <
class Archive>
333 void save(Archive &ar,
const unsigned int version)
const {
335 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
342 template <
class Archive>
343 void load(Archive &ar,
const unsigned int version) {
344 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
349 d_pattern = boost::shared_ptr<ROMol>(
new ROMol(res));
354 BOOST_SERIALIZATION_SPLIT_MEMBER();
372 std::vector<boost::shared_ptr<FilterMatcherBase> > d_offPatterns;
386 const std::vector<boost::shared_ptr<FilterMatcherBase> > &offPatterns)
392 for (
size_t i = 0; i < d_offPatterns.size(); ++i) {
393 res +=
" " + d_offPatterns[i]->getName();
400 for (
size_t i = 0; i < d_offPatterns.size(); ++i)
401 if (!d_offPatterns[i]->isValid())
return false;
407 d_offPatterns.push_back(base.
copy());
411 const std::vector<boost::shared_ptr<FilterMatcherBase> > &offPatterns) {
412 d_offPatterns = offPatterns;
417 "ExclusionList: one of the exclusion pattens is invalid");
419 for (
size_t i = 0; i < d_offPatterns.size() && result; ++i) {
420 result &= !d_offPatterns[i]->hasMatch(mol);
428 "ExclusionList: one of the exclusion pattens is invalid");
430 for (
size_t i = 0; i < d_offPatterns.size() && result; ++i) {
431 result &= !d_offPatterns[i]->hasMatch(mol);
437 virtual boost::shared_ptr<FilterMatcherBase>
copy()
const {
438 return boost::shared_ptr<FilterMatcherBase>(
new ExclusionList(*
this));
442 #ifdef RDK_USE_BOOST_SERIALIZATION 443 friend class boost::serialization::access;
444 template <
class Archive>
445 void serialize(Archive &ar,
const unsigned int version) {
447 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
454 std::vector<boost::shared_ptr<FilterHierarchyMatcher> > d_children;
455 boost::shared_ptr<FilterMatcherBase> d_matcher;
473 d_matcher(matcher.copy()) {
478 if (d_matcher.get()) {
479 return d_matcher->getName();
481 return "FilterMatcherHierarchy root";
486 return d_matcher->isValid();
495 d_matcher = matcher.
copy();
496 PRECONDITION(getName() == d_matcher->getName(),
"Opps");
505 boost::shared_ptr<FilterHierarchyMatcher>
addChild(
507 PRECONDITION(hierarchy.d_matcher.get() && hierarchy.d_matcher->isValid(),
508 "Only one root node is allowed in a FilterHierarchyMatcher");
510 d_children.push_back( boost::shared_ptr<FilterHierarchyMatcher>(
512 return d_children.back();
520 virtual bool getMatches(
const ROMol &mol, std::vector<FilterMatch> &matches)
const;
527 std::vector<FilterMatch> temp;
528 return getMatches(mol, temp);
532 virtual boost::shared_ptr<FilterMatcherBase>
copy()
const {
536 #ifdef RDK_USE_BOOST_SERIALIZATION 537 friend class boost::serialization::access;
538 template <
class Archive>
539 void serialize(Archive &ar,
const unsigned int version) {
541 ar &boost::serialization::base_object<FilterMatcherBase>(*this);
549 #ifdef RDK_USE_BOOST_SERIALIZATION 551 template <
class Archive>
552 void registerFilterMatcherTypes(Archive &ar) {
553 ar.register_type(static_cast<FilterMatchOps::And *>(NULL));
554 ar.register_type(static_cast<FilterMatchOps::Or *>(NULL));
555 ar.register_type(static_cast<FilterMatchOps::Not *>(NULL));
556 ar.register_type(static_cast<SmartsMatcher *>(NULL));
557 ar.register_type(static_cast<ExclusionList *>(NULL));
558 ar.register_type(static_cast<FilterHierarchyMatcher *>(NULL));
563 #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)
RDKIT_FILTERCATALOG_EXPORT const char * SMARTS_MATCH_NAME_DEFAULT
virtual std::string getName() const
pulls in the core RDKit functionality
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
#define RDKIT_FILTERCATALOG_EXPORT
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
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