void test2() { BOOST_LOG(rdErrorLog) << "---------------------- Test2" << 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); m.addAtom(a); delete a; m.addBond(0, 1, Bond::TRIPLE); m.addBond(1, 2, Bond::SINGLE); a = new Atom(8); m.addAtom(a); delete a; m.addBond(2, 3, Bond::DOUBLE); MolOps::sanitizeMol(m); QueryBond *qB; qB = new QueryBond(Bond::SINGLE); CHECK_INVARIANT(!qB->Match(m.getBondWithIdx(0)), ""); CHECK_INVARIANT(qB->Match(m.getBondWithIdx(1)), ""); CHECK_INVARIANT(!qB->Match(m.getBondWithIdx(2)), ""); BOND_EQUALS_QUERY *newQ = makeBondOrderEqualsQuery(Bond::DOUBLE); qB->expandQuery(newQ, Queries::COMPOSITE_OR); CHECK_INVARIANT(!qB->Match(m.getBondWithIdx(0)), ""); CHECK_INVARIANT(qB->Match(m.getBondWithIdx(1)), ""); CHECK_INVARIANT(qB->Match(m.getBondWithIdx(2)), ""); BOOST_LOG(rdErrorLog) << "Done!" << std::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 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 testExtraBondQueries() { BOOST_LOG(rdErrorLog) << "---------------------- Test extra bond queries" << std::endl; { // stereo QueryBond qB; qB.setQuery(makeBondHasStereoQuery()); Bond b1(Bond::DOUBLE); TEST_ASSERT(!qB.Match(&b1)); b1.setStereo(Bond::STEREOE); TEST_ASSERT(qB.Match(&b1)); b1.setStereo(Bond::STEREOANY); TEST_ASSERT(qB.Match(&b1)); qB.getQuery()->setNegation(true); b1.setStereo(Bond::STEREONONE); TEST_ASSERT(qB.Match(&b1)); b1.setStereo(Bond::STEREOE); TEST_ASSERT(!qB.Match(&b1)); b1.setStereo(Bond::STEREOANY); TEST_ASSERT(!qB.Match(&b1)); } BOOST_LOG(rdErrorLog) << "Done!" << std::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; }