| 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 |  * ManyBodyPotential_Tersoff.cpp
 | 
|---|
| 26 |  *
 | 
|---|
| 27 |  *  Created on: Sep 26, 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 "ManyBodyPotential_Tersoff.hpp"
 | 
|---|
| 40 | 
 | 
|---|
| 41 | #include <boost/bind.hpp>
 | 
|---|
| 42 | #include <cmath>
 | 
|---|
| 43 | 
 | 
|---|
| 44 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| 45 | //#include "CodePatterns/Info.hpp"
 | 
|---|
| 46 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 47 | 
 | 
|---|
| 48 | #include "Potentials/helpers.hpp"
 | 
|---|
| 49 | 
 | 
|---|
| 50 | ManyBodyPotential_Tersoff::ManyBodyPotential_Tersoff(
 | 
|---|
| 51 |     boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction
 | 
|---|
| 52 |     ) :
 | 
|---|
| 53 |     params(parameters_t(MAXPARAMS, 0.)),
 | 
|---|
| 54 |     R(3.2),
 | 
|---|
| 55 |     S(3.5),
 | 
|---|
| 56 |     lambda3(0.),
 | 
|---|
| 57 |     alpha(0.),
 | 
|---|
| 58 |     chi(1.),
 | 
|---|
| 59 |     omega(1.),
 | 
|---|
| 60 |     triplefunction(_triplefunction)
 | 
|---|
| 61 | {}
 | 
|---|
| 62 | 
 | 
|---|
| 63 | ManyBodyPotential_Tersoff::ManyBodyPotential_Tersoff(
 | 
|---|
| 64 |     const double &_R,
 | 
|---|
| 65 |     const double &_S,
 | 
|---|
| 66 |     const double &_A,
 | 
|---|
| 67 |     const double &_B,
 | 
|---|
| 68 |     const double &_lambda,
 | 
|---|
| 69 |     const double &_mu,
 | 
|---|
| 70 |     const double &_lambda3,
 | 
|---|
| 71 |     const double &_alpha,
 | 
|---|
| 72 |     const double &_beta,
 | 
|---|
| 73 |     const double &_chi,
 | 
|---|
| 74 |     const double &_omega,
 | 
|---|
| 75 |     const double &_n,
 | 
|---|
| 76 |     const double &_c,
 | 
|---|
| 77 |     const double &_d,
 | 
|---|
| 78 |     const double &_h,
 | 
|---|
| 79 |     const double &_offset,
 | 
|---|
| 80 |     boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction) :
 | 
|---|
| 81 |   params(parameters_t(MAXPARAMS, 0.)),
 | 
|---|
| 82 |   R(_R),
 | 
|---|
| 83 |   S(_S),
 | 
|---|
| 84 |   lambda3(_lambda3),
 | 
|---|
| 85 |   alpha(_alpha),
 | 
|---|
| 86 |   chi(_chi),
 | 
|---|
| 87 |   omega(_mu),
 | 
|---|
| 88 |   triplefunction(_triplefunction)
 | 
|---|
| 89 | {
 | 
|---|
| 90 | //  Info info(__func__);
 | 
|---|
| 91 | //  R = _R;
 | 
|---|
| 92 | //  S = _S;
 | 
|---|
| 93 |   params[A] = _A;
 | 
|---|
| 94 |   params[B] = _B;
 | 
|---|
| 95 |   params[lambda] = _lambda;
 | 
|---|
| 96 |   params[mu] = _mu;
 | 
|---|
| 97 | //  lambda3 = _lambda3;
 | 
|---|
| 98 | //  alpha = _alpha;
 | 
|---|
| 99 |   params[beta] = _beta;
 | 
|---|
| 100 | //  chi = _chi;
 | 
|---|
| 101 | //  omega = _omega;
 | 
|---|
| 102 |   params[n] = _n;
 | 
|---|
| 103 |   params[c] = _c;
 | 
|---|
| 104 |   params[d] = _d;
 | 
|---|
| 105 |   params[h] = _h;
 | 
|---|
| 106 |   params[offset] = _offset;
 | 
|---|
| 107 | }
 | 
