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_Angle.cpp
|
---|
26 | *
|
---|
27 | * Created on: Oct 11, 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_Angle.hpp"
|
---|
40 |
|
---|
41 | #include <boost/assign/list_of.hpp> // for 'map_list_of()'
|
---|
42 | #include <string>
|
---|
43 |
|
---|
44 | #include "CodePatterns/Assert.hpp"
|
---|
45 |
|
---|
46 | #include "Potentials/helpers.hpp"
|
---|
47 |
|
---|
48 | // static definitions
|
---|
49 | const PairPotential_Angle::ParameterNames_t
|
---|
50 | PairPotential_Angle::ParameterNames =
|
---|
51 | boost::assign::list_of<std::string>
|
---|
52 | ("spring_constant")
|
---|
53 | ("equilibrium_distance")
|
---|
54 | ("") //energy_offset
|
---|
55 | ;
|
---|
56 | const std::string PairPotential_Angle::potential_token("harmonic_angle");
|
---|
57 |
|
---|
58 | PairPotential_Angle::PairPotential_Angle(
|
---|
59 | const ParticleTypes_t &_ParticleTypes
|
---|
60 | ) :
|
---|
61 | SerializablePotential(_ParticleTypes),
|
---|
62 | params(parameters_t(MAXPARAMS, 0.))
|
---|
63 | {}
|
---|
64 |
|
---|
65 | PairPotential_Angle::PairPotential_Angle(
|
---|
66 | const ParticleTypes_t &_ParticleTypes,
|
---|
67 | const double _spring_constant,
|
---|
68 | const double _equilibrium_distance,
|
---|
69 | const double _energy_offset) :
|
---|
70 | SerializablePotential(_ParticleTypes),
|
---|
71 | params(parameters_t(MAXPARAMS, 0.))
|
---|
72 | {
|
---|
73 | params[spring_constant] = _spring_constant;
|
---|
74 | params[equilibrium_distance] = _equilibrium_distance;
|
---|
75 | params[energy_offset] = _energy_offset;
|
---|
76 | }
|
---|
77 |
|
---|
78 | void PairPotential_Angle::setParameters(const parameters_t &_params)
|
---|
79 | {
|
---|
80 | const size_t paramsDim = _params.size();
|
---|
81 | ASSERT( paramsDim <= getParameterDimension(),
|
---|
82 | "PairPotential_Angle::setParameters() - we need not more than "
|
---|
83 | +toString(getParameterDimension())+" parameters.");
|
---|
84 | for(size_t i=0;i<paramsDim;++i)
|
---|
85 | params[i] = _params[i];
|
---|
86 |
|
---|
87 | #ifndef NDEBUG
|
---|
88 | parameters_t check_params(getParameters());
|
---|
89 | check_params.resize(paramsDim); // truncate to same size
|
---|
90 | ASSERT( check_params == _params,
|
---|
91 | "PairPotential_Angle::setParameters() - failed, mismatch in to be set "
|
---|
92 | +toString(_params)+" and set "+toString(check_params)+" params.");
|
---|
93 | #endif
|
---|
94 | }
|
---|
95 |
|
---|
96 | PairPotential_Angle::result_t
|
---|
97 | PairPotential_Angle::function_theta(
|
---|
98 | const double &r_ij,
|
---|
99 | const double &r_ik,
|
---|
100 | const double &r_jk
|
---|
101 | ) const
|
---|
102 | {
|
---|
103 | // Info info(__func__);
|
---|
104 | const double angle = Helpers::pow(r_ij,2) + Helpers::pow(r_ik,2) - Helpers::pow(r_jk,2);
|
---|
105 | const double divisor = 2.* r_ij * r_ik;
|
---|
106 |
|
---|
107 | // LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
|
---|
108 | if (divisor == 0.)
|
---|
109 | return 0.;
|
---|
110 | else
|
---|
111 | return angle/divisor;
|
---|
112 | }
|
---|
113 |
|
---|
114 | PairPotential_Angle::results_t
|
---|
115 | PairPotential_Angle::operator()(
|
---|
116 | const arguments_t &arguments
|
---|
117 | ) const
|
---|
118 | {
|
---|
119 | ASSERT( arguments.size() == 3,
|
---|
120 | "PairPotential_Angle::operator() - requires exactly three arguments.");
|
---|
121 | ASSERT( arguments[0].types.first == getParticleTypes()[0],
|
---|
122 | "PairPotential_Angle::operator() - first charge of first distance "
|
---|
123 | +toString(arguments[0].types.first)+" is not "+toString(getParticleTypes()[0]));
|
---|
124 | ASSERT( arguments[0].types.second == getParticleTypes()[1],
|
---|
125 | "PairPotential_Angle::operator() - second charge of first distance "
|
---|
126 | +toString(arguments[0].types.second)+" is not "+toString(getParticleTypes()[1]));
|
---|
127 | ASSERT( arguments[1].types.first == getParticleTypes()[0],
|
---|
128 | "PairPotential_Angle::operator() - first charge of second distance "
|
---|
129 | +toString(arguments[1].types.first)+" is not "+toString(getParticleTypes()[0]));
|
---|
130 | ASSERT( arguments[1].types.second == getParticleTypes()[2],
|
---|
131 | "PairPotential_Angle::operator() - second charge of second distance "
|
---|
132 | +toString(arguments[1].types.second)+" is not "+toString(getParticleTypes()[2]));
|
---|
133 | ASSERT( arguments[2].types.first == getParticleTypes()[1],
|
---|
134 | "PairPotential_Angle::operator() - first charge of third distance "
|
---|
135 | +toString(arguments[2].types.first)+" is not "+toString(getParticleTypes()[1]));
|
---|
136 | ASSERT( arguments[2].types.second == getParticleTypes()[2],
|
---|
137 | "PairPotential_Angle::operator() - second charge of third distance "
|
---|
138 | +toString(arguments[2].types.second)+" is not "+toString(getParticleTypes()[2]));
|
---|
139 | const argument_t &r_ij = arguments[0];
|
---|
140 | const argument_t &r_ik = arguments[1];
|
---|
141 | const argument_t &r_jk = arguments[2];
|
---|
142 | const result_t result =
|
---|
143 | params[spring_constant]
|
---|
144 | * Helpers::pow( function_theta(r_ij.distance, r_ik.distance, r_jk.distance) - params[equilibrium_distance], 2 )
|
---|
145 | + params[energy_offset];
|
---|
146 | return std::vector<result_t>(1, result);
|
---|
147 | }
|
---|
148 |
|
---|
149 | PairPotential_Angle::derivative_components_t
|
---|
150 | PairPotential_Angle::derivative(
|
---|
151 | const arguments_t &arguments
|
---|
152 | ) const
|
---|
153 | {
|
---|
154 | ASSERT( arguments.size() == 3,
|
---|
155 | "PairPotential_Angle::operator() - requires exactly three arguments.");
|
---|
156 | ASSERT( arguments[0].types.first == getParticleTypes()[0],
|
---|
157 | "PairPotential_Angle::derivative() - first charge of first distance "
|
---|
158 | +toString(arguments[0].types.first)+" is not "+toString(getParticleTypes()[0]));
|
---|
159 | ASSERT( arguments[0].types.second == getParticleTypes()[1],
|
---|
160 | "PairPotential_Angle::derivative() - second charge of first distance "
|
---|
161 | +toString(arguments[0].types.second)+" is not "+toString(getParticleTypes()[1]));
|
---|
162 | ASSERT( arguments[1].types.first == getParticleTypes()[0],
|
---|
163 | "PairPotential_Angle::derivative() - first charge of second distance "
|
---|
164 | +toString(arguments[1].types.first)+" is not "+toString(getParticleTypes()[0]));
|
---|
165 | ASSERT( arguments[1].types.second == getParticleTypes()[2],
|
---|
166 | "PairPotential_Angle::derivative() - second charge of second distance "
|
---|
167 | +toString(arguments[1].types.second)+" is not "+toString(getParticleTypes()[2]));
|
---|
168 | ASSERT( arguments[2].types.first == getParticleTypes()[1],
|
---|
169 | "PairPotential_Angle::derivative() - first charge of third distance "
|
---|
170 | +toString(arguments[2].types.first)+" is not "+toString(getParticleTypes()[1]));
|
---|
171 | ASSERT( arguments[2].types.second == getParticleTypes()[2],
|
---|
172 | "PairPotential_Angle::derivative() - second charge of third distance "
|
---|
173 | +toString(arguments[2].types.second)+" is not "+toString(getParticleTypes()[2]));
|
---|
174 | derivative_components_t result;
|
---|
175 | const argument_t &r_ij = arguments[0];
|
---|
176 | const argument_t &r_ik = arguments[1];
|
---|
177 | const argument_t &r_jk = arguments[2];
|
---|
178 | result.push_back( 2. * params[spring_constant] * ( function_theta(r_ij.distance, r_ik.distance, r_jk.distance) - params[equilibrium_distance]) );
|
---|
179 | ASSERT( result.size() == 1,
|
---|
180 | "PairPotential_Angle::operator() - we did not create exactly one component.");
|
---|
181 | return result;
|
---|
182 | }
|
---|
183 |
|
---|
184 | PairPotential_Angle::results_t
|
---|
185 | PairPotential_Angle::parameter_derivative(
|
---|
186 | const arguments_t &arguments,
|
---|
187 | const size_t index
|
---|
188 | ) const
|
---|
189 | {
|
---|
190 | ASSERT( arguments.size() == 3,
|
---|
191 | "PairPotential_Angle::parameter_derivative() - requires exactly three arguments.");
|
---|
192 | ASSERT( arguments[0].types.first == getParticleTypes()[0],
|
---|
193 | "PairPotential_Angle::parameter_derivative() - first charge of first distance "
|
---|
194 | +toString(arguments[0].types.first)+" is not "+toString(getParticleTypes()[0]));
|
---|
195 | ASSERT( arguments[0].types.second == getParticleTypes()[1],
|
---|
196 | "PairPotential_Angle::parameter_derivative() - second charge of first distance "
|
---|
197 | +toString(arguments[0].types.second)+" is not "+toString(getParticleTypes()[1]));
|
---|
198 | ASSERT( arguments[1].types.first == getParticleTypes()[0],
|
---|
199 | "PairPotential_Angle::parameter_derivative() - first charge of second distance "
|
---|
200 | +toString(arguments[1].types.first)+" is not "+toString(getParticleTypes()[0]));
|
---|
201 | ASSERT( arguments[1].types.second == getParticleTypes()[2],
|
---|
202 | "PairPotential_Angle::parameter_derivative() - second charge of second distance "
|
---|
203 | +toString(arguments[1].types.second)+" is not "+toString(getParticleTypes()[2]));
|
---|
204 | ASSERT( arguments[2].types.first == getParticleTypes()[1],
|
---|
205 | "PairPotential_Angle::parameter_derivative() - first charge of third distance "
|
---|
206 | +toString(arguments[2].types.first)+" is not "+toString(getParticleTypes()[1]));
|
---|
207 | ASSERT( arguments[2].types.second == getParticleTypes()[2],
|
---|
208 | "PairPotential_Angle::parameter_derivative() - second charge of third distance "
|
---|
209 | +toString(arguments[2].types.second)+" is not "+toString(getParticleTypes()[2]));
|
---|
210 | const argument_t &r_ij = arguments[0];
|
---|
211 | const argument_t &r_ik = arguments[1];
|
---|
212 | const argument_t &r_jk = arguments[2];
|
---|
213 | switch (index) {
|
---|
214 | case spring_constant:
|
---|
215 | {
|
---|
216 | const result_t result =
|
---|
217 | Helpers::pow( function_theta(r_ij.distance, r_ik.distance, r_jk.distance) - params[equilibrium_distance], 2 );
|
---|
218 | return std::vector<result_t>(1, result);
|
---|
219 | break;
|
---|
220 | }
|
---|
221 | case equilibrium_distance:
|
---|
222 | {
|
---|
223 | const result_t result =
|
---|
224 | -2. * params[spring_constant]
|
---|
225 | * ( function_theta(r_ij.distance, r_ik.distance, r_jk.distance) - params[equilibrium_distance]);
|
---|
226 | return std::vector<result_t>(1, result);
|
---|
227 | break;
|
---|
228 | }
|
---|
229 | case energy_offset:
|
---|
230 | {
|
---|
231 | const result_t result = +1.;
|
---|
232 | return std::vector<result_t>(1, result);
|
---|
233 | break;
|
---|
234 | }
|
---|
235 | default:
|
---|
236 | return PairPotential_Angle::results_t(1, 0.);
|
---|
237 | break;
|
---|
238 | }
|
---|
239 | }
|
---|