/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2010-2012 University of Bonn. All rights reserved.
* Copyright (C) 2013 Frederik Heber. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* AnalysisPairCorrelationUnitTest.cpp
*
* Created on: Oct 13, 2009
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
using namespace std;
#include
#include
#include
#include
#include "Analysis/analysis_correlation.hpp"
#include "Descriptors/MoleculeDescriptor.hpp"
#include "Atom/atom.hpp"
#include "Descriptors/AtomTypeDescriptor.hpp"
#include "Element/element.hpp"
#include "Element/periodentafel.hpp"
#include "molecule.hpp"
#include "MoleculeListClass.hpp"
#include "World.hpp"
#include "AnalysisPairCorrelationUnitTest.hpp"
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisPairCorrelationUnitTest );
void AnalysisPairCorrelationUnitTest::setUp()
{
atom *Walker = NULL;
// init private all pointers to zero
TestMolecule = NULL;
correlationmap = NULL;
binmap = NULL;
// construct element list
std::vector elements;
hydrogen = World::getInstance().getPeriode()->FindElement(1);
CPPUNIT_ASSERT(hydrogen != NULL && "hydrogen element not found");
// construct molecule (tetraeder of hydrogens)
TestMolecule = World::getInstance().createMolecule();
Walker = World::getInstance().createAtom();
Walker->setType(hydrogen);
Walker->setPosition(Vector(1., 0., 1. ));
TestMolecule->AddAtom(Walker);
Walker = World::getInstance().createAtom();
Walker->setType(hydrogen);
Walker->setPosition(Vector(0., 1., 1. ));
TestMolecule->AddAtom(Walker);
Walker = World::getInstance().createAtom();
Walker->setType(hydrogen);
Walker->setPosition(Vector(1., 1., 0. ));
TestMolecule->AddAtom(Walker);
Walker = World::getInstance().createAtom();
Walker->setType(hydrogen);
Walker->setPosition(Vector(0., 0., 0. ));
TestMolecule->AddAtom(Walker);
// check that TestMolecule was correctly constructed
CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 4 );
// init maps
World::AtomComposite atoms_first = World::getInstance().getAllAtoms(AtomByType(hydrogen));
CPPUNIT_ASSERT_EQUAL( (size_t) 4, atoms_first.size());
correlationmap = PairCorrelation( atoms_first, atoms_first, 5.);
binmap = NULL;
};
void AnalysisPairCorrelationUnitTest::tearDown()
{
if (correlationmap != NULL)
delete(correlationmap);
if (binmap != NULL)
delete(binmap);
// note that all the atoms are cleaned by TestMolecule
World::purgeInstance();
logger::purgeInstance();
errorLogger::purgeInstance();
};
void AnalysisPairCorrelationUnitTest::PairCorrelationTest()
{
// do the pair correlation
CPPUNIT_ASSERT( correlationmap != NULL );
CPPUNIT_ASSERT_EQUAL( (size_t)6, correlationmap->size() );
};
void AnalysisPairCorrelationUnitTest::PairCorrelationBinNoRangeTest()
{
BinPairMap::iterator tester;
// put pair correlation into bins and check with no range
binmap = BinData( correlationmap, 0.5, 0., 0. );
CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
//OutputCorrelation ( binmap );
tester = binmap->begin();
// output precision of map is 6 digits
CPPUNIT_ASSERT( fabs(sqrt(2.)-tester->first) < 1e-5);
CPPUNIT_ASSERT_EQUAL( 6, tester->second );
};
void AnalysisPairCorrelationUnitTest::PairCorrelationBinRangeTest()
{
BinPairMap::iterator tester;
// ... and check with [0., 2.] range
binmap = BinData( correlationmap, 0.5, 0., 2. );
CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
//OutputCorrelation ( binmap );
tester = binmap->begin();
CPPUNIT_ASSERT_EQUAL( 0., tester->first );
tester = binmap->find(1.);
CPPUNIT_ASSERT_EQUAL( 1., tester->first );
CPPUNIT_ASSERT_EQUAL( 6, tester->second );
};