RDKit
Open-source cheminformatics and machine learning.
QueryOps.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2003-2010 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 #ifndef _RD_QUERY_OPS_H
16 #define _RD_QUERY_OPS_H
17 
18 #include <GraphMol/RDKitBase.h>
19 #include <Query/QueryObjects.h>
20 #include <Query/Query.h>
21 
22 #ifdef RDK_THREADSAFE_SSS
23 #include <boost/thread/mutex.hpp>
24 #endif
25 
26 namespace RDKit {
29 
32 
35 
38 
41 
44 
49 
52 
55 
58 
61 
64 
65 // -------------------------------------------------
66 // common atom queries
67 
68 static inline int queryAtomAromatic(Atom const *at) {
69  return at->getIsAromatic();
70 };
71 static inline int queryAtomAliphatic(Atom const *at) {
72  return !(at->getIsAromatic());
73 };
74 static inline int queryAtomExplicitDegree(Atom const *at) {
75  return at->getDegree();
76 };
77 static inline int queryAtomTotalDegree(Atom const *at) {
78  return at->getTotalDegree();
79 };
80 static inline int queryAtomHeavyAtomDegree(Atom const *at) {
81  return at->getTotalDegree() - at->getTotalNumHs(true);
82 };
83 static inline int queryAtomHCount(Atom const *at) {
84  return at->getTotalNumHs(true);
85 };
86 static inline int queryAtomImplicitHCount(Atom const *at) {
87  return at->getTotalNumHs(false);
88 };
89 static inline int queryAtomHasImplicitH(Atom const *at) {
90  return int(at->getTotalNumHs(false) > 0);
91 };
92 static inline int queryAtomImplicitValence(Atom const *at) {
93  return at->getImplicitValence();
94 };
95 static inline int queryAtomExplicitValence(Atom const *at) {
96  return at->getExplicitValence() - at->getNumExplicitHs();
97 };
98 static inline int queryAtomTotalValence(Atom const *at) {
99  return at->getExplicitValence() + at->getImplicitValence();
100 };
101 static inline int queryAtomUnsaturated(Atom const *at) {
102  return static_cast<int>(at->getDegree()) < at->getExplicitValence();
103 };
104 static inline int queryAtomNum(Atom const *at) { return at->getAtomicNum(); };
106 static inline int queryAtomMass(Atom const *at) {
107  return static_cast<int>(round(massIntegerConversionFactor * at->getMass()));
108 };
109 static inline int queryAtomIsotope(Atom const *at) {
110  return static_cast<int>(at->getIsotope());
111 };
112 static inline int queryAtomFormalCharge(Atom const *at) {
113  return static_cast<int>(at->getFormalCharge());
114 };
115 static inline int queryAtomHybridization(Atom const *at) {
116  return at->getHybridization();
117 };
118 unsigned int queryAtomBondProduct(Atom const *at);
119 unsigned int queryAtomAllBondProduct(Atom const *at);
120 
121 // -------------------------------------------------
122 // common bond queries
123 
124 static inline int queryBondOrder(Bond const *bond) {
125  return static_cast<int>(bond->getBondType());
126 };
127 static inline int queryBondDir(Bond const *bond) {
128  return static_cast<int>(bond->getBondDir());
129 };
130 static inline int queryIsBondInNRings(Bond const *at) {
131  return at->getOwningMol().getRingInfo()->numBondRings(at->getIdx());
132 };
133 
134 // -------------------------------------------------
135 // ring queries
136 
137 static inline int queryIsAtomInNRings(Atom const *at) {
138  return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx());
139 };
140 static inline int queryIsAtomInRing(Atom const *at) {
141  return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx()) != 0;
142 };
143 static inline int queryAtomHasRingBond(Atom const *at) {
144  ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
145  while (atomBonds.first != atomBonds.second) {
146  unsigned int bondIdx =
147  at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
148  if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
149  return 1;
150  }
151  ++atomBonds.first;
152  }
153  return 0;
154 };
155 static inline int queryIsBondInRing(Bond const *bond) {
156  return bond->getOwningMol().getRingInfo()->numBondRings(bond->getIdx()) != 0;
157 };
158 static inline int queryAtomMinRingSize(Atom const *at) {
159  return at->getOwningMol().getRingInfo()->minAtomRingSize(at->getIdx());
160 };
161 static inline int queryBondMinRingSize(Bond const *bond) {
162  return bond->getOwningMol().getRingInfo()->minBondRingSize(bond->getIdx());
163 };
164 
165 static inline int queryAtomRingBondCount(Atom const *at) {
166  // EFF: cache this result
167  int res = 0;
168  ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
169  while (atomBonds.first != atomBonds.second) {
170  unsigned int bondIdx =
171  at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
172  if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
173  res++;
174  }
175  ++atomBonds.first;
176  }
177  return res;
178 }
179 
180 template <int tgt>
182  if (at->getOwningMol().getRingInfo()->isAtomInRingOfSize(at->getIdx(), tgt)) {
183  return tgt;
184  } else {
185  return 0;
186  }
187 };
188 template <int tgt>
189 int queryBondIsInRingOfSize(Bond const *bond) {
190  if (bond->getOwningMol().getRingInfo()->isBondInRingOfSize(bond->getIdx(),
191  tgt)) {
192  return tgt;
193  } else {
194  return 0;
195  }
196 };
197 
198 template <class T>
199 T *makeAtomSimpleQuery(int what, int func(Atom const *),
200  const std::string &description = "Atom Simple") {
201  T *res = new T;
202  res->setVal(what);
203  res->setDataFunc(func);
204  res->setDescription(description);
205  return res;
206 }
207 
208 //! returns a Query for matching atomic number
209 template <class T>
210 T *makeAtomNumQuery(int what, const std::string &descr) {
211  return makeAtomSimpleQuery<T>(what, queryAtomNum, descr);
212 }
213 //! \overload
214 ATOM_EQUALS_QUERY *makeAtomNumQuery(int what);
215 
216 //! returns a Query for matching implicit valence
217 template <class T>
218 T *makeAtomImplicitValenceQuery(int what, const std::string &descr) {
219  return makeAtomSimpleQuery<T>(what, queryAtomImplicitValence, descr);
220 }
221 //! \overload
222 ATOM_EQUALS_QUERY *makeAtomImplicitValenceQuery(int what);
223 
224 //! returns a Query for matching explicit valence
225 template <class T>
226 T *makeAtomExplicitValenceQuery(int what, const std::string &descr) {
227  return makeAtomSimpleQuery<T>(what, queryAtomExplicitValence, descr);
228 }
229 //! \overload
230 ATOM_EQUALS_QUERY *makeAtomExplicitValenceQuery(int what);
231 
232 //! returns a Query for matching total valence
233 template <class T>
234 T *makeAtomTotalValenceQuery(int what, const std::string &descr) {
235  return makeAtomSimpleQuery<T>(what, queryAtomTotalValence, descr);
236 }
237 //! \overload
238 ATOM_EQUALS_QUERY *makeAtomTotalValenceQuery(int what);
239 
240 //! returns a Query for matching explicit degree
241 template <class T>
242 T *makeAtomExplicitDegreeQuery(int what, const std::string &descr) {
243  return makeAtomSimpleQuery<T>(what, queryAtomExplicitDegree, descr);
244 }
245 //! \overload
246 ATOM_EQUALS_QUERY *makeAtomExplicitDegreeQuery(int what);
247 
248 //! returns a Query for matching atomic degree
249 template <class T>
250 T *makeAtomTotalDegreeQuery(int what, const std::string &descr) {
251  return makeAtomSimpleQuery<T>(what, queryAtomTotalDegree, descr);
252 }
253 //! \overload
254 ATOM_EQUALS_QUERY *makeAtomTotalDegreeQuery(int what);
255 
256 //! returns a Query for matching hydrogen count
257 template <class T>
258 T *makeAtomHCountQuery(int what, const std::string &descr) {
259  return makeAtomSimpleQuery<T>(what, queryAtomHCount, descr);
260 }
261 //! \overload
262 ATOM_EQUALS_QUERY *makeAtomHCountQuery(int what);
263 
264 //! returns a Query for matching ring atoms
265 template <class T>
266 T *makeAtomHasImplicitHQuery(const std::string &descr) {
267  return makeAtomSimpleQuery<T>(true, queryAtomHasImplicitH, descr);
268 }
269 //! \overload
270 ATOM_EQUALS_QUERY *makeAtomHasImplicitHQuery();
271 
272 //! returns a Query for matching implicit hydrogen count
273 template <class T>
274 T *makeAtomImplicitHCountQuery(int what, const std::string &descr) {
275  return makeAtomSimpleQuery<T>(what, queryAtomImplicitHCount, descr);
276 }
277 //! \overload
278 ATOM_EQUALS_QUERY *makeAtomImplicitHCountQuery(int what);
279 
280 //! returns a Query for matching the \c isAromatic flag
281 template <class T>
282 T *makeAtomAromaticQuery(const std::string &descr) {
283  return makeAtomSimpleQuery<T>(true, queryAtomAromatic, descr);
284 }
285 //! \overload
286 ATOM_EQUALS_QUERY *makeAtomAromaticQuery();
287 
288 //! returns a Query for matching aliphatic atoms
289 template <class T>
290 T *makeAtomAliphaticQuery(const std::string &descr) {
291  return makeAtomSimpleQuery<T>(true, queryAtomAliphatic, descr);
292 }
293 //! \overload
294 ATOM_EQUALS_QUERY *makeAtomAliphaticQuery();
295 
296 //! returns a Query for matching atoms with a particular mass
297 template <class T>
298 T *makeAtomMassQuery(int what, const std::string &descr) {
299  return makeAtomSimpleQuery<T>(massIntegerConversionFactor * what,
300  queryAtomMass, descr);
301 }
302 //! \overload
303 ATOM_EQUALS_QUERY *makeAtomMassQuery(int what);
304 
305 //! returns a Query for matching atoms with a particular isotope
306 template <class T>
307 T *makeAtomIsotopeQuery(int what, const std::string &descr) {
308  return makeAtomSimpleQuery<T>(what, queryAtomIsotope, descr);
309 }
310 //! \overload
311 ATOM_EQUALS_QUERY *makeAtomIsotopeQuery(int what);
312 
313 //! returns a Query for matching formal charge
314 template <class T>
315 T *makeAtomFormalChargeQuery(int what, const std::string &descr) {
316  return makeAtomSimpleQuery<T>(what, queryAtomFormalCharge, descr);
317 }
318 //! \overload
319 ATOM_EQUALS_QUERY *makeAtomFormalChargeQuery(int what);
320 
321 //! returns a Query for matching hybridization
322 template <class T>
323 T *makeAtomHybridizationQuery(int what, const std::string &descr) {
324  return makeAtomSimpleQuery<T>(what, queryAtomHybridization, descr);
325 }
326 //! \overload
327 ATOM_EQUALS_QUERY *makeAtomHybridizationQuery(int what);
328 
329 //! returns a Query for matching atoms with unsaturation:
330 template <class T>
331 T *makeAtomUnsaturatedQuery(const std::string &descr) {
332  return makeAtomSimpleQuery<T>(true, queryAtomUnsaturated, descr);
333 }
334 //! \overload
335 ATOM_EQUALS_QUERY *makeAtomUnsaturatedQuery();
336 
337 //! returns a Query for matching ring atoms
338 template <class T>
339 T *makeAtomInRingQuery(const std::string &descr) {
340  return makeAtomSimpleQuery<T>(true, queryIsAtomInRing, descr);
341 }
342 //! \overload
343 ATOM_EQUALS_QUERY *makeAtomInRingQuery();
344 
345 //! returns a Query for matching atoms in a particular number of rings
346 template <class T>
347 T *makeAtomInNRingsQuery(int what, const std::string &descr) {
348  return makeAtomSimpleQuery<T>(what, queryIsAtomInNRings, descr);
349 }
350 //! \overload
351 ATOM_EQUALS_QUERY *makeAtomInNRingsQuery(int what);
352 
353 //! returns a Query for matching atoms in rings of a particular size
354 ATOM_EQUALS_QUERY *makeAtomInRingOfSizeQuery(int tgt);
355 
356 //! returns a Query for matching an atom's minimum ring size
357 template <class T>
358 T *makeAtomMinRingSizeQuery(int tgt, const std::string &descr) {
359  return makeAtomSimpleQuery<T>(tgt, queryAtomMinRingSize, descr);
360 }
361 //! \overload
362 ATOM_EQUALS_QUERY *makeAtomMinRingSizeQuery(int tgt);
363 
364 //! returns a Query for matching atoms with a particular number of ring bonds
365 template <class T>
366 T *makeAtomRingBondCountQuery(int what, const std::string &descr) {
367  return makeAtomSimpleQuery<T>(what, queryAtomRingBondCount, descr);
368 }
369 //! \overload
370 ATOM_EQUALS_QUERY *makeAtomRingBondCountQuery(int what);
371 
372 //! returns a Query for matching atoms with a particular number of ring bonds
373 template <class T>
374 T *makeAtomHasRingBondQuery(const std::string &descr) {
375  return makeAtomSimpleQuery<T>(1, queryAtomHasRingBond, descr);
376 }
377 //! \overload
378 ATOM_EQUALS_QUERY *makeAtomHasRingBondQuery();
379 
380 //! returns a Query for matching bond orders
381 BOND_EQUALS_QUERY *makeBondOrderEqualsQuery(Bond::BondType what);
382 //! returns a Query for matching bond directions
383 BOND_EQUALS_QUERY *makeBondDirEqualsQuery(Bond::BondDir what);
384 //! returns a Query for matching ring bonds
385 BOND_EQUALS_QUERY *makeBondIsInRingQuery();
386 //! returns a Query for matching bonds in rings of a particular size
387 BOND_EQUALS_QUERY *makeBondInRingOfSizeQuery(int what);
388 //! returns a Query for matching a bond's minimum ring size
389 BOND_EQUALS_QUERY *makeBondMinRingSizeQuery(int what);
390 //! returns a Query for matching bonds in a particular number of rings
391 BOND_EQUALS_QUERY *makeBondInNRingsQuery(int tgt);
392 
393 //! returns a Query for matching any bond
394 BOND_NULL_QUERY *makeBondNullQuery();
395 //! returns a Query for matching any atom
396 ATOM_NULL_QUERY *makeAtomNullQuery();
397 
398 static inline int queryAtomRingMembership(Atom const *at) {
399  return static_cast<int>(
400  at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx()));
401 }
402 // I'm pretty sure that this typedef shouldn't be necessary,
403 // but VC++ generates a warning about const Atom const * in
404 // the definition of Match, then complains about an override
405 // that differs only by const/volatile (c4301), then generates
406 // incorrect code if we don't do this... so let's do it.
407 typedef Atom const *ConstAtomPtr;
408 
409 class AtomRingQuery : public Queries::EqualityQuery<int, ConstAtomPtr, true> {
410  public:
411  AtomRingQuery() : Queries::EqualityQuery<int, ConstAtomPtr, true>(-1) {
412  // default is to just do a number of rings query:
413  this->setDescription("AtomInNRings");
415  };
416  explicit AtomRingQuery(int v)
417  : Queries::EqualityQuery<int, ConstAtomPtr, true>(v) {
418  // default is to just do a number of rings query:
419  this->setDescription("AtomInNRings");
421  };
422 
423  virtual bool Match(const ConstAtomPtr what) const {
424  int v = this->TypeConvert(what, Queries::Int2Type<true>());
425  bool res;
426  if (this->d_val < 0) {
427  res = v != 0;
428  } else {
429  res = !Queries::queryCmp(v, this->d_val, this->d_tol);
430  }
431  if (this->getNegation()) {
432  res = !res;
433  }
434  return res;
435  }
436 
437  //! returns a copy of this query
439  AtomRingQuery *res = new AtomRingQuery(this->d_val);
440  res->setNegation(getNegation());
441  res->setTol(this->getTol());
442  res->d_description = this->d_description;
443  res->d_dataFunc = this->d_dataFunc;
444  return res;
445  }
446 };
447 
448 //! allows use of recursive structure queries (e.g. recursive SMARTS)
450  : public Queries::SetQuery<int, Atom const *, true> {
451  public:
453  : Queries::SetQuery<int, Atom const *, true>(), d_serialNumber(0) {
455  setDescription("RecursiveStructure");
456  };
457  //! initialize from an ROMol pointer
458  /*!
459  <b>Notes</b>
460  - this takes over ownership of the pointer
461  */
462  RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber = 0)
463  : Queries::SetQuery<int, Atom const *, true>(),
464  d_serialNumber(serialNumber) {
465  setQueryMol(query);
467  setDescription("RecursiveStructure");
468  };
469  //! returns the index of an atom
470  static inline int getAtIdx(Atom const *at) {
471  PRECONDITION(at, "bad atom argument");
472  return at->getIdx();
473  };
474 
475  //! sets the molecule we'll use recursively
476  /*!
477  <b>Notes</b>
478  - this takes over ownership of the pointer
479  */
480  void setQueryMol(ROMol const *query) { dp_queryMol.reset(query); }
481  //! returns a pointer to our query molecule
482  ROMol const *getQueryMol() const { return dp_queryMol.get(); };
483 
484  //! returns a copy of this query
487  res->dp_queryMol.reset(new ROMol(*dp_queryMol, true));
488 
489  std::set<int>::const_iterator i;
490  for (i = d_set.begin(); i != d_set.end(); i++) {
491  res->insert(*i);
492  }
493  res->setNegation(getNegation());
495  res->d_serialNumber = d_serialNumber;
496  return res;
497  }
498  unsigned int getSerialNumber() const { return d_serialNumber; };
499 
500 #ifdef RDK_THREADSAFE_SSS
501  boost::mutex d_mutex;
502 #endif
503  private:
504  boost::shared_ptr<const ROMol> dp_queryMol;
505  unsigned int d_serialNumber;
506 };
507 
508 template <typename T>
509 int nullDataFun(T) {
510  return 1;
511 }
512 template <typename T>
513 bool nullQueryFun(T) {
514  return true;
515 }
516 
517 typedef Bond const *ConstBondPtr;
518 
519 // ! Query whether an atom has a property
520 template <class TargetPtr>
521 class HasPropQuery : public Queries::EqualityQuery<int, TargetPtr, true> {
522  std::string propname;
523 
524  public:
525  HasPropQuery() : Queries::EqualityQuery<int, TargetPtr, true>(), propname() {
526  // default is to just do a number of rings query:
527  this->setDescription("AtomHasProp");
528  this->setDataFunc(0);
529  };
530  explicit HasPropQuery(const std::string &v)
531  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(v) {
532  // default is to just do a number of rings query:
533  this->setDescription("AtomHasProp");
534  this->setDataFunc(0);
535  };
536 
537  virtual bool Match(const TargetPtr what) const {
538  bool res = what->hasProp(propname);
539  if (this->getNegation()) {
540  res = !res;
541  }
542  return res;
543  }
544 
545  //! returns a copy of this query
547  HasPropQuery *res = new HasPropQuery(this->propname);
548  res->setNegation(this->getNegation());
549  res->d_description = this->d_description;
550  return res;
551  }
552 };
553 
556 
557 //! returns a Query for matching atoms that have a particular property
558 template <class Target>
560  const std::string &property) {
561  return new HasPropQuery<const Target *>(property);
562 }
563 
564 // ! Query whether an atom has a property with a value
565 template <class TargetPtr, class T>
567  : public Queries::EqualityQuery<int, TargetPtr, true> {
568  std::string propname;
569  T val;
570  T tolerance;
571 
572  public:
574  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
575  // default is to just do a number of rings query:
576  this->setDescription("HasPropWithValue");
577  this->setDataFunc(0);
578  };
579  explicit HasPropWithValueQuery(const std::string &prop, const T &v,
580  const T &tol = 0.0)
581  : Queries::EqualityQuery<int, TargetPtr, true>(),
582  propname(prop),
583  val(v),
584  tolerance(tol) {
585  // default is to just do a number of rings query:
586  this->setDescription("HasPropWithValue");
587  this->setDataFunc(0);
588  };
589 
590  virtual bool Match(const TargetPtr what) const {
591  bool res = what->hasProp(propname);
592  if (res) {
593  try {
594  T atom_val = what->template getProp<T>(propname);
595  res = Queries::queryCmp(atom_val, this->val, this->tolerance) == 0;
596  } catch (KeyErrorException e) {
597  res = false;
598  }
599  catch (boost::bad_any_cast) {
600  res = false;
601  }
602 #ifdef __GNUC__
603 #if (__GNUC__ < 4 || \
604  (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
605  catch (...) {
606  // catch all -- this is currently necessary to
607  // trap some bugs in boost+gcc configurations
608  // Normally, this is not the correct thing to
609  // do, but the only exception above is due
610  // to the boost any_cast which is trapped
611  // by the Boost python wrapper when it shouldn't
612  // be.
613  res = false;
614  }
615 #endif
616 #endif
617  }
618  if (this->getNegation()) {
619  res = !res;
620  }
621  return res;
622  }
623 
624  //! returns a copy of this query
626  HasPropWithValueQuery *res =
627  new HasPropWithValueQuery(this->propname, this->val, this->tolerance);
628  res->setNegation(this->getNegation());
629  res->d_description = this->d_description;
630  return res;
631  }
632 };
633 
634 template <class TargetPtr>
635 class HasPropWithValueQuery<TargetPtr, std::string>
636  : public Queries::EqualityQuery<int, TargetPtr, true> {
637  std::string propname;
638  std::string val;
639 
640  public:
642  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
643  // default is to just do a number of rings query:
644  this->setDescription("HasPropWithValue");
645  this->setDataFunc(0);
646  };
647  explicit HasPropWithValueQuery(const std::string &prop, const std::string &v,
648  const std::string &tol = "")
649  : Queries::EqualityQuery<int, TargetPtr, true>(), propname(prop), val(v) {
650  RDUNUSED_PARAM(tol);
651  // default is to just do a number of rings query:
652  this->setDescription("HasPropWithValue");
653  this->setDataFunc(0);
654  };
655 
656  virtual bool Match(const TargetPtr what) const {
657  bool res = what->hasProp(propname);
658  if (res) {
659  try {
660  std::string atom_val = what->template getProp<std::string>(propname);
661  res = atom_val == this->val;
662  } catch (KeyErrorException) {
663  res = false;
664  } catch (boost::bad_any_cast) {
665  res = false;
666  }
667 #ifdef __GNUC__
668 #if (__GNUC__ < 4 || \
669  (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
670  catch (...) {
671  // catch all -- this is currently necessary to
672  // trap some bugs in boost+gcc configurations
673  // Normally, this is not the correct thing to
674  // do, but the only exception above is due
675  // to the boost any_cast which is trapped
676  // by the Boost python wrapper when it shouldn't
677  // be.
678  res = false;
679  }
680 #endif
681 #endif
682  }
683  if (this->getNegation()) {
684  res = !res;
685  }
686  return res;
687  }
688 
689  //! returns a copy of this query
693  this->val);
694  res->setNegation(this->getNegation());
695  res->d_description = this->d_description;
696  return res;
697  }
698 };
699 
700 template <class Target, class T>
702  const std::string &propname, const T &val, const T &tolerance = T()) {
703  return new HasPropWithValueQuery<const Target *, T>(propname, val, tolerance);
704 }
705 
706 bool isComplexQuery(const Bond *b);
707 bool isComplexQuery(const Atom *a);
708 bool isAtomAromatic(const Atom *a);
709 };
710 
711 #endif
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this Atom
Definition: Atom.h:123
HasPropQuery(const std::string &v)
Definition: QueryOps.h:530
bool getNegation() const
returns whether or not we are negated
Definition: Query.h:63
Queries::XOrQuery< int, Atom const *, true > ATOM_XOR_QUERY
Definition: QueryOps.h:36
T * makeAtomTotalValenceQuery(int what, const std::string &descr)
returns a Query for matching total valence
Definition: QueryOps.h:234
T * makeAtomInRingQuery(const std::string &descr)
returns a Query for matching ring atoms
Definition: QueryOps.h:339
static int queryAtomTotalDegree(Atom const *at)
Definition: QueryOps.h:77
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:177
T * makeAtomHybridizationQuery(int what, const std::string &descr)
returns a Query for matching hybridization
Definition: QueryOps.h:323
static int queryAtomHybridization(Atom const *at)
Definition: QueryOps.h:115
T * makeAtomMassQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular mass
Definition: QueryOps.h:298
Queries::OrQuery< int, Bond const *, true > BOND_OR_QUERY
Definition: QueryOps.h:34
double round(double v)
rounds a value to the closest int
Queries::LessQuery< int, Atom const *, true > ATOM_LESS_QUERY
Definition: QueryOps.h:50
bool isBondInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the bond with index idx is in a size - ring.
Queries::Query< int, ConstAtomPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:438
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:61
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Definition: QueryOps.h:656
Queries::Query< int, Atom const *, true > ATOM_NULL_QUERY
Definition: QueryOps.h:63
ATOM_NULL_QUERY * makeAtomNullQuery()
returns a Query for matching any atom
ROMol const * getQueryMol() const
returns a pointer to our query molecule
Definition: QueryOps.h:482
a Query implementing AND: requires all children to be true
Definition: AndQuery.h:20
T * makeAtomImplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching implicit valence
Definition: QueryOps.h:218
void setTol(MatchFuncArgType what)
sets our tolerance
Definition: EqualityQuery.h:43
Atom const * ConstAtomPtr
Definition: QueryOps.h:407
BOND_EQUALS_QUERY * makeBondOrderEqualsQuery(Bond::BondType what)
returns a Query for matching bond orders
unsigned int getTotalNumHs(bool includeNeighbors=false) const
returns the total number of Hs (implicit and explicit) that this Atom is bound to ...
Queries::EqualityQuery< int, Bond const *, true > BOND_PROP_QUERY
Definition: QueryOps.h:555
a Query implementing AND: requires any child to be true
Definition: OrQuery.h:19
unsigned int getIsotope() const
returns our isotope number
Definition: Atom.h:225
BondDir getBondDir() const
returns our direction
Definition: Bond.h:271
double getMass() const
returns our mass
unsigned int queryAtomAllBondProduct(Atom const *at)
T * makeAtomMinRingSizeQuery(int tgt, const std::string &descr)
returns a Query for matching an atom's minimum ring size
Definition: QueryOps.h:358
STL namespace.
Queries::Query< int, Bond const *, true > BOND_NULL_QUERY
Definition: QueryOps.h:62
static int queryAtomExplicitDegree(Atom const *at)
Definition: QueryOps.h:74
Queries::GreaterQuery< int, Bond const *, true > BOND_GREATER_QUERY
Definition: QueryOps.h:43
static int queryBondOrder(Bond const *bond)
Definition: QueryOps.h:124
int TypeConvert(intwhat, Int2Type< false >) const
calls our dataFunc (if it's set) on what and returns the result, otherwise returns what ...
Definition: Query.h:150
static int queryAtomImplicitHCount(Atom const *at)
Definition: QueryOps.h:86
unsigned int getIdx() const
returns our index within the ROMol
Definition: Atom.h:126
Queries::Query< bool, Bond const *, true > BOND_BOOL_QUERY
Definition: QueryOps.h:28
static int getAtIdx(Atom const *at)
returns the index of an atom
Definition: QueryOps.h:470
Queries::SetQuery< int, Bond const *, true > BOND_SET_QUERY
Definition: QueryOps.h:60
T * makeAtomImplicitHCountQuery(int what, const std::string &descr)
returns a Query for matching implicit hydrogen count
Definition: QueryOps.h:274
static int queryAtomMass(Atom const *at)
Definition: QueryOps.h:106
Queries::EqualityQuery< int, const Target *, true > * makePropQuery(const std::string &propname, const T &val, const T &tolerance=T())
Definition: QueryOps.h:701
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:690
BondType
the type of Bond
Definition: Bond.h:56
bool nullQueryFun(T)
Definition: QueryOps.h:513
pulls in the core RDKit functionality
Queries::GreaterEqualQuery< int, Atom const *, true > ATOM_GREATEREQUAL_QUERY
Definition: QueryOps.h:46
static int queryIsBondInRing(Bond const *bond)
Definition: QueryOps.h:155
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:102
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
Definition: QueryOps.h:48
unsigned int minAtomRingSize(unsigned int idx) const
returns the size of the smallest ring atom idx is involved in
virtual bool Match(const ConstAtomPtr what) const
Definition: QueryOps.h:423
unsigned int getDegree() const
T * makeAtomExplicitDegreeQuery(int what, const std::string &descr)
returns a Query for matching explicit degree
Definition: QueryOps.h:242
Queries::LessEqualQuery< int, Atom const *, true > ATOM_LESSEQUAL_QUERY
Definition: QueryOps.h:53
static int queryBondDir(Bond const *bond)
Definition: QueryOps.h:127
static int queryAtomUnsaturated(Atom const *at)
Definition: QueryOps.h:101
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Definition: QueryOps.h:590
Queries::LessEqualQuery< int, Bond const *, true > BOND_LESSEQUAL_QUERY
Definition: QueryOps.h:54
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Definition: QueryOps.h:537
a Query implementing a range: arguments must fall in a particular range of values.
Definition: RangeQuery.h:26
unsigned int getTotalDegree() const
int queryAtomIsInRingOfSize(Atom const *at)
Definition: QueryOps.h:181
bool isComplexQuery(const Bond *b)
T * makeAtomIsotopeQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular isotope
Definition: QueryOps.h:307
T * makeAtomAliphaticQuery(const std::string &descr)
returns a Query for matching aliphatic atoms
Definition: QueryOps.h:290
BOND_EQUALS_QUERY * makeBondInNRingsQuery(int tgt)
returns a Query for matching bonds in a particular number of rings
const int massIntegerConversionFactor
Definition: QueryOps.h:105
int getAtomicNum() const
returns our atomic number
Definition: Atom.h:115
T * makeAtomUnsaturatedQuery(const std::string &descr)
returns a Query for matching atoms with unsaturation:
Definition: QueryOps.h:331
unsigned int numAtomRings(unsigned int idx) const
returns the number of rings atom idx is involved in
class to allow integer values to pick templates
Definition: Query.h:26
static int queryAtomIsotope(Atom const *at)
Definition: QueryOps.h:109
int getExplicitValence() const
returns the explicit valence (including Hs) of this atom
Queries::LessQuery< int, Bond const *, true > BOND_LESS_QUERY
Definition: QueryOps.h:51
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
Definition: ROMol.h:481
BOND_NULL_QUERY * makeBondNullQuery()
returns a Query for matching any bond
allows use of recursive structure queries (e.g. recursive SMARTS)
Definition: QueryOps.h:449
bool isAtomAromatic(const Atom *a)
Bond const * ConstBondPtr
Definition: QueryOps.h:517
static int queryAtomExplicitValence(Atom const *at)
Definition: QueryOps.h:95
static int queryIsAtomInRing(Atom const *at)
Definition: QueryOps.h:140
a Query implementing <= using a particular value (and an optional tolerance)
Queries::Query< bool, Atom const *, true > ATOM_BOOL_QUERY
Definition: QueryOps.h:27
HasPropWithValueQuery(const std::string &prop, const std::string &v, const std::string &tol="")
Definition: QueryOps.h:647
static int queryAtomAromatic(Atom const *at)
Definition: QueryOps.h:68
unsigned int getNumExplicitHs() const
returns our number of explict Hs
Definition: Atom.h:212
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
static int queryBondMinRingSize(Bond const *bond)
Definition: QueryOps.h:161
static int queryAtomNum(Atom const *at)
Definition: QueryOps.h:104
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
Definition: QueryOps.h:40
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
Definition: QueryOps.h:37
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition: Query.h:146
T * makeAtomRingBondCountQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular number of ring bonds
Definition: QueryOps.h:366
T * makeAtomAromaticQuery(const std::string &descr)
returns a Query for matching the isAromatic flag
Definition: QueryOps.h:282
static int queryAtomFormalCharge(Atom const *at)
Definition: QueryOps.h:112
a Query implementing < using a particular value (and an optional tolerance)
Definition: LessQuery.h:20
a Query implementing ==: arguments must match a particular value (within an optional tolerance) ...
Definition: EqualityQuery.h:22
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
Definition: QueryOps.h:210
T * makeAtomFormalChargeQuery(int what, const std::string &descr)
returns a Query for matching formal charge
Definition: QueryOps.h:315
class for representing a bond
Definition: Bond.h:46
#define RDUNUSED_PARAM(x)
Definition: Invariant.h:190
static int queryAtomHeavyAtomDegree(Atom const *at)
Definition: QueryOps.h:80
T * makeAtomExplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching explicit valence
Definition: QueryOps.h:226
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:625
int getImplicitValence() const
returns the implicit valence for this Atom
RingInfo * getRingInfo() const
Definition: ROMol.h:374
void insert(const MatchFuncArgType what)
insert an entry into our set
Definition: SetQuery.h:32
void setDataFunc(int(*what)(ConstAtomPtr))
sets our data function
Definition: Query.h:90
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
Queries::AndQuery< int, Bond const *, true > BOND_AND_QUERY
Definition: QueryOps.h:31
BondDir
the bond's direction (for chirality)
Definition: Bond.h:83
static int queryIsAtomInNRings(Atom const *at)
Definition: QueryOps.h:137
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
Definition: QueryOps.h:480
unsigned int getSerialNumber() const
Definition: QueryOps.h:498
RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber=0)
initialize from an ROMol pointer
Definition: QueryOps.h:462
static int queryAtomHasImplicitH(Atom const *at)
Definition: QueryOps.h:89
#define PRECONDITION(expr, mess)
Definition: Invariant.h:103
static int queryAtomMinRingSize(Atom const *at)
Definition: QueryOps.h:158
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
HybridizationType getHybridization() const
returns our hybridization
Definition: Atom.h:239
Queries::AndQuery< int, Atom const *, true > ATOM_AND_QUERY
Definition: QueryOps.h:30
T * makeAtomHasRingBondQuery(const std::string &descr)
returns a Query for matching atoms with a particular number of ring bonds
Definition: QueryOps.h:374
Queries::EqualityQuery< int, Atom const *, true > ATOM_EQUALS_QUERY
Definition: QueryOps.h:39
std::string d_description
Definition: Query.h:139
T * makeAtomHasImplicitHQuery(const std::string &descr)
returns a Query for matching ring atoms
Definition: QueryOps.h:266
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:546
T * makeAtomInNRingsQuery(int what, const std::string &descr)
returns a Query for matching atoms in a particular number of rings
Definition: QueryOps.h:347
static int queryAtomAliphatic(Atom const *at)
Definition: QueryOps.h:71
Queries::RangeQuery< int, Atom const *, true > ATOM_RANGE_QUERY
Definition: QueryOps.h:56
HasPropWithValueQuery(const std::string &prop, const T &v, const T &tol=0.0)
Definition: QueryOps.h:579
a Query implementing > using a particular value (and an optional tolerance)
Definition: GreaterQuery.h:20
BOND_EQUALS_QUERY * makeBondMinRingSizeQuery(int what)
returns a Query for matching a bond's minimum ring size
ATOM_EQUALS_QUERY * makeAtomInRingOfSizeQuery(int tgt)
returns a Query for matching atoms in rings of a particular size
static int queryAtomRingBondCount(Atom const *at)
Definition: QueryOps.h:165
a Query implementing >= using a particular value (and an optional tolerance)
Pulls in all the query types.
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
Definition: QueryOps.h:42
BOND_EQUALS_QUERY * makeBondDirEqualsQuery(Bond::BondDir what)
returns a Query for matching bond directions
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
Definition: QueryOps.h:33
T * makeAtomSimpleQuery(int what, int func(Atom const *), const std::string &description="Atom Simple")
Definition: QueryOps.h:199
int getFormalCharge() const
returns the formal charge of this atom
Definition: Atom.h:199
int queryBondIsInRingOfSize(Bond const *bond)
Definition: QueryOps.h:189
unsigned int getIdx() const
returns our index within the ROMol
Definition: Bond.h:158
int nullDataFun(T)
Definition: QueryOps.h:509
static int queryAtomHasRingBond(Atom const *at)
Definition: QueryOps.h:143
BOND_EQUALS_QUERY * makeBondInRingOfSizeQuery(int what)
returns a Query for matching bonds in rings of a particular size
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this Bond
Definition: Bond.h:146
static int queryAtomRingMembership(Atom const *at)
Definition: QueryOps.h:398
Queries::EqualityQuery< int, Atom const *, true > ATOM_PROP_QUERY
Definition: QueryOps.h:554
Base class for all queries.
Definition: Query.h:45
static int queryAtomHCount(Atom const *at)
Definition: QueryOps.h:83
Queries::RangeQuery< int, Bond const *, true > BOND_RANGE_QUERY
Definition: QueryOps.h:57
unsigned int queryAtomBondProduct(Atom const *at)
static int queryAtomTotalValence(Atom const *at)
Definition: QueryOps.h:98
BOND_EQUALS_QUERY * makeBondIsInRingQuery()
returns a Query for matching ring bonds
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
The class for representing atoms.
Definition: Atom.h:67
BondType getBondType() const
returns our bondType
Definition: Bond.h:119
a Query implementing XOR: requires exactly one child to be true
Definition: XOrQuery.h:20
void setDescription(const std::string &descr)
sets our text description
Definition: Query.h:66
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:559
bool getIsAromatic() const
returns our isAromatic flag
Definition: Atom.h:217
static int queryAtomImplicitValence(Atom const *at)
Definition: QueryOps.h:92
Class to allow us to throw a KeyError from C++ and have it make it back to Python.
Definition: Exceptions.h:48
Queries::Query< int, Atom const *, true > * copy() const
returns a copy of this query
Definition: QueryOps.h:485
T * makeAtomHCountQuery(int what, const std::string &descr)
returns a Query for matching hydrogen count
Definition: QueryOps.h:258
T * makeAtomTotalDegreeQuery(int what, const std::string &descr)
returns a Query for matching atomic degree
Definition: QueryOps.h:250
Queries::SetQuery< int, Atom const *, true > ATOM_SET_QUERY
Definition: QueryOps.h:59
const int getTol() const
returns out tolerance
Definition: EqualityQuery.h:45
static int queryIsBondInNRings(Bond const *at)
Definition: QueryOps.h:130