source: src/unittests/analysisbondsunittest.cpp@ bf3817

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * analysisbondsunittest.cpp
3 *
4 * Created on: Nov 7, 2009
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13using namespace std;
14
15#include <cppunit/CompilerOutputter.h>
16#include <cppunit/extensions/TestFactoryRegistry.h>
17#include <cppunit/ui/text/TestRunner.h>
18
19#include <iostream>
20#include <stdio.h>
21#include <cstring>
22
23#include "analysis_bonds.hpp"
24#include "analysisbondsunittest.hpp"
25#include "atom.hpp"
26#include "bond.hpp"
27#include "bondgraph.hpp"
28#include "element.hpp"
29#include "molecule.hpp"
30#include "periodentafel.hpp"
31#include "LinearAlgebra/Vector.hpp"
32#include "World.hpp"
33
34#ifdef HAVE_TESTRUNNER
35#include "UnitTestMain.hpp"
36#endif /*HAVE_TESTRUNNER*/
37
38/********************************************** Test classes **************************************/
39
40// Registers the fixture into the 'registry'
41CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisBondsTest );
42
43
44void AnalysisBondsTest::setUp()
45{
46 atom *Walker = NULL;
47
48 // get elements
49 hydrogen = World::getInstance().getPeriode()->FindElement(1);
50 carbon = World::getInstance().getPeriode()->FindElement(6);
51 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
52 CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
53
54 // construct molecule (tetraeder of hydrogens)
55 TestMolecule = World::getInstance().createMolecule();
56 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
57 Walker = World::getInstance().createAtom();
58 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
59 Walker->setType(hydrogen);
60 Walker->setPosition(Vector(1.5, 0., 1.5 ));
61 TestMolecule->AddAtom(Walker);
62 Walker = World::getInstance().createAtom();
63 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
64 Walker->setType(hydrogen);
65 Walker->setPosition(Vector(0., 1.5, 1.5 ));
66 TestMolecule->AddAtom(Walker);
67 Walker = World::getInstance().createAtom();
68 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
69 Walker->setType(hydrogen);
70 Walker->setPosition(Vector(1.5, 1.5, 0. ));
71 TestMolecule->AddAtom(Walker);
72 Walker = World::getInstance().createAtom();
73 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
74 Walker->setType(hydrogen);
75 Walker->setPosition(Vector(0., 0., 0. ));
76 TestMolecule->AddAtom(Walker);
77 Walker = World::getInstance().createAtom();
78 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
79 Walker->setType(carbon);
80 Walker->setPosition(Vector(0.5, 0.5, 0.5 ));
81 TestMolecule->AddAtom(Walker);
82
83 // check that TestMolecule was correctly constructed
84 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 5 );
85
86 // create a small file with table
87 filename = new string("test.dat");
88 CPPUNIT_ASSERT(filename != NULL && "could not create string");
89 ofstream test(filename->c_str());
90 test << ".\tH\tHe\tLi\tBe\tB\tC\n";
91 test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
92 test << "He\t1.\t1.\t1.\t1.\t1.\t1.\n";
93 test << "Li\t1.\t1.\t1.\t1.\t1.\t1.\n";
94 test << "Be\t1.\t1.\t1.\t1.\t1.\t1.\n";
95 test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
96 test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n";
97 test.close();
98 BG = new BondGraph(true);
99 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
100
101 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
102 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
103 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
104 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
105
106 BG->ConstructBondGraph(TestMolecule);
107};
108
109
110void AnalysisBondsTest::tearDown()
111{
112 // remove the file
113 remove(filename->c_str());
114 delete(filename);
115 delete(BG);
116
117 // remove molecule
118 World::getInstance().destroyMolecule(TestMolecule);
119 // note that all the atoms are cleaned by TestMolecule
120 World::purgeInstance();
121};
122
123/** UnitTest for GetMaxMinMeanBondCount().
124 */
125void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
126{
127 double Min = 20.; // check that initialization resets these arbitrary values
128 double Mean = 200.;
129 double Max = 1e-6;
130 GetMaxMinMeanBondCount(TestMolecule, Min, Mean, Max);
131 CPPUNIT_ASSERT_EQUAL( 1., Min );
132 CPPUNIT_ASSERT_EQUAL( 1.6, Mean );
133 CPPUNIT_ASSERT_EQUAL( 4., Max );
134
135};
136
137/** UnitTest for MinMaxBondDistanceBetweenElements().
138 */
139void AnalysisBondsTest::MinMeanMaxBondDistanceBetweenElementsTest()
140{
141 double Min = 20.; // check that initialization resets these arbitrary values
142 double Mean = 2e+6;
143 double Max = 1e-6;
144 double Min2 = 20.;
145 double Mean2 = 2e+6;
146 double Max2 = 1e-6;
147 const double maxbondlength = sqrt(1.*1. + 1.*1. + .5*.5);
148 const double minbondlength = sqrt(.5*.5 + .5*.5 + .5*.5);
149 const double meanbondlength = (minbondlength+3.*maxbondlength)/4.;
150 // check bond lengths C-H
151 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, carbon, Min, Mean, Max);
152 CPPUNIT_ASSERT_EQUAL( minbondlength , Min );
153 CPPUNIT_ASSERT_EQUAL( meanbondlength , Mean );
154 CPPUNIT_ASSERT_EQUAL( maxbondlength , Max );
155
156 // check that elements are symmetric, i.e. C-H == H-C
157 MinMeanMaxBondDistanceBetweenElements(TestMolecule, carbon, hydrogen, Min2, Mean2, Max2);
158 CPPUNIT_ASSERT_EQUAL( Min , Min2 );
159 CPPUNIT_ASSERT_EQUAL( Mean , Mean2 );
160 CPPUNIT_ASSERT_EQUAL( Max , Max2 );
161
162 // check no bond case (no bonds H-H in system!)
163 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, hydrogen, Min, Mean, Max);
164 CPPUNIT_ASSERT_EQUAL( 0. , Min );
165 CPPUNIT_ASSERT_EQUAL( 0. , Mean );
166 CPPUNIT_ASSERT_EQUAL( 0. , Max );
167};
Note: See TracBrowser for help on using the repository browser.