 |
RDKit
Open-source cheminformatics and machine learning.
|
Go to the documentation of this file.
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;
174 ROMol::ADJ_ITER nbrIdx, endNbrs;
176 while (nbrIdx != endNbrs) {
188 ROMol::ADJ_ITER nbrIdx, endNbrs;
190 while (nbrIdx != endNbrs) {
201 ROMol::ADJ_ITER nbrIdx, endNbrs;
203 while (nbrIdx != endNbrs) {
216 ROMol::ADJ_ITER nbrIdx, endNbrs;
218 while (nbrIdx != endNbrs) {
263 while (atomBonds.first != atomBonds.second) {
264 unsigned int bondIdx =
287 while (atomBonds.first != atomBonds.second) {
288 unsigned int bondIdx =
318 const std::string &description =
"Atom Simple") {
321 res->setDataFunc(func);
322 res->setDescription(description);
327 int lower,
int upper,
bool lowerOpen,
bool upperOpen,
328 int func(
Atom const *),
const std::string &description =
"Atom Range") {
339 return makeAtomSimpleQuery<T>(what,
queryAtomNum, descr);
641 return static_cast<int>(
656 this->setDescription(
"AtomInNRings");
662 this->setDescription(
"AtomInNRings");
669 if (this->d_val < 0) {
674 if (this->getNegation()) {
684 res->
setTol(this->getTol());
696 :
Queries::SetQuery<int,
Atom const *, true>(), d_serialNumber(0) {
697 setDataFunc(getAtIdx);
698 setDescription(
"RecursiveStructure");
707 d_serialNumber(serialNumber) {
709 setDataFunc(getAtIdx);
710 setDescription(
"RecursiveStructure");
730 res->dp_queryMol.reset(
new ROMol(*dp_queryMol,
true));
732 std::set<int>::const_iterator i;
733 for (i = d_set.begin(); i != d_set.end(); i++) {
738 res->d_serialNumber = d_serialNumber;
743 #ifdef RDK_THREADSAFE_SSS
747 boost::shared_ptr<const ROMol> dp_queryMol;
748 unsigned int d_serialNumber;
751 template <
typename T>
755 template <
typename T>
763 template <
class TargetPtr>
765 std::string propname;
780 virtual bool Match(
const TargetPtr what)
const {
781 bool res = what->hasProp(propname);
801 template <
class Target>
803 const std::string &property) {
808 template <
class TargetPtr,
class T>
811 std::string propname;
833 virtual bool Match(
const TargetPtr what)
const {
834 bool res = what->hasProp(propname);
837 T atom_val = what->template getProp<T>(propname);
841 }
catch (boost::bad_any_cast &) {
845 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
875 template <
class TargetPtr>
878 std::string propname;
889 const std::string &tol =
"")
897 virtual bool Match(
const TargetPtr what)
const {
898 bool res = what->hasProp(propname);
901 std::string atom_val = what->template getProp<std::string>(propname);
902 res = atom_val == this->val;
905 }
catch (boost::bad_any_cast &) {
909 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
940 template <
class TargetPtr>
943 std::string propname;
967 virtual bool Match(
const TargetPtr what)
const {
968 bool res = what->hasProp(propname);
972 what->template getProp<const ExplicitBitVect &>(propname);
974 res = (1.0 - tani) <= tol;
977 }
catch (boost::bad_any_cast &) {
981 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
1005 this->propname, this->val, this->tol);
1012 template <
class Target,
class T>
1014 const std::string &propname,
const T &val,
const T &tolerance = T()) {
1018 template <
class Target>
1021 float tolerance = 0.0) {
1023 propname, val, tolerance);
double TanimotoSimilarity(const SparseIntVect< IndexType > &v1, const SparseIntVect< IndexType > &v2, bool returnDistance=false, double bounds=0.0)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInRingOfSizeQuery(int what)
returns a Query for matching bonds in rings of a particular size
static int queryAtomNumHeteroatomNbrs(Atom const *at)
static int queryAtomHasImplicitH(Atom const *at)
RingInfo * getRingInfo() const
Queries::EqualityQuery< int, const Target *, true > * makePropQuery(const std::string &propname, const T &val, const T &tolerance=T())
ChiralType getChiralTag() const
returns our chiralTag
HasPropWithValueQuery(const std::string &prop, const T &v, const T &tol=0.0)
static int queryAtomRingBondCount(Atom const *at)
unsigned int numAtomRings(unsigned int idx) const
returns the number of rings atom idx is involved in
T * makeAtomHybridizationQuery(int what, const std::string &descr)
returns a Query for matching hybridization
BondStereo getStereo() const
returns our stereo code
Queries::XOrQuery< int, Atom const *, true > ATOM_XOR_QUERY
Queries::Query< bool, Atom const *, true > ATOM_BOOL_QUERY
unsigned int getIsotope() const
returns our isotope number
unsigned int getTotalDegree() const
static int queryAtomFormalCharge(Atom const *at)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeMHAtomQuery()
returns a Query for matching generic MH atoms (metals or H)
Queries::SetQuery< int, Bond const *, true > BOND_SET_QUERY
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomAllBondProduct(Atom const *at)
static int queryAtomMass(Atom const *at)
Contains general bit-comparison and similarity operations.
static int queryIsBondInRing(Bond const *bond)
static int getAtIdx(Atom const *at)
returns the index of an atom
Pulls in all the query types.
void setNegation(bool what)
sets whether or not we are negated
unsigned int getNumExplicitHs() const
returns our number of explict Hs
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
T * makeAtomMassQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular mass
static int queryAtomImplicitValence(Atom const *at)
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAAtomQuery()
returns a Query for matching generic A atoms (heavy atoms)
const ROMol * getQueryMol() const
returns a pointer to our query molecule
T * makeAtomHasHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
@ CHI_UNSPECIFIED
chirality that hasn't been specified
HasPropWithValueQuery(const std::string &prop, const ExplicitBitVect &v, float tol=0.0)
Queries::AndQuery< int, Atom const *, true > ATOM_AND_QUERY
class for representing a bond
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
T * makeAtomHCountQuery(int what, const std::string &descr)
returns a Query for matching hydrogen count
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomBondProduct(Atom const *at)
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
static int queryAtomHasRingBond(Atom const *at)
HasPropQuery(const std::string &v)
T * makeAtomUnsaturatedQuery(const std::string &descr)
returns a Query for matching atoms with unsaturation:
int getAtomicNum() const
returns our atomic number
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondHasStereoQuery()
returns a Query for matching bonds with stereo set
static int queryBondMinRingSize(Bond const *bond)
static int queryAtomNonHydrogenDegree(Atom const *at)
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomInRingOfSizeQuery(int tgt)
returns a Query for matching atoms in rings of a particular size
unsigned int getIdx() const
returns our index within the ROMol
Class to allow us to throw a KeyError from C++ and have it make it back to Python.
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
const Bond * ConstBondPtr
static int queryAtomAliphatic(Atom const *at)
T * makeAtomInNRingsQuery(int what, const std::string &descr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
int getExplicitValence() const
returns the explicit valence (including Hs) of this atom
int getImplicitValence() const
returns the implicit valence for this Atom
#define RDUNUSED_PARAM(x)
static int queryAtomIsotope(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrAromaticBondQuery()
returns a Query for unspecified SMARTS bonds
void insert(const MatchFuncArgType what)
insert an entry into our set
static int queryAtomMinRingSize(Atom const *at)
T * makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of heteroatom neighbors
T * makeAtomExplicitDegreeQuery(int what, const std::string &descr)
returns a Query for matching explicit degree
Queries::Query< int, Atom const *, true > * copy() const
returns a copy of this query
Queries::RangeQuery< int, Atom const *, true > ATOM_RANGE_QUERY
The class for representing atoms.
static int queryAtomAromatic(Atom const *at)
T * makeAtomImplicitHCountQuery(int what, const std::string &descr)
returns a Query for matching implicit hydrogen count
RDKIT_GRAPHMOL_EXPORT bool isComplexQuery(const Bond *b)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXAtomQuery()
returns a Query for matching generic X atoms (halogens)
static void parseAtomType(int val, int &atomic_num, bool &aromatic)
T * makeAtomIsotopeQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular isotope
RDKIT_GRAPHMOL_EXPORT BOND_NULL_QUERY * makeBondNullQuery()
returns a Query for matching any bond
static int queryAtomType(Atom const *at)
static int queryAtomHasHeteroatomNbrs(Atom const *at)
static int queryAtomNum(Atom const *at)
unsigned int getIdx() const
returns our index within the ROMol
allows use of recursive structure queries (e.g. recursive SMARTS)
a Query implementing a range: arguments must fall in a particular range of values.
T * makeAtomMissingChiralTagQuery(const std::string &descr)
a Query implementing AND: requires any child to be true
static int queryBondOrder(Bond const *bond)
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeQHAtomQuery()
returns a Query for matching generic QH atoms (heteroatom or H)
T * makeAtomExplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching explicit valence
unsigned int getDegree() const
void setEndsOpen(bool lower, bool upper)
sets whether or not the ends of the range are open
int queryAtomIsInRingOfSize(Atom const *at)
pulls in the core RDKit functionality
static int queryBondIsSingleOrAromatic(Bond const *bond)
static int getAtomTypeAtomicNum(int val)
HasPropWithValueQuery(const std::string &prop, const std::string &v, const std::string &tol="")
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
T * makeAtomRingBondCountQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular number of ring bonds
static int queryAtomTotalDegree(Atom const *at)
#define RDKIT_GRAPHMOL_EXPORT
static int queryIsAtomInRing(Atom const *at)
a Query implementing XOR: requires exactly one child to be true
Queries::SetQuery< int, Atom const *, true > ATOM_SET_QUERY
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondOrderEqualsQuery(Bond::BondType what)
returns a Query for matching bond orders
Queries::AndQuery< int, Bond const *, true > BOND_AND_QUERY
Queries::LessEqualQuery< int, Bond const *, true > BOND_LESSEQUAL_QUERY
static int queryIsAtomInNRings(Atom const *at)
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
RDKIT_GRAPHMOL_EXPORT ATOM_NULL_QUERY * makeAtomNullQuery()
returns a Query for matching any atom
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
const RDKIT_RDGENERAL_EXPORT std::string _ChiralityPossible
T * makeAtomMinRingSizeQuery(int tgt, const std::string &descr)
returns a Query for matching an atom's minimum ring size
static int queryAtomRingMembership(Atom const *at)
T * makeAtomAliphaticQuery(const std::string &descr)
returns a Query for matching aliphatic atoms
const Atom * ConstAtomPtr
T * makeAtomImplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching implicit valence
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInNRingsQuery(int tgt)
returns a Query for matching bonds in a particular number of rings
std::string d_description
RDKIT_RDGENERAL_EXPORT double round(double v)
rounds a value to the closest int
unsigned int getTotalNumHs(bool includeNeighbors=false) const
returns the total number of Hs (implicit and explicit) that this Atom is bound to
virtual bool Match(const TargetPtr what) const
returns whether or not we match the argument
ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const
provides access to all neighbors around an Atom
static int queryAtomHybridization(Atom const *at)
unsigned int getSerialNumber() const
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
static int queryAtomNumAliphaticHeteroatomNbrs(Atom const *at)
Queries::EqualityQuery< int, const Target *, true > * makeHasPropQuery(const std::string &property)
returns a Query for matching atoms that have a particular property
T * makeAtomAromaticQuery(const std::string &descr)
returns a Query for matching the isAromatic flag
T * makeAtomInRingQuery(const std::string &descr)
returns a Query for matching ring atoms
BondDir getBondDir() const
returns our direction
int getFormalCharge() const
returns the formal charge of this atom
static int queryAtomTotalValence(Atom const *at)
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
T * makeAtomNegativeFormalChargeQuery(int what, const std::string &descr)
T * makeAtomHasImplicitHQuery(const std::string &descr)
returns a Query for matching ring atoms
static int queryBondDir(Bond const *bond)
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
T * makeAtomNumRadicalElectronsQuery(int what, const std::string &descr)
returns a Query for matching the number of radical electrons
T * makeAtomTypeQuery(int num, int aromatic, const std::string &descr)
returns a Query for matching atomic number and aromaticity
T * makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr)
returns a Query for matching heavy atom degree
RecursiveStructureQuery()
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXHAtomQuery()
returns a Query for matching generic XH atoms (halogen or H)
bool getNegation() const
returns whether or not we are negated
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
HybridizationType getHybridization() const
returns our hybridization
class to allow integer values to pick templates
Queries::GreaterEqualQuery< int, Atom const *, true > ATOM_GREATEREQUAL_QUERY
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
double getMass() const
returns our mass
T * makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of aliphatic heteroatom neighbors
T * makeAtomHasRingBondQuery(const std::string &descr)
returns a Query for matching atoms that have ring bonds
a Query implementing AND: requires all children to be true
T * makeAtomSimpleQuery(int what, int func(Atom const *), const std::string &description="Atom Simple")
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Queries::EqualityQuery< int, Bond const *, true > BOND_PROP_QUERY
a Query implementing < using a particular value (and an optional tolerance)
T * makeAtomHasChiralTagQuery(const std::string &descr)
int queryBondIsInRingOfSize(Bond const *bond)
static int makeAtomType(int atomic_num, bool aromatic)
Queries::LessEqualQuery< int, Atom const *, true > ATOM_LESSEQUAL_QUERY
RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber=0)
initialize from an ROMol pointer
RDKIT_GRAPHMOL_EXPORT bool isAtomAromatic(const Atom *a)
Queries::EqualityQuery< int, Atom const *, true > ATOM_PROP_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::EqualityQuery< int, Atom const *, true > ATOM_EQUALS_QUERY
a Query implementing > using a particular value (and an optional tolerance)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeQAtomQuery()
returns a Query for matching generic Q atoms (heteroatoms)
static int queryAtomHCount(Atom const *at)
static int queryBondHasStereo(Bond const *bnd)
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
Queries::LessQuery< int, Atom const *, true > ATOM_LESS_QUERY
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
void setTol(MatchFuncArgType what)
sets our tolerance
static int queryAtomUnsaturated(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondDirEqualsQuery(Bond::BondDir what)
returns a Query for matching bond directions
virtual bool Match(const ConstAtomPtr what) const
#define PRECONDITION(expr, mess)
static int queryAtomImplicitHCount(Atom const *at)
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
static ATOM_RANGE_QUERY * makeAtomRangeQuery(int lower, int upper, bool lowerOpen, bool upperOpen, int func(Atom const *), const std::string &description="Atom Range")
T * makeAtomFormalChargeQuery(int what, const std::string &descr)
returns a Query for matching formal charge
Pulls in all the BitVect classes.
Base class for all queries.
BondType getBondType() const
returns our bondType
T * makeAtomTotalValenceQuery(int what, const std::string &descr)
returns a Query for matching total valence
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAHAtomQuery()
returns a Query for matching generic AH atoms (any atom)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondMinRingSizeQuery(int what)
returns a Query for matching a bond's minimum ring size
static int queryAtomMissingChiralTag(Atom const *at)
bool getIsAromatic() const
returns our isAromatic flag
Queries::Query< int, ConstAtomPtr, true > * copy() const
returns a copy of this query
static bool getAtomTypeIsAromatic(int val)
Queries::Query< int, Bond const *, true > BOND_NULL_QUERY
static int queryAtomNegativeFormalCharge(Atom const *at)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeMAtomQuery()
returns a Query for matching generic M atoms (metals)
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
bool hasProp(const std::string &key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Queries::Query< int, Atom const *, true > ATOM_NULL_QUERY
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
static int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at)
static int queryAtomHeavyAtomDegree(Atom const *at)
static int queryAtomHasChiralTag(Atom const *at)
Queries::LessQuery< int, Bond const *, true > BOND_LESS_QUERY
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
Queries::GreaterQuery< int, Bond const *, true > BOND_GREATER_QUERY
const MolGraph & getTopology() const
brief returns a pointer to our underlying BGL object
T * makeAtomHasAliphaticHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
T * makeAtomTotalDegreeQuery(int what, const std::string &descr)
returns a Query for matching atomic degree
a Query implementing ==: arguments must match a particular value (within an optional tolerance)
const int massIntegerConversionFactor
void setDescription(const std::string &descr)
sets our text description
static int queryIsBondInNRings(Bond const *at)
static int queryAtomExplicitValence(Atom const *at)
Queries::Query< bool, Bond const *, true > BOND_BOOL_QUERY
static int queryAtomNumRadicalElectrons(Atom const *at)
a Query implementing >= using a particular value (and an optional tolerance)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondIsInRingQuery()
returns a Query for matching ring bonds
static int queryAtomExplicitDegree(Atom const *at)
BondDir
the bond's direction (for chirality)
a Query implementing <= using a particular value (and an optional tolerance)
Queries::RangeQuery< int, Bond const *, true > BOND_RANGE_QUERY
unsigned int minAtomRingSize(unsigned int idx) const
returns the size of the smallest ring atom idx is involved in
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
Queries::OrQuery< int, Bond const *, true > BOND_OR_QUERY
a class for bit vectors that are densely occupied