| [610c11] | 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>
 | 
|---|
| [d03292] | 18 | #include <limits>
 | 
|---|
| [610c11] | 19 | 
 | 
|---|
| [4f82f8] | 20 | #include "Potentials/EmpiricalPotential.hpp"
 | 
|---|
| [ed2551] | 21 | #include "Potentials/SerializablePotential.hpp"
 | 
|---|
| [4f82f8] | 22 | #include "FunctionApproximation/FunctionModel.hpp"
 | 
|---|
 | 23 | 
 | 
|---|
| [d52819] | 24 | class TrainingData;
 | 
|---|
 | 25 | 
 | 
|---|
| [610c11] | 26 | /** This class is the implementation of the Tersoff potential function.
 | 
|---|
 | 27 |  *
 | 
|---|
 | 28 |  * \note The arguments_t argument list is here in the following order:
 | 
|---|
| [dd966f] | 29 |  * -# first \f$ r_{ij} \f$,
 | 
|---|
 | 30 |  * -# then all \f$ r_{ik} \f$ that are within the cutoff, i.e. \f$ r_{ik} < R + D\f$
 | 
|---|
| [610c11] | 31 |  *
 | 
|---|
 | 32 |  */
 | 
|---|
| [ed2551] | 33 | class ManyBodyPotential_Tersoff :
 | 
|---|
 | 34 |   virtual public EmpiricalPotential,
 | 
|---|
 | 35 |   virtual public FunctionModel,
 | 
|---|
 | 36 |   virtual public SerializablePotential
 | 
