source: src/unittests/AnalysisBondsUnitTest.cpp@ 4e855e

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

BondGraph::LoadBondLengthTable() now accepts istream instead of const char *.

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