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) {
121 return at->getImplicitValence();
122};
123static inline int queryAtomExplicitValence(Atom const *at) {
124 return at->getExplicitValence() - at->getNumExplicitHs();
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 { return PairHolder(Dict::Pair(propname, val)); }
890
891 double getTolerance() const override { return tolerance; }
892
893 explicit HasPropWithValueQuery(std::string prop, const T &v,
894 const T &tol = 0.0)
896 propname(std::move(prop)),
897 val(v),
898 tolerance(tol) {
899 // default is to just do a number of rings query:
900 this->setDescription("HasPropWithValue");
901 this->setDataFunc(nullptr);
902 }
903
904 bool Match(const TargetPtr what) const override {
905 bool res = what->hasProp(propname);
906 if (res) {
907 try {
908 T atom_val = what->template getProp<T>(propname);
909 res = Queries::queryCmp(atom_val, this->val,
910 static_cast<T>(this->tolerance)) == 0;
911 } catch (KeyErrorException &) {
912 res = false;
913 } catch (std::bad_any_cast &) {
914 res = false;
915 }
916#ifdef __GNUC__
917#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
918 catch (...) {
919 // catch all -- this is currently necessary to
920 // trap some bugs in boost+gcc configurations
921 // Normally, this is not the correct thing to
922 // do, but the only exception above is due
923 // to the boost any_cast which is trapped
924 // by the Boost python wrapper when it shouldn't
925 // be.
926 res = false;
927 }
928#endif
929#endif
930 }
931 if (this->getNegation()) {
932 res = !res;
933 }
934 return res;
935 }
936
937 //! returns a copy of this query
940 new HasPropWithValueQuery(this->propname, this->val, this->tolerance);
941 res->setNegation(this->getNegation());
942 res->d_description = this->d_description;
943 return res;
944 }
945};
946
947template <class TargetPtr>
950 public Queries::EqualityQuery<int, TargetPtr, true> {
951 std::string propname;
952 std::string val;
953
954 public:
956 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
957 // default is to just do a number of rings query:
958 this->setDescription("HasPropWithValue");
959 this->setDataFunc(0);
960 }
961 explicit HasPropWithValueQuery(std::string prop, std::string v,
962 const double /*tol*/ = 0.0)
964 propname(std::move(prop)),
965 val(std::move(v)) {
966 // default is to just do a number of rings query:
967 this->setDescription("HasPropWithValue");
968 this->setDataFunc(nullptr);
969 }
970
971 PairHolder getPair() const override { return PairHolder(Dict::Pair(propname, val)); }
972
973 double getTolerance() const override { return 0.0; }
974
975 bool Match(const TargetPtr what) const override {
976 bool res = what->hasProp(propname);
977 if (res) {
978 try {
979 std::string atom_val = what->template getProp<std::string>(propname);
980 res = atom_val == this->val;
981 } catch (KeyErrorException &) {
982 res = false;
983 } catch (std::bad_any_cast &) {
984 res = false;
985 }
986#ifdef __GNUC__
987#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
988 catch (...) {
989 // catch all -- this is currently necessary to
990 // trap some bugs in boost+gcc configurations
991 // Normally, this is not the correct thing to
992 // do, but the only exception above is due
993 // to the boost any_cast which is trapped
994 // by the Boost python wrapper when it shouldn't
995 // be.
996 res = false;
997 }
998#endif
999#endif
1000 }
1001 if (this->getNegation()) {
1002 res = !res;
1003 }
1004 return res;
1005 }
1006
1007 //! returns a copy of this query
1011 this->val);
1012 res->setNegation(this->getNegation());
1013 res->d_description = this->d_description;
1014 return res;
1015 }
1016};
1017
1018template <class TargetPtr>
1021 public Queries::EqualityQuery<int, TargetPtr, true> {
1022 std::string propname;
1023 ExplicitBitVect val;
1024 double tol{0.0};
1025
1026 public:
1028 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
1029 this->setDescription("HasPropWithValue");
1030 this->setDataFunc(0);
1031 }
1032
1033 explicit HasPropWithValueQuery(std::string prop, const ExplicitBitVect &v,
1034 double tol = 0.0)
1036 propname(std::move(prop)),
1037 val(v),
1038 tol(tol) {
1039 this->setDescription("HasPropWithValue");
1040 this->setDataFunc(nullptr);
1041 }
1042
1043 PairHolder getPair() const override { return PairHolder(Dict::Pair(propname, val)); }
1044
1045 double getTolerance() const override { return tol; }
1046
1047 bool Match(const TargetPtr what) const override {
1048 bool res = what->hasProp(propname);
1049 if (res) {
1050 try {
1051 const ExplicitBitVect &bv =
1052 what->template getProp<const ExplicitBitVect &>(propname);
1053 const double tani = TanimotoSimilarity(val, bv);
1054 res = (1.0 - tani) <= tol;
1055 } catch (KeyErrorException &) {
1056 res = false;
1057 } catch (std::bad_any_cast &) {
1058 res = false;
1059 }
1060#ifdef __GNUC__
1061#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
1062 catch (...) {
1063 // catch all -- this is currently necessary to
1064 // trap some bugs in boost+gcc configurations
1065 // Normally, this is not the correct thing to
1066 // do, but the only exception above is due
1067 // to the boost any_cast which is trapped
1068 // by the Boost python wrapper when it shouldn't
1069 // be.
1070 res = false;
1071 }
1072#endif
1073#endif
1074 }
1075 if (this->getNegation()) {
1076 res = !res;
1077 }
1078 return res;
1079 }
1080
1081 //! returns a copy of this query
1085 this->propname, this->val, this->tol);
1086 res->setNegation(this->getNegation());
1087 res->d_description = this->d_description;
1088 return res;
1089 }
1090};
1091
1092template <class Target, class T>
1094 const std::string &propname, const T &val, double tolerance = 0.0) {
1095 return new HasPropWithValueQuery<const Target *, T>(propname, val, tolerance);
1096}
1097
1098template <class Target>
1100 const std::string &propname, const ExplicitBitVect &val,
1101 double tolerance = 0.0) {
1103 propname, val, tolerance);
1104}
1105
1111 std::vector<int> &vals);
1112
1113// Checks if an atom is dummy or not.
1114// 1. A dummy non-query atom (e.g., "*" in SMILES) is defined by its zero atomic
1115// number. This rule breaks for query atoms because a COMPOSITE_OR query atom
1116// also has a zero atomic number (#6349).
1117// 2. A dummy query atom (e.g., "*" in SMARTS) is defined by its explicit
1118// description: "AtomNull".
1119inline bool isAtomDummy(const Atom *a) {
1120 return (!a->hasQuery() && a->getAtomicNum() == 0) ||
1121 (a->hasQuery() && !a->getQuery()->getNegation() &&
1122 a->getQuery()->getDescription() == "AtomNull");
1123}
1124
1125namespace QueryOps {
1127 RWMol *mol, unsigned int magicVal = 0xDEADBEEF);
1128// Replaces the given atom in the molecule with a QueryAtom that is otherwise
1129// a copy of the given atom. Returns a pointer to that atom.
1130// if the atom already has a query, nothing will be changed
1132
1137
1140inline bool hasBondTypeQuery(const Bond &bond) {
1141 if (!bond.hasQuery()) {
1142 return false;
1143 }
1144 return hasBondTypeQuery(*bond.getQuery());
1145}
1148inline bool hasComplexBondTypeQuery(const Bond &bond) {
1149 if (!bond.hasQuery()) {
1150 return false;
1151 }
1152 return hasComplexBondTypeQuery(*bond.getQuery());
1153}
1154
1155} // namespace QueryOps
1156} // namespace RDKit
1157#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: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
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:1033
bool Match(const TargetPtr what) const override
Definition QueryOps.h:1047
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:1082
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:1008
bool Match(const TargetPtr what) const override
Definition QueryOps.h:975
HasPropWithValueQuery(std::string prop, std::string v, const double=0.0)
Definition QueryOps.h:961
HasPropWithValueQuery(std::string prop, const T &v, const T &tol=0.0)
Definition QueryOps.h:893
PairHolder getPair() const override
Definition QueryOps.h:889
bool Match(const TargetPtr what) const override
Definition QueryOps.h:904
double getTolerance() const override
Definition QueryOps.h:891
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:938
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 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:1093
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:1119
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