source: src/unittests/analysisbondsunittest.cpp@ 6cd16b

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 6cd16b was 6cd16b, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'FixAnalysisBonds_carbonwrongZ' into Analysis_PairCorrelation

Conflicts:

molecuilder/src/unittests/analysisbondsunittest.cpp

Conflict has been due to mixing of lines setting Z and vDw and CoV of carbon.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 5.2 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 "analysis_bonds.hpp"
19#include "analysisbondsunittest.hpp"
20#include "atom.hpp"
21#include "bond.hpp"
22#include "bondgraph.hpp"
23#include "element.hpp"
24#include "molecule.hpp"
25#include "periodentafel.hpp"
26
27/********************************************** Test classes **************************************/
28
29// Registers the fixture into the 'registry'
30CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisBondsTest );
31
32
33void AnalysisBondsTest::setUp()
34{
35 atom *Walker = NULL;
36
37 // init private all pointers to zero
38 TestMolecule = NULL;
39 hydrogen = NULL;
40 tafel = NULL;
41
42 // construct element
43 hydrogen = new element;
44 hydrogen->Z = 1;
45 hydrogen->Valence = 1;
46 hydrogen->NoValenceOrbitals = 1;
47 strcpy(hydrogen->name, "hydrogen");
48 strcpy(hydrogen->symbol, "H");
49 carbon = new element;
50 carbon->Z = 2;
51 carbon->Valence = 4;
52 carbon->NoValenceOrbitals = 4;
53 strcpy(carbon->name, "carbon");
54 strcpy(carbon->symbol, "C");
55
56
57 // construct periodentafel
58 tafel = new periodentafel;
59 tafel->AddElement(hydrogen);
60 tafel->AddElement(carbon);
61
62 // construct molecule (tetraeder of hydrogens)
63 TestMolecule = new molecule(tafel);
64 Walker = new atom();
65 Walker->type = hydrogen;
66 Walker->node->Init(1.5, 0., 1.5 );
67 TestMolecule->AddAtom(Walker);
68 Walker = new atom();
69 Walker->type = hydrogen;
70 Walker->node->Init(0., 1.5, 1.5 );
71 TestMolecule->AddAtom(Walker);
72 Walker = new atom();
73 Walker->type = hydrogen;
74 Walker->node->Init(1.5, 1.5, 0. );
75 TestMolecule->AddAtom(Walker);
76 Walker = new atom();
77 Walker->type = hydrogen;
78 Walker->node->Init(0., 0., 0. );
79 TestMolecule->AddAtom(Walker);
80 Walker = new atom();
81 Walker->type = carbon;
82 Walker->node->Init(0.5, 0.5, 0.5 );
83 TestMolecule->AddAtom(Walker);
84
85 // check that TestMolecule was correctly constructed
86 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
87
88 // create a small file with table
89 filename = new string("test.dat");
90 ofstream test(filename->c_str());
91 test << ".\tH\tC\n";
92 test << "H\t1.\t1.2\n";
93 test << "C\t1.2\t1.5\n";
94 test.close();
95 BG = new BondGraph(true);
96
97 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
98 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
99 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
100 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
101
102 BG->ConstructBondGraph(TestMolecule);
103};
104
105
106void AnalysisBondsTest::tearDown()
107{
108 // remove the file
109 remove(filename->c_str());
110 delete(filename);
111 delete(BG);
112
113 // remove molecule
114 delete(TestMolecule);
115 // note that all the atoms are cleaned by TestMolecule
116 delete(tafel);
117 // note that element is cleaned by periodentafel
118};
119
120/** UnitTest for GetMaxMinMeanBondCount().
121 */
122void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
123{
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 );
131
132};
133
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 );
164};
165
166
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.