void testIssue294() { BOOST_LOG(rdInfoLog) << "---- Test Issue294\n Watch memory usage." << std::endl; 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); FragCatalog fcat(fparams); FragCatGenerator catGen; std::vector<ROMol *> mols; ROMol *m = suppl.next(); while (m) { mols.push_back(m); catGen.addFragsFromMol(*m, &fcat); try { m = suppl.next(); } catch (FileParseException &) { m = nullptr; } } int nents = fcat.getNumEntries(); TEST_ASSERT(nents == 21); FragFPGenerator fpGen; m = mols[0]; for (unsigned int i = 0; i < 200; i++) { for (std::vector<ROMol *>::const_iterator mi = mols.begin(); mi != mols.end(); mi++) { ExplicitBitVect *fp = fpGen.getFPForMol(*(*mi), fcat); delete fp; } } BOOST_LOG(rdInfoLog) << "---- Done" << std::endl; }
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; }