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
|
---|
50 | const PairPotential_Morse::ParameterNames_t
|
---|
51 | PairPotential_Morse::ParameterNames =
|
---|
52 | boost::assign::list_of<std::string>
|
---|
53 | ("spring_constant")
|
---|
54 | ("equilibrium_distance")
|
---|
55 | ("dissociation_energy")
|
---|
56 | ("") //energy_offset
|
---|
57 | ;
|
---|
58 | const std::string PairPotential_Morse::potential_token("morse");
|
---|
59 |
|
---|
60 | PairPotential_Morse::PairPotential_Morse(
|
---|
61 | const ParticleTypes_t &_ParticleTypes
|
---|
62 | ) :
|
---|
63 | SerializablePotential(_ParticleTypes),
|
---|
64 | params(parameters_t(MAXPARAMS, 0.))
|
---|
65 | {}
|
---|
66 |
|
---|
67 | PairPotential_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 |
|
---|
82 | void 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 |
|
---|
100 | PairPotential_Morse::results_t
|
---|
101 | PairPotential_Morse::operator()(
|
---|
102 | const arguments_t &arguments
|
---|
103 | ) const
|
---|
104 | {
|
---|
105 | ASSERT( arguments.size() == 1,
|
---|
106 | "PairPotential_Morse::operator() - requires exactly one argument.");
|
---|
107 | const argument_t &r_ij = arguments[0];
|
---|
108 | // Maple: f(r,D,k,R,c) := D * (1 - exp(-k*(r-R)))^(2)+c
|
---|
109 | const result_t result =
|
---|
110 | params[dissociation_energy] * Helpers::pow( 1.
|
---|
111 | - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])),2)
|
---|
112 | + params[energy_offset];
|
---|
113 | return std::vector<result_t>(1, result);
|
---|
114 | }
|
---|
115 |
|
---|
116 | PairPotential_Morse::derivative_components_t
|
---|
117 | PairPotential_Morse::derivative(
|
---|
118 | const arguments_t &arguments
|
---|
119 | ) const
|
---|
120 | {
|
---|
121 | ASSERT( arguments.size() == 1,
|
---|
122 | "PairPotential_Morse::operator() - requires exactly one argument.");
|
---|
123 | derivative_components_t result;
|
---|
124 | const argument_t &r_ij = arguments[0];
|
---|
125 | // Maple result: 2*D*(1-exp(-k*(r-R)))*k*exp(-k*(r-R))
|
---|
126 | result.push_back(
|
---|
127 | 2. * params[dissociation_energy]
|
---|
128 | * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
|
---|
129 | * (- params[spring_constant]) * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]))
|
---|
130 | );
|
---|
131 | ASSERT( result.size() == 1,
|
---|
132 | "PairPotential_Morse::operator() - we did not create exactly one component.");
|
---|
133 | return result;
|
---|
134 | }
|
---|
135 |
|
---|
136 | PairPotential_Morse::results_t
|
---|
137 | PairPotential_Morse::parameter_derivative(
|
---|
138 | const arguments_t &arguments,
|
---|
139 | const size_t index
|
---|
140 | ) const
|
---|
141 | {
|
---|
142 | ASSERT( arguments.size() == 1,
|
---|
143 | "PairPotential_Morse::parameter_derivative() - requires exactly one argument.");
|
---|
144 | const argument_t &r_ij = arguments[0];
|
---|
145 | switch (index) {
|
---|
146 | case spring_constant:
|
---|
147 | {
|
---|
148 | // Maple result: -2*D*(1-exp(-k*(r-R)))*(-r+R)*exp(-k*(r-R))
|
---|
149 | const result_t result =
|
---|
150 | - 2. * params[dissociation_energy]
|
---|
151 | * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
|
---|
152 | * (- r_ij.distance + params[equilibrium_distance])
|
---|
153 | * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]))
|
---|
154 | ;
|
---|
155 | return std::vector<result_t>(1, result);
|
---|
156 | break;
|
---|
157 | }
|
---|
158 | case equilibrium_distance:
|
---|
159 | {
|
---|
160 | // Maple result: -2*D*(1-exp(-k*(r-R)))*k*exp(-k*(r-R))
|
---|
161 | const result_t result =
|
---|
162 | - 2. * params[dissociation_energy]
|
---|
163 | * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
|
---|
164 | * params[spring_constant] * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]))
|
---|
165 | ;
|
---|
166 | return std::vector<result_t>(1, result);
|
---|
167 | break;
|
---|
168 | }
|
---|
169 | case dissociation_energy:
|
---|
170 | {
|
---|
171 | // Maple result: (1-exp(-k*(r-R)))^2
|
---|
172 | const result_t result =
|
---|
173 | Helpers::pow(1.
|
---|
174 | - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])),2);
|
---|
175 | return std::vector<result_t>(1, result);
|
---|
176 | break;
|
---|
177 | }
|
---|
178 | case energy_offset:
|
---|
179 | {
|
---|
180 | // Maple result: 1
|
---|
181 | const result_t result = +1.;
|
---|
182 | return std::vector<result_t>(1, result);
|
---|
183 | break;
|
---|
184 | }
|
---|
185 | default:
|
---|
186 | break;
|
---|
187 | }
|
---|
188 | return std::vector<result_t>(1, 0.);
|
---|
189 | }
|
---|