Files
rdkit/Code/DistGeom/testDistGeom.cpp
Ric a6b26253ff Fix (most of) mem problems (#2123)
* 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
2018-10-29 14:33:26 +00:00

137 lines
4.5 KiB
C++

// $Id$
//
// Copyright (C) 2004-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 "BoundsMatrix.h"
#include "TriangleSmooth.h"
#include <iostream>
#include <boost/smart_ptr.hpp>
#include <math.h>
#include <Numerics/SymmMatrix.h>
#include "DistGeomUtils.h"
#include <RDGeneral/utils.h>
using namespace DistGeom;
using namespace RDNumeric;
void test1() {
// test triangle smoothing
unsigned int npt = 5;
double x = sqrt(3.0);
auto *mmat = new BoundsMatrix(npt);
mmat->setUpperBound(0, 1, 1.0);
mmat->setLowerBound(0, 1, 1.0);
mmat->setUpperBound(0, 2, x);
mmat->setLowerBound(0, 2, x);
mmat->setUpperBound(0, 3, 10.0);
mmat->setLowerBound(0, 3, 0.0);
mmat->setUpperBound(0, 4, 10.0);
mmat->setLowerBound(0, 4, 0.0);
mmat->setUpperBound(1, 2, 1.0);
mmat->setLowerBound(1, 2, 1.0);
mmat->setUpperBound(1, 3, x);
mmat->setLowerBound(1, 3, x);
mmat->setUpperBound(1, 4, 10.0);
mmat->setLowerBound(1, 4, 0.0);
mmat->setUpperBound(2, 3, 1.0);
mmat->setLowerBound(2, 3, 1.0);
mmat->setUpperBound(2, 4, x);
mmat->setLowerBound(2, 4, x);
mmat->setUpperBound(3, 4, 1.0);
mmat->setLowerBound(3, 4, 1.0);
BoundsMatPtr mptr(mmat);
triangleSmoothBounds(mptr);
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(0, 1), 1.0, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(0, 1), 1.0, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(0, 2), 1.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(0, 2), 1.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(0, 3), 2.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(0, 3), 0.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(0, 4), 3.464, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(0, 4), 0.0, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(1, 2), 1.0, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(1, 2), 1.0, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(1, 3), 1.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(1, 3), 1.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(1, 4), 2.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(1, 4), 0.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(2, 3), 1.0, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(2, 3), 1.0, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(2, 4), 1.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(2, 4), 1.732, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getUpperBound(3, 4), 1.0, 0.001), "");
CHECK_INVARIANT(RDKit::feq(mmat->getLowerBound(3, 4), 1.0, 0.001), "");
DoubleSymmMatrix dmat(npt, 0.0);
RDKit::rng_type generator(42u);
generator.seed(100);
RDKit::uniform_double distrib(0, 1.0);
RDKit::double_source_type rng(generator, distrib);
pickRandomDistMat(*mmat, dmat, rng);
double sumElem = 0.0;
for (unsigned int i = 0; i < dmat.getDataSize(); i++) {
sumElem += dmat.getData()[i];
}
CHECK_INVARIANT(RDKit::feq(sumElem, 14.3079, 0.001), "");
}
void testIssue216() {
RDNumeric::DoubleSymmMatrix dmat(4);
dmat.setVal(0, 0, 0.0);
dmat.setVal(0, 1, 1.0);
dmat.setVal(0, 2, 1.0);
dmat.setVal(0, 3, 1.0);
dmat.setVal(1, 1, 0.0);
dmat.setVal(1, 2, 1.0);
dmat.setVal(1, 3, 1.0);
dmat.setVal(2, 2, 0.0);
dmat.setVal(2, 3, 1.0);
dmat.setVal(3, 3, 0.0);
std::cout << dmat;
RDGeom::PointPtrVect pos;
for (int i = 0; i < 4; i++) {
auto *pt = new RDGeom::Point3D();
pos.push_back(pt);
}
bool gotCoords = DistGeom::computeInitialCoords(dmat, pos);
CHECK_INVARIANT(gotCoords, "");
for (int i = 1; i < 4; i++) {
RDGeom::Point3D pti = *(RDGeom::Point3D *)pos[i];
for (int j = 0; j < i; j++) {
RDGeom::Point3D ptj = *(RDGeom::Point3D *)pos[j];
ptj -= pti;
CHECK_INVARIANT(RDKit::feq(ptj.length(), 1.0, 0.02), "");
}
}
for (int i = 0; i < 4; i++) {
delete pos[i];
}
}
int main() {
std::cout << "***********************************************************\n";
std::cout << " test1 \n";
test1();
std::cout << "***********************************************************\n";
std::cout << " testIssue216 \n";
testIssue216();
std::cout
<< "***********************************************************\n\n";
return 0;
}