source: src/Potentials/Specifics/PairPotential_Morse.cpp@ acc9b1

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

FIX: Added new copyright lines to files in src/Potentials, too.

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