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