source: src/Potentials/unittests/CompoundPotentialUnitTest.cpp@ 64cafb2

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator 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_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 64cafb2 was e1fe7e, checked in by Frederik Heber <heber@…>, 11 years ago

FunctionModel now uses list_of_arguments to split sequence of subsets of distances.

  • this fixes ambiguities with the set of distances: Imagine the distances within a water molecule as OH (A) and HH (B). We then may have a sequence of argument_t as AABAAB. And with the current implementation of CompoundPotential::splitUpArgumentsByModels() we would always choose the latter (and more complex) model. Hence, we make two calls to TriplePotential_Angle, instead of calls twice to PairPotential_Harmonic for A, one to PairPotential_Harmonic for B, and once to TriplePotential_Angle for AAB.
  • now, we new list looks like A,A,B,AAB where each tuple of distances can be uniquely associated with a specific potential.
  • changed signatures of EmpiricalPotential::operator(), ::derivative(), ::parameter_derivative(). This involved changing all of the current specific potentials and CompoundPotential.
  • TrainingData must discern between the InputVector_t (just all distances) and the FilteredInputVector_t (tuples of subsets of distances).
  • FunctionApproximation now has list_of_arguments_t as parameter to evaluate() and evaluate_derivative().
  • DOCU: docu change in TrainingData.
  • Property mode set to 100644
File size: 6.7 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 (i.e. this simulates a water molecule)
95 {
96 // add nodes
97 nodes +=
98 std::make_pair(FragmentNode(0,2),1),
99 std::make_pair(FragmentNode(1,1),2);
100
101 // add edges
102 edges +=
103 std::make_pair(FragmentEdge(0,1),2);
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 2.*0.467226+d,
128 2.*0.183388+d,
129 2.*0.0532649+d,
130 2.*0.00609808+d,
131 2.*0.00160056+d,
132 2.*0.0172506+d,
133 2.*0.0407952+d,
134 2.*0.0658475+d,
135 2.*0.0893157+d,
136 2.*0.109914+d;
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 firstarg(argument_t::indices_t(0,1), argument_t::types_t(0,1), input[index]);
160 argument_t secondarg(argument_t::indices_t(0,2), argument_t::types_t(0,1), input[index]);
161 FunctionModel::list_of_arguments_t listargs;
162 listargs += FunctionModel::arguments_t(1,firstarg),FunctionModel::arguments_t(1,secondarg);
163 const double result = compound( listargs )[0];
164 CPPUNIT_ASSERT(
165 Helpers::isEqual(
166 output[index],
167 result,
168 1.e-4/std::numeric_limits<double>::epsilon() // only compare four digits
169 )
170 );
171 }
172}
173
174/** UnitTest for derivative()
175 */
176//void CompoundPotentialTest::derivativeTest()
177//{
178// CompoundPotential compound(*graph);
179// CompoundPotential::parameters_t params;
180// params += d,a,c,D;
181// compound.setParameters(params);
182// argument_t firstarg(argument_t::indices_t(0,1), argument_t::types_t(0,1), input[index]);
183// argument_t secondarg(argument_t::indices_t(0,2), argument_t::types_t(0,1), input[index]);
184// FunctionModel::arguments_t args;
185// args += firstarg,secondarg;
186// const double result = compound.derivative( args )[0]
187// CPPUNIT_ASSERT(
188// Helpers::isEqual(
189// 0.,
190// result,
191// 1.e+6
192// )
193// );
194//}
195
196
197/** UnitTest for parameter_derivative()
198 */
199void CompoundPotentialTest::parameter_derivativeTest()
200{
201 CompoundPotential compound(*graph);
202 CompoundPotential::parameters_t params;
203 params += d,a,c,D;
204 compound.setParameters(params);
205 argument_t firstarg(argument_t::indices_t(0,1), argument_t::types_t(0,1), c);
206 argument_t secondarg(argument_t::indices_t(0,2), argument_t::types_t(0,1), c);
207 FunctionModel::list_of_arguments_t listargs;
208 listargs += FunctionModel::arguments_t(1,firstarg),FunctionModel::arguments_t(1,secondarg);
209 {
210 const double result =
211 compound.parameter_derivative(
212 listargs,
213 0)[0];
214 CPPUNIT_ASSERT(
215 Helpers::isEqual(
216 1.,
217 result,
218 1.e+6
219 )
220 );
221 }
222 {
223 const double result =
224 compound.parameter_derivative(
225 listargs,
226 1)[0];
227 CPPUNIT_ASSERT(
228 Helpers::isEqual(
229 0.,
230 result,
231 1.e+6
232 )
233 );
234 }
235 {
236 const double result =
237 compound.parameter_derivative(
238 listargs,
239 2)[0];
240 CPPUNIT_ASSERT(
241 Helpers::isEqual(
242 0.,
243 result,
244 1.e+6
245 )
246 );
247 }
248 {
249 const double result =
250 compound.parameter_derivative(
251 listargs,
252 3)[0];
253 CPPUNIT_ASSERT(
254 Helpers::isEqual(
255 0.,
256 result,
257 1.e+6
258 )
259 );
260 }
261}
Note: See TracBrowser for help on using the repository browser.