|---|
| 108 | 
 | 
|---|
| 109 | ManyBodyPotential_Tersoff::results_t
 | 
|---|
| 110 | ManyBodyPotential_Tersoff::operator()(
 | 
|---|
| 111 |     const arguments_t &arguments
 | 
|---|
| 112 |     ) const
 | 
|---|
| 113 | {
 | 
|---|
| 114 | //  Info info(__func__);
 | 
|---|
| 115 |   double result = 0.;
 | 
|---|
| 116 |   for(arguments_t::const_iterator argiter = arguments.begin();
 | 
|---|
| 117 |       argiter != arguments.end();
 | 
|---|
| 118 |       ++argiter) {
 | 
|---|
| 119 |     const argument_t &r_ij = *argiter;
 | 
|---|
| 120 |     const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 121 |     const double temp = (cutoff == 0.) ?
 | 
|---|
| 122 |         0. :
 | 
|---|
| 123 |         cutoff * (
 | 
|---|
| 124 |             function_prefactor(
 | 
|---|
| 125 |                 alpha,
 | 
|---|
| 126 |                 function_eta(r_ij))
 | 
|---|
| 127 |             * function_smoother(
 | 
|---|
| 128 |                 params[A],
 | 
|---|
| 129 |                 params[lambda],
 | 
|---|
| 130 |                 r_ij.distance)
 | 
|---|
| 131 |             +
 | 
|---|
| 132 |             function_prefactor(
 | 
|---|
| 133 |                 params[beta],
 | 
|---|
| 134 |                 function_zeta(r_ij))
 | 
|---|
| 135 |             * function_smoother(
 | 
|---|
| 136 |                 -params[B],
 | 
|---|
| 137 |                 params[mu],
 | 
|---|
| 138 |                 r_ij.distance)
 | 
|---|
| 139 |         );
 | 
|---|
| 140 |     result += temp;
 | 
|---|
| 141 |   }
 | 
|---|
| 142 | //  LOG(2, "DEBUG: operator()(" << r_ij.distance << ") = " << result);
 | 
|---|
| 143 |   return std::vector<result_t>(1, params[offset]+result);
 | 
|---|
| 144 | }
 | 
|---|
| 145 | 
 | 
|---|
| 146 | ManyBodyPotential_Tersoff::derivative_components_t
 | 
|---|
| 147 | ManyBodyPotential_Tersoff::derivative(
 | 
|---|
| 148 |     const arguments_t &arguments
 | 
|---|
| 149 |     ) const
 | 
|---|
| 150 | {
 | 
|---|
| 151 | //  Info info(__func__);
 | 
|---|
| 152 |   return ManyBodyPotential_Tersoff::derivative_components_t();
 | 
|---|
| 153 | }
 | 
|---|
| 154 | 
 | 
|---|
| 155 | ManyBodyPotential_Tersoff::results_t
 | 
|---|
| 156 | ManyBodyPotential_Tersoff::parameter_derivative(
 | 
|---|
| 157 |     const arguments_t &arguments,
 | 
|---|
| 158 |     const size_t index
 | 
|---|
| 159 |     ) const
 | 
