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#include <functional>
26
27#include <limits>
28
29#ifdef RDK_BUILD_THREADSAFE_SSS
30#include <mutex>
31#include <utility>
32#endif
33
34namespace RDKit {
37
40
43
46
49
52
57
60
63
66
69
72
73// -------------------------------------------------
74// common atom queries
75
76static inline int queryAtomAromatic(Atom const *at) {
77 return at->getIsAromatic();
78};
79static inline int queryAtomAliphatic(Atom const *at) {
80 return !(at->getIsAromatic());
81};
82static inline int queryAtomExplicitDegree(Atom const *at) {
83 return at->getDegree();
84};
85static inline int queryAtomTotalDegree(Atom const *at) {
86 return at->getTotalDegree();
87};
88//! D and T are treated as "non-hydrogen" here
89static inline int queryAtomNonHydrogenDegree(Atom const *at) {
90 int res = 0;
91 for (const auto nbri :
92 boost::make_iterator_range(at->getOwningMol().getAtomNeighbors(at))) {
93 const auto nbr = at->getOwningMol()[nbri];
94 if (nbr->getAtomicNum() != 1 || nbr->getIsotope() > 1) {
95 res++;
96 }
97 }
98
99 return res;
100};
101//! D and T are not treated as heavy atoms here
102static inline int queryAtomHeavyAtomDegree(Atom const *at) {
103 int heavyDegree = 0;
104 for (const auto nbri :
105 boost::make_iterator_range(at->getOwningMol().getAtomNeighbors(at))) {
106 const auto nbr = at->getOwningMol()[nbri];
107 if (nbr->getAtomicNum() > 1) {
108 heavyDegree++;
109 }
110 }
111
112 return heavyDegree;
113};
114static inline int queryAtomHCount(Atom const *at) {
115 return at->getTotalNumHs(true);
116};
117static inline int queryAtomImplicitHCount(Atom const *at) {
118 return at->getTotalNumHs(false);
119};
120static inline int queryAtomHasImplicitH(Atom const *at) {
121 return int(at->getTotalNumHs(false) > 0);
122};
123static inline int queryAtomImplicitValence(Atom const *at) {
125};
126static inline int queryAtomExplicitValence(Atom const *at) {
128};
129static inline int queryAtomTotalValence(Atom const *at) {
130 return at->getTotalValence();
131};
132static inline int queryAtomUnsaturated(Atom const *at) {
133 return at->getTotalDegree() < at->getTotalValence();
134};
135static inline int queryAtomNum(Atom const *at) { return at->getAtomicNum(); }
136static inline int makeAtomType(int atomic_num, bool aromatic) {
137 return atomic_num + 1000 * static_cast<int>(aromatic);
138}
139static inline void parseAtomType(int val, int &atomic_num, bool &aromatic) {
140 if (val > 1000) {
141 aromatic = true;
142 atomic_num = val - 1000;
143 } else {
144 aromatic = false;
145 atomic_num = val;
146 }
147}
148static inline bool getAtomTypeIsAromatic(int val) { return val > 1000; }
149static inline int getAtomTypeAtomicNum(int val) {
150 if (val > 1000) {
151 return val - 1000;
152 }
153 return val;
154}
155
156static inline int queryAtomType(Atom const *at) {
157 return makeAtomType(at->getAtomicNum(), at->getIsAromatic());
158};
160static inline int queryAtomMass(Atom const *at) {
161 return static_cast<int>(
162 std::round(massIntegerConversionFactor * at->getMass()));
163};
164static inline int queryAtomIsotope(Atom const *at) {
165 return static_cast<int>(at->getIsotope());
166};
167static inline int queryAtomFormalCharge(Atom const *at) {
168 return static_cast<int>(at->getFormalCharge());
169};
170static inline int queryAtomNegativeFormalCharge(Atom const *at) {
171 return static_cast<int>(-1 * at->getFormalCharge());
172};
173static inline int queryAtomHybridization(Atom const *at) {
174 return at->getHybridization();
175};
176static inline int queryAtomNumRadicalElectrons(Atom const *at) {
177 return at->getNumRadicalElectrons();
178};
179static inline int queryAtomHasChiralTag(Atom const *at) {
180 return at->getChiralTag() != Atom::CHI_UNSPECIFIED;
181};
182static inline int queryAtomMissingChiralTag(Atom const *at) {
183 return at->getChiralTag() == Atom::CHI_UNSPECIFIED &&
185};
186
187static inline int queryAtomHasHeteroatomNbrs(Atom const *at) {
188 ROMol::ADJ_ITER nbrIdx, endNbrs;
189 boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
190 while (nbrIdx != endNbrs) {
191 const Atom *nbr = at->getOwningMol()[*nbrIdx];
192 if (nbr->getAtomicNum() != 6 && nbr->getAtomicNum() != 1) {
193 return 1;
194 }
195 ++nbrIdx;
196 }
197 return 0;
198};
199
200static inline int queryAtomNumHeteroatomNbrs(Atom const *at) {
201 int res = 0;
202 ROMol::ADJ_ITER nbrIdx, endNbrs;
203 boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
204 while (nbrIdx != endNbrs) {
205 const Atom *nbr = at->getOwningMol()[*nbrIdx];
206 if (nbr->getAtomicNum() != 6 && nbr->getAtomicNum() != 1) {
207 ++res;
208 }
209 ++nbrIdx;
210 }
211 return res;
212};
213
214static inline int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at) {
215 ROMol::ADJ_ITER nbrIdx, endNbrs;
216 boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
217 while (nbrIdx != endNbrs) {
218 const Atom *nbr = at->getOwningMol()[*nbrIdx];
219 if ((!nbr->getIsAromatic()) && nbr->getAtomicNum() != 6 &&
220 nbr->getAtomicNum() != 1) {
221 return 1;
222 }
223 ++nbrIdx;
224 }
225 return 0;
226};
227
228static inline int queryAtomNumAliphaticHeteroatomNbrs(Atom const *at) {
229 int res = 0;
230 ROMol::ADJ_ITER nbrIdx, endNbrs;
231 boost::tie(nbrIdx, endNbrs) = at->getOwningMol().getAtomNeighbors(at);
232 while (nbrIdx != endNbrs) {
233 const Atom *nbr = at->getOwningMol()[*nbrIdx];
234 if ((!nbr->getIsAromatic()) && nbr->getAtomicNum() != 6 &&
235 nbr->getAtomicNum() != 1) {
236 ++res;
237 }
238 ++nbrIdx;
239 }
240 return res;
241};
242
245
246// -------------------------------------------------
247// common bond queries
248
249static inline int queryBondOrder(Bond const *bond) {
250 return static_cast<int>(bond->getBondType());
251};
252static inline int queryBondIsSingleOrAromatic(Bond const *bond) {
253 return static_cast<int>(bond->getBondType() == Bond::SINGLE ||
254 bond->getBondType() == Bond::AROMATIC);
255};
256static inline int queryBondIsDoubleOrAromatic(Bond const *bond) {
257 return static_cast<int>(bond->getBondType() == Bond::DOUBLE ||
258 bond->getBondType() == Bond::AROMATIC);
259};
260static inline int queryBondIsSingleOrDouble(Bond const *bond) {
261 return static_cast<int>(bond->getBondType() == Bond::SINGLE ||
262 bond->getBondType() == Bond::DOUBLE);
263};
264static inline int queryBondIsSingleOrDoubleOrAromatic(Bond const *bond) {
265 return static_cast<int>(bond->getBondType() == Bond::SINGLE ||
266 bond->getBondType() == Bond::DOUBLE ||
267 bond->getBondType() == Bond::AROMATIC);
268};
269static inline int queryBondDir(Bond const *bond) {
270 return static_cast<int>(bond->getBondDir());
271};
272static inline int queryIsBondInNRings(Bond const *at) {
273 return at->getOwningMol().getRingInfo()->numBondRings(at->getIdx());
274};
275static inline int queryBondHasStereo(Bond const *bnd) {
276 return bnd->getStereo() > Bond::STEREONONE;
277};
278
279// -------------------------------------------------
280// ring queries
281
282static inline int queryIsAtomInNRings(Atom const *at) {
283 return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx());
284};
285static inline int queryIsAtomInRing(Atom const *at) {
286 return at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx()) != 0;
287};
288static inline int queryAtomHasRingBond(Atom const *at) {
289 ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
290 while (atomBonds.first != atomBonds.second) {
291 unsigned int bondIdx =
292 at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
293 if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
294 return 1;
295 }
296 ++atomBonds.first;
297 }
298 return 0;
299};
301
302static inline int queryIsBondInRing(Bond const *bond) {
303 return bond->getOwningMol().getRingInfo()->numBondRings(bond->getIdx()) != 0;
304};
305static inline int queryAtomMinRingSize(Atom const *at) {
306 return at->getOwningMol().getRingInfo()->minAtomRingSize(at->getIdx());
307};
308static inline int queryBondMinRingSize(Bond const *bond) {
309 return bond->getOwningMol().getRingInfo()->minBondRingSize(bond->getIdx());
310};
311
312static inline int queryAtomRingBondCount(Atom const *at) {
313 // EFF: cache this result
314 int res = 0;
315 ROMol::OBOND_ITER_PAIR atomBonds = at->getOwningMol().getAtomBonds(at);
316 while (atomBonds.first != atomBonds.second) {
317 unsigned int bondIdx =
318 at->getOwningMol().getTopology()[*atomBonds.first]->getIdx();
319 if (at->getOwningMol().getRingInfo()->numBondRings(bondIdx)) {
320 res++;
321 }
322 ++atomBonds.first;
323 }
324 return res;
325}
326
327static inline int queryAtomIsInRingOfSize(Atom const *at, int tgt) {
328 if (at->getOwningMol().getRingInfo()->isAtomInRingOfSize(at->getIdx(), tgt)) {
329 return tgt;
330 } else {
331 return 0;
332 }
333};
334//! returns the size of an SSSR ring the atom is in that's within the specified
335//! range, or a value outside the range if there are no rings with a size in the
336//! range. passing -1 for a bound leaves the range without a limit in that
337//! direction
338//! always returns a value outside the range for atoms that are not in a ring
339static inline int queryAtomIsInRingOfSize(Atom const *at, int lower, int upper,
340 bool lowerOpen = false,
341 bool upperOpen = false) {
342 const auto ri = at->getOwningMol().getRingInfo();
343 for (const auto ringSize : ri->atomRingSizes(at->getIdx())) {
344 if ((ringSize > lower || (ringSize == lower && !lowerOpen)) &&
345 (upper < 0 ||
346 (ringSize < upper || (ringSize == upper && !upperOpen)))) {
347 return ringSize;
348 }
349 }
350 // we didn't find it, return a result that's not in the acceptable range:
351 if (lower > -1) {
352 return -1;
353 } else if (upper > -1) {
354 return std::numeric_limits<int>::max();
355 } else {
356 return 0;
357 }
358};
359template <int tgt>
361 if (at->getOwningMol().getRingInfo()->isAtomInRingOfSize(at->getIdx(), tgt)) {
362 return tgt;
363 } else {
364 return 0;
365 }
366};
367template <int tgt>
369 if (bond->getOwningMol().getRingInfo()->isBondInRingOfSize(bond->getIdx(),
370 tgt)) {
371 return tgt;
372 } else {
373 return 0;
374 }
375};
376
377template <class T>
378T *makeAtomSimpleQuery(int what, std::function<int(Atom const *)> func,
379 const std::string &description = "Atom Simple") {
380 T *res = new T;
381 res->setVal(what);
382 res->setDataFunc(func);
383 res->setDescription(description);
384 return res;
385}
386
388 int lower, int upper, bool lowerOpen, bool upperOpen,
389 std::function<int(Atom const *)> func,
390 const std::string &description = "Atom Range") {
391 ATOM_RANGE_QUERY *res = new ATOM_RANGE_QUERY(lower, upper);
392 res->setDataFunc(func);
393 res->setDescription(description);
394 res->setEndsOpen(lowerOpen, upperOpen);
395 return res;
396}
397
398//! returns a Query for matching atomic number
399template <class T>
400T *makeAtomNumQuery(int what, const std::string &descr) {
401 return makeAtomSimpleQuery<T>(what, queryAtomNum, descr);
402}
403//! \overload
405
406//! returns a Query for matching atomic number and aromaticity
407template <class T>
408T *makeAtomTypeQuery(int num, int aromatic, const std::string &descr) {
410 descr);
411}
412//! \overload
414 int aromatic);
415
416//! returns a Query for matching implicit valence
417template <class T>
418T *makeAtomImplicitValenceQuery(int what, const std::string &descr) {
420}
421//! \overload
423
424//! returns a Query for matching explicit valence
425template <class T>
426T *makeAtomExplicitValenceQuery(int what, const std::string &descr) {
428}
429//! \overload
431
432//! returns a Query for matching total valence
433template <class T>
434T *makeAtomTotalValenceQuery(int what, const std::string &descr) {
436}
437//! \overload
439
440//! returns a Query for matching explicit degree
441template <class T>
442T *makeAtomExplicitDegreeQuery(int what, const std::string &descr) {
444}
445//! \overload
447
448//! returns a Query for matching atomic degree
449template <class T>
450T *makeAtomTotalDegreeQuery(int what, const std::string &descr) {
451 return makeAtomSimpleQuery<T>(what, queryAtomTotalDegree, descr);
452}
453//! \overload
455
456//! returns a Query for matching heavy atom degree
457template <class T>
458T *makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr) {
460}
461//! \overload
463
464//! returns a Query for matching hydrogen count
465template <class T>
466T *makeAtomHCountQuery(int what, const std::string &descr) {
467 return makeAtomSimpleQuery<T>(what, queryAtomHCount, descr);
468}
469//! \overload
471
472//! returns a Query for matching ring atoms
473template <class T>
474T *makeAtomHasImplicitHQuery(const std::string &descr) {
476}
477//! \overload
479
480//! returns a Query for matching implicit hydrogen count
481template <class T>
482T *makeAtomImplicitHCountQuery(int what, const std::string &descr) {
484}
485//! \overload
487
488//! returns a Query for matching the \c isAromatic flag
489template <class T>
490T *makeAtomAromaticQuery(const std::string &descr) {
491 return makeAtomSimpleQuery<T>(true, queryAtomAromatic, descr);
492}
493//! \overload
495
496//! returns a Query for matching aliphatic atoms
497template <class T>
498T *makeAtomAliphaticQuery(const std::string &descr) {
499 return makeAtomSimpleQuery<T>(true, queryAtomAliphatic, descr);
500}
501//! \overload
503
504//! returns a Query for matching atoms with a particular mass
505template <class T>
506T *makeAtomMassQuery(int what, const std::string &descr) {
508 queryAtomMass, descr);
509}
510//! \overload
512
513//! returns a Query for matching atoms with a particular isotope
514template <class T>
515T *makeAtomIsotopeQuery(int what, const std::string &descr) {
516 return makeAtomSimpleQuery<T>(what, queryAtomIsotope, descr);
517}
518//! \overload
520
521//! returns a Query for matching formal charge
522template <class T>
523T *makeAtomFormalChargeQuery(int what, const std::string &descr) {
525}
526//! \overload
528
529//! returns a Query for matching negative formal charges (i.e. a query val of 1
530//! matches a formal charge of -1)
531template <class T>
532T *makeAtomNegativeFormalChargeQuery(int what, const std::string &descr) {
534}
535//! \overload
537 int what);
538
539//! returns a Query for matching hybridization
540template <class T>
541T *makeAtomHybridizationQuery(int what, const std::string &descr) {
543}
544//! \overload
546
547//! returns a Query for matching the number of radical electrons
548template <class T>
549T *makeAtomNumRadicalElectronsQuery(int what, const std::string &descr) {
551}
552//! \overload
554 int what);
555
556//! returns a Query for matching whether or not chirality has been set on the
557//! atom
558template <class T>
559T *makeAtomHasChiralTagQuery(const std::string &descr) {
561}
562//! \overloadquery
564
565//! returns a Query for matching whether or not a potentially chiral atom is
566//! missing a chiral tag
567template <class T>
568T *makeAtomMissingChiralTagQuery(const std::string &descr) {
570}
571//! \overloadquery
573
574//! returns a Query for matching atoms with unsaturation:
575template <class T>
576T *makeAtomUnsaturatedQuery(const std::string &descr) {
577 return makeAtomSimpleQuery<T>(true, queryAtomUnsaturated, descr);
578}
579//! \overload
581
582//! returns a Query for matching ring atoms
583template <class T>
584T *makeAtomInRingQuery(const std::string &descr) {
585 return makeAtomSimpleQuery<T>(true, queryIsAtomInRing, descr);
586}
587//! \overload
589
590//! returns a Query for matching atoms in a particular number of rings
591template <class T>
592T *makeAtomInNRingsQuery(int what, const std::string &descr) {
593 return makeAtomSimpleQuery<T>(what, queryIsAtomInNRings, descr);
594}
595//! \overload
597
598//! returns a Query for matching atoms in rings of a particular size
599template <class T>
600T *makeAtomInRingOfSizeQuery(int tgt, const std::string &descr);
601//! \overload
603//! \overload
605 int lower, int upper, bool lowerOpen = false, bool upperOpen = false);
606
607//! returns a Query for matching an atom's minimum ring size
608template <class T>
609T *makeAtomMinRingSizeQuery(int tgt, const std::string &descr) {
611}
612//! \overload
614
615//! returns a Query for matching atoms with a particular number of ring bonds
616template <class T>
617T *makeAtomRingBondCountQuery(int what, const std::string &descr) {
619}
620//! \overload
622
623//! returns a Query for matching generic A atoms (heavy atoms)
625//! returns a Query for matching generic AH atoms (any atom)
627//! returns a Query for matching generic Q atoms (heteroatoms)
629//! returns a Query for matching generic QH atoms (heteroatom or H)
631//! returns a Query for matching generic X atoms (halogens)
633//! returns a Query for matching generic XH atoms (halogen or H)
635//! returns a Query for matching generic M atoms (metals)
637//! returns a Query for matching generic MH atoms (metals or H)
639
640// We support the same special atom queries that we can read from
641// CXSMILES
642const std::vector<std::string> complexQueries = {"A", "AH", "Q", "QH",
643 "X", "XH", "M", "MH"};
645 std::string_view symb);
646
647//! returns a Query for matching atoms that have ring bonds
648template <class T>
649T *makeAtomHasRingBondQuery(const std::string &descr) {
651}
652//! \overload
654
655//! returns a Query for matching the number of heteroatom neighbors
656template <class T>
657T *makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr) {
659}
660//! \overload
662 int what);
663
664//! returns a Query for matching atoms that have heteroatom neighbors
665template <class T>
666T *makeAtomHasHeteroatomNbrsQuery(const std::string &descr) {
668}
669//! \overload
671
672//! returns a Query for matching the number of aliphatic heteroatom neighbors
673template <class T>
674T *makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr) {
676 descr);
677}
678//! \overload
681
682//! returns a Query for matching atoms that have heteroatom neighbors
683template <class T>
687//! \overload
690
691//! returns a Query for matching the number of non-hydrogen neighbors
692template <class T>
693T *makeAtomNonHydrogenDegreeQuery(int what, const std::string &descr) {
695}
696//! \overload
698 int what);
699
700//! returns a Query for matching bridgehead atoms
701template <class T>
702T *makeAtomIsBridgeheadQuery(const std::string &descr) {
704}
705//! \overload
707
708//! returns a Query for matching bond orders
710 Bond::BondType what);
711//! returns a Query for unspecified SMARTS bonds
713//! returns a Query for double|aromatic bonds
715//! returns a Query for single|double bonds
717//! returns a Query for tautomeric bonds
720
721//! returns a Query for matching bond directions
723 Bond::BondDir what);
724//! returns a Query for matching bonds with stereo set
726//! returns a Query for matching ring bonds
728//! returns a Query for matching bonds in rings of a particular size
730//! returns a Query for matching a bond's minimum ring size
732//! returns a Query for matching bonds in a particular number of rings
734
735//! returns a Query for matching any bond
737//! returns a Query for matching any atom
739
740static inline int queryAtomRingMembership(Atom const *at) {
741 return static_cast<int>(
742 at->getOwningMol().getRingInfo()->numAtomRings(at->getIdx()));
743}
744// I'm pretty sure that this typedef shouldn't be necessary,
745// but VC++ generates a warning about const Atom const * in
746// the definition of Match, then complains about an override
747// that differs only by const/volatile (c4301), then generates
748// incorrect code if we don't do this... so let's do it.
749typedef Atom const *ConstAtomPtr;
750
752 : public Queries::EqualityQuery<int, ConstAtomPtr, true> {
753 public:
755 // default is to just do a number of rings query:
756 this->setDescription("AtomInNRings");
758 }
759 explicit AtomRingQuery(int v)
760 : Queries::EqualityQuery<int, ConstAtomPtr, true>(v) {
761 // default is to just do a number of rings query:
762 this->setDescription("AtomInNRings");
764 }
765
766 bool Match(const ConstAtomPtr what) const override {
767 int v = this->TypeConvert(what, Queries::Int2Type<true>());
768 bool res;
769 if (this->d_val < 0) {
770 res = v != 0;
771 } else {
772 res = !Queries::queryCmp(v, this->d_val, this->d_tol);
773 }
774 if (this->getNegation()) {
775 res = !res;
776 }
777 return res;
778 }
779
780 //! returns a copy of this query
782 AtomRingQuery *res = new AtomRingQuery(this->d_val);
783 res->setNegation(getNegation());
784 res->setTol(this->getTol());
785 res->d_description = this->d_description;
786 res->d_dataFunc = this->d_dataFunc;
787 return res;
788 }
789};
790
791//! allows use of recursive structure queries (e.g. recursive SMARTS)
793 : public Queries::SetQuery<int, Atom const *, true> {
794 public:
795 RecursiveStructureQuery() : Queries::SetQuery<int, Atom const *, true>() {
797 setDescription("RecursiveStructure");
798 }
799 //! initialize from an ROMol pointer
800 /*!
801 <b>Notes</b>
802 - this takes over ownership of the pointer
803 */
804 RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber = 0)
805 : Queries::SetQuery<int, Atom const *, true>(),
806 d_serialNumber(serialNumber) {
807 setQueryMol(query);
809 setDescription("RecursiveStructure");
810 }
811 //! returns the index of an atom
812 static inline int getAtIdx(Atom const *at) {
813 PRECONDITION(at, "bad atom argument");
814 return at->getIdx();
815 }
816
817 //! sets the molecule we'll use recursively
818 /*!
819 <b>Notes</b>
820 - this takes over ownership of the pointer
821 */
822 void setQueryMol(ROMol const *query) { dp_queryMol.reset(query); }
823 //! returns a pointer to our query molecule
824 ROMol const *getQueryMol() const { return dp_queryMol.get(); }
825
826 //! returns a copy of this query
829 res->dp_queryMol.reset(new ROMol(*dp_queryMol, true));
830
831 std::set<int>::const_iterator i;
832 for (i = d_set.begin(); i != d_set.end(); i++) {
833 res->insert(*i);
834 }
835 res->setNegation(getNegation());
837 res->d_serialNumber = d_serialNumber;
838 res->df_initialized = df_initialized;
839 return res;
840 }
841 unsigned int getSerialNumber() const { return d_serialNumber; }
842 void setInitialized(bool initialized) { df_initialized = initialized; }
843 bool getInitialized() const { return df_initialized; }
844
845#ifdef RDK_BUILD_THREADSAFE_SSS
846 std::mutex d_mutex;
847#endif
848 private:
849 boost::shared_ptr<const ROMol> dp_queryMol;
850 unsigned int d_serialNumber{0};
851 bool df_initialized{false};
852};
853
854template <typename T>
856 return 1;
857}
858template <typename T>
860 return true;
861}
862
863typedef Bond const *ConstBondPtr;
864
865// ! Query whether an atom has a property
866template <class TargetPtr>
867class HasPropQuery : public Queries::EqualityQuery<int, TargetPtr, true> {
868 std::string propname;
869
870 public:
871 HasPropQuery() : Queries::EqualityQuery<int, TargetPtr, true>(), propname() {
872 this->setDescription("HasProp");
873 this->setDataFunc(nullptr);
874 }
875 explicit HasPropQuery(std::string v)
876 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(std::move(v)) {
877 this->setDescription("HasProp");
878 this->setDataFunc(nullptr);
879 }
880
881 bool Match(const TargetPtr what) const override {
882 bool res = what->hasProp(propname);
883 if (this->getNegation()) {
884 res = !res;
885 }
886 return res;
887 }
888
889 //! returns a copy of this query
891 HasPropQuery *res = new HasPropQuery(this->propname);
892 res->setNegation(this->getNegation());
893 res->d_description = this->d_description;
894 return res;
895 }
896
897 const std::string &getPropName() const { return propname; }
898};
899
902
903//! returns a Query for matching atoms that have a particular property
904template <class Target>
906 const std::string &property) {
907 return new HasPropQuery<const Target *>(property);
908}
909
910// ! Query whether an atom has a property with a value
912 public:
914 virtual ~HasPropWithValueQueryBase() = default;
915 virtual PairHolder getPair() const = 0;
916 virtual double getTolerance() const = 0;
917};
918
919template <class TargetPtr, class T>
922 public Queries::EqualityQuery<int, TargetPtr, true> {
923 std::string propname;
924 T val;
925 double tolerance{0.0};
926
927 public:
929 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
930 // default is to just do a number of rings query:
931 this->setDescription("HasPropWithValue");
932 this->setDataFunc(0);
933 }
934
935 PairHolder getPair() const override {
936 return PairHolder(Dict::Pair(propname, val));
937 }
938
939 double getTolerance() const override { return tolerance; }
940
941 explicit HasPropWithValueQuery(std::string prop, const T &v,
942 const T &tol = 0.0)
943 : Queries::EqualityQuery<int, TargetPtr, true>(),
944 propname(std::move(prop)),
945 val(v),
946 tolerance(tol) {
947 // default is to just do a number of rings query:
948 this->setDescription("HasPropWithValue");
949 this->setDataFunc(nullptr);
950 }
951
952 bool Match(const TargetPtr what) const override {
953 bool res = what->hasProp(propname);
954 if (res) {
955 try {
956 T atom_val = what->template getProp<T>(propname);
957 res = Queries::queryCmp(atom_val, this->val,
958 static_cast<T>(this->tolerance)) == 0;
959 } catch (KeyErrorException &) {
960 res = false;
961 } catch (std::bad_any_cast &) {
962 res = false;
963 }
964#ifdef __GNUC__
965#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
966 catch (...) {
967 // catch all -- this is currently necessary to
968 // trap some bugs in boost+gcc configurations
969 // Normally, this is not the correct thing to
970 // do, but the only exception above is due
971 // to the boost any_cast which is trapped
972 // by the Boost python wrapper when it shouldn't
973 // be.
974 res = false;
975 }
976#endif
977#endif
978 }
979 if (this->getNegation()) {
980 res = !res;
981 }
982 return res;
983 }
984
985 //! returns a copy of this query
988 new HasPropWithValueQuery(this->propname, this->val, this->tolerance);
989 res->setNegation(this->getNegation());
990 res->d_description = this->d_description;
991 return res;
992 }
993};
994
995template <class TargetPtr>
996class HasPropWithValueQuery<TargetPtr, std::string>
998 public Queries::EqualityQuery<int, TargetPtr, true> {
999 std::string propname;
1000 std::string val;
1001
1002 public:
1004 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
1005 // default is to just do a number of rings query:
1006 this->setDescription("HasPropWithValue");
1007 this->setDataFunc(0);
1008 }
1009 explicit HasPropWithValueQuery(std::string prop, std::string v,
1010 const double /*tol*/ = 0.0)
1011 : Queries::EqualityQuery<int, TargetPtr, true>(),
1012 propname(std::move(prop)),
1013 val(std::move(v)) {
1014 // default is to just do a number of rings query:
1015 this->setDescription("HasPropWithValue");
1016 this->setDataFunc(nullptr);
1017 }
1018
1019 PairHolder getPair() const override {
1020 return PairHolder(Dict::Pair(propname, val));
1021 }
1022
1023 double getTolerance() const override { return 0.0; }
1024
1025 bool Match(const TargetPtr what) const override {
1026 bool res = what->hasProp(propname);
1027 if (res) {
1028 try {
1029 std::string atom_val = what->template getProp<std::string>(propname);
1030 res = atom_val == this->val;
1031 } catch (KeyErrorException &) {
1032 res = false;
1033 } catch (std::bad_any_cast &) {
1034 res = false;
1035 }
1036#ifdef __GNUC__
1037#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
1038 catch (...) {
1039 // catch all -- this is currently necessary to
1040 // trap some bugs in boost+gcc configurations
1041 // Normally, this is not the correct thing to
1042 // do, but the only exception above is due
1043 // to the boost any_cast which is trapped
1044 // by the Boost python wrapper when it shouldn't
1045 // be.
1046 res = false;
1047 }
1048#endif
1049#endif
1050 }
1051 if (this->getNegation()) {
1052 res = !res;
1053 }
1054 return res;
1055 }
1056
1057 //! returns a copy of this query
1061 this->val);
1062 res->setNegation(this->getNegation());
1063 res->d_description = this->d_description;
1064 return res;
1065 }
1066};
1067
1068template <class TargetPtr>
1071 public Queries::EqualityQuery<int, TargetPtr, true> {
1072 std::string propname;
1073 ExplicitBitVect val;
1074 double tol{0.0};
1075
1076 public:
1078 : Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
1079 this->setDescription("HasPropWithValue");
1080 this->setDataFunc(0);
1081 }
1082
1083 explicit HasPropWithValueQuery(std::string prop, const ExplicitBitVect &v,
1084 double tol = 0.0)
1085 : Queries::EqualityQuery<int, TargetPtr, true>(),
1086 propname(std::move(prop)),
1087 val(v),
1088 tol(tol) {
1089 this->setDescription("HasPropWithValue");
1090 this->setDataFunc(nullptr);
1091 }
1092
1093 PairHolder getPair() const override {
1094 return PairHolder(Dict::Pair(propname, val));
1095 }
1096
1097 double getTolerance() const override { return tol; }
1098
1099 bool Match(const TargetPtr what) const override {
1100 bool res = what->hasProp(propname);
1101 if (res) {
1102 try {
1103 const ExplicitBitVect &bv =
1104 what->template getProp<const ExplicitBitVect &>(propname);
1105 const double tani = TanimotoSimilarity(val, bv);
1106 res = (1.0 - tani) <= tol;
1107 } catch (KeyErrorException &) {
1108 res = false;
1109 } catch (std::bad_any_cast &) {
1110 res = false;
1111 }
1112#ifdef __GNUC__
1113#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
1114 catch (...) {
1115 // catch all -- this is currently necessary to
1116 // trap some bugs in boost+gcc configurations
1117 // Normally, this is not the correct thing to
1118 // do, but the only exception above is due
1119 // to the boost any_cast which is trapped
1120 // by the Boost python wrapper when it shouldn't
1121 // be.
1122 res = false;
1123 }
1124#endif
1125#endif
1126 }
1127 if (this->getNegation()) {
1128 res = !res;
1129 }
1130 return res;
1131 }
1132
1133 //! returns a copy of this query
1137 this->propname, this->val, this->tol);
1138 res->setNegation(this->getNegation());
1139 res->d_description = this->d_description;
1140 return res;
1141 }
1142};
1143
1144template <class Target, class T>
1146 const std::string &propname, const T &val, double tolerance = 0.0) {
1147 return new HasPropWithValueQuery<const Target *, T>(propname, val, tolerance);
1148}
1149
1150template <class Target>
1152 const std::string &propname, const ExplicitBitVect &val,
1153 double tolerance = 0.0) {
1155 propname, val, tolerance);
1156}
1157
1163 std::vector<int> &vals);
1164
1165// Checks if an atom is dummy or not.
1166// 1. A dummy non-query atom (e.g., "*" in SMILES) is defined by its zero atomic
1167// number. This rule breaks for query atoms because a COMPOSITE_OR query atom
1168// also has a zero atomic number (#6349).
1169// 2. A dummy query atom (e.g., "*" in SMARTS) is defined by its explicit
1170// description: "AtomNull".
1171inline bool isAtomDummy(const Atom *a) {
1172 return (!a->hasQuery() && a->getAtomicNum() == 0) ||
1173 (a->hasQuery() && !a->getQuery()->getNegation() &&
1174 a->getQuery()->getDescription() == "AtomNull");
1175}
1176
1177namespace QueryOps {
1179 RWMol *mol, unsigned int magicVal = 0xDEADBEEF);
1180// Replaces the given atom in the molecule with a QueryAtom that is otherwise
1181// a copy of the given atom. Returns a pointer to that atom.
1182// if the atom already has a query, nothing will be changed
1184
1186 Queries::Query<int, Atom const *, true> *query, Atom const *owner);
1188 Queries::Query<int, Bond const *, true> *query, Bond const *owner);
1189
1192inline bool hasBondTypeQuery(const Bond &bond) {
1193 if (!bond.hasQuery()) {
1194 return false;
1195 }
1196 return hasBondTypeQuery(*bond.getQuery());
1197}
1200inline bool hasComplexBondTypeQuery(const Bond &bond) {
1201 if (!bond.hasQuery()) {
1202 return false;
1203 }
1204 return hasComplexBondTypeQuery(*bond.getQuery());
1205}
1206
1208} // namespace QueryOps
1209} // namespace RDKit
1210#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:108
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:57
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:27
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:48
int TypeConvert(int what, Int2Type< false >) const
Definition Query.h:174
std::function< MatchFuncArgType(DataFuncArgType)> d_dataFunc
Definition Query.h:169
void setDataFunc(std::function< MatchFuncArgType(DataFuncArgType)> what)
sets our data function
Definition Query.h:99
void setNegation(bool what)
sets whether or not we are negated
Definition Query.h:62
const std::string & getDescription() const
returns our text description
Definition Query.h:73
void setDescription(const std::string &descr)
sets our text description
Definition Query.h:67
std::string d_description
Definition Query.h:157
a Query implementing a range: arguments must fall in a particular range of values.
Definition RangeQuery.h:28
void setEndsOpen(bool lower, bool upper)
sets whether or not the ends of the range are open
Definition RangeQuery.h:47
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:766
Queries::Query< int, ConstAtomPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:781
The class for representing atoms.
Definition Atom.h:75
ChiralType getChiralTag() const
returns our chiralTag
Definition Atom.h:245
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
Definition Atom.h:157
Queries::Query< int, Atom const *, true > QUERYATOM_QUERY
Definition Atom.h:90
@ CHI_UNSPECIFIED
chirality that hasn't been specified
Definition Atom.h:107
unsigned int getIdx() const
returns our index within the ROMol
Definition Atom.h:163
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:225
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
Definition Atom.h:208
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:146
virtual bool hasQuery() const
Definition Atom.h:269
HybridizationType getHybridization() const
returns our hybridization
Definition Atom.h:252
bool getIsAromatic() const
returns our isAromatic flag
Definition Atom.h:230
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:212
double getMass() const
returns our mass
unsigned int getIsotope() const
returns our isotope number
Definition Atom.h:238
unsigned int getTotalDegree() const
virtual QUERYATOM_QUERY * getQuery() const
returns nullptr
unsigned int getDegree() const
class for representing a bond
Definition Bond.h:48
unsigned int getIdx() const
returns our index within the ROMol
Definition Bond.h:209
virtual QUERYBOND_QUERY * getQuery() const
NOT CALLABLE.
virtual bool hasQuery() const
Definition Bond.h:290
BondType getBondType() const
returns our bondType
Definition Bond.h:163
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
Definition Bond.h:191
BondType
the type of Bond
Definition Bond.h:57
@ AROMATIC
Definition Bond.h:70
@ DOUBLE
Definition Bond.h:60
@ SINGLE
Definition Bond.h:59
@ STEREONONE
Definition Bond.h:97
BondStereo getStereo() const
returns our stereo code
Definition Bond.h:338
BondDir
the bond's direction (for chirality)
Definition Bond.h:84
BondDir getBondDir() const
returns our direction
Definition Bond.h:316
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:890
const std::string & getPropName() const
Definition QueryOps.h:897
HasPropQuery(std::string v)
Definition QueryOps.h:875
bool Match(const TargetPtr what) const override
returns whether or not we match the argument
Definition QueryOps.h:881
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:1083
bool Match(const TargetPtr what) const override
returns whether or not we match the argument
Definition QueryOps.h:1099
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:1134
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:1058
bool Match(const TargetPtr what) const override
returns whether or not we match the argument
Definition QueryOps.h:1025
HasPropWithValueQuery(std::string prop, std::string v, const double=0.0)
Definition QueryOps.h:1009
HasPropWithValueQuery(std::string prop, const T &v, const T &tol=0.0)
Definition QueryOps.h:941
PairHolder getPair() const override
Definition QueryOps.h:935
bool Match(const TargetPtr what) const override
returns whether or not we match the argument
Definition QueryOps.h:952
double getTolerance() const override
Definition QueryOps.h:939
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:986
bool hasProp(const std::string_view key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition RDProps.h:132
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:774
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
Definition ROMol.h:877
RWMol is a molecule class that is intended to be edited.
Definition RWMol.h:32
RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber=0)
initialize from an ROMol pointer
Definition QueryOps.h:804
unsigned int getSerialNumber() const
Definition QueryOps.h:841
Queries::Query< int, Atom const *, true > * copy() const override
returns a copy of this query
Definition QueryOps.h:827
ROMol const * getQueryMol() const
returns a pointer to our query molecule
Definition QueryOps.h:824
void setInitialized(bool initialized)
Definition QueryOps.h:842
static int getAtIdx(Atom const *at)
returns the index of an atom
Definition QueryOps.h:812
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
Definition QueryOps.h:822
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:321
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition Query.h:202
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)
constexpr std::string_view _ChiralityPossible
Definition types.h:77
Std stuff.
Queries::LessQuery< int, Bond const *, true > BOND_LESS_QUERY
Definition QueryOps.h:59
static int queryAtomNumRadicalElectrons(Atom const *at)
Definition QueryOps.h:176
static int queryAtomIsInRingOfSize(Atom const *at, int tgt)
Definition QueryOps.h:327
T * makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr)
returns a Query for matching heavy atom degree
Definition QueryOps.h:458
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:58
static int queryAtomHybridization(Atom const *at)
Definition QueryOps.h:173
static int queryAtomMinRingSize(Atom const *at)
Definition QueryOps.h:305
T * makeAtomTotalDegreeQuery(int what, const std::string &descr)
returns a Query for matching atomic degree
Definition QueryOps.h:450
Queries::LessEqualQuery< int, Bond const *, true > BOND_LESSEQUAL_QUERY
Definition QueryOps.h:62
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:82
static int queryAtomHasRingBond(Atom const *at)
Definition QueryOps.h:288
Bond const * ConstBondPtr
Definition QueryOps.h:863
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrDoubleBondQuery()
returns a Query for single|double bonds
static int queryBondHasStereo(Bond const *bnd)
Definition QueryOps.h:275
static int queryAtomUnsaturated(Atom const *at)
Definition QueryOps.h:132
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrAromaticBondQuery()
returns a Query for unspecified SMARTS bonds
static ATOM_RANGE_QUERY * makeAtomRangeQuery(int lower, int upper, bool lowerOpen, bool upperOpen, std::function< int(Atom const *)> func, const std::string &description="Atom Range")
Definition QueryOps.h:387
static int queryAtomAromatic(Atom const *at)
Definition QueryOps.h:76
Queries::RangeQuery< int, Atom const *, true > ATOM_RANGE_QUERY
Definition QueryOps.h:64
Queries::Query< bool, Bond const *, true > BOND_BOOL_QUERY
Definition QueryOps.h:36
static int queryAtomType(Atom const *at)
Definition QueryOps.h:156
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:38
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:256
static int queryAtomHasImplicitH(Atom const *at)
Definition QueryOps.h:120
Queries::LessEqualQuery< int, Atom const *, true > ATOM_LESSEQUAL_QUERY
Definition QueryOps.h:61
Queries::EqualityQuery< int, const Target *, true > * makePropQuery(const std::string &propname, const T &val, double tolerance=0.0)
Definition QueryOps.h:1145
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInRingOfSizeQuery(int what)
returns a Query for matching bonds in rings of a particular size
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeDoubleOrAromaticBondQuery()
returns a Query for double|aromatic bonds
RDKIT_GRAPHMOL_EXPORT ATOM_NULL_QUERY * makeAtomNullQuery()
returns a Query for matching any atom
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomAllBondProduct(Atom const *at)
double TanimotoSimilarity(const SparseIntVect< IndexType > &v1, const SparseIntVect< IndexType > &v2, bool returnDistance=false, double bounds=0.0)
bool nullQueryFun(T)
Definition QueryOps.h:859
static int queryAtomNegativeFormalCharge(Atom const *at)
Definition QueryOps.h:170
Queries::SetQuery< int, Atom const *, true > ATOM_SET_QUERY
Definition QueryOps.h:67
static int queryAtomHasHeteroatomNbrs(Atom const *at)
Definition QueryOps.h:187
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:434
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:44
bool isAtomDummy(const Atom *a)
Definition QueryOps.h:1171
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:68
static int queryBondIsSingleOrAromatic(Bond const *bond)
Definition QueryOps.h:252
T * makeAtomFormalChargeQuery(int what, const std::string &descr)
returns a Query for matching formal charge
Definition QueryOps.h:523
Queries::OrQuery< int, Bond const *, true > BOND_OR_QUERY
Definition QueryOps.h:42
static int queryBondMinRingSize(Bond const *bond)
Definition QueryOps.h:308
const int massIntegerConversionFactor
Definition QueryOps.h:159
T * makeAtomNumRadicalElectronsQuery(int what, const std::string &descr)
returns a Query for matching the number of radical electrons
Definition QueryOps.h:549
static int queryAtomTotalValence(Atom const *at)
Definition QueryOps.h:129
static int queryAtomNonHydrogenDegree(Atom const *at)
D and T are treated as "non-hydrogen" here.
Definition QueryOps.h:89
T * makeAtomRingBondCountQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular number of ring bonds
Definition QueryOps.h:617
static int makeAtomType(int atomic_num, bool aromatic)
Definition QueryOps.h:136
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:609
static int queryAtomHeavyAtomDegree(Atom const *at)
D and T are not treated as heavy atoms here.
Definition QueryOps.h:102
static int queryAtomRingBondCount(Atom const *at)
Definition QueryOps.h:312
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:482
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:506
T * makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of aliphatic heteroatom neighbors
Definition QueryOps.h:674
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
Definition QueryOps.h:45
Queries::Query< int, Atom const *, true > ATOM_NULL_QUERY
Definition QueryOps.h:71
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomMissingChiralTagQuery()
\overloadquery
static int queryAtomAliphatic(Atom const *at)
Definition QueryOps.h:79
static int queryAtomNumHeteroatomNbrs(Atom const *at)
Definition QueryOps.h:200
static bool getAtomTypeIsAromatic(int val)
Definition QueryOps.h:148
static int queryIsAtomInNRings(Atom const *at)
Definition QueryOps.h:282
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:179
Queries::EqualityQuery< int, Bond const *, true > BOND_PROP_QUERY
Definition QueryOps.h:901
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
Definition QueryOps.h:41
static int queryAtomImplicitHCount(Atom const *at)
Definition QueryOps.h:117
static int queryAtomFormalCharge(Atom const *at)
Definition QueryOps.h:167
T * makeAtomNonHydrogenDegreeQuery(int what, const std::string &descr)
returns a Query for matching the number of non-hydrogen neighbors
Definition QueryOps.h:693
RDKIT_GRAPHMOL_EXPORT int queryIsAtomBridgehead(Atom const *at)
static int queryAtomNum(Atom const *at)
Definition QueryOps.h:135
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
Definition QueryOps.h:56
static int queryIsAtomInRing(Atom const *at)
Definition QueryOps.h:285
static int queryAtomHCount(Atom const *at)
Definition QueryOps.h:114
T * makeAtomImplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching implicit valence
Definition QueryOps.h:418
static int queryAtomExplicitValence(Atom const *at)
Definition QueryOps.h:126
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:160
static int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at)
Definition QueryOps.h:214
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:228
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
Definition QueryOps.h:48
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
Definition QueryOps.h:50
T * makeAtomExplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching explicit valence
Definition QueryOps.h:426
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:368
Queries::AndQuery< int, Bond const *, true > BOND_AND_QUERY
Definition QueryOps.h:39
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:264
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:442
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:47
static int queryIsBondInNRings(Bond const *at)
Definition QueryOps.h:272
static int queryAtomTotalDegree(Atom const *at)
Definition QueryOps.h:85
Queries::Query< int, Bond const *, true > BOND_NULL_QUERY
Definition QueryOps.h:70
T * makeAtomInNRingsQuery(int what, const std::string &descr)
returns a Query for matching atoms in a particular number of rings
Definition QueryOps.h:592
RDKIT_GRAPHMOL_EXPORT bool isComplexQuery(const Bond *b)
Queries::EqualityQuery< int, Atom const *, true > ATOM_PROP_QUERY
Definition QueryOps.h:900
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:269
T * makeAtomIsotopeQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular isotope
Definition QueryOps.h:515
static int getAtomTypeAtomicNum(int val)
Definition QueryOps.h:149
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:855
const std::vector< std::string > complexQueries
Definition QueryOps.h:642
T * makeAtomNegativeFormalChargeQuery(int what, const std::string &descr)
Definition QueryOps.h:532
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
Definition QueryOps.h:400
static int queryBondIsSingleOrDouble(Bond const *bond)
Definition QueryOps.h:260
Atom const * ConstAtomPtr
Definition QueryOps.h:749
T * makeAtomHCountQuery(int what, const std::string &descr)
returns a Query for matching hydrogen count
Definition QueryOps.h:466
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:905
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:54
static int queryAtomIsotope(Atom const *at)
Definition QueryOps.h:164
T * makeAtomInRingOfSizeQuery(int tgt, const std::string &descr)
returns a Query for matching atoms in rings of a particular size
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:408
Queries::RangeQuery< int, Bond const *, true > BOND_RANGE_QUERY
Definition QueryOps.h:65
static int queryAtomImplicitValence(Atom const *at)
Definition QueryOps.h:123
T * makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of heteroatom neighbors
Definition QueryOps.h:657
static int queryIsBondInRing(Bond const *bond)
Definition QueryOps.h:302
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:249
static int queryAtomRingMembership(Atom const *at)
Definition QueryOps.h:740
static void parseAtomType(int val, int &atomic_num, bool &aromatic)
Definition QueryOps.h:139
T * makeAtomHybridizationQuery(int what, const std::string &descr)
returns a Query for matching hybridization
Definition QueryOps.h:541
Queries::GreaterQuery< int, Bond const *, true > BOND_GREATER_QUERY
Definition QueryOps.h:51
T * makeAtomSimpleQuery(int what, std::function< int(Atom const *)> func, const std::string &description="Atom Simple")
Definition QueryOps.h:378
static int queryAtomMissingChiralTag(Atom const *at)
Definition QueryOps.h:182
Queries::Query< bool, Atom const *, true > ATOM_BOOL_QUERY
Definition QueryOps.h:35