| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2012 University of Bonn. All rights reserved.
 | 
|---|
| 5 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| 6 |  * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
 | 
|---|
| 7 |  * 
 | 
|---|
| 8 |  *
 | 
|---|
| 9 |  *   This file is part of MoleCuilder.
 | 
|---|
| 10 |  *
 | 
|---|
| 11 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
| 12 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
| 13 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
| 14 |  *    (at your option) any later version.
 | 
|---|
| 15 |  *
 | 
|---|
| 16 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
| 17 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 18 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 19 |  *    GNU General Public License for more details.
 | 
|---|
| 20 |  *
 | 
|---|
| 21 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
| 22 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. 
 | 
|---|
| 23 |  */
 | 
|---|
| 24 | 
 | 
|---|
| 25 | /*
 | 
|---|
| 26 |  * ManyBodyPotential_Tersoff.cpp
 | 
|---|
| 27 |  *
 | 
|---|
| 28 |  *  Created on: Sep 26, 2012
 | 
|---|
| 29 |  *      Author: heber
 | 
|---|
| 30 |  */
 | 
|---|
| 31 | 
 | 
|---|
| 32 | 
 | 
|---|
| 33 | // include config.h
 | 
|---|
| 34 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 35 | #include <config.h>
 | 
|---|
| 36 | #endif
 | 
|---|
| 37 | 
 | 
|---|
| 38 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 39 | 
 | 
|---|
| 40 | #include "ManyBodyPotential_Tersoff.hpp"
 | 
|---|
| 41 | 
 | 
|---|
| 42 | #include <boost/assign/list_of.hpp> // for 'map_list_of()'
 | 
|---|
| 43 | #include <boost/bind.hpp>
 | 
|---|
| 44 | #include <cmath>
 | 
|---|
| 45 | #include <string>
 | 
|---|
| 46 | 
 | 
|---|
| 47 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| 48 | //#include "CodePatterns/Info.hpp"
 | 
|---|
| 49 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 50 | 
 | 
|---|
| 51 | #include "FunctionApproximation/Extractors.hpp"
 | 
|---|
| 52 | #include "FunctionApproximation/TrainingData.hpp"
 | 
|---|
| 53 | #include "Potentials/helpers.hpp"
 | 
|---|
| 54 | #include "Potentials/InternalCoordinates/OneBody_Constant.hpp"
 | 
|---|
| 55 | #include "Potentials/ParticleTypeCheckers.hpp"
 | 
|---|
| 56 | #include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
 | 
|---|
| 57 | #include "RandomNumbers/RandomNumberGenerator.hpp"
 | 
|---|
| 58 | 
 | 
|---|
| 59 | class Fragment;
 | 
|---|
| 60 | 
 | 
|---|
| 61 | // static definitions
 | 
|---|
| 62 | const ManyBodyPotential_Tersoff::ParameterNames_t
 | 
|---|
| 63 | ManyBodyPotential_Tersoff::ParameterNames =
 | 
|---|
| 64 |       boost::assign::list_of<std::string>
 | 
|---|
| 65 |       ("A")
 | 
|---|
| 66 |       ("B")
 | 
|---|
| 67 |       ("lambda")
 | 
|---|
| 68 |       ("mu")
 | 
|---|
| 69 |       ("beta")
 | 
|---|
| 70 |       ("n")
 | 
|---|
| 71 |       ("c")
 | 
|---|
| 72 |       ("d")
 | 
|---|
| 73 |       ("h")
 | 
|---|
| 74 | //      ("R")
 | 
|---|
| 75 | //      ("S")
 | 
|---|
| 76 | //      ("lambda3")
 | 
|---|
| 77 | //      ("alpha")
 | 
|---|
| 78 | //      ("chi")
 | 
|---|
| 79 | //      ("omega")
 | 
|---|
| 80 |     ;
 | 
|---|
| 81 | const std::string ManyBodyPotential_Tersoff::potential_token("tersoff");
 | 
|---|
| 82 | Coordinator::ptr ManyBodyPotential_Tersoff::coordinator(Memory::ignore(new OneBody_Constant()));
 | 
|---|
| 83 | 
 | 
|---|
| 84 | ManyBodyPotential_Tersoff::ManyBodyPotential_Tersoff() :
 | 
|---|
| 85 |     EmpiricalPotential(),
 | 
|---|
| 86 |     params(parameters_t(MAXPARAMS, 0.)),
 | 
|---|
| 87 |     R(3.2),
 | 
|---|
| 88 |     S(3.5),
 | 
|---|
| 89 |     lambda3(0.),
 | 
|---|
| 90 |     alpha(0.),
 | 
|---|
| 91 |     chi(1.),
 | 
|---|
| 92 |     omega(1.),
 | 
|---|
| 93 |     triplefunction(&Helpers::NoOp_Triplefunction)
 | 
|---|
| 94 | {}
 | 
|---|
| 95 | 
 | 
|---|
| 96 | ManyBodyPotential_Tersoff::ManyBodyPotential_Tersoff(
 | 
|---|
| 97 |     const ParticleTypes_t &_ParticleTypes
 | 
|---|
| 98 |     ) :
 | 
|---|
| 99 |     EmpiricalPotential(_ParticleTypes),
 | 
|---|
| 100 |     params(parameters_t(MAXPARAMS, 0.)),
 | 
|---|
| 101 |     R(3.2),
 | 
|---|
| 102 |     S(3.5),
 | 
