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