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>(round(massIntegerConversionFactor * at->getMass()));
149 };
150 static inline int queryAtomIsotope(Atom const *at) {
151  return static_cast<int>(at->getIsotope());
152 };
153 static inline int queryAtomFormalCharge(Atom const *at) {
154  return static_cast<int>(at->getFormalCharge());
155 };
156 static inline int queryAtomNegativeFormalCharge(Atom const *at) {
157  return static_cast<int>(-1 * at->getFormalCharge());
158 };
159 static inline int queryAtomHybridization(Atom const *at) {
160  return at->getHybridization();
161 };
162 static inline int queryAtomNumRadicalElectrons(Atom const *at) {
163  return at->getNumRadicalElectrons();
164 };
165 static inline int queryAtomHasChiralTag(Atom const *at) {
166  return at->getChiralTag() != Atom::CHI_UNSPECIFIED;
167 };
168 static inline int queryAtomMissingChiralTag(Atom const *at) {
169  return at->getChiralTag() == Atom::CHI_UNSPECIFIED &&
171 };
172 
173 static inline int queryAtomHasHeteroatomNbrs(Atom const *at) {
174  ROMol::ADJ_ITER nbrIdx, endNbrs;
175  boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
176  while (nbrIdx != endNbrs) {
177  const Atom *nbr = at->getOwningMol()[*nbrIdx];
178  if (nbr->getAtomicNum() != 6 && nbr->getAtomicNum() != 1) {
179  return 1;
180  }
181  ++nbrIdx;
182  }
183  return 0;
184 };
185 
186 static inline int queryAtomNumHeteroatomNbrs(Atom const *at) {
187  int res = 0;
188  ROMol::ADJ_ITER nbrIdx, endNbrs;
189  boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
190  while (nbrIdx != endNbrs) {
191  const Atom *nbr = at->getOwningMol()[*nbrIdx];
192  if (nbr->getAtomicNum() != 6 && nbr->getAtomicNum() != 1) {
193  ++res;
194  }
195  ++nbrIdx;
196  }
197  return res;
198 };
199 
200 static inline int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at) {
201  ROMol::ADJ_ITER nbrIdx, endNbrs;
202  boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
203  while (nbrIdx != endNbrs) {
204  const Atom *nbr = at->getOwningMol()[*nbrIdx];
205  if ((!nbr->getIsAromatic()) && nbr->getAtomicNum() != 6 &&
206  nbr->getAtomicNum() != 1) {
207  return 1;
208  }
209  ++nbrIdx;
210  }
211  return 0;
212 };
213 
214 static inline int queryAtomNumAliphaticHeteroatomNbrs(Atom const *at) {
215  int res = 0;
216  ROMol::ADJ_ITER nbrIdx, endNbrs;
217  boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
218  while (nbrIdx != endNbrs) {
219  const Atom *nbr = at->getOwningMol()[*nbrIdx];
220  if ((!nbr->getIsAromatic()) && nbr->getAtomicNum() != 6 &&
221  nbr->getAtomicNum() != 1) {
222  ++res;
223  }
224  ++nbrIdx;
225  }
226  return res;
227 };
228 
229 RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomBondProduct(Atom const *at);
230 RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomAllBondProduct(Atom const *at);
231 
232 // -------------------------------------------------
233 // common bond queries
234 
235 static inline int queryBondOrder(Bond const *bond) {
236  return static_cast<int>(bond->getBondType());
237 };
238 static inline int queryBondIsSingleOrAromatic(Bond const *bond) {
239  return static_cast<int>(bond->getBondType() == Bond::SINGLE ||
240  bond->getBondType() == Bond::AROMATIC);
241 };
242 static inline int queryBondDir(Bond const *bond) {
243  return static_cast<int>(bond->getBondDir());
244 };
245 static inline int queryIsBondInNRings(Bond const *at) {
246  return at->getOwningMol().getRingInfo()->numBondRings(at->getIdx());
247 };
248 static inline int queryBondHasStereo(Bond const *bnd) {
249  return bnd->getStereo() > Bond::STEREONONE;
250 };
251 
252 // -------------------------------------------------
253 // ring queries
254 
255 static inline int queryIsAtomInNRings(Atom const *at) {
256  return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx());
257 };
258 static inline int queryIsAtomInRing(Atom const *at) {
259  return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx()) != 0;
260 };
261 static inline int queryAtomHasRingBond(Atom const *at) {
262  ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
263  while (atomBonds.first != atomBonds.second) {
264  unsigned int bondIdx =
265  at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
266  if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
267  return 1;
268  }
269  ++atomBonds.first;
270  }
271  return 0;
272 };
273 static inline int queryIsBondInRing(Bond const *bond) {
274  return bond->getOwningMol().getRingInfo()->numBondRings(bond->getIdx()) != 0;
275 };
276 static inline int queryAtomMinRingSize(Atom const *at) {
277  return at->getOwningMol().getRingInfo()->minAtomRingSize(at->getIdx());
278 };
279 static inline int queryBondMinRingSize(Bond const *bond) {
280  return bond->getOwningMol().getRingInfo()->minBondRingSize(bond->getIdx());
281 };
282 
283 static inline int queryAtomRingBondCount(Atom const *at) {
284  // EFF: cache this result
285  int res = 0;
286  ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
287  while (atomBonds.first != atomBonds.second) {
288  unsigned int bondIdx =
289  at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
290  if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
291  res++;
292  }
293  ++atomBonds.first;
294  }
295  return res;
296 }
297 
298 template <int tgt>
300  if (at->getOwningMol().getRingInfo()->isAtomInRingOfSize(at->getIdx(), tgt)) {
301  return tgt;
302  } else {
303  return 0;
304  }
305 };
306 template <int tgt>
307 int queryBondIsInRingOfSize(Bond const *bond) {
308  if (bond->getOwningMol().getRingInfo()->isBondInRingOfSize(bond->getIdx(),
309  tgt)) {
310  return tgt;
311  } else {
312  return 0;
313  }
314 };
315 
316 template <class T>
317 T *makeAtomSimpleQuery(int what, int func(Atom const *),
318  const std::string &description = "Atom Simple") {
319  T *res = new T;
320  res->setVal(what);
321  res->setDataFunc(func);
322  res->setDescription(description);
323  return res;
324 }
325 
327  int lower, int upper, bool lowerOpen, bool upperOpen,
328  int func(Atom const *), const std::string &description = "Atom Range") {
329  ATOM_RANGE_QUERY *res = new ATOM_RANGE_QUERY(lower, upper);
330  res->setDataFunc(func);
331  res->setDescription(description);
332  res->setEndsOpen(lowerOpen, upperOpen);
333  return res;
334 }
335 
336 //! returns a Query for matching atomic number
337 template <class T>
338 T *makeAtomNumQuery(int what, const std::string &descr) {
339  return makeAtomSimpleQuery<T>(what, queryAtomNum, descr);
340 }
341 //! \overload
343 
344 //! returns a Query for matching atomic number and aromaticity
345 template <class T>
346 T *makeAtomTypeQuery(int num, int aromatic, const std::string &descr) {
347  return makeAtomSimpleQuery<T>(makeAtomType(num, aromatic), queryAtomType,
348  descr);
349 }
350 //! \overload
352  int aromatic);
353 
354 //! returns a Query for matching implicit valence
355 template <class T>
356 T *makeAtomImplicitValenceQuery(int what, const std::string &descr) {
357  return makeAtomSimpleQuery<T>(what, queryAtomImplicitValence, descr);
358 }
359 //! \overload
361 
362 //! returns a Query for matching explicit valence
363 template <class T>
364 T *makeAtomExplicitValenceQuery(int what, const std::string &descr) {
365  return makeAtomSimpleQuery<T>(what, queryAtomExplicitValence, descr);
366 }
367 //! \overload
369 
370 //! returns a Query for matching total valence
371 template <class T>
372 T *makeAtomTotalValenceQuery(int what, const std::string &descr) {
373  return makeAtomSimpleQuery<T>(what, queryAtomTotalValence, descr);
374 }
375 //! \overload
377 
378 //! returns a Query for matching explicit degree
379 template <class T>
380 T *makeAtomExplicitDegreeQuery(int what, const std::string &descr) {
381  return makeAtomSimpleQuery<T>(what, queryAtomExplicitDegree, descr);
382 }
383 //! \overload
385 
386 //! returns a Query for matching atomic degree
387 template <class T>
388 T *makeAtomTotalDegreeQuery(int what, const std::string &descr) {
389  return makeAtomSimpleQuery<T>(what, queryAtomTotalDegree, descr);
390 }
391 //! \overload
393 
394 //! returns a Query for matching heavy atom degree
395 template <class T>
396 T *makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr) {
397  return makeAtomSimpleQuery<T>(what, queryAtomHeavyAtomDegree, descr);
398 }
399 //! \overload
401 
402 //! returns a Query for matching hydrogen count
403 template <class T>
404 T *makeAtomHCountQuery(int what, const std::string &descr) {
405  return makeAtomSimpleQuery<T>(what, queryAtomHCount, descr);
406 }
407 //! \overload
409 
410 //! returns a Query for matching ring atoms
411 template <class T>
412 T *makeAtomHasImplicitHQuery(const std::string &descr) {
413  return makeAtomSimpleQuery<T>(true, queryAtomHasImplicitH, descr);
414 }
415 //! \overload
417 
418 //! returns a Query for matching implicit hydrogen count
419 template <class T>
420 T *makeAtomImplicitHCountQuery(int what, const std::string &descr) {
421  return makeAtomSimpleQuery<T>(what, queryAtomImplicitHCount, descr);
422 }
423 //! \overload
425 
426 //! returns a Query for matching the \c isAromatic flag
427 template <class T>
428 T *makeAtomAromaticQuery(const std::string &descr) {
429  return makeAtomSimpleQuery<T>(true, queryAtomAromatic, descr);
430 }
431 //! \overload
433 
434 //! returns a Query for matching aliphatic atoms
435 template <class T>
436 T *makeAtomAliphaticQuery(const std::string &descr) {
437  return makeAtomSimpleQuery<T>(true, queryAtomAliphatic, descr);
438 }
439 //! \overload
441 
442 //! returns a Query for matching atoms with a particular mass
443 template <class T>
444 T *makeAtomMassQuery(int what, const std::string &descr) {
445  return makeAtomSimpleQuery<T>(massIntegerConversionFactor * what,
446  queryAtomMass, descr);
447 }
448 //! \overload
450 
451 //! returns a Query for matching atoms with a particular isotope
452 template <class T>
453 T *makeAtomIsotopeQuery(int what, const std::string &descr) {
454  return makeAtomSimpleQuery<T>(what, queryAtomIsotope, descr);
455 }
456 //! \overload
458 
459 //! returns a Query for matching formal charge
460 template <class T>
461 T *makeAtomFormalChargeQuery(int what, const std::string &descr) {
462  return makeAtomSimpleQuery<T>(what, queryAtomFormalCharge, descr);
463 }
464 //! \overload
466 
467 //! returns a Query for matching negative formal charges (i.e. a query val of 1
468 //! matches a formal charge of -1)
469 template <class T>
470 T *makeAtomNegativeFormalChargeQuery(int what, const std::string &descr) {
471  return makeAtomSimpleQuery<T>(what, queryAtomNegativeFormalCharge, descr);
472 }
473 //! \overload
475  int what);
476 
477 //! returns a Query for matching hybridization
478 template <class T>
479 T *makeAtomHybridizationQuery(int what, const std::string &descr) {
480  return makeAtomSimpleQuery<T>(what, queryAtomHybridization, descr);
481 }
482 //! \overload
484 
485 //! returns a Query for matching the number of radical electrons
486 template <class T>
487 T *makeAtomNumRadicalElectronsQuery(int what, const std::string &descr) {
488  return makeAtomSimpleQuery<T>(what, queryAtomNumRadicalElectrons, descr);
489 }
490 //! \overload
492  int what);
493 
494 //! returns a Query for matching whether or not chirality has been set on the
495 //! atom
496 template <class T>
497 T *makeAtomHasChiralTagQuery(const std::string &descr) {
498  return makeAtomSimpleQuery<T>(true, queryAtomHasChiralTag, descr);
499 }
500 //! \overloadquery
502 
503 //! returns a Query for matching whether or not a potentially chiral atom is
504 //! missing a chiral tag
505 template <class T>
506 T *makeAtomMissingChiralTagQuery(const std::string &descr) {
507  return makeAtomSimpleQuery<T>(true, queryAtomMissingChiralTag, descr);
508 }
509 //! \overloadquery
511 
512 //! returns a Query for matching atoms with unsaturation:
513 template <class T>
514 T *makeAtomUnsaturatedQuery(const std::string &descr) {
515  return makeAtomSimpleQuery<T>(true, queryAtomUnsaturated, descr);
516 }
517 //! \overload
519 
520 //! returns a Query for matching ring atoms
521 template <class T>
522 T *makeAtomInRingQuery(const std::string &descr) {
523  return makeAtomSimpleQuery<T>(true, queryIsAtomInRing, descr);
524 }
526 //! \overload
527 
528 //! returns a Query for matching atoms in a particular number of rings
529 template <class T>
530 T *makeAtomInNRingsQuery(int what, const std::string &descr) {
531  return makeAtomSimpleQuery<T>(what, queryIsAtomInNRings, descr);
532 }
533 //! \overload
535 
536 //! returns a Query for matching atoms in rings of a particular size
538 
539 //! returns a Query for matching an atom's minimum ring size
540 template <class T>
541 T *makeAtomMinRingSizeQuery(int tgt, const std::string &descr) {
542  return makeAtomSimpleQuery<T>(tgt, queryAtomMinRingSize, descr);
543 }
544 //! \overload
546 
547 //! returns a Query for matching atoms with a particular number of ring bonds
548 template <class T>
549 T *makeAtomRingBondCountQuery(int what, const std::string &descr) {
550  return makeAtomSimpleQuery<T>(what, queryAtomRingBondCount, descr);
551 }
552 //! \overload
554 
555 //! returns a Query for matching generic A atoms (heavy atoms)
557 //! returns a Query for matching generic AH atoms (any atom)
559 //! returns a Query for matching generic Q atoms (heteroatoms)
561 //! returns a Query for matching generic QH atoms (heteroatom or H)
563 //! returns a Query for matching generic X atoms (halogens)
565 //! returns a Query for matching generic XH atoms (halogen or H)
567 //! returns a Query for matching generic M atoms (metals)
569 //! returns a Query for matching generic MH atoms (metals or H)
571 
572 //! returns a Query for matching atoms that have ring bonds
573 template <class T>
574 T *makeAtomHasRingBondQuery(const std::string &descr) {
575  return makeAtomSimpleQuery<T>(1, queryAtomHasRingBond, descr);
576 }
577 //! \overload
579 
580 //! returns a Query for matching the number of heteroatom neighbors
581 template <class T>
582 T *makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr) {
583  return makeAtomSimpleQuery<T>(what, queryAtomNumHeteroatomNbrs, descr);
584 }
585 //! \overload
587  int what);
588 
589 //! returns a Query for matching atoms that have heteroatom neighbors
590 template <class T>
591 T *makeAtomHasHeteroatomNbrsQuery(const std::string &descr) {
592  return makeAtomSimpleQuery<T>(1, queryAtomHasHeteroatomNbrs, descr);
593 }
594 //! \overload
596 
597 //! returns a Query for matching the number of aliphatic heteroatom neighbors
598 template <class T>
599 T *makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr) {
600  return makeAtomSimpleQuery<T>(what, queryAtomNumAliphaticHeteroatomNbrs,
601  descr);
602 }
603 //! \overload
606 
607 //! returns a Query for matching atoms that have heteroatom neighbors
608 template <class T>
609 T *makeAtomHasAliphaticHeteroatomNbrsQuery(const std::string &descr) {
610  return makeAtomSimpleQuery<T>(1, queryAtomHasAliphaticHeteroatomNbrs, descr);
611 }
612 //! \overload
615 
616 //! returns a Query for matching bond orders
618  Bond::BondType what);
619 //! returns a Query for unspecified SMARTS bonds
621 //! returns a Query for matching bond directions
623  Bond::BondDir what);
624 //! returns a Query for matching bonds with stereo set
626 //! returns a Query for matching ring bonds
628 //! returns a Query for matching bonds in rings of a particular size
630 //! returns a Query for matching a bond's minimum ring size
632 //! returns a Query for matching bonds in a particular number of rings
634 
635 //! returns a Query for matching any bond
637 //! returns a Query for matching any atom
639 
640 static inline int queryAtomRingMembership(Atom const *at) {
641  return static_cast<int>(
642  at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx()));
643 }
644 // I'm pretty sure that this typedef shouldn't be necessary,
645 // but VC++ generates a warning about const Atom const * in
646 // the definition of Match, then complains about an override
647 // that differs only by const/volatile (c4301), then generates
648 // incorrect code if we don't do this... so let's do it.
649 typedef Atom const *ConstAtomPtr;
650 
652  : public Queries::EqualityQuery<int, ConstAtomPtr, true> {
653  public:
654  AtomRingQuery() : Queries::EqualityQuery<int, ConstAtomPtr, true>(-1) {
655  // default is to just do a number of rings query:
656  this->setDescription("AtomInNRings");
657  this->setDataFunc(queryAtomRingMembership);
658  };
659  explicit AtomRingQuery(int v)
660  : Queries::EqualityQuery<int, ConstAtomPtr, true>(v) {
661  // default is to just do a number of rings query:
662  this->setDescription("AtomInNRings");
663  this->setDataFunc(queryAtomRingMembership);
664  };
665 
666  virtual bool Match(const ConstAtomPtr what) const {
667  int v = this->TypeConvert(what, Queries::Int2Type<true>());
668  bool res;
669  if (this->d_val < 0) {
670  res = v != 0;
671  } else {
672  res = !Queries::queryCmp(v, this->d_val, this->d_tol);
673  }
674  if (this->getNegation()) {
675  res = !res;
676  }
677  return res;
678  }
679 
680  //! returns a copy of this query
682  AtomRingQuery *res = new AtomRingQuery(this->d_val);
683  res->setNegation(getNegation());
684  res->setTol(this->getTol());
685  res->d_description = this->d_description;
686  res->d_dataFunc = this->d_dataFunc;
687  return res;
688  }
689 };
690 
691 //! allows use of recursive structure queries (e.g. recursive SMARTS)
693  : public Queries::SetQuery<int, Atom const *, true> {
694  public:
696  : Queries::SetQuery<int, Atom const *, true>(), d_serialNumber(0) {
697  setDataFunc(getAtIdx);
698  setDescription("RecursiveStructure");
699  };
700  //! initialize from an ROMol pointer
701  /*!
702  <b>Notes</b>
703  - this takes over ownership of the pointer
704  */
705  RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber = 0)
706  : Queries::SetQuery<int, Atom const *, true>(),
707  d_serialNumber(serialNumber) {
708  setQueryMol(query);
709  setDataFunc(getAtIdx);
710  setDescription("RecursiveStructure");
711  };
712  //! returns the index of an atom
713  static inline int getAtIdx(Atom const *at) {
714  PRECONDITION(at, "bad atom argument");
715  return at->getIdx();
716  };
717 
718  //! sets the molecule we'll use recursively
719  /*!
720  <b>Notes</b>
721  - this takes over ownership of the pointer
722  */
723  void setQueryMol(ROMol const *query) { dp_queryMol.reset(query); }
724  //! returns a pointer to our query molecule
725  ROMol const *getQueryMol() const { return dp_queryMol.get(); };
726 
727  //! returns a copy of this query
730  res->dp_queryMol.reset(new ROMol(*dp_queryMol, true));
731 
732  std::set<int>::const_iterator i;
733  for (i = d_set.begin(); i != d_set.end(); i++) {
734  res->insert(*i);
735  }
736  res->setNegation(getNegation());
737  res->d_description = d_description;
738  res->d_serialNumber = d_serialNumber;
739  return res;
740  }
741  unsigned int getSerialNumber() const { return d_serialNumber; };
742 
743 #ifdef RDK_THREADSAFE_SSS
744  std::mutex d_mutex;
745 #endif
746  private:
747  boost::shared_ptr<const ROMol> dp_queryMol;
748  unsigned int d_serialNumber;
749 };
750 
751 template <typename T>
752 int nullDataFun(T) {
753  return 1;
754 }
755 template <typename T>
756 bool nullQueryFun(T) {
757  return true;
758 }
759 
760 typedef Bond const *ConstBondPtr;
761 
762 // ! Query whether an atom has a property
763 template <class TargetPtr>
764 class HasPropQuery : public Queries::EqualityQuery<int, TargetPtr, true> {
765  std::string propname;
766 
767  public:
768  HasPropQuery() : Queries::EqualityQuery<int, TargetPtr, true>(), propname() {
769  // default is to just do a number of rings query:
770  this->setDescription("AtomHasProp");
771  this->setDataFunc(0);
772  };
773  explicit HasPropQuery(const std::string &v)
774  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(v) {
775  // default is to just do a number of rings query:
776  this->setDescription("AtomHasProp");
777  this->setDataFunc(0);
778  };
779 
780  virtual bool Match(const TargetPtr what) const {
781  bool res = what->hasProp(propname);
782  if (this->getNegation()) {
783  res = !res;
784  }
785  return res;
786  }
787 
788  //! returns a copy of this query
790  HasPropQuery *res = new HasPropQuery(this->propname);
791  res->setNegation(this->getNegation());
792  res->d_description = this->d_description;
793  return res;
794  }
795 };
796 
799 
800 //! returns a Query for matching atoms that have a particular property
801 template <class Target>
803  const std::string &property) {
804  return new HasPropQuery<const Target *>(property);
805 }
806 
807 // ! Query whether an atom has a property with a value
808 template <class TargetPtr, class T>
810  : public Queries::EqualityQuery<int, TargetPtr, true> {
811  std::string propname;
812  T val;
813  T tolerance;
814 
815  public:
817  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
818  // default is to just do a number of rings query:
819  this->setDescription("HasPropWithValue");
820  this->setDataFunc(0);
821  };
822  explicit HasPropWithValueQuery(const std::string &prop, const T &v,
823  const T &tol = 0.0)
824  : Queries::EqualityQuery<int, TargetPtr, true>(),
825  propname(prop),
826  val(v),
827  tolerance(tol) {
828  // default is to just do a number of rings query:
829  this->setDescription("HasPropWithValue");
830  this->setDataFunc(0);
831  };
832 
833  virtual bool Match(const TargetPtr what) const {
834  bool res = what->hasProp(propname);
835  if (res) {
836  try {
837  T atom_val = what->template getProp<T>(propname);
838  res = Queries::queryCmp(atom_val, this->val, this->tolerance) == 0;
839  } catch (KeyErrorException &) {
840  res = false;
841  } catch (boost::bad_any_cast &) {
842  res = false;
843  }
844 #ifdef __GNUC__
845 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
846  catch (...) {
847  // catch all -- this is currently necessary to
848  // trap some bugs in boost+gcc configurations
849  // Normally, this is not the correct thing to
850  // do, but the only exception above is due
851  // to the boost any_cast which is trapped
852  // by the Boost python wrapper when it shouldn't
853  // be.
854  res = false;
855  }
856 #endif
857 #endif
858  }
859  if (this->getNegation()) {
860  res = !res;
861  }
862  return res;
863  }
864 
865  //! returns a copy of this query
867  HasPropWithValueQuery *res =
868  new HasPropWithValueQuery(this->propname, this->val, this->tolerance);
869  res->setNegation(this->getNegation());
870  res->d_description = this->d_description;
871  return res;
872  }
873 };
874 
875 template <class TargetPtr>
876 class HasPropWithValueQuery<TargetPtr, std::string>
877  : public Queries::EqualityQuery<int, TargetPtr, true> {
878  std::string propname;
879  std::string val;
880 
881  public:
883  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
884  // default is to just do a number of rings query:
885  this->setDescription("HasPropWithValue");
886  this->setDataFunc(0);
887  };
888  explicit HasPropWithValueQuery(const std::string &prop, const std::string &v,
889  const std::string &tol = "")
890  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(prop), val(v) {
891  RDUNUSED_PARAM(tol);
892  // default is to just do a number of rings query:
893  this->setDescription("HasPropWithValue");
894  this->setDataFunc(0);
895  };
896 
897  virtual bool Match(const TargetPtr what) const {
898  bool res = what->hasProp(propname);
899  if (res) {
900  try {
901  std::string atom_val = what->template getProp<std::string>(propname);
902  res = atom_val == this->val;
903  } catch (KeyErrorException &) {
904  res = false;
905  } catch (boost::bad_any_cast &) {
906  res = false;
907  }
908 #ifdef __GNUC__
909 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
910  catch (...) {
911  // catch all -- this is currently necessary to
912  // trap some bugs in boost+gcc configurations
913  // Normally, this is not the correct thing to
914  // do, but the only exception above is due
915  // to the boost any_cast which is trapped
916  // by the Boost python wrapper when it shouldn't
917  // be.
918  res = false;
919  }
920 #endif
921 #endif
922  }
923  if (this->getNegation()) {
924  res = !res;
925  }
926  return res;
927  }
928 
929  //! returns a copy of this query
933  this->val);
934  res->setNegation(this->getNegation());
935  res->d_description = this->d_description;
936  return res;
937  }
938 };
939 
940 template <class TargetPtr>
942  : public Queries::EqualityQuery<int, TargetPtr, true> {
943  std::string propname;
944  ExplicitBitVect val;
945  float tol;
946 
947  public:
949  : Queries::EqualityQuery<int, TargetPtr, true>(),
950  propname(),
951  val(),
952  tol(0.0) {
953  this->setDescription("HasPropWithValue");
954  this->setDataFunc(0);
955  };
956 
957  explicit HasPropWithValueQuery(const std::string &prop,
958  const ExplicitBitVect &v, float tol = 0.0)
959  : Queries::EqualityQuery<int, TargetPtr, true>(),
960  propname(prop),
961  val(v),
962  tol(tol) {
963  this->setDescription("HasPropWithValue");
964  this->setDataFunc(0);
965  };
966 
967  virtual bool Match(const TargetPtr what) const {
968  bool res = what->hasProp(propname);
969  if (res) {
970  try {
971  const ExplicitBitVect &bv =
972  what->template getProp<const ExplicitBitVect &>(propname);
973  const double tani = TanimotoSimilarity(val, bv);
974  res = (1.0 - tani) <= tol;
975  } catch (KeyErrorException &) {
976  res = false;
977  } catch (boost::bad_any_cast &) {
978  res = false;
979  }
980 #ifdef __GNUC__
981 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
982  catch (...) {
983  // catch all -- this is currently necessary to
984  // trap some bugs in boost+gcc configurations
985  // Normally, this is not the correct thing to
986  // do, but the only exception above is due
987  // to the boost any_cast which is trapped
988  // by the Boost python wrapper when it shouldn't
989  // be.
990  res = false;
991  }
992 #endif
993 #endif
994  }
995  if (this->getNegation()) {
996  res = !res;
997  }
998  return res;
999  }
1000 
1001  //! returns a copy of this query
1005  this->propname, this->val, this->tol);
1006  res->setNegation(this->getNegation());
1007  res->d_description = this->d_description;
1008  return res;
1009  }
1010 };
1011 
1012 template <class Target, class T>
1014  const std::string &propname, const T &val, const T &tolerance = T()) {
1015  return new HasPropWithValueQuery<const Target *, T>(propname, val, tolerance);
1016 }
1017 
1018 template <class Target>
1020  const std::string &propname, const ExplicitBitVect &val,
1021  float tolerance = 0.0) {
1023  propname, val, tolerance);
1024 }
1025 
1026 RDKIT_GRAPHMOL_EXPORT bool isComplexQuery(const Bond *b);
1027 RDKIT_GRAPHMOL_EXPORT bool isComplexQuery(const Atom *a);
1028 RDKIT_GRAPHMOL_EXPORT bool isAtomAromatic(const Atom *a);
1029 }; // namespace RDKit
1030 
1031 #endif
RDKit::TanimotoSimilarity
double TanimotoSimilarity(const SparseIntVect< IndexType > &v1, const SparseIntVect< IndexType > &v2, bool returnDistance=false, double bounds=0.0)
Definition: SparseIntVect.h:541
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:186
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:1013
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:822
RDKit::queryAtomRingBondCount
static int queryAtomRingBondCount(Atom const *at)
Definition: QueryOps.h:283
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:479
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:153
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:273
RDKit::RecursiveStructureQuery::getAtIdx
static int getAtIdx(Atom const *at)
returns the index of an atom
Definition: QueryOps.h:713
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 explict 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:444
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::RecursiveStructureQuery::getQueryMol
const ROMol * getQueryMol() const
returns a pointer to our query molecule
Definition: QueryOps.h:725
RDKit::makeAtomHasHeteroatomNbrsQuery
T * makeAtomHasHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
Definition: QueryOps.h:591
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:957
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:654
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:780
RDKit::HasPropWithValueQuery< TargetPtr, std::string >::Match
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Definition: QueryOps.h:897
RDKit::HasPropWithValueQuery::HasPropWithValueQuery
HasPropWithValueQuery()
Definition: QueryOps.h:816
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:404
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:789
RDKit::queryAtomHasRingBond
static int queryAtomHasRingBond(Atom const *at)
Definition: QueryOps.h:261
RDKit::HasPropQuery::HasPropQuery
HasPropQuery(const std::string &v)
Definition: QueryOps.h:773
RDKit::makeAtomUnsaturatedQuery
T * makeAtomUnsaturatedQuery(const std::string &descr)
returns a Query for matching atoms with unsaturation:
Definition: QueryOps.h:514
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:279
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:49
Queries::Query::d_dataFunc
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition: Query.h:158
RDKit::ConstBondPtr
const Bond * ConstBondPtr
Definition: QueryOps.h:760
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:530
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:196
Query.h
RDKit::queryAtomIsotope
static int queryAtomIsotope(Atom const *at)
Definition: QueryOps.h:150
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:276
RDKit::makeAtomNumHeteroatomNbrsQuery
T * makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of heteroatom neighbors
Definition: QueryOps.h:582
RDKit::makeAtomExplicitDegreeQuery
T * makeAtomExplicitDegreeQuery(int what, const std::string &descr)
returns a Query for matching explicit degree
Definition: QueryOps.h:380
RDKit::RecursiveStructureQuery::copy
Queries::Query< int, Atom const *, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:728
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:420
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:453
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:173
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:692
Queries::RangeQuery
a Query implementing a range: arguments must fall in a particular range of values.
Definition: RangeQuery.h:27
RDKit::makeAtomMissingChiralTagQuery
T * makeAtomMissingChiralTagQuery(const std::string &descr)
Definition: QueryOps.h:506
Queries::OrQuery
a Query implementing AND: requires any child to be true
Definition: OrQuery.h:20
RDKit::queryBondOrder
static int queryBondOrder(Bond const *bond)
Definition: QueryOps.h:235
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:364
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:299
RDKitBase.h
pulls in the core RDKit functionality
RDKit::queryBondIsSingleOrAromatic
static int queryBondIsSingleOrAromatic(Bond const *bond)
Definition: QueryOps.h:238
Queries
Definition: AndQuery.h:16
RDKit::HasPropQuery
Definition: QueryOps.h:764
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:888
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:549
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:258
Queries::XOrQuery
a Query implementing XOR: requires exactly one child to be true
Definition: XOrQuery.h:21
RDKit::AtomRingQuery::AtomRingQuery
AtomRingQuery(int v)
Definition: QueryOps.h:659
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:255
RDKit::nullDataFun
int nullDataFun(T)
Definition: QueryOps.h:752
RDKit::RecursiveStructureQuery::setQueryMol
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
Definition: QueryOps.h:723
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:967
RDKit::common_properties::_ChiralityPossible
const RDKIT_RDGENERAL_EXPORT std::string _ChiralityPossible
RDKit::makeAtomMinRingSizeQuery
T * makeAtomMinRingSizeQuery(int tgt, const std::string &descr)
returns a Query for matching an atom's minimum ring size
Definition: QueryOps.h:541
RDKit::queryAtomRingMembership
static int queryAtomRingMembership(Atom const *at)
Definition: QueryOps.h:640
RDKit::makeAtomAliphaticQuery
T * makeAtomAliphaticQuery(const std::string &descr)
returns a Query for matching aliphatic atoms
Definition: QueryOps.h:436
RDKit::ConstAtomPtr
const Atom * ConstAtomPtr
Definition: QueryOps.h:649
RDKit::makeAtomImplicitValenceQuery
T * makeAtomImplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching implicit valence
Definition: QueryOps.h:356
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::round
RDKIT_RDGENERAL_EXPORT double round(double v)
rounds a value to the closest int
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:833
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:756
RDKit::queryAtomHybridization
static int queryAtomHybridization(Atom const *at)
Definition: QueryOps.h:159
RDKit::RecursiveStructureQuery::getSerialNumber
unsigned int getSerialNumber() const
Definition: QueryOps.h:741
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:214
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:802
RDKit::makeAtomAromaticQuery
T * makeAtomAromaticQuery(const std::string &descr)
returns a Query for matching the isAromatic flag
Definition: QueryOps.h:428
RDKit::makeAtomInRingQuery
T * makeAtomInRingQuery(const std::string &descr)
returns a Query for matching ring atoms
Definition: QueryOps.h:522
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:470
RDKit::makeAtomHasImplicitHQuery
T * makeAtomHasImplicitHQuery(const std::string &descr)
returns a Query for matching ring atoms
Definition: QueryOps.h:412
RDKit::queryBondDir
static int queryBondDir(Bond const *bond)
Definition: QueryOps.h:242
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:487
RDKit::makeAtomTypeQuery
T * makeAtomTypeQuery(int num, int aromatic, const std::string &descr)
returns a Query for matching atomic number and aromaticity
Definition: QueryOps.h:346
RDKit::makeAtomHeavyAtomDegreeQuery
T * makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr)
returns a Query for matching heavy atom degree
Definition: QueryOps.h:396
RDKit::RecursiveStructureQuery::RecursiveStructureQuery
RecursiveStructureQuery()
Definition: QueryOps.h:695
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:1002
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:599
RDKit::makeAtomHasRingBondQuery
T * makeAtomHasRingBondQuery(const std::string &descr)
returns a Query for matching atoms that have ring bonds
Definition: QueryOps.h:574
Queries::AndQuery
a Query implementing AND: requires all children to be true
Definition: AndQuery.h:21
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:317
RDKit::HasPropWithValueQuery< TargetPtr, std::string >::copy
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:930
RDKit::HasPropQuery::HasPropQuery
HasPropQuery()
Definition: QueryOps.h:768
RDKit::HasPropWithValueQuery< TargetPtr, ExplicitBitVect >::HasPropWithValueQuery
HasPropWithValueQuery()
Definition: QueryOps.h:948
RDKit::BOND_PROP_QUERY
Queries::EqualityQuery< int, Bond const *, true > BOND_PROP_QUERY
Definition: QueryOps.h:798
Queries::LessQuery
a Query implementing < using a particular value (and an optional tolerance)
Definition: LessQuery.h:21
RDKit::makeAtomHasChiralTagQuery
T * makeAtomHasChiralTagQuery(const std::string &descr)
Definition: QueryOps.h:497
RDKit::queryBondIsInRingOfSize
int queryBondIsInRingOfSize(Bond const *bond)
Definition: QueryOps.h:307
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:705
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:797
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:21
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:248
RDKit::HasPropWithValueQuery
Definition: QueryOps.h:809
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:666
PRECONDITION
#define PRECONDITION(expr, mess)
Definition: Invariant.h:109
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:326
RDKit::makeAtomFormalChargeQuery
T * makeAtomFormalChargeQuery(int what, const std::string &descr)
returns a Query for matching formal charge
Definition: QueryOps.h:461
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::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:372
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:168
RDKit::AtomRingQuery
Definition: QueryOps.h:651
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:681
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:156
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:338
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:118
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:200
RDKit::queryAtomHeavyAtomDegree
static int queryAtomHeavyAtomDegree(Atom const *at)
Definition: QueryOps.h:86
RDKit::queryAtomHasChiralTag
static int queryAtomHasChiralTag(Atom const *at)
Definition: QueryOps.h:165
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::ROMol::getTopology
const MolGraph & getTopology() const
brief returns a pointer to our underlying BGL object
Definition: ROMol.h:555
RDKit::HasPropWithValueQuery< TargetPtr, std::string >
Definition: QueryOps.h:876
RDKit::makeAtomHasAliphaticHeteroatomNbrsQuery
T * makeAtomHasAliphaticHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
Definition: QueryOps.h:609
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:388
Queries::EqualityQuery
a Query implementing ==: arguments must match a particular value (within an optional tolerance)
Definition: EqualityQuery.h:23
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:245
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:162
Queries::GreaterEqualQuery
a Query implementing >= using a particular value (and an optional tolerance)
Definition: GreaterEqualQuery.h:21
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:21
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:941
RDKit::HasPropWithValueQuery::copy
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:866
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:882
ExplicitBitVect
a class for bit vectors that are densely occupied
Definition: ExplicitBitVect.h:29
export.h