16 #ifndef _RD_QUERY_OPS_H 17 #define _RD_QUERY_OPS_H 23 #ifdef RDK_THREADSAFE_SSS 86 ROMol::ADJ_ITER nbrIdx, endNbrs;
88 while (nbrIdx != endNbrs) {
121 return atomic_num + 1000 *
static_cast<int>(aromatic);
123 static inline void parseAtomType(
int val,
int &atomic_num,
bool &aromatic) {
126 atomic_num = val - 1000;
133 if(val>1000)
return true;
137 if(val>1000)
return val-1000;
146 return static_cast<int>(
round(massIntegerConversionFactor * at->
getMass()));
169 ROMol::ADJ_ITER nbrIdx, endNbrs;
171 while (nbrIdx != endNbrs) {
183 ROMol::ADJ_ITER nbrIdx, endNbrs;
185 while (nbrIdx != endNbrs) {
196 ROMol::ADJ_ITER nbrIdx, endNbrs;
198 while (nbrIdx != endNbrs) {
211 ROMol::ADJ_ITER nbrIdx, endNbrs;
213 while (nbrIdx != endNbrs) {
258 while (atomBonds.first != atomBonds.second) {
259 unsigned int bondIdx =
282 while (atomBonds.first != atomBonds.second) {
283 unsigned int bondIdx =
313 const std::string &description =
"Atom Simple") {
316 res->setDataFunc(func);
317 res->setDescription(description);
322 int lower,
int upper,
bool lowerOpen,
bool upperOpen,
323 int func(
Atom const *),
const std::string &description =
"Atom Range") {
334 return makeAtomSimpleQuery<T>(what,
queryAtomNum, descr);
440 return makeAtomSimpleQuery<T>(massIntegerConversionFactor * what,
626 return static_cast<int>(
641 this->setDescription(
"AtomInNRings");
645 :
Queries::EqualityQuery<int, ConstAtomPtr, true>(v) {
647 this->setDescription(
"AtomInNRings");
651 virtual bool Match(
const ConstAtomPtr what)
const {
654 if (this->d_val < 0) {
659 if (this->getNegation()) {
669 res->
setTol(this->getTol());
681 :
Queries::SetQuery<int,
Atom const *, true>(), d_serialNumber(0) {
682 setDataFunc(getAtIdx);
683 setDescription(
"RecursiveStructure");
692 d_serialNumber(serialNumber) {
694 setDataFunc(getAtIdx);
695 setDescription(
"RecursiveStructure");
715 res->dp_queryMol.reset(
new ROMol(*dp_queryMol,
true));
717 std::set<int>::const_iterator i;
718 for (i = d_set.begin(); i != d_set.end(); i++) {
723 res->d_serialNumber = d_serialNumber;
728 #ifdef RDK_THREADSAFE_SSS 732 boost::shared_ptr<const ROMol> dp_queryMol;
733 unsigned int d_serialNumber;
736 template <
typename T>
740 template <
typename T>
748 template <
class TargetPtr>
750 std::string propname;
755 this->setDescription(
"AtomHasProp");
756 this->setDataFunc(0);
759 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(v) {
761 this->setDescription(
"AtomHasProp");
762 this->setDataFunc(0);
765 virtual bool Match(
const TargetPtr what)
const {
766 bool res = what->hasProp(propname);
767 if (this->getNegation()) {
786 template <
class Target>
788 const std::string &property) {
793 template <
class TargetPtr,
class T>
796 std::string propname;
802 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
804 this->setDescription(
"HasPropWithValue");
805 this->setDataFunc(0);
809 :
Queries::EqualityQuery<int, TargetPtr, true>(),
814 this->setDescription(
"HasPropWithValue");
815 this->setDataFunc(0);
818 virtual bool Match(
const TargetPtr what)
const {
819 bool res = what->hasProp(propname);
822 T atom_val = what->template getProp<T>(propname);
826 }
catch (boost::bad_any_cast &) {
830 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 844 if (this->getNegation()) {
860 template <
class TargetPtr>
863 std::string propname;
868 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
870 this->setDescription(
"HasPropWithValue");
871 this->setDataFunc(0);
874 const std::string &tol =
"")
875 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(prop), val(v) {
878 this->setDescription(
"HasPropWithValue");
879 this->setDataFunc(0);
882 virtual bool Match(
const TargetPtr what)
const {
883 bool res = what->hasProp(propname);
886 std::string atom_val = what->template getProp<std::string>(propname);
887 res = atom_val == this->val;
890 }
catch (boost::bad_any_cast &) {
894 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 908 if (this->getNegation()) {
925 template <
class Target,
class T>
927 const std::string &propname,
const T &val,
const T &tolerance = T()) {
HasPropQuery(const std::string &v)
Queries::XOrQuery< int, Atom const *, true > ATOM_XOR_QUERY
T * makeAtomTotalValenceQuery(int what, const std::string &descr)
returns a Query for matching total valence
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondIsInRingQuery()
returns a Query for matching ring bonds
T * makeAtomInRingQuery(const std::string &descr)
returns a Query for matching ring atoms
RDKIT_GRAPHMOL_EXPORT bool isComplexQuery(const Bond *b)
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeQHAtomQuery()
returns a Query for matching generic QH atoms (heteroatom or H)
static int queryAtomTotalDegree(Atom const *at)
static int queryAtomMissingChiralTag(Atom const *at)
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
BondStereo getStereo() const
returns our stereo code
T * makeAtomHybridizationQuery(int what, const std::string &descr)
returns a Query for matching hybridization
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondHasStereoQuery()
returns a Query for matching bonds with stereo set
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomInRingOfSizeQuery(int tgt)
returns a Query for matching atoms in rings of a particular size
static int queryAtomHybridization(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondDirEqualsQuery(Bond::BondDir what)
returns a Query for matching bond directions
T * makeAtomMassQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular mass
static int queryAtomHasHeteroatomNbrs(Atom const *at)
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
Queries::OrQuery< int, Bond const *, true > BOND_OR_QUERY
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this Bond
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeMHAtomQuery()
returns a Query for matching generic MH atoms (metals or H)
Queries::LessQuery< int, Atom const *, true > ATOM_LESS_QUERY
RDKIT_GRAPHMOL_EXPORT BOND_NULL_QUERY * makeBondNullQuery()
returns a Query for matching any bond
void setNegation(bool what)
sets whether or not we are negated
Queries::Query< int, Atom const *, true > ATOM_NULL_QUERY
T * makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of aliphatic heteroatom neighbors
a Query implementing AND: requires all children to be true
T * makeAtomImplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching implicit valence
void setTol(MatchFuncArgType what)
sets our tolerance
Atom const * ConstAtomPtr
Queries::EqualityQuery< int, Bond const *, true > BOND_PROP_QUERY
int getImplicitValence() const
returns the implicit valence for this Atom
a Query implementing AND: requires any child to be true
HybridizationType getHybridization() const
returns our hybridization
unsigned int getTotalNumHs(bool includeNeighbors=false) const
returns the total number of Hs (implicit and explicit) that this Atom is bound to ...
T * makeAtomMinRingSizeQuery(int tgt, const std::string &descr)
returns a Query for matching an atom's minimum ring size
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXAtomQuery()
returns a Query for matching generic X atoms (halogens)
Queries::Query< int, Bond const *, true > BOND_NULL_QUERY
static int queryAtomExplicitDegree(Atom const *at)
bool getIsAromatic() const
returns our isAromatic flag
Queries::GreaterQuery< int, Bond const *, true > BOND_GREATER_QUERY
static int queryBondOrder(Bond const *bond)
T * makeAtomHasAliphaticHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
T * makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of heteroatom neighbors
static int queryAtomImplicitHCount(Atom const *at)
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
Queries::Query< bool, Bond const *, true > BOND_BOOL_QUERY
static int getAtIdx(Atom const *at)
returns the index of an atom
Queries::SetQuery< int, Bond const *, true > BOND_SET_QUERY
T * makeAtomImplicitHCountQuery(int what, const std::string &descr)
returns a Query for matching implicit hydrogen count
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAHAtomQuery()
returns a Query for matching generic AH atoms (any atom)
static int queryAtomMass(Atom const *at)
Queries::EqualityQuery< int, const Target *, true > * makePropQuery(const std::string &propname, const T &val, const T &tolerance=T())
T * makeAtomHasChiralTagQuery(const std::string &descr)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXHAtomQuery()
returns a Query for matching generic XH atoms (halogen or H)
ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const
provides access to all neighbors around an Atom
static int queryAtomNumHeteroatomNbrs(Atom const *at)
pulls in the core RDKit functionality
Queries::GreaterEqualQuery< int, Atom const *, true > ATOM_GREATEREQUAL_QUERY
static int queryBondHasStereo(Bond const *bnd)
static int queryIsBondInRing(Bond const *bond)
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
static int queryBondIsSingleOrAromatic(Bond const *bond)
BondDir getBondDir() const
returns our direction
double getMass() const
returns our mass
int getExplicitValence() const
returns the explicit valence (including Hs) of this atom
static int queryAtomType(Atom const *at)
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
static int queryAtomNumAliphaticHeteroatomNbrs(Atom const *at)
T * makeAtomExplicitDegreeQuery(int what, const std::string &descr)
returns a Query for matching explicit degree
Queries::LessEqualQuery< int, Atom const *, true > ATOM_LESSEQUAL_QUERY
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeMAtomQuery()
returns a Query for matching generic M atoms (metals)
#define RDKIT_GRAPHMOL_EXPORT
static int queryAtomHasChiralTag(Atom const *at)
static int queryBondDir(Bond const *bond)
RingInfo * getRingInfo() const
unsigned int getIsotope() const
returns our isotope number
static int queryAtomUnsaturated(Atom const *at)
Queries::LessEqualQuery< int, Bond const *, true > BOND_LESSEQUAL_QUERY
a Query implementing a range: arguments must fall in a particular range of values.
static ATOM_RANGE_QUERY * makeAtomRangeQuery(int lower, int upper, bool lowerOpen, bool upperOpen, int func(Atom const *), const std::string &description="Atom Range")
int queryAtomIsInRingOfSize(Atom const *at)
T * makeAtomIsotopeQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular isotope
T * makeAtomAliphaticQuery(const std::string &descr)
returns a Query for matching aliphatic atoms
const int massIntegerConversionFactor
T * makeAtomUnsaturatedQuery(const std::string &descr)
returns a Query for matching atoms with unsaturation:
T * makeAtomMissingChiralTagQuery(const std::string &descr)
class to allow integer values to pick templates
static int queryAtomIsotope(Atom const *at)
unsigned int getSerialNumber() const
Queries::LessQuery< int, Bond const *, true > BOND_LESS_QUERY
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
allows use of recursive structure queries (e.g. recursive SMARTS)
RecursiveStructureQuery()
static int makeAtomType(int atomic_num, bool aromatic)
Bond const * ConstBondPtr
static int queryAtomExplicitValence(Atom const *at)
static int queryIsAtomInRing(Atom const *at)
int getFormalCharge() const
returns the formal charge of this atom
a Query implementing <= using a particular value (and an optional tolerance)
Queries::Query< bool, Atom const *, true > ATOM_BOOL_QUERY
unsigned int getIdx() const
returns our index within the ROMol
HasPropWithValueQuery(const std::string &prop, const std::string &v, const std::string &tol="")
static int queryAtomAromatic(Atom const *at)
static int queryBondMinRingSize(Bond const *bond)
static int queryAtomNonHydrogenDegree(Atom const *at)
static int queryAtomNum(Atom const *at)
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
T * makeAtomTypeQuery(int num, int aromatic, const std::string &descr)
returns a Query for matching atomic number and aromaticity
static void parseAtomType(int val, int &atomic_num, bool &aromatic)
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
int getAtomicNum() const
returns our atomic number
bool hasProp(const std::string &key) const
T * makeAtomRingBondCountQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular number of ring bonds
T * makeAtomAromaticQuery(const std::string &descr)
returns a Query for matching the isAromatic flag
static int queryAtomFormalCharge(Atom const *at)
a Query implementing < using a particular value (and an optional tolerance)
void setEndsOpen(bool lower, bool upper)
sets whether or not the ends of the range are open
a Query implementing ==: arguments must match a particular value (within an optional tolerance) ...
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrAromaticBondQuery()
returns a Query for unspecified SMARTS bonds
T * makeAtomFormalChargeQuery(int what, const std::string &descr)
returns a Query for matching formal charge
class for representing a bond
#define RDUNUSED_PARAM(x)
static int queryAtomHeavyAtomDegree(Atom const *at)
T * makeAtomExplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching explicit valence
void insert(const MatchFuncArgType what)
insert an entry into our set
static int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at)
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
unsigned int getNumExplicitHs() const
returns our number of explict Hs
Queries::AndQuery< int, Bond const *, true > BOND_AND_QUERY
BondDir
the bond's direction (for chirality)
RDKIT_RDGENERAL_EXPORT double round(double v)
rounds a value to the closest int
static int queryIsAtomInNRings(Atom const *at)
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
Queries::Query< int, ConstAtomPtr, true > * copy() const
returns a copy of this query
RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber=0)
initialize from an ROMol pointer
ROMol const * getQueryMol() const
returns a pointer to our query molecule
static int queryAtomHasImplicitH(Atom const *at)
#define PRECONDITION(expr, mess)
static int queryAtomMinRingSize(Atom const *at)
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomAllBondProduct(Atom const *at)
Queries::Query< int, Atom const *, true > * copy() const
returns a copy of this query
unsigned int getDegree() const
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this Atom
Queries::AndQuery< int, Atom const *, true > ATOM_AND_QUERY
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAAtomQuery()
returns a Query for matching generic A atoms (heavy atoms)
static int queryAtomNumRadicalElectrons(Atom const *at)
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
T * makeAtomHasRingBondQuery(const std::string &descr)
returns a Query for matching atoms that have ring bonds
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondOrderEqualsQuery(Bond::BondType what)
returns a Query for matching bond orders
Queries::EqualityQuery< int, Atom const *, true > ATOM_EQUALS_QUERY
std::string d_description
BondType getBondType() const
returns our bondType
T * makeAtomHasImplicitHQuery(const std::string &descr)
returns a Query for matching ring atoms
T * makeAtomInNRingsQuery(int what, const std::string &descr)
returns a Query for matching atoms in a particular number of rings
static int queryAtomAliphatic(Atom const *at)
Queries::RangeQuery< int, Atom const *, true > ATOM_RANGE_QUERY
HasPropWithValueQuery(const std::string &prop, const T &v, const T &tol=0.0)
T * makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr)
returns a Query for matching heavy atom degree
a Query implementing > using a particular value (and an optional tolerance)
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomBondProduct(Atom const *at)
static int queryAtomRingBondCount(Atom const *at)
a Query implementing >= using a particular value (and an optional tolerance)
Pulls in all the query types.
T * makeAtomNumRadicalElectronsQuery(int what, const std::string &descr)
returns a Query for matching the number of radical electrons
RDKIT_RDGENERAL_EXPORT const std::string _ChiralityPossible
ChiralType getChiralTag() const
returns our chiralTag
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
chirality that hasn't been specified
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInRingOfSizeQuery(int what)
returns a Query for matching bonds in rings of a particular size
unsigned int getTotalDegree() const
T * makeAtomSimpleQuery(int what, int func(Atom const *), const std::string &description="Atom Simple")
static int getAtomTypeAtomicNum(int val)
unsigned int numAtomRings(unsigned int idx) const
returns the number of rings atom idx is involved in
T * makeAtomHasHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
int queryBondIsInRingOfSize(Bond const *bond)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInNRingsQuery(int tgt)
returns a Query for matching bonds in a particular number of rings
static int queryAtomHasRingBond(Atom const *at)
virtual bool Match(const ConstAtomPtr what) const
bool isBondInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the bond with index idx is in a size - ring.
static bool getAtomTypeIsAromatic(int val)
static int queryAtomRingMembership(Atom const *at)
Queries::EqualityQuery< int, Atom const *, true > ATOM_PROP_QUERY
unsigned int minAtomRingSize(unsigned int idx) const
returns the size of the smallest ring atom idx is involved in
Base class for all queries.
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondMinRingSizeQuery(int what)
returns a Query for matching a bond's minimum ring size
static int queryAtomHCount(Atom const *at)
Queries::RangeQuery< int, Bond const *, true > BOND_RANGE_QUERY
static int queryAtomTotalValence(Atom const *at)
unsigned int getIdx() const
returns our index within the ROMol
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
The class for representing atoms.
a Query implementing XOR: requires exactly one child to be true
void setDescription(const std::string &descr)
sets our text description
Queries::EqualityQuery< int, const Target *, true > * makeHasPropQuery(const std::string &property)
returns a Query for matching atoms that have a particular property
static int queryAtomImplicitValence(Atom const *at)
Class to allow us to throw a KeyError from C++ and have it make it back to Python.
RDKIT_GRAPHMOL_EXPORT bool isAtomAromatic(const Atom *a)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeQAtomQuery()
returns a Query for matching generic Q atoms (heteroatoms)
T * makeAtomHCountQuery(int what, const std::string &descr)
returns a Query for matching hydrogen count
T * makeAtomTotalDegreeQuery(int what, const std::string &descr)
returns a Query for matching atomic degree
RDKIT_GRAPHMOL_EXPORT ATOM_NULL_QUERY * makeAtomNullQuery()
returns a Query for matching any atom
Queries::SetQuery< int, Atom const *, true > ATOM_SET_QUERY
static int queryIsBondInNRings(Bond const *at)