| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [bcf653] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [c4d4df] | 8 | /* | 
|---|
|  | 9 | * AnalysisPairCorrelationUnitTest.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 |  | 
|---|
| [9b5a2c] | 28 | #include "Analysis/analysis_correlation.hpp" | 
|---|
| [e65de8] | 29 | #include "Descriptors/MoleculeDescriptor.hpp" | 
|---|
|  | 30 |  | 
|---|
| [6f0841] | 31 | #include "Atom/atom.hpp" | 
|---|
| [c1a9d6] | 32 | #include "Descriptors/AtomTypeDescriptor.hpp" | 
|---|
| [3bdb6d] | 33 | #include "Element/element.hpp" | 
|---|
| [42127c] | 34 | #include "Element/periodentafel.hpp" | 
|---|
| [c4d4df] | 35 | #include "molecule.hpp" | 
|---|
| [42127c] | 36 | #include "MoleculeListClass.hpp" | 
|---|
| [e6fdbe] | 37 | #include "World.hpp" | 
|---|
| [c4d4df] | 38 |  | 
|---|
| [f844ef] | 39 | #include "AnalysisPairCorrelationUnitTest.hpp" | 
|---|
|  | 40 |  | 
|---|
| [9b6b2f] | 41 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 42 | #include "UnitTestMain.hpp" | 
|---|
|  | 43 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
| [c4d4df] | 44 |  | 
|---|
|  | 45 | /********************************************** Test classes **************************************/ | 
|---|
|  | 46 |  | 
|---|
|  | 47 | // Registers the fixture into the 'registry' | 
|---|
|  | 48 | CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisPairCorrelationUnitTest ); | 
|---|
|  | 49 |  | 
|---|
|  | 50 |  | 
|---|
|  | 51 | void AnalysisPairCorrelationUnitTest::setUp() | 
|---|
|  | 52 | { | 
|---|
|  | 53 | atom *Walker = NULL; | 
|---|
|  | 54 |  | 
|---|
|  | 55 | // init private all pointers to zero | 
|---|
|  | 56 | TestMolecule = NULL; | 
|---|
|  | 57 | correlationmap = NULL; | 
|---|
|  | 58 | binmap = NULL; | 
|---|
|  | 59 |  | 
|---|
| [c78d44] | 60 | // construct element list | 
|---|
| [e5c0a1] | 61 | std::vector<const element *> elements; | 
|---|
| [4eb4fe] | 62 | hydrogen = World::getInstance().getPeriode()->FindElement(1); | 
|---|
| [c78d44] | 63 | CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found"); | 
|---|
|  | 64 |  | 
|---|
|  | 65 | // construct molecule (tetraeder of hydrogens) | 
|---|
| [23b547] | 66 | TestMolecule = World::getInstance().createMolecule(); | 
|---|
|  | 67 | Walker = World::getInstance().createAtom(); | 
|---|
| [d74077] | 68 | Walker->setType(hydrogen); | 
|---|
|  | 69 | Walker->setPosition(Vector(1., 0., 1. )); | 
|---|
| [c4d4df] | 70 | TestMolecule->AddAtom(Walker); | 
|---|
| [23b547] | 71 | Walker = World::getInstance().createAtom(); | 
|---|
| [d74077] | 72 | Walker->setType(hydrogen); | 
|---|
|  | 73 | Walker->setPosition(Vector(0., 1., 1. )); | 
|---|
| [c4d4df] | 74 | TestMolecule->AddAtom(Walker); | 
|---|
| [23b547] | 75 | Walker = World::getInstance().createAtom(); | 
|---|
| [d74077] | 76 | Walker->setType(hydrogen); | 
|---|
|  | 77 | Walker->setPosition(Vector(1., 1., 0. )); | 
|---|
| [c4d4df] | 78 | TestMolecule->AddAtom(Walker); | 
|---|
| [23b547] | 79 | Walker = World::getInstance().createAtom(); | 
|---|
| [d74077] | 80 | Walker->setType(hydrogen); | 
|---|
|  | 81 | Walker->setPosition(Vector(0., 0., 0. )); | 
|---|
| [c4d4df] | 82 | TestMolecule->AddAtom(Walker); | 
|---|
|  | 83 |  | 
|---|
|  | 84 | // check that TestMolecule was correctly constructed | 
|---|
| [ea7176] | 85 | CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 ); | 
|---|
| [c4d4df] | 86 |  | 
|---|
|  | 87 | // init maps | 
|---|
| [c1a9d6] | 88 | World::AtomComposite atoms_first = World::getInstance().getAllAtoms(AtomByType(hydrogen)); | 
|---|
|  | 89 | CPPUNIT_ASSERT_EQUAL( (size_t) 4, atoms_first.size()); | 
|---|
|  | 90 | correlationmap = PairCorrelation( atoms_first, atoms_first, 5.); | 
|---|
| [c4d4df] | 91 | binmap = NULL; | 
|---|
|  | 92 |  | 
|---|
|  | 93 | }; | 
|---|
|  | 94 |  | 
|---|
|  | 95 |  | 
|---|
|  | 96 | void AnalysisPairCorrelationUnitTest::tearDown() | 
|---|
|  | 97 | { | 
|---|
|  | 98 | if (correlationmap != NULL) | 
|---|
|  | 99 | delete(correlationmap); | 
|---|
|  | 100 | if (binmap != NULL) | 
|---|
|  | 101 | delete(binmap); | 
|---|
|  | 102 |  | 
|---|
|  | 103 | // note that all the atoms are cleaned by TestMolecule | 
|---|
| [23b547] | 104 | World::purgeInstance(); | 
|---|
| [e6fdbe] | 105 | logger::purgeInstance(); | 
|---|
|  | 106 | errorLogger::purgeInstance(); | 
|---|
| [c4d4df] | 107 | }; | 
|---|
|  | 108 |  | 
|---|
|  | 109 | void AnalysisPairCorrelationUnitTest::PairCorrelationTest() | 
|---|
|  | 110 | { | 
|---|
|  | 111 | // do the pair correlation | 
|---|
|  | 112 | CPPUNIT_ASSERT( correlationmap != NULL ); | 
|---|
|  | 113 | CPPUNIT_ASSERT_EQUAL( (size_t)6, correlationmap->size() ); | 
|---|
|  | 114 | }; | 
|---|
|  | 115 |  | 
|---|
|  | 116 | void AnalysisPairCorrelationUnitTest::PairCorrelationBinNoRangeTest() | 
|---|
|  | 117 | { | 
|---|
|  | 118 | BinPairMap::iterator tester; | 
|---|
|  | 119 | // put pair correlation into bins and check with no range | 
|---|
| [e138de] | 120 | binmap = BinData( correlationmap, 0.5, 0., 0. ); | 
|---|
| [c4d4df] | 121 | CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() ); | 
|---|
| [e138de] | 122 | //OutputCorrelation ( binmap ); | 
|---|
| [c4d4df] | 123 | tester = binmap->begin(); | 
|---|
|  | 124 | CPPUNIT_ASSERT_EQUAL( sqrt(2.), tester->first ); | 
|---|
|  | 125 | CPPUNIT_ASSERT_EQUAL( 6, tester->second ); | 
|---|
|  | 126 | }; | 
|---|
|  | 127 |  | 
|---|
|  | 128 | void AnalysisPairCorrelationUnitTest::PairCorrelationBinRangeTest() | 
|---|
|  | 129 | { | 
|---|
|  | 130 | BinPairMap::iterator tester; | 
|---|
|  | 131 | // ... and check with [0., 2.] range | 
|---|
| [e138de] | 132 | binmap = BinData( correlationmap, 0.5, 0., 2. ); | 
|---|
| [c4d4df] | 133 | CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() ); | 
|---|
| [e138de] | 134 | //OutputCorrelation ( binmap ); | 
|---|
| [c4d4df] | 135 | tester = binmap->begin(); | 
|---|
|  | 136 | CPPUNIT_ASSERT_EQUAL( 0., tester->first ); | 
|---|
|  | 137 | tester = binmap->find(1.); | 
|---|
|  | 138 | CPPUNIT_ASSERT_EQUAL( 1., tester->first ); | 
|---|
|  | 139 | CPPUNIT_ASSERT_EQUAL( 6, tester->second ); | 
|---|
|  | 140 | }; | 
|---|