source: src/Potentials/Specifics/FourBodyPotential_Torsion.cpp@ f4496d

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