[c4d4df] | 1 | /*
|
---|
| 2 | * AnalysisCorrelationToSurfaceUnitTest.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Oct 13, 2009
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[bf3817] | 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[c4d4df] | 13 | using namespace std;
|
---|
| 14 |
|
---|
| 15 | #include <cppunit/CompilerOutputter.h>
|
---|
| 16 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 17 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 18 |
|
---|
[49e1ae] | 19 | #include <cstring>
|
---|
| 20 |
|
---|
[c4d4df] | 21 | #include "analysis_correlation.hpp"
|
---|
| 22 | #include "AnalysisCorrelationToSurfaceUnitTest.hpp"
|
---|
| 23 |
|
---|
[e65de8] | 24 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
| 25 |
|
---|
[c4d4df] | 26 | #include "atom.hpp"
|
---|
| 27 | #include "boundary.hpp"
|
---|
| 28 | #include "element.hpp"
|
---|
| 29 | #include "molecule.hpp"
|
---|
| 30 | #include "linkedcell.hpp"
|
---|
| 31 | #include "periodentafel.hpp"
|
---|
| 32 | #include "tesselation.hpp"
|
---|
[e6fdbe] | 33 | #include "World.hpp"
|
---|
[8d2772] | 34 | #include "Helpers/Assert.hpp"
|
---|
[c4d4df] | 35 |
|
---|
[5be0eb] | 36 | #include "Helpers/Assert.hpp"
|
---|
| 37 |
|
---|
[9b6b2f] | 38 | #ifdef HAVE_TESTRUNNER
|
---|
| 39 | #include "UnitTestMain.hpp"
|
---|
| 40 | #endif /*HAVE_TESTRUNNER*/
|
---|
[c4d4df] | 41 |
|
---|
| 42 | /********************************************** Test classes **************************************/
|
---|
| 43 |
|
---|
| 44 | // Registers the fixture into the 'registry'
|
---|
| 45 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest );
|
---|
| 46 |
|
---|
| 47 | void AnalysisCorrelationToSurfaceUnitTest::setUp()
|
---|
| 48 | {
|
---|
[e0b6fd] | 49 | ASSERT_DO(Assert::Throw);
|
---|
[5be0eb] | 50 |
|
---|
[d74077] | 51 | setVerbosity(5);
|
---|
| 52 |
|
---|
[c4d4df] | 53 | atom *Walker = NULL;
|
---|
| 54 |
|
---|
| 55 | // init private all pointers to zero
|
---|
[8cbb97] | 56 | TestSurfaceMolecule = NULL;
|
---|
[c4d4df] | 57 | surfacemap = NULL;
|
---|
| 58 | binmap = NULL;
|
---|
| 59 | Surface = NULL;
|
---|
| 60 | LC = NULL;
|
---|
| 61 |
|
---|
[c78d44] | 62 | // prepare element list
|
---|
[4eb4fe] | 63 | hydrogen = World::getInstance().getPeriode()->FindElement(1);
|
---|
[c78d44] | 64 | CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
|
---|
| 65 | elements.clear();
|
---|
| 66 |
|
---|
| 67 | // construct molecule (tetraeder of hydrogens) base
|
---|
[5f612ee] | 68 | TestSurfaceMolecule = World::getInstance().createMolecule();
|
---|
[a7b761b] | 69 |
|
---|
[23b547] | 70 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 71 | Walker->setType(hydrogen);
|
---|
| 72 | Walker->setPosition(Vector(1., 0., 1. ));
|
---|
[8db598] | 73 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 74 |
|
---|
[23b547] | 75 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 76 | Walker->setType(hydrogen);
|
---|
| 77 | Walker->setPosition(Vector(0., 1., 1. ));
|
---|
[8db598] | 78 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 79 |
|
---|
[23b547] | 80 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 81 | Walker->setType(hydrogen);
|
---|
| 82 | Walker->setPosition(Vector(1., 1., 0. ));
|
---|
[8db598] | 83 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 84 |
|
---|
[23b547] | 85 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 86 | Walker->setType(hydrogen);
|
---|
| 87 | Walker->setPosition(Vector(0., 0., 0. ));
|
---|
[8db598] | 88 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[c4d4df] | 89 |
|
---|
| 90 | // check that TestMolecule was correctly constructed
|
---|
[a7b761b] | 91 | CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->getAtomCount(), 4 );
|
---|
[c4d4df] | 92 |
|
---|
[8db598] | 93 | TestSurfaceMolecule->ActiveFlag = true;
|
---|
[a5551b] | 94 |
|
---|
[c4d4df] | 95 | // init tesselation and linked cell
|
---|
| 96 | Surface = new Tesselation;
|
---|
[8db598] | 97 | LC = new LinkedCell(TestSurfaceMolecule, 5.);
|
---|
| 98 | FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
|
---|
[c4d4df] | 99 |
|
---|
[bbc338] | 100 | // add outer atoms
|
---|
[4eb4fe] | 101 | carbon = World::getInstance().getPeriode()->FindElement(6);
|
---|
[8cbb97] | 102 | TestSurfaceMolecule = World::getInstance().createMolecule();
|
---|
[23b547] | 103 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 104 | Walker->setType(carbon);
|
---|
| 105 | Walker->setPosition(Vector(4., 0., 4. ));
|
---|
[8cbb97] | 106 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 107 |
|
---|
[23b547] | 108 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 109 | Walker->setType(carbon);
|
---|
| 110 | Walker->setPosition(Vector(0., 4., 4. ));
|
---|
[8cbb97] | 111 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 112 |
|
---|
[23b547] | 113 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 114 | Walker->setType(carbon);
|
---|
| 115 | Walker->setPosition(Vector(4., 4., 0. ));
|
---|
[8cbb97] | 116 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 117 |
|
---|
[bbc338] | 118 | // add inner atoms
|
---|
[23b547] | 119 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 120 | Walker->setType(carbon);
|
---|
| 121 | Walker->setPosition(Vector(0.5, 0.5, 0.5 ));
|
---|
[8cbb97] | 122 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 123 |
|
---|
[e65de8] | 124 | World::getInstance().selectAllMolecules(AllMolecules());
|
---|
| 125 | allMolecules = World::getInstance().getSelectedMolecules();
|
---|
| 126 | CPPUNIT_ASSERT_EQUAL( (size_t) 2, allMolecules.size());
|
---|
[bbc338] | 127 |
|
---|
[c4d4df] | 128 | // init maps
|
---|
[bbc338] | 129 | surfacemap = NULL;
|
---|
[c4d4df] | 130 | binmap = NULL;
|
---|
| 131 |
|
---|
| 132 | };
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | void AnalysisCorrelationToSurfaceUnitTest::tearDown()
|
---|
| 136 | {
|
---|
| 137 | if (surfacemap != NULL)
|
---|
| 138 | delete(surfacemap);
|
---|
| 139 | if (binmap != NULL)
|
---|
| 140 | delete(binmap);
|
---|
| 141 |
|
---|
[776b64] | 142 | delete(Surface);
|
---|
| 143 | // note that all the atoms are cleaned by TestMolecule
|
---|
[c4d4df] | 144 | delete(LC);
|
---|
[23b547] | 145 | World::purgeInstance();
|
---|
[e6fdbe] | 146 | logger::purgeInstance();
|
---|
[c4d4df] | 147 | };
|
---|
| 148 |
|
---|
| 149 |
|
---|
[8db598] | 150 | /** Checks whether setup() does the right thing.
|
---|
| 151 | */
|
---|
| 152 | void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
|
---|
| 153 | {
|
---|
[a7b761b] | 154 | CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() );
|
---|
[e65de8] | 155 | CPPUNIT_ASSERT_EQUAL( (size_t)2, allMolecules.size() );
|
---|
[8db598] | 156 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
|
---|
| 157 | CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
|
---|
| 158 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
|
---|
| 159 | };
|
---|
| 160 |
|
---|
[c4d4df] | 161 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
|
---|
| 162 | {
|
---|
| 163 | // do the pair correlation
|
---|
[c78d44] | 164 | elements.push_back(hydrogen);
|
---|
[e65de8] | 165 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[8db598] | 166 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[c4d4df] | 167 | CPPUNIT_ASSERT( surfacemap != NULL );
|
---|
| 168 | CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
|
---|
| 169 | };
|
---|
| 170 |
|
---|
[bbc338] | 171 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
|
---|
[c4d4df] | 172 | {
|
---|
| 173 | BinPairMap::iterator tester;
|
---|
[c78d44] | 174 | elements.push_back(hydrogen);
|
---|
[e65de8] | 175 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[c4d4df] | 176 | // put pair correlation into bins and check with no range
|
---|
[8db598] | 177 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[e138de] | 178 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
[c4d4df] | 179 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
---|
[8db598] | 180 | OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
[c4d4df] | 181 | tester = binmap->begin();
|
---|
| 182 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 183 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
| 184 |
|
---|
| 185 | };
|
---|
| 186 |
|
---|
[bbc338] | 187 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
|
---|
[c4d4df] | 188 | {
|
---|
| 189 | BinPairMap::iterator tester;
|
---|
[c78d44] | 190 | elements.push_back(hydrogen);
|
---|
[e65de8] | 191 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[8db598] | 192 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[c4d4df] | 193 | // ... and check with [0., 2.] range
|
---|
[e138de] | 194 | binmap = BinData( surfacemap, 0.5, 0., 2. );
|
---|
[c4d4df] | 195 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
[8db598] | 196 | // OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
[c4d4df] | 197 | tester = binmap->begin();
|
---|
| 198 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 199 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
| 200 | tester = binmap->find(1.);
|
---|
| 201 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 202 | CPPUNIT_ASSERT_EQUAL( 0, tester->second );
|
---|
| 203 |
|
---|
| 204 | };
|
---|
| 205 |
|
---|
[bbc338] | 206 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
|
---|
| 207 | {
|
---|
| 208 | BinPairMap::iterator tester;
|
---|
[c78d44] | 209 | elements.push_back(carbon);
|
---|
[e65de8] | 210 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[8db598] | 211 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[bbc338] | 212 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 213 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
[3b9e34] | 214 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
[c6394d] | 215 | CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
|
---|
[bbc338] | 216 | // inside point is first and must have negative value
|
---|
[8db598] | 217 | tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
|
---|
[bbc338] | 218 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 219 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 220 | // inner point
|
---|
[8db598] | 221 | tester = binmap->lower_bound(0.);
|
---|
[bbc338] | 222 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 223 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
| 224 | };
|
---|
| 225 |
|
---|
| 226 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
|
---|
| 227 | {
|
---|
| 228 | BinPairMap::iterator tester;
|
---|
[c78d44] | 229 | elements.push_back(carbon);
|
---|
[e65de8] | 230 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[8db598] | 231 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[bbc338] | 232 | // ... and check with [0., 2.] range
|
---|
[e138de] | 233 | binmap = BinData( surfacemap, 0.5, -2., 4. );
|
---|
[3b9e34] | 234 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
[bbc338] | 235 | CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
|
---|
| 236 | // three outside points
|
---|
[8db598] | 237 | tester = binmap->lower_bound(4.25-0.5);
|
---|
[bbc338] | 238 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 239 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 240 | // inner point
|
---|
[8db598] | 241 | tester = binmap->lower_bound(0.);
|
---|
[bbc338] | 242 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 243 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
| 244 | };
|
---|