|---|
| [610c11] | 37 | {
 | 
|---|
| [ffc368] | 38 |   //!> grant unit test access to internal parts
 | 
|---|
 | 39 |   friend class ManyBodyPotential_TersoffTest;
 | 
|---|
| [3ccea3] | 40 |   // some repeated typedefs to avoid ambiguities
 | 
|---|
 | 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;
 | 
|---|
| [e7579e] | 45 |   typedef FunctionModel::parameters_t parameters_t;
 | 
|---|
| [610c11] | 46 | public:
 | 
|---|
 | 47 |   /** Constructor for class ManyBodyPotential_Tersoff.
 | 
|---|
 | 48 |    *
 | 
|---|
| [775dd1a] | 49 |    * \param _ParticleTypes particle types for this potential
 | 
|---|
| [610c11] | 50 |    */
 | 
|---|
 | 51 |   ManyBodyPotential_Tersoff(
 | 
|---|
| [775dd1a] | 52 |       const ParticleTypes_t &_ParticleTypes
 | 
|---|
| [e7579e] | 53 |       );
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 |   /** Constructor for class ManyBodyPotential_Tersoff.
 | 
|---|
 | 56 |    *
 | 
|---|
| [ffc368] | 57 |    * @param _R offset for cutoff
 | 
|---|
 | 58 |    * @param _S halfwidth for cutoff relative to \a _R
 | 
|---|
| [e7579e] | 59 |    * @param A
 | 
|---|
 | 60 |    * @param B
 | 
|---|
| [ffc368] | 61 |    * @param lambda
 | 
|---|
 | 62 |    * @param mu
 | 
|---|
| [e7579e] | 63 |    * @param lambda3
 | 
|---|
 | 64 |    * @param alpha
 | 
|---|
 | 65 |    * @param beta
 | 
|---|
| [ffc368] | 66 |    * @param chi
 | 
|---|
 | 67 |    * @param omega
 | 
|---|
| [e7579e] | 68 |    * @param n
 | 
|---|
 | 69 |    * @param c
 | 
|---|
 | 70 |    * @param d
 | 
|---|
 | 71 |    * @param h
 | 
|---|
| [56c5de4] | 72 |    * @param offset
 | 
|---|
| [e7579e] | 73 |    * @param _triplefunction function that returns a list of triples (i.e. the
 | 
|---|
 | 74 |    *        two remaining distances) to a given pair of points (contained as
 | 
|---|
 | 75 |    *        indices within the argument)
 | 
|---|
 | 76 |    */
 | 
|---|
 | 77 |   ManyBodyPotential_Tersoff(
 | 
|---|
| [ed2551] | 78 |       const ParticleTypes_t &_ParticleTypes,
 | 
|---|
| [ffc368] | 79 |       const double &_R,
 | 
|---|
 | 80 |       const double &_S,
 | 
|---|
 | 81 |       const double &_A,
 | 
|---|
 | 82 |       const double &_B,
 | 
|---|
 | 83 |       const double &_lambda,
 | 
|---|
 | 84 |       const double &_mu,
 | 
|---|
 | 85 |       const double &_lambda3,
 | 
|---|
 | 86 |       const double &_alpha,
 | 
|---|
 | 87 |       const double &_beta,
 | 
|---|
 | 88 |       const double &_chi,
 | 
|---|
 | 89 |       const double &_omega,
 | 
|---|
 | 90 |       const double &_n,
 | 
|---|
 | 91 |       const double &_c,
 | 
|---|
 | 92 |       const double &_d,
 | 
|---|
 | 93 |       const double &_h,
 | 
|---|
| [775dd1a] | 94 |       const double &_offset);
 | 
|---|
| [e7579e] | 95 | 
 | 
|---|
| [610c11] | 96 |   /** Destructor of class ManyBodyPotential_Tersoff.
 | 
|---|
 | 97 |    *
 | 
|---|
 | 98 |    */
 | 
|---|
 | 99 |   virtual ~ManyBodyPotential_Tersoff() {}
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 |   /** Evaluates the Tersoff potential for the given arguments.
 | 
|---|
 | 102 |    *
 | 
|---|
 | 103 |    * @param arguments single distance
 | 
|---|
 | 104 |    * @return value of the potential function
 | 
|---|
 | 105 |    */
 | 
|---|
| [4f82f8] | 106 |   results_t operator()(const arguments_t &arguments) const;
 | 
|---|
| [610c11] | 107 | 
 | 
|---|
 | 108 |   /** Evaluates the derivative of the Tersoff potential with respect to the
 | 
|---|
 | 109 |    * input variables.
 | 
|---|
 | 110 |    *
 | 
|---|
 | 111 |    * @param arguments single distance
 | 
|---|
 | 112 |    * @return vector with components of the derivative
 | 
|---|
 | 113 |    */
 | 
|---|
 | 114 |   derivative_components_t derivative(const arguments_t &arguments) const;
 | 
|---|
 | 115 | 
 | 
|---|
| [3ccea3] | 116 |   /** Evaluates the derivative of the function with the given \a arguments
 | 
|---|
 | 117 |    * with respect to a specific parameter indicated by \a index.
 | 
|---|
 | 118 |    *
 | 
|---|
 | 119 |    * \param arguments set of arguments as input variables to the function
 | 
|---|
 | 120 |    * \param index derivative of which parameter
 | 
|---|
 | 121 |    * \return result vector containing the derivative with respect to the given
 | 
|---|
 | 122 |    *         input
 | 
|---|
 | 123 |    */
 | 
|---|
| [e7579e] | 124 |   results_t parameter_derivative(const arguments_t &arguments, const size_t index) const;
 | 
|---|
 | 125 | 
 | 
|---|
| [6efcae] | 126 |   /** Return the token name of this specific potential.
 | 
|---|
| [67cd3a] | 127 |    *
 | 
|---|
| [6efcae] | 128 |    * \return token name of the potential
 | 
|---|
| [67cd3a] | 129 |    */
 | 
|---|
| [ed2551] | 130 |   const std::string& getToken() const
 | 
|---|
 | 131 |   { return potential_token; }
 | 
|---|
 | 132 | 
 | 
|---|
 | 133 |   /** Returns a vector of parameter names.
 | 
|---|
 | 134 |    *
 | 
|---|
 | 135 |    * This is required from the specific implementation
 | 
|---|
 | 136 |    *
 | 
|---|
 | 137 |    * \return vector of strings containing parameter names
 | 
|---|
 | 138 |    */
 | 
|---|
 | 139 |   const ParameterNames_t& getParameterNames() const
 | 
|---|
 | 140 |   { return ParameterNames; }
 | 
|---|
| [67cd3a] | 141 | 
 | 
|---|
| [d03292] | 142 |   /** States whether lower and upper boundaries should be used to constraint
 | 
|---|
 | 143 |    * the parameter search for this function model.
 | 
|---|
 | 144 |    *
 | 
|---|
 | 145 |    * \return true - constraints should be used, false - else
 | 
|---|
 | 146 |    */
 | 
|---|
 | 147 |   bool isBoxConstraint() const {
 | 
|---|
 | 148 |     return true;
 | 
|---|
 | 149 |   }
 | 
|---|
 | 150 | 
 | 
|---|
 | 151 |   /** Returns a vector which are the lower boundaries for each parameter_t
 | 
|---|
 | 152 |    * of this FunctionModel.
 | 
|---|
 | 153 |    *
 | 
|---|
 | 154 |    * \return vector of parameter_t resembling lowest allowed values
 | 
|---|
 | 155 |    */
 | 
|---|
 | 156 |   parameters_t getLowerBoxConstraints() const {
 | 
|---|
 | 157 |     parameters_t lowerbound(getParameterDimension(), -std::numeric_limits<double>::max());
 | 
|---|
 | 158 | //    lowerbound[R] = 0.;
 | 
|---|
 | 159 | //    lowerbound[S] = 0.;
 | 
|---|
 | 160 | //    lowerbound[lambda3] = 0.;
 | 
|---|
 | 161 | //    lowerbound[alpha] = 0.;
 | 
|---|
 | 162 |     lowerbound[beta] = std::numeric_limits<double>::min();
 | 
|---|
 | 163 |     lowerbound[n] = std::numeric_limits<double>::min();
 | 
|---|
 | 164 |     lowerbound[c] = std::numeric_limits<double>::min();
 | 
|---|
 | 165 |     lowerbound[d] = std::numeric_limits<double>::min();
 | 
|---|
 | 166 |     return lowerbound;
 | 
|---|
 | 167 |   }
 | 
|---|
 | 168 | 
 | 
|---|
 | 169 |   /** Returns a vector which are the upper boundaries for each parameter_t
 | 
|---|
 | 170 |    * of this FunctionModel.
 | 
|---|
 | 171 |    *
 | 
|---|
 | 172 |    * \return vector of parameter_t resembling highest allowed values
 | 
|---|
 | 173 |    */
 | 
|---|
 | 174 |   parameters_t getUpperBoxConstraints() const {
 | 
|---|
 | 175 |     return parameters_t(getParameterDimension(), std::numeric_limits<double>::max());
 | 
|---|
 | 176 |   }
 | 
|---|
 | 177 | 
 | 
|---|
| [7b019a] | 178 |   /** Returns a bound function to be used with TrainingData, extracting distances
 | 
|---|
 | 179 |    * from a Fragment.
 | 
|---|
 | 180 |    *
 | 
|---|
 | 181 |    * \param charges vector of charges to be extracted
 | 
|---|
 | 182 |    * \return bound function extracting distances from a fragment
 | 
|---|
 | 183 |    */
 | 
|---|
 | 184 |   FunctionModel::extractor_t getFragmentSpecificExtractor(const charges_t &charges) const;
 | 
|---|
 | 185 | 
 | 
|---|
| [775dd1a] | 186 |   /** Sets the magic triple function that we use for getting angle distances.
 | 
|---|
 | 187 |    *
 | 
|---|
 | 188 |    * @param _triplefunction function that returns a list of triples (i.e. the
 | 
|---|
 | 189 |    *        two remaining distances) to a given pair of points (contained as
 | 
|---|
 | 190 |    *        indices within the argument)
 | 
|---|
 | 191 |    */
 | 
|---|
 | 192 |   void setTriplefunction(
 | 
|---|
 | 193 |       boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction
 | 
|---|
 | 194 |       )
 | 
|---|
 | 195 |   {
 | 
|---|
 | 196 |     triplefunction = _triplefunction;
 | 
|---|
 | 197 |   }
 | 
|---|
 | 198 | 
 | 
|---|
| [e7579e] | 199 | private:
 | 
|---|
 | 200 |   /** Prohibit private default constructor.
 | 
|---|
 | 201 |    *
 | 
|---|
 | 202 |    * We essentially need the triplefunction, hence without this function cannot
 | 
|---|
 | 203 |    * be.
 | 
|---|
 | 204 |    */
 | 
|---|
 | 205 |   ManyBodyPotential_Tersoff();
 | 
|---|
| [3ccea3] | 206 | 
 | 
|---|
| [610c11] | 207 | private:
 | 
|---|
 | 208 |   /** This function represents the cutoff \f$ f_C \f$.
 | 
|---|
 | 209 |    *
 | 
|---|
 | 210 |    * @param distance variable of the function
 | 
|---|
 | 211 |    * @return a value in [0,1].
 | 
|---|
 | 212 |    */
 | 
|---|
 | 213 |   result_t function_cutoff(
 | 
|---|
 | 214 |       const double &distance
 | 
|---|
 | 215 |       ) const;
 | 
|---|
 | 216 |   /** This  function has the exponential feature from the Morse potential.
 | 
|---|
 | 217 |    *
 | 
|---|
 | 218 |    * @param prefactor prefactor parameter to exp function
 | 
|---|
 | 219 |    * @param lambda scale parameter of exp function's argument
 | 
|---|
| [ffc368] | 220 |    * @param distance variable of the function
 | 
|---|
| [610c11] | 221 |    * @return
 | 
|---|
 | 222 |    */
 | 
|---|
 | 223 |   result_t function_smoother(
 | 
|---|
 | 224 |       const double &prefactor,
 | 
|---|
| [ffc368] | 225 |       const double &lambda,
 | 
|---|
 | 226 |       const double &distance
 | 
|---|
 | 227 |       ) const;
 | 
|---|
| [610c11] | 228 | 
 | 
|---|
 | 229 |   /** This function represents \f$ (1 + \alpha^n \eta^n)^{-1/2n} \f$.
 | 
|---|
 | 230 |    *
 | 
|---|
 | 231 |    * @param alpha prefactor to eta function
 | 
|---|
 | 232 |    * @param r_ij distance argument
 | 
|---|
| [ffc368] | 233 |    * @param eta result value of eta or zeta
 | 
|---|
| [610c11] | 234 |    * @return \f$ (1 + \alpha^n \eta^n)^{-1/2n} \f$
 | 
|---|
 | 235 |    */
 | 
|---|
 | 236 |   result_t function_prefactor(
 | 
|---|
 | 237 |       const double &alpha,
 | 
|---|
| [ffc368] | 238 |       const double &eta
 | 
|---|
| [610c11] | 239 |         ) const;
 | 
|---|
 | 240 | 
 | 
|---|
 | 241 |   result_t
 | 
|---|
 | 242 |   function_eta(
 | 
|---|
 | 243 |       const argument_t &r_ij
 | 
|---|
 | 244 |     ) const;
 | 
|---|
 | 245 | 
 | 
|---|
 | 246 |   result_t
 | 
|---|
 | 247 |   function_zeta(
 | 
|---|
 | 248 |       const argument_t &r_ij
 | 
|---|
 | 249 |     ) const;
 | 
|---|
 | 250 | 
 | 
|---|
| [f904d5] | 251 |   result_t
 | 
|---|
 | 252 |   function_theta(
 | 
|---|
 | 253 |       const double &r_ij,
 | 
|---|
 | 254 |       const double &r_ik,
 | 
|---|
 | 255 |       const double &r_jk
 | 
|---|
 | 256 |     ) const;
 | 
|---|
 | 257 | 
 | 
|---|
| [610c11] | 258 |   result_t
 | 
|---|
 | 259 |   function_angle(
 | 
|---|
 | 260 |       const double &r_ij,
 | 
|---|
 | 261 |       const double &r_ik,
 | 
|---|
 | 262 |       const double &r_jk
 | 
|---|
 | 263 |     ) const;
 | 
|---|
 | 264 | 
 | 
|---|
| [e7579e] | 265 | private:
 | 
|---|
| [ca8d82] | 266 |   result_t
 | 
|---|
 | 267 |   function_derivative_c(
 | 
|---|
 | 268 |       const argument_t &r_ij
 | 
|---|
 | 269 |     ) const;
 | 
|---|
 | 270 | 
 | 
|---|
 | 271 |   result_t
 | 
|---|
 | 272 |   function_derivative_d(
 | 
|---|
 | 273 |       const argument_t &r_ij
 | 
|---|
 | 274 |     ) const;
 | 
|---|
 | 275 | 
 | 
|---|
 | 276 |   result_t
 | 
|---|
 | 277 |   function_derivative_h(
 | 
|---|
 | 278 |       const argument_t &r_ij
 | 
|---|
 | 279 |     ) const;
 | 
|---|
 | 280 | 
 | 
|---|
 | 281 | public:
 | 
|---|
| [e7579e] | 282 |   enum parameter_enum_t {
 | 
|---|
| [752dc7] | 283 |     A,
 | 
|---|
 | 284 |     B,
 | 
|---|
 | 285 |     lambda,
 | 
|---|
 | 286 |     mu,
 | 
|---|
 | 287 |     beta,
 | 
|---|
 | 288 |     n,
 | 
|---|
 | 289 |     c,
 | 
|---|
 | 290 |     d,
 | 
|---|
 | 291 |     h,
 | 
|---|
| [56c5de4] | 292 |     offset,
 | 
|---|
| [752dc7] | 293 | //    R,
 | 
|---|
 | 294 | //    S,
 | 
|---|
 | 295 | //    lambda3,
 | 
|---|
 | 296 | //    alpha,
 | 
|---|
 | 297 | //    chi,
 | 
|---|
 | 298 | //    omega,
 | 
|---|
| [e7579e] | 299 |     MAXPARAMS
 | 
|---|
 | 300 |   };
 | 
|---|
| [f48ad3] | 301 | 
 | 
|---|
 | 302 | private:
 | 
|---|
| [e7579e] | 303 |   //!> parameter vector with parameters as in enum parameter_enum_t
 | 
|---|
 | 304 |   parameters_t params;
 | 
|---|
 | 305 | 
 | 
|---|
| [752dc7] | 306 | public:
 | 
|---|
| [990a62] | 307 |   // some internal parameters which are fixed
 | 
|---|
| [752dc7] | 308 |   const double R;
 | 
|---|
 | 309 |   const double S;
 | 
|---|
| [990a62] | 310 |   const double lambda3;
 | 
|---|
 | 311 |   const double alpha;
 | 
|---|
 | 312 |   const double chi;
 | 
|---|
 | 313 |   const double omega;
 | 
|---|
 | 314 | 
 | 
|---|
| [e7579e] | 315 | public:
 | 
|---|
 | 316 |   /** Setter for parameters as required by FunctionModel interface.
 | 
|---|
 | 317 |    *
 | 
|---|
 | 318 |    * \param _params given set of parameters
 | 
|---|
 | 319 |    */
 | 
|---|
| [086070] | 320 |   void setParameters(const parameters_t &_params);
 | 
|---|
| [e7579e] | 321 | 
 | 
|---|
 | 322 |   /** Getter for parameters as required by FunctionModel interface.
 | 
|---|
 | 323 |    *
 | 
|---|
 | 324 |    * \return set of parameters
 | 
|---|
 | 325 |    */
 | 
|---|
 | 326 |   parameters_t getParameters() const
 | 
|---|
 | 327 |   {
 | 
|---|
 | 328 |     return params;
 | 
|---|
 | 329 |   }
 | 
|---|
 | 330 | 
 | 
|---|
| [d52819] | 331 |   /** Sets the parameter randomly within the sensible range of each parameter.
 | 
|---|
 | 332 |    *
 | 
|---|
 | 333 |    * \param data container with training data for guesstimating range
 | 
|---|
 | 334 |    */
 | 
|---|
 | 335 |   void setParametersToRandomInitialValues(const TrainingData &data);
 | 
|---|
 | 336 | 
 | 
|---|
| [e7579e] | 337 |   /** Getter for the number of parameters of this model function.
 | 
|---|
 | 338 |    *
 | 
|---|
 | 339 |    * \return number of parameters
 | 
|---|
 | 340 |    */
 | 
|---|
 | 341 |   size_t getParameterDimension() const
 | 
|---|
 | 342 |   {
 | 
|---|
 | 343 |     return MAXPARAMS;
 | 
|---|
 | 344 |   }
 | 
|---|
 | 345 | 
 | 
|---|
| [610c11] | 346 | private:
 | 
|---|
 | 347 |   //!> bound function that obtains the triples for the internal coordinationb summation.
 | 
|---|
| [775dd1a] | 348 |   boost::function< std::vector< arguments_t >(const argument_t &, const double)> triplefunction;
 | 
|---|
| [ed2551] | 349 | 
 | 
|---|
 | 350 |   //!> static definitions of the parameter name for this potential
 | 
|---|
 | 351 |   static const ParameterNames_t ParameterNames;
 | 
|---|
 | 352 | 
 | 
|---|
 | 353 |   //!> static token of this potential type
 | 
|---|
 | 354 |   static const std::string potential_token;
 | 
|---|
| [610c11] | 355 | };
 | 
|---|
 | 356 | 
 | 
|---|
 | 357 | 
 | 
|---|
 | 358 | #endif /* MANYBODYPOTENTIAL_TERSOFF_HPP_ */
 | 
|---|