RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
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_BUILD_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>
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") {
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) {
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) {
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) {
383}
384//! \overload
386
387//! returns a Query for matching explicit valence
388template <class T>
389T *makeAtomExplicitValenceQuery(int what, const std::string &descr) {
391}
392//! \overload
394
395//! returns a Query for matching total valence
396template <class T>
397T *makeAtomTotalValenceQuery(int what, const std::string &descr) {
399}
400//! \overload
402
403//! returns a Query for matching explicit degree
404template <class T>
405T *makeAtomExplicitDegreeQuery(int what, const std::string &descr) {
407}
408//! \overload
410
411//! returns a Query for matching atomic degree
412template <class T>
413T *makeAtomTotalDegreeQuery(int what, const std::string &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) {
423}
424//! \overload
426
427//! returns a Query for matching hydrogen count
428template <class T>
429T *makeAtomHCountQuery(int what, const std::string &descr) {
431}
432//! \overload
434
435//! returns a Query for matching ring atoms
436template <class T>
437T *makeAtomHasImplicitHQuery(const std::string &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) {
447}
448//! \overload
450
451//! returns a Query for matching the \c isAromatic flag
452template <class T>
453T *makeAtomAromaticQuery(const std::string &descr) {
455}
456//! \overload
458
459//! returns a Query for matching aliphatic atoms
460template <class T>
461T *makeAtomAliphaticQuery(const std::string &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) {
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) {
480}
481//! \overload
483
484//! returns a Query for matching formal charge
485template <class T>
486T *makeAtomFormalChargeQuery(int what, const std::string &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>
498//! \overload
500 int what);
501
502//! returns a Query for matching hybridization
503template <class T>
504T *makeAtomHybridizationQuery(int what, const std::string &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) {
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) {
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>
534//! \overloadquery
536
537//! returns a Query for matching atoms with unsaturation:
538template <class T>
539T *makeAtomUnsaturatedQuery(const std::string &descr) {
541}
542//! \overload
544
545//! returns a Query for matching ring atoms
546template <class T>
547T *makeAtomInRingQuery(const std::string &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) {
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>
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) {
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// We support the same special atom queries that we can read from
598// CXSMILES
599const std::vector<std::string> complexQueries = {"A", "AH", "Q", "QH",
600 "X", "XH", "M", "MH"};
601RDKIT_GRAPHMOL_EXPORT void convertComplexNameToQuery(Atom *query, std::string_view symb);
602
603//! returns a Query for matching atoms that have ring bonds
604template <class T>
608//! \overload
610
611//! returns a Query for matching the number of heteroatom neighbors
612template <class T>
613T *makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr) {
615}
616//! \overload
618 int what);
619
620//! returns a Query for matching atoms that have heteroatom neighbors
621template <class T>
625//! \overload
627
628//! returns a Query for matching the number of aliphatic heteroatom neighbors
629template <class T>
634//! \overload
637
638//! returns a Query for matching atoms that have heteroatom neighbors
639template <class T>
643//! \overload
646
647//! returns a Query for matching the number of non-hydrogen neighbors
648template <class T>
649T *makeAtomNonHydrogenDegreeQuery(int what, const std::string &descr) {
651}
652//! \overload
654 int what);
655
656//! returns a Query for matching bridgehead atoms
657template <class T>
658T *makeAtomIsBridgeheadQuery(const std::string &descr) {
660}
661//! \overload
663
664//! returns a Query for matching bond orders
666 Bond::BondType what);
667//! returns a Query for unspecified SMARTS bonds
669//! returns a Query for double|aromatic bonds
671//! returns a Query for single|double bonds
673//! returns a Query for tautomeric bonds
676
677//! returns a Query for matching bond directions
679 Bond::BondDir what);
680//! returns a Query for matching bonds with stereo set
682//! returns a Query for matching ring bonds
684//! returns a Query for matching bonds in rings of a particular size
686//! returns a Query for matching a bond's minimum ring size
688//! returns a Query for matching bonds in a particular number of rings
690
691//! returns a Query for matching any bond
693//! returns a Query for matching any atom
695
696static inline int queryAtomRingMembership(Atom const *at) {
697 return static_cast<int>(
699}
700// I'm pretty sure that this typedef shouldn't be necessary,
701// but VC++ generates a warning about const Atom const * in
702// the definition of Match, then complains about an override
703// that differs only by const/volatile (c4301), then generates
704// incorrect code if we don't do this... so let's do it.
705typedef Atom const *ConstAtomPtr;
706
708 : public Queries::EqualityQuery<int, ConstAtomPtr, true> {
709 public:
710 AtomRingQuery() : Queries::EqualityQuery<int, ConstAtomPtr, true>(-1) {
711 // default is to just do a number of rings query:
712 this->setDescription("AtomInNRings");
713 this->setDataFunc(queryAtomRingMembership);
714 }
715 explicit AtomRingQuery(int v)
716 : Queries::EqualityQuery<int, ConstAtomPtr, true>(v) {
717 // default is to just do a number of rings query:
718 this->setDescription("AtomInNRings");
719 this->setDataFunc(queryAtomRingMembership);
720 }
721
722 bool Match(const ConstAtomPtr what) const override {
723 int v = this->TypeConvert(what, Queries::Int2Type<true>());
724 bool res;
725 if (this->d_val < 0) {
726 res = v != 0;
727 } else {
728 res = !Queries::queryCmp(v, this->d_val, this->d_tol);
729 }
730 if (this->getNegation()) {
731 res = !res;
732 }
733 return res;
734 }
735
736 //! returns a copy of this query
738 AtomRingQuery *res = new AtomRingQuery(this->d_val);
739 res->setNegation(getNegation());
740 res->setTol(this->getTol());
741 res->d_description = this->d_description;
742 res->d_dataFunc = this->d_dataFunc;
743 return res;
744 }
745};
746
747//! allows use of recursive structure queries (e.g. recursive SMARTS)
749 : public Queries::SetQuery<int, Atom const *, true> {
750 public:
751 RecursiveStructureQuery() : Queries::SetQuery<int, Atom const *, true>() {
752 setDataFunc(getAtIdx);
753 setDescription("RecursiveStructure");
754 }
755 //! initialize from an ROMol pointer
756 /*!
757 <b>Notes</b>
758 - this takes over ownership of the pointer
759 */
760 RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber = 0)
761 : Queries::SetQuery<int, Atom const *, true>(),
762 d_serialNumber(serialNumber) {
763 setQueryMol(query);
764 setDataFunc(getAtIdx);
765 setDescription("RecursiveStructure");
766 }
767 //! returns the index of an atom
768 static inline int getAtIdx(Atom const *at) {
769 PRECONDITION(at, "bad atom argument");
770 return at->getIdx();
771 }
772
773 //! sets the molecule we'll use recursively
774 /*!
775 <b>Notes</b>
776 - this takes over ownership of the pointer
777 */
778 void setQueryMol(ROMol const *query) { dp_queryMol.reset(query); }
779 //! returns a pointer to our query molecule
780 ROMol const *getQueryMol() const { return dp_queryMol.get(); }
781
782 //! returns a copy of this query
785 res->dp_queryMol.reset(new ROMol(*dp_queryMol, true));
786
787 std::set<int>::const_iterator i;
788 for (i = d_set.begin(); i != d_set.end(); i++) {
789 res->insert(*i);
790 }
791 res->setNegation(getNegation());
792 res->d_description = d_description;
793 res->d_serialNumber = d_serialNumber;
794 return res;
795 }
796 unsigned int getSerialNumber() const { return d_serialNumber; }
797
798#ifdef RDK_BUILD_THREADSAFE_SSS
799 std::mutex d_mutex;
800#endif
801 private:
802 boost::shared_ptr<const ROMol> dp_queryMol;
803 unsigned int d_serialNumber{0};
804};
805
806template <typename T>
808 return 1;
809}
810template <typename T>
812 return true;
813}
814
815typedef Bond const *ConstBondPtr;
816
817// ! Query whether an atom has a property
818template <class TargetPtr>
819class HasPropQuery : public Queries::EqualityQuery<int, TargetPtr, true> {
820 std::string propname;
821
822 public:
824 // default is to just do a number of rings query:
825 this->setDescription("AtomHasProp");
826 this->setDataFunc(0);
827 }
828 explicit HasPropQuery(std::string v)
829 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(std::move(v)) {
830 // default is to just do a number of rings query:
831 this->setDescription("AtomHasProp");
832 this->setDataFunc(nullptr);
833 }
834
835 bool Match(const TargetPtr what) const override {
836 bool res = what->hasProp(propname);
837 if (this->getNegation()) {
838 res = !res;
839 }
840 return res;
841 }
842
843 //! returns a copy of this query
845 HasPropQuery *res = new HasPropQuery(this->propname);
846 res->setNegation(this->getNegation());
847 res->d_description = this->d_description;
848 return res;
849 }
850};
851
854
855//! returns a Query for matching atoms that have a particular property
856template <class Target>
861
862// ! Query whether an atom has a property with a value
863template <class TargetPtr, class T>
865 : public Queries::EqualityQuery<int, TargetPtr, true> {
866 std::string propname;
867 T val;
868 T tolerance;
869
870 public:
872 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
873 // default is to just do a number of rings query:
874 this->setDescription("HasPropWithValue");
875 this->setDataFunc(0);
876 }
877 explicit HasPropWithValueQuery(std::string prop, const T &v,
878 const T &tol = 0.0)
880 propname(std::move(prop)),
881 val(v),
882 tolerance(tol) {
883 // default is to just do a number of rings query:
884 this->setDescription("HasPropWithValue");
885 this->setDataFunc(nullptr);
886 }
887
888 bool Match(const TargetPtr what) const override {
889 bool res = what->hasProp(propname);
890 if (res) {
891 try {
892 T atom_val = what->template getProp<T>(propname);
893 res = Queries::queryCmp(atom_val, this->val, this->tolerance) == 0;
894 } catch (KeyErrorException &) {
895 res = false;
896 } catch (std::bad_any_cast &) {
897 res = false;
898 }
899#ifdef __GNUC__
900#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
901 catch (...) {
902 // catch all -- this is currently necessary to
903 // trap some bugs in boost+gcc configurations
904 // Normally, this is not the correct thing to
905 // do, but the only exception above is due
906 // to the boost any_cast which is trapped
907 // by the Boost python wrapper when it shouldn't
908 // be.
909 res = false;
910 }
911#endif
912#endif
913 }
914 if (this->getNegation()) {
915 res = !res;
916 }
917 return res;
918 }
919
920 //! returns a copy of this query
923 new HasPropWithValueQuery(this->propname, this->val, this->tolerance);
924 res->setNegation(this->getNegation());
925 res->d_description = this->d_description;
926 return res;
927 }
928};
929
930template <class TargetPtr>
932 : public Queries::EqualityQuery<int, TargetPtr, true> {
933 std::string propname;
934 std::string val;
935
936 public:
938 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
939 // default is to just do a number of rings query:
940 this->setDescription("HasPropWithValue");
941 this->setDataFunc(0);
942 }
943 explicit HasPropWithValueQuery(std::string prop, std::string v,
944 const std::string &tol = "")
946 propname(std::move(prop)),
947 val(std::move(v)) {
948 RDUNUSED_PARAM(tol);
949 // default is to just do a number of rings query:
950 this->setDescription("HasPropWithValue");
951 this->setDataFunc(nullptr);
952 }
953
954 bool Match(const TargetPtr what) const override {
955 bool res = what->hasProp(propname);
956 if (res) {
957 try {
958 std::string atom_val = what->template getProp<std::string>(propname);
959 res = atom_val == this->val;
960 } catch (KeyErrorException &) {
961 res = false;
962 } catch (std::bad_any_cast &) {
963 res = false;
964 }
965#ifdef __GNUC__
966#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
967 catch (...) {
968 // catch all -- this is currently necessary to
969 // trap some bugs in boost+gcc configurations
970 // Normally, this is not the correct thing to
971 // do, but the only exception above is due
972 // to the boost any_cast which is trapped
973 // by the Boost python wrapper when it shouldn't
974 // be.
975 res = false;
976 }
977#endif
978#endif
979 }
980 if (this->getNegation()) {
981 res = !res;
982 }
983 return res;
984 }
985
986 //! returns a copy of this query
990 this->val);
991 res->setNegation(this->getNegation());
992 res->d_description = this->d_description;
993 return res;
994 }
995};
996
997template <class TargetPtr>
999 : public Queries::EqualityQuery<int, TargetPtr, true> {
1000 std::string propname;
1001 ExplicitBitVect val;
1002 float tol{0.0};
1003
1004 public:
1006 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
1007 this->setDescription("HasPropWithValue");
1008 this->setDataFunc(0);
1009 }
1010
1011 explicit HasPropWithValueQuery(std::string prop, const ExplicitBitVect &v,
1012 float tol = 0.0)
1014 propname(std::move(prop)),
1015 val(v),
1016 tol(tol) {
1017 this->setDescription("HasPropWithValue");
1018 this->setDataFunc(nullptr);
1019 }
1020
1021 bool Match(const TargetPtr what) const override {
1022 bool res = what->hasProp(propname);
1023 if (res) {
1024 try {
1025 const ExplicitBitVect &bv =
1026 what->template getProp<const ExplicitBitVect &>(propname);
1027 const double tani = TanimotoSimilarity(val, bv);
1028 res = (1.0 - tani) <= tol;
1029 } catch (KeyErrorException &) {
1030 res = false;
1031 } catch (std::bad_any_cast &) {
1032 res = false;
1033 }
1034#ifdef __GNUC__
1035#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
1036 catch (...) {
1037 // catch all -- this is currently necessary to
1038 // trap some bugs in boost+gcc configurations
1039 // Normally, this is not the correct thing to
1040 // do, but the only exception above is due
1041 // to the boost any_cast which is trapped
1042 // by the Boost python wrapper when it shouldn't
1043 // be.
1044 res = false;
1045 }
1046#endif
1047#endif
1048 }
1049 if (this->getNegation()) {
1050 res = !res;
1051 }
1052 return res;
1053 }
1054
1055 //! returns a copy of this query
1059 this->propname, this->val, this->tol);
1060 res->setNegation(this->getNegation());
1061 res->d_description = this->d_description;
1062 return res;
1063 }
1064};
1065
1066template <class Target, class T>
1068 const std::string &propname, const T &val, const T &tolerance = T()) {
1069 return new HasPropWithValueQuery<const Target *, T>(propname, val, tolerance);
1070}
1071
1072template <class Target>
1074 const std::string &propname, const ExplicitBitVect &val,
1075 float tolerance = 0.0) {
1077 propname, val, tolerance);
1078}
1079
1085 std::vector<int> &vals);
1086
1087// Checks if an atom is dummy or not.
1088// 1. A dummy non-query atom (e.g., "*" in SMILES) is defined by its zero atomic
1089// number. This rule breaks for query atoms because a COMPOSITE_OR query atom
1090// also has a zero atomic number (#6349).
1091// 2. A dummy query atom (e.g., "*" in SMARTS) is defined by its explicit
1092// description: "AtomNull".
1093inline bool isAtomDummy(const Atom *a) {
1094 return (!a->hasQuery() && a->getAtomicNum() == 0) ||
1095 (a->hasQuery() && !a->getQuery()->getNegation() &&
1096 a->getQuery()->getDescription() == "AtomNull");
1097}
1098
1099namespace QueryOps {
1101 RWMol *mol, unsigned int magicVal = 0xDEADBEEF);
1103
1108
1111inline bool hasBondTypeQuery(const Bond &bond) {
1112 if (!bond.hasQuery()) {
1113 return false;
1114 }
1115 return hasBondTypeQuery(*bond.getQuery());
1116}
1119inline bool hasComplexBondTypeQuery(const Bond &bond) {
1120 if (!bond.hasQuery()) {
1121 return false;
1122 }
1123 return hasComplexBondTypeQuery(*bond.getQuery());
1124}
1125
1126} // namespace QueryOps
1127} // namespace RDKit
1128#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)
void setTol(MatchFuncArgType what)
sets our tolerance
a Query implementing >= using a particular value (and an optional tolerance)
a Query implementing > using a particular value (and an optional tolerance)
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
const std::string & getDescription() const
returns our text description
Definition Query.h:70
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
a Query implementing a set: arguments must one of a set of values
Definition SetQuery.h:26
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:722
Queries::Query< int, ConstAtomPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:737
The class for representing atoms.
Definition Atom.h:75
ChiralType getChiralTag() const
returns our chiralTag
Definition Atom.h:262
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
Definition Atom.h:145
unsigned int getIdx() const
returns our index within the ROMol
Definition Atom.h:151
unsigned int getNumExplicitHs() const
returns our number of explicit Hs
Definition Atom.h:242
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
Definition Atom.h:225
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:134
@ CHI_UNSPECIFIED
chirality that hasn't been specified
Definition Atom.h:100
virtual bool hasQuery() const
Definition Atom.h:286
HybridizationType getHybridization() const
returns our hybridization
Definition Atom.h:269
bool getIsAromatic() const
returns our isAromatic flag
Definition Atom.h:247
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:229
double getMass() const
returns our mass
unsigned int getIsotope() const
returns our isotope number
Definition Atom.h:255
unsigned int getTotalDegree() const
virtual QUERYATOM_QUERY * getQuery() const
NOT CALLABLE.
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:204
virtual QUERYBOND_QUERY * getQuery() const
NOT CALLABLE.
virtual bool hasQuery() const
Definition Bond.h:285
BondType getBondType() const
returns our bondType
Definition Bond.h:158
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
Definition Bond.h:186
BondDir
the bond's direction (for chirality)
Definition Bond.h:83
@ STEREONONE
Definition Bond.h:96
BondDir getBondDir() const
returns our direction
Definition Bond.h:311
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:844
HasPropQuery(std::string v)
Definition QueryOps.h:828
bool Match(const TargetPtr what) const override
Definition QueryOps.h:835
bool Match(const TargetPtr what) const override
Definition QueryOps.h:1021
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:1056
HasPropWithValueQuery(std::string prop, const ExplicitBitVect &v, float tol=0.0)
Definition QueryOps.h:1011
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:987
HasPropWithValueQuery(std::string prop, std::string v, const std::string &tol="")
Definition QueryOps.h:943
bool Match(const TargetPtr what) const override
Definition QueryOps.h:954
HasPropWithValueQuery(std::string prop, const T &v, const T &tol=0.0)
Definition QueryOps.h:877
bool Match(const TargetPtr what) const override
Definition QueryOps.h:888
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:921
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:577
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
Definition ROMol.h:680
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:749
RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber=0)
initialize from an ROMol pointer
Definition QueryOps.h:760
unsigned int getSerialNumber() const
Definition QueryOps.h:796
Queries::Query< int, Atom const *, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:783
ROMol const * getQueryMol() const
returns a pointer to our query molecule
Definition QueryOps.h:780
static int getAtIdx(Atom const *at)
returns the index of an atom
Definition QueryOps.h:768
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
Definition QueryOps.h:778
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:233
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.
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:1067
T * makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr)
returns a Query for matching heavy atom degree
Definition QueryOps.h:421
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomUnsaturatedQuery()
This is an overloaded member function, provided for convenience. It differs from the above function o...
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
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomHasHeteroatomNbrsQuery()
This is an overloaded member function, provided for convenience. It differs from the above function o...
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:815
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
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomHasAliphaticHeteroatomNbrsQuery()
This is an overloaded member function, provided for convenience. It differs from the above function o...
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 ATOM_EQUALS_QUERY * makeAtomHasImplicitHQuery()
This is an overloaded member function, provided for convenience. It differs from the above function o...
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
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
bool rdvalue_is(const RDValue_cast_t)
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)
double TanimotoSimilarity(const SparseIntVect< IndexType > &v1, const SparseIntVect< IndexType > &v2, bool returnDistance=false, double bounds=0.0)
bool nullQueryFun(T)
Definition QueryOps.h:811
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 ATOM_EQUALS_QUERY * makeAtomIsBridgeheadQuery()
This is an overloaded member function, provided for convenience. It differs from the above function o...
RDKIT_GRAPHMOL_EXPORT bool isAtomAromatic(const Atom *a)
Queries::XOrQuery< int, Atom const *, true > ATOM_XOR_QUERY
Definition QueryOps.h:40
bool isAtomDummy(const Atom *a)
Definition QueryOps.h:1093
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)
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomHasRingBondQuery()
This is an overloaded member function, provided for convenience. It differs from the above function o...
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
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 * 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
RDKIT_GRAPHMOL_EXPORT void convertComplexNameToQuery(Atom *query, std::string_view symb)
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
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomAromaticQuery()
This is an overloaded member function, provided for convenience. It differs from the above function o...
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:630
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
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomMissingChiralTagQuery()
\overloadquery
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:853
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
Definition QueryOps.h:37
static int queryAtomImplicitHCount(Atom const *at)
Definition QueryOps.h:113
static int queryAtomFormalCharge(Atom const *at)
Definition QueryOps.h:163
T * makeAtomNonHydrogenDegreeQuery(int what, const std::string &descr)
returns a Query for matching the number of non-hydrogen neighbors
Definition QueryOps.h:649
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)
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomHasChiralTagQuery()
\overloadquery
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
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
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomAliphaticQuery()
This is an overloaded member function, provided for convenience. It differs from the above function o...
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
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomInRingQuery()
This is an overloaded member function, provided for convenience. It differs from the above function o...
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:852
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:807
const std::vector< std::string > complexQueries
Definition QueryOps.h:599
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:705
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:857
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
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:613
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:696
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
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