source: src/Potentials/unittests/CompoundPotentialUnitTest.cpp@ 7e5b94

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

CompoundPotential now combines ConstantPotential and PairPotential_Morse successfully.

  • we set PairPotential_Morse::energy_offset to 0 as default value, but we need to remove the offsets fully from all potentials.
  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * CompoundPotentialUnitTest.cpp
25 *
26 * Created on: May 08, 2013
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include "CompoundPotentialUnitTest.hpp"
42
43#include <boost/assign.hpp>
44
45#include "CodePatterns/Assert.hpp"
46
47#include "FunctionApproximation/FunctionArgument.hpp"
48#include "Potentials/CompoundPotential.hpp"
49#include "Potentials/helpers.hpp"
50#include "Potentials/PotentialFactory.hpp"
51#include "Potentials/PotentialRegistry.hpp"
52#include "Potentials/Specifics/ConstantPotential.hpp"
53#include "Potentials/Specifics/PairPotential_Morse.hpp"
54
55using namespace boost::assign;
56
57#ifdef HAVE_TESTRUNNER
58#include "UnitTestMain.hpp"
59#endif /*HAVE_TESTRUNNER*/
60
61/********************************************** Test classes **************************************/
62
63// Registers the fixture into the 'registry'
64CPPUNIT_TEST_SUITE_REGISTRATION( CompoundPotentialTest );
65
66
67void CompoundPotentialTest::setUp()
68{
69 // failing asserts should be thrown
70 ASSERT_DO(Assert::Throw);
71
72 // register MorsePotential with registry
73 {
74 PairPotential_Morse::ParticleTypes_t types =
75 boost::assign::list_of<PairPotential_Morse::ParticleType_t>
76 (0)(1)
77 ;
78 EmpiricalPotential *morse =
79 PotentialFactory::getInstance().createInstance(
80 std::string("morse"), types);
81 PotentialRegistry::getInstance().registerInstance(morse);
82 morse = NULL;
83 }
84 // register ConstantPotential with registry
85 {
86 ConstantPotential::ParticleTypes_t types;
87 EmpiricalPotential *constant =
88 PotentialFactory::getInstance().createInstance(
89 std::string("constant"), types);
90 PotentialRegistry::getInstance().registerInstance(constant);
91 constant = NULL;
92 }
93
94 // create graph
95 {
96 // add nodes
97 nodes +=
98 std::make_pair(FragmentNode(0,1),1),
99 std::make_pair(FragmentNode(1,1),1);
100
101 // add edges
102 edges +=
103 std::make_pair(FragmentEdge(0,1),1);
104
105 // construct graph
106 graph = new HomologyGraph(nodes, edges);
107 }
108
109 // data is taken from gnuplot via set table "morse.dat" with
110 // g(x)=D*(1- exp(-a*(x-c)))**2+d
111 a = 0.897888;
112 c = 2.92953;
113 d = -78.9883;
114 D = 0.196289;
115 input +=
116 1.89012,
117 2.17632,
118 2.46253,
119 2.74873,
120 3.03493,
121 3.32114,
122 3.60734,
123 3.89354,
124 4.17974,
125 4.46595;
126 output +=
127 -78.5211,
128 -78.8049,
129 -78.935,
130 -78.9822,
131 -78.9867,
132 -78.971,
133 -78.9475,
134 -78.9225,
135 -78.899,
136 -78.8784;
137
138 CPPUNIT_ASSERT_EQUAL( input.size(), output.size() );
139}
140
141
142void CompoundPotentialTest::tearDown()
143{
144 delete graph;
145 PotentialFactory::purgeInstance();
146 PotentialRegistry::getInstance().cleanup();
147 PotentialRegistry::purgeInstance();
148}
149
150/** UnitTest for operator()
151 */
152void CompoundPotentialTest::operatorTest()
153{
154 CompoundPotential compound(*graph);
155 CompoundPotential::parameters_t params;
156 params += d,a,c,D;
157 compound.setParameters(params);
158 for (size_t index = 0; index < input.size(); ++index) {
159 argument_t arg(argument_t::indices_t(0,1), argument_t::types_t(0,1), input[index]);
160 const double result = compound( FunctionModel::arguments_t(1,arg) )[0];
161 CPPUNIT_ASSERT(
162 Helpers::isEqual(
163 output[index],
164 result,
165 1.e-4/std::numeric_limits<double>::epsilon() // only compare four digits
166 )
167 );
168 }
169}
170
171/** UnitTest for derivative()
172 */
173//void CompoundPotentialTest::derivativeTest()
174//{
175// CompoundPotential compound(*graph);
176// CompoundPotential::parameters_t params;
177// params += d,a,c,D;
178// compound.setParameters(params);
179// argument_t arg(argument_t::indices_t(0,1), argument_t::types_t(0,1), c);
180// const double result = compound.derivative(FunctionModel::arguments_t(1,arg))[0]
181// CPPUNIT_ASSERT(
182// Helpers::isEqual(
183// 0.,
184// result,
185// 1.e+6
186// )
187// );
188//}
189
190
191/** UnitTest for parameter_derivative()
192 */
193void CompoundPotentialTest::parameter_derivativeTest()
194{
195 CompoundPotential compound(*graph);
196 CompoundPotential::parameters_t params;
197 params += d,a,c,D;
198 compound.setParameters(params);
199 argument_t arg(argument_t::indices_t(0,1), argument_t::types_t(0,1), c);
200 {
201 const double result =
202 compound.parameter_derivative(
203 FunctionModel::arguments_t(1,arg),
204 0)[0];
205 CPPUNIT_ASSERT(
206 Helpers::isEqual(
207 1.,
208 result,
209 1.e+6
210 )
211 );
212 }
213 {
214 const double result =
215 compound.parameter_derivative(
216 FunctionModel::arguments_t(1,arg),
217 1)[0];
218 CPPUNIT_ASSERT(
219 Helpers::isEqual(
220 0.,
221 result,
222 1.e+6
223 )
224 );
225 }
226 {
227 const double result =
228 compound.parameter_derivative(
229 FunctionModel::arguments_t(1,arg),
230 2)[0];
231 CPPUNIT_ASSERT(
232 Helpers::isEqual(
233 0.,
234 result,
235 1.e+6
236 )
237 );
238 }
239 {
240 const double result =
241 compound.parameter_derivative(
242 FunctionModel::arguments_t(1,arg),
243 3)[0];
244 CPPUNIT_ASSERT(
245 Helpers::isEqual(
246 0.,
247 result,
248 1.e+6
249 )
250 );
251 }
252}
Note: See TracBrowser for help on using the repository browser.