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