|---|
| 160 | {
 | 
|---|
| 161 | //  Info info(__func__);
 | 
|---|
| 162 | //  ASSERT( arguments.size() == 1,
 | 
|---|
| 163 | //      "ManyBodyPotential_Tersoff::parameter_derivative() - requires exactly one argument.");
 | 
|---|
| 164 |   if (index == offset)
 | 
|---|
| 165 |     return results_t(1, 1.);
 | 
|---|
| 166 | 
 | 
|---|
| 167 |   double result = 0.;
 | 
|---|
| 168 |   for(arguments_t::const_iterator argiter = arguments.begin();
 | 
|---|
| 169 |       argiter != arguments.end();
 | 
|---|
| 170 |       ++argiter) {
 | 
|---|
| 171 |     const argument_t &r_ij = *argiter;
 | 
|---|
| 172 |   switch (index) {
 | 
|---|
| 173 | //    case R:
 | 
|---|
| 174 | //    {
 | 
|---|
| 175 | //      result += 0.;
 | 
|---|
| 176 | //      break;
 | 
|---|
| 177 | //    }
 | 
|---|
| 178 | //    case S:
 | 
|---|
| 179 | //    {
 | 
|---|
| 180 | //      result += 0.;
 | 
|---|
| 181 | //      break;
 | 
|---|
| 182 | //    }
 | 
|---|
| 183 |     case A:
 | 
|---|
| 184 |     {
 | 
|---|
| 185 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 186 |       result += (cutoff == 0.) ?
 | 
|---|
| 187 |           0. :
 | 
|---|
| 188 |           cutoff *
 | 
|---|
| 189 |               function_prefactor(
 | 
|---|
| 190 |                   alpha,
 | 
|---|
| 191 |                   function_eta(r_ij))
 | 
|---|
| 192 |               * function_smoother(
 | 
|---|
| 193 |                   1.,
 | 
|---|
| 194 |                   params[lambda],
 | 
|---|
| 195 |                   r_ij.distance);
 | 
|---|
| 196 | //          cutoff * function_prefactor(
 | 
|---|
| 197 | //              alpha,
 | 
|---|
| 198 | //              function_eta(r_ij))
 | 
|---|
| 199 | //          * function_smoother(
 | 
|---|
| 200 | //              1.,
 | 
|---|
| 201 | //              params[mu],
 | 
|---|
| 202 | //              r_ij.distance);
 | 
|---|
| 203 |       break;
 | 
|---|
| 204 |     }
 | 
|---|
| 205 |     case B:
 | 
|---|
| 206 |     {
 | 
|---|
| 207 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 208 |       result += (cutoff == 0.) ?
 | 
|---|
| 209 |           0. :
 | 
|---|
| 210 |           cutoff * function_prefactor(
 | 
|---|
| 211 |               params[beta],
 | 
|---|
| 212 |               function_zeta(r_ij))
 | 
|---|
| 213 |           * function_smoother(
 | 
|---|
| 214 |               -1.,
 | 
|---|
| 215 |               params[mu],
 | 
|---|
| 216 |               r_ij.distance);
 | 
|---|
| 217 | //          cutoff * function_prefactor(
 | 
|---|
| 218 | //              beta,
 | 
|---|
| 219 | //              function_zeta(r_ij))
 | 
|---|
| 220 | //          * function_smoother(
 | 
|---|
| 221 | //              -params[B],
 | 
|---|
| 222 | //              params[mu],
 | 
|---|
| 223 | //              r_ij.distance)/params[B];
 | 
|---|
| 224 |       break;
 | 
|---|
| 225 |     }
 | 
|---|
| 226 |     case lambda:
 | 
|---|
| 227 |     {
 | 
|---|
| 228 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 229 |       result += (cutoff == 0.) ?
 | 
|---|
| 230 |           0. :
 | 
|---|
| 231 |           -r_ij.distance * cutoff *
 | 
|---|
| 232 |               function_prefactor(
 | 
|---|
| 233 |                   alpha,
 | 
|---|
| 234 |                   function_eta(r_ij))
 | 
|---|
| 235 |               * function_smoother(
 | 
|---|
| 236 |                   params[A],
 | 
|---|
| 237 |                   params[lambda],
 | 
|---|
| 238 |                   r_ij.distance);
 | 
|---|
| 239 |       break;
 | 
|---|
| 240 |     }
 | 
|---|
| 241 |     case mu:
 | 
|---|
| 242 |     {
 | 
|---|
| 243 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 244 |       result += (cutoff == 0.) ?
 | 
|---|
| 245 |           0. :
 | 
|---|
| 246 |           -r_ij.distance * cutoff *(
 | 
|---|
| 247 |           function_prefactor(
 | 
|---|
| 248 |               params[beta],
 | 
|---|
| 249 |               function_zeta(r_ij))
 | 
|---|
| 250 |           * function_smoother(
 | 
|---|
| 251 |               -params[B],
 | 
|---|
| 252 |               params[mu],
 | 
|---|
| 253 |               r_ij.distance)
 | 
|---|
| 254 |       );
 | 
|---|
| 255 |       break;
 | 
|---|
| 256 |     }
 | 
|---|
| 257 | //    case lambda3:
 | 
|---|
| 258 | //    {
 | 
|---|
| 259 | //      result += 0.;
 | 
|---|
| 260 | //      break;
 | 
|---|
| 261 | //    }
 | 
|---|
| 262 | //    case alpha:
 | 
|---|
| 263 | //    {
 | 
|---|
| 264 | //      const double temp =
 | 
|---|
| 265 | //          pow(alpha*function_eta(r_ij), params[n]);
 | 
|---|
| 266 | //      const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 267 | //      result += (cutoff == 0.) || (alpha == 0. )?
 | 
|---|
| 268 | //          0. :
 | 
|---|
| 269 | //          function_smoother(
 | 
|---|
| 270 | //              params[A],
 | 
|---|
| 271 | //              params[lambda],
 | 
|---|
| 272 | //              r_ij.distance)
 | 
|---|
| 273 | //          * (-.5) * alpha * (temp/alpha)
 | 
|---|
| 274 | //          / (1. + temp)
 | 
|---|
| 275 | //          ;
 | 
|---|
| 276 | //      break;
 | 
|---|
| 277 | //    }
 | 
|---|
| 278 | //    case chi:
 | 
|---|
| 279 | //    {
 | 
|---|
| 280 | //      result += 0.;
 | 
|---|
| 281 | //      break;
 | 
|---|
| 282 | //    }
 | 
|---|
| 283 | //    case omega:
 | 
|---|
| 284 | //    {
 | 
|---|
| 285 | //      result += 0.;
 | 
|---|
| 286 | //      break;
 | 
|---|
| 287 | //    }
 | 
|---|
| 288 |     case beta:
 | 
|---|
| 289 |     {
 | 
|---|
| 290 |       const double temp =
 | 
|---|
| 291 |           pow(params[beta]*function_zeta(r_ij), params[n]);
 | 
|---|
| 292 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 293 |       result += (cutoff == 0.) || (params[beta] == 0. )?
 | 
|---|
| 294 |           0. : cutoff *
 | 
|---|
| 295 |           function_smoother(
 | 
|---|
| 296 |               -params[B],
 | 
|---|
| 297 |               params[mu],
 | 
|---|
| 298 |               r_ij.distance)
 | 
|---|
| 299 |           * (-.5)
 | 
|---|
| 300 |           * function_prefactor(
 | 
|---|
| 301 |               params[beta],
 | 
|---|
| 302 |               function_zeta(r_ij))
 | 
|---|
| 303 |           * (temp/params[beta])
 | 
|---|
| 304 |           / (1. + temp)
 | 
|---|
| 305 |           ;
 | 
|---|
| 306 |       break;
 | 
|---|
| 307 |     }
 | 
|---|
| 308 |     case n:
 | 
|---|
| 309 |     {
 | 
|---|
| 310 |       const double zeta = function_zeta(r_ij);
 | 
|---|
| 311 |       const double temp = pow( params[beta]*zeta , params[n]);
 | 
|---|
| 312 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 313 |       const double tempres = ((cutoff == 0.) || (zeta == 0.)) ? // zeta must be caught if zero due to log
 | 
|---|
| 314 |           0. : .5 * cutoff *
 | 
|---|
| 315 |           function_smoother(
 | 
|---|
| 316 |               -params[B],
 | 
|---|
| 317 |               params[mu],
 | 
|---|
| 318 |               r_ij.distance)
 | 
|---|
| 319 |           * function_prefactor(
 | 
|---|
| 320 |               params[beta],
 | 
|---|
| 321 |               function_zeta(r_ij))
 | 
|---|
| 322 |           * ( log(1.+temp)/(params[n]*params[n]) - temp
 | 
|---|
| 323 |               * (log(function_zeta(r_ij)) + log(params[beta]))
 | 
|---|
| 324 |               /(params[n]*(1.+temp)))
 | 
|---|
| 325 |           ;
 | 
|---|
| 326 | //      if (tempres != tempres)
 | 
|---|
| 327 | //      LOG(2, "DEBUG: tempres is NaN."); 
 | 
|---|
| 328 | //      LOG(2, "DEBUG: Adding " << tempres << " for p.d. w.r.t n, temp=" << temp << ", cutoff=" << cutoff);
 | 
|---|
| 329 |       result += tempres;
 | 
|---|
| 330 |       break;
 | 
|---|
| 331 |     }
 | 
|---|
| 332 |     case c:
 | 
|---|
| 333 |     {
 | 
|---|
| 334 |       const double zeta = function_zeta(r_ij);
 | 
|---|
| 335 |       if (zeta == 0.)
 | 
|---|
| 336 |         break;
 | 
|---|
| 337 |       const double temp =
 | 
|---|
| 338 |           pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
 | 
|---|
| 339 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 340 |       const double tempres = (cutoff == 0.) ?
 | 
|---|
| 341 |           0. : cutoff *
 | 
|---|
| 342 |           function_smoother(
 | 
|---|
| 343 |               -params[B],
 | 
|---|
| 344 |               params[mu],
 | 
|---|
| 345 |               r_ij.distance)
 | 
|---|
| 346 |           * function_prefactor(
 | 
|---|
| 347 |               params[beta],
 | 
|---|
| 348 |               zeta)
 | 
|---|
| 349 |            * (-1.) * temp / (1.+temp*zeta);
 | 
|---|
| 350 |       double factor = function_derivative_c(r_ij);
 | 
|---|
| 351 |       result += tempres*factor;
 | 
|---|
| 352 |       if (result != result)
 | 
|---|
| 353 |         ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
 | 
|---|
| 354 |       break;
 | 
|---|
| 355 |     }
 | 
|---|
| 356 |     case d:
 | 
|---|
| 357 |     {
 | 
|---|
| 358 |       const double zeta = function_zeta(r_ij);
 | 
|---|
| 359 |       const double temp =
 | 
|---|
| 360 |           pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
 | 
|---|
| 361 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 362 |       const double tempres = (cutoff == 0.) ?
 | 
|---|
| 363 |           0. : cutoff *
 | 
|---|
| 364 |           function_smoother(
 | 
|---|
| 365 |               -params[B],
 | 
|---|
| 366 |               params[mu],
 | 
|---|
| 367 |               r_ij.distance)
 | 
|---|
| 368 |           * function_prefactor(
 | 
|---|
| 369 |               params[beta],
 | 
|---|
| 370 |               zeta)
 | 
|---|
| 371 |            * (-1.) * temp / (1.+temp*zeta);
 | 
|---|
| 372 |       double factor = function_derivative_d(r_ij);
 | 
|---|
| 373 |       result += tempres*factor;
 | 
|---|
| 374 |       if (result != result)
 | 
|---|
| 375 |         ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
 | 
|---|
| 376 |       break;
 | 
|---|
| 377 |     }
 | 
|---|
| 378 |     case h:
 | 
|---|
| 379 |     {
 | 
|---|
| 380 |       const double zeta = function_zeta(r_ij);
 | 
|---|
| 381 |       const double temp =
 | 
|---|
| 382 |           pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
 | 
|---|
| 383 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 384 |       const double tempres = (cutoff == 0.) ?
 | 
|---|
| 385 |           0. : cutoff *
 | 
|---|
| 386 |           function_smoother(
 | 
|---|
| 387 |               -params[B],
 | 
|---|
| 388 |               params[mu],
 | 
|---|
| 389 |               r_ij.distance)
 | 
|---|
| 390 |           * function_prefactor(
 | 
|---|
| 391 |               params[beta],
 | 
|---|
| 392 |               zeta)
 | 
|---|
| 393 |            * (-1.) * temp / (1.+temp*zeta);
 | 
|---|
| 394 |       double factor = function_derivative_h(r_ij);
 | 
|---|
| 395 |       result += tempres*factor;
 | 
|---|
| 396 |       if (result != result)
 | 
|---|
| 397 |         ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
 | 
|---|
| 398 |       break;
 | 
|---|
| 399 |     }
 | 
|---|
| 400 |     case offset:
 | 
|---|
| 401 |       result += 1.;
 | 
|---|
| 402 |       break;
 | 
|---|
| 403 |     default:
 | 
|---|
| 404 |       break;
 | 
|---|
| 405 |   }
 | 
|---|
| 406 |   if (result != result)
 | 
|---|
| 407 |     ELOG(1, "result is NaN.");
 | 
|---|
| 408 |   }
 | 
|---|
| 409 |   return results_t(1,-result);
 | 
|---|
| 410 | }
 | 
