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