source: src/unittests/analysisbondsunittest.cpp@ 986ed3

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

Merge commit 'jupiter/MoleculeStartEndSwitch' into CommandLineActionMapping

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/helpers.hpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

Integration of MoleculeStartEndSwitch had the following consequences:

  • no more AtomCount -> getAtomCount()
  • no more start/end -> begin(), end() and iterator
  • no more decent ordering in atomic ids (hence, Simple_configuration/8 and Domain/5, Domain/6 now check by comparing sorted xyz, not confs)

There is still a huge problem with bonds. One test runs into an endless loop.

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 "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 // get elements
44 hydrogen = World::getInstance().getPeriode()->FindElement(1);
45 carbon = World::getInstance().getPeriode()->FindElement(6);
46 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
47 CPPUNIT_ASSERT(carbon != NULL && "could not find element carbon");
48
49 // construct molecule (tetraeder of hydrogens)
50 TestMolecule = World::getInstance().createMolecule();
51 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
52 Walker = World::getInstance().createAtom();
53 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
54 Walker->type = hydrogen;
55 *Walker->node = Vector(1.5, 0., 1.5 );
56 TestMolecule->AddAtom(Walker);
57 Walker = World::getInstance().createAtom();
58 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
59 Walker->type = hydrogen;
60 *Walker->node = Vector(0., 1.5, 1.5 );
61 TestMolecule->AddAtom(Walker);
62 Walker = World::getInstance().createAtom();
63 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
64 Walker->type = hydrogen;
65 *Walker->node = Vector(1.5, 1.5, 0. );
66 TestMolecule->AddAtom(Walker);
67 Walker = World::getInstance().createAtom();
68 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
69 Walker->type = hydrogen;
70 *Walker->node = Vector(0., 0., 0. );
71 TestMolecule->AddAtom(Walker);
72 Walker = World::getInstance().createAtom();
73 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
74 Walker->type = carbon;
75 *Walker->node = Vector(0.5, 0.5, 0.5 );
76 TestMolecule->AddAtom(Walker);
77
78 // check that TestMolecule was correctly constructed
79 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 5 );
80
81 // create a small file with table
82 filename = new string("test.dat");
83 CPPUNIT_ASSERT(filename != NULL && "could not create string");
84 ofstream test(filename->c_str());
85 test << ".\tH\tHe\tLi\tBe\tB\tC\n";
86 test << "H\t1.\t1.\t1.\t1.\t1.\t1.2\n";
87 test << "He\t1.\t1.\t1.\t1.\t1.\t1.\n";
88 test << "Li\t1.\t1.\t1.\t1.\t1.\t1.\n";
89 test << "Be\t1.\t1.\t1.\t1.\t1.\t1.\n";
90 test << "B\t1.\t1.\t1.\t1.\t1.\t1.\n";
91 test << "C\t1.2\t1.\t1.\t1.\t1.\t1.5\n";
92 test.close();
93 BG = new BondGraph(true);
94 CPPUNIT_ASSERT(BG != NULL && "could not create BondGraph");
95
96 CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
97 CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
98 CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,5) );
99 CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(5,5) );
100
101 BG->ConstructBondGraph(TestMolecule);
102};
103
104
105void AnalysisBondsTest::tearDown()
106{
107 // remove the file
108 remove(filename->c_str());
109 delete(filename);
110 delete(BG);
111
112 // remove molecule
113 World::getInstance().destroyMolecule(TestMolecule);
114 // note that all the atoms are cleaned by TestMolecule
115 World::purgeInstance();
116};
117
118/** UnitTest for GetMaxMinMeanBondCount().
119 */
120void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
121{
122 double Min = 20.; // check that initialization resets these arbitrary values
123 double Mean = 200.;
124 double Max = 1e-6;
125 GetMaxMinMeanBondCount(TestMolecule, Min, Mean, Max);
126 CPPUNIT_ASSERT_EQUAL( 1., Min );
127 CPPUNIT_ASSERT_EQUAL( 1.6, Mean );
128 CPPUNIT_ASSERT_EQUAL( 4., Max );
129
130};
131
132/** UnitTest for MinMaxBondDistanceBetweenElements().
133 */
134void AnalysisBondsTest::MinMeanMaxBondDistanceBetweenElementsTest()
135{
136 double Min = 20.; // check that initialization resets these arbitrary values
137 double Mean = 2e+6;
138 double Max = 1e-6;
139 double Min2 = 20.;
140 double Mean2 = 2e+6;
141 double Max2 = 1e-6;
142 const double maxbondlength = sqrt(1.*1. + 1.*1. + .5*.5);
143 const double minbondlength = sqrt(.5*.5 + .5*.5 + .5*.5);
144 const double meanbondlength = (minbondlength+3.*maxbondlength)/4.;
145 // check bond lengths C-H
146 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, carbon, Min, Mean, Max);
147 CPPUNIT_ASSERT_EQUAL( minbondlength , Min );
148 CPPUNIT_ASSERT_EQUAL( meanbondlength , Mean );
149 CPPUNIT_ASSERT_EQUAL( maxbondlength , Max );
150
151 // check that elements are symmetric, i.e. C-H == H-C
152 MinMeanMaxBondDistanceBetweenElements(TestMolecule, carbon, hydrogen, Min2, Mean2, Max2);
153 CPPUNIT_ASSERT_EQUAL( Min , Min2 );
154 CPPUNIT_ASSERT_EQUAL( Mean , Mean2 );
155 CPPUNIT_ASSERT_EQUAL( Max , Max2 );
156
157 // check no bond case (no bonds H-H in system!)
158 MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, hydrogen, Min, Mean, Max);
159 CPPUNIT_ASSERT_EQUAL( 0. , Min );
160 CPPUNIT_ASSERT_EQUAL( 0. , Mean );
161 CPPUNIT_ASSERT_EQUAL( 0. , Max );
162};
Note: See TracBrowser for help on using the repository browser.