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#include <RDGeneral/Dict.h>
17#ifndef RD_QUERY_OPS_H
18#define RD_QUERY_OPS_H
19
20#include <GraphMol/RDKitBase.h>
21#include <Query/QueryObjects.h>
22#include <Query/Query.h>
24#include <DataStructs/BitOps.h>
25
26#ifdef RDK_BUILD_THREADSAFE_SSS
27#include <mutex>
28#include <utility>
29#endif
30
31namespace RDKit {
34
37
40
43
46
49
54
57
60
63
66
69
70// -------------------------------------------------
71// common atom queries
72
73static inline int queryAtomAromatic(Atom const *at) {
74 return at->getIsAromatic();
75};
76static inline int queryAtomAliphatic(Atom const *at) {
77 return !(at->getIsAromatic());
78};
79static inline int queryAtomExplicitDegree(Atom const *at) {
80 return at->getDegree();
81};
82static inline int queryAtomTotalDegree(Atom const *at) {
83 return at->getTotalDegree();
84};
85//! D and T are treated as "non-hydrogen" here
86static inline int queryAtomNonHydrogenDegree(Atom const *at) {
87 int res = 0;
88 for (const auto nbri :
89 boost::make_iterator_range(at->getOwningMol().getAtomNeighbors(at))) {
90 const auto nbr = at->getOwningMol()[nbri];
91 if (nbr->getAtomicNum() != 1 || nbr->getIsotope() > 1) {
92 res++;
93 }
94 }
95
96 return res;
97};
98//! D and T are not treated as heavy atoms here
99static inline int queryAtomHeavyAtomDegree(Atom const *at) {
100 int heavyDegree = 0;
101 for (const auto nbri :
102 boost::make_iterator_range(at->getOwningMol().getAtomNeighbors(at))) {
103 const auto nbr = at->getOwningMol()[nbri];
104 if (nbr->getAtomicNum() > 1) {
105 heavyDegree++;
106 }
107 }
108
109 return heavyDegree;
110};
111static inline int queryAtomHCount(Atom const *at) {
112 return at->getTotalNumHs(true);
113};
114static inline int queryAtomImplicitHCount(Atom const *at) {
115 return at->getTotalNumHs(false);
116};
117static inline int queryAtomHasImplicitH(Atom const *at) {
118 return int(at->getTotalNumHs(false) > 0);
119};
120static inline int queryAtomImplicitValence(Atom const *at) {
122};
123static inline int queryAtomExplicitValence(Atom const *at) {
125};
126static inline int queryAtomTotalValence(Atom const *at) {
127 return at->getTotalValence();
128};
129static inline int queryAtomUnsaturated(Atom const *at) {
130 return at->getTotalDegree() < at->getTotalValence();
131};
132static inline int queryAtomNum(Atom const *at) { return at->getAtomicNum(); }
133static inline int makeAtomType(int atomic_num, bool aromatic) {
134 return atomic_num + 1000 * static_cast<int>(aromatic);
135}
136static inline void parseAtomType(int val, int &atomic_num, bool &aromatic) {
137 if (val > 1000) {
138 aromatic = true;
139 atomic_num = val - 1000;
140 } else {
141 aromatic = false;
142 atomic_num = val;
143 }
144}
145static inline bool getAtomTypeIsAromatic(int val) { return val > 1000; }
146static inline int getAtomTypeAtomicNum(int val) {
147 if (val > 1000) {
148 return val - 1000;
149 }
150 return val;
151}
152
153static inline int queryAtomType(Atom const *at) {
154 return makeAtomType(at->getAtomicNum(), at->getIsAromatic());
155};
157static inline int queryAtomMass(Atom const *at) {
158 return static_cast<int>(
159 std::round(massIntegerConversionFactor * at->getMass()));
160};
161static inline int queryAtomIsotope(Atom const *at) {
162 return static_cast<int>(at->getIsotope());
163};
164static inline int queryAtomFormalCharge(Atom const *at) {
165 return static_cast<int>(at->getFormalCharge());
166};
167static inline int queryAtomNegativeFormalCharge(Atom const *at) {
168 return static_cast<int>(-1 * at->getFormalCharge());
169};
170static inline int queryAtomHybridization(Atom const *at) {
171 return at->getHybridization();
172};
173static inline int queryAtomNumRadicalElectrons(Atom const *at) {
174 return at->getNumRadicalElectrons();
175};
176static inline int queryAtomHasChiralTag(Atom const *at) {
177 return at->getChiralTag() != Atom::CHI_UNSPECIFIED;
178};
179static inline int queryAtomMissingChiralTag(Atom const *at) {
180 return at->getChiralTag() == Atom::CHI_UNSPECIFIED &&
182};
183
184static inline int queryAtomHasHeteroatomNbrs(Atom const *at) {
185 ROMol::ADJ_ITER nbrIdx, endNbrs;
186 boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
187 while (nbrIdx != endNbrs) {
188 const Atom *nbr = at->getOwningMol()[*nbrIdx];
189 if (nbr->getAtomicNum() != 6 && nbr->getAtomicNum() != 1) {
190 return 1;
191 }
192 ++nbrIdx;
193 }
194 return 0;
195};
196
197static inline int queryAtomNumHeteroatomNbrs(Atom const *at) {
198 int res = 0;
199 ROMol::ADJ_ITER nbrIdx, endNbrs;
200 boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
201 while (nbrIdx != endNbrs) {
202 const Atom *nbr = at->getOwningMol()[*nbrIdx];
203 if (nbr->getAtomicNum() != 6 && nbr->getAtomicNum() != 1) {
204 ++res;
205 }
206 ++nbrIdx;
207 }
208 return res;
209};
210
211static inline int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at) {
212 ROMol::ADJ_ITER nbrIdx, endNbrs;
213 boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
214 while (nbrIdx != endNbrs) {
215 const Atom *nbr = at->getOwningMol()[*nbrIdx];
216 if ((!nbr->getIsAromatic()) && nbr->getAtomicNum() != 6 &&
217 nbr->getAtomicNum() != 1) {
218 return 1;
219 }
220 ++nbrIdx;
221 }
222 return 0;
223};
224
225static inline int queryAtomNumAliphaticHeteroatomNbrs(Atom const *at) {
226 int res = 0;
227 ROMol::ADJ_ITER nbrIdx, endNbrs;
228 boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
229 while (nbrIdx != endNbrs) {
230 const Atom *nbr = at->getOwningMol()[*nbrIdx];
231 if ((!nbr->getIsAromatic()) && nbr->getAtomicNum() != 6 &&
232 nbr->getAtomicNum() != 1) {
233 ++res;
234 }
235 ++nbrIdx;
236 }
237 return res;
238};
239
242
243// -------------------------------------------------
244// common bond queries
245
246static inline int queryBondOrder(Bond const *bond) {
247 return static_cast<int>(bond->getBondType());
248};
249static inline int queryBondIsSingleOrAromatic(Bond const *bond) {
250 return static_cast<int>(bond->getBondType() == Bond::SINGLE ||
251 bond->getBondType() == Bond::AROMATIC);
252};
253static inline int queryBondIsDoubleOrAromatic(Bond const *bond) {
254 return static_cast<int>(bond->getBondType() == Bond::DOUBLE ||
255 bond->getBondType() == Bond::AROMATIC);
256};
257static inline int queryBondIsSingleOrDouble(Bond const *bond) {
258 return static_cast<int>(bond->getBondType() == Bond::SINGLE ||
259 bond->getBondType() == Bond::DOUBLE);
260};
261static inline int queryBondIsSingleOrDoubleOrAromatic(Bond const *bond) {
262 return static_cast<int>(bond->getBondType() == Bond::SINGLE ||
263 bond->getBondType() == Bond::DOUBLE ||
264 bond->getBondType() == Bond::AROMATIC);
265};
266static inline int queryBondDir(Bond const *bond) {
267 return static_cast<int>(bond->getBondDir());
268};
269static inline int queryIsBondInNRings(Bond const *at) {
270 return at->getOwningMol().getRingInfo()->numBondRings(at->getIdx());
271};
272static inline int queryBondHasStereo(Bond const *bnd) {
273 return bnd->getStereo() > Bond::STEREONONE;
274};
275
276// -------------------------------------------------
277// ring queries
278
279static inline int queryIsAtomInNRings(Atom const *at) {
280 return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx());
281};
282static inline int queryIsAtomInRing(Atom const *at) {
283 return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx()) != 0;
284};
285static inline int queryAtomHasRingBond(Atom const *at) {
286 ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
287 while (atomBonds.first != atomBonds.second) {
288 unsigned int bondIdx =
289 at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
290 if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
291 return 1;
292 }
293 ++atomBonds.first;
294 }
295 return 0;
296};
298
299static inline int queryIsBondInRing(Bond const *bond) {
300 return bond->getOwningMol().getRingInfo()->numBondRings(bond->getIdx()) != 0;
301};
302static inline int queryAtomMinRingSize(Atom const *at) {
303 return at->getOwningMol().getRingInfo()->minAtomRingSize(at->getIdx());
304};
305static inline int queryBondMinRingSize(Bond const *bond) {
306 return bond->getOwningMol().getRingInfo()->minBondRingSize(bond->getIdx());
307};
308
309static inline int queryAtomRingBondCount(Atom const *at) {
310 // EFF: cache this result
311 int res = 0;
312 ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
313 while (atomBonds.first != atomBonds.second) {
314 unsigned int bondIdx =
315 at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
316 if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
317 res++;
318 }
319 ++atomBonds.first;
320 }
321 return res;
322}
323
324template <int tgt>
327 return tgt;
328 } else {
329 return 0;
330 }
331};
332template <int tgt>
334 if (bond->getOwningMol().getRingInfo()->isBondInRingOfSize(bond->getIdx(),
335 tgt)) {
336 return tgt;
337 } else {
338 return 0;
339 }
340};
341
342template <class T>
343T *makeAtomSimpleQuery(int what, int func(Atom const *),
344 const std::string &description = "Atom Simple") {
345 T *res = new T;
346 res->setVal(what);
347 res->setDataFunc(func);
348 res->setDescription(description);
349 return res;
350}
351
353 int lower, int upper, bool lowerOpen, bool upperOpen,
354 int func(Atom const *), const std::string &description = "Atom Range") {
356 res->setDataFunc(func);
357 res->setDescription(description);
358 res->setEndsOpen(lowerOpen, upperOpen);
359 return res;
360}
361
362//! returns a Query for matching atomic number
363template <class T>
364T *makeAtomNumQuery(int what, const std::string &descr) {
366}
367//! \overload
369
370//! returns a Query for matching atomic number and aromaticity
371template <class T>
372T *makeAtomTypeQuery(int num, int aromatic, const std::string &descr) {
374 descr);
375}
376//! \overload
378 int aromatic);
379
380//! returns a Query for matching implicit valence
381template <class T>
382T *makeAtomImplicitValenceQuery(int what, const std::string &descr) {
384}
385//! \overload
387
388//! returns a Query for matching explicit valence
389template <class T>
390T *makeAtomExplicitValenceQuery(int what, const std::string &descr) {
392}
393//! \overload
395
396//! returns a Query for matching total valence
397template <class T>
398T *makeAtomTotalValenceQuery(int what, const std::string &descr) {
400}
401//! \overload
403
404//! returns a Query for matching explicit degree
405template <class T>
406T *makeAtomExplicitDegreeQuery(int what, const std::string &descr) {
408}
409//! \overload
411
412//! returns a Query for matching atomic degree
413template <class T>
414T *makeAtomTotalDegreeQuery(int what, const std::string &descr) {
416}
417//! \overload
419
420//! returns a Query for matching heavy atom degree
421template <class T>
422T *makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr) {
424}
425//! \overload
427
428//! returns a Query for matching hydrogen count
429template <class T>
430T *makeAtomHCountQuery(int what, const std::string &descr) {
432}
433//! \overload
435
436//! returns a Query for matching ring atoms
437template <class T>
438T *makeAtomHasImplicitHQuery(const std::string &descr) {
440}
441//! \overload
443
444//! returns a Query for matching implicit hydrogen count
445template <class T>
446T *makeAtomImplicitHCountQuery(int what, const std::string &descr) {
448}
449//! \overload
451
452//! returns a Query for matching the \c isAromatic flag
453template <class T>
454T *makeAtomAromaticQuery(const std::string &descr) {
456}
457//! \overload
459
460//! returns a Query for matching aliphatic atoms
461template <class T>
462T *makeAtomAliphaticQuery(const std::string &descr) {
464}
465//! \overload
467
468//! returns a Query for matching atoms with a particular mass
469template <class T>
470T *makeAtomMassQuery(int what, const std::string &descr) {
473}
474//! \overload
476
477//! returns a Query for matching atoms with a particular isotope
478template <class T>
479T *makeAtomIsotopeQuery(int what, const std::string &descr) {
481}
482//! \overload
484
485//! returns a Query for matching formal charge
486template <class T>
487T *makeAtomFormalChargeQuery(int what, const std::string &descr) {
489}
490//! \overload
492
493//! returns a Query for matching negative formal charges (i.e. a query val of 1
494//! matches a formal charge of -1)
495template <class T>
499//! \overload
501 int what);
502
503//! returns a Query for matching hybridization
504template <class T>
505T *makeAtomHybridizationQuery(int what, const std::string &descr) {
507}
508//! \overload
510
511//! returns a Query for matching the number of radical electrons
512template <class T>
513T *makeAtomNumRadicalElectronsQuery(int what, const std::string &descr) {
515}
516//! \overload
518 int what);
519
520//! returns a Query for matching whether or not chirality has been set on the
521//! atom
522template <class T>
523T *makeAtomHasChiralTagQuery(const std::string &descr) {
525}
526//! \overloadquery
528
529//! returns a Query for matching whether or not a potentially chiral atom is
530//! missing a chiral tag
531template <class T>
535//! \overloadquery
537
538//! returns a Query for matching atoms with unsaturation:
539template <class T>
540T *makeAtomUnsaturatedQuery(const std::string &descr) {
542}
543//! \overload
545
546//! returns a Query for matching ring atoms
547template <class T>
548T *makeAtomInRingQuery(const std::string &descr) {
550}
551//! \overload
553
554//! returns a Query for matching atoms in a particular number of rings
555template <class T>
556T *makeAtomInNRingsQuery(int what, const std::string &descr) {
558}
559//! \overload
561
562//! returns a Query for matching atoms in rings of a particular size
564
565//! returns a Query for matching an atom's minimum ring size
566template <class T>
570//! \overload
572
573//! returns a Query for matching atoms with a particular number of ring bonds
574template <class T>
575T *makeAtomRingBondCountQuery(int what, const std::string &descr) {
577}
578//! \overload
580
581//! returns a Query for matching generic A atoms (heavy atoms)
583//! returns a Query for matching generic AH atoms (any atom)
585//! returns a Query for matching generic Q atoms (heteroatoms)
587//! returns a Query for matching generic QH atoms (heteroatom or H)
589//! returns a Query for matching generic X atoms (halogens)
591//! returns a Query for matching generic XH atoms (halogen or H)
593//! returns a Query for matching generic M atoms (metals)
595//! returns a Query for matching generic MH atoms (metals or H)
597
598// We support the same special atom queries that we can read from
599// CXSMILES
600const std::vector<std::string> complexQueries = {"A", "AH", "Q", "QH",
601 "X", "XH", "M", "MH"};
603 std::string_view symb);
604
605//! returns a Query for matching atoms that have ring bonds
606template <class T>
610//! \overload
612
613//! returns a Query for matching the number of heteroatom neighbors
614template <class T>
615T *makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr) {
617}
618//! \overload
620 int what);
621
622//! returns a Query for matching atoms that have heteroatom neighbors
623template <class T>
627//! \overload
629
630//! returns a Query for matching the number of aliphatic heteroatom neighbors
631template <class T>
636//! \overload
639
640//! returns a Query for matching atoms that have heteroatom neighbors
641template <class T>
645//! \overload
648
649//! returns a Query for matching the number of non-hydrogen neighbors
650template <class T>
651T *makeAtomNonHydrogenDegreeQuery(int what, const std::string &descr) {
653}
654//! \overload
656 int what);
657
658//! returns a Query for matching bridgehead atoms
659template <class T>
660T *makeAtomIsBridgeheadQuery(const std::string &descr) {
662}
663//! \overload
665
666//! returns a Query for matching bond orders
668 Bond::BondType what);
669//! returns a Query for unspecified SMARTS bonds
671//! returns a Query for double|aromatic bonds
673//! returns a Query for single|double bonds
675//! returns a Query for tautomeric bonds
678
679//! returns a Query for matching bond directions
681 Bond::BondDir what);
682//! returns a Query for matching bonds with stereo set
684//! returns a Query for matching ring bonds
686//! returns a Query for matching bonds in rings of a particular size
688//! returns a Query for matching a bond's minimum ring size
690//! returns a Query for matching bonds in a particular number of rings
692
693//! returns a Query for matching any bond
695//! returns a Query for matching any atom
697
698static inline int queryAtomRingMembership(Atom const *at) {
699 return static_cast<int>(
701}
702// I'm pretty sure that this typedef shouldn't be necessary,
703// but VC++ generates a warning about const Atom const * in
704// the definition of Match, then complains about an override
705// that differs only by const/volatile (c4301), then generates
706// incorrect code if we don't do this... so let's do it.
707typedef Atom const *ConstAtomPtr;
708
710 : public Queries::EqualityQuery<int, ConstAtomPtr, true> {
711 public:
712 AtomRingQuery() : Queries::EqualityQuery<int, ConstAtomPtr, true>(-1) {
713 // default is to just do a number of rings query:
714 this->setDescription("AtomInNRings");
715 this->setDataFunc(queryAtomRingMembership);
716 }
717 explicit AtomRingQuery(int v)
718 : Queries::EqualityQuery<int, ConstAtomPtr, true>(v) {
719 // default is to just do a number of rings query:
720 this->setDescription("AtomInNRings");
721 this->setDataFunc(queryAtomRingMembership);
722 }
723
724 bool Match(const ConstAtomPtr what) const override {
725 int v = this->TypeConvert(what, Queries::Int2Type<true>());
726 bool res;
727 if (this->d_val < 0) {
728 res = v != 0;
729 } else {
730 res = !Queries::queryCmp(v, this->d_val, this->d_tol);
731 }
732 if (this->getNegation()) {
733 res = !res;
734 }
735 return res;
736 }
737
738 //! returns a copy of this query
740 AtomRingQuery *res = new AtomRingQuery(this->d_val);
741 res->setNegation(getNegation());
742 res->setTol(this->getTol());
743 res->d_description = this->d_description;
744 res->d_dataFunc = this->d_dataFunc;
745 return res;
746 }
747};
748
749//! allows use of recursive structure queries (e.g. recursive SMARTS)
751 : public Queries::SetQuery<int, Atom const *, true> {
752 public:
753 RecursiveStructureQuery() : Queries::SetQuery<int, Atom const *, true>() {
754 setDataFunc(getAtIdx);
755 setDescription("RecursiveStructure");
756 }
757 //! initialize from an ROMol pointer
758 /*!
759 <b>Notes</b>
760 - this takes over ownership of the pointer
761 */
762 RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber = 0)
763 : Queries::SetQuery<int, Atom const *, true>(),
764 d_serialNumber(serialNumber) {
765 setQueryMol(query);
766 setDataFunc(getAtIdx);
767 setDescription("RecursiveStructure");
768 }
769 //! returns the index of an atom
770 static inline int getAtIdx(Atom const *at) {
771 PRECONDITION(at, "bad atom argument");
772 return at->getIdx();
773 }
774
775 //! sets the molecule we'll use recursively
776 /*!
777 <b>Notes</b>
778 - this takes over ownership of the pointer
779 */
780 void setQueryMol(ROMol const *query) { dp_queryMol.reset(query); }
781 //! returns a pointer to our query molecule
782 ROMol const *getQueryMol() const { return dp_queryMol.get(); }
783
784 //! returns a copy of this query
787 res->dp_queryMol.reset(new ROMol(*dp_queryMol, true));
788
789 std::set<int>::const_iterator i;
790 for (i = d_set.begin(); i != d_set.end(); i++) {
791 res->insert(*i);
792 }
793 res->setNegation(getNegation());
794 res->d_description = d_description;
795 res->d_serialNumber = d_serialNumber;
796 return res;
797 }
798 unsigned int getSerialNumber() const { return d_serialNumber; }
799
800#ifdef RDK_BUILD_THREADSAFE_SSS
801 std::mutex d_mutex;
802#endif
803 private:
804 boost::shared_ptr<const ROMol> dp_queryMol;
805 unsigned int d_serialNumber{0};
806};
807
808template <typename T>
810 return 1;
811}
812template <typename T>
814 return true;
815}
816
817typedef Bond const *ConstBondPtr;
818
819// ! Query whether an atom has a property
820template <class TargetPtr>
821class HasPropQuery : public Queries::EqualityQuery<int, TargetPtr, true> {
822 std::string propname;
823
824 public:
826 this->setDescription("HasProp");
827 this->setDataFunc(nullptr);
828 }
829 explicit HasPropQuery(std::string v)
830 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(std::move(v)) {
831 this->setDescription("HasProp");
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 const std::string &getPropName() const { return propname; }
852};
853
856
857//! returns a Query for matching atoms that have a particular property
858template <class Target>
863
864// ! Query whether an atom has a property with a value
866 public:
868 virtual ~HasPropWithValueQueryBase() = default;
869 virtual PairHolder getPair() const = 0;
870 virtual double getTolerance() const = 0;
871};
872
873template <class TargetPtr, class T>
876 public Queries::EqualityQuery<int, TargetPtr, true> {
877 std::string propname;
878 T val;
879 double tolerance{0.0};
880
881 public:
883 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
884 // default is to just do a number of rings query:
885 this->setDescription("HasPropWithValue");
886 this->setDataFunc(0);
887 }
888
889 PairHolder getPair() const override {
890 return PairHolder(Dict::Pair(propname, val));
891 }
892
893 double getTolerance() const override { return tolerance; }
894
895 explicit HasPropWithValueQuery(std::string prop, const T &v,
896 const T &tol = 0.0)
898 propname(std::move(prop)),
899 val(v),
900 tolerance(tol) {
901 // default is to just do a number of rings query:
902 this->setDescription("HasPropWithValue");
903 this->setDataFunc(nullptr);
904 }
905
906 bool Match(const TargetPtr what) const override {
907 bool res = what->hasProp(propname);
908 if (res) {
909 try {
910 T atom_val = what->template getProp<T>(propname);
911 res = Queries::queryCmp(atom_val, this->val,
912 static_cast<T>(this->tolerance)) == 0;
913 } catch (KeyErrorException &) {
914 res = false;
915 } catch (std::bad_any_cast &) {
916 res = false;
917 }
918#ifdef __GNUC__
919#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
920 catch (...) {
921 // catch all -- this is currently necessary to
922 // trap some bugs in boost+gcc configurations
923 // Normally, this is not the correct thing to
924 // do, but the only exception above is due
925 // to the boost any_cast which is trapped
926 // by the Boost python wrapper when it shouldn't
927 // be.
928 res = false;
929 }
930#endif
931#endif
932 }
933 if (this->getNegation()) {
934 res = !res;
935 }
936 return res;
937 }
938
939 //! returns a copy of this query
942 new HasPropWithValueQuery(this->propname, this->val, this->tolerance);
943 res->setNegation(this->getNegation());
944 res->d_description = this->d_description;
945 return res;
946 }
947};
948
949template <class TargetPtr>
952 public Queries::EqualityQuery<int, TargetPtr, true> {
953 std::string propname;
954 std::string val;
955
956 public:
958 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
959 // default is to just do a number of rings query:
960 this->setDescription("HasPropWithValue");
961 this->setDataFunc(0);
962 }
963 explicit HasPropWithValueQuery(std::string prop, std::string v,
964 const double /*tol*/ = 0.0)
966 propname(std::move(prop)),
967 val(std::move(v)) {
968 // default is to just do a number of rings query:
969 this->setDescription("HasPropWithValue");
970 this->setDataFunc(nullptr);
971 }
972
973 PairHolder getPair() const override {
974 return PairHolder(Dict::Pair(propname, val));
975 }
976
977 double getTolerance() const override { return 0.0; }
978
979 bool Match(const TargetPtr what) const override {
980 bool res = what->hasProp(propname);
981 if (res) {
982 try {
983 std::string atom_val = what->template getProp<std::string>(propname);
984 res = atom_val == this->val;
985 } catch (KeyErrorException &) {
986 res = false;
987 } catch (std::bad_any_cast &) {
988 res = false;
989 }
990#ifdef __GNUC__
991#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
992 catch (...) {
993 // catch all -- this is currently necessary to
994 // trap some bugs in boost+gcc configurations
995 // Normally, this is not the correct thing to
996 // do, but the only exception above is due
997 // to the boost any_cast which is trapped
998 // by the Boost python wrapper when it shouldn't
999 // be.
1000 res = false;
1001 }
1002#endif
1003#endif
1004 }
1005 if (this->getNegation()) {
1006 res = !res;
1007 }
1008 return res;
1009 }
1010
1011 //! returns a copy of this query
1015 this->val);
1016 res->setNegation(this->getNegation());
1017 res->d_description = this->d_description;
1018 return res;
1019 }
1020};
1021
1022template <class TargetPtr>
1025 public Queries::EqualityQuery<int, TargetPtr, true> {
1026 std::string propname;
1027 ExplicitBitVect val;
1028 double tol{0.0};
1029
1030 public:
1032 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
1033 this->setDescription("HasPropWithValue");
1034 this->setDataFunc(0);
1035 }
1036
1037 explicit HasPropWithValueQuery(std::string prop, const ExplicitBitVect &v,
1038 double tol = 0.0)
1040 propname(std::move(prop)),
1041 val(v),
1042 tol(tol) {
1043 this->setDescription("HasPropWithValue");
1044 this->setDataFunc(nullptr);
1045 }
1046
1047 PairHolder getPair() const override {
1048 return PairHolder(Dict::Pair(propname, val));
1049 }
1050
1051 double getTolerance() const override { return tol; }
1052
1053 bool Match(const TargetPtr what) const override {
1054 bool res = what->hasProp(propname);
1055 if (res) {
1056 try {
1057 const ExplicitBitVect &bv =
1058 what->template getProp<const ExplicitBitVect &>(propname);
1059 const double tani = TanimotoSimilarity(val, bv);
1060 res = (1.0 - tani) <= tol;
1061 } catch (KeyErrorException &) {
1062 res = false;
1063 } catch (std::bad_any_cast &) {
1064 res = false;
1065 }
1066#ifdef __GNUC__
1067#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
1068 catch (...) {
1069 // catch all -- this is currently necessary to
1070 // trap some bugs in boost+gcc configurations
1071 // Normally, this is not the correct thing to
1072 // do, but the only exception above is due
1073 // to the boost any_cast which is trapped
1074 // by the Boost python wrapper when it shouldn't
1075 // be.
1076 res = false;
1077 }
1078#endif
1079#endif
1080 }
1081 if (this->getNegation()) {
1082 res = !res;
1083 }
1084 return res;
1085 }
1086
1087 //! returns a copy of this query
1091 this->propname, this->val, this->tol);
1092 res->setNegation(this->getNegation());
1093 res->d_description = this->d_description;
1094 return res;
1095 }
1096};
1097
1098template <class Target, class T>
1100 const std::string &propname, const T &val, double tolerance = 0.0) {
1101 return new HasPropWithValueQuery<const Target *, T>(propname, val, tolerance);
1102}
1103
1104template <class Target>
1106 const std::string &propname, const ExplicitBitVect &val,
1107 double tolerance = 0.0) {
1109 propname, val, tolerance);
1110}
1111
1117 std::vector<int> &vals);
1118
1119// Checks if an atom is dummy or not.
1120// 1. A dummy non-query atom (e.g., "*" in SMILES) is defined by its zero atomic
1121// number. This rule breaks for query atoms because a COMPOSITE_OR query atom
1122// also has a zero atomic number (#6349).
1123// 2. A dummy query atom (e.g., "*" in SMARTS) is defined by its explicit
1124// description: "AtomNull".
1125inline bool isAtomDummy(const Atom *a) {
1126 return (!a->hasQuery() && a->getAtomicNum() == 0) ||
1127 (a->hasQuery() && !a->getQuery()->getNegation() &&
1128 a->getQuery()->getDescription() == "AtomNull");
1129}
1130
1131namespace QueryOps {
1133 RWMol *mol, unsigned int magicVal = 0xDEADBEEF);
1134// Replaces the given atom in the molecule with a QueryAtom that is otherwise
1135// a copy of the given atom. Returns a pointer to that atom.
1136// if the atom already has a query, nothing will be changed
1138
1143
1146inline bool hasBondTypeQuery(const Bond &bond) {
1147 if (!bond.hasQuery()) {
1148 return false;
1149 }
1150 return hasBondTypeQuery(*bond.getQuery());
1151}
1154inline bool hasComplexBondTypeQuery(const Bond &bond) {
1155 if (!bond.hasQuery()) {
1156 return false;
1157 }
1158 return hasComplexBondTypeQuery(*bond.getQuery());
1159}
1160
1162} // namespace QueryOps
1163} // namespace RDKit
1164#endif
Contains general bit-comparison and similarity operations.
Pulls in all the BitVect classes.
Defines the Dict class.
#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:724
Queries::Query< int, ConstAtomPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:739
The class for representing atoms.
Definition Atom.h:75
ChiralType getChiralTag() const
returns our chiralTag
Definition Atom.h:240
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
Definition Atom.h:152
unsigned int getIdx() const
returns our index within the ROMol
Definition Atom.h:158
unsigned int getValence(ValenceType which) const
returns the valence (explicit or implicit) of this atom
unsigned int getNumExplicitHs() const
returns our number of explicit Hs
Definition Atom.h:220
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
Definition Atom.h:203
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:141
@ CHI_UNSPECIFIED
chirality that hasn't been specified
Definition Atom.h:102
virtual bool hasQuery() const
Definition Atom.h:264
HybridizationType getHybridization() const
returns our hybridization
Definition Atom.h:247
bool getIsAromatic() const
returns our isAromatic flag
Definition Atom.h:225
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:207
double getMass() const
returns our mass
unsigned int getIsotope() const
returns our isotope number
Definition Atom.h:233
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
const std::string & getPropName() const
Definition QueryOps.h:851
HasPropQuery(std::string v)
Definition QueryOps.h:829
bool Match(const TargetPtr what) const override
Definition QueryOps.h:835
virtual ~HasPropWithValueQueryBase()=default
virtual PairHolder getPair() const =0
virtual double getTolerance() const =0
HasPropWithValueQuery(std::string prop, const ExplicitBitVect &v, double tol=0.0)
Definition QueryOps.h:1037
bool Match(const TargetPtr what) const override
Definition QueryOps.h:1053
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:1088
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:1012
bool Match(const TargetPtr what) const override
Definition QueryOps.h:979
HasPropWithValueQuery(std::string prop, std::string v, const double=0.0)
Definition QueryOps.h:963
HasPropWithValueQuery(std::string prop, const T &v, const T &tol=0.0)
Definition QueryOps.h:895
PairHolder getPair() const override
Definition QueryOps.h:889
bool Match(const TargetPtr what) const override
Definition QueryOps.h:906
double getTolerance() const override
Definition QueryOps.h:893
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:940
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:751
RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber=0)
initialize from an ROMol pointer
Definition QueryOps.h:762
unsigned int getSerialNumber() const
Definition QueryOps.h:798
Queries::Query< int, Atom const *, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:785
ROMol const * getQueryMol() const
returns a pointer to our query molecule
Definition QueryOps.h:782
static int getAtIdx(Atom const *at)
returns the index of an atom
Definition QueryOps.h:770
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
Definition QueryOps.h:780
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 isMetal(const Atom &atom)
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:56
static int queryAtomNumRadicalElectrons(Atom const *at)
Definition QueryOps.h:173
T * makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr)
returns a Query for matching heavy atom degree
Definition QueryOps.h:422
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:55
static int queryAtomHybridization(Atom const *at)
Definition QueryOps.h:170
static int queryAtomMinRingSize(Atom const *at)
Definition QueryOps.h:302
T * makeAtomTotalDegreeQuery(int what, const std::string &descr)
returns a Query for matching atomic degree
Definition QueryOps.h:414
Queries::LessEqualQuery< int, Bond const *, true > BOND_LESSEQUAL_QUERY
Definition QueryOps.h:59
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:79
static int queryAtomHasRingBond(Atom const *at)
Definition QueryOps.h:285
Bond const * ConstBondPtr
Definition QueryOps.h:817
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrDoubleBondQuery()
returns a Query for single|double bonds
static int queryBondHasStereo(Bond const *bnd)
Definition QueryOps.h:272
static int queryAtomUnsaturated(Atom const *at)
Definition QueryOps.h:129
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrAromaticBondQuery()
returns a Query for unspecified SMARTS bonds
static int queryAtomAromatic(Atom const *at)
Definition QueryOps.h:73
Queries::RangeQuery< int, Atom const *, true > ATOM_RANGE_QUERY
Definition QueryOps.h:61
Queries::Query< bool, Bond const *, true > BOND_BOOL_QUERY
Definition QueryOps.h:33
static int queryAtomType(Atom const *at)
Definition QueryOps.h:153
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:35
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:253
static int queryAtomHasImplicitH(Atom const *at)
Definition QueryOps.h:117
Queries::LessEqualQuery< int, Atom const *, true > ATOM_LESSEQUAL_QUERY
Definition QueryOps.h:58
Queries::EqualityQuery< int, const Target *, true > * makePropQuery(const std::string &propname, const T &val, double tolerance=0.0)
Definition QueryOps.h:1099
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:813
static int queryAtomNegativeFormalCharge(Atom const *at)
Definition QueryOps.h:167
Queries::SetQuery< int, Atom const *, true > ATOM_SET_QUERY
Definition QueryOps.h:64
static int queryAtomHasHeteroatomNbrs(Atom const *at)
Definition QueryOps.h:184
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:398
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:41
bool isAtomDummy(const Atom *a)
Definition QueryOps.h:1125
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:65
static int queryBondIsSingleOrAromatic(Bond const *bond)
Definition QueryOps.h:249
T * makeAtomFormalChargeQuery(int what, const std::string &descr)
returns a Query for matching formal charge
Definition QueryOps.h:487
Queries::OrQuery< int, Bond const *, true > BOND_OR_QUERY
Definition QueryOps.h:39
static int queryBondMinRingSize(Bond const *bond)
Definition QueryOps.h:305
const int massIntegerConversionFactor
Definition QueryOps.h:156
T * makeAtomNumRadicalElectronsQuery(int what, const std::string &descr)
returns a Query for matching the number of radical electrons
Definition QueryOps.h:513
static int queryAtomTotalValence(Atom const *at)
Definition QueryOps.h:126
static int queryAtomNonHydrogenDegree(Atom const *at)
D and T are treated as "non-hydrogen" here.
Definition QueryOps.h:86
T * makeAtomRingBondCountQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular number of ring bonds
Definition QueryOps.h:575
static int makeAtomType(int atomic_num, bool aromatic)
Definition QueryOps.h:133
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:567
static int queryAtomHeavyAtomDegree(Atom const *at)
D and T are not treated as heavy atoms here.
Definition QueryOps.h:99
static int queryAtomRingBondCount(Atom const *at)
Definition QueryOps.h:309
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:446
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:470
T * makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of aliphatic heteroatom neighbors
Definition QueryOps.h:632
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
Definition QueryOps.h:42
T * makeAtomSimpleQuery(int what, int func(Atom const *), const std::string &description="Atom Simple")
Definition QueryOps.h:343
Queries::Query< int, Atom const *, true > ATOM_NULL_QUERY
Definition QueryOps.h:68
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomMissingChiralTagQuery()
\overloadquery
static int queryAtomAliphatic(Atom const *at)
Definition QueryOps.h:76
static int queryAtomNumHeteroatomNbrs(Atom const *at)
Definition QueryOps.h:197
static bool getAtomTypeIsAromatic(int val)
Definition QueryOps.h:145
static int queryIsAtomInNRings(Atom const *at)
Definition QueryOps.h:279
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:176
Queries::EqualityQuery< int, Bond const *, true > BOND_PROP_QUERY
Definition QueryOps.h:855
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
Definition QueryOps.h:38
static int queryAtomImplicitHCount(Atom const *at)
Definition QueryOps.h:114
static int queryAtomFormalCharge(Atom const *at)
Definition QueryOps.h:164
T * makeAtomNonHydrogenDegreeQuery(int what, const std::string &descr)
returns a Query for matching the number of non-hydrogen neighbors
Definition QueryOps.h:651
RDKIT_GRAPHMOL_EXPORT int queryIsAtomBridgehead(Atom const *at)
static int queryAtomNum(Atom const *at)
Definition QueryOps.h:132
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
Definition QueryOps.h:53
static int queryIsAtomInRing(Atom const *at)
Definition QueryOps.h:282
static int queryAtomHCount(Atom const *at)
Definition QueryOps.h:111
T * makeAtomImplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching implicit valence
Definition QueryOps.h:382
static int queryAtomExplicitValence(Atom const *at)
Definition QueryOps.h:123
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:157
static int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at)
Definition QueryOps.h:211
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:225
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
Definition QueryOps.h:45
int queryAtomIsInRingOfSize(Atom const *at)
Definition QueryOps.h:325
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
Definition QueryOps.h:47
T * makeAtomExplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching explicit valence
Definition QueryOps.h:390
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:333
Queries::AndQuery< int, Bond const *, true > BOND_AND_QUERY
Definition QueryOps.h:36
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:261
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:406
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:44
static int queryIsBondInNRings(Bond const *at)
Definition QueryOps.h:269
static int queryAtomTotalDegree(Atom const *at)
Definition QueryOps.h:82
Queries::Query< int, Bond const *, true > BOND_NULL_QUERY
Definition QueryOps.h:67
T * makeAtomInNRingsQuery(int what, const std::string &descr)
returns a Query for matching atoms in a particular number of rings
Definition QueryOps.h:556
RDKIT_GRAPHMOL_EXPORT bool isComplexQuery(const Bond *b)
Queries::EqualityQuery< int, Atom const *, true > ATOM_PROP_QUERY
Definition QueryOps.h:854
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:266
T * makeAtomIsotopeQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular isotope
Definition QueryOps.h:479
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:146
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:809
const std::vector< std::string > complexQueries
Definition QueryOps.h:600
T * makeAtomNegativeFormalChargeQuery(int what, const std::string &descr)
Definition QueryOps.h:496
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
Definition QueryOps.h:364
static int queryBondIsSingleOrDouble(Bond const *bond)
Definition QueryOps.h:257
Atom const * ConstAtomPtr
Definition QueryOps.h:707
T * makeAtomHCountQuery(int what, const std::string &descr)
returns a Query for matching hydrogen count
Definition QueryOps.h:430
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:352
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:859
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:51
static int queryAtomIsotope(Atom const *at)
Definition QueryOps.h:161
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:372
Queries::RangeQuery< int, Bond const *, true > BOND_RANGE_QUERY
Definition QueryOps.h:62
static int queryAtomImplicitValence(Atom const *at)
Definition QueryOps.h:120
T * makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of heteroatom neighbors
Definition QueryOps.h:615
static int queryIsBondInRing(Bond const *bond)
Definition QueryOps.h:299
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:246
static int queryAtomRingMembership(Atom const *at)
Definition QueryOps.h:698
static void parseAtomType(int val, int &atomic_num, bool &aromatic)
Definition QueryOps.h:136
T * makeAtomHybridizationQuery(int what, const std::string &descr)
returns a Query for matching hybridization
Definition QueryOps.h:505
Queries::GreaterQuery< int, Bond const *, true > BOND_GREATER_QUERY
Definition QueryOps.h:48
static int queryAtomMissingChiralTag(Atom const *at)
Definition QueryOps.h:179
Queries::Query< bool, Atom const *, true > ATOM_BOOL_QUERY
Definition QueryOps.h:32