source: src/Potentials/Specifics/ThreeBodyPotential_Angle.cpp@ c76b8b

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 c76b8b was 94453f1, checked in by Frederik Heber <heber@…>, 11 years ago

Added getCoordinator() to EmpiricalPotential interface.

  • implemented with all specific potentials.
  • Property mode set to 100644
File size: 8.2 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
55class Fragment;
56
57// static definitions
58const ThreeBodyPotential_Angle::ParameterNames_t
59ThreeBodyPotential_Angle::ParameterNames =
60 boost::assign::list_of<std::string>
61 ("spring_constant")
62 ("equilibrium_distance")
63 ;
64const std::string ThreeBodyPotential_Angle::potential_token("harmonic_angle");
65Coordinator::ptr ThreeBodyPotential_Angle::coordinator(new ThreeBody_Angle());
66
67ThreeBodyPotential_Angle::ThreeBodyPotential_Angle() :
68 EmpiricalPotential(),
69 params(parameters_t(MAXPARAMS, 0.))
70{
71 // have some decent defaults for parameter_derivative checking
72 params[spring_constant] = 1.;
73 params[equilibrium_distance] = 0.1;
74}
75
76ThreeBodyPotential_Angle::ThreeBodyPotential_Angle(
77 const ParticleTypes_t &_ParticleTypes
78 ) :
79 EmpiricalPotential(_ParticleTypes),
80 params(parameters_t(MAXPARAMS, 0.))
81{
82 // have some decent defaults for parameter_derivative checking
83 params[spring_constant] = 1.;
84 params[equilibrium_distance] = 0.1;
85}
86
87ThreeBodyPotential_Angle::ThreeBodyPotential_Angle(
88 const ParticleTypes_t &_ParticleTypes,
89 const double _spring_constant,
90 const double _equilibrium_distance) :
91 EmpiricalPotential(_ParticleTypes),
92 params(parameters_t(MAXPARAMS, 0.))
93{
94 params[spring_constant] = _spring_constant;
95 params[equilibrium_distance] = _equilibrium_distance;
96}
97
98void ThreeBodyPotential_Angle::setParameters(const parameters_t &_params)
99{
100 const size_t paramsDim = _params.size();
101 ASSERT( paramsDim <= getParameterDimension(),
102 "ThreeBodyPotential_Angle::setParameters() - we need not more than "
103 +toString(getParameterDimension())+" parameters.");
104 for(size_t i=0;i<paramsDim;++i)
105 params[i] = _params[i];
106
107#ifndef NDEBUG
108 parameters_t check_params(getParameters());
109 check_params.resize(paramsDim); // truncate to same size
110 ASSERT( check_params == _params,
111 "ThreeBodyPotential_Angle::setParameters() - failed, mismatch in to be set "
112 +toString(_params)+" and set "+toString(check_params)+" params.");
113#endif
114}
115
116ThreeBodyPotential_Angle::result_t
117ThreeBodyPotential_Angle::function_theta(
118 const double &r_ij,
119 const double &r_jk,
120 const double &r_ik
121 ) const
122{
123// Info info(__func__);
124 const double angle = Helpers::pow(r_ij,2) + Helpers::pow(r_jk,2) - Helpers::pow(r_ik,2);
125 const double divisor = 2.* r_ij * r_jk;
126
127// LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
128 if (divisor == 0.)
129 return 0.;
130 else
131 return angle/divisor;
132}
133
134ThreeBodyPotential_Angle::results_t
135ThreeBodyPotential_Angle::operator()(
136 const arguments_t &arguments
137 ) const
138{
139 ASSERT( arguments.size() == 3,
140 "ThreeBodyPotential_Angle::operator() - requires exactly three arguments.");
141 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
142 arguments, getParticleTypes()),
143 "ThreeBodyPotential_Angle::operator() - types don't match with ones in arguments.");
144 const argument_t &r_ij = arguments[0]; // 01
145 const argument_t &r_jk = arguments[2]; // 12
146 const argument_t &r_ik = arguments[1]; // 02
147 const result_t result =
148 params[spring_constant]
149 * Helpers::pow( function_theta(r_ij.distance, r_jk.distance, r_ik.distance) - params[equilibrium_distance], 2 );
150 return std::vector<result_t>(1, result);
151}
152
153ThreeBodyPotential_Angle::derivative_components_t
154ThreeBodyPotential_Angle::derivative(
155 const arguments_t &arguments
156 ) const
157{
158 ASSERT( arguments.size() == 3,
159 "ThreeBodyPotential_Angle::operator() - requires exactly three arguments.");
160 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
161 arguments, getParticleTypes()),
162 "ThreeBodyPotential_Angle::operator() - types don't match with ones in arguments.");
163 derivative_components_t result;
164 const argument_t &r_ij = arguments[0]; //01
165 const argument_t &r_jk = arguments[2]; //12
166 const argument_t &r_ik = arguments[1]; //02
167 result.push_back( 2. * params[spring_constant] * ( function_theta(r_ij.distance, r_jk.distance, r_ik.distance) - params[equilibrium_distance]) );
168 ASSERT( result.size() == 1,
169 "ThreeBodyPotential_Angle::operator() - we did not create exactly one component.");
170 return result;
171}
172
173ThreeBodyPotential_Angle::results_t
174ThreeBodyPotential_Angle::parameter_derivative(
175 const arguments_t &arguments,
176 const size_t index
177 ) const
178{
179 ASSERT( arguments.size() == 3,
180 "ThreeBodyPotential_Angle::parameter_derivative() - requires exactly three arguments.");
181 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
182 arguments, getParticleTypes()),
183 "ThreeBodyPotential_Angle::operator() - types don't match with ones in arguments.");
184 const argument_t &r_ij = arguments[0]; //01
185 const argument_t &r_jk = arguments[2]; //12
186 const argument_t &r_ik = arguments[1]; //02
187 switch (index) {
188 case spring_constant:
189 {
190 const result_t result =
191 Helpers::pow( function_theta(r_ij.distance, r_jk.distance, r_ik.distance) - params[equilibrium_distance], 2 );
192 return std::vector<result_t>(1, result);
193 break;
194 }
195 case equilibrium_distance:
196 {
197 const result_t result =
198 -2. * params[spring_constant]
199 * ( function_theta(r_ij.distance, r_jk.distance, r_ik.distance) - params[equilibrium_distance]);
200 return std::vector<result_t>(1, result);
201 break;
202 }
203 default:
204 ASSERT(0, "ThreeBodyPotential_Angle::parameter_derivative() - derivative to unknown parameter desired.");
205 break;
206 }
207}
208
209FunctionModel::extractor_t
210ThreeBodyPotential_Angle::getSpecificExtractor() const
211{
212 Fragment::charges_t charges;
213 charges.resize(getParticleTypes().size());
214 std::transform(getParticleTypes().begin(), getParticleTypes().end(),
215 charges.begin(), boost::lambda::_1);
216 FunctionModel::extractor_t returnfunction =
217 boost::bind(&Extractors::gatherDistancesFromFragment,
218 boost::bind(&Fragment::getPositions, _1),
219 boost::bind(&Fragment::getCharges, _1),
220 charges,
221 _2);
222 return returnfunction;
223}
224
225FunctionModel::filter_t ThreeBodyPotential_Angle::getSpecificFilter() const
226{
227 FunctionModel::filter_t returnfunction =
228 boost::bind(&Extractors::reorderArgumentsByParticleTypes,
229 boost::bind(&Extractors::filterArgumentsByParticleTypes,
230 _1,
231 getParticleTypes()),
232 getParticleTypes()
233 );
234 return returnfunction;
235}
236
237void
238ThreeBodyPotential_Angle::setParametersToRandomInitialValues(
239 const TrainingData &data)
240{
241 params[ThreeBodyPotential_Angle::spring_constant] = 1e+0*rand()/(double)RAND_MAX;// 0.2;
242 params[ThreeBodyPotential_Angle::equilibrium_distance] = -0.3;//2e+0*rand()/(double)RAND_MAX - 1.;// 1.;
243}
244
Note: See TracBrowser for help on using the repository browser.