 |
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;
148 return static_cast<int>(
175 ROMol::ADJ_ITER nbrIdx, endNbrs;
177 while (nbrIdx != endNbrs) {
189 ROMol::ADJ_ITER nbrIdx, endNbrs;
191 while (nbrIdx != endNbrs) {
202 ROMol::ADJ_ITER nbrIdx, endNbrs;
204 while (nbrIdx != endNbrs) {
217 ROMol::ADJ_ITER nbrIdx, endNbrs;
219 while (nbrIdx != endNbrs) {
264 while (atomBonds.first != atomBonds.second) {
265 unsigned int bondIdx =
288 while (atomBonds.first != atomBonds.second) {
289 unsigned int bondIdx =
319 const std::string &description =
"Atom Simple") {
322 res->setDataFunc(func);
323 res->setDescription(description);
328 int lower,
int upper,
bool lowerOpen,
bool upperOpen,
329 int func(
Atom const *),
const std::string &description =
"Atom Range") {
340 return makeAtomSimpleQuery<T>(what,
queryAtomNum, descr);
642 return static_cast<int>(
657 this->setDescription(
"AtomInNRings");
663 this->setDescription(
"AtomInNRings");
670 if (this->d_val < 0) {
675 if (this->getNegation()) {
685 res->
setTol(this->getTol());
697 :
Queries::SetQuery<int,
Atom const *, true>(), d_serialNumber(0) {
698 setDataFunc(getAtIdx);
699 setDescription(
"RecursiveStructure");
708 d_serialNumber(serialNumber) {
710 setDataFunc(getAtIdx);
711 setDescription(
"RecursiveStructure");
731 res->dp_queryMol.reset(
new ROMol(*dp_queryMol,
true));
733 std::set<int>::const_iterator i;
734 for (i = d_set.begin(); i != d_set.end(); i++) {
739 res->d_serialNumber = d_serialNumber;
744 #ifdef RDK_THREADSAFE_SSS
748 boost::shared_ptr<const ROMol> dp_queryMol;
749 unsigned int d_serialNumber;
752 template <
typename T>
756 template <
typename T>
764 template <
class TargetPtr>
766 std::string propname;
781 virtual bool Match(
const TargetPtr what)
const {
782 bool res = what->hasProp(propname);
802 template <
class Target>
804 const std::string &property) {
809 template <
class TargetPtr,
class T>
812 std::string propname;
834 virtual bool Match(
const TargetPtr what)
const {
835 bool res = what->hasProp(propname);
838 T atom_val = what->template getProp<T>(propname);
842 }
catch (boost::bad_any_cast &) {
846 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
876 template <
class TargetPtr>
879 std::string propname;
890 const std::string &tol =
"")
898 virtual bool Match(
const TargetPtr what)
const {
899 bool res = what->hasProp(propname);
902 std::string atom_val = what->template getProp<std::string>(propname);
903 res = atom_val == this->val;
906 }
catch (boost::bad_any_cast &) {
910 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
941 template <
class TargetPtr>
944 std::string propname;
968 virtual bool Match(
const TargetPtr what)
const {
969 bool res = what->hasProp(propname);
973 what->template getProp<const ExplicitBitVect &>(propname);
975 res = (1.0 - tani) <= tol;
978 }
catch (boost::bad_any_cast &) {
982 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
1006 this->propname, this->val, this->tol);
1013 template <
class Target,
class T>
1015 const std::string &propname,
const T &val,
const T &tolerance = T()) {
1019 template <
class Target>
1022 float tolerance = 0.0) {
1024 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 explicit 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)
Atom const * ConstAtomPtr
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)
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
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
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
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
Bond const * ConstBondPtr
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
ROMol const * getQueryMol() const
returns a pointer to our query molecule
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.
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
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
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
RDKIT_RDGENERAL_EXPORT const std::string _ChiralityPossible
a class for bit vectors that are densely occupied