1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
//
// Copyright (C) 2024 Gareth Jones, Glysade LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
%include <boost_shared_ptr.i>
%shared_ptr(RDKit::QueryAtom)
%shared_ptr(RDKit::QueryBond)
// Adapted from the Python Wrappers
%{
#include <GraphMol/RDKitBase.h>
#include <GraphMol/RDKitQueries.h>
#include <RDGeneral/types.h>
%}
%include <GraphMol/RDKitBase.h>;
%include <GraphMol/RDKitQueries.h>;
%include <RDGeneral/types.h>;
/*
NOTE: it looks like there is a typo in the below code
ATOM_GREATER_QUERY is intentionally being used for the LessQueryAtom
and ATOM_LESS_QUERY for GreaterQueryAtom in the python API.
The C++ API is internally consistent and logical, but having
AtomNumLessQueryAtom(6) return atoms where 6 is less than their atomic
number feels backwards in Python.
*/
%define QAFUNC1(funcname, func, type)
%inline %{
boost::shared_ptr<RDKit::QueryAtom> funcname ## EqualsQueryAtom(type val, bool negate=false) {
boost::shared_ptr<RDKit::QueryAtom> res(new RDKit::QueryAtom());
res->setQuery(RDKit:: ## func(val));
if (negate) {
res->getQuery()->setNegation(true);
}
return res;
}
boost::shared_ptr<RDKit::QueryAtom> funcname ## LessQueryAtom(type val, bool negate=false) {
boost::shared_ptr<RDKit::QueryAtom> res(new RDKit::QueryAtom());
res->setQuery(
RDKit:: ## func <RDKit::ATOM_GREATER_QUERY>(val, std::string( # funcname "Less")));
if (negate) {
res->getQuery()->setNegation(true);
}
return res;
}
boost::shared_ptr<RDKit::QueryAtom> funcname ## GreaterQueryAtom(type val, bool negate=false) {
boost::shared_ptr<RDKit::QueryAtom> res(new RDKit::QueryAtom());
res->setQuery(
RDKit:: ## func <RDKit::ATOM_LESS_QUERY>(val, std::string(# funcname "Greater")));
if (negate) {
res->getQuery()->setNegation(true);
}
return res;
}
%}
%enddef
%define QAFUNC2(funcname, func, type)
%inline %{
boost::shared_ptr<RDKit::QueryAtom> funcname(bool negate=false) {
boost::shared_ptr<RDKit::QueryAtom> res(new RDKit::QueryAtom());
res->setQuery(RDKit:: ## func());
if (negate) {
res->getQuery()->setNegation(true);
}
return res;
}
%}
%enddef
QAFUNC1(AtomNum, makeAtomNumQuery, int);
QAFUNC1(ExplicitValence, makeAtomExplicitValenceQuery, int);
QAFUNC1(TotalValence, makeAtomTotalValenceQuery, int);
QAFUNC1(ExplicitDegree, makeAtomExplicitDegreeQuery, int);
QAFUNC1(TotalDegree, makeAtomTotalDegreeQuery, int);
QAFUNC1(NonHydrogenDegree, makeAtomNonHydrogenDegreeQuery, int);
QAFUNC1(HCount, makeAtomHCountQuery, int);
QAFUNC1(Mass, makeAtomMassQuery, int);
QAFUNC1(Isotope, makeAtomIsotopeQuery, int);
QAFUNC1(FormalCharge, makeAtomFormalChargeQuery, int);
QAFUNC1(Hybridization, makeAtomHybridizationQuery, int);
QAFUNC1(InNRings, makeAtomInNRingsQuery, int);
QAFUNC1(MinRingSize, makeAtomMinRingSizeQuery, int);
QAFUNC1(RingBondCount, makeAtomRingBondCountQuery, int);
QAFUNC1(NumRadicalElectrons, makeAtomNumRadicalElectronsQuery, int);
QAFUNC1(NumHeteroatomNeighbors, makeAtomNumHeteroatomNbrsQuery, int);
QAFUNC1(NumAliphaticHeteroatomNeighbors,
makeAtomNumAliphaticHeteroatomNbrsQuery, int);
QAFUNC2(IsUnsaturatedQueryAtom, makeAtomUnsaturatedQuery, int);
QAFUNC2(IsAromaticQueryAtom, makeAtomAromaticQuery, int);
QAFUNC2(IsAliphaticQueryAtom, makeAtomAliphaticQuery, int);
QAFUNC2(IsInRingQueryAtom, makeAtomInRingQuery, int);
QAFUNC2(HasChiralTagQueryAtom, makeAtomHasChiralTagQuery, int);
QAFUNC2(MissingChiralTagQueryAtom, makeAtomMissingChiralTagQuery, int);
QAFUNC2(IsBridgeheadQueryAtom, makeAtomIsBridgeheadQuery, int);
QAFUNC2(AAtomQueryAtom, makeAAtomQuery, int);
QAFUNC2(AHAtomQueryAtom, makeAHAtomQuery, int);
QAFUNC2(QAtomQueryAtom, makeQAtomQuery, int);
QAFUNC2(QHAtomQueryAtom, makeQHAtomQuery, int);
QAFUNC2(XAtomQueryAtom, makeXAtomQuery, int);
QAFUNC2(XHAtomQueryAtom, makeXHAtomQuery, int);
QAFUNC2(MAtomQueryAtom, makeMAtomQuery, int);
QAFUNC2(MHAtomQueryAtom, makeMHAtomQuery, int);
%{
template <class Ob, class Ret, class T>
boost::shared_ptr<Ret> PropQuery(const std::string &propname, const T &v, bool negate) {
boost::shared_ptr<Ret> res(new Ret());
res->setQuery(RDKit::makePropQuery<Ob, T>(propname, v));
if (negate) {
res->getQuery()->setNegation(true);
}
return res;
}
template <class Ob, class Ret, class T>
boost::shared_ptr<Ret> PropQueryWithTol(const std::string &propname, const T &v, bool negate,
const T &tol = T()) {
boost::shared_ptr<Ret> res(new Ret());
res->setQuery(RDKit::makePropQuery<Ob, T>(propname, v, tol));
if (negate) {
res->getQuery()->setNegation(true);
}
return res;
}
template <class Ob, class Ret>
boost::shared_ptr<Ret> PropQueryWithTol(const std::string &propname, const ExplicitBitVect &v,
bool negate=false, float tol = 0.0) {
boost::shared_ptr<Ret> res(new Ret());
res->setQuery(RDKit::makePropQuery<Ob>(propname, v, tol));
if (negate) {
res->getQuery()->setNegation(true);
}
return res;
}
boost::shared_ptr<RDKit::QueryAtom> HasPropQueryAtom(const std::string &propname, bool negate=false) {
boost::shared_ptr<RDKit::QueryAtom> res(new RDKit::QueryAtom());
res->setQuery(RDKit::makeHasPropQuery<RDKit::Atom>(propname));
if (negate) {
res->getQuery()->setNegation(true);
}
return res;
}
boost::shared_ptr<RDKit::QueryAtom> HasIntPropWithValueQueryAtom(const std::string &propname, int val, bool negate=false) {
return PropQuery<RDKit::Atom, RDKit::QueryAtom, int>(propname, val, negate);
}
boost::shared_ptr<RDKit::QueryAtom> HasBoolPropWithValueQueryAtom(const std::string &propname, bool val, bool negate=false) {
return PropQuery<RDKit::Atom, RDKit::QueryAtom, bool>(propname, val, negate);
}
boost::shared_ptr<RDKit::QueryAtom> HasStringPropWithValueQueryAtom(const std::string &propname, const std::string &val, bool negate=false) {
return PropQuery<RDKit::Atom, RDKit::QueryAtom, std::string>(propname, val, negate);
}
boost::shared_ptr<RDKit::QueryAtom> HasDoublePropWithValueQueryAtom(const std::string &propname, double val, bool negate=false, double tol=0) {
return PropQueryWithTol<RDKit::Atom, RDKit::QueryAtom, double>(propname, val, negate, tol);
}
boost::shared_ptr<RDKit::QueryAtom> HasBitVectPropWithValueQueryAtom(const std::string &propname, const ExplicitBitVect &val, bool negate=false, float tol=0) {
return PropQueryWithTol<RDKit::Atom, RDKit::QueryAtom>(propname, val, negate, tol);
}
boost::shared_ptr<RDKit::QueryBond> HasPropQueryBond(const std::string &propname, bool negate=false) {
boost::shared_ptr<RDKit::QueryBond> res(new RDKit::QueryBond());
res->setQuery(RDKit::makeHasPropQuery<RDKit::Bond>(propname));
if (negate) {
res->getQuery()->setNegation(true);
}
return res;
}
boost::shared_ptr<RDKit::QueryBond> HasIntPropWithValueQueryBond(const std::string &propname, int val, bool negate=false) {
return PropQuery<RDKit::Bond, RDKit::QueryBond, int>(propname, val, negate);
}
boost::shared_ptr<RDKit::QueryBond> HasBoolPropWithValueQueryBond(const std::string &propname, bool val, bool negate=false) {
return PropQuery<RDKit::Bond, RDKit::QueryBond, bool>(propname, val, negate);
}
boost::shared_ptr<RDKit::QueryBond> HasStringPropWithValueQueryBond(const std::string &propname, const std::string &val, bool negate=false) {
return PropQuery<RDKit::Bond, RDKit::QueryBond, std::string>(propname, val, negate);
}
boost::shared_ptr<RDKit::QueryBond> HasDoublePropWithValueQueryBond(const std::string &propname, double val, bool negate=false, double tol=0) {
return PropQueryWithTol<RDKit::Bond, RDKit::QueryBond, double>(propname, val, negate, tol);
}
%}
boost::shared_ptr<RDKit::QueryAtom> HasPropQueryAtom(const std::string &propname, bool negate=false);
boost::shared_ptr<RDKit::QueryBond> HasPropQueryBond(const std::string &propname, bool negate=false);
boost::shared_ptr<RDKit::QueryAtom> HasIntPropWithValueQueryAtom(const std::string &propname, int val, bool negate=false);
boost::shared_ptr<RDKit::QueryAtom> HasBoolPropWithValueQueryAtom(const std::string &propname, bool val, bool negate=false);
boost::shared_ptr<RDKit::QueryAtom> HasStringPropWithValueQueryAtom(const std::string &propname, const std::string &val, bool negate=false);
boost::shared_ptr<RDKit::QueryAtom> HasDoublePropWithValueQueryAtom(const std::string &propname, double val, bool negate=false, double tol=0);
boost::shared_ptr<RDKit::QueryAtom> HasBitVectPropWithValueQueryAtom(const std::string &propname, const ExplicitBitVect &val, bool negate=false, float tol=0);
boost::shared_ptr<RDKit::QueryBond> HasPropQueryBond(const std::string &propname, bool negate=false);
boost::shared_ptr<RDKit::QueryBond> HasIntPropWithValueQueryBond(const std::string &propname, int val, bool negate=false);
boost::shared_ptr<RDKit::QueryBond> HasBoolPropWithValueQueryBond(const std::string &propname, bool val, bool negate=false);
boost::shared_ptr<RDKit::QueryBond> HasStringPropWithValueQueryBond(const std::string &propname, const std::string &val, bool negate=false);
boost::shared_ptr<RDKit::QueryBond> HasDoublePropWithValueQueryBond(const std::string &propname, double val, bool negate=false, double tol=0);
%extend RDKit::QueryAtom {
void ExpandQuery(const RDKit::QueryAtom *other, Queries::CompositeQueryType how=Queries::COMPOSITE_AND, bool maintainOrder=true) {
PRECONDITION(other, "bad atoms");
if (other->hasQuery()) {
const RDKit::QueryAtom::QUERYATOM_QUERY *qry = other->getQuery();
($self)->expandQuery(qry->copy(), how, maintainOrder);
}
}
void setQuery(const RDKit::QueryAtom *other) {
PRECONDITION(other, "bad atoms");
if (other->hasQuery()) {
($self)->setQuery(other->getQuery()->copy());
}
}
}
%extend RDKit::Atom {
void ExpandQuery(const RDKit::QueryAtom *other, Queries::CompositeQueryType how=Queries::COMPOSITE_AND, bool maintainOrder=true) {
PRECONDITION(other, "bad atoms");
if (other->hasQuery()) {
const RDKit::QueryAtom::QUERYATOM_QUERY *qry = other->getQuery();
($self)->expandQuery(qry->copy(), how, maintainOrder);
}
}
void setQuery(const RDKit::QueryAtom *other) {
PRECONDITION(other, "bad atoms");
if (other->hasQuery()) {
($self)->setQuery(other->getQuery()->copy());
}
}
}
%extend RDKit::QueryBond {
void ExpandQuery(const RDKit::QueryBond *other, Queries::CompositeQueryType how=Queries::COMPOSITE_AND, bool maintainOrder=true) {
PRECONDITION(other, "bad bonds");
if (other->hasQuery()) {
const RDKit::QueryBond::QUERYBOND_QUERY *qry = other->getQuery();
($self)->expandQuery(qry->copy(), how, maintainOrder);
}
}
void SetQuery(const RDKit::QueryBond *other) {
PRECONDITION(other, "bad bonds");
if (other->hasQuery()) {
($self)->setQuery(other->getQuery()->copy());
}
}
}
%extend RDKit::Bond {
void ExpandQuery(const RDKit::QueryBond *other, Queries::CompositeQueryType how=Queries::COMPOSITE_AND, bool maintainOrder=true) {
PRECONDITION(other, "bad bonds");
if (other->hasQuery()) {
const RDKit::QueryBond::QUERYBOND_QUERY *qry = other->getQuery();
($self)->expandQuery(qry->copy(), how, maintainOrder);
}
}
void SetQuery(const RDKit::QueryBond *other) {
PRECONDITION(other, "bad bonds");
if (other->hasQuery()) {
($self)->setQuery(other->getQuery()->copy());
}
}
}
|