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