[4ffbb7] | 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 | * SaturationPotential.cpp
|
---|
| 26 | *
|
---|
| 27 | * Created on: Oct 11, 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 "SaturationPotential.hpp"
|
---|
| 40 |
|
---|
[93e908] | 41 | #include <boost/assign.hpp>
|
---|
[ed2551] | 42 | #include <boost/assign/list_of.hpp> // for 'map_list_of()'
|
---|
| 43 | #include <iostream>
|
---|
| 44 | #include <string>
|
---|
| 45 |
|
---|
[4ffbb7] | 46 | #include "CodePatterns/Assert.hpp"
|
---|
[94f567] | 47 | #include "CodePatterns/Log.hpp"
|
---|
[4ffbb7] | 48 |
|
---|
[7b019a] | 49 | #include "FunctionApproximation/Extractors.hpp"
|
---|
[d52819] | 50 | #include "FunctionApproximation/TrainingData.hpp"
|
---|
[4ffbb7] | 51 | #include "Potentials/helpers.hpp"
|
---|
[b760bc3] | 52 | #include "Potentials/ParticleTypeCheckers.hpp"
|
---|
[4ffbb7] | 53 |
|
---|
[7b019a] | 54 | class Fragment;
|
---|
| 55 |
|
---|
[93e908] | 56 | using namespace boost::assign;
|
---|
| 57 |
|
---|
[ed2551] | 58 | // static definitions
|
---|
| 59 | const SaturationPotential::ParameterNames_t
|
---|
| 60 | SaturationPotential::ParameterNames =
|
---|
| 61 | boost::assign::list_of<std::string>
|
---|
| 62 | ("all_energy_offset")
|
---|
| 63 | ("")
|
---|
| 64 | ("")
|
---|
| 65 | ("")
|
---|
| 66 | ("")
|
---|
| 67 | ("")
|
---|
| 68 | ;
|
---|
| 69 | const std::string SaturationPotential::potential_token("saturation");
|
---|
| 70 |
|
---|
[4ffbb7] | 71 | SaturationPotential::SaturationPotential(
|
---|
[775dd1a] | 72 | const ParticleTypes_t &_ParticleTypes) :
|
---|
[ed2551] | 73 | SerializablePotential(_ParticleTypes),
|
---|
| 74 | morse(_ParticleTypes),
|
---|
[dbf8c8] | 75 | angle(symmetrizeTypes(_ParticleTypes)),
|
---|
[775dd1a] | 76 | energy_offset(0.)
|
---|
[7b019a] | 77 | {
|
---|
| 78 | // have some decent defaults for parameter_derivative checking
|
---|
| 79 | // Morse and Angle have their own defaults, offset is set
|
---|
| 80 | ASSERT( _ParticleTypes.size() == (size_t)2,
|
---|
| 81 | "SaturationPotential::SaturationPotential() - exactly two types must be given.");
|
---|
| 82 | ASSERT( _ParticleTypes[1] == 1,
|
---|
| 83 | "SaturationPotential::SaturationPotential() - second type must be hydrogen.");
|
---|
| 84 | }
|
---|
[4ffbb7] | 85 |
|
---|
| 86 | SaturationPotential::SaturationPotential(
|
---|
[ed2551] | 87 | const ParticleTypes_t &_ParticleTypes,
|
---|
[b3eabc] | 88 | const double _all_energy_offset,
|
---|
[4ffbb7] | 89 | const double _morse_spring_constant,
|
---|
| 90 | const double _morse_equilibrium_distance,
|
---|
| 91 | const double _morse_dissociation_energy,
|
---|
| 92 | const double _angle_spring_constant,
|
---|
[775dd1a] | 93 | const double _angle_equilibrium_distance) :
|
---|
[ed2551] | 94 | SerializablePotential(_ParticleTypes),
|
---|
| 95 | morse(_ParticleTypes),
|
---|
[93e908] | 96 | angle(symmetrizeTypes(_ParticleTypes)),
|
---|
[775dd1a] | 97 | energy_offset(_all_energy_offset)
|
---|
[4ffbb7] | 98 | {
|
---|
[7b019a] | 99 | ASSERT( _ParticleTypes.size() == (size_t)2,
|
---|
| 100 | "SaturationPotential::SaturationPotential() - exactly two types must be given.");
|
---|
| 101 | ASSERT( _ParticleTypes[1] == 1,
|
---|
| 102 | "SaturationPotential::SaturationPotential() - second type must be hydrogen.");
|
---|
[4ffbb7] | 103 | parameters_t morse_params(morse.getParameterDimension());
|
---|
| 104 | morse_params[PairPotential_Morse::spring_constant] = _morse_spring_constant;
|
---|
| 105 | morse_params[PairPotential_Morse::equilibrium_distance] = _morse_equilibrium_distance;
|
---|
| 106 | morse_params[PairPotential_Morse::dissociation_energy] = _morse_dissociation_energy;
|
---|
| 107 | morse_params[PairPotential_Morse::energy_offset] = 0.;
|
---|
| 108 | morse.setParameters(morse_params);
|
---|
| 109 | parameters_t angle_params(angle.getParameterDimension());
|
---|
| 110 | angle_params[PairPotential_Angle::spring_constant] = _angle_spring_constant;
|
---|
| 111 | angle_params[PairPotential_Angle::equilibrium_distance] = _angle_equilibrium_distance;
|
---|
| 112 | angle_params[PairPotential_Angle::energy_offset] = 0.;
|
---|
| 113 | angle.setParameters(angle_params);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | void SaturationPotential::setParameters(const parameters_t &_params)
|
---|
| 117 | {
|
---|
| 118 | const size_t paramsDim = _params.size();
|
---|
| 119 | ASSERT( paramsDim <= getParameterDimension(),
|
---|
| 120 | "SaturationPotential::setParameters() - we need not more than "
|
---|
| 121 | +toString(getParameterDimension())+" parameters.");
|
---|
| 122 | // LOG(1, "INFO: Setting new SaturationPotential params: " << _params);
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | // offsets
|
---|
| 126 | if (paramsDim > all_energy_offset)
|
---|
| 127 | energy_offset = _params[all_energy_offset];
|
---|
| 128 |
|
---|
| 129 | // Morse
|
---|
| 130 | {
|
---|
| 131 | parameters_t morse_params(morse.getParameters());
|
---|
| 132 | if (paramsDim > morse_spring_constant)
|
---|
| 133 | morse_params[PairPotential_Morse::spring_constant] = _params[morse_spring_constant];
|
---|
| 134 | if (paramsDim > morse_equilibrium_distance)
|
---|
| 135 | morse_params[PairPotential_Morse::equilibrium_distance] = _params[morse_equilibrium_distance];
|
---|
| 136 | if (paramsDim > morse_dissociation_energy)
|
---|
| 137 | morse_params[PairPotential_Morse::dissociation_energy] = _params[morse_dissociation_energy];
|
---|
| 138 | morse_params[PairPotential_Morse::energy_offset] = 0.;
|
---|
| 139 | morse.setParameters(morse_params);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | // Angle
|
---|
| 143 | {
|
---|
| 144 | parameters_t angle_params(angle.getParameters());
|
---|
| 145 | if (paramsDim > angle_spring_constant)
|
---|
| 146 | angle_params[PairPotential_Angle::spring_constant] = _params[angle_spring_constant];
|
---|
| 147 | if (paramsDim > angle_equilibrium_distance)
|
---|
| 148 | angle_params[PairPotential_Angle::equilibrium_distance] = _params[angle_equilibrium_distance];
|
---|
| 149 | angle_params[PairPotential_Angle::energy_offset] = 0.;
|
---|
| 150 | angle.setParameters(angle_params);
|
---|
| 151 | }
|
---|
| 152 | #ifndef NDEBUG
|
---|
| 153 | parameters_t check_params(getParameters());
|
---|
| 154 | check_params.resize(paramsDim); // truncate to same size
|
---|
| 155 | ASSERT( check_params == _params,
|
---|
| 156 | "SaturationPotential::setParameters() - failed, mismatch in to be set "
|
---|
| 157 | +toString(_params)+" and set "+toString(check_params)+" params.");
|
---|
| 158 | #endif
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | SaturationPotential::parameters_t SaturationPotential::getParameters() const
|
---|
| 162 | {
|
---|
| 163 | parameters_t params(getParameterDimension());
|
---|
| 164 | const parameters_t morse_params = morse.getParameters();
|
---|
| 165 | const parameters_t angle_params = angle.getParameters();
|
---|
| 166 |
|
---|
| 167 | params[all_energy_offset] = energy_offset;
|
---|
| 168 |
|
---|
| 169 | params[morse_spring_constant] = morse_params[PairPotential_Morse::spring_constant];
|
---|
| 170 | params[morse_equilibrium_distance] = morse_params[PairPotential_Morse::equilibrium_distance];
|
---|
| 171 | params[morse_dissociation_energy] = morse_params[PairPotential_Morse::dissociation_energy];
|
---|
| 172 |
|
---|
| 173 | params[angle_spring_constant] = angle_params[PairPotential_Angle::spring_constant];
|
---|
| 174 | params[angle_equilibrium_distance] = angle_params[PairPotential_Angle::equilibrium_distance];
|
---|
| 175 | return params;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[3d2559] | 178 | void SaturationPotential::stream_to(std::ostream &ost) const
|
---|
| 179 | {
|
---|
| 180 | morse.stream_to(ost);
|
---|
| 181 | ost << std::endl;
|
---|
| 182 | angle.stream_to(ost);
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | void SaturationPotential::stream_from(std::istream &ist)
|
---|
| 186 | {
|
---|
| 187 | morse.stream_from(ist);
|
---|
| 188 | ist >> ws;
|
---|
| 189 | angle.stream_from(ist);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[0dad5f] | 192 | std::vector<FunctionModel::arguments_t>
|
---|
| 193 | triplefunction(
|
---|
| 194 | const argument_t &argument,
|
---|
| 195 | const FunctionModel::arguments_t& args)
|
---|
| 196 | {
|
---|
| 197 | const size_t firstindex = argument.indices.first;
|
---|
| 198 | const size_t secondindex = argument.indices.second;
|
---|
| 199 | // LOG(2, "DEBUG: first index is " << firstindex << ", second index is " << secondindex << ".");
|
---|
| 200 |
|
---|
| 201 | // place all arguments that share either index into a lookup map
|
---|
| 202 | typedef std::map< size_t, FunctionModel::arguments_t::const_iterator > IndexLookup_t;
|
---|
| 203 | IndexLookup_t LookuptoFirst;
|
---|
| 204 | IndexLookup_t LookuptoSecond;
|
---|
| 205 | for (FunctionModel::arguments_t::const_iterator iter = args.begin();
|
---|
| 206 | iter != args.end();
|
---|
| 207 | ++iter) {
|
---|
| 208 | if (((*iter).indices.first == argument.indices.first)
|
---|
| 209 | && ((*iter).indices.second == argument.indices.second))
|
---|
| 210 | continue;
|
---|
| 211 | if (firstindex == (*iter).indices.first) {
|
---|
| 212 | LookuptoFirst.insert( std::make_pair( (*iter).indices.second, iter) );
|
---|
| 213 | }
|
---|
| 214 | else if (firstindex == (*iter).indices.second) {
|
---|
| 215 | LookuptoFirst.insert( std::make_pair( (*iter).indices.first, iter) );
|
---|
| 216 | }
|
---|
| 217 | if (secondindex == (*iter).indices.first) {
|
---|
| 218 | LookuptoSecond.insert( std::make_pair( (*iter).indices.second, iter) );
|
---|
| 219 | }
|
---|
| 220 | else if (secondindex == (*iter).indices.second) {
|
---|
| 221 | LookuptoSecond.insert( std::make_pair((*iter).indices.first, iter) );
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
| 224 | // {
|
---|
| 225 | // std::stringstream lookupstream;
|
---|
| 226 | // for (IndexLookup_t::const_iterator iter = LookuptoFirst.begin();
|
---|
| 227 | // iter != LookuptoFirst.end();
|
---|
| 228 | // ++iter) {
|
---|
| 229 | // lookupstream << "(" << iter->first << "," << *(iter->second) << ") ";
|
---|
| 230 | // }
|
---|
| 231 | // LOG(2, "DEBUG: LookupToFirst is " << lookupstream.str() << ".");
|
---|
| 232 | // }
|
---|
| 233 | // {
|
---|
| 234 | // std::stringstream lookupstream;
|
---|
| 235 | // for (IndexLookup_t::const_iterator iter = LookuptoSecond.begin();
|
---|
| 236 | // iter != LookuptoSecond.end();
|
---|
| 237 | // ++iter) {
|
---|
| 238 | // lookupstream << "(" << iter->first << "," << *(iter->second) << ") ";
|
---|
| 239 | // }
|
---|
| 240 | // LOG(2, "DEBUG: LookuptoSecond is " << lookupstream.str() << ".");
|
---|
| 241 | // }
|
---|
| 242 |
|
---|
| 243 | // now go through the first lookup as the second argument and pick the
|
---|
| 244 | // corresponding third argument by the matching index
|
---|
| 245 | std::vector<FunctionModel::arguments_t> results;
|
---|
| 246 | for (IndexLookup_t::const_iterator iter = LookuptoFirst.begin();
|
---|
| 247 | iter != LookuptoFirst.end();
|
---|
| 248 | ++iter) {
|
---|
| 249 | IndexLookup_t::const_iterator otheriter = LookuptoSecond.find(iter->first);
|
---|
| 250 | ASSERT( otheriter != LookuptoSecond.end(),
|
---|
| 251 | "triplefunction() - cannot find index "+toString(iter->first)
|
---|
| 252 | +" in LookupToSecond");
|
---|
| 253 | FunctionModel::arguments_t result(1, argument);
|
---|
| 254 | result.reserve(3);
|
---|
| 255 | result.push_back(*(iter->second));
|
---|
| 256 | result.push_back(*(otheriter->second));
|
---|
| 257 | results.push_back(result);
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | return results;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[4ffbb7] | 263 | SaturationPotential::results_t
|
---|
| 264 | SaturationPotential::operator()(
|
---|
| 265 | const arguments_t &arguments
|
---|
| 266 | ) const
|
---|
| 267 | {
|
---|
| 268 | double result = 0.;
|
---|
[b760bc3] | 269 | const ParticleTypes_t &morse_types = morse.getParticleTypes();
|
---|
[4ffbb7] | 270 | for(arguments_t::const_iterator argiter = arguments.begin();
|
---|
| 271 | argiter != arguments.end();
|
---|
| 272 | ++argiter) {
|
---|
| 273 | const argument_t &r_ij = *argiter;
|
---|
[b760bc3] | 274 | if (((r_ij.types.first == morse_types[0]) && (r_ij.types.second == morse_types[1]))
|
---|
| 275 | || ((r_ij.types.first == morse_types[1]) && (r_ij.types.second == morse_types[0]))) {
|
---|
[2ba2ed] | 276 | arguments_t args(1, r_ij);
|
---|
| 277 |
|
---|
| 278 | // Morse contribution
|
---|
[b760bc3] | 279 | const double tmp = morse(args)[0];
|
---|
[a82127] | 280 | // LOG(3, "DEBUG: Morse yields " << tmp << " for << " << r_ij << ".");
|
---|
[b760bc3] | 281 | result += tmp;
|
---|
[94f567] | 282 | if (result != result)
|
---|
| 283 | ELOG(1, "result is NAN.");
|
---|
[0dad5f] | 284 |
|
---|
| 285 | // Angle contribution
|
---|
| 286 | {
|
---|
| 287 | typedef std::vector<FunctionModel::arguments_t> tripleargs_t;
|
---|
| 288 | tripleargs_t tripleargs =
|
---|
| 289 | triplefunction(r_ij, arguments);
|
---|
| 290 | for (tripleargs_t::const_iterator iter = tripleargs.begin();
|
---|
| 291 | iter != tripleargs.end();
|
---|
| 292 | ++iter) {
|
---|
| 293 | FunctionModel::arguments_t tempargs =
|
---|
| 294 | Extractors::reorderArgumentsByParticleTypes(*iter, angle.getParticleTypes());
|
---|
[a82127] | 295 | // We get both angles, e.g. 0-4-1 and 1-4-0, hence multiply with 0.5
|
---|
| 296 | const double tmp = .5*angle(tempargs)[0]; // as we have all distances we get both jk and kj
|
---|
| 297 | // LOG(3, "DEBUG: angle yields " << tmp << " for << " << tempargs << ".");
|
---|
[0dad5f] | 298 | result += tmp;
|
---|
| 299 | if (result != result)
|
---|
| 300 | ELOG(1, "result is NAN.");
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
[4ffbb7] | 303 | }
|
---|
| 304 | }
|
---|
| 305 | return std::vector<result_t>(1, energy_offset + result);
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | SaturationPotential::derivative_components_t
|
---|
| 309 | SaturationPotential::derivative(
|
---|
| 310 | const arguments_t &arguments
|
---|
| 311 | ) const
|
---|
| 312 | {
|
---|
| 313 | ASSERT( 0,
|
---|
| 314 | "SaturationPotential::operator() - not implemented.");
|
---|
| 315 | derivative_components_t result;
|
---|
| 316 | return result;
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | SaturationPotential::results_t
|
---|
| 320 | SaturationPotential::parameter_derivative(
|
---|
| 321 | const arguments_t &arguments,
|
---|
| 322 | const size_t index
|
---|
| 323 | ) const
|
---|
| 324 | {
|
---|
| 325 | double result = 0.;
|
---|
[0dad5f] | 326 | if (index == all_energy_offset) {
|
---|
| 327 | result = 1.;
|
---|
| 328 | } else {
|
---|
| 329 | const ParticleTypes_t &morse_types = morse.getParticleTypes();
|
---|
| 330 | for(arguments_t::const_iterator argiter = arguments.begin();
|
---|
| 331 | argiter != arguments.end();
|
---|
| 332 | ++argiter) {
|
---|
| 333 | const argument_t &r_ij = *argiter;
|
---|
| 334 | if (((r_ij.types.first == morse_types[0]) && (r_ij.types.second == morse_types[1]))
|
---|
| 335 | || ((r_ij.types.first == morse_types[1]) && (r_ij.types.second == morse_types[0]))) {
|
---|
| 336 | arguments_t args(1, r_ij);
|
---|
| 337 |
|
---|
| 338 | switch (index) {
|
---|
| 339 | case morse_spring_constant:
|
---|
| 340 | result += morse.parameter_derivative(args, PairPotential_Morse::spring_constant)[0];
|
---|
| 341 | break;
|
---|
| 342 | case morse_equilibrium_distance:
|
---|
| 343 | result += morse.parameter_derivative(args, PairPotential_Morse::equilibrium_distance)[0];
|
---|
| 344 | break;
|
---|
| 345 | case morse_dissociation_energy:
|
---|
| 346 | result += morse.parameter_derivative(args, PairPotential_Morse::dissociation_energy)[0];
|
---|
| 347 | break;
|
---|
| 348 | case angle_spring_constant:
|
---|
| 349 | case angle_equilibrium_distance:
|
---|
| 350 | {
|
---|
| 351 | typedef std::vector<FunctionModel::arguments_t> tripleargs_t;
|
---|
| 352 | tripleargs_t tripleargs =
|
---|
| 353 | triplefunction(r_ij, arguments);
|
---|
| 354 | for (tripleargs_t::const_iterator iter = tripleargs.begin();
|
---|
| 355 | iter != tripleargs.end();
|
---|
| 356 | ++iter) {
|
---|
| 357 | FunctionModel::arguments_t tempargs =
|
---|
| 358 | Extractors::reorderArgumentsByParticleTypes(*iter, angle.getParticleTypes());
|
---|
[a82127] | 359 | // We get both angles, e.g. 0-4-1 and 1-4-0, hence multiply with 0.5
|
---|
[0dad5f] | 360 | if (index == angle_spring_constant)
|
---|
[a82127] | 361 | result += .5*angle.parameter_derivative(tempargs, PairPotential_Angle::spring_constant)[0];
|
---|
[0dad5f] | 362 | else if (index == angle_equilibrium_distance)
|
---|
[a82127] | 363 | result += .5*angle.parameter_derivative(tempargs, PairPotential_Angle::equilibrium_distance)[0];
|
---|
[0dad5f] | 364 | // LOG(2, "DEBUG: angle yields " << tmp << " for << " << arguments << ".");
|
---|
| 365 | // result += tmp;
|
---|
| 366 | if (result != result)
|
---|
| 367 | ELOG(1, "result is NAN.");
|
---|
| 368 | }
|
---|
[4ffbb7] | 369 | }
|
---|
[0dad5f] | 370 | break;
|
---|
| 371 | default:
|
---|
| 372 | ASSERT( 0, "SaturationPotential::parameter_derivative() - impossible to get here.");
|
---|
| 373 | break;
|
---|
[4ffbb7] | 374 | }
|
---|
| 375 | }
|
---|
[b3eabc] | 376 | }
|
---|
[4ffbb7] | 377 | }
|
---|
| 378 | return SaturationPotential::results_t(1, result);
|
---|
| 379 | }
|
---|
[ed2551] | 380 |
|
---|
[93e908] | 381 | const SaturationPotential::ParticleTypes_t
|
---|
| 382 | SaturationPotential::symmetrizeTypes(const ParticleTypes_t &_ParticleTypes)
|
---|
| 383 | {
|
---|
| 384 | ASSERT( _ParticleTypes.size() == (size_t)2,
|
---|
| 385 | "SaturationPotential::symmetrizeTypes() - require initial _ParticleTypes with two elements.");
|
---|
| 386 | // // insert before couple
|
---|
| 387 | // ParticleTypes_t types(1, _ParticleTypes[1]);
|
---|
| 388 | // types.insert(types.end(), _ParticleTypes.begin(), _ParticleTypes.end());
|
---|
| 389 | // insert after the couple
|
---|
| 390 | ParticleTypes_t types(_ParticleTypes);
|
---|
| 391 | types.push_back( _ParticleTypes.back() );
|
---|
| 392 | ASSERT( types.size() == (size_t)3,
|
---|
| 393 | "SaturationPotential::symmetrizeTypes() - failed to generate three types for angle.");
|
---|
| 394 | return types;
|
---|
| 395 | }
|
---|
| 396 |
|
---|
[7b019a] | 397 | FunctionModel::extractor_t
|
---|
| 398 | SaturationPotential::getFragmentSpecificExtractor(
|
---|
| 399 | const charges_t &charges) const
|
---|
| 400 | {
|
---|
| 401 | ASSERT(charges.size() == (size_t)2,
|
---|
| 402 | "SaturationPotential::getFragmentSpecificExtractor() - requires 2 charges.");
|
---|
| 403 | FunctionModel::extractor_t returnfunction;
|
---|
| 404 | if (charges[0] == charges[1]) {
|
---|
| 405 | // In case both types are equal there is only a single pair of possible
|
---|
| 406 | // type combinations.
|
---|
| 407 | returnfunction =
|
---|
| 408 | boost::bind(&Extractors::gatherAllDistancesFromFragment,
|
---|
| 409 | boost::bind(&Fragment::getPositions, _1),
|
---|
| 410 | boost::bind(&Fragment::getCharges, _1),
|
---|
| 411 | boost::cref(charges),
|
---|
| 412 | _2);
|
---|
| 413 | } else {
|
---|
| 414 | // we have to chain here a rather complex "tree" of functions
|
---|
| 415 | // as we only have a couple of ParticleTypes but need to get
|
---|
| 416 | // all possible three pairs of the set of the two types.
|
---|
| 417 | // Finally, we also need to arrange them in correct order
|
---|
| 418 | // (for PairPotentiale_Angle).
|
---|
[0dad5f] | 419 | //charges_t firstpair(2, boost::cref(charges[0]));
|
---|
| 420 | // only that saturation potential never has its middle element twice!
|
---|
| 421 | // hence, we skip the firstpair but keep the code for later generalization
|
---|
[7b019a] | 422 | charges_t secondpair(2, boost::cref(charges[1]));
|
---|
| 423 | const charges_t &thirdpair = charges;
|
---|
| 424 | returnfunction =
|
---|
[0dad5f] | 425 | // boost::bind(&Extractors::reorderArgumentsByParticleTypes,
|
---|
[7b019a] | 426 | boost::bind(&Extractors::combineArguments,
|
---|
[0dad5f] | 427 | // boost::bind(&Extractors::combineArguments,
|
---|
| 428 | // boost::bind(&Extractors::gatherAllDistancesFromFragment,
|
---|
| 429 | // boost::bind(&Fragment::getPositions, _1),
|
---|
| 430 | // boost::bind(&Fragment::getCharges, _1),
|
---|
| 431 | // firstpair, // no crefs here as are temporaries!
|
---|
| 432 | // _2),
|
---|
[7b019a] | 433 | boost::bind(&Extractors::gatherAllDistancesFromFragment,
|
---|
| 434 | boost::bind(&Fragment::getPositions, _1),
|
---|
| 435 | boost::bind(&Fragment::getCharges, _1),
|
---|
| 436 | secondpair, // no crefs here as are temporaries!
|
---|
[0dad5f] | 437 | _2),
|
---|
| 438 | // ),
|
---|
[7b019a] | 439 | boost::bind(&Extractors::gatherAllDistancesFromFragment,
|
---|
| 440 | boost::bind(&Fragment::getPositions, _1),
|
---|
| 441 | boost::bind(&Fragment::getCharges, _1),
|
---|
| 442 | boost::cref(thirdpair), // only the last one is no temporary
|
---|
| 443 | _2)
|
---|
[0dad5f] | 444 | );
|
---|
| 445 | // boost::cref(angle.getParticleTypes())
|
---|
| 446 | // );
|
---|
[7b019a] | 447 | }
|
---|
| 448 | return returnfunction;
|
---|
| 449 | }
|
---|
[d52819] | 450 |
|
---|
| 451 | void
|
---|
| 452 | SaturationPotential::setParametersToRandomInitialValues(
|
---|
| 453 | const TrainingData &data)
|
---|
| 454 | {
|
---|
| 455 | energy_offset = data.getTrainingOutputAverage()[0];
|
---|
| 456 | morse.setParametersToRandomInitialValues(data);
|
---|
| 457 | angle.setParametersToRandomInitialValues(data);
|
---|
| 458 | }
|
---|