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