15 #ifndef _RD_QUERY_OPS_H 16 #define _RD_QUERY_OPS_H 22 #ifdef RDK_THREADSAFE_SSS 24 #include <boost/thread/mutex.hpp> 109 return static_cast<int>(
round(massIntegerConversionFactor * at->
getMass()));
161 while (atomBonds.first != atomBonds.second) {
162 unsigned int bondIdx =
185 while (atomBonds.first != atomBonds.second) {
186 unsigned int bondIdx =
216 const std::string &description =
"Atom Simple") {
219 res->setDataFunc(func);
220 res->setDescription(description);
227 return makeAtomSimpleQuery<T>(what,
queryAtomNum, descr);
323 return makeAtomSimpleQuery<T>(massIntegerConversionFactor * what,
468 return static_cast<int>(
492 virtual bool Match(
const ConstAtomPtr what)
const {
495 if (this->
d_val < 0) {
522 :
Queries::SetQuery<int,
Atom const *, true>(), d_serialNumber(0) {
533 d_serialNumber(serialNumber) {
556 res->dp_queryMol.reset(
new ROMol(*dp_queryMol,
true));
558 std::set<int>::const_iterator i;
559 for (i = d_set.begin(); i != d_set.end(); i++) {
564 res->d_serialNumber = d_serialNumber;
569 #ifdef RDK_THREADSAFE_SSS 570 boost::mutex d_mutex;
573 boost::shared_ptr<const ROMol> dp_queryMol;
574 unsigned int d_serialNumber;
577 template <
typename T>
581 template <
typename T>
589 template <
class TargetPtr>
591 std::string propname;
606 virtual bool Match(
const TargetPtr what)
const {
607 bool res = what->hasProp(propname);
627 template <
class Target>
629 const std::string &property) {
634 template <
class TargetPtr,
class T>
637 std::string propname;
659 virtual bool Match(
const TargetPtr what)
const {
660 bool res = what->hasProp(propname);
663 T atom_val = what->template getProp<T>(propname);
667 }
catch (boost::bad_any_cast) {
671 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 701 template <
class TargetPtr>
704 std::string propname;
715 const std::string &tol =
"")
723 virtual bool Match(
const TargetPtr what)
const {
724 bool res = what->hasProp(propname);
727 std::string atom_val = what->template getProp<std::string>(propname);
728 res = atom_val == this->val;
731 }
catch (boost::bad_any_cast) {
735 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 766 template <
class Target,
class T>
768 const std::string &propname,
const T &val,
const T &tolerance = T()) {
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this Atom
HasPropQuery(const std::string &v)
bool getNegation() const
returns whether or not we are negated
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
ATOM_OR_QUERY * makeMHAtomQuery()
returns a Query for matching generic MH atoms (metals or H)
static int queryAtomTotalDegree(Atom const *at)
ATOM_EQUALS_QUERY * makeQHAtomQuery()
returns a Query for matching generic QH atoms (heteroatom or H)
static int queryAtomMissingChiralTag(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
Queries::OrQuery< int, Bond const *, true > BOND_OR_QUERY
double round(double v)
rounds a value to the closest int
Queries::LessQuery< int, Atom const *, true > ATOM_LESS_QUERY
bool isBondInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the bond with index idx is in a size - ring.
Queries::Query< int, ConstAtomPtr, true > * copy() const
returns a copy of this query
void setNegation(bool what)
sets whether or not we are negated
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Queries::Query< int, Atom const *, true > ATOM_NULL_QUERY
ATOM_NULL_QUERY * makeAtomNullQuery()
returns a Query for matching any atom
ROMol const * getQueryMol() const
returns a pointer to our query molecule
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
unsigned int getTotalNumHs(bool includeNeighbors=false) const
returns the total number of Hs (implicit and explicit) that this Atom is bound to ...
Queries::EqualityQuery< int, Bond const *, true > BOND_PROP_QUERY
a Query implementing AND: requires any child to be true
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
unsigned int getIsotope() const
returns our isotope number
BondDir getBondDir() const
returns our direction
double getMass() const
returns our mass
unsigned int queryAtomAllBondProduct(Atom const *at)
BondStereo getStereo() const
returns our stereo code
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)
Queries::GreaterQuery< int, Bond const *, true > BOND_GREATER_QUERY
static int queryBondOrder(Bond const *bond)
int TypeConvert(intwhat, Int2Type< false >) const
calls our dataFunc (if it's set) on what and returns the result, otherwise returns what ...
static int queryAtomImplicitHCount(Atom const *at)
unsigned int getIdx() const
returns our index within the ROMol
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())
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
T * makeAtomHasChiralTagQuery(const std::string &descr)
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)
ROMol is a molecule class that is intended to have a fixed topology.
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
unsigned int minAtomRingSize(unsigned int idx) const
returns the size of the smallest ring atom idx is involved in
virtual bool Match(const ConstAtomPtr what) const
unsigned int getDegree() const
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 queryAtomHasChiralTag(Atom const *at)
static int queryBondDir(Bond const *bond)
ATOM_OR_QUERY * makeXHAtomQuery()
returns a Query for matching generic XH atoms (halogen or H)
static int queryAtomUnsaturated(Atom const *at)
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
Queries::LessEqualQuery< int, Bond const *, true > BOND_LESSEQUAL_QUERY
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
a Query implementing a range: arguments must fall in a particular range of values.
unsigned int getTotalDegree() const
int queryAtomIsInRingOfSize(Atom const *at)
ATOM_OR_QUERY * makeMAtomQuery()
returns a Query for matching generic M atoms (metals)
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
int getAtomicNum() const
returns our atomic number
T * makeAtomUnsaturatedQuery(const std::string &descr)
returns a Query for matching atoms with unsaturation:
unsigned int numAtomRings(unsigned int idx) const
returns the number of rings atom idx is involved in
T * makeAtomMissingChiralTagQuery(const std::string &descr)
class to allow integer values to pick templates
static int queryAtomIsotope(Atom const *at)
int getExplicitValence() const
returns the explicit valence (including Hs) of this atom
Queries::LessQuery< int, Bond const *, true > BOND_LESS_QUERY
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
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)
a Query implementing <= using a particular value (and an optional tolerance)
Queries::Query< bool, Atom const *, true > ATOM_BOOL_QUERY
HasPropWithValueQuery(const std::string &prop, const std::string &v, const std::string &tol="")
static int queryAtomAromatic(Atom const *at)
unsigned int getNumExplicitHs() const
returns our number of explict Hs
static int queryBondMinRingSize(Bond const *bond)
static int queryAtomNum(Atom const *at)
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
ATOM_EQUALS_QUERY * makeAHAtomQuery()
returns a Query for matching generic AH atoms (any atom)
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
ATOM_OR_QUERY * makeXAtomQuery()
returns a Query for matching generic X atoms (halogens)
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)
ChiralType getChiralTag() const
returns our chiralTag
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
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
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
int getImplicitValence() const
returns the implicit valence for this Atom
RingInfo * getRingInfo() const
void insert(const MatchFuncArgType what)
insert an entry into our set
void setDataFunc(int(*what)(ConstAtomPtr))
sets our data function
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
Queries::AndQuery< int, Bond const *, true > BOND_AND_QUERY
BondDir
the bond's direction (for chirality)
static int queryIsAtomInNRings(Atom const *at)
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
BOND_EQUALS_QUERY * makeBondHasStereoQuery()
returns a Query for matching bonds with stereo set
unsigned int getSerialNumber() const
RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber=0)
initialize from an ROMol pointer
static int queryAtomHasImplicitH(Atom const *at)
#define PRECONDITION(expr, mess)
static int queryAtomMinRingSize(Atom const *at)
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
HybridizationType getHybridization() const
returns our hybridization
Queries::AndQuery< int, Atom const *, true > ATOM_AND_QUERY
static int queryAtomNumRadicalElectrons(Atom const *at)
T * makeAtomHasRingBondQuery(const std::string &descr)
returns a Query for matching atoms that have ring bonds
Queries::EqualityQuery< int, Atom const *, true > ATOM_EQUALS_QUERY
std::string d_description
T * makeAtomHasImplicitHQuery(const std::string &descr)
returns a Query for matching ring atoms
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
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)
bool hasProp(const std::string &key) const
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
const std::string _ChiralityPossible
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
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
chirality that hasn't been specified
BOND_EQUALS_QUERY * makeBondDirEqualsQuery(Bond::BondDir what)
returns a Query for matching bond directions
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
T * makeAtomSimpleQuery(int what, int func(Atom const *), const std::string &description="Atom Simple")
int getFormalCharge() const
returns the formal charge of this atom
int queryBondIsInRingOfSize(Bond const *bond)
unsigned int getIdx() const
returns our index within the ROMol
static int queryAtomHasRingBond(Atom const *at)
BOND_EQUALS_QUERY * makeBondInRingOfSizeQuery(int what)
returns a Query for matching bonds in rings of a particular size
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this Bond
static int queryAtomRingMembership(Atom const *at)
Queries::EqualityQuery< int, Atom const *, true > ATOM_PROP_QUERY
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)
BOND_EQUALS_QUERY * makeBondIsInRingQuery()
returns a Query for matching ring bonds
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
The class for representing atoms.
BondType getBondType() const
returns our bondType
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
bool getIsAromatic() const
returns our isAromatic flag
ATOM_EQUALS_QUERY * makeAAtomQuery()
returns a Query for matching generic A atoms (heavy atoms)
static int queryAtomImplicitValence(Atom const *at)
Class to allow us to throw a KeyError from C++ and have it make it back to Python.
Queries::Query< int, Atom const *, true > * copy() const
returns a copy of this query
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
ATOM_OR_QUERY * makeQAtomQuery()
returns a Query for matching generic Q atoms (heteroatoms)
const int getTol() const
returns out tolerance
static int queryIsBondInNRings(Bond const *at)