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