[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"
|
---|
[e65de8] | 29 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
| 30 |
|
---|
[c4d4df] | 31 | #include "atom.hpp"
|
---|
| 32 | #include "boundary.hpp"
|
---|
| 33 | #include "element.hpp"
|
---|
| 34 | #include "molecule.hpp"
|
---|
| 35 | #include "linkedcell.hpp"
|
---|
| 36 | #include "periodentafel.hpp"
|
---|
| 37 | #include "tesselation.hpp"
|
---|
[e6fdbe] | 38 | #include "World.hpp"
|
---|
[ad011c] | 39 | #include "CodePatterns/Assert.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;
|
---|
[af2c424] | 102 | LC = new LinkedCell(*TestSurfaceMolecule, 5.);
|
---|
[8db598] | 103 | FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
|
---|
[c4d4df] | 104 |
|
---|
[bbc338] | 105 | // add outer atoms
|
---|
[4eb4fe] | 106 | carbon = World::getInstance().getPeriode()->FindElement(6);
|
---|
[8cbb97] | 107 | TestSurfaceMolecule = World::getInstance().createMolecule();
|
---|
[23b547] | 108 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 109 | Walker->setType(carbon);
|
---|
| 110 | Walker->setPosition(Vector(4., 0., 4. ));
|
---|
[8cbb97] | 111 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 112 |
|
---|
[23b547] | 113 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 114 | Walker->setType(carbon);
|
---|
| 115 | Walker->setPosition(Vector(0., 4., 4. ));
|
---|
[8cbb97] | 116 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 117 |
|
---|
[23b547] | 118 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 119 | Walker->setType(carbon);
|
---|
| 120 | Walker->setPosition(Vector(4., 4., 0. ));
|
---|
[8cbb97] | 121 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 122 |
|
---|
[bbc338] | 123 | // add inner atoms
|
---|
[23b547] | 124 | Walker = World::getInstance().createAtom();
|
---|
[d74077] | 125 | Walker->setType(carbon);
|
---|
| 126 | Walker->setPosition(Vector(0.5, 0.5, 0.5 ));
|
---|
[8cbb97] | 127 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
[a7b761b] | 128 |
|
---|
[e65de8] | 129 | World::getInstance().selectAllMolecules(AllMolecules());
|
---|
| 130 | allMolecules = World::getInstance().getSelectedMolecules();
|
---|
| 131 | CPPUNIT_ASSERT_EQUAL( (size_t) 2, allMolecules.size());
|
---|
[bbc338] | 132 |
|
---|
[c4d4df] | 133 | // init maps
|
---|
[bbc338] | 134 | surfacemap = NULL;
|
---|
[c4d4df] | 135 | binmap = NULL;
|
---|
| 136 |
|
---|
| 137 | };
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | void AnalysisCorrelationToSurfaceUnitTest::tearDown()
|
---|
| 141 | {
|
---|
| 142 | if (surfacemap != NULL)
|
---|
| 143 | delete(surfacemap);
|
---|
| 144 | if (binmap != NULL)
|
---|
| 145 | delete(binmap);
|
---|
| 146 |
|
---|
[776b64] | 147 | delete(Surface);
|
---|
| 148 | // note that all the atoms are cleaned by TestMolecule
|
---|
[c4d4df] | 149 | delete(LC);
|
---|
[23b547] | 150 | World::purgeInstance();
|
---|
[e6fdbe] | 151 | logger::purgeInstance();
|
---|
[c4d4df] | 152 | };
|
---|
| 153 |
|
---|
| 154 |
|
---|
[8db598] | 155 | /** Checks whether setup() does the right thing.
|
---|
| 156 | */
|
---|
| 157 | void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
|
---|
| 158 | {
|
---|
[a7b761b] | 159 | CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() );
|
---|
[e65de8] | 160 | CPPUNIT_ASSERT_EQUAL( (size_t)2, allMolecules.size() );
|
---|
[8db598] | 161 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
|
---|
| 162 | CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
|
---|
| 163 | CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
|
---|
| 164 | };
|
---|
| 165 |
|
---|
[c4d4df] | 166 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
|
---|
| 167 | {
|
---|
| 168 | // do the pair correlation
|
---|
[c78d44] | 169 | elements.push_back(hydrogen);
|
---|
[e65de8] | 170 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[8db598] | 171 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[c4d4df] | 172 | CPPUNIT_ASSERT( surfacemap != NULL );
|
---|
| 173 | CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
|
---|
| 174 | };
|
---|
| 175 |
|
---|
[bbc338] | 176 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
|
---|
[c4d4df] | 177 | {
|
---|
| 178 | BinPairMap::iterator tester;
|
---|
[c78d44] | 179 | elements.push_back(hydrogen);
|
---|
[e65de8] | 180 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[c4d4df] | 181 | // put pair correlation into bins and check with no range
|
---|
[8db598] | 182 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[e138de] | 183 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
[c4d4df] | 184 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
---|
[92e5cb] | 185 | OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
|
---|
[c4d4df] | 186 | tester = binmap->begin();
|
---|
| 187 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 188 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
| 189 |
|
---|
| 190 | };
|
---|
| 191 |
|
---|
[bbc338] | 192 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
|
---|
[c4d4df] | 193 | {
|
---|
| 194 | BinPairMap::iterator tester;
|
---|
[c78d44] | 195 | elements.push_back(hydrogen);
|
---|
[e65de8] | 196 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[8db598] | 197 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[c4d4df] | 198 | // ... and check with [0., 2.] range
|
---|
[e138de] | 199 | binmap = BinData( surfacemap, 0.5, 0., 2. );
|
---|
[c4d4df] | 200 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
[8db598] | 201 | // OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
[c4d4df] | 202 | tester = binmap->begin();
|
---|
| 203 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
| 204 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
| 205 | tester = binmap->find(1.);
|
---|
| 206 | CPPUNIT_ASSERT_EQUAL( 1., tester->first );
|
---|
| 207 | CPPUNIT_ASSERT_EQUAL( 0, tester->second );
|
---|
| 208 |
|
---|
| 209 | };
|
---|
| 210 |
|
---|
[bbc338] | 211 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
|
---|
| 212 | {
|
---|
| 213 | BinPairMap::iterator tester;
|
---|
[c78d44] | 214 | elements.push_back(carbon);
|
---|
[e65de8] | 215 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[8db598] | 216 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[bbc338] | 217 | // put pair correlation into bins and check with no range
|
---|
[e138de] | 218 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
[3b9e34] | 219 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
[c6394d] | 220 | CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
|
---|
[bbc338] | 221 | // inside point is first and must have negative value
|
---|
[8db598] | 222 | tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
|
---|
[bbc338] | 223 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 224 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 225 | // inner point
|
---|
[8db598] | 226 | tester = binmap->lower_bound(0.);
|
---|
[bbc338] | 227 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 228 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
| 229 | };
|
---|
| 230 |
|
---|
| 231 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
|
---|
| 232 | {
|
---|
| 233 | BinPairMap::iterator tester;
|
---|
[c78d44] | 234 | elements.push_back(carbon);
|
---|
[e65de8] | 235 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
[8db598] | 236 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
[bbc338] | 237 | // ... and check with [0., 2.] range
|
---|
[e138de] | 238 | binmap = BinData( surfacemap, 0.5, -2., 4. );
|
---|
[3b9e34] | 239 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
[bbc338] | 240 | CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
|
---|
| 241 | // three outside points
|
---|
[8db598] | 242 | tester = binmap->lower_bound(4.25-0.5);
|
---|
[bbc338] | 243 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 244 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
| 245 | // inner point
|
---|
[8db598] | 246 | tester = binmap->lower_bound(0.);
|
---|
[bbc338] | 247 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
| 248 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
| 249 | };
|
---|