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 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
|
//
// Copyright (C) 2002-2017 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 <RDGeneral/test.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/RDKitQueries.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>
#include <RDGeneral/RDLog.h>
#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace RDKit;
using namespace std;
typedef class ROMol Mol;
void test1() {
string smi = "CCOC";
Mol *m = SmilesToMol(smi);
Mol::AtomIterator atIt;
unsigned int idx = 0;
for (atIt = m->beginAtoms(); atIt != m->endAtoms(); atIt++) {
CHECK_INVARIANT((*atIt)->getIdx() == idx, "bad idx");
idx++;
}
atIt = m->beginAtoms();
CHECK_INVARIANT((*(atIt + 2))->getIdx() == 2, "bad idx");
atIt = m->beginAtoms();
Mol::AtomIterator atIt2 = m->beginAtoms();
CHECK_INVARIANT(atIt == atIt2, "iterators don't compare equal");
atIt++;
CHECK_INVARIANT((*atIt)->getIdx() == 1, "bad idx");
atIt += 2;
CHECK_INVARIANT((*atIt)->getIdx() == 3, "bad idx");
atIt -= 1;
CHECK_INVARIANT((*atIt)->getIdx() == 2, "bad idx");
CHECK_INVARIANT(atIt != atIt2, "iterators don't compare different");
CHECK_INVARIANT(atIt2 < atIt, "iterator inequality failed");
CHECK_INVARIANT(atIt2 <= atIt, "iterator inequality failed");
CHECK_INVARIANT(atIt > atIt2, "iterator inequality failed");
CHECK_INVARIANT(atIt >= atIt2, "iterator inequality failed");
atIt--;
--atIt;
CHECK_INVARIANT((*atIt)->getIdx() == 0, "bad idx");
CHECK_INVARIANT(atIt == atIt2, "iterator inequality failed");
atIt++;
++atIt;
CHECK_INVARIANT((*atIt)->getIdx() == 2, "bad idx");
atIt = m->beginAtoms();
atIt = atIt + 2;
atIt = atIt - 2;
CHECK_INVARIANT((*atIt)->getIdx() == 0, "bad idx");
atIt2 = m->beginAtoms();
atIt2 += 2;
CHECK_INVARIANT(atIt2 - atIt == 2, "subtraction failed");
CHECK_INVARIANT(atIt - atIt2 == -2, "subtraction failed");
// past the end stuff
atIt2 = m->endAtoms();
atIt = m->beginAtoms() + 10;
CHECK_INVARIANT(atIt >= atIt2, "past-the-end failed");
// this is whack
atIt = m->beginAtoms();
atIt -= 10;
CHECK_INVARIANT(atIt >= atIt2, "past-the-end failed");
BOOST_LOG(rdInfoLog) << "test1 done" << endl;
};
void test2() {
string smi = "C1COC1";
Mol *m = SmilesToMol(smi);
Mol::BondIterator bondIt;
unsigned int idx = 0;
for (bondIt = m->beginBonds(); bondIt != m->endBonds(); bondIt++) {
CHECK_INVARIANT((*bondIt)->getIdx() == idx, "bad idx");
idx++;
}
bondIt = m->beginBonds();
Mol::BondIterator bondIt2 = m->beginBonds();
CHECK_INVARIANT(bondIt == bondIt2, "iterators don't compare equal");
bondIt++;
CHECK_INVARIANT((*bondIt)->getIdx() == 1, "bad idx");
bondIt++;
bondIt++;
bondIt--;
CHECK_INVARIANT((*bondIt)->getIdx() == 2, "bad idx");
CHECK_INVARIANT(bondIt != bondIt2, "iterators don't compare different");
bondIt--;
--bondIt;
CHECK_INVARIANT((*bondIt)->getIdx() == 0, "bad idx");
CHECK_INVARIANT(bondIt == bondIt2, "iterator inequality failed");
bondIt++;
++bondIt;
CHECK_INVARIANT((*bondIt)->getIdx() == 2, "bad idx");
// past the end stuff
bondIt2 = m->endBonds();
bondIt = m->beginBonds();
bondIt--;
BOOST_LOG(rdInfoLog) << "test2 done" << endl;
};
void test3() {
string smi = "C1COCCNCOCNSCC1";
unsigned char heteros[] = {2, 5, 7, 9, 10};
Mol *m = SmilesToMol(smi);
{
unsigned int nSeen = 0;
for (Mol::HeteroatomIterator heteroIt = m->beginHeteros();
heteroIt != m->endHeteros(); heteroIt++) {
CHECK_INVARIANT((*heteroIt)->getIdx() == heteros[nSeen], "bad hetero");
nSeen++;
}
}
{
unsigned int nSeen = 0;
for (Mol::HeteroatomIterator heteroIt = m->beginHeteros();
heteroIt != m->endHeteros(); ++heteroIt) {
CHECK_INVARIANT((*heteroIt)->getIdx() == heteros[nSeen], "bad hetero");
nSeen++;
}
}
{
Mol::HeteroatomIterator heteroIt = m->beginHeteros();
heteroIt++;
heteroIt++;
heteroIt--;
CHECK_INVARIANT((*heteroIt)->getIdx() == heteros[1], "bad hetero");
CHECK_INVARIANT((*--heteroIt)->getIdx() == heteros[0], "bad hetero");
CHECK_INVARIANT((*heteroIt)->getIdx() == heteros[0], "bad hetero");
}
BOOST_LOG(rdInfoLog) << "test3 done" << endl;
};
void test4() {
string smi = "C1COCCNCOCNSCC1";
unsigned int heteros1[] = {2, 7};
Mol *m = SmilesToMol(smi);
auto *q = new QueryAtom();
q->setQuery(makeAtomNumQuery(8));
{
unsigned int nSeen = 0;
for (Mol::QueryAtomIterator queryIt = m->beginQueryAtoms(q);
queryIt != m->endQueryAtoms(); queryIt++) {
CHECK_INVARIANT((*queryIt)->getIdx() == heteros1[nSeen], "bad query");
nSeen++;
}
}
{
Mol::QueryAtomIterator queryIt = m->beginQueryAtoms(q);
queryIt++;
queryIt--;
CHECK_INVARIANT((*queryIt)->getIdx() == heteros1[0], "bad query");
CHECK_INVARIANT((*++queryIt)->getIdx() == heteros1[1], "bad query");
CHECK_INVARIANT((*queryIt)->getIdx() == heteros1[1], "bad query");
}
{
Mol::QueryAtomIterator queryIt = m->beginQueryAtoms(q);
queryIt++;
queryIt--;
Mol::QueryAtomIterator queryIt2 = queryIt;
CHECK_INVARIANT((*queryIt2)->getIdx() == heteros1[0], "bad query");
CHECK_INVARIANT((*++queryIt2)->getIdx() == heteros1[1], "bad query");
CHECK_INVARIANT((*queryIt2)->getIdx() == heteros1[1], "bad query");
}
smi = "CC(C)CC(C)CC(C)CC(C)C";
unsigned int heteros2[] = {1, 4, 7, 10};
m = SmilesToMol(smi);
// m->debugMol(cout);
q->setQuery(makeAtomImplicitValenceQuery(1));
{
unsigned int nSeen = 0;
for (Mol::QueryAtomIterator queryIt = m->beginQueryAtoms(q);
queryIt != m->endQueryAtoms(); ++queryIt) {
CHECK_INVARIANT((*queryIt)->getIdx() == heteros2[nSeen], "bad query");
nSeen++;
}
}
BOOST_LOG(rdInfoLog) << "test4 done" << endl;
};
void test5() {
string smi = "CCCC";
Mol *m = SmilesToMol(smi);
Mol::BondIterator bondIt;
unsigned int idx = 0;
for (bondIt = m->beginBonds(); bondIt != m->endBonds(); bondIt++) {
CHECK_INVARIANT((*bondIt)->getIdx() == idx, "bad idx");
idx++;
}
CHECK_INVARIANT(idx == 3, "bad idx");
idx = 0;
for (bondIt = m->beginBonds(); bondIt != m->endBonds(); bondIt++) {
CHECK_INVARIANT((*bondIt)->getIdx() == idx, "bad idx");
idx++;
}
CHECK_INVARIANT(idx == 3, "bad idx");
idx = 0;
Mol::BondIterator beginP(m->beginBonds());
Mol::BondIterator endP(m->endBonds());
for (bondIt = beginP; bondIt != endP; bondIt++) {
CHECK_INVARIANT((*bondIt)->getIdx() == idx, "bad idx");
idx++;
}
CHECK_INVARIANT(idx == 3, "bad idx");
BOOST_LOG(rdInfoLog) << "test5 done" << endl;
}
#if 1
void _test6Help(const ROMol *m) {
Mol::ConstAtomIterator atIt;
unsigned int idx = 0;
for (atIt = m->beginAtoms(); atIt != m->endAtoms(); atIt++) {
CHECK_INVARIANT((*atIt)->getIdx() == idx, "bad idx");
idx++;
}
atIt = m->beginAtoms();
CHECK_INVARIANT((*(atIt + 2))->getIdx() == 2, "bad idx");
atIt = m->beginAtoms();
Mol::ConstAtomIterator atIt2 = m->beginAtoms();
CHECK_INVARIANT(atIt == atIt2, "iterators don't compare equal");
atIt++;
CHECK_INVARIANT((*atIt)->getIdx() == 1, "bad idx");
atIt += 2;
CHECK_INVARIANT((*atIt)->getIdx() == 3, "bad idx");
atIt -= 1;
CHECK_INVARIANT((*atIt)->getIdx() == 2, "bad idx");
CHECK_INVARIANT(atIt != atIt2, "iterators don't compare different");
CHECK_INVARIANT(atIt2 < atIt, "iterator inequality failed");
CHECK_INVARIANT(atIt2 <= atIt, "iterator inequality failed");
CHECK_INVARIANT(atIt > atIt2, "iterator inequality failed");
CHECK_INVARIANT(atIt >= atIt2, "iterator inequality failed");
atIt--;
--atIt;
CHECK_INVARIANT((*atIt)->getIdx() == 0, "bad idx");
CHECK_INVARIANT(atIt == atIt2, "iterator inequality failed");
atIt++;
++atIt;
CHECK_INVARIANT((*atIt)->getIdx() == 2, "bad idx");
atIt = m->beginAtoms();
atIt = atIt + 2;
atIt = atIt - 2;
CHECK_INVARIANT((*atIt)->getIdx() == 0, "bad idx");
atIt2 = m->beginAtoms();
atIt2 += 2;
CHECK_INVARIANT(atIt2 - atIt == 2, "subtraction failed");
CHECK_INVARIANT(atIt - atIt2 == -2, "subtraction failed");
// past the end stuff
atIt2 = m->endAtoms();
atIt = m->beginAtoms() + 10;
CHECK_INVARIANT(atIt >= atIt2, "past-the-end failed");
// this is whack
atIt = m->beginAtoms();
atIt -= 10;
CHECK_INVARIANT(atIt >= atIt2, "past-the-end failed");
}
void test6() {
string smi = "CCOC";
Mol *m = SmilesToMol(smi);
_test6Help(m);
BOOST_LOG(rdInfoLog) << "test6 done" << endl;
};
#endif
void test7() {
string smi = "c1ccccc1C";
#if 1
Mol *m = SmilesToMol(smi);
Mol::AromaticAtomIterator atomIt;
Mol::AromaticAtomIterator beginP(m->beginAromaticAtoms());
Mol::AromaticAtomIterator endP(m->endAromaticAtoms());
unsigned int idx = 0;
for (atomIt = beginP; atomIt != endP; atomIt++) {
TEST_ASSERT((*atomIt)->getIdx() == idx);
idx++;
}
TEST_ASSERT(idx == 6);
atomIt = beginP;
atomIt++;
atomIt--;
TEST_ASSERT((*atomIt)->getIdx() == 0);
delete m;
smi = "Cc1ccccc1";
m = SmilesToMol(smi);
beginP = m->beginAromaticAtoms();
endP = m->endAromaticAtoms();
idx = 0;
for (atomIt = beginP; atomIt != endP; atomIt++) {
TEST_ASSERT((*atomIt)->getIdx() == idx + 1);
idx++;
}
TEST_ASSERT(idx == 6);
#endif
BOOST_LOG(rdInfoLog) << "test7 done" << endl;
}
void testIssue263() {
string smi = "c1ccccc1C";
#if 1
Mol *m = SmilesToMol(smi);
Mol::AtomIterator atomIt;
unsigned int idx = 0;
for (atomIt = m->beginAtoms(); atomIt != m->endAtoms(); ++atomIt) {
TEST_ASSERT((*atomIt)->getIdx() == idx);
idx++;
}
TEST_ASSERT(idx == 7);
Mol::BondIterator bondIt;
idx = 0;
for (bondIt = m->beginBonds(); bondIt != m->endBonds(); ++bondIt) {
CHECK_INVARIANT((*bondIt)->getIdx() == idx, "bad idx");
idx++;
}
CHECK_INVARIANT(idx == 7, "bad idx");
#endif
BOOST_LOG(rdInfoLog) << "testIssue263 done" << endl;
}
void test8() {
{
string smi = "CC1CC2CC1C2";
Mol *m = SmilesToMol(smi);
auto *q = new QueryAtom();
q->setQuery(makeAtomExplicitDegreeQuery(3));
q->expandQuery(makeAtomRingBondCountQuery(2));
unsigned int nSeen = 0;
for (Mol::QueryAtomIterator queryIt = m->beginQueryAtoms(q);
queryIt != m->endQueryAtoms(); ++queryIt) {
TEST_ASSERT((*queryIt)->getIdx() == 1);
nSeen++;
}
TEST_ASSERT(nSeen == 1);
delete m;
delete q;
}
BOOST_LOG(rdInfoLog) << "test8 done" << endl;
};
int main() {
RDLog::InitLogs();
test1();
test2();
test3();
test4();
test5();
test6();
test7();
test8();
testIssue263();
return 0;
}
|