|---|
| 411 | 
 | 
|---|
| 412 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 413 | ManyBodyPotential_Tersoff::function_derivative_c(
 | 
|---|
| 414 |     const argument_t &r_ij
 | 
|---|
| 415 |   ) const
 | 
|---|
| 416 | {
 | 
|---|
| 417 |   double result = 0.;
 | 
|---|
| 418 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 419 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 420 |       iter != triples.end(); ++iter) {
 | 
|---|
| 421 |     ASSERT( iter->size() == 2,
 | 
|---|
| 422 |         "ManyBodyPotential_Tersoff::function_derivative_c() - the triples result must contain exactly two distances.");
 | 
|---|
| 423 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 424 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
| 425 |     const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
 | 
|---|
| 426 |     const double cutoff = function_cutoff(r_ik.distance);
 | 
|---|
| 427 |     result += (cutoff == 0.) ?
 | 
|---|
| 428 |         0. : cutoff * omega * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
 | 
|---|
| 429 |             params[c]/Helpers::pow(params[d],2)
 | 
|---|
| 430 |             - params[c] / ( Helpers::pow(params[d],2) + Helpers::pow(tempangle,2) )
 | 
|---|
| 431 |         );
 | 
|---|
| 432 |   }
 | 
|---|
| 433 |   return result;
 | 
