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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
// $Id: QueryOps.cpp 1625 2011-01-13 04:22:56Z glandrum $
//
// Copyright (C) 2003-2008 Greg Landrum and Rational Discovery 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 "QueryOps.h"
#include <algorithm>
#include <RDGeneral/types.h>
namespace RDKit{
// common general queries
//! returns a Query for matching atoms with a particular number of ring bonds
ATOM_EQUALS_QUERY *makeAtomRingBondCountQuery(int what) {
ATOM_EQUALS_QUERY *res=new AtomRingQuery(what);
res->setDescription("AtomRingBondCount");
res->setDataFunc(queryAtomRingBondCount);
return res;
};
ATOM_EQUALS_QUERY *makeAtomInRingOfSizeQuery(int tgt){
RANGE_CHECK(3,tgt,20);
ATOM_EQUALS_QUERY *res = new ATOM_EQUALS_QUERY;
res->setVal(tgt);
switch(tgt){
case 3:
res->setDataFunc(queryAtomIsInRingOfSize<3>);break;
case 4:
res->setDataFunc(queryAtomIsInRingOfSize<4>);break;
case 5:
res->setDataFunc(queryAtomIsInRingOfSize<5>);break;
case 6:
res->setDataFunc(queryAtomIsInRingOfSize<6>);break;
case 7:
res->setDataFunc(queryAtomIsInRingOfSize<7>);break;
case 8:
res->setDataFunc(queryAtomIsInRingOfSize<8>);break;
case 9:
res->setDataFunc(queryAtomIsInRingOfSize<9>);break;
case 10:
res->setDataFunc(queryAtomIsInRingOfSize<10>);break;
case 11:
res->setDataFunc(queryAtomIsInRingOfSize<11>);break;
case 12:
res->setDataFunc(queryAtomIsInRingOfSize<12>);break;
case 13:
res->setDataFunc(queryAtomIsInRingOfSize<13>);break;
case 14:
res->setDataFunc(queryAtomIsInRingOfSize<14>);break;
case 15:
res->setDataFunc(queryAtomIsInRingOfSize<15>);break;
case 16:
res->setDataFunc(queryAtomIsInRingOfSize<16>);break;
case 17:
res->setDataFunc(queryAtomIsInRingOfSize<17>);break;
case 18:
res->setDataFunc(queryAtomIsInRingOfSize<18>);break;
case 19:
res->setDataFunc(queryAtomIsInRingOfSize<19>);break;
case 20:
res->setDataFunc(queryAtomIsInRingOfSize<20>);break;
}
res->setDescription("AtomRingSize");
return res;
}
BOND_EQUALS_QUERY *makeBondInRingOfSizeQuery(int tgt){
RANGE_CHECK(3,tgt,20);
BOND_EQUALS_QUERY *res = new BOND_EQUALS_QUERY;
res->setVal(tgt);
switch(tgt){
case 3:
res->setDataFunc(queryBondIsInRingOfSize<3>);break;
case 4:
res->setDataFunc(queryBondIsInRingOfSize<4>);break;
case 5:
res->setDataFunc(queryBondIsInRingOfSize<5>);break;
case 6:
res->setDataFunc(queryBondIsInRingOfSize<6>);break;
case 7:
res->setDataFunc(queryBondIsInRingOfSize<7>);break;
case 8:
res->setDataFunc(queryBondIsInRingOfSize<8>);break;
case 9:
res->setDataFunc(queryBondIsInRingOfSize<9>);break;
case 10:
res->setDataFunc(queryBondIsInRingOfSize<10>);break;
case 11:
res->setDataFunc(queryBondIsInRingOfSize<11>);break;
case 12:
res->setDataFunc(queryBondIsInRingOfSize<12>);break;
case 13:
res->setDataFunc(queryBondIsInRingOfSize<13>);break;
case 14:
res->setDataFunc(queryBondIsInRingOfSize<14>);break;
case 15:
res->setDataFunc(queryBondIsInRingOfSize<15>);break;
case 16:
res->setDataFunc(queryBondIsInRingOfSize<16>);break;
case 17:
res->setDataFunc(queryBondIsInRingOfSize<17>);break;
case 18:
res->setDataFunc(queryBondIsInRingOfSize<18>);break;
case 19:
res->setDataFunc(queryBondIsInRingOfSize<19>);break;
case 20:
res->setDataFunc(queryBondIsInRingOfSize<20>);break;
}
res->setDescription("BondRingSize");
return res;
}
ATOM_EQUALS_QUERY *makeAtomMinRingSizeQuery(int tgt){
RANGE_CHECK(3,tgt,20);
ATOM_EQUALS_QUERY *res = new ATOM_EQUALS_QUERY;
res->setVal(tgt);
res->setDataFunc(queryAtomMinRingSize);
res->setDescription("AtomMinRingSize");
return res;
}
BOND_EQUALS_QUERY *makeBondMinRingSizeQuery(int tgt){
RANGE_CHECK(3,tgt,20);
BOND_EQUALS_QUERY *res = new BOND_EQUALS_QUERY;
res->setVal(tgt);
res->setDataFunc(queryBondMinRingSize);
res->setDescription("BondMinRingSize");
return res;
}
ATOM_EQUALS_QUERY *makeAtomSimpleQuery(int what,int func(Atom const *)){
ATOM_EQUALS_QUERY *res = new ATOM_EQUALS_QUERY;
res->setVal(what);
res->setDataFunc(func);
res->setDescription("AtomSimple");
return res;
}
unsigned int queryAtomBondProduct(Atom const * at) {
ROMol::OEDGE_ITER beg,end;
boost::tie(beg,end) = at->getOwningMol().getAtomBonds(at);
unsigned int prod=1;
while(beg!=end){
prod *= static_cast<unsigned int>(firstThousandPrimes[at->getOwningMol()[*beg]->getBondType()]);
++beg;
}
return prod;
}
unsigned int queryAtomAllBondProduct(Atom const * at) {
ROMol::OEDGE_ITER beg,end;
boost::tie(beg,end) = at->getOwningMol().getAtomBonds(at);
unsigned int prod=1;
while(beg!=end){
prod *= static_cast<unsigned int>(firstThousandPrimes[at->getOwningMol()[*beg]->getBondType()]);
++beg;
}
for(unsigned int i=0;i<at->getTotalNumHs();i++){
prod *= static_cast<unsigned int>(firstThousandPrimes[Bond::SINGLE]);
}
return prod;
}
ATOM_EQUALS_QUERY *makeAtomImplicitValenceQuery(int what){
ATOM_EQUALS_QUERY *res = makeAtomSimpleQuery(what,queryAtomImplicitValence);
res->setDescription("AtomImplicitValence");
return res;
}
ATOM_EQUALS_QUERY *makeAtomExplicitValenceQuery(int what){
ATOM_EQUALS_QUERY *res = makeAtomSimpleQuery(what,queryAtomExplicitValence);
res->setDescription("AtomExplicitValence");
return res;
}
ATOM_EQUALS_QUERY *makeAtomTotalValenceQuery(int what){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(what,queryAtomTotalValence);
res->setDescription("AtomTotalValence");
return res;
}
ATOM_EQUALS_QUERY *makeAtomNumEqualsQuery(int what){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(what,queryAtomNum);
res->setDescription("AtomAtomicNum");
return res;
}
ATOM_EQUALS_QUERY *makeAtomExplicitDegreeQuery(int what){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(what,queryAtomExplicitDegree);
res->setDescription("AtomExplicitDegree");
return res;
}
ATOM_EQUALS_QUERY *makeAtomTotalDegreeQuery(int what){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(what,queryAtomTotalDegree);
res->setDescription("AtomTotalDegree");
return res;
}
ATOM_EQUALS_QUERY *makeAtomHCountQuery(int what){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(what,queryAtomHCount);
res->setDescription("AtomHCount");
return res;
}
ATOM_EQUALS_QUERY *makeAtomAromaticQuery(){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(true,queryAtomAromatic);
res->setDescription("AtomIsAromatic");
return res;
}
ATOM_EQUALS_QUERY *makeAtomAliphaticQuery(){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(true,queryAtomAliphatic);
res->setDescription("AtomIsAliphatic");
return res;
}
ATOM_EQUALS_QUERY *makeAtomUnsaturatedQuery(){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(true,queryAtomUnsaturated);
res->setDescription("AtomUnsaturated");
return res;
}
ATOM_EQUALS_QUERY *makeAtomMassQuery(int what){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(massIntegerConversionFactor*what,
queryAtomMass);
res->setDescription("AtomMass");
return res;
}
ATOM_EQUALS_QUERY *makeAtomFormalChargeQuery(int what){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(what,queryAtomFormalCharge);
res->setDescription("AtomFormalCharge");
return res;
}
ATOM_EQUALS_QUERY *makeAtomHybridizationQuery(int what){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(what,queryAtomHybridization);
res->setDescription("AtomHybridization");
return res;
}
ATOM_EQUALS_QUERY *makeAtomInRingQuery(){
ATOM_EQUALS_QUERY *res=makeAtomSimpleQuery(true,queryIsAtomInRing);
res->setDescription("AtomInRing");
return res;
}
ATOM_EQUALS_QUERY *makeAtomInNRingsQuery(int what){
ATOM_EQUALS_QUERY *res;
res = makeAtomSimpleQuery(what,queryIsAtomInNRings);
res->setDescription("AtomInNRings");
return res;
}
BOND_EQUALS_QUERY *makeBondOrderEqualsQuery(Bond::BondType what){
BOND_EQUALS_QUERY *res = new BOND_EQUALS_QUERY;
res->setVal(what);
res->setDataFunc(queryBondOrder);
res->setDescription("BondOrder");
return res;
}
BOND_EQUALS_QUERY *makeBondDirEqualsQuery(Bond::BondDir what){
BOND_EQUALS_QUERY *res = new BOND_EQUALS_QUERY;
res->setVal(what);
res->setDataFunc(queryBondDir);
res->setDescription("BondDir");
return res;
}
BOND_EQUALS_QUERY *makeBondIsInRingQuery(){
BOND_EQUALS_QUERY *res = new BOND_EQUALS_QUERY;
res->setVal(true);
res->setDataFunc(queryIsBondInRing);
res->setDescription("BondInRing");
return res;
}
BOND_EQUALS_QUERY *makeBondInNRingsQuery(int what){
BOND_EQUALS_QUERY *res = new BOND_EQUALS_QUERY;
res->setVal(what);
res->setDataFunc(queryIsBondInNRings);
res->setDescription("BondInNRings");
return res;
}
BOND_NULL_QUERY *makeBondNullQuery(){
BOND_NULL_QUERY *res = new BOND_NULL_QUERY;
res->setDataFunc(nullDataFun);
res->setMatchFunc(nullQueryFun);
res->setDescription("BondNull");
return res;
}
ATOM_NULL_QUERY *makeAtomNullQuery(){
ATOM_NULL_QUERY *res = new ATOM_NULL_QUERY;
res->setDataFunc(nullDataFun);
res->setMatchFunc(nullQueryFun);
res->setDescription("AtomNull");
return res;
}
};
|