|---|
| 103 |     lambda3(0.),
 | 
|---|
| 104 |     alpha(0.),
 | 
|---|
| 105 |     chi(1.),
 | 
|---|
| 106 |     omega(1.),
 | 
|---|
| 107 |     triplefunction(&Helpers::NoOp_Triplefunction)
 | 
|---|
| 108 | {
 | 
|---|
| 109 |   // have some decent defaults for parameter_derivative checking
 | 
|---|
| 110 |   params[A] = 3000.;
 | 
|---|
| 111 |   params[B] = 300.;
 | 
|---|
| 112 |   params[lambda] = 5.;
 | 
|---|
| 113 |   params[mu] = 3.;
 | 
|---|
| 114 |   params[beta] = 2.;
 | 
|---|
| 115 |   params[n] = 1.;
 | 
|---|
| 116 |   params[c] = 0.01;
 | 
|---|
| 117 |   params[d] = 1.;
 | 
|---|
| 118 |   params[h] = 0.01;
 | 
|---|
| 119 | }
 | 
|---|
| 120 | 
 | 
|---|
| 121 | ManyBodyPotential_Tersoff::ManyBodyPotential_Tersoff(
 | 
|---|
| 122 |     const ParticleTypes_t &_ParticleTypes,
 | 
|---|
| 123 |     const double &_R,
 | 
|---|
| 124 |     const double &_S,
 | 
|---|
| 125 |     const double &_A,
 | 
|---|
| 126 |     const double &_B,
 | 
|---|
| 127 |     const double &_lambda,
 | 
|---|
| 128 |     const double &_mu,
 | 
|---|
| 129 |     const double &_lambda3,
 | 
|---|
| 130 |     const double &_alpha,
 | 
|---|
| 131 |     const double &_beta,
 | 
|---|
| 132 |     const double &_chi,
 | 
|---|
| 133 |     const double &_omega,
 | 
|---|
| 134 |     const double &_n,
 | 
|---|
| 135 |     const double &_c,
 | 
|---|
| 136 |     const double &_d,
 | 
|---|
| 137 |     const double &_h) :
 | 
|---|
| 138 |   EmpiricalPotential(_ParticleTypes),
 | 
|---|
| 139 |   params(parameters_t(MAXPARAMS, 0.)),
 | 
|---|
| 140 |   R(_R),
 | 
|---|
| 141 |   S(_S),
 | 
|---|
| 142 |   lambda3(_lambda3),
 | 
|---|
| 143 |   alpha(_alpha),
 | 
|---|
| 144 |   chi(_chi),
 | 
|---|
| 145 |   omega(_mu),
 | 
|---|
| 146 |   triplefunction(&Helpers::NoOp_Triplefunction)
 | 
|---|
| 147 | {
 | 
|---|
| 148 | //  Info info(__func__);
 | 
|---|
| 149 | //  R = _R;
 | 
|---|
| 150 | //  S = _S;
 | 
|---|
| 151 |   params[A] = _A;
 | 
|---|
| 152 |   params[B] = _B;
 | 
|---|
| 153 |   params[lambda] = _lambda;
 | 
|---|
| 154 |   params[mu] = _mu;
 | 
|---|
| 155 | //  lambda3 = _lambda3;
 | 
|---|
| 156 | //  alpha = _alpha;
 | 
|---|
| 157 |   params[beta] = _beta;
 | 
|---|
| 158 | //  chi = _chi;
 | 
|---|
| 159 | //  omega = _omega;
 | 
|---|
| 160 |   params[n] = _n;
 | 
|---|
| 161 |   params[c] = _c;
 | 
|---|
| 162 |   params[d] = _d;
 | 
|---|
| 163 |   params[h] = _h;
 | 
|---|
| 164 | }
 | 
|---|
| 165 | 
 | 
|---|
| 166 | void ManyBodyPotential_Tersoff::setParameters(const parameters_t &_params)
 | 
|---|
| 167 | {
 | 
|---|
| 168 |   const size_t paramsDim = _params.size();
 | 
|---|
| 169 |   ASSERT( paramsDim <= getParameterDimension(),
 | 
|---|
| 170 |       "ManyBodyPotential_Tersoff::setParameters() - we need not more than "
 | 
|---|
| 171 |       +toString(getParameterDimension())+" parameters.");
 | 
|---|
| 172 |   for (size_t i=0; i< paramsDim; ++i)
 | 
|---|
| 173 |     params[i] = _params[i];
 | 
|---|
| 174 | 
 | 
|---|
| 175 | #ifndef NDEBUG
 | 
|---|
| 176 |   parameters_t check_params(getParameters());
 | 
|---|
| 177 |   check_params.resize(paramsDim); // truncate to same size
 | 
|---|
| 178 |   ASSERT( check_params == _params,
 | 
|---|
| 179 |       "ManyBodyPotential_Tersoff::setParameters() - failed, mismatch in to be set "
 | 
|---|
| 180 |       +toString(_params)+" and set "+toString(check_params)+" params.");
 | 
|---|
| 181 | #endif
 | 
|---|
| 182 | }
 | 
|---|
| 183 | 
 | 
|---|
| 184 | ManyBodyPotential_Tersoff::results_t
 | 
|---|
| 185 | ManyBodyPotential_Tersoff::operator()(
 | 
|---|
| 186 |     const list_of_arguments_t &listarguments
 | 
|---|
| 187 |     ) const
 | 
