source: src/unittests/analysisbondsunittest.cpp@ 9879f6

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

Huge Refactoring due to class molecule now being an STL container.

  • molecule::start and molecule::end were dropped. Hence, the usual construct Walker = start while (Walker->next != end) {

Walker = walker->next
...

}
was changed to
for (molecule::iterator iter = begin(); iter != end(); ++iter) {

...

}
and (*iter) used instead of Walker.

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