source: src/Potentials/Specifics/unittests/PairPotential_LennardJonesUnitTest.cpp@ 35d171

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults 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 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_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 FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes 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 Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 35d171 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: 4.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 * PairPotential_LennardJonesUnitTest.cpp
25 *
26 * Created on: Jul 05, 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 "PairPotential_LennardJonesUnitTest.hpp"
42
43#include <boost/assign.hpp>
44
45#include "CodePatterns/Assert.hpp"
46
47#include "FunctionApproximation/FunctionArgument.hpp"
48#include "Potentials/Specifics/PairPotential_LennardJones.hpp"
49#include "Potentials/helpers.hpp"
50
51using namespace boost::assign;
52
53#ifdef HAVE_TESTRUNNER
54#include "UnitTestMain.hpp"
55#endif /*HAVE_TESTRUNNER*/
56
57/********************************************** Test classes **************************************/
58
59// Registers the fixture into the 'registry'
60CPPUNIT_TEST_SUITE_REGISTRATION( PairPotential_LennardJonesTest );
61
62
63void PairPotential_LennardJonesTest::setUp()
64{
65 // failing asserts should be thrown
66 ASSERT_DO(Assert::Throw);
67
68 // data is taken from gnuplot via
69 // g(x)=4*epsilon*((sigma/x)**12 - (sigma/x)**6)
70 // set table "lj.dat"
71 // set samples 10
72 // plot [1.89012:4.46595] g(x)
73 epsilon = 0.897888;
74 sigma = 1.92953;
75 input +=
76 1.89012,
77 2.17632,
78 2.46253,
79 2.74873,
80 3.03493,
81 3.32114,
82 3.60734,
83 3.89354,
84 4.17975,
85 4.46595;
86 output +=
87 0.535795,
88 -0.897154,
89 -0.638834,
90 -0.378315,
91 -0.221526,
92 -0.132813,
93 -0.0821442,
94 -0.0524131,
95 -0.0344245,
96 -0.0232099;
97
98 CPPUNIT_ASSERT_EQUAL( input.size(), output.size() );
99}
100
101
102void PairPotential_LennardJonesTest::tearDown()
103{
104}
105
106/** UnitTest for operator()
107 */
108void PairPotential_LennardJonesTest::operatorTest()
109{
110 PairPotential_LennardJones::ParticleTypes_t types =
111 boost::assign::list_of<PairPotential_LennardJones::ParticleType_t>
112 (0)(1)
113 ;
114 PairPotential_LennardJones lj(types, epsilon, sigma);
115 for (size_t index = 0; index < input.size(); ++index) {
116 argument_t arg(argument_t::indices_t(0,1), argument_t::types_t(0,1), input[index]);
117 CPPUNIT_ASSERT(
118 Helpers::isEqual(
119 output[index],
120 lj( FunctionModel::list_of_arguments_t(1, FunctionModel::arguments_t(1,arg)) )[0],
121 1.e-4/std::numeric_limits<double>::epsilon() // only compare four digits
122 )
123 );
124 }
125}
126
127/** UnitTest for derivative()
128 */
129void PairPotential_LennardJonesTest::derivativeTest()
130{
131 PairPotential_LennardJones::ParticleTypes_t types =
132 boost::assign::list_of<PairPotential_LennardJones::ParticleType_t>
133 (0)(1)
134 ;
135 PairPotential_LennardJones lj(types, epsilon, sigma);
136 argument_t arg(argument_t::indices_t(0,1), argument_t::types_t(0,1), pow(2,1./6.)*sigma);
137 // check for zero derivative at minimum
138 CPPUNIT_ASSERT(
139 Helpers::isEqual(
140 0.,
141 lj.derivative(
142 FunctionModel::list_of_arguments_t(1, FunctionModel::arguments_t(1,arg))
143 )[0],
144 1.e+6
145 )
146 );
147}
148
149
150/** UnitTest for parameter_derivative()
151 */
152void PairPotential_LennardJonesTest::parameter_derivativeTest()
153{
154 PairPotential_LennardJones::ParticleTypes_t types =
155 boost::assign::list_of<PairPotential_LennardJones::ParticleType_t>
156 (0)(1)
157 ;
158 PairPotential_LennardJones lj(types, epsilon, sigma);
159 argument_t arg(argument_t::indices_t(0,1), argument_t::types_t(0,1), pow(2,1./6.)*sigma);
160 CPPUNIT_ASSERT(
161 Helpers::isEqual(
162 -1.,
163 lj.parameter_derivative(
164 FunctionModel::list_of_arguments_t(1, FunctionModel::arguments_t(1,arg)),
165 0
166 )[0],
167 1.e+6
168 )
169 );
170 CPPUNIT_ASSERT(
171 Helpers::isEqual(
172 0.,
173 lj.parameter_derivative(
174 FunctionModel::list_of_arguments_t(1, FunctionModel::arguments_t(1,arg)),
175 1
176 )[0],
177 1.e+6
178 )
179 );
180}
Note: See TracBrowser for help on using the repository browser.