|---|
| 434 | }
 | 
|---|
| 435 | 
 | 
|---|
| 436 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 437 | ManyBodyPotential_Tersoff::function_derivative_d(
 | 
|---|
| 438 |     const argument_t &r_ij
 | 
|---|
| 439 |   ) const
 | 
|---|
| 440 | {
 | 
|---|
| 441 |   double result = 0.;
 | 
|---|
| 442 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 443 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 444 |       iter != triples.end(); ++iter) {
 | 
|---|
| 445 |     ASSERT( iter->size() == 2,
 | 
|---|
| 446 |         "ManyBodyPotential_Tersoff::function_derivative_d() - the triples result must contain exactly two distances.");
 | 
|---|
| 447 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 448 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
| 449 |     const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
 | 
|---|
| 450 |     const double cutoff = function_cutoff(r_ik.distance);
 | 
|---|
| 451 |     result += (cutoff == 0.) ?
 | 
|---|
| 452 |         0. : cutoff * omega  * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
 | 
|---|
| 453 |           - Helpers::pow(params[c],2)/Helpers::pow(params[d],3)
 | 
|---|
| 454 |           + Helpers::pow(params[c],2) * params[d]
 | 
|---|
| 455 |             / Helpers::pow(Helpers::pow(params[d],2) + Helpers::pow(tempangle,2),2)
 | 
|---|
| 456 |         );
 | 
