15 #ifndef _RD_QUERY_OPS_H 16 #define _RD_QUERY_OPS_H 22 #ifdef RDK_THREADSAFE_SSS 23 #include <boost/thread/mutex.hpp> 107 return static_cast<int>(
round(massIntegerConversionFactor * at->
getMass()));
145 while (atomBonds.first != atomBonds.second) {
146 unsigned int bondIdx =
169 while (atomBonds.first != atomBonds.second) {
170 unsigned int bondIdx =
200 const std::string &description =
"Atom Simple") {
203 res->setDataFunc(func);
204 res->setDescription(description);
211 return makeAtomSimpleQuery<T>(what,
queryAtomNum, descr);
299 return makeAtomSimpleQuery<T>(massIntegerConversionFactor * what,
399 return static_cast<int>(
423 virtual bool Match(
const ConstAtomPtr what)
const {
426 if (this->
d_val < 0) {
453 :
Queries::SetQuery<int,
Atom const *, true>(), d_serialNumber(0) {
464 d_serialNumber(serialNumber) {
487 res->dp_queryMol.reset(
new ROMol(*dp_queryMol,
true));
489 std::set<int>::const_iterator i;
490 for (i = d_set.begin(); i != d_set.end(); i++) {
495 res->d_serialNumber = d_serialNumber;
500 #ifdef RDK_THREADSAFE_SSS 501 boost::mutex d_mutex;
504 boost::shared_ptr<const ROMol> dp_queryMol;
505 unsigned int d_serialNumber;
508 template <
typename T>
512 template <
typename T>
520 template <
class TargetPtr>
522 std::string propname;
537 virtual bool Match(
const TargetPtr what)
const {
538 bool res = what->hasProp(propname);
558 template <
class Target>
560 const std::string &property) {
565 template <
class TargetPtr,
class T>
568 std::string propname;
590 virtual bool Match(
const TargetPtr what)
const {
591 bool res = what->hasProp(propname);
594 T atom_val = what->template getProp<T>(propname);
599 catch (boost::bad_any_cast) {
603 #if (__GNUC__ < 4 || \ 604 (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 634 template <
class TargetPtr>
637 std::string propname;
648 const std::string &tol =
"")
656 virtual bool Match(
const TargetPtr what)
const {
657 bool res = what->hasProp(propname);
660 std::string atom_val = what->template getProp<std::string>(propname);
661 res = atom_val == this->val;
664 }
catch (boost::bad_any_cast) {
668 #if (__GNUC__ < 4 || \ 669 (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 700 template <
class Target,
class T>
702 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
T * makeAtomInRingQuery(const std::string &descr)
returns a Query for matching ring atoms
static int queryAtomTotalDegree(Atom const *at)
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
T * makeAtomHybridizationQuery(int what, const std::string &descr)
returns a Query for matching hybridization
static int queryAtomHybridization(Atom const *at)
T * makeAtomMassQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular mass
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
double round(double v)
rounds a value to the closest int
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this Bond
Queries::LessQuery< int, Atom const *, true > ATOM_LESS_QUERY
void setNegation(bool what)
sets whether or not we are negated
Queries::Query< int, Atom const *, true > ATOM_NULL_QUERY
ATOM_NULL_QUERY * makeAtomNullQuery()
returns a Query for matching any atom
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
BOND_EQUALS_QUERY * makeBondOrderEqualsQuery(Bond::BondType what)
returns a Query for matching bond orders
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 ...
unsigned int queryAtomAllBondProduct(Atom const *at)
T * makeAtomMinRingSizeQuery(int tgt, const std::string &descr)
returns a Query for matching an atom's minimum ring size
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)
bool getNegation() const
returns whether or not we are negated
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
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
static int queryAtomMass(Atom const *at)
Queries::EqualityQuery< int, const Target *, true > * makePropQuery(const std::string &propname, const T &val, const T &tolerance=T())
pulls in the core RDKit functionality
Queries::GreaterEqualQuery< int, Atom const *, true > ATOM_GREATEREQUAL_QUERY
static int queryIsBondInRing(Bond const *bond)
ROMol is a molecule class that is intended to have a fixed topology.
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
BondDir getBondDir() const
returns our direction
double getMass() const
returns our mass
int getExplicitValence() const
returns the explicit valence (including Hs) of this atom
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
T * makeAtomExplicitDegreeQuery(int what, const std::string &descr)
returns a Query for matching explicit degree
Queries::LessEqualQuery< int, Atom const *, true > ATOM_LESSEQUAL_QUERY
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.
int queryAtomIsInRingOfSize(Atom const *at)
bool isComplexQuery(const Bond *b)
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
BOND_EQUALS_QUERY * makeBondInNRingsQuery(int tgt)
returns a Query for matching bonds in a particular number of rings
const int massIntegerConversionFactor
T * makeAtomUnsaturatedQuery(const std::string &descr)
returns a Query for matching atoms with unsaturation:
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
BOND_NULL_QUERY * makeBondNullQuery()
returns a Query for matching any bond
allows use of recursive structure queries (e.g. recursive SMARTS)
bool isAtomAromatic(const Atom *a)
RecursiveStructureQuery()
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)
Includes a bunch of functionality for handling Atom and Bond queries.
static int queryBondMinRingSize(Bond const *bond)
static int queryAtomNum(Atom const *at)
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
int getAtomicNum() const
returns our atomic number
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)
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
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
void setDataFunc(int(*what)(ConstAtomPtr))
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)
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
const int getTol() const
returns out tolerance
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)
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
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 with a particular number of ring bonds
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)
a Query implementing > using a particular value (and an optional tolerance)
BOND_EQUALS_QUERY * makeBondMinRingSizeQuery(int what)
returns a Query for matching a bond's minimum ring size
ATOM_EQUALS_QUERY * makeAtomInRingOfSizeQuery(int tgt)
returns a Query for matching atoms in rings of a particular size
static int queryAtomRingBondCount(Atom const *at)
a Query implementing >= using a particular value (and an optional tolerance)
Pulls in all the query types.
int TypeConvert(int what, Int2Type< false >) const
calls our dataFunc (if it's set) on what and returns the result, otherwise returns what ...
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
BOND_EQUALS_QUERY * makeBondDirEqualsQuery(Bond::BondDir what)
returns a Query for matching bond directions
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
unsigned int getTotalDegree() const
T * makeAtomSimpleQuery(int what, int func(Atom const *), const std::string &description="Atom Simple")
unsigned int numAtomRings(unsigned int idx) const
returns the number of rings atom idx is involved in
int queryBondIsInRingOfSize(Bond const *bond)
static int queryAtomHasRingBond(Atom const *at)
BOND_EQUALS_QUERY * makeBondInRingOfSizeQuery(int what)
returns a Query for matching bonds in rings of a particular size
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 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.
static int queryAtomHCount(Atom const *at)
Queries::RangeQuery< int, Bond const *, true > BOND_RANGE_QUERY
unsigned int queryAtomBondProduct(Atom const *at)
static int queryAtomTotalValence(Atom const *at)
unsigned int getIdx() const
returns our index within the ROMol
BOND_EQUALS_QUERY * makeBondIsInRingQuery()
returns a Query for matching ring bonds
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.
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
Queries::SetQuery< int, Atom const *, true > ATOM_SET_QUERY
static int queryIsBondInNRings(Bond const *at)