|---|
| 188 | {
 | 
|---|
| 189 | //  Info info(__func__);
 | 
|---|
| 190 |   result_t result = 0.;
 | 
|---|
| 191 |   for(list_of_arguments_t::const_iterator iter = listarguments.begin();
 | 
|---|
| 192 |       iter != listarguments.end(); ++iter) {
 | 
|---|
| 193 |     const arguments_t &arguments = *iter;
 | 
|---|
| 194 |     for(arguments_t::const_iterator argiter = arguments.begin();
 | 
|---|
| 195 |         argiter != arguments.end();
 | 
|---|
| 196 |         ++argiter) {
 | 
|---|
| 197 |       const argument_t &r_ij = *argiter;
 | 
|---|
| 198 |       ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
 | 
|---|
| 199 |           arguments_t(1, r_ij), getParticleTypes()),
 | 
|---|
| 200 |           "ManyBodyPotential_Tersoff::operator() - types don't match with ones in arguments.");
 | 
|---|
| 201 | 
 | 
|---|
| 202 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 203 |       const double temp = (cutoff == 0.) ?
 | 
|---|
| 204 |           0. :
 | 
|---|
| 205 |           cutoff * (
 | 
|---|
| 206 |               function_prefactor(
 | 
|---|
| 207 |                   alpha,
 | 
|---|
| 208 |                   function_eta(r_ij))
 | 
|---|
| 209 |               * function_smoother(
 | 
|---|
| 210 |                   params[A],
 | 
|---|
| 211 |                   params[lambda],
 | 
|---|
| 212 |                   r_ij.distance)
 | 
|---|
| 213 |               +
 | 
|---|
| 214 |               function_prefactor(
 | 
|---|
| 215 |                   params[beta],
 | 
|---|
| 216 |                   function_zeta(r_ij))
 | 
|---|
| 217 |               * function_smoother(
 | 
|---|
| 218 |                   -params[B],
 | 
|---|
| 219 |                   params[mu],
 | 
|---|
| 220 |                   r_ij.distance)
 | 
|---|
| 221 |           );
 | 
|---|
| 222 |       result += temp;
 | 
|---|
| 223 |     }
 | 
|---|
| 224 |   }
 | 
|---|
| 225 | //  LOG(2, "DEBUG: operator()(" << r_ij.distance << ") = " << result);
 | 
|---|
| 226 |   return results_t(1, result);
 | 
|---|
| 227 | }
 | 
|---|
| 228 | 
 | 
|---|
| 229 | ManyBodyPotential_Tersoff::derivative_components_t
 | 
|---|
| 230 | ManyBodyPotential_Tersoff::derivative(
 | 
|---|
| 231 |     const list_of_arguments_t &listarguments
 | 
|---|
| 232 |     ) const
 | 
|---|
| 233 | {
 | 
|---|
| 234 | //  Info info(__func__);
 | 
|---|
| 235 |   return derivative_components_t();
 | 
|---|
| 236 | }
 | 
|---|
| 237 | 
 | 
|---|
| 238 | ManyBodyPotential_Tersoff::results_t
 | 
|---|
| 239 | ManyBodyPotential_Tersoff::parameter_derivative(
 | 
|---|
| 240 |     const list_of_arguments_t &listarguments,
 | 
|---|
| 241 |     const size_t index
 | 
|---|
| 242 |     ) const
 | 
