16 #ifndef RD_QUERY_OPS_H
17 #define RD_QUERY_OPS_H
25 #ifdef RDK_THREADSAFE_SSS
86 for (
const auto &nbri :
89 if (nbr->getAtomicNum() != 1 || nbr->getIsotope() > 1) {
99 for (
const auto &nbri :
102 if (nbr->getAtomicNum() > 1) {
132 return atomic_num + 1000 *
static_cast<int>(aromatic);
134 static inline void parseAtomType(
int val,
int &atomic_num,
bool &aromatic) {
137 atomic_num = val - 1000;
144 if (val > 1000)
return true;
148 if (val > 1000)
return val - 1000;
157 return static_cast<int>(
184 ROMol::ADJ_ITER nbrIdx, endNbrs;
186 while (nbrIdx != endNbrs) {
198 ROMol::ADJ_ITER nbrIdx, endNbrs;
200 while (nbrIdx != endNbrs) {
211 ROMol::ADJ_ITER nbrIdx, endNbrs;
213 while (nbrIdx != endNbrs) {
226 ROMol::ADJ_ITER nbrIdx, endNbrs;
228 while (nbrIdx != endNbrs) {
278 while (atomBonds.first != atomBonds.second) {
279 unsigned int bondIdx =
302 while (atomBonds.first != atomBonds.second) {
303 unsigned int bondIdx =
333 const std::string &description =
"Atom Simple") {
336 res->setDataFunc(func);
337 res->setDescription(description);
342 int lower,
int upper,
bool lowerOpen,
bool upperOpen,
343 int func(
Atom const *),
const std::string &description =
"Atom Range") {
354 return makeAtomSimpleQuery<T>(what,
queryAtomNum, descr);
668 return static_cast<int>(
683 this->setDescription(
"AtomInNRings");
689 this->setDescription(
"AtomInNRings");
696 if (this->d_val < 0) {
701 if (this->getNegation()) {
711 res->
setTol(this->getTol());
723 setDataFunc(getAtIdx);
724 setDescription(
"RecursiveStructure");
733 d_serialNumber(serialNumber) {
735 setDataFunc(getAtIdx);
736 setDescription(
"RecursiveStructure");
756 res->dp_queryMol.reset(
new ROMol(*dp_queryMol,
true));
758 std::set<int>::const_iterator i;
759 for (i = d_set.begin(); i != d_set.end(); i++) {
764 res->d_serialNumber = d_serialNumber;
769 #ifdef RDK_THREADSAFE_SSS
773 boost::shared_ptr<const ROMol> dp_queryMol;
774 unsigned int d_serialNumber{0};
777 template <
typename T>
781 template <
typename T>
789 template <
class TargetPtr>
791 std::string propname;
806 virtual bool Match(
const TargetPtr what)
const {
807 bool res = what->hasProp(propname);
827 template <
class Target>
829 const std::string &property) {
834 template <
class TargetPtr,
class T>
837 std::string propname;
859 virtual bool Match(
const TargetPtr what)
const {
860 bool res = what->hasProp(propname);
863 T atom_val = what->template getProp<T>(propname);
867 }
catch (boost::bad_any_cast &) {
871 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
901 template <
class TargetPtr>
904 std::string propname;
915 const std::string &tol =
"")
923 virtual bool Match(
const TargetPtr what)
const {
924 bool res = what->hasProp(propname);
927 std::string atom_val = what->template getProp<std::string>(propname);
928 res = atom_val == this->val;
931 }
catch (boost::bad_any_cast &) {
935 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
966 template <
class TargetPtr>
969 std::string propname;
990 virtual bool Match(
const TargetPtr what)
const {
991 bool res = what->hasProp(propname);
995 what->template getProp<const ExplicitBitVect &>(propname);
997 res = (1.0 - tani) <= tol;
1000 }
catch (boost::bad_any_cast &) {
1004 #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
1028 this->propname, this->val, this->tol);
1035 template <
class Target,
class T>
1037 const std::string &propname,
const T &val,
const T &tolerance = T()) {
1041 template <
class Target>
1044 float tolerance = 0.0) {
1046 propname, val, tolerance);
1053 namespace QueryOps {
1055 RWMol *mol,
unsigned int magicVal = 0xDEADBEEF);
Contains general bit-comparison and similarity operations.
Pulls in all the BitVect classes.
#define RDUNUSED_PARAM(x)
#define PRECONDITION(expr, mess)
Pulls in all the query types.
pulls in the core RDKit functionality
a class for bit vectors that are densely occupied
Class to allow us to throw a KeyError from C++ and have it make it back to Python.
a Query implementing AND: requires all children to be true
a Query implementing ==: arguments must match a particular value (within an optional tolerance)
void setTol(MatchFuncArgType what)
sets our tolerance
a Query implementing >= using a particular value (and an optional tolerance)
a Query implementing > using a particular value (and an optional tolerance)
class to allow integer values to pick templates
a Query implementing <= using a particular value (and an optional tolerance)
a Query implementing < using a particular value (and an optional tolerance)
a Query implementing AND: requires any child to be true
Base class for all queries.
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
bool getNegation() const
returns whether or not we are negated
void setNegation(bool what)
sets whether or not we are negated
void setDescription(const std::string &descr)
sets our text description
std::string d_description
a Query implementing a range: arguments must fall in a particular range of values.
void setEndsOpen(bool lower, bool upper)
sets whether or not the ends of the range are open
void insert(const MatchFuncArgType what)
insert an entry into our set
a Query implementing XOR: requires exactly one child to be true
Queries::Query< int, ConstAtomPtr, true > * copy() const
returns a copy of this query
virtual bool Match(const ConstAtomPtr what) const
The class for representing atoms.
ChiralType getChiralTag() const
returns our chiralTag
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
unsigned int getIdx() const
returns our index within the ROMol
unsigned int getNumExplicitHs() const
returns our number of explicit Hs
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
int getExplicitValence() const
returns the explicit valence (including Hs) of this atom
int getImplicitValence() const
returns the implicit valence for this Atom
unsigned int getTotalNumHs(bool includeNeighbors=false) const
returns the total number of Hs (implicit and explicit) that this Atom is bound to
int getAtomicNum() const
returns our atomic number
@ CHI_UNSPECIFIED
chirality that hasn't been specified
HybridizationType getHybridization() const
returns our hybridization
bool getIsAromatic() const
returns our isAromatic flag
unsigned int getTotalValence() const
returns the total valence (implicit and explicit) for an atom
int getFormalCharge() const
returns the formal charge of this atom
double getMass() const
returns our mass
unsigned int getIsotope() const
returns our isotope number
unsigned int getTotalDegree() const
unsigned int getDegree() const
class for representing a bond
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
unsigned int getIdx() const
returns our index within the ROMol
BondType getBondType() const
returns our bondType
BondDir
the bond's direction (for chirality)
BondStereo getStereo() const
returns our stereo code
BondDir getBondDir() const
returns our direction
HasPropQuery(const std::string &v)
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
virtual bool Match(const TargetPtr what) const
virtual bool Match(const TargetPtr what) const
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
HasPropWithValueQuery(const std::string &prop, const ExplicitBitVect &v, float tol=0.0)
HasPropWithValueQuery(const std::string &prop, const std::string &v, const std::string &tol="")
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
virtual bool Match(const TargetPtr what) const
virtual bool Match(const TargetPtr what) const
Queries::Query< int, TargetPtr, true > * copy() const
returns a copy of this query
HasPropWithValueQuery(const std::string &prop, const T &v, const T &tol=0.0)
bool hasProp(const std::string &key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
ADJ_ITER_PAIR getAtomNeighbors(Atom const *at) const
provides access to all neighbors around an Atom
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
RingInfo * getRingInfo() const
MolGraph const & getTopology() const
brief returns a pointer to our underlying BGL object
RWMol is a molecule class that is intended to be edited.
allows use of recursive structure queries (e.g. recursive SMARTS)
ROMol const * getQueryMol() const
returns a pointer to our query molecule
RecursiveStructureQuery(ROMol const *query, unsigned int serialNumber=0)
initialize from an ROMol pointer
RecursiveStructureQuery()
unsigned int getSerialNumber() const
Queries::Query< int, Atom const *, true > * copy() const
returns a copy of this query
static int getAtIdx(Atom const *at)
returns the index of an atom
void setQueryMol(ROMol const *query)
sets the molecule we'll use recursively
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
unsigned int numAtomRings(unsigned int idx) const
returns the number of rings atom idx is involved in
bool isBondInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the bond with index idx is in a size - ring.
unsigned int minAtomRingSize(unsigned int idx) const
returns the size of the smallest ring atom idx is involved in
#define RDKIT_GRAPHMOL_EXPORT
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
RDKIT_GRAPHMOL_EXPORT void completeMolQueries(RWMol *mol, unsigned int magicVal=0xDEADBEEF)
RDKIT_GRAPHMOL_EXPORT Atom * replaceAtomWithQueryAtom(RWMol *mol, Atom *atom)
RDKIT_RDGENERAL_EXPORT const std::string _ChiralityPossible
Queries::LessQuery< int, Bond const *, true > BOND_LESS_QUERY
T * makeAtomUnsaturatedQuery(const std::string &descr)
returns a Query for matching atoms with unsaturation:
static int queryAtomNumRadicalElectrons(Atom const *at)
Queries::LessQuery< int, Atom const *, true > ATOM_LESS_QUERY
static int queryAtomHybridization(Atom const *at)
static int queryAtomMinRingSize(Atom const *at)
Queries::LessEqualQuery< int, Bond const *, true > BOND_LESSEQUAL_QUERY
static int queryAtomExplicitDegree(Atom const *at)
static int queryAtomHasRingBond(Atom const *at)
Bond const * ConstBondPtr
T * makeAtomImplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching implicit valence
T * makeAtomExplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching explicit valence
T * makeAtomMassQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular mass
static int queryBondHasStereo(Bond const *bnd)
T * makeAtomHybridizationQuery(int what, const std::string &descr)
returns a Query for matching hybridization
static int queryAtomUnsaturated(Atom const *at)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeQAtomQuery()
returns a Query for matching generic Q atoms (heteroatoms)
RDKIT_GRAPHMOL_EXPORT ATOM_NULL_QUERY * makeAHAtomQuery()
returns a Query for matching generic AH atoms (any atom)
static int queryAtomAromatic(Atom const *at)
Queries::RangeQuery< int, Atom const *, true > ATOM_RANGE_QUERY
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondIsInRingQuery()
returns a Query for matching ring bonds
T * makeAtomHasHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
Queries::Query< bool, Bond const *, true > BOND_BOOL_QUERY
static int queryAtomType(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrDoubleOrAromaticBondQuery()
returns a Query for tautomeric bonds
Queries::AndQuery< int, Atom const *, true > ATOM_AND_QUERY
T * makeAtomAliphaticQuery(const std::string &descr)
returns a Query for matching aliphatic atoms
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomBondProduct(Atom const *at)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeMHAtomQuery()
returns a Query for matching generic MH atoms (metals or H)
static int queryAtomHasImplicitH(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondDirEqualsQuery(Bond::BondDir what)
returns a Query for matching bond directions
Queries::LessEqualQuery< int, Atom const *, true > ATOM_LESSEQUAL_QUERY
T * makeAtomTypeQuery(int num, int aromatic, const std::string &descr)
returns a Query for matching atomic number and aromaticity
T * makeAtomMinRingSizeQuery(int tgt, const std::string &descr)
returns a Query for matching an atom's minimum ring size
T * makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of heteroatom neighbors
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomAllBondProduct(Atom const *at)
double TanimotoSimilarity(const SparseIntVect< IndexType > &v1, const SparseIntVect< IndexType > &v2, bool returnDistance=false, double bounds=0.0)
static int queryAtomNegativeFormalCharge(Atom const *at)
Queries::SetQuery< int, Atom const *, true > ATOM_SET_QUERY
static int queryAtomHasHeteroatomNbrs(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInRingOfSizeQuery(int what)
returns a Query for matching bonds in rings of a particular size
T * makeAtomFormalChargeQuery(int what, const std::string &descr)
returns a Query for matching formal charge
RDKIT_GRAPHMOL_EXPORT ATOM_NULL_QUERY * makeAtomNullQuery()
returns a Query for matching any atom
T * makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of aliphatic heteroatom neighbors
T * makeAtomHasChiralTagQuery(const std::string &descr)
RDKIT_GRAPHMOL_EXPORT bool isAtomAromatic(const Atom *a)
Queries::XOrQuery< int, Atom const *, true > ATOM_XOR_QUERY
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeMAtomQuery()
returns a Query for matching generic M atoms (metals)
Queries::SetQuery< int, Bond const *, true > BOND_SET_QUERY
static int queryBondIsSingleOrAromatic(Bond const *bond)
T * makeAtomHasAliphaticHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
Queries::OrQuery< int, Bond const *, true > BOND_OR_QUERY
T * makeAtomNonHydrogenDegreeQuery(int what, const std::string &descr)
returns a Query for matching the number of non-hydrogen neighbors
T * makeAtomHCountQuery(int what, const std::string &descr)
returns a Query for matching hydrogen count
static int queryBondMinRingSize(Bond const *bond)
T * makeAtomNegativeFormalChargeQuery(int what, const std::string &descr)
const int massIntegerConversionFactor
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXHAtomQuery()
returns a Query for matching generic XH atoms (halogen or H)
static int queryAtomTotalValence(Atom const *at)
static int queryAtomNonHydrogenDegree(Atom const *at)
D and T are treated as "non-hydrogen" here.
static int makeAtomType(int atomic_num, bool aromatic)
Queries::EqualityQuery< int, const Target *, true > * makePropQuery(const std::string &propname, const T &val, const T &tolerance=T())
T * makeAtomSimpleQuery(int what, int func(Atom const *), const std::string &description="Atom Simple")
T * makeAtomInNRingsQuery(int what, const std::string &descr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static int queryAtomHeavyAtomDegree(Atom const *at)
D and T are not treated as heavy atoms here.
static int queryAtomRingBondCount(Atom const *at)
static ATOM_RANGE_QUERY * makeAtomRangeQuery(int lower, int upper, bool lowerOpen, bool upperOpen, int func(Atom const *), const std::string &description="Atom Range")
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
T * makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr)
returns a Query for matching heavy atom degree
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXAtomQuery()
returns a Query for matching generic X atoms (halogens)
Queries::Query< int, Atom const *, true > ATOM_NULL_QUERY
static int queryAtomAliphatic(Atom const *at)
static int queryAtomNumHeteroatomNbrs(Atom const *at)
static bool getAtomTypeIsAromatic(int val)
static int queryIsAtomInNRings(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_NULL_QUERY * makeBondNullQuery()
returns a Query for matching any bond
static int queryAtomHasChiralTag(Atom const *at)
Queries::EqualityQuery< int, Bond const *, true > BOND_PROP_QUERY
Queries::OrQuery< int, Atom const *, true > ATOM_OR_QUERY
static int queryAtomImplicitHCount(Atom const *at)
static int queryAtomFormalCharge(Atom const *at)
static int queryAtomNum(Atom const *at)
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomInRingOfSizeQuery(int tgt)
returns a Query for matching atoms in rings of a particular size
T * makeAtomInRingQuery(const std::string &descr)
returns a Query for matching ring atoms
static int queryIsAtomInRing(Atom const *at)
static int queryAtomHCount(Atom const *at)
static int queryAtomExplicitValence(Atom const *at)
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeQHAtomQuery()
returns a Query for matching generic QH atoms (heteroatom or H)
static int queryAtomMass(Atom const *at)
static int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at)
static int queryAtomNumAliphaticHeteroatomNbrs(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondHasStereoQuery()
returns a Query for matching bonds with stereo set
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
int queryAtomIsInRingOfSize(Atom const *at)
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
int queryBondIsInRingOfSize(Bond const *bond)
Queries::AndQuery< int, Bond const *, true > BOND_AND_QUERY
static int queryBondIsSingleOrDoubleOrAromatic(Bond const *bond)
Queries::EqualityQuery< int, const Target *, true > * makeHasPropQuery(const std::string &property)
returns a Query for matching atoms that have a particular property
T * makeAtomIsotopeQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular isotope
Queries::EqualityQuery< int, Atom const *, true > ATOM_EQUALS_QUERY
static int queryIsBondInNRings(Bond const *at)
T * makeAtomHasImplicitHQuery(const std::string &descr)
returns a Query for matching ring atoms
static int queryAtomTotalDegree(Atom const *at)
Queries::Query< int, Bond const *, true > BOND_NULL_QUERY
RDKIT_GRAPHMOL_EXPORT bool isComplexQuery(const Bond *b)
Queries::EqualityQuery< int, Atom const *, true > ATOM_PROP_QUERY
T * makeAtomTotalValenceQuery(int what, const std::string &descr)
returns a Query for matching total valence
T * makeAtomAromaticQuery(const std::string &descr)
returns a Query for matching the isAromatic flag
static int queryBondDir(Bond const *bond)
T * makeAtomTotalDegreeQuery(int what, const std::string &descr)
returns a Query for matching atomic degree
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrAromaticBondQuery()
returns a Query for unspecified SMARTS bonds
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAAtomQuery()
returns a Query for matching generic A atoms (heavy atoms)
static int getAtomTypeAtomicNum(int val)
T * makeAtomRingBondCountQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular number of ring bonds
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondMinRingSizeQuery(int what)
returns a Query for matching a bond's minimum ring size
Atom const * ConstAtomPtr
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondOrderEqualsQuery(Bond::BondType what)
returns a Query for matching bond orders
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInNRingsQuery(int tgt)
returns a Query for matching bonds in a particular number of rings
Queries::GreaterEqualQuery< int, Atom const *, true > ATOM_GREATEREQUAL_QUERY
T * makeAtomNumRadicalElectronsQuery(int what, const std::string &descr)
returns a Query for matching the number of radical electrons
static int queryAtomIsotope(Atom const *at)
Queries::RangeQuery< int, Bond const *, true > BOND_RANGE_QUERY
static int queryAtomImplicitValence(Atom const *at)
T * makeAtomMissingChiralTagQuery(const std::string &descr)
static int queryIsBondInRing(Bond const *bond)
T * makeAtomExplicitDegreeQuery(int what, const std::string &descr)
returns a Query for matching explicit degree
static int queryBondOrder(Bond const *bond)
static int queryAtomRingMembership(Atom const *at)
T * makeAtomHasRingBondQuery(const std::string &descr)
returns a Query for matching atoms that have ring bonds
static void parseAtomType(int val, int &atomic_num, bool &aromatic)
T * makeAtomImplicitHCountQuery(int what, const std::string &descr)
returns a Query for matching implicit hydrogen count
Queries::GreaterQuery< int, Bond const *, true > BOND_GREATER_QUERY
static int queryAtomMissingChiralTag(Atom const *at)
Queries::Query< bool, Atom const *, true > ATOM_BOOL_QUERY