25#ifdef RDK_BUILD_THREADSAFE_SSS
87 for (
const auto nbri :
90 if (nbr->getAtomicNum() != 1 || nbr->getIsotope() > 1) {
100 for (
const auto nbri :
103 if (nbr->getAtomicNum() > 1) {
133 return atomic_num + 1000 *
static_cast<int>(aromatic);
138 atomic_num = 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) {
286 while (atomBonds.first != atomBonds.second) {
287 unsigned int bondIdx =
312 while (atomBonds.first != atomBonds.second) {
313 unsigned int bondIdx =
343 const std::string &description =
"Atom Simple") {
346 res->setDataFunc(func);
347 res->setDescription(description);
352 int lower,
int upper,
bool lowerOpen,
bool upperOpen,
353 int func(
Atom const *),
const std::string &description =
"Atom Range") {
364 return makeAtomSimpleQuery<T>(what,
queryAtomNum, descr);
691 return static_cast<int>(
706 this->setDescription(
"AtomInNRings");
712 this->setDescription(
"AtomInNRings");
719 if (this->d_val < 0) {
724 if (this->getNegation()) {
734 res->
setTol(this->getTol());
746 setDataFunc(getAtIdx);
747 setDescription(
"RecursiveStructure");
756 d_serialNumber(serialNumber) {
758 setDataFunc(getAtIdx);
759 setDescription(
"RecursiveStructure");
779 res->dp_queryMol.reset(
new ROMol(*dp_queryMol,
true));
781 std::set<int>::const_iterator i;
782 for (i = d_set.begin(); i != d_set.end(); i++) {
787 res->d_serialNumber = d_serialNumber;
792#ifdef RDK_BUILD_THREADSAFE_SSS
796 boost::shared_ptr<const ROMol> dp_queryMol;
797 unsigned int d_serialNumber{0};
812template <
class TargetPtr>
814 std::string propname;
829 bool Match(
const TargetPtr what)
const override {
830 bool res = what->hasProp(propname);
850template <
class Target>
852 const std::string &property) {
857template <
class TargetPtr,
class T>
860 std::string propname;
874 propname(std::move(prop)),
882 bool Match(
const TargetPtr what)
const override {
883 bool res = what->hasProp(propname);
886 T atom_val = what->template getProp<T>(propname);
890 }
catch (boost::bad_any_cast &) {
894#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
924template <
class TargetPtr>
927 std::string propname;
938 const std::string &tol =
"")
940 propname(std::move(prop)),
948 bool Match(
const TargetPtr what)
const override {
949 bool res = what->hasProp(propname);
952 std::string atom_val = what->template getProp<std::string>(propname);
953 res = atom_val == this->val;
956 }
catch (boost::bad_any_cast &) {
960#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
991template <
class TargetPtr>
994 std::string propname;
1008 propname(std::move(prop)),
1015 bool Match(
const TargetPtr what)
const override {
1016 bool res = what->hasProp(propname);
1020 what->template getProp<const ExplicitBitVect &>(propname);
1022 res = (1.0 - tani) <= tol;
1025 }
catch (boost::bad_any_cast &) {
1029#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
1053 this->propname, this->val, this->tol);
1060template <
class Target,
class T>
1062 const std::string &propname,
const T &val,
const T &tolerance = T()) {
1066template <
class Target>
1069 float tolerance = 0.0) {
1071 propname, val, tolerance);
1079 std::vector<int> &vals);
1083 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
bool Match(const ConstAtomPtr what) const override
Queries::Query< int, ConstAtomPtr, true > * copy() const override
returns a copy of this query
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
unsigned int getIdx() const
returns our index within the ROMol
virtual QUERYBOND_QUERY * getQuery() const
NOT CALLABLE.
virtual bool hasQuery() const
BondType getBondType() const
returns our bondType
ROMol & getOwningMol() const
returns a reference to the ROMol that owns this instance
BondDir
the bond's direction (for chirality)
BondStereo getStereo() const
returns our stereo code
BondDir getBondDir() const
returns our direction
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
HasPropQuery(std::string v)
bool Match(const TargetPtr what) const override
returns whether or not we match the argument
bool Match(const TargetPtr what) const override
returns whether or not we match the argument
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
HasPropWithValueQuery(std::string prop, const ExplicitBitVect &v, float tol=0.0)
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
HasPropWithValueQuery(std::string prop, std::string v, const std::string &tol="")
bool Match(const TargetPtr what) const override
returns whether or not we match the argument
HasPropWithValueQuery(std::string prop, const T &v, const T &tol=0.0)
bool Match(const TargetPtr what) const override
returns whether or not we match the argument
Queries::Query< int, TargetPtr, true > * copy() const override
returns a copy of this query
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)
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 override
returns a copy of this query
ROMol const * getQueryMol() const
returns a pointer to our query molecule
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 bool hasComplexBondTypeQuery(const Queries::Query< int, Bond const *, true > &qry)
RDKIT_GRAPHMOL_EXPORT void finalizeQueryFromDescription(Queries::Query< int, Atom const *, true > *query, Atom const *owner)
RDKIT_GRAPHMOL_EXPORT bool hasBondTypeQuery(const Queries::Query< int, Bond const *, true > &qry)
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
static int queryAtomNumRadicalElectrons(Atom const *at)
Queries::EqualityQuery< int, const Target *, true > * makePropQuery(const std::string &propname, const T &val, const T &tolerance=T())
T * makeAtomHeavyAtomDegreeQuery(int what, const std::string &descr)
returns a Query for matching heavy atom degree
Queries::LessQuery< int, Atom const *, true > ATOM_LESS_QUERY
static int queryAtomHybridization(Atom const *at)
static int queryAtomMinRingSize(Atom const *at)
T * makeAtomTotalDegreeQuery(int what, const std::string &descr)
returns a Query for matching atomic degree
Queries::LessEqualQuery< int, Bond const *, true > BOND_LESSEQUAL_QUERY
static int queryAtomExplicitDegree(Atom const *at)
static int queryAtomHasRingBond(Atom const *at)
Bond const * ConstBondPtr
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrDoubleBondQuery()
returns a Query for single|double bonds
static int queryBondHasStereo(Bond const *bnd)
static int queryAtomUnsaturated(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeSingleOrAromaticBondQuery()
returns a Query for unspecified SMARTS bonds
static int queryAtomAromatic(Atom const *at)
Queries::RangeQuery< int, Atom const *, true > ATOM_RANGE_QUERY
Queries::Query< bool, Bond const *, true > BOND_BOOL_QUERY
static int queryAtomType(Atom const *at)
Queries::AndQuery< int, Atom const *, true > ATOM_AND_QUERY
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeMHAtomQuery()
returns a Query for matching generic MH atoms (metals or H)
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomBondProduct(Atom const *at)
static int queryBondIsDoubleOrAromatic(Bond const *bond)
static int queryAtomHasImplicitH(Atom const *at)
T * makeAtomIsBridgeheadQuery(const std::string &descr)
returns a Query for matching bridgehead atoms
Queries::LessEqualQuery< int, Atom const *, true > ATOM_LESSEQUAL_QUERY
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInRingOfSizeQuery(int what)
returns a Query for matching bonds in rings of a particular size
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeDoubleOrAromaticBondQuery()
returns a Query for double|aromatic bonds
RDKIT_GRAPHMOL_EXPORT ATOM_NULL_QUERY * makeAtomNullQuery()
returns a Query for matching any atom
RDKIT_GRAPHMOL_EXPORT unsigned int queryAtomAllBondProduct(Atom const *at)
T * makeAtomAliphaticQuery(const std::string &descr)
returns a Query for matching aliphatic atoms
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 * makeSingleOrDoubleOrAromaticBondQuery()
returns a Query for tautomeric bonds
T * makeAtomTotalValenceQuery(int what, const std::string &descr)
returns a Query for matching total valence
RDKIT_GRAPHMOL_EXPORT bool isAtomAromatic(const Atom *a)
Queries::XOrQuery< int, Atom const *, true > ATOM_XOR_QUERY
T * makeAtomHasRingBondQuery(const std::string &descr)
returns a Query for matching atoms that have ring bonds
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXAtomQuery()
returns a Query for matching generic X atoms (halogens)
RDKIT_GRAPHMOL_EXPORT ATOM_NULL_QUERY * makeAHAtomQuery()
returns a Query for matching generic AH atoms (any atom)
Queries::SetQuery< int, Bond const *, true > BOND_SET_QUERY
static int queryBondIsSingleOrAromatic(Bond const *bond)
T * makeAtomFormalChargeQuery(int what, const std::string &descr)
returns a Query for matching formal charge
Queries::OrQuery< int, Bond const *, true > BOND_OR_QUERY
T * makeAtomInRingQuery(const std::string &descr)
returns a Query for matching ring atoms
static int queryBondMinRingSize(Bond const *bond)
const int massIntegerConversionFactor
T * makeAtomNumRadicalElectronsQuery(int what, const std::string &descr)
returns a Query for matching the number of radical electrons
static int queryAtomTotalValence(Atom const *at)
static int queryAtomNonHydrogenDegree(Atom const *at)
D and T are treated as "non-hydrogen" here.
T * makeAtomHasAliphaticHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
T * makeAtomRingBondCountQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular number of ring bonds
static int makeAtomType(int atomic_num, bool aromatic)
T * makeAtomMinRingSizeQuery(int tgt, const std::string &descr)
returns a Query for matching an atom's minimum ring size
static int queryAtomHeavyAtomDegree(Atom const *at)
D and T are not treated as heavy atoms here.
static int queryAtomRingBondCount(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_NULL_QUERY * makeBondNullQuery()
returns a Query for matching any bond
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondDirEqualsQuery(Bond::BondDir what)
returns a Query for matching bond directions
T * makeAtomImplicitHCountQuery(int what, const std::string &descr)
returns a Query for matching implicit hydrogen count
T * makeAtomMassQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular mass
T * makeAtomNumAliphaticHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of aliphatic heteroatom neighbors
Queries::XOrQuery< int, Bond const *, true > BOND_XOR_QUERY
T * makeAtomSimpleQuery(int what, int func(Atom const *), const std::string &description="Atom Simple")
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 ATOM_OR_QUERY * makeMAtomQuery()
returns a Query for matching generic M atoms (metals)
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)
T * makeAtomAromaticQuery(const std::string &descr)
returns a Query for matching the isAromatic flag
static int queryAtomFormalCharge(Atom const *at)
T * makeAtomNonHydrogenDegreeQuery(int what, const std::string &descr)
returns a Query for matching the number of non-hydrogen neighbors
RDKIT_GRAPHMOL_EXPORT int queryIsAtomBridgehead(Atom const *at)
static int queryAtomNum(Atom const *at)
Queries::GreaterEqualQuery< int, Bond const *, true > BOND_GREATEREQUAL_QUERY
static int queryIsAtomInRing(Atom const *at)
static int queryAtomHCount(Atom const *at)
T * makeAtomImplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching implicit valence
static int queryAtomExplicitValence(Atom const *at)
RDKIT_GRAPHMOL_EXPORT bool isAtomListQuery(const Atom *a)
static int queryAtomMass(Atom const *at)
static int queryAtomHasAliphaticHeteroatomNbrs(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondOrderEqualsQuery(Bond::BondType what)
returns a Query for matching bond orders
static int queryAtomNumAliphaticHeteroatomNbrs(Atom const *at)
Queries::EqualityQuery< int, Bond const *, true > BOND_EQUALS_QUERY
int queryAtomIsInRingOfSize(Atom const *at)
Queries::GreaterQuery< int, Atom const *, true > ATOM_GREATER_QUERY
T * makeAtomExplicitValenceQuery(int what, const std::string &descr)
returns a Query for matching explicit valence
T * makeAtomHasHeteroatomNbrsQuery(const std::string &descr)
returns a Query for matching atoms that have heteroatom neighbors
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAAtomQuery()
returns a Query for matching generic A atoms (heavy atoms)
int queryBondIsInRingOfSize(Bond const *bond)
Queries::AndQuery< int, Bond const *, true > BOND_AND_QUERY
static int queryBondIsSingleOrDoubleOrAromatic(Bond const *bond)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondMinRingSizeQuery(int what)
returns a Query for matching a bond's minimum ring size
RDKIT_GRAPHMOL_EXPORT void getAtomListQueryVals(const Atom::QUERYATOM_QUERY *q, std::vector< int > &vals)
T * makeAtomExplicitDegreeQuery(int what, const std::string &descr)
returns a Query for matching explicit degree
T * makeAtomUnsaturatedQuery(const std::string &descr)
returns a Query for matching atoms with unsaturation:
T * makeAtomHasChiralTagQuery(const std::string &descr)
Queries::EqualityQuery< int, Atom const *, true > ATOM_EQUALS_QUERY
static int queryIsBondInNRings(Bond const *at)
static int queryAtomTotalDegree(Atom const *at)
Queries::Query< int, Bond const *, true > BOND_NULL_QUERY
T * makeAtomInNRingsQuery(int what, const std::string &descr)
returns a Query for matching atoms in a particular number of rings
RDKIT_GRAPHMOL_EXPORT bool isComplexQuery(const Bond *b)
Queries::EqualityQuery< int, Atom const *, true > ATOM_PROP_QUERY
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondInNRingsQuery(int tgt)
returns a Query for matching bonds in a particular number of rings
static int queryBondDir(Bond const *bond)
T * makeAtomIsotopeQuery(int what, const std::string &descr)
returns a Query for matching atoms with a particular isotope
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeAtomInRingOfSizeQuery(int tgt)
returns a Query for matching atoms in rings of a particular size
static int getAtomTypeAtomicNum(int val)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeXHAtomQuery()
returns a Query for matching generic XH atoms (halogen or H)
RDKIT_GRAPHMOL_EXPORT ATOM_EQUALS_QUERY * makeQHAtomQuery()
returns a Query for matching generic QH atoms (heteroatom or H)
T * makeAtomNegativeFormalChargeQuery(int what, const std::string &descr)
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
static int queryBondIsSingleOrDouble(Bond const *bond)
Atom const * ConstAtomPtr
T * makeAtomHCountQuery(int what, const std::string &descr)
returns a Query for matching hydrogen count
static ATOM_RANGE_QUERY * makeAtomRangeQuery(int lower, int upper, bool lowerOpen, bool upperOpen, int func(Atom const *), const std::string &description="Atom Range")
Queries::EqualityQuery< int, const Target *, true > * makeHasPropQuery(const std::string &property)
returns a Query for matching atoms that have a particular property
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondHasStereoQuery()
returns a Query for matching bonds with stereo set
Queries::GreaterEqualQuery< int, Atom const *, true > ATOM_GREATEREQUAL_QUERY
static int queryAtomIsotope(Atom const *at)
RDKIT_GRAPHMOL_EXPORT BOND_EQUALS_QUERY * makeBondIsInRingQuery()
returns a Query for matching ring bonds
T * makeAtomTypeQuery(int num, int aromatic, const std::string &descr)
returns a Query for matching atomic number and aromaticity
T * makeAtomHasImplicitHQuery(const std::string &descr)
returns a Query for matching ring atoms
Queries::RangeQuery< int, Bond const *, true > BOND_RANGE_QUERY
static int queryAtomImplicitValence(Atom const *at)
T * makeAtomNumHeteroatomNbrsQuery(int what, const std::string &descr)
returns a Query for matching the number of heteroatom neighbors
static int queryIsBondInRing(Bond const *bond)
RDKIT_GRAPHMOL_EXPORT ATOM_OR_QUERY * makeQAtomQuery()
returns a Query for matching generic Q atoms (heteroatoms)
static int queryBondOrder(Bond const *bond)
static int queryAtomRingMembership(Atom const *at)
static void parseAtomType(int val, int &atomic_num, bool &aromatic)
T * makeAtomHybridizationQuery(int what, const std::string &descr)
returns a Query for matching hybridization
T * makeAtomMissingChiralTagQuery(const std::string &descr)
Queries::GreaterQuery< int, Bond const *, true > BOND_GREATER_QUERY
static int queryAtomMissingChiralTag(Atom const *at)
Queries::Query< bool, Atom const *, true > ATOM_BOOL_QUERY