16 #ifndef _RD_QUERY_OPS_H 17 #define _RD_QUERY_OPS_H 25 #ifdef RDK_THREADSAFE_SSS 88 ROMol::ADJ_ITER nbrIdx, endNbrs;
90 while (nbrIdx != endNbrs) {
123 return atomic_num + 1000 *
static_cast<int>(aromatic);
125 static inline void parseAtomType(
int val,
int &atomic_num,
bool &aromatic) {
128 atomic_num = val - 1000;
135 if (val > 1000)
return true;
139 if (val > 1000)
return val - 1000;
148 return static_cast<int>(
round(massIntegerConversionFactor * at->
getMass()));
171 ROMol::ADJ_ITER nbrIdx, endNbrs;
173 while (nbrIdx != endNbrs) {
185 ROMol::ADJ_ITER nbrIdx, endNbrs;
187 while (nbrIdx != endNbrs) {
198 ROMol::ADJ_ITER nbrIdx, endNbrs;
200 while (nbrIdx != endNbrs) {
213 ROMol::ADJ_ITER nbrIdx, endNbrs;
215 while (nbrIdx != endNbrs) {
260 while (atomBonds.first != atomBonds.second) {
261 unsigned int bondIdx =
284 while (atomBonds.first != atomBonds.second) {
285 unsigned int bondIdx =
315 const std::string &description =
"Atom Simple") {
318 res->setDataFunc(func);
319 res->setDescription(description);
324 int lower,
int upper,
bool lowerOpen,
bool upperOpen,
325 int func(
Atom const *),
const std::string &description =
"Atom Range") {
336 return makeAtomSimpleQuery<T>(what,
queryAtomNum, descr);
442 return makeAtomSimpleQuery<T>(massIntegerConversionFactor * what,
628 return static_cast<int>(
643 this->setDescription(
"AtomInNRings");
647 :
Queries::EqualityQuery<int, ConstAtomPtr, true>(v) {
649 this->setDescription(
"AtomInNRings");
653 virtual bool Match(
const ConstAtomPtr what)
const {
656 if (this->d_val < 0) {
661 if (this->getNegation()) {
671 res->
setTol(this->getTol());
683 :
Queries::SetQuery<int,
Atom const *, true>(), d_serialNumber(0) {
684 setDataFunc(getAtIdx);
685 setDescription(
"RecursiveStructure");
694 d_serialNumber(serialNumber) {
696 setDataFunc(getAtIdx);
697 setDescription(
"RecursiveStructure");
717 res->dp_queryMol.reset(
new ROMol(*dp_queryMol,
true));
719 std::set<int>::const_iterator i;
720 for (i = d_set.begin(); i != d_set.end(); i++) {
725 res->d_serialNumber = d_serialNumber;
730 #ifdef RDK_THREADSAFE_SSS 734 boost::shared_ptr<const ROMol> dp_queryMol;
735 unsigned int d_serialNumber;
738 template <
typename T>
742 template <
typename T>
750 template <
class TargetPtr>
752 std::string propname;
757 this->setDescription(
"AtomHasProp");
758 this->setDataFunc(0);
761 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(v) {
763 this->setDescription(
"AtomHasProp");
764 this->setDataFunc(0);
767 virtual bool Match(
const TargetPtr what)
const {
768 bool res = what->hasProp(propname);
769 if (this->getNegation()) {
788 template <
class Target>
790 const std::string &property) {
795 template <
class TargetPtr,
class T>
798 std::string propname;
804 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
806 this->setDescription(
"HasPropWithValue");
807 this->setDataFunc(0);
811 :
Queries::EqualityQuery<int, TargetPtr, true>(),
816 this->setDescription(
"HasPropWithValue");
817 this->setDataFunc(0);
820 virtual bool Match(
const TargetPtr what)
const {
821 bool res = what->hasProp(propname);
824 T atom_val = what->template getProp<T>(propname);
828 }
catch (boost::bad_any_cast &) {
832 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 846 if (this->getNegation()) {
862 template <
class TargetPtr>
865 std::string propname;
870 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val() {
872 this->setDescription(
"HasPropWithValue");
873 this->setDataFunc(0);
876 const std::string &tol =
"")
877 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(prop), val(v) {
880 this->setDescription(
"HasPropWithValue");
881 this->setDataFunc(0);
884 virtual bool Match(
const TargetPtr what)
const {
885 bool res = what->hasProp(propname);
888 std::string atom_val = what->template getProp<std::string>(propname);
889 res = atom_val == this->val;
892 }
catch (boost::bad_any_cast &) {
896 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 910 if (this->getNegation()) {
927 template <
class TargetPtr>
930 std::string propname;
936 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(), val(), tol(0.0) {
937 this->setDescription(
"HasPropWithValue");
938 this->setDataFunc(0);
944 :
Queries::EqualityQuery<int, TargetPtr, true>(), propname(prop), val(v), tol(tol) {
945 this->setDescription(
"HasPropWithValue");
946 this->setDataFunc(0);
949 virtual bool Match(
const TargetPtr what)
const {
950 bool res = what->hasProp(propname);
953 const ExplicitBitVect &bv = what->template getProp<const ExplicitBitVect&>(propname);
955 res = (1.0 - tani) <= tol;
958 }
catch (boost::bad_any_cast) {
962 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 976 if (this->getNegation()) {
994 template <
class Target,
class T>
996 const std::string &propname,
const T &val,
const T &tolerance = T()) {
1000 template <
class Target>
1002 const std::string &propname,
const ExplicitBitVect &val,
float tolerance=0.0) {
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
Pulls in all the BitVect classes.
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)
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
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:
double TanimotoSimilarity(const SparseIntVect< IndexType > &v1, const SparseIntVect< IndexType > &v2, bool returnDistance=false, double bounds=0.0)
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
Contains general bit-comparison and similarity operations.
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
HasPropWithValueQuery(const std::string &prop, const ExplicitBitVect &v, float tol=0.0)
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
a class for bit vectors that are densely occupied
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::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Queries::SetQuery< int, Atom const *, true > ATOM_SET_QUERY
static int queryIsBondInNRings(Bond const *at)