source: src/Potentials/Specifics/PairPotential_Morse.cpp@ 64cafb2

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction 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 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_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects 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 ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 64cafb2 was 7d320c, checked in by Frederik Heber <heber@…>, 10 years ago

MEMFIX: Static coordinator instances of specificv potentials need to be Memory::ignore()'d.

  • Property mode set to 100644
File size: 8.6 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_Morse.cpp
27 *
28 * Created on: Oct 03, 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_Morse.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 <cmath>
46#include <string>
47
48#include "CodePatterns/Assert.hpp"
49
50#include "FunctionApproximation/Extractors.hpp"
51#include "FunctionApproximation/TrainingData.hpp"
52#include "Potentials/helpers.hpp"
53#include "Potentials/InternalCoordinates/TwoBody_Length.hpp"
54#include "Potentials/ParticleTypeCheckers.hpp"
55#include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
56#include "RandomNumbers/RandomNumberGenerator.hpp"
57
58class Fragment;
59
60// static definitions
61const PairPotential_Morse::ParameterNames_t
62PairPotential_Morse::ParameterNames =
63 boost::assign::list_of<std::string>
64 ("spring_constant")
65 ("equilibrium_distance")
66 ("dissociation_energy")
67 ;
68const std::string PairPotential_Morse::potential_token("morse");
69Coordinator::ptr PairPotential_Morse::coordinator(Memory::ignore(new TwoBody_Length()));
70
71PairPotential_Morse::PairPotential_Morse() :
72 EmpiricalPotential(),
73 params(parameters_t(MAXPARAMS, 0.))
74{
75 // have some decent defaults for parameter_derivative checking
76 params[spring_constant] = 1.;
77 params[equilibrium_distance] = 1.;
78 params[dissociation_energy] = 0.1;
79}
80
81PairPotential_Morse::PairPotential_Morse(
82 const ParticleTypes_t &_ParticleTypes
83 ) :
84 EmpiricalPotential(_ParticleTypes),
85 params(parameters_t(MAXPARAMS, 0.))
86{
87 // have some decent defaults for parameter_derivative checking
88 params[spring_constant] = 1.;
89 params[equilibrium_distance] = 1.;
90 params[dissociation_energy] = 0.1;
91}
92
93PairPotential_Morse::PairPotential_Morse(
94 const ParticleTypes_t &_ParticleTypes,
95 const double _spring_constant,
96 const double _equilibrium_distance,
97 const double _dissociation_energy) :
98 EmpiricalPotential(_ParticleTypes),
99 params(parameters_t(MAXPARAMS, 0.))
100{
101 params[spring_constant] = _spring_constant;
102 params[equilibrium_distance] = _equilibrium_distance;
103 params[dissociation_energy] = _dissociation_energy;
104}
105
106void PairPotential_Morse::setParameters(const parameters_t &_params)
107{
108 const size_t paramsDim = _params.size();
109 ASSERT( paramsDim <= getParameterDimension(),
110 "PairPotential_Morse::setParameters() - we need not more than "
111 +toString(getParameterDimension())+" parameters.");
112 for(size_t i=0;i<paramsDim;++i)
113 params[i] = _params[i];
114
115#ifndef NDEBUG
116 parameters_t check_params(getParameters());
117 check_params.resize(paramsDim); // truncate to same size
118 ASSERT( check_params == _params,
119 "PairPotential_Morse::setParameters() - failed, mismatch in to be set "
120 +toString(_params)+" and set "+toString(check_params)+" params.");
121#endif
122}
123
124PairPotential_Morse::results_t
125PairPotential_Morse::operator()(
126 const list_of_arguments_t &listarguments
127 ) const
128{
129 result_t result = 0.;
130 for(list_of_arguments_t::const_iterator iter = listarguments.begin();
131 iter != listarguments.end(); ++iter) {
132 const arguments_t &arguments = *iter;
133 ASSERT( arguments.size() == 1,
134 "PairPotential_Morse::operator() - requires exactly one argument.");
135 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
136 arguments, getParticleTypes()),
137 "PairPotential_Morse::operator() - types don't match with ones in arguments.");
138 const argument_t &r_ij = arguments[0];
139 // Maple: f(r,D,k,R,c) := D * (1 - exp(-k*(r-R)))^(2)+c
140 result +=
141 params[dissociation_energy] * Helpers::pow( 1.
142 - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])),2);
143 }
144 return std::vector<result_t>(1, result);
145}
146
147PairPotential_Morse::derivative_components_t
148PairPotential_Morse::derivative(
149 const list_of_arguments_t &listarguments
150 ) const
151{
152 result_t result = 0.;
153 for(list_of_arguments_t::const_iterator iter = listarguments.begin();
154 iter != listarguments.end(); ++iter) {
155 const arguments_t &arguments = *iter;
156 ASSERT( arguments.size() == 1,
157 "PairPotential_Morse::operator() - requires exactly one argument.");
158 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
159 arguments, getParticleTypes()),
160 "PairPotential_Morse::operator() - types don't match with ones in arguments.");
161 const argument_t &r_ij = arguments[0];
162 // Maple result: 2*D*(1-exp(-k*(r-R)))*k*exp(-k*(r-R))
163 result +=
164 2. * params[dissociation_energy]
165 * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
166 * (- params[spring_constant]) * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]));
167 }
168 return derivative_components_t(1, result);
169}
170
171PairPotential_Morse::results_t
172PairPotential_Morse::parameter_derivative(
173 const list_of_arguments_t &listarguments,
174 const size_t index
175 ) const
176{
177 result_t result = 0.;
178 for(list_of_arguments_t::const_iterator iter = listarguments.begin();
179 iter != listarguments.end(); ++iter) {
180 const arguments_t &arguments = *iter;
181 ASSERT( arguments.size() == 1,
182 "PairPotential_Morse::parameter_derivative() - requires exactly one argument.");
183 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
184 arguments, getParticleTypes()),
185 "PairPotential_Morse::operator() - types don't match with ones in arguments.");
186 const argument_t &r_ij = arguments[0];
187 switch (index) {
188 case spring_constant:
189 {
190 // Maple result: -2*D*(1-exp(-k*(r-R)))*(-r+R)*exp(-k*(r-R))
191 result +=
192 - 2. * params[dissociation_energy]
193 * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
194 * (- r_ij.distance + params[equilibrium_distance])
195 * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]))
196 ;
197 break;
198 }
199 case equilibrium_distance:
200 {
201 // Maple result: -2*D*(1-exp(-k*(r-R)))*k*exp(-k*(r-R))
202 result +=
203 - 2. * params[dissociation_energy]
204 * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
205 * params[spring_constant] * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]))
206 ;
207 break;
208 }
209 case dissociation_energy:
210 {
211 // Maple result: (1-exp(-k*(r-R)))^2
212 result +=
213 Helpers::pow(1.
214 - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])),2);
215 break;
216 }
217 default:
218 ASSERT(0, "PairPotential_Morse::parameter_derivative() - derivative to unknown parameter desired.");
219 break;
220 }
221 }
222 return results_t(1, result);
223}
224
225FunctionModel::filter_t PairPotential_Morse::getSpecificFilter() const
226{
227 FunctionModel::filter_t returnfunction =
228 boost::bind(&Extractors::filterArgumentsByParticleTypes,
229 _1,
230 getParticleTypes());
231 return returnfunction;
232}
233
234void
235PairPotential_Morse::setParametersToRandomInitialValues(
236 const TrainingData &data)
237{
238 RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
239 const double rng_min = random.min();
240 const double rng_max = random.max();
241 params[PairPotential_Morse::dissociation_energy] = 1e+0*(random()/(rng_max-rng_min));// 0.5;
242 params[PairPotential_Morse::spring_constant] = 1e+0*(random()/(rng_max-rng_min));// 1.;
243 params[PairPotential_Morse::equilibrium_distance] = 3e+0*(random()/(rng_max-rng_min));//2.9;
244}
245
Note: See TracBrowser for help on using the repository browser.