mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-04 21:54:27 +08:00
* do not use new on loggers * del pointers in testDistGeom * Update Dict hasNonPOD status on bulk update * delete new Dicts in memtest1.cpp * fixes in MolSuppliers and testFMCS * PeriodicTable singleton as unique_ptr * fix EEM_arrays leak * fix leaks in testPBF * fix ParamCollection leak in test UFF * fix leaks in MMFF * clear prop dict before read in in pickler * fix leaks in testFreeSASA * fix leaks in test3D * modernize Dict.h & SmilesParse.cpp * fix leaks in testQuery * fix leaks in testCrystalFF * fix leaks in cxsmilesTest * fix leaks in Catalog & mol cat test * fix leaks in ShapeUtils & tests * fix leaks in testSubgraphs1 * fix leaks testFingerprintGenerators * fix leaks in Catalog/FilterCatalog * fix leaks in graphmolqueryTest * these changes reduce bison parse leaks * fixed leaks in testChirality.cpp * fix leaks + 2 tests in testMolWriter * fix 4m leaks in substructLibraryTest * small improvements to molTautomerTest; still leaks * fix leaks in testRGroupDecomp * fix leaks in test; parser still leaks * fix leaks in itertest * fix 4m leaks in testDepictor * fixes in smatest; still leaking due to parser * fixes in testSLNParse; still leaking due to parser * flex/bison: always add atoms with ownership; smarts error cleanup * fix leaks in testReaction * fix leaks in testSubstructMatch * fix leaks in resMolSupplierTest * fix leaks in testChemTransforms + bug in ChemTransforms * fix leaks in testPickler * fix leaks in testMolTransform * fix leaks in testFragCatalog * fix leak in testSLNParse. Still leaks due to Smiles * fixed most leaks in testMolSupplier * pre bison fix * fix some atom & bond parse problems; others still fail * bison smiles & smarts, atoms & bonds more or less fixed * fix leaks in molopstest.cpp * fix leaks in testFingerprints, MACCS.cpp & AtomPairs.cpp * fix leaks in moldraw2Dtest1 * fix leaks in testDescriptors * fix leaks in testInchi * fix leaks in testUFFForceFieldHelpers * fix leaks in hanoiTest & new_canon.h * fix leaks in testMMFFForceField * fix leaks in graphmolTest1 * fix leaks in testMMFFForceFieldHelpers * fix leaks in testDistGeomHelpers * fix leaks in testMolAlign * initialize occupancy & temp facto with default values * fix leak in TautomerTransform * updated suppressions * fix testStructChecker * fix logging & py tests * fix TautomerTransform class/struct issue * remove misplaced delete in testSLNParse * deinit in testAvalonLib1 * fix Avalon-triggered(?) bug in StructChecker/Pattern.cpp * fix random testMolWriter/Supplier fails - diversify output file names to avoid clashing. - unify Writers close/destruct behavior. - flushing/closing in tests. * use reset in FFs Params.cpp * comments on testMMFFForceField * unrequired 'if's added to mol suppliers * correct cast in FilterCatalog.h * use unique_ptr in MACCS Patterns * remove unrequred if in new_canon * update & move suppressions
257 lines
7.9 KiB
C++
257 lines
7.9 KiB
C++
// $Id$
|
|
//
|
|
// Copyright (C) 2003-2006 Rational Discovery LLC
|
|
//
|
|
// @@ All Rights Reserved @@
|
|
// This file is part of the RDKit.
|
|
// The contents are covered by the terms of the BSD license
|
|
// which is included in the file license.txt, found at the root
|
|
// of the RDKit source tree.
|
|
//
|
|
#include <RDGeneral/test.h>
|
|
#include <GraphMol/RDKitBase.h>
|
|
#include <GraphMol/RDKitQueries.h>
|
|
#include <RDGeneral/RDLog.h>
|
|
#include <GraphMol/SmilesParse/SmilesParse.h>
|
|
#include <GraphMol/SmilesParse/SmilesWrite.h>
|
|
|
|
#include "FragCatGenerator.h"
|
|
|
|
#include "FragCatalogEntry.h"
|
|
#include "FragCatParams.h"
|
|
#include "FragCatalogUtils.h"
|
|
#include "FragFPGenerator.h"
|
|
#include <stdlib.h>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
|
|
#include <GraphMol/Subgraphs/SubgraphUtils.h>
|
|
#include <GraphMol/Subgraphs/Subgraphs.h>
|
|
#include <GraphMol/FileParsers/MolSupplier.h>
|
|
#include <RDGeneral/types.h>
|
|
#include <RDGeneral/FileParseException.h>
|
|
#include <DataStructs/BitVects.h>
|
|
|
|
using namespace RDKit;
|
|
|
|
void testMols(std::vector<std::unique_ptr<ROMol>> &mols, FragFPGenerator &fpGen,
|
|
FragCatalog &fcat) {
|
|
int nDone = 0;
|
|
for (auto&& mi : mols) {
|
|
ExplicitBitVect *fp = fpGen.getFPForMol(*mi, fcat);
|
|
switch (nDone) {
|
|
case 0:
|
|
TEST_ASSERT(fp->getNumOnBits() == 3);
|
|
TEST_ASSERT((*fp)[0]);
|
|
TEST_ASSERT((*fp)[1]);
|
|
TEST_ASSERT((*fp)[2]);
|
|
break;
|
|
case 1:
|
|
TEST_ASSERT(fp->getNumOnBits() == 2);
|
|
TEST_ASSERT((*fp)[1]);
|
|
TEST_ASSERT((*fp)[3]);
|
|
break;
|
|
case 2:
|
|
TEST_ASSERT(fp->getNumOnBits() == 3);
|
|
TEST_ASSERT((*fp)[1]);
|
|
TEST_ASSERT((*fp)[4]);
|
|
TEST_ASSERT((*fp)[5]);
|
|
break;
|
|
case 3:
|
|
TEST_ASSERT(fp->getNumOnBits() == 3);
|
|
TEST_ASSERT((*fp)[1]);
|
|
TEST_ASSERT((*fp)[6]);
|
|
TEST_ASSERT((*fp)[7]);
|
|
break;
|
|
case 4:
|
|
TEST_ASSERT(fp->getNumOnBits() == 2);
|
|
TEST_ASSERT((*fp)[0]);
|
|
TEST_ASSERT((*fp)[8]);
|
|
break;
|
|
case 5:
|
|
TEST_ASSERT(fp->getNumOnBits() == 3);
|
|
TEST_ASSERT((*fp)[0]);
|
|
TEST_ASSERT((*fp)[6]);
|
|
TEST_ASSERT((*fp)[9]);
|
|
break;
|
|
case 6:
|
|
TEST_ASSERT(fp->getNumOnBits() == 5);
|
|
TEST_ASSERT((*fp)[0]);
|
|
TEST_ASSERT((*fp)[1]);
|
|
TEST_ASSERT((*fp)[2]);
|
|
TEST_ASSERT((*fp)[3]);
|
|
TEST_ASSERT((*fp)[10]);
|
|
break;
|
|
}
|
|
delete fp;
|
|
nDone += 1;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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<std::unique_ptr<ROMol>> mols;
|
|
ROMol *m = suppl.next();
|
|
while (m) {
|
|
mols.push_back(std::unique_ptr<ROMol>(m));
|
|
catGen.addFragsFromMol(*m, &fcat);
|
|
try {
|
|
m = suppl.next();
|
|
} catch (FileParseException &) {
|
|
m = nullptr;
|
|
}
|
|
}
|
|
int nents = fcat.getNumEntries();
|
|
TEST_ASSERT(nents == 21);
|
|
FragFPGenerator fpGen;
|
|
|
|
for (unsigned int i = 0; i < 200; i++) {
|
|
for (auto&& mi : mols) {
|
|
ExplicitBitVect *fp = fpGen.getFPForMol(*mi, fcat);
|
|
delete fp;
|
|
}
|
|
}
|
|
delete fparams;
|
|
BOOST_LOG(rdInfoLog) << "---- Done" << std::endl;
|
|
}
|
|
|
|
int main() {
|
|
RDLog::InitLogs();
|
|
test1();
|
|
testIssue294();
|
|
return 0;
|
|
}
|