|---|
| 243 | {
 | 
|---|
| 244 | //  Info info(__func__);
 | 
|---|
| 245 | //  ASSERT( arguments.size() == 1,
 | 
|---|
| 246 | //      "ManyBodyPotential_Tersoff::parameter_derivative() - requires exactly one argument.");
 | 
|---|
| 247 | 
 | 
|---|
| 248 |   result_t result = 0.;
 | 
|---|
| 249 |   for(list_of_arguments_t::const_iterator iter = listarguments.begin();
 | 
|---|
| 250 |       iter != listarguments.end(); ++iter) {
 | 
|---|
| 251 |     const arguments_t &arguments = *iter;
 | 
|---|
| 252 |     for(arguments_t::const_iterator argiter = arguments.begin();
 | 
|---|
| 253 |         argiter != arguments.end();
 | 
|---|
| 254 |         ++argiter) {
 | 
|---|
| 255 |       const argument_t &r_ij = *argiter;
 | 
|---|
| 256 |       ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
 | 
|---|
| 257 |           arguments_t(1, r_ij), getParticleTypes()),
 | 
|---|
| 258 |           "ManyBodyPotential_Tersoff::operator() - types don't match with ones in arguments.");
 | 
|---|
| 259 | 
 | 
|---|
| 260 |     switch (index) {
 | 
|---|
| 261 | //      case R:
 | 
|---|
| 262 | //      {
 | 
|---|
| 263 | //        result += 0.;
 | 
|---|
| 264 | //        break;
 | 
|---|
| 265 | //      }
 | 
|---|
| 266 | //      case S:
 | 
|---|
| 267 | //      {
 | 
|---|
| 268 | //        result += 0.;
 | 
|---|
| 269 | //        break;
 | 
|---|
| 270 | //      }
 | 
|---|
| 271 |       case A:
 | 
|---|
| 272 |       {
 | 
|---|
| 273 |         const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 274 |         result += (cutoff == 0.) ?
 | 
|---|
| 275 |             0. :
 | 
|---|
| 276 |             cutoff *
 | 
|---|
| 277 |                 function_prefactor(
 | 
|---|
| 278 |                     alpha,
 | 
|---|
| 279 |                     function_eta(r_ij))
 | 
|---|
| 280 |                 * function_smoother(
 | 
|---|
| 281 |                     1.,
 | 
|---|
| 282 |                     params[lambda],
 | 
|---|
| 283 |                     r_ij.distance);
 | 
|---|
| 284 | //            cutoff * function_prefactor(
 | 
|---|
| 285 | //                alpha,
 | 
|---|
| 286 | //                function_eta(r_ij))
 | 
|---|
| 287 | //            * function_smoother(
 | 
|---|
| 288 | //                1.,
 | 
|---|
| 289 | //                params[mu],
 | 
|---|
| 290 | //                r_ij.distance);
 | 
|---|
| 291 |         break;
 | 
|---|
| 292 |       }
 | 
|---|
| 293 |       case B:
 | 
|---|
| 294 |       {
 | 
|---|
| 295 |         const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 296 |         result += (cutoff == 0.) ?
 | 
|---|
| 297 |             0. :
 | 
|---|
| 298 |             cutoff * function_prefactor(
 | 
|---|
| 299 |                 params[beta],
 | 
|---|
| 300 |                 function_zeta(r_ij))
 | 
|---|
| 301 |             * function_smoother(
 | 
|---|
| 302 |                 -1.,
 | 
|---|
| 303 |                 params[mu],
 | 
|---|
| 304 |                 r_ij.distance);
 | 
|---|
| 305 | //            cutoff * function_prefactor(
 | 
|---|
| 306 | //                beta,
 | 
|---|
| 307 | //                function_zeta(r_ij))
 | 
|---|
| 308 | //            * function_smoother(
 | 
|---|
| 309 | //                -params[B],
 | 
|---|
| 310 | //                params[mu],
 | 
|---|
| 311 | //                r_ij.distance)/params[B];
 | 
|---|
| 312 |         break;
 | 
|---|
| 313 |       }
 | 
|---|
| 314 |       case lambda:
 | 
|---|
| 315 |       {
 | 
|---|
| 316 |         const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 317 |         result += (cutoff == 0.) ?
 | 
|---|
| 318 |             0. :
 | 
|---|
| 319 |             -r_ij.distance * cutoff *
 | 
|---|
| 320 |                 function_prefactor(
 | 
|---|
| 321 |                     alpha,
 | 
|---|
| 322 |                     function_eta(r_ij))
 | 
|---|
| 323 |                 * function_smoother(
 | 
|---|
| 324 |                     params[A],
 | 
|---|
| 325 |                     params[lambda],
 | 
|---|
| 326 |                     r_ij.distance);
 | 
|---|
| 327 |         break;
 | 
|---|
| 328 |       }
 | 
|---|
| 329 |       case mu:
 | 
|---|
| 330 |       {
 | 
|---|
| 331 |         const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 332 |         result += (cutoff == 0.) ?
 | 
|---|
| 333 |             0. :
 | 
|---|
| 334 |             -r_ij.distance * cutoff *(
 | 
|---|
| 335 |             function_prefactor(
 | 
|---|
| 336 |                 params[beta],
 | 
|---|
| 337 |                 function_zeta(r_ij))
 | 
|---|
| 338 |             * function_smoother(
 | 
|---|
| 339 |                 -params[B],
 | 
|---|
| 340 |                 params[mu],
 | 
|---|
| 341 |                 r_ij.distance)
 | 
|---|
| 342 |         );
 | 
|---|
| 343 |         break;
 | 
|---|
| 344 |       }
 | 
|---|
| 345 | //      case lambda3:
 | 
|---|
| 346 | //      {
 | 
|---|
| 347 | //        result += 0.;
 | 
|---|
| 348 | //        break;
 | 
|---|
| 349 | //      }
 | 
|---|
| 350 | //      case alpha:
 | 
|---|
| 351 | //      {
 | 
|---|
| 352 | //        const double temp =
 | 
|---|
| 353 | //            pow(alpha*function_eta(r_ij), params[n]);
 | 
|---|
| 354 | //        const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 355 | //        result += (cutoff == 0.) || (alpha == 0. )?
 | 
|---|
| 356 | //            0. :
 | 
|---|
| 357 | //            function_smoother(
 | 
|---|
| 358 | //                params[A],
 | 
|---|
| 359 | //                params[lambda],
 | 
|---|
| 360 | //                r_ij.distance)
 | 
|---|
| 361 | //            * (-.5) * alpha * (temp/alpha)
 | 
|---|
| 362 | //            / (1. + temp)
 | 
|---|
| 363 | //            ;
 | 
|---|
| 364 | //        break;
 | 
|---|
| 365 | //      }
 | 
|---|
| 366 | //      case chi:
 | 
|---|
| 367 | //      {
 | 
|---|
| 368 | //        result += 0.;
 | 
|---|
| 369 | //        break;
 | 
|---|
| 370 | //      }
 | 
|---|
| 371 | //      case omega:
 | 
|---|
| 372 | //      {
 | 
|---|
| 373 | //        result += 0.;
 | 
|---|
| 374 | //        break;
 | 
|---|
| 375 | //      }
 | 
|---|
| 376 |       case beta:
 | 
|---|
| 377 |       {
 | 
|---|
| 378 |         const double temp =
 | 
|---|
| 379 |             pow(params[beta]*function_zeta(r_ij), params[n]);
 | 
|---|
| 380 |         const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 381 |         result += (cutoff == 0.) || (params[beta] == 0. )?
 | 
|---|
| 382 |             0. : cutoff *
 | 
|---|
| 383 |             function_smoother(
 | 
|---|
| 384 |                 -params[B],
 | 
|---|
| 385 |                 params[mu],
 | 
|---|
| 386 |                 r_ij.distance)
 | 
|---|
| 387 |             * (-.5)
 | 
|---|
| 388 |             * function_prefactor(
 | 
|---|
| 389 |                 params[beta],
 | 
|---|
| 390 |                 function_zeta(r_ij))
 | 
|---|
| 391 |             * (temp/params[beta])
 | 
|---|
| 392 |             / (1. + temp)
 | 
|---|
| 393 |             ;
 | 
|---|
| 394 |         break;
 | 
|---|
| 395 |       }
 | 
|---|
| 396 |       case n:
 | 
|---|
| 397 |       {
 | 
|---|
| 398 |         const double zeta = function_zeta(r_ij);
 | 
|---|
| 399 |         const double temp = pow( params[beta]*zeta , params[n]);
 | 
|---|
| 400 |         const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 401 |         const double tempres = ((cutoff == 0.) || (zeta == 0.)) ? // zeta must be caught if zero due to log
 | 
|---|
| 402 |             0. : .5 * cutoff *
 | 
|---|
| 403 |             function_smoother(
 | 
|---|
| 404 |                 -params[B],
 | 
|---|
| 405 |                 params[mu],
 | 
|---|
| 406 |                 r_ij.distance)
 | 
|---|
| 407 |             * function_prefactor(
 | 
|---|
| 408 |                 params[beta],
 | 
|---|
| 409 |                 function_zeta(r_ij))
 | 
|---|
| 410 |             * ( log(1.+temp)/(params[n]*params[n]) - temp
 | 
|---|
| 411 |                 * (log(function_zeta(r_ij)) + log(params[beta]))
 | 
|---|
| 412 |                 /(params[n]*(1.+temp)))
 | 
|---|
| 413 |             ;
 | 
|---|
| 414 | //        if (tempres != tempres)
 | 
|---|
| 415 | //    LOG(2, "DEBUG: tempres is NaN.");
 | 
|---|
| 416 | //        LOG(2, "DEBUG: Adding " << tempres << " for p.d. w.r.t n, temp=" << temp << ", cutoff=" << cutoff);
 | 
|---|
| 417 |         result += tempres;
 | 
|---|
| 418 |         break;
 | 
|---|
| 419 |       }
 | 
|---|
| 420 |       case c:
 | 
|---|
| 421 |       {
 | 
|---|
| 422 |         const double zeta = function_zeta(r_ij);
 | 
|---|
| 423 |         if (zeta == 0.)
 | 
|---|
| 424 |           break;
 | 
|---|
| 425 |         const double temp =
 | 
|---|
| 426 |             pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
 | 
|---|
| 427 |         const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 428 |         const double tempres = (cutoff == 0.) ?
 | 
|---|
| 429 |             0. : cutoff *
 | 
|---|
| 430 |             function_smoother(
 | 
|---|
| 431 |                 -params[B],
 | 
|---|
| 432 |                 params[mu],
 | 
|---|
| 433 |                 r_ij.distance)
 | 
|---|
| 434 |             * function_prefactor(
 | 
|---|
| 435 |                 params[beta],
 | 
|---|
| 436 |                 zeta)
 | 
|---|
| 437 |              * (-1.) * temp / (1.+temp*zeta);
 | 
|---|
| 438 |         double factor = function_derivative_c(r_ij);
 | 
|---|
| 439 |         result += tempres*factor;
 | 
|---|
| 440 |         if (result != result)
 | 
|---|
| 441 |           ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
 | 
|---|
| 442 |         break;
 | 
|---|
| 443 |       }
 | 
|---|
| 444 |       case d:
 | 
|---|
| 445 |       {
 | 
|---|
| 446 |         const double zeta = function_zeta(r_ij);
 | 
|---|
| 447 |         const double temp =
 | 
|---|
| 448 |             pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
 | 
|---|
| 449 |         const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 450 |         const double tempres = (cutoff == 0.) ?
 | 
|---|
| 451 |             0. : cutoff *
 | 
|---|
| 452 |             function_smoother(
 | 
|---|
| 453 |                 -params[B],
 | 
|---|
| 454 |                 params[mu],
 | 
|---|
| 455 |                 r_ij.distance)
 | 
|---|
| 456 |             * function_prefactor(
 | 
|---|
| 457 |                 params[beta],
 | 
|---|
| 458 |                 zeta)
 | 
|---|
| 459 |              * (-1.) * temp / (1.+temp*zeta);
 | 
|---|
| 460 |         double factor = function_derivative_d(r_ij);
 | 
|---|
| 461 |         result += tempres*factor;
 | 
|---|
| 462 |         if (result != result)
 | 
|---|
| 463 |           ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
 | 
|---|
| 464 |         break;
 | 
|---|
| 465 |       }
 | 
|---|
| 466 |       case h:
 | 
|---|
| 467 |       {
 | 
|---|
| 468 |         const double zeta = function_zeta(r_ij);
 | 
|---|
| 469 |         const double temp =
 | 
|---|
| 470 |             pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
 | 
|---|
| 471 |         const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| 472 |         const double tempres = (cutoff == 0.) ?
 | 
|---|
| 473 |             0. : cutoff *
 | 
|---|
| 474 |             function_smoother(
 | 
|---|
| 475 |                 -params[B],
 | 
|---|
| 476 |                 params[mu],
 | 
|---|
| 477 |                 r_ij.distance)
 | 
|---|
| 478 |             * function_prefactor(
 | 
|---|
| 479 |                 params[beta],
 | 
|---|
| 480 |                 zeta)
 | 
|---|
| 481 |              * (-1.) * temp / (1.+temp*zeta);
 | 
|---|
| 482 |         double factor = function_derivative_h(r_ij);
 | 
|---|
| 483 |         result += tempres*factor;
 | 
|---|
| 484 |         if (result != result)
 | 
|---|
| 485 |           ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
 | 
|---|
| 486 |         break;
 | 
|---|
| 487 |       }
 | 
|---|
| 488 |       default:
 | 
|---|
| 489 |         ASSERT(0, "ManyBodyPotential_Tersoff::parameter_derivative() - derivative to unknown parameter desired.");
 | 
|---|
| 490 |         break;
 | 
|---|
| 491 |     }
 | 
|---|
| 492 |     if (result != result)
 | 
|---|
| 493 |       ELOG(1, "result is NaN.");
 | 
|---|
| 494 |     }
 | 
