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