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