void testRecursiveSerialNumbers(){ std::cout << " ----------------- Testing serial numbers on recursive queries" << std::endl; MatchVectType matchV; std::vector< MatchVectType > matches; int n; RWMol *m,*q1,*q2; Atom *a6 = new Atom(6); Atom *a8 = new Atom(8); m = new RWMol(); m->addAtom(a6); m->addAtom(a6); m->addAtom(a8); m->addAtom(a6); m->addAtom(a6); m->addBond(1,0,Bond::SINGLE); m->addBond(1,2,Bond::SINGLE); m->addBond(1,3,Bond::SINGLE); m->addBond(2,4,Bond::SINGLE); { // this will be the recursive query q1 = new RWMol(); q1->addAtom(new QueryAtom(6),true); q1->addAtom(new QueryAtom(8),true); q1->addBond(0,1,Bond::UNSPECIFIED); // here's the main query q2 = new RWMol(); QueryAtom *qA = new QueryAtom(6); RecursiveStructureQuery *rsq = new RecursiveStructureQuery(new RWMol(*q1),1); qA->expandQuery(rsq,Queries::COMPOSITE_AND); //std::cout << "post expand: " << qA->getQuery() << std::endl; q2->addAtom(qA,true,true); //std::cout << "mol: " << q2->getAtomWithIdx(0)->getQuery() << std::endl; q2->addAtom(new QueryAtom(8),true,true); q2->addBond(0,1,Bond::UNSPECIFIED); qA = new QueryAtom(6); rsq = new RecursiveStructureQuery(new RWMol(*q1),1); qA->expandQuery(rsq,Queries::COMPOSITE_AND); q2->addAtom(qA,true,true); q2->addBond(1,2,Bond::UNSPECIFIED); bool found = SubstructMatch(*m,*q2,matchV); CHECK_INVARIANT(found,""); CHECK_INVARIANT(matchV.size()==3,""); n = SubstructMatch(*m,*q2,matches,true); TEST_ASSERT(n==1); TEST_ASSERT(matches.size()==1); TEST_ASSERT(matches[0].size()==3); delete q1; delete q2; } delete m; std::cout << "Done\n" << std::endl; }
void test8() { { string smi = "CC1CC2CC1C2"; Mol *m = SmilesToMol(smi); QueryAtom *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; };
void test1() { BOOST_LOG(rdErrorLog) << "---------------------- Test1" << std::endl; Mol qM; Mol m; Atom *a = new Atom(6); // we copy in addAtom, so this is safe m.addAtom(a); m.addAtom(a); delete a; m.addBond(0, 1, Bond::SINGLE); a = new Atom(8); m.addAtom(a); delete a; m.addBond(1, 2, Bond::DOUBLE); MolOps::sanitizeMol(m); QueryAtom *qA = new QueryAtom(6); CHECK_INVARIANT(qA->Match(m.getAtomWithIdx(0)), ""); CHECK_INVARIANT(qA->Match(m.getAtomWithIdx(1)), ""); CHECK_INVARIANT(!qA->Match(m.getAtomWithIdx(2)), ""); qA->expandQuery(makeAtomImplicitValenceQuery(3)); CHECK_INVARIANT(qA->Match(m.getAtomWithIdx(0)), ""); CHECK_INVARIANT(!qA->Match(m.getAtomWithIdx(1)), ""); CHECK_INVARIANT(!qA->Match(m.getAtomWithIdx(2)), ""); qM.addAtom(qA); delete qA; qA = new QueryAtom(6); qA->expandQuery(makeAtomNumQuery(8), Queries::COMPOSITE_OR); qM.addAtom(qA); delete qA; qM.addAtom(new QueryAtom(8), true, true); // Atom::ATOM_SPTR qA(new QueryAtom(6)); QueryBond *qB; qB = new QueryBond(Bond::UNSPECIFIED); qB->setOwningMol(qM); qB->setBeginAtomIdx(0); qB->setEndAtomIdx(1); CHECK_INVARIANT(qB->Match(m.getBondWithIdx(0)), ""); CHECK_INVARIANT(qB->Match(m.getBondWithIdx(1)), ""); qM.addBond(qB, true); qB = new QueryBond(Bond::DOUBLE); qB->setOwningMol(qM); qB->setBeginAtomIdx(1); qB->setEndAtomIdx(2); qM.addBond(qB, true); CHECK_INVARIANT(qM.getAtomWithIdx(0)->Match(m.getAtomWithIdx(0)), ""); CHECK_INVARIANT(!qM.getAtomWithIdx(0)->Match(m.getAtomWithIdx(1)), ""); CHECK_INVARIANT(!qM.getAtomWithIdx(0)->Match(m.getAtomWithIdx(2)), ""); CHECK_INVARIANT(qM.getAtomWithIdx(1)->Match(m.getAtomWithIdx(0)), ""); CHECK_INVARIANT(qM.getAtomWithIdx(1)->Match(m.getAtomWithIdx(1)), ""); CHECK_INVARIANT(qM.getAtomWithIdx(1)->Match(m.getAtomWithIdx(2)), ""); CHECK_INVARIANT(!qM.getAtomWithIdx(2)->Match(m.getAtomWithIdx(0)), ""); CHECK_INVARIANT(!qM.getAtomWithIdx(2)->Match(m.getAtomWithIdx(1)), ""); CHECK_INVARIANT(qM.getAtomWithIdx(2)->Match(m.getAtomWithIdx(2)), ""); CHECK_INVARIANT(qM.getBondWithIdx(0)->Match(m.getBondWithIdx(0)), ""); CHECK_INVARIANT(qM.getBondWithIdx(0)->Match(m.getBondWithIdx(1)), ""); CHECK_INVARIANT(!qM.getBondWithIdx(1)->Match(m.getBondWithIdx(0)), ""); CHECK_INVARIANT(qM.getBondWithIdx(1)->Match(m.getBondWithIdx(1)), ""); BOOST_LOG(rdErrorLog) << "Done!" << std::endl; }