|---|
| 457 |   }
 | 
|---|
| 458 |   return result;
 | 
|---|
| 459 | }
 | 
|---|
| 460 | 
 | 
|---|
| 461 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 462 | ManyBodyPotential_Tersoff::function_derivative_h(
 | 
|---|
| 463 |     const argument_t &r_ij
 | 
|---|
| 464 |   ) const
 | 
|---|
| 465 | {
 | 
|---|
| 466 |   double result = 0.;
 | 
|---|
| 467 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 468 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 469 |       iter != triples.end(); ++iter) {
 | 
|---|
| 470 |     ASSERT( iter->size() == 2,
 | 
|---|
| 471 |         "ManyBodyPotential_Tersoff::function_derivative_h() - the triples result must contain exactly two distances.");
 | 
|---|
| 472 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 473 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
| 474 |     const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
 | 
|---|
| 475 |     const double cutoff = function_cutoff(r_ik.distance);
 | 
|---|
| 476 |     result += (cutoff == 0.) ?
 | 
|---|
| 477 |         0. : cutoff * omega  * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
 | 
|---|
| 478 |           ( Helpers::pow(params[c],2)*tempangle )
 | 
|---|
| 479 |             / Helpers::pow(Helpers::pow(params[d],2) + Helpers::pow(tempangle,2),2)
 | 
|---|
| 480 |         );
 | 
