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