source: src/Potentials/Specifics/PairPotential_Morse.cpp@ 55fe788

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

All specific Potentials now assert that arguments have charges matching with internal ParticleTypes_t.

  • this ensures that we don't have to pick indices.first == 0 or something similar spooky anymore.
  • TESTFIX: Modified Potentials/Specifics/unittests that now need to specify the (correct) types in each argument_t.
  • Property mode set to 100644
File size: 7.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. 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 * PairPotential_Morse.cpp
26 *
27 * Created on: Oct 03, 2012
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 "PairPotential_Morse.hpp"
40
41#include <boost/assign/list_of.hpp> // for 'map_list_of()'
42#include <cmath>
43#include <string>
44
45#include "CodePatterns/Assert.hpp"
46
47#include "Potentials/helpers.hpp"
48
49// static definitions
50const PairPotential_Morse::ParameterNames_t
51PairPotential_Morse::ParameterNames =
52 boost::assign::list_of<std::string>
53 ("spring_constant")
54 ("equilibrium_distance")
55 ("dissociation_energy")
56 ("") //energy_offset
57 ;
58const std::string PairPotential_Morse::potential_token("morse");
59
60PairPotential_Morse::PairPotential_Morse(
61 const ParticleTypes_t &_ParticleTypes
62 ) :
63 SerializablePotential(_ParticleTypes),
64 params(parameters_t(MAXPARAMS, 0.))
65{}
66
67PairPotential_Morse::PairPotential_Morse(
68 const ParticleTypes_t &_ParticleTypes,
69 const double _spring_constant,
70 const double _equilibrium_distance,
71 const double _dissociation_energy,
72 const double _energy_offset) :
73 SerializablePotential(_ParticleTypes),
74 params(parameters_t(MAXPARAMS, 0.))
75{
76 params[spring_constant] = _spring_constant;
77 params[equilibrium_distance] = _equilibrium_distance;
78 params[dissociation_energy] = _dissociation_energy;
79 params[energy_offset] = _energy_offset;
80}
81
82void PairPotential_Morse::setParameters(const parameters_t &_params)
83{
84 const size_t paramsDim = _params.size();
85 ASSERT( paramsDim <= getParameterDimension(),
86 "PairPotential_Morse::setParameters() - we need not more than "
87 +toString(getParameterDimension())+" parameters.");
88 for(size_t i=0;i<paramsDim;++i)
89 params[i] = _params[i];
90
91#ifndef NDEBUG
92 parameters_t check_params(getParameters());
93 check_params.resize(paramsDim); // truncate to same size
94 ASSERT( check_params == _params,
95 "PairPotential_Morse::setParameters() - failed, mismatch in to be set "
96 +toString(_params)+" and set "+toString(check_params)+" params.");
97#endif
98}
99
100PairPotential_Morse::results_t
101PairPotential_Morse::operator()(
102 const arguments_t &arguments
103 ) const
104{
105 ASSERT( arguments.size() == 1,
106 "PairPotential_Morse::operator() - requires exactly one argument.");
107 ASSERT( arguments[0].types.first == getParticleTypes()[0],
108 "PairPotential_Morse::operator() - first charge "
109 +toString(arguments[0].types.first)+" is not "+toString(getParticleTypes()[0]));
110 ASSERT( arguments[0].types.second == getParticleTypes()[1],
111 "PairPotential_Morse::operator() - second charge "
112 +toString(arguments[0].types.second)+" is not "+toString(getParticleTypes()[1]));
113 const argument_t &r_ij = arguments[0];
114 // Maple: f(r,D,k,R,c) := D * (1 - exp(-k*(r-R)))^(2)+c
115 const result_t result =
116 params[dissociation_energy] * Helpers::pow( 1.
117 - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])),2)
118 + params[energy_offset];
119 return std::vector<result_t>(1, result);
120}
121
122PairPotential_Morse::derivative_components_t
123PairPotential_Morse::derivative(
124 const arguments_t &arguments
125 ) const
126{
127 ASSERT( arguments.size() == 1,
128 "PairPotential_Morse::operator() - requires exactly one argument.");
129 ASSERT( arguments[0].types.first == getParticleTypes()[0],
130 "PairPotential_Morse::derivative() - first charge "
131 +toString(arguments[0].types.first)+" is not "+toString(getParticleTypes()[0]));
132 ASSERT( arguments[0].types.second == getParticleTypes()[1],
133 "PairPotential_Morse::derivative() - second charge "
134 +toString(arguments[0].types.second)+" is not "+toString(getParticleTypes()[1]));
135 derivative_components_t result;
136 const argument_t &r_ij = arguments[0];
137 // Maple result: 2*D*(1-exp(-k*(r-R)))*k*exp(-k*(r-R))
138 result.push_back(
139 2. * params[dissociation_energy]
140 * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
141 * (- params[spring_constant]) * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]))
142 );
143 ASSERT( result.size() == 1,
144 "PairPotential_Morse::operator() - we did not create exactly one component.");
145 return result;
146}
147
148PairPotential_Morse::results_t
149PairPotential_Morse::parameter_derivative(
150 const arguments_t &arguments,
151 const size_t index
152 ) const
153{
154 ASSERT( arguments.size() == 1,
155 "PairPotential_Morse::parameter_derivative() - requires exactly one argument.");
156 ASSERT( arguments[0].types.first == getParticleTypes()[0],
157 "PairPotential_Morse::parameter_derivative() - first charge "
158 +toString(arguments[0].types.first)+" is not "+toString(getParticleTypes()[0]));
159 ASSERT( arguments[0].types.second == getParticleTypes()[1],
160 "PairPotential_Morse::parameter_derivative() - second charge "
161 +toString(arguments[0].types.second)+" is not "+toString(getParticleTypes()[1]));
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 case energy_offset:
197 {
198 // Maple result: 1
199 const result_t result = +1.;
200 return std::vector<result_t>(1, result);
201 break;
202 }
203 default:
204 break;
205 }
206 return std::vector<result_t>(1, 0.);
207}
Note: See TracBrowser for help on using the repository browser.