source: src/Potentials/Specifics/ManyBodyPotential_Tersoff.hpp

stable v1.7.0
Last change on this file was a0d8aa, checked in by Frederik Heber <frederik.heber@…>, 8 weeks ago

PotentialFactory exposes particle type numbers.

  • Also, potentials use getParticleTypeNumber() in asserts.
  • Property mode set to 100644
File size: 10.5 KB
Line 
1/*
2 * ManyBodyPotential_Tersoff.hpp
3 *
4 * Created on: Sep 26, 2012
5 * Author: heber
6 */
7
8#ifndef MANYBODYPOTENTIAL_TERSOFF_HPP_
9#define MANYBODYPOTENTIAL_TERSOFF_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <boost/function.hpp>
17#include <cmath>
18#include <limits>
19
20#include "Potentials/EmpiricalPotential.hpp"
21
22class PotentialFactory;
23class TrainingData;
24
25/** This class is the implementation of the Tersoff potential function.
26 *
27 * \note The arguments_t argument list is here in the following order:
28 * -# first \f$ r_{ij} \f$,
29 * -# then all \f$ r_{ik} \f$ that are within the cutoff, i.e. \f$ r_{ik} < R + D\f$
30 *
31 */
32class ManyBodyPotential_Tersoff :
33 public EmpiricalPotential
34{
35 //!> grant unit test access to internal parts
36 friend class ManyBodyPotential_TersoffTest;
37 //!> grant PotentialFactory access to default cstor
38 friend class PotentialFactory;
39 // some repeated typedefs to avoid ambiguities
40 typedef FunctionModel::list_of_arguments_t list_of_arguments_t;
41 typedef FunctionModel::arguments_t arguments_t;
42 typedef FunctionModel::result_t result_t;
43 typedef FunctionModel::results_t results_t;
44 typedef EmpiricalPotential::derivative_components_t derivative_components_t;
45 typedef FunctionModel::parameters_t parameters_t;
46private:
47 /** Private default constructor.
48 *
49 * This prevents creation of potential without set ParticleTypes_t.
50 *
51 */
52 ManyBodyPotential_Tersoff();
53
54 /** Creates the binding model specific for this potential.
55 *
56 * Private because this is used internally some of the constructors.
57 *
58 * \param _ParticleTypes particle type for the potential
59 * \return binding model
60 */
61 BindingModel generateBindingModel(const EmpiricalPotential::ParticleTypes_t &_ParticleTypes) const;
62
63public:
64 /** Constructor for class ManyBodyPotential_Tersoff.
65 *
66 * \param _ParticleTypes particle types for this potential
67 */
68 ManyBodyPotential_Tersoff(
69 const ParticleTypes_t &_ParticleTypes
70 );
71
72 /** Constructor for class ManyBodyPotential_Tersoff.
73 *
74 * @param _R offset for cutoff
75 * @param _S halfwidth for cutoff relative to \a _R
76 * @param A
77 * @param B
78 * @param lambda
79 * @param mu
80 * @param lambda3
81 * @param alpha
82 * @param beta
83 * @param chi
84 * @param omega
85 * @param n
86 * @param c
87 * @param d
88 * @param h
89 * @param _triplefunction function that returns a list of triples (i.e. the
90 * two remaining distances) to a given pair of points (contained as
91 * indices within the argument)
92 */
93 ManyBodyPotential_Tersoff(
94 const ParticleTypes_t &_ParticleTypes,
95 const double &_R,
96 const double &_S,
97 const double &_A,
98 const double &_B,
99 const double &_lambda,
100 const double &_mu,
101 const double &_lambda3,
102 const double &_alpha,
103 const double &_beta,
104 const double &_chi,
105 const double &_omega,
106 const double &_n,
107 const double &_c,
108 const double &_d,
109 const double &_h);
110
111 /** Destructor of class ManyBodyPotential_Tersoff.
112 *
113 */
114 virtual ~ManyBodyPotential_Tersoff() {}
115
116 /** Evaluates the Tersoff potential for the given arguments.
117 *
118 * @param listarguments list of distances
119 * @return value of the potential function
120 */
121 results_t operator()(const list_of_arguments_t &listarguments) const;
122
123 /** Evaluates the derivative of the Tersoff potential with respect to the
124 * input variables.
125 *
126 * @param listarguments list of distances
127 * @return vector with components of the derivative
128 */
129 derivative_components_t derivative(const list_of_arguments_t &listarguments) const;
130
131 /** Evaluates the derivative of the function with the given \a arguments
132 * with respect to a specific parameter indicated by \a index.
133 *
134 * \param listarguments list of distances
135 * \param index derivative of which parameter
136 * \return result vector containing the derivative with respect to the given
137 * input
138 */
139 results_t parameter_derivative(const list_of_arguments_t &listarguments, const size_t index) const;
140
141 /** Returns the functor that converts argument_s into the
142 * internal coordinate described by this potential function.
143 *
144 * \return coordinator functor
145 */
146 Coordinator::ptr getCoordinator() const
147 { return coordinator; }
148
149 /** Return the token name of this specific potential.
150 *
151 * \return token name of the potential
152 */
153 const std::string& getToken() const
154 { return potential_token; }
155
156 /** Returns a vector of parameter names.
157 *
158 * This is required from the specific implementation
159 *
160 * \return vector of strings containing parameter names
161 */
162 const ParameterNames_t& getParameterNames() const
163 { return ParameterNames; }
164
165 /** States whether lower and upper boundaries should be used to constraint
166 * the parameter search for this function model.
167 *
168 * \return true - constraints should be used, false - else
169 */
170 bool isBoxConstraint() const {
171 return true;
172 }
173
174 /** Returns a vector which are the lower boundaries for each parameter_t
175 * of this FunctionModel.
176 *
177 * \return vector of parameter_t resembling lowest allowed values
178 */
179 parameters_t getLowerBoxConstraints() const {
180 parameters_t lowerbound(getParameterDimension(), -std::numeric_limits<double>::max());
181// lowerbound[R] = 0.;
182// lowerbound[S] = 0.;
183// lowerbound[lambda3] = 0.;
184// lowerbound[alpha] = 0.;
185 lowerbound[beta] = std::numeric_limits<double>::min();
186 lowerbound[n] = std::numeric_limits<double>::min();
187 lowerbound[c] = std::numeric_limits<double>::min();
188 lowerbound[d] = std::numeric_limits<double>::min();
189 return lowerbound;
190 }
191
192 /** Returns a vector which are the upper boundaries for each parameter_t
193 * of this FunctionModel.
194 *
195 * \return vector of parameter_t resembling highest allowed values
196 */
197 parameters_t getUpperBoxConstraints() const {
198 return parameters_t(getParameterDimension(), std::numeric_limits<double>::max());
199 }
200
201 /** Returns a bound function to be used with TrainingData, extracting distances
202 * from a Fragment.
203 *
204 * \return bound function extracting distances from a fragment
205 */
206 FunctionModel::filter_t getSpecificFilter() const;
207
208 /** Returns the number of arguments the underlying function requires.
209 *
210 * \return number of arguments of the function
211 */
212 size_t getSpecificArgumentCount() const
213 { return 1; }
214
215 /** Sets the magic triple function that we use for getting angle distances.
216 *
217 * @param _triplefunction function that returns a list of triples (i.e. the
218 * two remaining distances) to a given pair of points (contained as
219 * indices within the argument)
220 */
221 void setTriplefunction(triplefunction_t &_triplefunction)
222 { triplefunction = _triplefunction; }
223
224 /** Getter for the graph specifying the binding model of the potential.
225 *
226 * \return BindingModel ref of the binding model
227 */
228 const BindingModel& getBindingModel() const
229 { return bindingmodel; }
230
231 /**
232 * Returns the number of particle types associated with the potential.
233 *
234 * \return number of particle types
235 */
236 unsigned int getParticleTypeNumber() const
237 { return 2; }
238
239private:
240 /** This function represents the cutoff \f$ f_C \f$.
241 *
242 * @param distance variable of the function
243 * @return a value in [0,1].
244 */
245 result_t function_cutoff(
246 const double &distance
247 ) const;
248 /** This function has the exponential feature from the Morse potential.
249 *
250 * @param prefactor prefactor parameter to exp function
251 * @param lambda scale parameter of exp function's argument
252 * @param distance variable of the function
253 * @return
254 */
255 result_t function_smoother(
256 const double &prefactor,
257 const double &lambda,
258 const double &distance
259 ) const;
260
261 /** This function represents \f$ (1 + \alpha^n \eta^n)^{-1/2n} \f$.
262 *
263 * @param alpha prefactor to eta function
264 * @param r_ij distance argument
265 * @param eta result value of eta or zeta
266 * @return \f$ (1 + \alpha^n \eta^n)^{-1/2n} \f$
267 */
268 result_t function_prefactor(
269 const double &alpha,
270 const double &eta
271 ) const;
272
273 result_t
274 function_eta(
275 const argument_t &r_ij
276 ) const;
277
278 result_t
279 function_zeta(
280 const argument_t &r_ij
281 ) const;
282
283 result_t
284 function_theta(
285 const double &r_ij,
286 const double &r_ik,
287 const double &r_jk
288 ) const;
289
290 result_t
291 function_angle(
292 const double &r_ij,
293 const double &r_ik,
294 const double &r_jk
295 ) const;
296
297private:
298 result_t
299 function_derivative_c(
300 const argument_t &r_ij
301 ) const;
302
303 result_t
304 function_derivative_d(
305 const argument_t &r_ij
306 ) const;
307
308 result_t
309 function_derivative_h(
310 const argument_t &r_ij
311 ) const;
312
313public:
314 enum parameter_enum_t {
315 A,
316 B,
317 lambda,
318 mu,
319 beta,
320 n,
321 c,
322 d,
323 h,
324// R,
325// S,
326// lambda3,
327// alpha,
328// chi,
329// omega,
330 MAXPARAMS
331 };
332
333private:
334 //!> parameter vector with parameters as in enum parameter_enum_t
335 parameters_t params;
336
337public:
338 // some internal parameters which are fixed
339 const double R;
340 const double S;
341 const double lambda3;
342 const double alpha;
343 const double chi;
344 const double omega;
345
346public:
347 /** Setter for parameters as required by FunctionModel interface.
348 *
349 * \param _params given set of parameters
350 */
351 void setParameters(const parameters_t &_params);
352
353 /** Getter for parameters as required by FunctionModel interface.
354 *
355 * \return set of parameters
356 */
357 parameters_t getParameters() const
358 {
359 return params;
360 }
361
362 /** Sets the parameter randomly within the sensible range of each parameter.
363 *
364 * \param data container with training data for guesstimating range
365 */
366 void setParametersToRandomInitialValues(const TrainingData &data);
367
368 /** Getter for the number of parameters of this model function.
369 *
370 * \return number of parameters
371 */
372 size_t getParameterDimension() const
373 {
374 return MAXPARAMS;
375 }
376
377private:
378 //!> bound function that obtains the triples for the internal coordinationb summation.
379 boost::function< std::vector< arguments_t >(const argument_t &, const double)> triplefunction;
380
381 //!> static definitions of the parameter name for this potential
382 static const ParameterNames_t ParameterNames;
383
384 //!> static token of this potential type
385 static const std::string potential_token;
386
387 //!> internal coordinator object for converting arguments_t
388 static Coordinator::ptr coordinator;
389
390 //!> binding model for this potential
391 const BindingModel bindingmodel;
392};
393
394
395#endif /* MANYBODYPOTENTIAL_TERSOFF_HPP_ */
Note: See TracBrowser for help on using the repository browser.