RDKit
Open-source cheminformatics and machine learning.
QueryOps.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2003-2017 Greg Landrum and Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 
11 //! \file QueryOps.h
12 /*!
13  \brief Includes a bunch of functionality for handling Atom and Bond queries.
14 */
15 #include <RDGeneral/export.h>
16 #ifndef _RD_QUERY_OPS_H
17 #define _RD_QUERY_OPS_H
18 
19 #include <GraphMol/RDKitBase.h>
20 #include <Query/QueryObjects.h>
21 #include <Query/Query.h>
22 #include <DataStructs/BitVects.h>
23 #include <DataStructs/BitOps.h>
24 
25 #ifdef RDK_THREADSAFE_SSS
26 #include <mutex>
27 #endif
28 
29 namespace RDKit {
32 
35 
38 
41 
44 
47 
52 
55 
58 
61 
64 
67 
68 // -------------------------------------------------
69 // common atom queries
70 
71 static inline int queryAtomAromatic(Atom const *at) {
72  return at->getIsAromatic();
73 };
74 static inline int queryAtomAliphatic(Atom const *at) {
75  return !(at->getIsAromatic());
76 };
77 static inline int queryAtomExplicitDegree(Atom const *at) {
78  return at->getDegree();
79 };
80 static inline int queryAtomTotalDegree(Atom const *at) {
81  return at->getTotalDegree();
82 };
83 static inline int queryAtomNonHydrogenDegree(Atom const *at) {
84  return at->getTotalDegree() - at->getTotalNumHs(true);
85 }
86 static inline int queryAtomHeavyAtomDegree(Atom const *at) {
87  int heavyDegree = 0;
88  ROMol::ADJ_ITER nbrIdx, endNbrs;
89  boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
90  while (nbrIdx != endNbrs) {
91  const Atom *nbr = at->getOwningMol()[*nbrIdx];
92  if (nbr->getAtomicNum() > 1) {
93  heavyDegree++;
94  }
95  ++nbrIdx;
96  }
97 
98  return heavyDegree;
99 };
100 static inline int queryAtomHCount(Atom const *at) {
101  return at->getTotalNumHs(true);
102 };
103 static inline int queryAtomImplicitHCount(Atom const *at) {
104  return at->getTotalNumHs(false);
105 };
106 static inline int queryAtomHasImplicitH(Atom const *at) {
107  return int(at->getTotalNumHs(false) > 0);
108 };
109 static inline int queryAtomImplicitValence(Atom const *at) {
110  return at->getImplicitValence();
111 };
112 static inline int queryAtomExplicitValence(Atom const *at) {
113  return at->getExplicitValence() - at->getNumExplicitHs();
114 };
115 static inline int queryAtomTotalValence(Atom const *at) {
116  return at->getExplicitValence() + at->getImplicitValence();
117 };
118 static inline int queryAtomUnsaturated(Atom const *at) {
119  return static_cast<int>(at->getDegree()) < at->getExplicitValence();
120 };
121 static inline int queryAtomNum(Atom const *at) { return at->getAtomicNum(); };
122 static inline int makeAtomType(int atomic_num, bool aromatic) {
123  return atomic_num + 1000 * static_cast<int>(aromatic);
124 }
125 static inline void parseAtomType(int val, int &atomic_num, bool &aromatic) {
126  if (val > 1000) {
127  aromatic = true;
128  atomic_num = val - 1000;
129  } else {
130  aromatic = false;
131  atomic_num = val;
132  }
133 }
134 static inline bool getAtomTypeIsAromatic(int val) {
135  if (val > 1000) return true;
136  return false;
137 }
138 static inline int getAtomTypeAtomicNum(int val) {
139  if (val > 1000) return val - 1000;
140  return val;
141 }
142 
143 static inline int queryAtomType(Atom const *at) {
144  return makeAtomType(at->getAtomicNum(), at->getIsAromatic());
145 };
147 static inline int queryAtomMass(Atom const *at) {
148  return static_cast<int>(
149  std::round(massIntegerConversionFactor * at->getMass()));
150 };
151 static inline int queryAtomIsotope(Atom const *at) {
152  return static_cast<int>(at->getIsotope());
153 };
154 static inline int queryAtomFormalCharge(Atom const *at) {
155  return static_cast<int>(at->getFormalCharge());
156 };
157 static inline int queryAtomNegativeFormalCharge(Atom const *at) {
158  return static_cast<int>(-1 * at->getFormalCharge());
159 };
160 static inline int queryAtomHybridization(Atom const *at) {
161  return at->getHybridization();
162 };
163 static inline int queryAtomNumRadicalElectrons(Atom const *at) {
164  return at->getNumRadicalElectrons();
165 };
166 static inline int queryAtomHasChiralTag(Atom const *at) {
167  return at->getChiralTag() != Atom::CHI_UNSPECIFIED;
168 };
169 static inline int queryAtomMissingChiralTag(Atom const *at) {
170  return at->getChiralTag() == Atom::CHI_UNSPECIFIED &&
172 };
173 
174 static inline int queryAtomHasHeteroatomNbrs(Atom const *at) {
175  ROMol::ADJ_ITER nbrIdx, endNbrs;
176  boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
177  while (nbrIdx != endNbrs) {
178  const Atom *nbr = at->getOwningMol()[*nbrIdx];
179  if (nbr->getAtomicNum() != 6 && nbr->getAtomicNum() != 1) {
180  return 1;
181  }
182  ++nbrIdx;
183  }
184  return 0;
185 };
186 
187 static inline int queryAtomNumHeteroatomNbrs(Atom const *at) {
188  int res = 0;
189  ROMol::ADJ_ITER nbrIdx, endNbrs;
190  boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
191  while (nbrIdx != endNbrs) {
192  const Atom *nbr = at->getOwningMol()[*nbrIdx];
193  if (nbr->getAtomicNum() != 6 && nbr->getAtomicNum() != 1) {
194  ++res;
195  }
196  ++nbrIdx;
197  }
198  return res;
199 };
200 
201 static inline int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at) {
202  ROMol::ADJ_ITER nbrIdx, endNbrs;
203  boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
204  while (nbrIdx != endNbrs) {
205  const Atom *nbr = at->getOwningMol()[*nbrIdx];
206  if ((!nbr->getIsAromatic()) && nbr->getAtomicNum() != 6 &&
207  nbr->getAtomicNum() != 1) {
208  return 1;
209  }
210  ++nbrIdx;
211  }
212  return 0;
213 };
214 
215 static inline int queryAtomNumAliphaticHeteroatomNbrs(Atom const *at) {
216  int res = 0;
217  ROMol::ADJ_ITER nbrIdx, endNbrs;
218  boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
219  while (nbrIdx != endNbrs) {
220  const Atom *nbr = at->getOwningMol()[*nbrIdx];
221  if ((!nbr->getIsAromatic()) && nbr->getAtomicNum() != 6 &&
222  nbr->getAtomicNum() != 1) {
223  ++res;
224  }
225  ++nbrIdx;
226  }
227  return res;
228 };
229 
232 
233 // -------------------------------------------------
234 // common bond queries
235 
236 static inline int queryBondOrder(Bond const *bond) {
237  return static_cast<int>(bond->getBondType());
238 };
239 static inline int queryBondIsSingleOrAromatic(Bond const *bond) {
240  return static_cast<int>(bond->getBondType() == Bond::SINGLE ||
241  bond->getBondType() == Bond::AROMATIC);
242 };
243 static inline int queryBondDir(Bond const *bond) {
244  return static_cast<int>(bond->getBondDir());
245 };
246 static inline int queryIsBondInNRings(Bond const *at) {
247  return at->getOwningMol().getRingInfo()->numBondRings(at->getIdx());
248 };
249 static inline int queryBondHasStereo(Bond const *bnd) {
250  return bnd->getStereo() > Bond::STEREONONE;
251 };
252 
253 // -------------------------------------------------
254 // ring queries
255 
256 static inline int queryIsAtomInNRings(Atom const *at) {
257  return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx());
258 };
259 static inline int queryIsAtomInRing(Atom const *at) {
260  return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx()) != 0;
261 };
262 static inline int queryAtomHasRingBond(Atom const *at) {
263  ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
264  while (atomBonds.first != atomBonds.second) {
265  unsigned int bondIdx =
266  at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
267  if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
268  return 1;
269  }
270  ++atomBonds.first;
271  }
272  return 0;
273 };
274 static inline int queryIsBondInRing(Bond const *bond) {
275  return bond->getOwningMol().getRingInfo()->numBondRings(bond->getIdx()) != 0;
276 };
277 static inline int queryAtomMinRingSize(Atom const *at) {
278  return at->getOwningMol().getRingInfo()->minAtomRingSize(at->getIdx());
279 };
280 static inline int queryBondMinRingSize(Bond const *bond) {
281  return bond->getOwningMol().getRingInfo()->minBondRingSize(bond->getIdx());
282 };
283 
284 static inline int queryAtomRingBondCount(Atom const *at) {
285  // EFF: cache this result
286  int res = 0;
287  ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
288  while (atomBonds.first != atomBonds.second) {
289  unsigned int bondIdx =
290  at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
291  if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
292  res++;
293  }
294  ++atomBonds.first;
295  }
296  return res;
297 }
298 
299 template <int tgt>
301  if (at->getOwningMol().getRingInfo()->isAtomInRingOfSize(at->getIdx(), tgt)) {
302  return tgt;
303  } else {
304  return 0;
305  }
306 };
307 template <int tgt>
308 int queryBondIsInRingOfSize(Bond const *bond) {
309  if (bond->getOwningMol().getRingInfo()->isBondInRingOfSize(bond->getIdx(),
310  tgt)) {
311  return tgt;
312  } else {
313  return 0;
314  }
315 };
316 
317 template <class T>
318 T *makeAtomSimpleQuery(int what, int func(Atom const *),
319  const std::string &description = "Atom Simple") {
320  T *res = new T;
321  res->setVal(what);
322  res->setDataFunc(func);
323  res->setDescription(description);
324  return res;
325 }
326 
328  int lower, int upper, bool lowerOpen, bool upperOpen,
329  int func(Atom const *), const std::string &description = "Atom Range") {
330  ATOM_RANGE_QUERY *res = new ATOM_RANGE_QUERY(lower, upper);
331  res->setDataFunc(func);
332  res->setDescription(description);
333  res->setEndsOpen(lowerOpen, upperOpen);
334  return res;
335 }
336 
337 //! returns a Query for matching atomic number
338 template <class T>
339 T *makeAtomNumQuery(int what, const std::string &descr) {
340  return makeAtomSimpleQuery<T>(what, queryAtomNum, descr);
341 }
342 //! \overload
344 
345 //! returns a Query for matching atomic number and aromaticity
346 template <class T>
347 T *makeAtomTypeQuery(int num, int aromatic, const std::string &descr) {
348  return makeAtomSimpleQuery<T>(makeAtomType(num, aromatic), queryAtomType,
349  descr);
350 }
351 //! \overload
353  int aromatic);
354 
355 //! returns a Query for matching implicit valence
356 template <class T>
357 T *makeAtomImplicitValenceQuery(int what, const std::string &descr) {
358  return makeAtomSimpleQuery<T>(what, queryAtomImplicitValence, descr);
359 }
360 //! \overload
362 
363 //! returns a Query for matching explicit valence
364 template <class T>
365 T *makeAtomExplicitValenceQuery(int what, const std::string &descr) {
366  return makeAtomSimpleQuery<T>(what, queryAtomExplicitValence, descr);
367 }
368 //! \overload
370 
371 //! returns a Query for matching total valence
372 template <class T>
373 T *makeAtomTotalValenceQuery(int what, const std::string &descr) {
374  return makeAtomSimpleQuery<T>(what, queryAtomTotalValence, descr);
375 }
376 //! \overload
378 
379 //! returns a Query for matching explicit degree
380 template <class T>
381 T *makeAtomExplicitDegreeQuery(int what, const std::string &descr) {
382  return makeAtomSimpleQuery<T>(what, queryAtomExplicitDegree, descr);
383 }
384 //! \overload
386 
387 //! returns a Query for matching atomic degree
388 template <class T>
389 T *makeAtomTotalDegreeQuery(int what, const std::string &descr) {
390  return makeAtomSimpleQuery<T>(what, queryAtomTotalDegree, descr);
391 }
392 //! \overload
394 
395 //! returns a Query for matching heavy atom degree
396 template <class T>
397 T *makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr) {
398  return makeAtomSimpleQuery<T>(what, queryAtomHeavyAtomDegree, descr);
399 }
400 //! \overload
402 
403 //! returns a Query for matching hydrogen count
404 template <class T>
405 T *makeAtomHCountQuery(int what, const std::string &descr) {
406  return makeAtomSimpleQuery<T>(what, queryAtomHCount, descr);
407 }
408 //! \overload
410 
411 //! returns a Query for matching ring atoms
412 template <class T>
413 T *makeAtomHasImplicitHQuery(const std::string &descr) {
414  return makeAtomSimpleQuery<T>(true, queryAtomHasImplicitH, descr);
415 }
416 //! \overload
418 
419 //! returns a Query for matching implicit hydrogen count
420 template <class T>
421 T *makeAtomImplicitHCountQuery(int what, const std::string &descr) {
422  return makeAtomSimpleQuery<T>(what, queryAtomImplicitHCount, descr);
423 }
424 //! \overload
426 
427 //! returns a Query for matching the \c isAromatic flag
428 template <class T>
429 T *makeAtomAromaticQuery(const std::string &descr) {
430  return makeAtomSimpleQuery<T>(true, queryAtomAromatic, descr);
431 }
432 //! \overload
434 
435 //! returns a Query for matching aliphatic atoms
436 template <class T>
437 T *makeAtomAliphaticQuery(const std::string &descr) {
438  return makeAtomSimpleQuery<T>(true, queryAtomAliphatic, descr);
439 }
440 //! \overload
442 
443 //! returns a Query for matching atoms with a particular mass
444 template <class T>
445 T *makeAtomMassQuery(int what, const std::string &descr) {
446  return makeAtomSimpleQuery<T>(massIntegerConversionFactor * what,
447  queryAtomMass, descr);
448 }
449 //! \overload
451 
452 //! returns a Query for matching atoms with a particular isotope
453 template <class T>
454 T *makeAtomIsotopeQuery(int what, const std::string &descr) {
455  return makeAtomSimpleQuery<T>(what, queryAtomIsotope, descr);
456 }
457 //! \overload
459 
460 //! returns a Query for matching formal charge
461 template <class T>
462 T *makeAtomFormalChargeQuery(int what, const std::string &descr) {
463  return makeAtomSimpleQuery<T>(what, queryAtomFormalCharge, descr);
464 }
465 //! \overload
467 
468 //! returns a Query for matching negative formal charges (i.e. a query val of 1
469 //! matches a formal charge of -1)
470 template <class T>
471 T *makeAtomNegativeFormalChargeQuery(int what, const std::string &descr) {
472  return makeAtomSimpleQuery<T>(what, queryAtomNegativeFormalCharge, descr);
473 }
474 //! \overload
476  int what);
477 
478 //! returns a Query for matching hybridization
479 template <class T>
480 T *makeAtomHybridizationQuery(int what, const std::string &descr) {
481  return makeAtomSimpleQuery<T>(what, queryAtomHybridization, descr);
482 }
483 //! \overload
485 
486 //! returns a Query for matching the number of radical electrons
487 template <class T>
488 T *makeAtomNumRadicalElectronsQuery(int what, const std::string &descr) {
489  return makeAtomSimpleQuery<T>(what, queryAtomNumRadicalElectrons, descr);
490 }
491 //! \overload
493  int what);
494 
495 //! returns a Query for matching whether or not chirality has been set on the
496 //! atom
497 template <class T>
498 T *makeAtomHasChiralTagQuery(const std::string &descr) {
499  return makeAtomSimpleQuery<T>(true, queryAtomHasChiralTag, descr);
500 }
501 //! \overloadquery
503 
504 //! returns a Query for matching whether or not a potentially chiral atom is
505 //! missing a chiral tag
506 template <class T>
507 T *makeAtomMissingChiralTagQuery(const std::string &descr) {
508  return makeAtomSimpleQuery<T>(true, queryAtomMissingChiralTag, descr);
509 }
510 //! \overloadquery
512 
513 //! returns a Query for matching atoms with unsaturation:
514 template <class T>
515 T *makeAtomUnsaturatedQuery(const std::string &descr) {
516  return makeAtomSimpleQuery<T>(true, queryAtomUnsaturated, descr);
517 }
518 //! \overload
520 
521 //! returns a Query for matching ring atoms
522 template <class T>
523 T *makeAtomInRingQuery(const std::string &descr) {
524  return makeAtomSimpleQuery<T>(true, queryIsAtomInRing, descr);
525 }
527 //! \overload
528 
529 //! returns a Query for matching atoms in a particular number of rings
530 template <class T>
531 T *makeAtomInNRingsQuery(int what, const std::string &descr) {
532  return makeAtomSimpleQuery<T>(what, queryIsAtomInNRings, descr);
533 }
534 //! \overload
536 
537 //! returns a Query for matching atoms in rings of a particular size
539 
540 //! returns a Query for matching an atom's minimum ring size
541 template <class T>
542 T *makeAtomMinRingSizeQuery(int tgt, const std::string &descr) {
543  return makeAtomSimpleQuery<T>(tgt, queryAtomMinRingSize, descr);
544 }
545 //! \overload
547 
548 //! returns a Query for matching atoms with a particular number of ring bonds
549 template <class T>
550 T *makeAtomRingBondCountQuery(int what, const std::string &descr) {
551  return makeAtomSimpleQuery<T>(what, queryAtomRingBondCount, descr);
552 }
553 //! \overload
555 
556 //! returns a Query for matching generic A atoms (heavy atoms)
558 //! returns a Query for matching generic AH atoms (any atom)
560 //! returns a Query for matching generic Q atoms (heteroatoms)
562 //! returns a Query for matching generic QH atoms (heteroatom or H)
564 //! returns a Query for matching generic X atoms (halogens)
566 //! returns a Query for matching generic XH atoms (halogen or H)
568 //! returns a Query for matching generic M atoms (metals)
570 //! returns a Query for matching generic MH atoms (metals or H)
572 
573 //! returns a Query for matching atoms that have ring bonds
574 template <class T>
575 T *makeAtomHasRingBondQuery(const std::string &descr) {
576  return makeAtomSimpleQuery<T>(1, queryAtomHasRingBond, descr);
577 }
578 //! \overload
580 
581 //! returns a Query for matching the number of heteroatom neighbors
582 template <class T>
583 T *makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr) {
584  return makeAtomSimpleQuery<T>(what, queryAtomNumHeteroatomNbrs, descr);
585 }
586 //! \overload
588  int what);
589 
590 //! returns a Query for matching atoms that have heteroatom neighbors
591 template <class T>
592 T *makeAtomHasHeteroatomNbrsQuery(const std::string &descr) {
593  return makeAtomSimpleQuery<T>(1, queryAtomHasHeteroatomNbrs, descr);
594 }
595 //! \overload
597 
598 //! returns a Query for matching the number of aliphatic heteroatom neighbors
599 template <class T>
600 T *makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr) {
601  return makeAtomSimpleQuery<T>(what, queryAtomNumAliphaticHeteroatomNbrs,
602  descr);
603 }
604 //! \overload
607 
608 //! returns a Query for matching atoms that have heteroatom neighbors
609 template <class T>
610 T *makeAtomHasAliphaticHeteroatomNbrsQuery(const std::string &descr) {
611  return makeAtomSimpleQuery<T>(1, queryAtomHasAliphaticHeteroatomNbrs, descr);
612 }
613 //! \overload
616 
617 //! returns a Query for matching bond orders
619  Bond::BondType what);
620 //! returns a Query for unspecified SMARTS bonds
622 //! returns a Query for matching bond directions
624  Bond::BondDir what);
625 //! returns a Query for matching bonds with stereo set
627 //! returns a Query for matching ring bonds
629 //! returns a Query for matching bonds in rings of a particular size
631 //! returns a Query for matching a bond's minimum ring size
633 //! returns a Query for matching bonds in a particular number of rings
635 
636 //! returns a Query for matching any bond
638 //! returns a Query for matching any atom
640 
641 static inline int queryAtomRingMembership(Atom const *at) {
642  return static_cast<int>(
643  at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx()));
644 }
645 // I'm pretty sure that this typedef shouldn't be necessary,
646 // but VC++ generates a warning about const Atom const * in
647 // the definition of Match, then complains about an override
648 // that differs only by const/volatile (c4301), then generates
649 // incorrect code if we don't do this... so let's do it.
650 typedef Atom const *ConstAtomPtr;
651 
653  : public Queries::EqualityQuery<int, ConstAtomPtr, true> {
654  public:
655  AtomRingQuery() : Queries::EqualityQuery<int, ConstAtomPtr, true>(-1) {
656  // default is to just do a number of rings query:
657  this->setDescription("AtomInNRings");
658  this->setDataFunc(queryAtomRingMembership);
659  };
660  explicit AtomRingQuery(int v)
661  : Queries::EqualityQuery<int, ConstAtomPtr, true>(v) {
662  // default is to just do a number of rings query:
663  this->setDescription("AtomInNRings");
664  this->setDataFunc(queryAtomRingMembership);
665  };
666 
667  virtual bool Match(const ConstAtomPtr what) const {
668  int v = this->TypeConvert(what, Queries::Int2Type<true>());
669  bool res;
670  if (this->d_val < 0) {
671  res = v != 0;
672  } else {
673  res = !Queries::queryCmp(v, this->d_val, this->d_tol);
674  }
675  if (this->getNegation()) {
676  res = !res;
677  }
678  return res;
679  }
680 
681  //! returns a copy of this query
683  AtomRingQuery *res = new AtomRingQuery(this->d_val);
684  res->setNegation(getNegation());
685  res->setTol(this->getTol());
686  res->d_description = this->d_description;
687  res->d_dataFunc = this->d_dataFunc;
688  return res;
689  }
690 };
691 
692 //! allows use of recursive structure queries (e.g. recursive SMARTS)
694  : public Queries::SetQuery<int, Atom const *, true> {
695  public:
697  : Queries::SetQuery<int, Atom const *, true>(), d_serialNumber(0) {
698  setDataFunc(getAtIdx);
699  setDescription("RecursiveStructure");
700  };
701  //! initialize from an ROMol pointer
702  /*!
703  <b>Notes</b>
704  - this takes over ownership of the pointer
705  */
706  RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber = 0)
707  : Queries::SetQuery<int, Atom const *, true>(),
708  d_serialNumber(serialNumber) {
709  setQueryMol(query);
710  setDataFunc(getAtIdx);
711  setDescription("RecursiveStructure");
712  };
713  //! returns the index of an atom
714  static inline int getAtIdx(Atom const *at) {
715  PRECONDITION(at, "bad atom argument");
716  return at->getIdx();
717  };
718 
719  //! sets the molecule we'll use recursively
720  /*!
721  <b>Notes</b>
722  - this takes over ownership of the pointer
723  */
724  void setQueryMol(ROMol const *query) { dp_queryMol.reset(query); }
725  //! returns a pointer to our query molecule
726  ROMol const *getQueryMol() const { return dp_queryMol.get(); };
727 
728  //! returns a copy of this query
731  res->dp_queryMol.reset(new ROMol(*dp_queryMol, true));
732 
733  std::set<int>::const_iterator i;
734  for (i = d_set.begin(); i != d_set.end(); i++) {
735  res->insert(*i);
736  }
737  res->setNegation(getNegation());
738  res->d_description = d_description;
739  res->d_serialNumber = d_serialNumber;
740  return res;
741  }
742  unsigned int getSerialNumber() const { return d_serialNumber; };
743 
744 #ifdef RDK_THREADSAFE_SSS
745  std::mutex d_mutex;
746 #endif
747  private:
748  boost::shared_ptr<const ROMol> dp_queryMol;
749  unsigned int d_serialNumber;
750 };
751 
752 template <typename T>
753 int nullDataFun(T) {
754  return 1;
755 }
756 template <typename T>
757 bool nullQueryFun(T) {
758  return true;
759 }
760 
761 typedef Bond const *ConstBondPtr;
762 
763 // ! Query whether an atom has a property
764 template <class TargetPtr>
765 class HasPropQuery : public Queries::EqualityQuery<int, TargetPtr, true> {
766  std::string propname;
767 
768  public:
769  HasPropQuery() : Queries::EqualityQuery<int, TargetPtr, true>(), propname() {
770  // default is to just do a number of rings query:
771  this->setDescription("AtomHasProp");
772  this->setDataFunc(0);
773  };
774  explicit HasPropQuery(const std::string &v)
775  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(v) {
776  // default is to just do a number of rings query:
777  this->setDescription("AtomHasProp");
778  this->setDataFunc(0);
779  };
780 
781  virtual bool Match(const TargetPtr what) const {
782  bool res = what->hasProp(propname);
783  if (this->getNegation()) {
784  res = !res;
785  }
786  return res;
787  }
788 
789  //! returns a copy of this query
791  HasPropQuery *res = new HasPropQuery(this->propname);
792  res->setNegation(this->getNegation());
793  res->d_description = this->d_description;
794  return res;
795  }
796 };
797 
800 
801 //! returns a Query for matching atoms that have a particular property
802 template <class Target>
804  const std::string &property) {
805  return new HasPropQuery<const Target *>(property);
806 }
807 
808 // ! Query whether an atom has a property with a value
809 template <class TargetPtr, class T>
811  : public Queries::EqualityQuery<int, TargetPtr, true> {
812  std::string propname;
813  T val;
814  T tolerance;
815 
816  public:
818  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
819  // default is to just do a number of rings query:
820  this->setDescription("HasPropWithValue");
821  this->setDataFunc(0);
822  };
823  explicit HasPropWithValueQuery(const std::string &prop, const T &v,
824  const T &tol = 0.0)
825  : Queries::EqualityQuery<int, TargetPtr, true>(),
826  propname(prop),
827  val(v),
828  tolerance(tol) {
829  // default is to just do a number of rings query:
830  this->setDescription("HasPropWithValue");
831  this->setDataFunc(0);
832  };
833 
834  virtual bool Match(const TargetPtr what) const {
835  bool res = what->hasProp(propname);
836  if (res) {
837  try {
838  T atom_val = what->template getProp<T>(propname);
839  res = Queries::queryCmp(atom_val, this->val, this->tolerance) == 0;
840  } catch (KeyErrorException &) {
841  res = false;
842  } catch (boost::bad_any_cast &) {
843  res = false;
844  }
845 #ifdef __GNUC__
846 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
847  catch (...) {
848  // catch all -- this is currently necessary to
849  // trap some bugs in boost+gcc configurations
850  // Normally, this is not the correct thing to
851  // do, but the only exception above is due
852  // to the boost any_cast which is trapped
853  // by the Boost python wrapper when it shouldn't
854  // be.
855  res = false;
856  }
857 #endif
858 #endif
859  }
860  if (this->getNegation()) {
861  res = !res;
862  }
863  return res;
864  }
865 
866  //! returns a copy of this query
868  HasPropWithValueQuery *res =
869  new HasPropWithValueQuery(this->propname, this->val, this->tolerance);
870  res->setNegation(this->getNegation());
871  res->d_description = this->d_description;
872  return res;
873  }
874 };
875 
876 template <class TargetPtr>
877 class HasPropWithValueQuery<TargetPtr, std::string>
878  : public Queries::EqualityQuery<int, TargetPtr, true> {
879  std::string propname;
880  std::string val;
881 
882  public:
884  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
885  // default is to just do a number of rings query:
886  this->setDescription("HasPropWithValue");
887  this->setDataFunc(0);
888  };
889  explicit HasPropWithValueQuery(const std::string &prop, const std::string &v,
890  const std::string &tol = "")
891  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(prop), val(v) {
892  RDUNUSED_PARAM(tol);
893  // default is to just do a number of rings query:
894  this->setDescription("HasPropWithValue");
895  this->setDataFunc(0);
896  };
897 
898  virtual bool Match(const TargetPtr what) const {
899  bool res = what->hasProp(propname);
900  if (res) {
901  try {
902  std::string atom_val = what->template getProp<std::string>(propname);
903  res = atom_val == this->val;
904  } catch (KeyErrorException &) {
905  res = false;
906  } catch (boost::bad_any_cast &) {
907  res = false;
908  }
909 #ifdef __GNUC__
910 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
911  catch (...) {
912  // catch all -- this is currently necessary to
913  // trap some bugs in boost+gcc configurations
914  // Normally, this is not the correct thing to
915  // do, but the only exception above is due
916  // to the boost any_cast which is trapped
917  // by the Boost python wrapper when it shouldn't
918  // be.
919  res = false;
920  }
921 #endif
922 #endif
923  }
924  if (this->getNegation()) {
925  res = !res;
926  }
927  return res;
928  }
929 
930  //! returns a copy of this query
934  this->val);
935  res->setNegation(this->getNegation());
936  res->d_description = this->d_description;
937  return res;
938  }
939 };
940 
941 template <class TargetPtr>
943  : public Queries::EqualityQuery<int, TargetPtr, true> {
944  std::string propname;
945  ExplicitBitVect val;
946  float tol;
947 
948  public:
950  : Queries::EqualityQuery<int, TargetPtr, true>(),
951  propname(),
952  val(),
953  tol(0.0) {
954  this->setDescription("HasPropWithValue");
955  this->setDataFunc(0);
956  };
957 
958  explicit HasPropWithValueQuery(const std::string &prop,
959  const ExplicitBitVect &v, float tol = 0.0)
960  : Queries::EqualityQuery<int, TargetPtr, true>(),
961  propname(prop),
962  val(v),
963  tol(tol) {
964  this->setDescription("HasPropWithValue");
965  this->setDataFunc(0);
966  };
967 
968  virtual bool Match(const TargetPtr what) const {
969  bool res = what->hasProp(propname);
970  if (res) {
971  try {
972  const ExplicitBitVect &bv =
973  what->template getProp<const ExplicitBitVect &>(propname);
974  const double tani = TanimotoSimilarity(val, bv);
975  res = (1.0 - tani) <= tol;
976  } catch (KeyErrorException &) {
977  res = false;
978  } catch (boost::bad_any_cast &) {
979  res = false;
980  }
981 #ifdef __GNUC__
982 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
983  catch (...) {
984  // catch all -- this is currently necessary to
985  // trap some bugs in boost+gcc configurations
986  // Normally, this is not the correct thing to
987  // do, but the only exception above is due
988  // to the boost any_cast which is trapped
989  // by the Boost python wrapper when it shouldn't
990  // be.
991  res = false;
992  }
993 #endif
994 #endif
995  }
996  if (this->getNegation()) {
997  res = !res;
998  }
999  return res;
1000  }
1001 
1002  //! returns a copy of this query
1006  this->propname, this->val, this->tol);
1007  res->setNegation(this->getNegation());
1008  res->d_description = this->d_description;
1009  return res;
1010  }
1011 };
1012 
1013 template <class Target, class T>
1015  const std::string &propname, const T &val, const T &tolerance = T()) {
1016  return new HasPropWithValueQuery<const Target *, T>(propname, val, tolerance);
1017 }
1018 
1019 template <class Target>
1021  const std::string &propname, const ExplicitBitVect &val,
1022  float tolerance = 0.0) {
1024  propname, val, tolerance);
1025 }
1026 
1030 }; // namespace RDKit
1031 
1032 #endif
RDKit::TanimotoSimilarity
double TanimotoSimilarity(const SparseIntVect< IndexType > &v1, const SparseIntVect< IndexType > &v2, bool returnDistance=false, double bounds=0.0)
Definition: SparseIntVect.h:538
RDKit::makeBondInRingOfSizeQuery
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInRingOfSizeQuery(int what)
returns a Query for matching bonds in rings of a particular size
RDKit::queryAtomNumHeteroatomNbrs
static int queryAtomNumHeteroatomNbrs(Atom const *at)
Definition: QueryOps.h:187
RDKit::queryAtomHasImplicitH
static int queryAtomHasImplicitH(Atom const *at)
Definition: QueryOps.h:106
RDKit::ROMol::getRingInfo
RingInfo * getRingInfo() const
Definition: ROMol.h:452
RDKit::makePropQuery
Queries::EqualityQuery< int, const Target *, true > * makePropQuery(const std::string &propname, const T &val, const T &tolerance=T())
Definition: QueryOps.h:1014
RDKit::Atom::getChiralTag
ChiralType getChiralTag() const
returns our chiralTag
Definition: Atom.h:239
RDKit::HasPropWithValueQuery::HasPropWithValueQuery
HasPropWithValueQuery(const std::string &prop, const T &v, const T &tol=0.0)
Definition: QueryOps.h:823
RDKit::queryAtomRingBondCount
static int queryAtomRingBondCount(Atom const *at)
Definition: QueryOps.h:284
RDKit::RingInfo::numAtomRings
unsigned int numAtomRings(unsigned int idx) const
returns the number of rings atom idx is involved in
RDKit::makeAtomHybridizationQuery
T * makeAtomHybridizationQuery(int what, const std::string &descr)
returns a Query for matching hybridization
Definition: QueryOps.h:480
RDKit::Bond::getStereo
BondStereo getStereo() const
returns our stereo code
Definition: Bond.h:292
RDKit::ATOM_XOR_QUERY
Queries::XOrQuery< int, Atom const *, true > ATOM_XOR_QUERY
Definition: QueryOps.h:39
RDKit::ATOM_BOOL_QUERY
Queries::Query< bool, Atom const *, true > ATOM_BOOL_QUERY
Definition: QueryOps.h:30
RDKit::Atom::getIsotope
unsigned int getIsotope() const
returns our isotope number
Definition: Atom.h:232
RDKit::Atom::getTotalDegree
unsigned int getTotalDegree() const
RDKit::queryAtomFormalCharge
static int queryAtomFormalCharge(Atom const *at)
Definition: QueryOps.h:154
RDKit::makeMHAtomQuery
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeMHAtomQuery()
returns a Query for matching generic MH atoms (metals or H)
RDKit::BOND_SET_QUERY
Queries::SetQuery< int, Bond const *, true > BOND_SET_QUERY
Definition: QueryOps.h:63
RDKit::queryAtomAllBondProduct
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomAllBondProduct(Atom const *at)
RDKit::queryAtomMass
static int queryAtomMass(Atom const *at)
Definition: QueryOps.h:147
BitOps.h
Contains general bit-comparison and similarity operations.
RDKit::queryIsBondInRing
static int queryIsBondInRing(Bond const *bond)
Definition: QueryOps.h:274
RDKit::RecursiveStructureQuery::getAtIdx
static int getAtIdx(Atom const *at)
returns the index of an atom
Definition: QueryOps.h:714
QueryObjects.h
Pulls in all the query types.
Queries::Query::setNegation
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:63
RDKit::Atom::getNumExplicitHs
unsigned int getNumExplicitHs() const
returns our number of explicit Hs
Definition: Atom.h:219
RDKit::RingInfo::numBondRings
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
RDKit::BOND_XOR_QUERY
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
Definition: QueryOps.h:40
Queries::queryCmp
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:191
RDKit::makeAtomMassQuery
T * makeAtomMassQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular mass
Definition: QueryOps.h:445
RDKit::queryAtomImplicitValence
static int queryAtomImplicitValence(Atom const *at)
Definition: QueryOps.h:109
RDKit::makeAAtomQuery
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAAtomQuery()
returns a Query for matching generic A atoms (heavy atoms)
RDKit::ConstAtomPtr
Atom const * ConstAtomPtr
Definition: QueryOps.h:650
RDKit::makeAtomHasHeteroatomNbrsQuery
T * makeAtomHasHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
Definition: QueryOps.h:592
RDKit::Atom::CHI_UNSPECIFIED
@ CHI_UNSPECIFIED
chirality that hasn't been specified
Definition: Atom.h:92
RDKit::HasPropWithValueQuery< TargetPtr, ExplicitBitVect >::HasPropWithValueQuery
HasPropWithValueQuery(const std::string &prop, const ExplicitBitVect &v, float tol=0.0)
Definition: QueryOps.h:958
RDKit::ATOM_AND_QUERY
Queries::AndQuery< int, Atom const *, true > ATOM_AND_QUERY
Definition: QueryOps.h:33
RDKit::Bond
class for representing a bond
Definition: Bond.h:47
RDKit::AtomRingQuery::AtomRingQuery
AtomRingQuery()
Definition: QueryOps.h:655
RDKit::Bond::SINGLE
@ SINGLE
Definition: Bond.h:58
RDKit::HasPropQuery::Match
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Definition: QueryOps.h:781
RDKit::HasPropWithValueQuery< TargetPtr, std::string >::Match
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Definition: QueryOps.h:898
RDKit::HasPropWithValueQuery::HasPropWithValueQuery
HasPropWithValueQuery()
Definition: QueryOps.h:817
RDKit::RingInfo::minBondRingSize
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
RDKit::makeAtomHCountQuery
T * makeAtomHCountQuery(int what, const std::string &descr)
returns a Query for matching hydrogen count
Definition: QueryOps.h:405
RDKit::queryAtomBondProduct
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomBondProduct(Atom const *at)
RDKit::HasPropQuery::copy
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:790
RDKit::queryAtomHasRingBond
static int queryAtomHasRingBond(Atom const *at)
Definition: QueryOps.h:262
RDKit::HasPropQuery::HasPropQuery
HasPropQuery(const std::string &v)
Definition: QueryOps.h:774
RDKit::makeAtomUnsaturatedQuery
T * makeAtomUnsaturatedQuery(const std::string &descr)
returns a Query for matching atoms with unsaturation:
Definition: QueryOps.h:515
RDKit::Atom::getAtomicNum
int getAtomicNum() const
returns our atomic number
Definition: Atom.h:116
RDKit::makeBondHasStereoQuery
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondHasStereoQuery()
returns a Query for matching bonds with stereo set
RDKit::queryBondMinRingSize
static int queryBondMinRingSize(Bond const *bond)
Definition: QueryOps.h:280
RDKit::queryAtomNonHydrogenDegree
static int queryAtomNonHydrogenDegree(Atom const *at)
Definition: QueryOps.h:83
RDKit::makeAtomInRingOfSizeQuery
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomInRingOfSizeQuery(int tgt)
returns a Query for matching atoms in rings of a particular size
RDKit::Atom::getIdx
unsigned int getIdx() const
returns our index within the ROMol
Definition: Atom.h:133
KeyErrorException
Class to allow us to throw a KeyError from C++ and have it make it back to Python.
Definition: Exceptions.h:57
Queries::Query::d_dataFunc
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition: Query.h:158
RDKit::queryAtomAliphatic
static int queryAtomAliphatic(Atom const *at)
Definition: QueryOps.h:74
RDKit::makeAtomInNRingsQuery
T * makeAtomInNRingsQuery(int what, const std::string &descr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: QueryOps.h:531
RDKit::Bond::BondType
BondType
the type of Bond
Definition: Bond.h:56
RDKit::Atom::getExplicitValence
int getExplicitValence() const
returns the explicit valence (including Hs) of this atom
RDKit::Atom::getImplicitValence
int getImplicitValence() const
returns the implicit valence for this Atom
RDUNUSED_PARAM
#define RDUNUSED_PARAM(x)
Definition: Invariant.h:197
Query.h
RDKit::queryAtomIsotope
static int queryAtomIsotope(Atom const *at)
Definition: QueryOps.h:151
RDKit::makeSingleOrAromaticBondQuery
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrAromaticBondQuery()
returns a Query for unspecified SMARTS bonds
Queries::SetQuery::insert
void insert(const MatchFuncArgType what)
insert an entry into our set
Definition: SetQuery.h:33
RDKit::queryAtomMinRingSize
static int queryAtomMinRingSize(Atom const *at)
Definition: QueryOps.h:277
RDKit::makeAtomNumHeteroatomNbrsQuery
T * makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of heteroatom neighbors
Definition: QueryOps.h:583
RDKit::makeAtomExplicitDegreeQuery
T * makeAtomExplicitDegreeQuery(int what, const std::string &descr)
returns a Query for matching explicit degree
Definition: QueryOps.h:381
RDKit::RecursiveStructureQuery::copy
Queries::Query< int, Atom const *, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:729
RDKit::ATOM_RANGE_QUERY
Queries::RangeQuery< int, Atom const *, true > ATOM_RANGE_QUERY
Definition: QueryOps.h:59
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:69
RDKit::queryAtomAromatic
static int queryAtomAromatic(Atom const *at)
Definition: QueryOps.h:71
RDKit::makeAtomImplicitHCountQuery
T * makeAtomImplicitHCountQuery(int what, const std::string &descr)
returns a Query for matching implicit hydrogen count
Definition: QueryOps.h:421
RDKit::isComplexQuery
RDKIT_GRAPHMOL_EXPORT bool isComplexQuery(const Bond *b)
RDKit::makeXAtomQuery
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXAtomQuery()
returns a Query for matching generic X atoms (halogens)
RDKit::parseAtomType
static void parseAtomType(int val, int &atomic_num, bool &aromatic)
Definition: QueryOps.h:125
RDKit::makeAtomIsotopeQuery
T * makeAtomIsotopeQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular isotope
Definition: QueryOps.h:454
RDKit::makeBondNullQuery
RDKIT_GRAPHMOL_EXPORT BOND_NULL_QUERY * makeBondNullQuery()
returns a Query for matching any bond
RDKit::queryAtomType
static int queryAtomType(Atom const *at)
Definition: QueryOps.h:143
RDKit::queryAtomHasHeteroatomNbrs
static int queryAtomHasHeteroatomNbrs(Atom const *at)
Definition: QueryOps.h:174
RDKit::queryAtomNum
static int queryAtomNum(Atom const *at)
Definition: QueryOps.h:121
RDKit::Bond::getIdx
unsigned int getIdx() const
returns our index within the ROMol
Definition: Bond.h:164
RDKit::RecursiveStructureQuery
allows use of recursive structure queries (e.g. recursive SMARTS)
Definition: QueryOps.h:694
Queries::RangeQuery
a Query implementing a range: arguments must fall in a particular range of values.
Definition: RangeQuery.h:28
RDKit::makeAtomMissingChiralTagQuery
T * makeAtomMissingChiralTagQuery(const std::string &descr)
Definition: QueryOps.h:507
Queries::OrQuery
a Query implementing AND: requires any child to be true
Definition: OrQuery.h:21
RDKit::queryBondOrder
static int queryBondOrder(Bond const *bond)
Definition: QueryOps.h:236
RDKit::makeQHAtomQuery
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeQHAtomQuery()
returns a Query for matching generic QH atoms (heteroatom or H)
RDKit::makeAtomExplicitValenceQuery
T * makeAtomExplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching explicit valence
Definition: QueryOps.h:365
RDKit::ROMol
Definition: ROMol.h:171
RDKit::Atom::getDegree
unsigned int getDegree() const
Queries::RangeQuery::setEndsOpen
void setEndsOpen(bool lower, bool upper)
sets whether or not the ends of the range are open
Definition: RangeQuery.h:50
RDKit::queryAtomIsInRingOfSize
int queryAtomIsInRingOfSize(Atom const *at)
Definition: QueryOps.h:300
RDKitBase.h
pulls in the core RDKit functionality
RDKit::queryBondIsSingleOrAromatic
static int queryBondIsSingleOrAromatic(Bond const *bond)
Definition: QueryOps.h:239
Queries
Definition: AndQuery.h:16
RDKit::HasPropQuery
Definition: QueryOps.h:765
RDKit::getAtomTypeAtomicNum
static int getAtomTypeAtomicNum(int val)
Definition: QueryOps.h:138
RDKit::HasPropWithValueQuery< TargetPtr, std::string >::HasPropWithValueQuery
HasPropWithValueQuery(const std::string &prop, const std::string &v, const std::string &tol="")
Definition: QueryOps.h:889
RDKit::Atom::getOwningMol
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
Definition: Atom.h:127
RDKit::makeAtomRingBondCountQuery
T * makeAtomRingBondCountQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular number of ring bonds
Definition: QueryOps.h:550
RDKit::queryAtomTotalDegree
static int queryAtomTotalDegree(Atom const *at)
Definition: QueryOps.h:80
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:307
RDKit::queryIsAtomInRing
static int queryIsAtomInRing(Atom const *at)
Definition: QueryOps.h:259
Queries::XOrQuery
a Query implementing XOR: requires exactly one child to be true
Definition: XOrQuery.h:22
RDKit::AtomRingQuery::AtomRingQuery
AtomRingQuery(int v)
Definition: QueryOps.h:660
RDKit::ATOM_SET_QUERY
Queries::SetQuery< int, Atom const *, true > ATOM_SET_QUERY
Definition: QueryOps.h:62
RDKit::makeBondOrderEqualsQuery
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondOrderEqualsQuery(Bond::BondType what)
returns a Query for matching bond orders
RDKit::BOND_AND_QUERY
Queries::AndQuery< int, Bond const *, true > BOND_AND_QUERY
Definition: QueryOps.h:34
RDKit::BOND_LESSEQUAL_QUERY
Queries::LessEqualQuery< int, Bond const *, true > BOND_LESSEQUAL_QUERY
Definition: QueryOps.h:57
RDKit::queryIsAtomInNRings
static int queryIsAtomInNRings(Atom const *at)
Definition: QueryOps.h:256
RDKit::nullDataFun
int nullDataFun(T)
Definition: QueryOps.h:753
RDKit::RecursiveStructureQuery::setQueryMol
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
Definition: QueryOps.h:724
RDKit::makeAtomNullQuery
RDKIT_GRAPHMOL_EXPORT ATOM_NULL_QUERY * makeAtomNullQuery()
returns a Query for matching any atom
RDKit::HasPropWithValueQuery< TargetPtr, ExplicitBitVect >::Match
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Definition: QueryOps.h:968
RDKit::makeAtomMinRingSizeQuery
T * makeAtomMinRingSizeQuery(int tgt, const std::string &descr)
returns a Query for matching an atom's minimum ring size
Definition: QueryOps.h:542
RDKit::queryAtomRingMembership
static int queryAtomRingMembership(Atom const *at)
Definition: QueryOps.h:641
RDKit::makeAtomAliphaticQuery
T * makeAtomAliphaticQuery(const std::string &descr)
returns a Query for matching aliphatic atoms
Definition: QueryOps.h:437
RDKit::makeAtomImplicitValenceQuery
T * makeAtomImplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching implicit valence
Definition: QueryOps.h:357
RDKit::makeBondInNRingsQuery
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInNRingsQuery(int tgt)
returns a Query for matching bonds in a particular number of rings
Queries::Query::d_description
std::string d_description
Definition: Query.h:147
RDKit::Atom::getTotalNumHs
unsigned int getTotalNumHs(bool includeNeighbors=false) const
returns the total number of Hs (implicit and explicit) that this Atom is bound to
RDKit::HasPropWithValueQuery::Match
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Definition: QueryOps.h:834
RDKit::ROMol::getAtomNeighbors
ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const
provides access to all neighbors around an Atom
RDKit::nullQueryFun
bool nullQueryFun(T)
Definition: QueryOps.h:757
RDKit::queryAtomHybridization
static int queryAtomHybridization(Atom const *at)
Definition: QueryOps.h:160
RDKit::RecursiveStructureQuery::getSerialNumber
unsigned int getSerialNumber() const
Definition: QueryOps.h:742
RDKit::BOND_EQUALS_QUERY
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
Definition: QueryOps.h:43
RDKit::queryAtomNumAliphaticHeteroatomNbrs
static int queryAtomNumAliphaticHeteroatomNbrs(Atom const *at)
Definition: QueryOps.h:215
RDKit::makeHasPropQuery
Queries::EqualityQuery< int, const Target *, true > * makeHasPropQuery(const std::string &property)
returns a Query for matching atoms that have a particular property
Definition: QueryOps.h:803
RDKit::makeAtomAromaticQuery
T * makeAtomAromaticQuery(const std::string &descr)
returns a Query for matching the isAromatic flag
Definition: QueryOps.h:429
RDKit::makeAtomInRingQuery
T * makeAtomInRingQuery(const std::string &descr)
returns a Query for matching ring atoms
Definition: QueryOps.h:523
RDKit::Bond::getBondDir
BondDir getBondDir() const
returns our direction
Definition: Bond.h:271
RDKit::Atom::getFormalCharge
int getFormalCharge() const
returns the formal charge of this atom
Definition: Atom.h:206
Queries::EqualityQuery< int, TargetPtr, true >::EqualityQuery
EqualityQuery()
Definition: EqualityQuery.h:26
RDKit::queryAtomTotalValence
static int queryAtomTotalValence(Atom const *at)
Definition: QueryOps.h:115
Queries::Query::setDataFunc
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
Definition: Query.h:92
RDKit::makeAtomNegativeFormalChargeQuery
T * makeAtomNegativeFormalChargeQuery(int what, const std::string &descr)
Definition: QueryOps.h:471
RDKit::makeAtomHasImplicitHQuery
T * makeAtomHasImplicitHQuery(const std::string &descr)
returns a Query for matching ring atoms
Definition: QueryOps.h:413
RDKit::ConstBondPtr
Bond const * ConstBondPtr
Definition: QueryOps.h:761
RDKit::queryBondDir
static int queryBondDir(Bond const *bond)
Definition: QueryOps.h:243
RDKit::ROMol::getAtomBonds
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
RDKit::makeAtomNumRadicalElectronsQuery
T * makeAtomNumRadicalElectronsQuery(int what, const std::string &descr)
returns a Query for matching the number of radical electrons
Definition: QueryOps.h:488
RDKit::makeAtomTypeQuery
T * makeAtomTypeQuery(int num, int aromatic, const std::string &descr)
returns a Query for matching atomic number and aromaticity
Definition: QueryOps.h:347
RDKit::makeAtomHeavyAtomDegreeQuery
T * makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr)
returns a Query for matching heavy atom degree
Definition: QueryOps.h:397
RDKit::RecursiveStructureQuery::RecursiveStructureQuery
RecursiveStructureQuery()
Definition: QueryOps.h:696
RDKit::makeXHAtomQuery
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXHAtomQuery()
returns a Query for matching generic XH atoms (halogen or H)
Queries::Query< int, TargetPtr, needsConversion >::getNegation
bool getNegation() const
returns whether or not we are negated
Definition: Query.h:65
RDKit::HasPropWithValueQuery< TargetPtr, ExplicitBitVect >::copy
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:1003
RDKit::Atom::getHybridization
HybridizationType getHybridization() const
returns our hybridization
Definition: Atom.h:246
Queries::Int2Type
class to allow integer values to pick templates
Definition: Query.h:27
RDKit::ATOM_GREATEREQUAL_QUERY
Queries::GreaterEqualQuery< int, Atom const *, true > ATOM_GREATEREQUAL_QUERY
Definition: QueryOps.h:49
RDKit::BOND_GREATEREQUAL_QUERY
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
Definition: QueryOps.h:51
RDKit::Atom::getMass
double getMass() const
returns our mass
RDKit::makeAtomNumAliphaticHeteroatomNbrsQuery
T * makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of aliphatic heteroatom neighbors
Definition: QueryOps.h:600
RDKit::makeAtomHasRingBondQuery
T * makeAtomHasRingBondQuery(const std::string &descr)
returns a Query for matching atoms that have ring bonds
Definition: QueryOps.h:575
Queries::AndQuery
a Query implementing AND: requires all children to be true
Definition: AndQuery.h:22
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::makeAtomSimpleQuery
T * makeAtomSimpleQuery(int what, int func(Atom const *), const std::string &description="Atom Simple")
Definition: QueryOps.h:318
RDKit::HasPropWithValueQuery< TargetPtr, std::string >::copy
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:931
RDKit::HasPropQuery::HasPropQuery
HasPropQuery()
Definition: QueryOps.h:769
RDKit::HasPropWithValueQuery< TargetPtr, ExplicitBitVect >::HasPropWithValueQuery
HasPropWithValueQuery()
Definition: QueryOps.h:949
RDKit::BOND_PROP_QUERY
Queries::EqualityQuery< int, Bond const *, true > BOND_PROP_QUERY
Definition: QueryOps.h:799
Queries::LessQuery
a Query implementing < using a particular value (and an optional tolerance)
Definition: LessQuery.h:22
RDKit::makeAtomHasChiralTagQuery
T * makeAtomHasChiralTagQuery(const std::string &descr)
Definition: QueryOps.h:498
RDKit::queryBondIsInRingOfSize
int queryBondIsInRingOfSize(Bond const *bond)
Definition: QueryOps.h:308
RDKit::makeAtomType
static int makeAtomType(int atomic_num, bool aromatic)
Definition: QueryOps.h:122
RDKit::ATOM_LESSEQUAL_QUERY
Queries::LessEqualQuery< int, Atom const *, true > ATOM_LESSEQUAL_QUERY
Definition: QueryOps.h:56
RDKit::RecursiveStructureQuery::RecursiveStructureQuery
RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber=0)
initialize from an ROMol pointer
Definition: QueryOps.h:706
RDKit::RecursiveStructureQuery::getQueryMol
ROMol const * getQueryMol() const
returns a pointer to our query molecule
Definition: QueryOps.h:726
RDKit::isAtomAromatic
RDKIT_GRAPHMOL_EXPORT bool isAtomAromatic(const Atom *a)
RDKit::ATOM_PROP_QUERY
Queries::EqualityQuery< int, Atom const *, true > ATOM_PROP_QUERY
Definition: QueryOps.h:798
RDKit::RingInfo::isBondInRingOfSize
bool isBondInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the bond with index idx is in a size - ring.
RDKit::ATOM_EQUALS_QUERY
Queries::EqualityQuery< int, Atom const *, true > ATOM_EQUALS_QUERY
Definition: QueryOps.h:42
Queries::GreaterQuery
a Query implementing > using a particular value (and an optional tolerance)
Definition: GreaterQuery.h:22
RDKit::makeQAtomQuery
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeQAtomQuery()
returns a Query for matching generic Q atoms (heteroatoms)
RDKit::queryAtomHCount
static int queryAtomHCount(Atom const *at)
Definition: QueryOps.h:100
RDKit::queryBondHasStereo
static int queryBondHasStereo(Bond const *bnd)
Definition: QueryOps.h:249
RDKit::HasPropWithValueQuery
Definition: QueryOps.h:811
RDKit::RingInfo::isAtomInRingOfSize
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
RDKit::ATOM_LESS_QUERY
Queries::LessQuery< int, Atom const *, true > ATOM_LESS_QUERY
Definition: QueryOps.h:53
RDKit::ATOM_OR_QUERY
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
Definition: QueryOps.h:36
Queries::EqualityQuery::setTol
void setTol(MatchFuncArgType what)
sets our tolerance
Definition: EqualityQuery.h:47
RDKit::queryAtomUnsaturated
static int queryAtomUnsaturated(Atom const *at)
Definition: QueryOps.h:118
RDKit::makeBondDirEqualsQuery
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondDirEqualsQuery(Bond::BondDir what)
returns a Query for matching bond directions
RDKit::AtomRingQuery::Match
virtual bool Match(const ConstAtomPtr what) const
Definition: QueryOps.h:667
PRECONDITION
#define PRECONDITION(expr, mess)
Definition: Invariant.h:110
RDKit::queryAtomImplicitHCount
static int queryAtomImplicitHCount(Atom const *at)
Definition: QueryOps.h:103
RDKit::Atom::getNumRadicalElectrons
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
Definition: Atom.h:200
RDKit::Bond::STEREONONE
@ STEREONONE
Definition: Bond.h:96
RDKit::makeAtomRangeQuery
static ATOM_RANGE_QUERY * makeAtomRangeQuery(int lower, int upper, bool lowerOpen, bool upperOpen, int func(Atom const *), const std::string &description="Atom Range")
Definition: QueryOps.h:327
RDKit::makeAtomFormalChargeQuery
T * makeAtomFormalChargeQuery(int what, const std::string &descr)
returns a Query for matching formal charge
Definition: QueryOps.h:462
BitVects.h
Pulls in all the BitVect classes.
Queries::SetQuery< int, Atom const *, true >
Queries::Query
Base class for all queries.
Definition: Query.h:46
RDKit::ROMol::getTopology
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
Definition: ROMol.h:555
RDKit::Bond::getBondType
BondType getBondType() const
returns our bondType
Definition: Bond.h:121
RDKit::makeAtomTotalValenceQuery
T * makeAtomTotalValenceQuery(int what, const std::string &descr)
returns a Query for matching total valence
Definition: QueryOps.h:373
RDKit::makeAHAtomQuery
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAHAtomQuery()
returns a Query for matching generic AH atoms (any atom)
RDKit::makeBondMinRingSizeQuery
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondMinRingSizeQuery(int what)
returns a Query for matching a bond's minimum ring size
RDKit::queryAtomMissingChiralTag
static int queryAtomMissingChiralTag(Atom const *at)
Definition: QueryOps.h:169
RDKit::AtomRingQuery
Definition: QueryOps.h:653
RDKit::Atom::getIsAromatic
bool getIsAromatic() const
returns our isAromatic flag
Definition: Atom.h:224
RDKit::AtomRingQuery::copy
Queries::Query< int, ConstAtomPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:682
RDKit::getAtomTypeIsAromatic
static bool getAtomTypeIsAromatic(int val)
Definition: QueryOps.h:134
RDKit::BOND_NULL_QUERY
Queries::Query< int, Bond const *, true > BOND_NULL_QUERY
Definition: QueryOps.h:65
RDKit::queryAtomNegativeFormalCharge
static int queryAtomNegativeFormalCharge(Atom const *at)
Definition: QueryOps.h:157
RDKit::makeMAtomQuery
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeMAtomQuery()
returns a Query for matching generic M atoms (metals)
RDKit::makeAtomNumQuery
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
Definition: QueryOps.h:339
RDKit::RDProps::hasProp
bool hasProp(const std::string &key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: RDProps.h:121
RDKit::ATOM_NULL_QUERY
Queries::Query< int, Atom const *, true > ATOM_NULL_QUERY
Definition: QueryOps.h:66
RDKit::ATOM_GREATER_QUERY
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
Definition: QueryOps.h:45
RDKit::queryAtomHasAliphaticHeteroatomNbrs
static int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at)
Definition: QueryOps.h:201
RDKit::queryAtomHeavyAtomDegree
static int queryAtomHeavyAtomDegree(Atom const *at)
Definition: QueryOps.h:86
RDKit::queryAtomHasChiralTag
static int queryAtomHasChiralTag(Atom const *at)
Definition: QueryOps.h:166
RDKit::BOND_LESS_QUERY
Queries::LessQuery< int, Bond const *, true > BOND_LESS_QUERY
Definition: QueryOps.h:54
RDKit::Bond::getOwningMol
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
Definition: Bond.h:149
RDKit::BOND_GREATER_QUERY
Queries::GreaterQuery< int, Bond const *, true > BOND_GREATER_QUERY
Definition: QueryOps.h:46
RDKit::HasPropWithValueQuery< TargetPtr, std::string >
Definition: QueryOps.h:878
RDKit::makeAtomHasAliphaticHeteroatomNbrsQuery
T * makeAtomHasAliphaticHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
Definition: QueryOps.h:610
RDKit::Bond::AROMATIC
@ AROMATIC
Definition: Bond.h:69
RDKit::makeAtomTotalDegreeQuery
T * makeAtomTotalDegreeQuery(int what, const std::string &descr)
returns a Query for matching atomic degree
Definition: QueryOps.h:389
Queries::EqualityQuery
a Query implementing ==: arguments must match a particular value (within an optional tolerance)
Definition: EqualityQuery.h:24
RDKit::massIntegerConversionFactor
const int massIntegerConversionFactor
Definition: QueryOps.h:146
Queries::Query::setDescription
void setDescription(const std::string &descr)
sets our text description
Definition: Query.h:68
RDKit::queryIsBondInNRings
static int queryIsBondInNRings(Bond const *at)
Definition: QueryOps.h:246
RDKit::queryAtomExplicitValence
static int queryAtomExplicitValence(Atom const *at)
Definition: QueryOps.h:112
RDKit::BOND_BOOL_QUERY
Queries::Query< bool, Bond const *, true > BOND_BOOL_QUERY
Definition: QueryOps.h:31
RDKit::queryAtomNumRadicalElectrons
static int queryAtomNumRadicalElectrons(Atom const *at)
Definition: QueryOps.h:163
Queries::GreaterEqualQuery
a Query implementing >= using a particular value (and an optional tolerance)
Definition: GreaterEqualQuery.h:22
RDKit::makeBondIsInRingQuery
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondIsInRingQuery()
returns a Query for matching ring bonds
RDKit::queryAtomExplicitDegree
static int queryAtomExplicitDegree(Atom const *at)
Definition: QueryOps.h:77
RDKit::Bond::BondDir
BondDir
the bond's direction (for chirality)
Definition: Bond.h:83
Queries::LessEqualQuery
a Query implementing <= using a particular value (and an optional tolerance)
Definition: LessEqualQuery.h:22
RDKit::BOND_RANGE_QUERY
Queries::RangeQuery< int, Bond const *, true > BOND_RANGE_QUERY
Definition: QueryOps.h:60
RDKit::RingInfo::minAtomRingSize
unsigned int minAtomRingSize(unsigned int idx) const
returns the size of the smallest ring atom idx is involved in
RDKit::HasPropWithValueQuery< TargetPtr, ExplicitBitVect >
Definition: QueryOps.h:943
RDKit::HasPropWithValueQuery::copy
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:867
RDKit::BOND_OR_QUERY
Queries::OrQuery< int, Bond const *, true > BOND_OR_QUERY
Definition: QueryOps.h:37
RDKit::HasPropWithValueQuery< TargetPtr, std::string >::HasPropWithValueQuery
HasPropWithValueQuery()
Definition: QueryOps.h:883
RDKit::common_properties::_ChiralityPossible
RDKIT_RDGENERAL_EXPORT const std::string _ChiralityPossible
ExplicitBitVect
a class for bit vectors that are densely occupied
Definition: ExplicitBitVect.h:29
export.h