|---|
| 495 |   }
 | 
|---|
| 496 |   return results_t(1,-result);
 | 
|---|
| 497 | }
 | 
|---|
| 498 | 
 | 
|---|
| 499 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 500 | ManyBodyPotential_Tersoff::function_derivative_c(
 | 
|---|
| 501 |     const argument_t &r_ij
 | 
|---|
| 502 |   ) const
 | 
|---|
| 503 | {
 | 
|---|
| 504 |   double result = 0.;
 | 
|---|
| 505 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 506 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 507 |       iter != triples.end(); ++iter) {
 | 
|---|
| 508 |     ASSERT( iter->size() == 2,
 | 
|---|
| 509 |         "ManyBodyPotential_Tersoff::function_derivative_c() - the triples result must contain exactly two distances.");
 | 
|---|
| 510 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 511 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
| 512 |     const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
 | 
|---|
| 513 |     const double cutoff = function_cutoff(r_ik.distance);
 | 
|---|
| 514 |     result += (cutoff == 0.) ?
 | 
|---|
| 515 |         0. : cutoff * omega * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
 | 
|---|
| 516 |             params[c]/Helpers::pow(params[d],2)
 | 
|---|
| 517 |             - params[c] / ( Helpers::pow(params[d],2) + Helpers::pow(tempangle,2) )
 | 
|---|
| 518 |         );
 | 
