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