|---|
| 481 |   }
 | 
|---|
| 482 |   return result;
 | 
|---|
| 483 | }
 | 
|---|
| 484 | 
 | 
|---|
| 485 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 486 | ManyBodyPotential_Tersoff::function_cutoff(
 | 
|---|
| 487 |     const double &distance
 | 
|---|
| 488 |   ) const
 | 
|---|
| 489 | {
 | 
|---|
| 490 | //  Info info(__func__);
 | 
|---|
| 491 |   double result = 0.;
 | 
|---|
| 492 |   if (distance < R)
 | 
|---|
| 493 |     result = 1.;
 | 
|---|
| 494 |   else if (distance > S)
 | 
|---|
| 495 |     result = 0.;
 | 
|---|
| 496 |   else {
 | 
|---|
| 497 |     result = (0.5 + 0.5 * cos( M_PI * (distance - R)/(S-R)));
 | 
|---|
| 498 |   }
 | 
|---|
| 499 | //  LOG(2, "DEBUG: function_cutoff(" << distance << ") = " << result);
 | 
|---|
| 500 |   return result;
 | 
|---|
| 501 | }
 | 
|---|
| 502 | 
 | 
|---|
| 503 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 504 | ManyBodyPotential_Tersoff::function_prefactor(
 | 
|---|
| 505 |     const double &alpha,
 | 
|---|
| 506 |     const double &eta
 | 
|---|
| 507 |   ) const
 | 
|---|
| 508 | {
 | 
|---|
| 509 | //  Info info(__func__);
 | 
|---|
| 510 |   const double result = chi * pow(
 | 
|---|
| 511 |       (1. + pow(alpha * eta, params[n])),
 | 
|---|
| 512 |       -1./(2.*params[n]));
 | 
|---|
| 513 | //  LOG(2, "DEBUG: function_prefactor(" << alpha << "," << eta << ") = " << result);
 | 
|---|
| 514 |   return result;
 | 
|---|
| 515 | }
 | 
|---|
| 516 | 
 | 
|---|
| 517 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 518 | ManyBodyPotential_Tersoff::function_smoother(
 | 
|---|
| 519 |     const double &prefactor,
 | 
|---|
| 520 |     const double &lambda,
 | 
|---|
| 521 |     const double &distance
 | 
|---|
| 522 |     ) const
 | 
|---|
| 523 | {
 | 
|---|
| 524 | //  Info info(__func__);
 | 
|---|
| 525 |   const double result = prefactor * exp(-lambda * distance);
 | 
|---|
| 526 | //  LOG(2, "DEBUG: function_smoother(" << prefactor << "," << lambda << "," << distance << ") = " << result);
 | 
|---|
| 527 |   return result;
 | 
|---|
| 528 | }
 | 
|---|
| 529 | 
 | 
|---|
| 530 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 531 | ManyBodyPotential_Tersoff::function_eta(
 | 
|---|
| 532 |     const argument_t &r_ij
 | 
|---|
| 533 |   ) const
 | 
|---|
| 534 | {
 | 
|---|
| 535 | //  Info info(__func__);
 | 
|---|
| 536 |   result_t result = 0.;
 | 
|---|
| 537 | 
 | 
|---|
| 538 |   // get all triples within the cutoff
 | 
|---|
| 539 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 540 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 541 |       iter != triples.end(); ++iter) {
 | 
|---|
| 542 |     ASSERT( iter->size() == 2,
 | 
|---|
| 543 |         "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain of exactly two distances.");
 | 
|---|
| 544 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 545 |     result += function_cutoff(r_ik.distance)
 | 
|---|
| 546 |         * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3));
 | 