|---|
| 519 |   }
 | 
|---|
| 520 |   return result;
 | 
|---|
| 521 | }
 | 
|---|
| 522 | 
 | 
|---|
| 523 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 524 | ManyBodyPotential_Tersoff::function_derivative_d(
 | 
|---|
| 525 |     const argument_t &r_ij
 | 
|---|
| 526 |   ) const
 | 
|---|
| 527 | {
 | 
|---|
| 528 |   double result = 0.;
 | 
|---|
| 529 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 530 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 531 |       iter != triples.end(); ++iter) {
 | 
|---|
| 532 |     ASSERT( iter->size() == 2,
 | 
|---|
| 533 |         "ManyBodyPotential_Tersoff::function_derivative_d() - the triples result must contain exactly two distances.");
 | 
|---|
| 534 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 535 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
| 536 |     const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
 | 
|---|
| 537 |     const double cutoff = function_cutoff(r_ik.distance);
 | 
|---|
| 538 |     result += (cutoff == 0.) ?
 | 
|---|
| 539 |         0. : cutoff * omega  * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
 | 
|---|
| 540 |           - Helpers::pow(params[c],2)/Helpers::pow(params[d],3)
 | 
|---|
| 541 |           + Helpers::pow(params[c],2) * params[d]
 | 
|---|
| 542 |             / Helpers::pow(Helpers::pow(params[d],2) + Helpers::pow(tempangle,2),2)
 | 
|---|
| 543 |         );
 | 
|---|
| 544 |   }
 | 
|---|
| 545 |   return result;
 | 
|---|
| 546 | }
 | 
|---|
| 547 | 
 | 
|---|
| 548 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 549 | ManyBodyPotential_Tersoff::function_derivative_h(
 | 
|---|
| 550 |     const argument_t &r_ij
 | 
|---|
| 551 |   ) const
 | 
|---|
| 552 | {
 | 
|---|
| 553 |   double result = 0.;
 | 
|---|
| 554 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 555 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 556 |       iter != triples.end(); ++iter) {
 | 
|---|
| 557 |     ASSERT( iter->size() == 2,
 | 
|---|
| 558 |         "ManyBodyPotential_Tersoff::function_derivative_h() - the triples result must contain exactly two distances.");
 | 
|---|
| 559 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 560 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
| 561 |     const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
 | 
|---|
| 562 |     const double cutoff = function_cutoff(r_ik.distance);
 | 
|---|
| 563 |     result += (cutoff == 0.) ?
 | 
|---|
| 564 |         0. : cutoff * omega  * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
 | 
|---|
| 565 |           ( Helpers::pow(params[c],2)*tempangle )
 | 
|---|
| 566 |             / Helpers::pow(Helpers::pow(params[d],2) + Helpers::pow(tempangle,2),2)
 | 
|---|
| 567 |         );
 | 
