Exemple #1
0
FragCatParams::FragCatParams(const FragCatParams &other) {
  d_funcGroups.clear();
  // copy consttructor
  d_typeStr = other.getTypeStr();
  d_lowerFragLen = other.getLowerFragLength();
  d_upperFragLen = other.getUpperFragLength();
  d_tolerance = other.getTolerance();

  // std::cout << "In param copier\n";
  const MOL_SPTR_VECT &ofgrps = other.getFuncGroups();
  // const MOL_PTR_VECT &ofgrps = other.getFuncGroups();
  MOL_SPTR_VECT::const_iterator fgi;
  // MOL_PTR_VECT_CI fgi;
  for (fgi = ofgrps.begin(); fgi != ofgrps.end(); fgi++) {
    ROMol *nmol = new ROMol(*(fgi->get()));
    // ROMol *nmol = new ROMol(*(*fgi));
    d_funcGroups.push_back(ROMOL_SPTR(nmol));
    // d_funcGroups.push_back(nmol);
  }
}
Exemple #2
0
void test1() {
  std::string rdbase = getenv("RDBASE");
  std::string fname = rdbase + "/Code/GraphMol/FragCatalog/test_data/mols.smi";
  std::string fgrpFile =
      rdbase + "/Code/GraphMol/FragCatalog/test_data/funcGroups.txt";
  SmilesMolSupplier suppl(fname, " ", 0, 1, false);

  auto *fparams = new FragCatParams(1, 6, fgrpFile, 1.0e-8);
  TEST_ASSERT(fparams->getNumFuncGroups() == 15);
  FragCatalog fcat(fparams);
  FragCatGenerator catGen;

  std::vector<std::unique_ptr<ROMol>> mols;
  unsigned int nDone = 0;
  ROMol *m = suppl.next();
  while (m) {
    mols.push_back(std::unique_ptr<ROMol>(m));
    nDone += 1;
    catGen.addFragsFromMol(*m, &fcat);
    try {
      m = suppl.next();
    } catch (FileParseException &) {
      m = nullptr;
    }
  }
  TEST_ASSERT(mols.size() == 16);
  TEST_ASSERT(nDone == 16);
  int nents = fcat.getNumEntries();
  std::cerr << " " << nents << std::endl;
  TEST_ASSERT(nents == 21);
  FragFPGenerator fpGen;

  BOOST_LOG(rdInfoLog) << "----- Test 1" << std::endl;
  testMols(mols, fpGen, fcat);
  BOOST_LOG(rdInfoLog) << "---- Done" << std::endl;

  //----------------------------------------------------------
  //  SERIALIZATION TESTS
  //----------------------------------------------------------

  // make sure we can pickle and unpickle parameter objects:
  FragCatParams newParams;
  std::string pickle = fparams->Serialize();
  newParams.initFromString(pickle);
  TEST_ASSERT(newParams.getLowerFragLength() == fparams->getLowerFragLength());
  TEST_ASSERT(newParams.getUpperFragLength() == fparams->getUpperFragLength());
  TEST_ASSERT(newParams.getTolerance() == fparams->getTolerance());
  TEST_ASSERT(newParams.getNumFuncGroups() == fparams->getNumFuncGroups());

  // make sure we can pickle and unpickle catalog entries:
  const FragCatalogEntry *fpEntry = fcat.getEntryWithIdx(0);
  auto *fpEntry2 = new FragCatalogEntry();
  fpEntry2->initFromString(fpEntry->Serialize());
  TEST_ASSERT(fpEntry->getDescription() == fpEntry2->getDescription());
  TEST_ASSERT(fpEntry->getOrder() == fpEntry2->getOrder());
  TEST_ASSERT(fpEntry->getBitId() == fpEntry2->getBitId());
  TEST_ASSERT(fpEntry2->match(fpEntry, 1e-8));
  TEST_ASSERT(fpEntry->match(fpEntry2, 1e-8));
  delete fpEntry2;

  // test catalogs' initFromString:
  FragCatalog fcat2;
  fcat2.initFromString(fcat.Serialize());
  TEST_ASSERT(fcat2.getNumEntries() == fcat.getNumEntries());
  BOOST_LOG(rdInfoLog) << "----- Test 2" << std::endl;
  testMols(mols, fpGen, fcat2);
  BOOST_LOG(rdInfoLog) << "---- Done" << std::endl;

  // and the pickle ctor:
  FragCatalog *fcat3 = new FragCatalog(fcat.Serialize());
  TEST_ASSERT(fcat3->getNumEntries() == fcat.getNumEntries());
  BOOST_LOG(rdInfoLog) << "----- Test 3" << std::endl;
  testMols(mols, fpGen, *fcat3);
  BOOST_LOG(rdInfoLog) << "---- Done" << std::endl;

  //----------------------------------------------------------
  // test issue 115
  //----------------------------------------------------------
  BOOST_LOG(rdInfoLog) << "----- Test Issue 115" << std::endl;
  delete fparams;
  fparams = new FragCatParams(3, 3, fgrpFile, 1.0e-8);
  TEST_ASSERT(fparams->getNumFuncGroups() == 15);
  delete fcat3;
  fcat3 = new FragCatalog(fparams);
  suppl.reset();
  nDone = 0;
  while (!suppl.atEnd()) {
    nDone++;
    ROMol *m = suppl.next();
    catGen.addFragsFromMol(*m, fcat3);
    delete m;
  }
  TEST_ASSERT(nDone == suppl.length());
  TEST_ASSERT(fcat3->getNumEntries() == 21);
  TEST_ASSERT(fcat3->getFPLength() == 10);
  for (unsigned int i = 0; i < fcat3->getFPLength(); i++) {
    TEST_ASSERT(fcat3->getEntryWithBitId(i)->getOrder() == 3);
  }
  BOOST_LOG(rdInfoLog) << "---- Done" << std::endl;

  //----------------------------------------------------------
  // test issue 117
  //----------------------------------------------------------
  BOOST_LOG(rdInfoLog) << "----- Test Issue 117" << std::endl;
  delete fparams;
  fparams = new FragCatParams(1, 2, fgrpFile, 1.0e-8);
  delete fcat3;
  fcat3 = new FragCatalog(fparams);
  ROMol *tmpMol = SmilesToMol("OC(N)CO");
  TEST_ASSERT(tmpMol);
  catGen.addFragsFromMol(*tmpMol, fcat3);
  TEST_ASSERT(fcat3->getNumEntries() == 1);
  // std::cout << fcat3->getEntryWithBitId(0)->getDescription() << std::endl;
  TEST_ASSERT(fcat3->getEntryWithBitId(0)->getDescription() ==
              "C(<-O>)<-N>C<-O>");
  BOOST_LOG(rdInfoLog) << "---- Done" << std::endl;

  delete tmpMol;
  delete fparams;
  delete fcat3;
}