source: src/Potentials/Specifics/PairPotential_Angle.cpp@ b3b31e

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

FIX: Default cstor of specific potentials did not allocate parameter vector.

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