|---|
| 568 |   }
 | 
|---|
| 569 |   return result;
 | 
|---|
| 570 | }
 | 
|---|
| 571 | 
 | 
|---|
| 572 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 573 | ManyBodyPotential_Tersoff::function_cutoff(
 | 
|---|
| 574 |     const double &distance
 | 
|---|
| 575 |   ) const
 | 
|---|
| 576 | {
 | 
|---|
| 577 | //  Info info(__func__);
 | 
|---|
| 578 |   double result = 0.;
 | 
|---|
| 579 |   if (distance < R)
 | 
|---|
| 580 |     result = 1.;
 | 
|---|
| 581 |   else if (distance > S)
 | 
|---|
| 582 |     result = 0.;
 | 
|---|
| 583 |   else {
 | 
|---|
| 584 |     result = (0.5 + 0.5 * cos( M_PI * (distance - R)/(S-R)));
 | 
|---|
| 585 |   }
 | 
|---|
| 586 | //  LOG(2, "DEBUG: function_cutoff(" << distance << ") = " << result);
 | 
|---|
| 587 |   return result;
 | 
|---|
| 588 | }
 | 
|---|
| 589 | 
 | 
|---|
| 590 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 591 | ManyBodyPotential_Tersoff::function_prefactor(
 | 
|---|
| 592 |     const double &alpha,
 | 
|---|
| 593 |     const double &eta
 | 
|---|
| 594 |   ) const
 | 
|---|
| 595 | {
 | 
|---|
| 596 | //  Info info(__func__);
 | 
|---|
| 597 |   const double result = chi * pow(
 | 
|---|
| 598 |       (1. + pow(alpha * eta, params[n])),
 | 
|---|
| 599 |       -1./(2.*params[n]));
 | 
|---|
| 600 | //  LOG(2, "DEBUG: function_prefactor(" << alpha << "," << eta << ") = " << result);
 | 
|---|
| 601 |   return result;
 | 
|---|
| 602 | }
 | 
|---|
| 603 | 
 | 
|---|
| 604 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 605 | ManyBodyPotential_Tersoff::function_smoother(
 | 
|---|
| 606 |     const double &prefactor,
 | 
|---|
| 607 |     const double &lambda,
 | 
|---|
| 608 |     const double &distance
 | 
|---|
| 609 |     ) const
 | 
|---|
| 610 | {
 | 
|---|
| 611 | //  Info info(__func__);
 | 
|---|
| 612 |   const double result = prefactor * exp(-lambda * distance);
 | 
|---|
| 613 | //  LOG(2, "DEBUG: function_smoother(" << prefactor << "," << lambda << "," << distance << ") = " << result);
 | 
|---|
| 614 |   return result;
 | 
|---|
| 615 | }
 | 
|---|
| 616 | 
 | 
|---|
| 617 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 618 | ManyBodyPotential_Tersoff::function_eta(
 | 
|---|
| 619 |     const argument_t &r_ij
 | 
|---|
| 620 |   ) const
 | 
|---|
| 621 | {
 | 
|---|
| 622 | //  Info info(__func__);
 | 
|---|
| 623 |   result_t result = 0.;
 | 
|---|
| 624 | 
 | 
|---|
| 625 |   // get all triples within the cutoff
 | 
|---|
| 626 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 627 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 628 |       iter != triples.end(); ++iter) {
 | 
|---|
| 629 |     ASSERT( iter->size() == 2,
 | 
|---|
| 630 |         "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain of exactly two distances.");
 | 
|---|
| 631 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 632 |     result += function_cutoff(r_ik.distance)
 | 
|---|
| 633 |         * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3));
 | 
|---|
| 634 |   }
 | 
|---|
| 635 | 
 | 
|---|
| 636 | //  LOG(2, "DEBUG: function_eta(" << r_ij.distance << ") = " << result);
 | 
|---|
| 637 |   return result;
 | 
|---|
| 638 | }
 | 
|---|
| 639 | 
 | 
|---|
| 640 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 641 | ManyBodyPotential_Tersoff::function_zeta(
 | 
|---|
| 642 |     const argument_t &r_ij
 | 
|---|
| 643 |   ) const
 | 
|---|
| 644 | {
 | 
|---|
| 645 | //  Info info(__func__);
 | 
|---|
| 646 |   result_t result = 0.;
 | 
|---|
| 647 | 
 | 
|---|
| 648 |   // get all triples within the cutoff
 | 
|---|
| 649 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| 650 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 651 |       iter != triples.end(); ++iter) {
 | 
|---|
| 652 |     ASSERT( iter->size() == 2,
 | 
|---|
| 653 |         "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain exactly two distances.");
 | 
|---|
| 654 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 655 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
| 656 |     result +=
 | 
|---|
| 657 |         function_cutoff(r_ik.distance)
 | 
|---|
| 658 |         * omega
 | 
|---|
| 659 |         * function_angle(r_ij.distance, r_ik.distance, r_jk.distance)
 | 
|---|
| 660 |         * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3));
 | 
|---|
| 661 |   }
 | 
|---|
| 662 | 
 | 
|---|
| 663 | //  LOG(2, "DEBUG: function_zeta(" << r_ij.distance << ") = " << result);
 | 
|---|
| 664 |   return result;
 | 
|---|
| 665 | }
 | 
|---|
| 666 | 
 | 