|---|
| 547 |   }
 | 
|---|
| 548 | 
 | 
|---|
| 549 | //  LOG(2, "DEBUG: function_eta(" << r_ij.distance << ") = " << result);
 | 
|---|
| 550 |   return result;
 | 
|---|
| 551 | }
 | 
|---|
| 552 | 
 | 
|---|
| 553 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 554 | ManyBodyPotential_Tersoff::function_zeta(
 | 
|---|
| 555 |     const argument_t &r_ij
 | 
|---|
| 556 |   ) const
 | 
|---|
| 557 | {
 | 
|---|
| 558 | //  Info info(__func__);
 | 
|---|
| 559 |   result_t result = 0.;
 | 
|---|
| 560 | 
 | 
|---|
| 561 |   // get all triples within the cutoff
 | 
|---|
| 562 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 563 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 564 |       iter != triples.end(); ++iter) {
 | 
|---|
| 565 |     ASSERT( iter->size() == 2,
 | 
|---|
| 566 |         "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain exactly two distances.");
 | 
|---|
| 567 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 568 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
| 569 |     result +=
 | 
|---|
| 570 |         function_cutoff(r_ik.distance)
 | 
|---|
| 571 |         * omega
 | 
|---|
| 572 |         * function_angle(r_ij.distance, r_ik.distance, r_jk.distance)
 | 
|---|
| 573 |         * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3));
 | 
|---|
| 574 |   }
 | 
|---|
| 575 | 
 | 
|---|
| 576 | //  LOG(2, "DEBUG: function_zeta(" << r_ij.distance << ") = " << result);
 | 
|---|
| 577 |   return result;
 | 
|---|
| 578 | }
 | 
|---|
| 579 | 
 | 
|---|
| 580 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 581 | ManyBodyPotential_Tersoff::function_theta(
 | 
|---|
| 582 |     const double &r_ij,
 | 
|---|
| 583 |     const double &r_ik,
 | 
|---|
| 584 |     const double &r_jk
 | 
|---|
| 585 |   ) const
 | 
|---|
| 586 | {
 | 
|---|
| 587 |   const double angle = Helpers::pow(r_ij,2) + Helpers::pow(r_ik,2) - Helpers::pow(r_jk,2);
 | 
|---|
| 588 |   const double divisor = 2.* r_ij * r_ik;
 | 
|---|
| 589 |   if (divisor != 0.) {
 | 
|---|
| 590 |     LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
 | 
|---|
| 591 |     return angle/divisor;
 | 
|---|
| 592 |   } else
 | 
|---|
| 593 |     return 0.;
 | 
|---|
| 594 | }
 | 
|---|
| 595 | 
 | 
|---|
| 596 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 597 | ManyBodyPotential_Tersoff::function_angle(
 | 
|---|
| 598 |     const double &r_ij,
 | 
|---|
| 599 |     const double &r_ik,
 | 
|---|
| 600 |     const double &r_jk
 | 
|---|
| 601 |   ) const
 | 
|---|
| 602 | {
 | 
|---|
| 603 | //  Info info(__func__);
 | 
|---|
| 604 |   const double result =
 | 
|---|
| 605 |       1.
 | 
|---|
| 606 |       + (Helpers::pow(params[c]/params[d], 2))
 | 
|---|
| 607 |       - Helpers::pow(params[c], 2)/(Helpers::pow(params[d], 2) +
 | 
|---|
| 608 |           Helpers::pow(params[h] - function_theta(r_ij, r_ik, r_jk),2));
 | 
|---|
| 609 | 
 | 
|---|
| 610 | //  LOG(2, "DEBUG: function_angle(" << r_ij << "," << r_ik << "," << r_jk << ") = " << result);
 | 
|---|
| 611 |   return result;
 | 
|---|
| 612 | }
 | 
|---|
| 613 | 
 | 
|---|