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