source: src/unittests/analysisbondsunittest.cpp@ 1f2217

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 1f2217 was cbc5fb, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Made the world solely responsible for creating and erasing molecules.

  • Property mode set to 100644
File size: 5.3 KB
RevLine 
[96c961]1/*
2 * analysisbondsunittest.cpp
3 *
4 * Created on: Nov 7, 2009
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include <iostream>
15#include <stdio.h>
[49e1ae]16#include <cstring>
[96c961]17
[46d958]18#include "World.hpp"
[220cf37]19#include "analysis_bonds.hpp"
20#include "analysisbondsunittest.hpp"
[96c961]21#include "atom.hpp"
22#include "bond.hpp"
23#include "bondgraph.hpp"
24#include "element.hpp"
25#include "molecule.hpp"
26#include "periodentafel.hpp"
27
28/********************************************** Test classes **************************************/
29
30// Registers the fixture into the 'registry'
31CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisBondsTest );
32
33
34void AnalysisBondsTest::setUp()
35{
36 atom *Walker = NULL;
37
38 // init private all pointers to zero
39 TestMolecule = NULL;
40 hydrogen = NULL;
41 tafel = NULL;
42
43 // construct element
44 hydrogen = new element;
45 hydrogen->Z = 1;
[220cf37]46 hydrogen->Valence = 1;
47 hydrogen->NoValenceOrbitals = 1;
[96c961]48 strcpy(hydrogen->name, "hydrogen");
49 strcpy(hydrogen->symbol, "H");
50 carbon = new element;
51 carbon->Z = 1;
[220cf37]52 carbon->Valence = 4;
53 carbon->NoValenceOrbitals = 4;
[96c961]54 strcpy(carbon->name, "carbon");
55 strcpy(carbon->symbol, "C");
56
57
58 // construct periodentafel
[cbc5fb]59 tafel = World::get()->getPeriode();
[96c961]60 tafel->AddElement(hydrogen);
61 tafel->AddElement(carbon);
62
63 // construct molecule (tetraeder of hydrogens)
[cbc5fb]64 TestMolecule = World::get()->createMolecule();
[46d958]65 Walker = World::get()->createAtom();
[96c961]66 Walker->type = hydrogen;
[220cf37]67 Walker->node->Init(1.5, 0., 1.5 );
[96c961]68 TestMolecule->AddAtom(Walker);
[46d958]69 Walker = World::get()->createAtom();
[96c961]70 Walker->type = hydrogen;
[220cf37]71 Walker->node->Init(0., 1.5, 1.5 );
[96c961]72 TestMolecule->AddAtom(Walker);
[46d958]73 Walker = World::get()->createAtom();
[96c961]74 Walker->type = hydrogen;
[220cf37]75 Walker->node->Init(1.5, 1.5, 0. );
[96c961]76 TestMolecule->AddAtom(Walker);
[46d958]77 Walker = World::get()->createAtom();
[96c961]78 Walker->type = hydrogen;
79 Walker->node->Init(0., 0., 0. );
80 TestMolecule->AddAtom(Walker);
[46d958]81 Walker = World::get()->createAtom();
[220cf37]82 Walker->type = carbon;
83 Walker->node->Init(0.5, 0.5, 0.5 );
84 TestMolecule->AddAtom(Walker);
[96c961]85
86 // check that TestMolecule was correctly constructed
[220cf37]87 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
[96c961]88
89 // create a small file with table
90 filename = new string("test.dat");
91 ofstream test(filename->c_str());
92 test << ".\tH\tC\n";
93 test << "H\t1.\t1.2\n";
94 test << "C\t1.2\t1.5\n";
[220cf37]95 test.close();
[96c961]96 BG = new BondGraph(true);
[220cf37]97
98 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
99 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
100 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
101 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
102
103 BG->ConstructBondGraph(TestMolecule);
[96c961]104};
105
106
107void AnalysisBondsTest::tearDown()
108{
109 // remove the file
110 remove(filename->c_str());
111 delete(filename);
112 delete(BG);
113
114 // remove molecule
[cbc5fb]115 World::get()->destroyMolecule(TestMolecule);
[96c961]116 // note that all the atoms are cleaned by TestMolecule
[cbc5fb]117 World::destroy();
[96c961]118};
119
[220cf37]120/** UnitTest for GetMaxMinMeanBondCount().
[96c961]121 */
[220cf37]122void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
[96c961]123{
[220cf37]124 double Min = 20.; // check that initialization resets these arbitrary values
125 double Mean = 200.;
126 double Max = 1e-6;
127 GetMaxMinMeanBondCount(TestMolecule, Min, Mean, Max);
128 CPPUNIT_ASSERT_EQUAL( 1., Min );
129 CPPUNIT_ASSERT_EQUAL( 1.6, Mean );
130 CPPUNIT_ASSERT_EQUAL( 4., Max );
[96c961]131
[220cf37]132};
[96c961]133
[220cf37]134/** UnitTest for MinMaxBondDistanceBetweenElements().
135 */
136void AnalysisBondsTest::MinMeanMaxBondDistanceBetweenElementsTest()
137{
138 double Min = 20.; // check that initialization resets these arbitrary values
139 double Mean = 2e+6;
140 double Max = 1e-6;
141 double Min2 = 20.;
142 double Mean2 = 2e+6;
143 double Max2 = 1e-6;
144 const double maxbondlength = sqrt(1.*1. + 1.*1. + .5*.5);
145 const double minbondlength = sqrt(.5*.5 + .5*.5 + .5*.5);
146 const double meanbondlength = (minbondlength+3.*maxbondlength)/4.;
147 // check bond lengths C-H
148 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, carbon, Min, Mean, Max);
149 CPPUNIT_ASSERT_EQUAL( minbondlength , Min );
150 CPPUNIT_ASSERT_EQUAL( meanbondlength , Mean );
151 CPPUNIT_ASSERT_EQUAL( maxbondlength , Max );
152
153 // check that elements are symmetric, i.e. C-H == H-C
154 MinMeanMaxBondDistanceBetweenElements(TestMolecule, carbon, hydrogen, Min2, Mean2, Max2);
155 CPPUNIT_ASSERT_EQUAL( Min , Min2 );
156 CPPUNIT_ASSERT_EQUAL( Mean , Mean2 );
157 CPPUNIT_ASSERT_EQUAL( Max , Max2 );
158
159 // check no bond case (no bonds H-H in system!)
160 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, hydrogen, Min, Mean, Max);
161 CPPUNIT_ASSERT_EQUAL( 0. , Min );
162 CPPUNIT_ASSERT_EQUAL( 0. , Mean );
163 CPPUNIT_ASSERT_EQUAL( 0. , Max );
[96c961]164};
165
[220cf37]166
[96c961]167/********************************************** Main routine **************************************/
168
169int main(int argc, char **argv)
170{
171 // Get the top level suite from the registry
172 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
173
174 // Adds the test to the list of test to run
175 CppUnit::TextUi::TestRunner runner;
176 runner.addTest( suite );
177
178 // Change the default outputter to a compiler error format outputter
179 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
180 std::cerr ) );
181 // Run the tests.
182 bool wasSucessful = runner.run();
183
184 // Return error code 1 if the one of test failed.
185 return wasSucessful ? 0 : 1;
186};
Note: See TracBrowser for help on using the repository browser.