Exemple #1
0
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));
}
Exemple #2
0
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));
  }
}
Exemple #3
0
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));
  }
}
Exemple #4
0
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;
}
Exemple #5
0
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;
}
Exemple #6
0
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;
}