source: src/unittests/analysisbondsunittest.cpp@ c6efc1

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 c6efc1 was 1bd79e, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Changed implementation of Vector to forward operations to contained objects

  • Property mode set to 100644
File size: 4.8 KB
Line 
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>
16#include <cstring>
17
18#include "World.hpp"
19#include "analysis_bonds.hpp"
20#include "analysisbondsunittest.hpp"
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#ifdef HAVE_TESTRUNNER
29#include "UnitTestMain.hpp"
30#endif /*HAVE_TESTRUNNER*/
31
32/********************************************** Test classes **************************************/
33
34// Registers the fixture into the 'registry'
35CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisBondsTest );
36
37
38void AnalysisBondsTest::setUp()
39{
40 atom *Walker = NULL;
41
42 // init private all pointers to zero
43 TestMolecule = NULL;
44 hydrogen = NULL;
45 tafel = NULL;
46
47 // construct element
48 hydrogen = new element;
49 hydrogen->Z = 1;
50 hydrogen->Valence = 1;
51 hydrogen->NoValenceOrbitals = 1;
52 strcpy(hydrogen->name, "hydrogen");
53 strcpy(hydrogen->symbol, "H");
54 carbon = new element;
55 carbon->Z = 2;
56 carbon->Valence = 4;
57 carbon->NoValenceOrbitals = 4;
58 strcpy(carbon->name, "carbon");
59 strcpy(carbon->symbol, "C");
60
61
62 // construct periodentafel
63 tafel = World::getInstance().getPeriode();
64 tafel->AddElement(hydrogen);
65 tafel->AddElement(carbon);
66
67 // construct molecule (tetraeder of hydrogens)
68 TestMolecule = World::getInstance().createMolecule();
69 Walker = World::getInstance().createAtom();
70 Walker->type = hydrogen;
71 *Walker->node = Vector(1.5, 0., 1.5 );
72 TestMolecule->AddAtom(Walker);
73 Walker = World::getInstance().createAtom();
74 Walker->type = hydrogen;
75 *Walker->node = Vector(0., 1.5, 1.5 );
76 TestMolecule->AddAtom(Walker);
77 Walker = World::getInstance().createAtom();
78 Walker->type = hydrogen;
79 *Walker->node = Vector(1.5, 1.5, 0. );
80 TestMolecule->AddAtom(Walker);
81 Walker = World::getInstance().createAtom();
82 Walker->type = hydrogen;
83 *Walker->node = Vector(0., 0., 0. );
84 TestMolecule->AddAtom(Walker);
85 Walker = World::getInstance().createAtom();
86 Walker->type = carbon;
87 *Walker->node = Vector(0.5, 0.5, 0.5 );
88 TestMolecule->AddAtom(Walker);
89
90 // check that TestMolecule was correctly constructed
91 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
92
93 // create a small file with table
94 filename = new string("test.dat");
95 ofstream test(filename->c_str());
96 test << ".\tH\tC\n";
97 test << "H\t1.\t1.2\n";
98 test << "C\t1.2\t1.5\n";
99 test.close();
100 BG = new BondGraph(true);
101
102 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
103 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
104 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
105 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
106
107 BG->ConstructBondGraph(TestMolecule);
108};
109
110
111void AnalysisBondsTest::tearDown()
112{
113 // remove the file
114 remove(filename->c_str());
115 delete(filename);
116 delete(BG);
117
118 // remove molecule
119 World::getInstance().destroyMolecule(TestMolecule);
120 // note that all the atoms are cleaned by TestMolecule
121 World::purgeInstance();
122};
123
124/** UnitTest for GetMaxMinMeanBondCount().
125 */
126void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
127{
128 double Min = 20.; // check that initialization resets these arbitrary values
129 double Mean = 200.;
130 double Max = 1e-6;
131 GetMaxMinMeanBondCount(TestMolecule, Min, Mean, Max);
132 CPPUNIT_ASSERT_EQUAL( 1., Min );
133 CPPUNIT_ASSERT_EQUAL( 1.6, Mean );
134 CPPUNIT_ASSERT_EQUAL( 4., Max );
135
136};
137
138/** UnitTest for MinMaxBondDistanceBetweenElements().
139 */
140void AnalysisBondsTest::MinMeanMaxBondDistanceBetweenElementsTest()
141{
142 double Min = 20.; // check that initialization resets these arbitrary values
143 double Mean = 2e+6;
144 double Max = 1e-6;
145 double Min2 = 20.;
146 double Mean2 = 2e+6;
147 double Max2 = 1e-6;
148 const double maxbondlength = sqrt(1.*1. + 1.*1. + .5*.5);
149 const double minbondlength = sqrt(.5*.5 + .5*.5 + .5*.5);
150 const double meanbondlength = (minbondlength+3.*maxbondlength)/4.;
151 // check bond lengths C-H
152 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, carbon, Min, Mean, Max);
153 CPPUNIT_ASSERT_EQUAL( minbondlength , Min );
154 CPPUNIT_ASSERT_EQUAL( meanbondlength , Mean );
155 CPPUNIT_ASSERT_EQUAL( maxbondlength , Max );
156
157 // check that elements are symmetric, i.e. C-H == H-C
158 MinMeanMaxBondDistanceBetweenElements(TestMolecule, carbon, hydrogen, Min2, Mean2, Max2);
159 CPPUNIT_ASSERT_EQUAL( Min , Min2 );
160 CPPUNIT_ASSERT_EQUAL( Mean , Mean2 );
161 CPPUNIT_ASSERT_EQUAL( Max , Max2 );
162
163 // check no bond case (no bonds H-H in system!)
164 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, hydrogen, Min, Mean, Max);
165 CPPUNIT_ASSERT_EQUAL( 0. , Min );
166 CPPUNIT_ASSERT_EQUAL( 0. , Mean );
167 CPPUNIT_ASSERT_EQUAL( 0. , Max );
168};
Note: See TracBrowser for help on using the repository browser.