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