void testHasPropWithValueMatch() { { QueryAtom qA; qA.setQuery(makePropQuery<Atom, int>("foo", 2)); Atom a1(6); TEST_ASSERT(!qA.Match(&a1)); a1.setProp<int>("foo", 1); TEST_ASSERT(!qA.Match(&a1)); a1.setProp<int>("foo", 2); TEST_ASSERT(qA.Match(&a1)); a1.clearProp("foo"); a1.setProp<double>("foo", 2); TEST_ASSERT(!qA.Match(&a1)); } { QueryAtom qA; qA.setQuery(makePropQuery<Atom, std::string>("foo", "bar")); Atom a1(6); TEST_ASSERT(!qA.Match(&a1)); a1.setProp<std::string>("foo", "bar"); TEST_ASSERT(qA.Match(&a1)); } { QueryBond qA; qA.setQuery(makePropQuery<Bond, int>("foo", 2)); Bond a1; TEST_ASSERT(!qA.Match(&a1)); a1.setProp<int>("foo", 1); TEST_ASSERT(!qA.Match(&a1)); a1.setProp<int>("foo", 2); TEST_ASSERT(qA.Match(&a1)); a1.clearProp("foo"); a1.setProp<double>("foo", 2); TEST_ASSERT(!qA.Match(&a1)); } { QueryBond qA; qA.setQuery(makePropQuery<Bond, std::string>("foo", "bar")); Bond a1; TEST_ASSERT(!qA.Match(&a1)); a1.setProp<std::string>("foo", "bar"); TEST_ASSERT(qA.Match(&a1)); } }
void test4() { string smi = "C1COCCNCOCNSCC1"; unsigned int heteros1[] = {2, 7}; Mol *m = SmilesToMol(smi); QueryAtom *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 testHasPropMatch() { QueryAtom qA; qA.setQuery(makeHasPropQuery<Atom>("foo")); Atom a1(6); TEST_ASSERT(!qA.Match(&a1)); a1.setProp<int>("foo", 1); TEST_ASSERT(qA.Match(&a1)); }
void testQualifiedQueries() { BOOST_LOG(rdErrorLog) << "---------------------- Test queries using qualifiers instead of ==" << std::endl; RWMol *m = SmilesToMol("CNO"); { QueryAtom qA; qA.setQuery(makeAtomNumQuery<ATOM_GREATER_QUERY>(7, "test")); TEST_ASSERT(qA.Match(m->getAtomWithIdx(0))); TEST_ASSERT(!qA.Match(m->getAtomWithIdx(1))); TEST_ASSERT(!qA.Match(m->getAtomWithIdx(2))); } { QueryAtom qA; qA.setQuery(makeAtomNumQuery<ATOM_GREATEREQUAL_QUERY>(7, "test")); TEST_ASSERT(qA.Match(m->getAtomWithIdx(0))); TEST_ASSERT(qA.Match(m->getAtomWithIdx(1))); TEST_ASSERT(!qA.Match(m->getAtomWithIdx(2))); } { QueryAtom qA; qA.setQuery(makeAtomNumQuery<ATOM_LESS_QUERY>(7, "test")); TEST_ASSERT(!qA.Match(m->getAtomWithIdx(0))); TEST_ASSERT(!qA.Match(m->getAtomWithIdx(1))); TEST_ASSERT(qA.Match(m->getAtomWithIdx(2))); } { QueryAtom qA; qA.setQuery(makeAtomNumQuery<ATOM_LESSEQUAL_QUERY>(7, "test")); TEST_ASSERT(!qA.Match(m->getAtomWithIdx(0))); TEST_ASSERT(qA.Match(m->getAtomWithIdx(1))); TEST_ASSERT(qA.Match(m->getAtomWithIdx(2))); } delete m; BOOST_LOG(rdErrorLog) << "Done!" << std::endl; }
void test5QueryRoot(){ std::cout << " ----------------- Test 5 QueryRoot" << std::endl; MatchVectType matchV; std::vector< MatchVectType > matches; int n; RWMol *m,*q1,*q2; Atom *a6 = new Atom(6); Atom *a8 = new Atom(8); // CC(OC)C m = new RWMol(); m->addAtom(a6); m->addAtom(a6); m->addAtom(a8); m->addAtom(a6); m->addAtom(a6); m->addBond(0,1,Bond::SINGLE); m->addBond(1,2,Bond::SINGLE); m->addBond(1,4,Bond::SINGLE); m->addBond(2,3,Bond::SINGLE); // this will be the recursive query q1 = new RWMol(); q1->addAtom(new QueryAtom(8),true); q1->addAtom(new QueryAtom(6),true); q1->addBond(0,1,Bond::UNSPECIFIED); q1->setProp("_queryRootAtom",1); // here's the main query q2 = new RWMol(); QueryAtom *qA = new QueryAtom(); RecursiveStructureQuery *rsq = new RecursiveStructureQuery(q1); qA->setQuery(rsq); q2->addAtom(qA,true,true); q2->addAtom(new QueryAtom(6),true,true); q2->addBond(0,1,Bond::UNSPECIFIED); bool found = SubstructMatch(*m,*q2,matchV); CHECK_INVARIANT(found,""); CHECK_INVARIANT(matchV.size()==2,""); n = SubstructMatch(*m,*q2,matches,true); CHECK_INVARIANT(n==2,""); CHECK_INVARIANT(matches[0].size()==2,""); 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 testHasPropWithDoubleValueMatch() { { QueryAtom qA; qA.setQuery(makePropQuery<Atom, double>("foo", 2)); Atom a1(6); TEST_ASSERT(!qA.Match(&a1)); a1.setProp<double>("foo", 1); TEST_ASSERT(!qA.Match(&a1)); a1.setProp<double>("foo", 2); TEST_ASSERT(qA.Match(&a1)); } { QueryBond qA; qA.setQuery(makePropQuery<Bond, double>("foo", 2)); Bond a1; TEST_ASSERT(!qA.Match(&a1)); a1.setProp<double>("foo", 1); TEST_ASSERT(!qA.Match(&a1)); a1.setProp<double>("foo", 2); TEST_ASSERT(qA.Match(&a1)); } }
void testExtraAtomQueries() { BOOST_LOG(rdErrorLog) << "---------------------- Test extra atom queries" << std::endl; { // radicals QueryAtom qA; qA.setQuery(makeAtomNumRadicalElectronsQuery(1)); Atom a1(6); TEST_ASSERT(!qA.Match(&a1)); a1.setNumRadicalElectrons(1); TEST_ASSERT(qA.Match(&a1)); a1.setNumRadicalElectrons(2); TEST_ASSERT(!qA.Match(&a1)); qA.getQuery()->setNegation(true); TEST_ASSERT(qA.Match(&a1)); a1.setNumRadicalElectrons(0); TEST_ASSERT(qA.Match(&a1)); a1.setNumRadicalElectrons(1); TEST_ASSERT(!qA.Match(&a1)); } { // chiral tags QueryAtom qA; qA.setQuery(makeAtomHasChiralTagQuery()); Atom a1(6); TEST_ASSERT(!qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CW); TEST_ASSERT(qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CCW); TEST_ASSERT(qA.Match(&a1)); a1.setChiralTag(Atom::CHI_OTHER); TEST_ASSERT(qA.Match(&a1)); qA.getQuery()->setNegation(true); a1.setChiralTag(Atom::CHI_UNSPECIFIED); TEST_ASSERT(qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CW); TEST_ASSERT(!qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CCW); TEST_ASSERT(!qA.Match(&a1)); a1.setChiralTag(Atom::CHI_OTHER); TEST_ASSERT(!qA.Match(&a1)); } { // missing chiral tags QueryAtom qA; qA.setQuery(makeAtomMissingChiralTagQuery()); Atom a1(6); TEST_ASSERT(!qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CW); TEST_ASSERT(!qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CCW); TEST_ASSERT(!qA.Match(&a1)); a1.setChiralTag(Atom::CHI_OTHER); TEST_ASSERT(!qA.Match(&a1)); a1.setChiralTag(Atom::CHI_UNSPECIFIED); a1.setProp(common_properties::_ChiralityPossible, 1); TEST_ASSERT(qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CW); TEST_ASSERT(!qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CCW); TEST_ASSERT(!qA.Match(&a1)); a1.setChiralTag(Atom::CHI_OTHER); TEST_ASSERT(!qA.Match(&a1)); qA.getQuery()->setNegation(true); a1.clearProp(common_properties::_ChiralityPossible); a1.setChiralTag(Atom::CHI_UNSPECIFIED); TEST_ASSERT(qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CW); TEST_ASSERT(qA.Match(&a1)); a1.setChiralTag(Atom::CHI_TETRAHEDRAL_CCW); TEST_ASSERT(qA.Match(&a1)); a1.setChiralTag(Atom::CHI_OTHER); TEST_ASSERT(qA.Match(&a1)); a1.setChiralTag(Atom::CHI_UNSPECIFIED); a1.setProp(common_properties::_ChiralityPossible, 1); TEST_ASSERT(!qA.Match(&a1)); } BOOST_LOG(rdErrorLog) << "Done!" << std::endl; }
QueryAtom *HasPropQueryAtom(const std::string &propname, bool negate) { QueryAtom *res = new QueryAtom(); res->setQuery(makeHasPropQuery<Atom>(propname)); if (negate) res->getQuery()->setNegation(true); return res; }