source: src/Potentials/Specifics/ThreeBodyPotential_Angle.cpp@ 1dbbeb

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 1dbbeb was 0932c2, checked in by Frederik Heber <heber@…>, 11 years ago

FIX: RandomNumberEngine_Encapsulation::clone() did not set the seed obtained from its prototype.

  • this caused all engines to always start with default seed of 1, irrespective of the set parameter. The engine is always cloned from prototypes in the factory that can be manipulated to change their parameters. Hence, clone needs to set the seed (the engine's only parameter).
  • EmpiricalPotentials now use RandomNumberGenerator to obtain random starting values.
  • TESTFIX: fit-potential regression tests now use fixed seed in order to always take the same amount of time (some test runs in debug mode take very long because of ill-chosen random values).
  • Property mode set to 100644
File size: 8.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
7 *
8 *
9 * This file is part of MoleCuilder.
10 *
11 * MoleCuilder is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * MoleCuilder is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25/*
26 * ThreeBodyPotential_Angle.cpp
27 *
28 * Created on: Oct 11, 2012
29 * Author: heber
30 */
31
32
33// include config.h
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37
38#include "CodePatterns/MemDebug.hpp"
39
40#include "ThreeBodyPotential_Angle.hpp"
41
42#include <boost/assign/list_of.hpp> // for 'map_list_of()'
43#include <boost/bind.hpp>
44#include <boost/lambda/lambda.hpp>
45#include <string>
46
47#include "CodePatterns/Assert.hpp"
48
49#include "FunctionApproximation/Extractors.hpp"
50#include "FunctionApproximation/TrainingData.hpp"
51#include "Potentials/helpers.hpp"
52#include "Potentials/InternalCoordinates/ThreeBody_Angle.hpp"
53#include "Potentials/ParticleTypeCheckers.hpp"
54#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
55#include "RandomNumbers/RandomNumberGenerator.hpp"
56
57class Fragment;
58
59// static definitions
60const ThreeBodyPotential_Angle::ParameterNames_t
61ThreeBodyPotential_Angle::ParameterNames =
62 boost::assign::list_of<std::string>
63 ("spring_constant")
64 ("equilibrium_distance")
65 ;
66const std::string ThreeBodyPotential_Angle::potential_token("harmonic_angle");
67Coordinator::ptr ThreeBodyPotential_Angle::coordinator(new ThreeBody_Angle());
68
69ThreeBodyPotential_Angle::ThreeBodyPotential_Angle() :
70 EmpiricalPotential(),
71 params(parameters_t(MAXPARAMS, 0.))
72{
73 // have some decent defaults for parameter_derivative checking
74 params[spring_constant] = 1.;
75 params[equilibrium_distance] = 0.1;
76}
77
78ThreeBodyPotential_Angle::ThreeBodyPotential_Angle(
79 const ParticleTypes_t &_ParticleTypes
80 ) :
81 EmpiricalPotential(_ParticleTypes),
82 params(parameters_t(MAXPARAMS, 0.))
83{
84 // have some decent defaults for parameter_derivative checking
85 params[spring_constant] = 1.;
86 params[equilibrium_distance] = 0.1;
87}
88
89ThreeBodyPotential_Angle::ThreeBodyPotential_Angle(
90 const ParticleTypes_t &_ParticleTypes,
91 const double _spring_constant,
92 const double _equilibrium_distance) :
93 EmpiricalPotential(_ParticleTypes),
94 params(parameters_t(MAXPARAMS, 0.))
95{
96 params[spring_constant] = _spring_constant;
97 params[equilibrium_distance] = _equilibrium_distance;
98}
99
100void ThreeBodyPotential_Angle::setParameters(const parameters_t &_params)
101{
102 const size_t paramsDim = _params.size();
103 ASSERT( paramsDim <= getParameterDimension(),
104 "ThreeBodyPotential_Angle::setParameters() - we need not more than "
105 +toString(getParameterDimension())+" parameters.");
106 for(size_t i=0;i<paramsDim;++i)
107 params[i] = _params[i];
108
109#ifndef NDEBUG
110 parameters_t check_params(getParameters());
111 check_params.resize(paramsDim); // truncate to same size
112 ASSERT( check_params == _params,
113 "ThreeBodyPotential_Angle::setParameters() - failed, mismatch in to be set "
114 +toString(_params)+" and set "+toString(check_params)+" params.");
115#endif
116}
117
118ThreeBodyPotential_Angle::result_t
119ThreeBodyPotential_Angle::function_theta(
120 const double &r_ij,
121 const double &r_jk,
122 const double &r_ik
123 ) const
124{
125// Info info(__func__);
126 const double angle = Helpers::pow(r_ij,2) + Helpers::pow(r_jk,2) - Helpers::pow(r_ik,2);
127 const double divisor = 2.* r_ij * r_jk;
128
129// LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
130 if (divisor == 0.)
131 return 0.;
132 else
133 return angle/divisor;
134}
135
136ThreeBodyPotential_Angle::results_t
137ThreeBodyPotential_Angle::operator()(
138 const arguments_t &arguments
139 ) const
140{
141 ASSERT( arguments.size() == 3,
142 "ThreeBodyPotential_Angle::operator() - requires exactly three arguments.");
143 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
144 arguments, getParticleTypes()),
145 "ThreeBodyPotential_Angle::operator() - types don't match with ones in arguments.");
146 const argument_t &r_ij = arguments[0]; // 01
147 const argument_t &r_jk = arguments[2]; // 12
148 const argument_t &r_ik = arguments[1]; // 02
149 const result_t result =
150 params[spring_constant]
151 * Helpers::pow( function_theta(r_ij.distance, r_jk.distance, r_ik.distance) - params[equilibrium_distance], 2 );
152 return std::vector<result_t>(1, result);
153}
154
155ThreeBodyPotential_Angle::derivative_components_t
156ThreeBodyPotential_Angle::derivative(
157 const arguments_t &arguments
158 ) const
159{
160 ASSERT( arguments.size() == 3,
161 "ThreeBodyPotential_Angle::operator() - requires exactly three arguments.");
162 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
163 arguments, getParticleTypes()),
164 "ThreeBodyPotential_Angle::operator() - types don't match with ones in arguments.");
165 derivative_components_t result;
166 const argument_t &r_ij = arguments[0]; //01
167 const argument_t &r_jk = arguments[2]; //12
168 const argument_t &r_ik = arguments[1]; //02
169 result.push_back( 2. * params[spring_constant] * ( function_theta(r_ij.distance, r_jk.distance, r_ik.distance) - params[equilibrium_distance]) );
170 ASSERT( result.size() == 1,
171 "ThreeBodyPotential_Angle::operator() - we did not create exactly one component.");
172 return result;
173}
174
175ThreeBodyPotential_Angle::results_t
176ThreeBodyPotential_Angle::parameter_derivative(
177 const arguments_t &arguments,
178 const size_t index
179 ) const
180{
181 ASSERT( arguments.size() == 3,
182 "ThreeBodyPotential_Angle::parameter_derivative() - requires exactly three arguments.");
183 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
184 arguments, getParticleTypes()),
185 "ThreeBodyPotential_Angle::operator() - types don't match with ones in arguments.");
186 const argument_t &r_ij = arguments[0]; //01
187 const argument_t &r_jk = arguments[2]; //12
188 const argument_t &r_ik = arguments[1]; //02
189 switch (index) {
190 case spring_constant:
191 {
192 const result_t result =
193 Helpers::pow( function_theta(r_ij.distance, r_jk.distance, r_ik.distance) - params[equilibrium_distance], 2 );
194 return std::vector<result_t>(1, result);
195 break;
196 }
197 case equilibrium_distance:
198 {
199 const result_t result =
200 -2. * params[spring_constant]
201 * ( function_theta(r_ij.distance, r_jk.distance, r_ik.distance) - params[equilibrium_distance]);
202 return std::vector<result_t>(1, result);
203 break;
204 }
205 default:
206 ASSERT(0, "ThreeBodyPotential_Angle::parameter_derivative() - derivative to unknown parameter desired.");
207 break;
208 }
209 return std::vector<result_t>(1);
210}
211
212FunctionModel::extractor_t
213ThreeBodyPotential_Angle::getSpecificExtractor() const
214{
215 Fragment::charges_t charges;
216 charges.resize(getParticleTypes().size());
217 std::transform(getParticleTypes().begin(), getParticleTypes().end(),
218 charges.begin(), boost::lambda::_1);
219 FunctionModel::extractor_t returnfunction =
220 boost::bind(&Extractors::gatherDistancesFromFragment,
221 boost::bind(&Fragment::getPositions, _1),
222 boost::bind(&Fragment::getCharges, _1),
223 charges,
224 _2);
225 return returnfunction;
226}
227
228FunctionModel::filter_t ThreeBodyPotential_Angle::getSpecificFilter() const
229{
230 FunctionModel::filter_t returnfunction =
231 boost::bind(&Extractors::reorderArgumentsByParticleTypes,
232 boost::bind(&Extractors::filterArgumentsByParticleTypes,
233 _1,
234 getParticleTypes()),
235 getParticleTypes()
236 );
237 return returnfunction;
238}
239
240void
241ThreeBodyPotential_Angle::setParametersToRandomInitialValues(
242 const TrainingData &data)
243{
244 RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
245 const double rng_min = random.min();
246 const double rng_max = random.max();
247 params[ThreeBodyPotential_Angle::spring_constant] = 1e+0*(random()/(rng_max-rng_min));// 0.2;
248 params[ThreeBodyPotential_Angle::equilibrium_distance] = -0.3;//2e+0*(random()/(rng_max-rng_min)) - 1.;// 1.;
249}
250
Note: See TracBrowser for help on using the repository browser.