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