1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
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/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * AnalysisCorrelationToSurfaceUnitTest.cpp
|
---|
25 | *
|
---|
26 | * Created on: Oct 13, 2009
|
---|
27 | * Author: heber
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 |
|
---|
37 | #include <cppunit/CompilerOutputter.h>
|
---|
38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
40 |
|
---|
41 | #include <cstring>
|
---|
42 |
|
---|
43 | #include "Analysis/analysis_correlation.hpp"
|
---|
44 | #include "Atom/atom.hpp"
|
---|
45 | #include "CodePatterns/Assert.hpp"
|
---|
46 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
47 | #include "Element/element.hpp"
|
---|
48 | #include "Element/periodentafel.hpp"
|
---|
49 | #include "LinkedCell/linkedcell.hpp"
|
---|
50 | #include "LinkedCell/PointCloudAdaptor.hpp"
|
---|
51 | #include "molecule.hpp"
|
---|
52 | #include "Tesselation/boundary.hpp"
|
---|
53 | #include "Tesselation/tesselation.hpp"
|
---|
54 | #include "World.hpp"
|
---|
55 |
|
---|
56 | #include "AnalysisCorrelationToSurfaceUnitTest.hpp"
|
---|
57 |
|
---|
58 | #ifdef HAVE_TESTRUNNER
|
---|
59 | #include "UnitTestMain.hpp"
|
---|
60 | #endif /*HAVE_TESTRUNNER*/
|
---|
61 |
|
---|
62 | /********************************************** Test classes **************************************/
|
---|
63 |
|
---|
64 | // Registers the fixture into the 'registry'
|
---|
65 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest );
|
---|
66 |
|
---|
67 | void AnalysisCorrelationToSurfaceUnitTest::setUp()
|
---|
68 | {
|
---|
69 | ASSERT_DO(Assert::Throw);
|
---|
70 |
|
---|
71 | setVerbosity(5);
|
---|
72 |
|
---|
73 | atom *Walker = NULL;
|
---|
74 |
|
---|
75 | // init private all pointers to zero
|
---|
76 | TestSurfaceMolecule = NULL;
|
---|
77 | surfacemap = NULL;
|
---|
78 | binmap = NULL;
|
---|
79 | Surface = NULL;
|
---|
80 | LC = NULL;
|
---|
81 |
|
---|
82 | // prepare element list
|
---|
83 | hydrogen = World::getInstance().getPeriode()->FindElement(1);
|
---|
84 | CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
|
---|
85 | elements.clear();
|
---|
86 |
|
---|
87 | // construct molecule (tetraeder of hydrogens) base
|
---|
88 | TestSurfaceMolecule = World::getInstance().createMolecule();
|
---|
89 |
|
---|
90 | Walker = World::getInstance().createAtom();
|
---|
91 | Walker->setType(hydrogen);
|
---|
92 | Walker->setPosition(Vector(1., 0., 1. ));
|
---|
93 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
94 |
|
---|
95 | Walker = World::getInstance().createAtom();
|
---|
96 | Walker->setType(hydrogen);
|
---|
97 | Walker->setPosition(Vector(0., 1., 1. ));
|
---|
98 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
99 |
|
---|
100 | Walker = World::getInstance().createAtom();
|
---|
101 | Walker->setType(hydrogen);
|
---|
102 | Walker->setPosition(Vector(1., 1., 0. ));
|
---|
103 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
104 |
|
---|
105 | Walker = World::getInstance().createAtom();
|
---|
106 | Walker->setType(hydrogen);
|
---|
107 | Walker->setPosition(Vector(0., 0., 0. ));
|
---|
108 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
109 |
|
---|
110 | // check that TestMolecule was correctly constructed
|
---|
111 | CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->getAtomCount(), 4 );
|
---|
112 |
|
---|
113 | TestSurfaceMolecule->ActiveFlag = true;
|
---|
114 |
|
---|
115 | // init tesselation and linked cell
|
---|
116 | Surface = new Tesselation;
|
---|
117 | PointCloudAdaptor<molecule> cloud(TestSurfaceMolecule, TestSurfaceMolecule->name);
|
---|
118 | LC = new LinkedCell_deprecated(cloud, 5.);
|
---|
119 | FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell_deprecated *&)LC, 2.5, NULL);
|
---|
120 |
|
---|
121 | // add outer atoms
|
---|
122 | carbon = World::getInstance().getPeriode()->FindElement(6);
|
---|
123 | TestSurfaceMolecule = World::getInstance().createMolecule();
|
---|
124 | Walker = World::getInstance().createAtom();
|
---|
125 | Walker->setType(carbon);
|
---|
126 | Walker->setPosition(Vector(4., 0., 4. ));
|
---|
127 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
128 |
|
---|
129 | Walker = World::getInstance().createAtom();
|
---|
130 | Walker->setType(carbon);
|
---|
131 | Walker->setPosition(Vector(0., 4., 4. ));
|
---|
132 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
133 |
|
---|
134 | Walker = World::getInstance().createAtom();
|
---|
135 | Walker->setType(carbon);
|
---|
136 | Walker->setPosition(Vector(4., 4., 0. ));
|
---|
137 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
138 |
|
---|
139 | // add inner atoms
|
---|
140 | Walker = World::getInstance().createAtom();
|
---|
141 | Walker->setType(carbon);
|
---|
142 | Walker->setPosition(Vector(0.5, 0.5, 0.5 ));
|
---|
143 | TestSurfaceMolecule->AddAtom(Walker);
|
---|
144 |
|
---|
145 | World::getInstance().selectAllMolecules(AllMolecules());
|
---|
146 | allMolecules = const_cast<const World &>(World::getInstance()).getSelectedMolecules();
|
---|
147 | CPPUNIT_ASSERT_EQUAL( (size_t) 2, allMolecules.size());
|
---|
148 |
|
---|
149 | // init maps
|
---|
150 | surfacemap = NULL;
|
---|
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 |
|
---|
163 | delete(Surface);
|
---|
164 | // note that all the atoms are cleaned by TestMolecule
|
---|
165 | delete(LC);
|
---|
166 | World::purgeInstance();
|
---|
167 | logger::purgeInstance();
|
---|
168 | };
|
---|
169 |
|
---|
170 |
|
---|
171 | /** Checks whether setup() does the right thing.
|
---|
172 | */
|
---|
173 | void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
|
---|
174 | {
|
---|
175 | CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->getAtomCount() );
|
---|
176 | CPPUNIT_ASSERT_EQUAL( (size_t)2, allMolecules.size() );
|
---|
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 |
|
---|
182 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
|
---|
183 | {
|
---|
184 | // do the pair correlation
|
---|
185 | elements.push_back(hydrogen);
|
---|
186 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
187 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
188 | CPPUNIT_ASSERT( surfacemap != NULL );
|
---|
189 | CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
|
---|
190 | };
|
---|
191 |
|
---|
192 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
|
---|
193 | {
|
---|
194 | BinPairMap::iterator tester;
|
---|
195 | elements.push_back(hydrogen);
|
---|
196 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
197 | // put pair correlation into bins and check with no range
|
---|
198 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
199 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
200 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
|
---|
201 | OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
|
---|
202 | tester = binmap->begin();
|
---|
203 | CPPUNIT_ASSERT_EQUAL( 0., tester->first );
|
---|
204 | CPPUNIT_ASSERT_EQUAL( 4, tester->second );
|
---|
205 |
|
---|
206 | };
|
---|
207 |
|
---|
208 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
|
---|
209 | {
|
---|
210 | BinPairMap::iterator tester;
|
---|
211 | elements.push_back(hydrogen);
|
---|
212 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
213 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
214 | // ... and check with [0., 2.] range
|
---|
215 | binmap = BinData( surfacemap, 0.5, 0., 2. );
|
---|
216 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
|
---|
217 | // OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
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 |
|
---|
227 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
|
---|
228 | {
|
---|
229 | BinPairMap::iterator tester;
|
---|
230 | elements.push_back(carbon);
|
---|
231 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
232 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
233 | // put pair correlation into bins and check with no range
|
---|
234 | binmap = BinData( surfacemap, 0.5, 0., 0. );
|
---|
235 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
236 | CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
|
---|
237 | // inside point is first and must have negative value
|
---|
238 | tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
|
---|
239 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
240 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
241 | // inner point
|
---|
242 | tester = binmap->lower_bound(0.);
|
---|
243 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
244 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
245 | };
|
---|
246 |
|
---|
247 | void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
|
---|
248 | {
|
---|
249 | BinPairMap::iterator tester;
|
---|
250 | elements.push_back(carbon);
|
---|
251 | surfacemap = CorrelationToSurface( allMolecules, elements, Surface, LC );
|
---|
252 | // OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
|
---|
253 | // ... and check with [0., 2.] range
|
---|
254 | binmap = BinData( surfacemap, 0.5, -2., 4. );
|
---|
255 | //OutputCorrelation ( (ofstream *)&cout, binmap );
|
---|
256 | CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
|
---|
257 | // three outside points
|
---|
258 | tester = binmap->lower_bound(4.25-0.5);
|
---|
259 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
260 | CPPUNIT_ASSERT_EQUAL( 3, tester->second );
|
---|
261 | // inner point
|
---|
262 | tester = binmap->lower_bound(0.);
|
---|
263 | CPPUNIT_ASSERT( tester != binmap->end() );
|
---|
264 | CPPUNIT_ASSERT_EQUAL( 1, tester->second );
|
---|
265 | };
|
---|