|---|
| 667 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 668 | ManyBodyPotential_Tersoff::function_theta(
 | 
|---|
| 669 |     const double &r_ij,
 | 
|---|
| 670 |     const double &r_ik,
 | 
|---|
| 671 |     const double &r_jk
 | 
|---|
| 672 |   ) const
 | 
|---|
| 673 | {
 | 
|---|
| 674 |   const double angle = Helpers::pow(r_ij,2) + Helpers::pow(r_ik,2) - Helpers::pow(r_jk,2);
 | 
|---|
| 675 |   const double divisor = 2.* r_ij * r_ik;
 | 
|---|
| 676 |   if (divisor != 0.) {
 | 
|---|
| 677 |     LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
 | 
|---|
| 678 |     return angle/divisor;
 | 
|---|
| 679 |   } else
 | 
|---|
| 680 |     return 0.;
 | 
|---|
| 681 | }
 | 
|---|
| 682 | 
 | 
|---|
| 683 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| 684 | ManyBodyPotential_Tersoff::function_angle(
 | 
|---|
| 685 |     const double &r_ij,
 | 
|---|
| 686 |     const double &r_ik,
 | 
|---|
| 687 |     const double &r_jk
 | 
|---|
| 688 |   ) const
 | 
|---|
| 689 | {
 | 
|---|
| 690 | //  Info info(__func__);
 | 
|---|
| 691 |   const double result =
 | 
|---|
| 692 |       1.
 | 
|---|
| 693 |       + (Helpers::pow(params[c]/params[d], 2))
 | 
|---|
| 694 |       - Helpers::pow(params[c], 2)/(Helpers::pow(params[d], 2) +
 | 
|---|
| 695 |           Helpers::pow(params[h] - function_theta(r_ij, r_ik, r_jk),2));
 | 
|---|
| 696 | 
 | 
|---|
| 697 | //  LOG(2, "DEBUG: function_angle(" << r_ij << "," << r_ik << "," << r_jk << ") = " << result);
 | 
|---|
| 698 |   return result;
 | 
|---|
| 699 | }
 | 
|---|
| 700 | 
 | 
|---|
| 701 | FunctionModel::filter_t ManyBodyPotential_Tersoff::getSpecificFilter() const
 | 
|---|
| 702 | {
 | 
|---|
| 703 |   FunctionModel::filter_t returnfunction =
 | 
|---|
| 704 |       boost::bind(&Extractors::filterArgumentsByParticleTypes,
 | 
|---|
| 705 |           _1,
 | 
|---|
| 706 |           getParticleTypes());
 | 
|---|
| 707 |   return returnfunction;
 | 
|---|
| 708 | }
 | 
|---|
| 709 | 
 | 
|---|
| 710 | void
 | 
|---|
| 711 | ManyBodyPotential_Tersoff::setParametersToRandomInitialValues(
 | 
|---|
| 712 |     const TrainingData &data)
 | 
|---|
| 713 | {
 | 
|---|
| 714 |   RandomNumberGenerator &random = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();
 | 
|---|
| 715 |   const double rng_min = random.min();
 | 
|---|
| 716 |   const double rng_max = random.max();
 | 
|---|
| 717 | //  params[ManyBodyPotential_Tersoff::R] = 1./AtomicLengthToAngstroem;
 | 
|---|
| 718 | //  params[ManyBodyPotential_Tersoff::S] = 2./AtomicLengthToAngstroem;
 | 
|---|
| 719 |   params[ManyBodyPotential_Tersoff::A] = 1e+4*(random()/(rng_max-rng_min));//1.393600e+03;
 | 
|---|
| 720 |   params[ManyBodyPotential_Tersoff::B] = 1e+4*(random()/(rng_max-rng_min));//3.467000e+02;
 | 
|---|
| 721 |   params[ManyBodyPotential_Tersoff::lambda] = 1e+1*(random()/(rng_max-rng_min));//3.487900e+00;
 | 
|---|
| 722 |   params[ManyBodyPotential_Tersoff::mu] = 1e+1*(random()/(rng_max-rng_min));//2.211900e+00;
 | 
|---|
| 723 |   //  params[ManyBodyPotential_Tersoff::lambda3] = 0.;
 | 
|---|
| 724 |   //  params[ManyBodyPotential_Tersoff::alpha] = 0.;
 | 
|---|
| 725 |   params[ManyBodyPotential_Tersoff::beta] = 1e-1*(random()/(rng_max-rng_min));//1.572400e-07;
 | 
|---|
| 726 |   //  params[ManyBodyPotential_Tersoff::chi] = 1.;
 | 
|---|
| 727 |   //  params[ManyBodyPotential_Tersoff::omega] = 1.;
 | 
|---|
| 728 |   params[ManyBodyPotential_Tersoff::n] = 1e+1*(random()/(rng_max-rng_min));//7.275100e-01;
 | 
|---|
| 729 |   params[ManyBodyPotential_Tersoff::c] = 1e+1*(random()/(rng_max-rng_min));//3.804900e+04;
 | 
|---|
| 730 |   params[ManyBodyPotential_Tersoff::d] = 1e+1*(random()/(rng_max-rng_min));//4.384000e+00;
 | 
|---|
| 731 |   params[ManyBodyPotential_Tersoff::h] = 1e+1*(random()/(rng_max-rng_min));//-5.705800e-01;
 | 
|---|
| 732 | }
 | 
|---|
| 733 | 
 | 
|---|