| [f06d52] | 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 | * LevMartester.cpp | 
|---|
|  | 26 | * | 
|---|
|  | 27 | *  Created on: Sep 27, 2012 | 
|---|
|  | 28 | *      Author: heber | 
|---|
|  | 29 | */ | 
|---|
|  | 30 |  | 
|---|
|  | 31 |  | 
|---|
|  | 32 | // include config.h | 
|---|
|  | 33 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 34 | #include <config.h> | 
|---|
|  | 35 | #endif | 
|---|
|  | 36 |  | 
|---|
| [69b30a] | 37 | #include <boost/archive/text_iarchive.hpp> | 
|---|
|  | 38 |  | 
|---|
| [f06d52] | 39 | #include "CodePatterns/MemDebug.hpp" | 
|---|
|  | 40 |  | 
|---|
| [9340ee] | 41 | #include <boost/assign.hpp> | 
|---|
| [6efcae] | 42 | #include <boost/assign/list_of.hpp> | 
|---|
| [4ec18b] | 43 | #include <boost/bind.hpp> | 
|---|
| [f06d52] | 44 | #include <boost/filesystem.hpp> | 
|---|
| [4ec18b] | 45 | #include <boost/function.hpp> | 
|---|
| [f06d52] | 46 | #include <boost/program_options.hpp> | 
|---|
|  | 47 |  | 
|---|
| [17b3598] | 48 | #include <cstdlib> | 
|---|
|  | 49 | #include <ctime> | 
|---|
| [f06d52] | 50 | #include <fstream> | 
|---|
|  | 51 | #include <iostream> | 
|---|
|  | 52 | #include <iterator> | 
|---|
| [eb1efe] | 53 | #include <list> | 
|---|
| [f06d52] | 54 | #include <vector> | 
|---|
|  | 55 |  | 
|---|
|  | 56 | #include <levmar.h> | 
|---|
|  | 57 |  | 
|---|
|  | 58 | #include "CodePatterns/Assert.hpp" | 
|---|
|  | 59 | #include "CodePatterns/Log.hpp" | 
|---|
|  | 60 |  | 
|---|
|  | 61 | #include "LinearAlgebra/Vector.hpp" | 
|---|
|  | 62 |  | 
|---|
|  | 63 | #include "Fragmentation/Homology/HomologyContainer.hpp" | 
|---|
|  | 64 | #include "Fragmentation/SetValues/Fragment.hpp" | 
|---|
| [8aa597] | 65 | #include "FunctionApproximation/Extractors.hpp" | 
|---|
| [c62f96] | 66 | #include "FunctionApproximation/FunctionApproximation.hpp" | 
|---|
|  | 67 | #include "FunctionApproximation/FunctionModel.hpp" | 
|---|
| [68172a] | 68 | #include "FunctionApproximation/TrainingData.hpp" | 
|---|
| [04cc7e] | 69 | #include "FunctionApproximation/writeDistanceEnergyTable.hpp" | 
|---|
| [f48ad3] | 70 | #include "Helpers/defs.hpp" | 
|---|
| [155cc2] | 71 | #include "Potentials/Specifics/PairPotential_Morse.hpp" | 
|---|
| [9340ee] | 72 | #include "Potentials/Specifics/PairPotential_Angle.hpp" | 
|---|
| [40fff1] | 73 | #include "Potentials/Specifics/SaturationPotential.hpp" | 
|---|
| [d94e7e] | 74 | #include "types.hpp" | 
|---|
| [f06d52] | 75 |  | 
|---|
|  | 76 | namespace po = boost::program_options; | 
|---|
|  | 77 |  | 
|---|
| [9340ee] | 78 | using namespace boost::assign; | 
|---|
|  | 79 |  | 
|---|
| [e920d3d] | 80 | HomologyGraph getFirstGraphwithTimesSpecificElement( | 
|---|
|  | 81 | const HomologyContainer &homologies, | 
|---|
|  | 82 | const size_t _number, | 
|---|
|  | 83 | const size_t _times) | 
|---|
|  | 84 | { | 
|---|
|  | 85 | for (HomologyContainer::container_t::const_iterator iter = | 
|---|
|  | 86 | homologies.begin(); iter != homologies.end(); ++iter) { | 
|---|
|  | 87 | if (iter->first.hasTimesAtomicNumber(_number,_times)) | 
|---|
|  | 88 | return iter->first; | 
|---|
|  | 89 | } | 
|---|
|  | 90 | return HomologyGraph(); | 
|---|
|  | 91 | } | 
|---|
| [eb1efe] | 92 |  | 
|---|
|  | 93 | /** This function returns the elements of the sum over index "k" for an | 
|---|
|  | 94 | * argument containing indices "i" and "j" | 
|---|
|  | 95 | * @param inputs vector of all configuration (containing each a vector of all arguments) | 
|---|
|  | 96 | * @param arg argument containing indices "i" and "j" | 
|---|
|  | 97 | * @param cutoff cutoff criterion for sum over k | 
|---|
|  | 98 | * @return vector of argument pairs (a vector) of ik and jk for at least all k | 
|---|
|  | 99 | *        within distance of \a cutoff to i | 
|---|
|  | 100 | */ | 
|---|
|  | 101 | std::vector<FunctionModel::arguments_t> | 
|---|
|  | 102 | getTripleFromArgument(const FunctionApproximation::inputs_t &inputs, const argument_t &arg, const double cutoff) | 
|---|
|  | 103 | { | 
|---|
|  | 104 | typedef std::list<argument_t> arg_list_t; | 
|---|
|  | 105 | typedef std::map<size_t, arg_list_t > k_args_map_t; | 
|---|
|  | 106 | k_args_map_t tempresult; | 
|---|
|  | 107 | ASSERT( inputs.size() > arg.globalid, | 
|---|
|  | 108 | "getTripleFromArgument() - globalid "+toString(arg.globalid) | 
|---|
|  | 109 | +" is greater than all inputs "+toString(inputs.size())+"."); | 
|---|
|  | 110 | const FunctionModel::arguments_t &listofargs = inputs[arg.globalid]; | 
|---|
|  | 111 | for (FunctionModel::arguments_t::const_iterator argiter = listofargs.begin(); | 
|---|
|  | 112 | argiter != listofargs.end(); | 
|---|
|  | 113 | ++argiter) { | 
|---|
|  | 114 | // first index must be either i or j but second index not | 
|---|
|  | 115 | if (((argiter->indices.first == arg.indices.first) | 
|---|
|  | 116 | || (argiter->indices.first == arg.indices.second)) | 
|---|
|  | 117 | && ((argiter->indices.second != arg.indices.first) | 
|---|
|  | 118 | && (argiter->indices.second != arg.indices.second))) { | 
|---|
|  | 119 | // we need arguments ik and jk | 
|---|
|  | 120 | std::pair< k_args_map_t::iterator, bool> inserter = | 
|---|
|  | 121 | tempresult.insert( std::make_pair( argiter->indices.second, arg_list_t(1,*argiter))); | 
|---|
|  | 122 | if (!inserter.second) { | 
|---|
|  | 123 | // is present one ik or jk, if ik insert jk at back | 
|---|
|  | 124 | if (inserter.first->second.begin()->indices.first == arg.indices.first) | 
|---|
|  | 125 | inserter.first->second.push_back(*argiter); | 
|---|
|  | 126 | else // if jk, insert ik at front | 
|---|
|  | 127 | inserter.first->second.push_front(*argiter); | 
|---|
|  | 128 | } | 
|---|
|  | 129 | } | 
|---|
|  | 130 | //    // or second index must be either i or j but first index not | 
|---|
|  | 131 | //    else if (((argiter->indices.first != arg.indices.first) | 
|---|
|  | 132 | //              && (argiter->indices.first != arg.indices.second)) | 
|---|
|  | 133 | //            && ((argiter->indices.second == arg.indices.first) | 
|---|
|  | 134 | //                || (argiter->indices.second == arg.indices.second))) { | 
|---|
|  | 135 | //      // we need arguments ki and kj | 
|---|
|  | 136 | //      std::pair< k_args_map_t::iterator, bool> inserter = | 
|---|
|  | 137 | //          tempresult.insert( std::make_pair( argiter->indices.first, arg_list_t(1,*argiter))); | 
|---|
|  | 138 | //      if (!inserter.second) { | 
|---|
|  | 139 | //        // is present one ki or kj, if ki insert kj at back | 
|---|
|  | 140 | //        if (inserter.first->second.begin()->indices.second == arg.indices.first) | 
|---|
|  | 141 | //          inserter.first->second.push_back(*argiter); | 
|---|
|  | 142 | //        else // if kj, insert ki at front | 
|---|
|  | 143 | //          inserter.first->second.push_front(*argiter); | 
|---|
|  | 144 | //      } | 
|---|
|  | 145 | //    } | 
|---|
|  | 146 | } | 
|---|
|  | 147 | // check that i,j are NOT contained | 
|---|
|  | 148 | ASSERT( tempresult.count(arg.indices.first) == 0, | 
|---|
|  | 149 | "getTripleFromArgument() - first index of argument present in k_args_map?"); | 
|---|
|  | 150 | ASSERT( tempresult.count(arg.indices.second) == 0, | 
|---|
|  | 151 | "getTripleFromArgument() - first index of argument present in k_args_map?"); | 
|---|
|  | 152 |  | 
|---|
|  | 153 | // convert | 
|---|
|  | 154 | std::vector<FunctionModel::arguments_t> result; | 
|---|
|  | 155 | for (k_args_map_t::const_iterator iter = tempresult.begin(); | 
|---|
|  | 156 | iter != tempresult.end(); | 
|---|
|  | 157 | ++iter) { | 
|---|
|  | 158 | ASSERT( iter->second.size() == 2, | 
|---|
|  | 159 | "getTripleFromArgument() - for index "+toString(iter->first)+" we did not find both ik and jk."); | 
|---|
|  | 160 | result.push_back( FunctionModel::arguments_t(iter->second.begin(), iter->second.end()) ); | 
|---|
|  | 161 | } | 
|---|
|  | 162 | return result; | 
|---|
|  | 163 | } | 
|---|
|  | 164 |  | 
|---|
| [f06d52] | 165 | int main(int argc, char **argv) | 
|---|
|  | 166 | { | 
|---|
|  | 167 | std::cout << "Hello to the World from LevMar!" << std::endl; | 
|---|
|  | 168 |  | 
|---|
|  | 169 | // load homology file | 
|---|
|  | 170 | po::options_description desc("Allowed options"); | 
|---|
|  | 171 | desc.add_options() | 
|---|
|  | 172 | ("help", "produce help message") | 
|---|
|  | 173 | ("homology-file", po::value< boost::filesystem::path >(), "homology file to parse") | 
|---|
|  | 174 | ; | 
|---|
|  | 175 |  | 
|---|
|  | 176 | po::variables_map vm; | 
|---|
|  | 177 | po::store(po::parse_command_line(argc, argv, desc), vm); | 
|---|
|  | 178 | po::notify(vm); | 
|---|
|  | 179 |  | 
|---|
|  | 180 | if (vm.count("help")) { | 
|---|
|  | 181 | std::cout << desc << "\n"; | 
|---|
|  | 182 | return 1; | 
|---|
|  | 183 | } | 
|---|
|  | 184 |  | 
|---|
|  | 185 | boost::filesystem::path homology_file; | 
|---|
|  | 186 | if (vm.count("homology-file")) { | 
|---|
|  | 187 | homology_file = vm["homology-file"].as<boost::filesystem::path>(); | 
|---|
|  | 188 | LOG(1, "INFO: Parsing " << homology_file.string() << "."); | 
|---|
|  | 189 | } else { | 
|---|
|  | 190 | LOG(0, "homology-file level was not set."); | 
|---|
|  | 191 | } | 
|---|
|  | 192 | HomologyContainer homologies; | 
|---|
|  | 193 | if (boost::filesystem::exists(homology_file)) { | 
|---|
|  | 194 | std::ifstream returnstream(homology_file.string().c_str()); | 
|---|
|  | 195 | if (returnstream.good()) { | 
|---|
|  | 196 | boost::archive::text_iarchive ia(returnstream); | 
|---|
|  | 197 | ia >> homologies; | 
|---|
|  | 198 | } else { | 
|---|
|  | 199 | ELOG(2, "Failed to parse from " << homology_file.string() << "."); | 
|---|
|  | 200 | } | 
|---|
|  | 201 | returnstream.close(); | 
|---|
|  | 202 | } else { | 
|---|
|  | 203 | ELOG(0, homology_file << " does not exist."); | 
|---|
|  | 204 | } | 
|---|
|  | 205 |  | 
|---|
|  | 206 | // first we try to look into the HomologyContainer | 
|---|
|  | 207 | LOG(1, "INFO: Listing all present homologies ..."); | 
|---|
|  | 208 | for (HomologyContainer::container_t::const_iterator iter = | 
|---|
|  | 209 | homologies.begin(); iter != homologies.end(); ++iter) { | 
|---|
|  | 210 | LOG(1, "INFO: graph " << iter->first << " has Fragment " | 
|---|
|  | 211 | << iter->second.first << " and associated energy " << iter->second.second << "."); | 
|---|
|  | 212 | } | 
|---|
|  | 213 |  | 
|---|
| [9340ee] | 214 | /******************** Angle TRAINING ********************/ | 
|---|
|  | 215 | { | 
|---|
|  | 216 | // then we ought to pick the right HomologyGraph ... | 
|---|
| [edac7c] | 217 | const HomologyGraph graph = getFirstGraphwithTimesSpecificElement(homologies,8,1); | 
|---|
| [b17e0f] | 218 | if (graph != HomologyGraph()) { | 
|---|
|  | 219 | LOG(1, "First representative graph containing three saturated carbons is " << graph << "."); | 
|---|
|  | 220 |  | 
|---|
|  | 221 | // Afterwards we go through all of this type and gather the distance and the energy value | 
|---|
| [edac7c] | 222 | Fragment::charges_t h2o; | 
|---|
|  | 223 | h2o += 8,1,1; | 
|---|
| [b17e0f] | 224 | TrainingData AngleData( | 
|---|
| [691be4] | 225 | boost::bind(&Extractors::gatherDistancesFromFragment, | 
|---|
|  | 226 | boost::bind(&Fragment::getPositions, _1), | 
|---|
|  | 227 | boost::bind(&Fragment::getCharges, _1), | 
|---|
|  | 228 | boost::cref(h2o), | 
|---|
|  | 229 | _2) | 
|---|
| [b17e0f] | 230 | ); | 
|---|
|  | 231 | AngleData(homologies.getHomologousGraphs(graph)); | 
|---|
|  | 232 | LOG(1, "INFO: I gathered the following training data: " << AngleData); | 
|---|
|  | 233 | // NOTICE that distance are in bohrradi as they come from MPQC! | 
|---|
|  | 234 |  | 
|---|
|  | 235 | // now perform the function approximation by optimizing the model function | 
|---|
|  | 236 | FunctionModel::parameters_t params(PairPotential_Angle::MAXPARAMS, 0.); | 
|---|
|  | 237 | params[PairPotential_Angle::energy_offset] =  -1.; | 
|---|
|  | 238 | params[PairPotential_Angle::spring_constant] =  1.; | 
|---|
|  | 239 | params[PairPotential_Angle::equilibrium_distance] =  0.2; | 
|---|
|  | 240 | PairPotential_Angle angle; | 
|---|
|  | 241 | LOG(0, "INFO: Initial parameters are " << params << "."); | 
|---|
|  | 242 | angle.setParameters(params); | 
|---|
|  | 243 | FunctionModel &model = angle; | 
|---|
|  | 244 | FunctionApproximation approximator(AngleData, model); | 
|---|
|  | 245 | if (model.isBoxConstraint() && approximator.checkParameterDerivatives()) | 
|---|
|  | 246 | approximator(FunctionApproximation::ParameterDerivative); | 
|---|
|  | 247 | else { | 
|---|
|  | 248 | ELOG(0, "We require parameter derivatives for a box constraint minimization."); | 
|---|
|  | 249 | return 1; | 
|---|
|  | 250 | } | 
|---|
|  | 251 | params = model.getParameters(); | 
|---|
|  | 252 |  | 
|---|
|  | 253 | LOG(0, "RESULT: Best parameters are " << params << "."); | 
|---|
|  | 254 | } | 
|---|
| [9340ee] | 255 | } | 
|---|
|  | 256 |  | 
|---|
| [eb1efe] | 257 | /******************** MORSE TRAINING ********************/ | 
|---|
|  | 258 | { | 
|---|
|  | 259 | // then we ought to pick the right HomologyGraph ... | 
|---|
| [edac7c] | 260 | const HomologyGraph graph = getFirstGraphwithTimesSpecificElement(homologies,8,1); | 
|---|
| [b17e0f] | 261 | if (graph != HomologyGraph()) { | 
|---|
|  | 262 | LOG(1, "First representative graph containing two saturated carbons is " << graph << "."); | 
|---|
|  | 263 |  | 
|---|
|  | 264 | // Afterwards we go through all of this type and gather the distance and the energy value | 
|---|
| [edac7c] | 265 | Fragment::charges_t h2o; | 
|---|
|  | 266 | h2o += 8,1; | 
|---|
| [b17e0f] | 267 | TrainingData MorseData( | 
|---|
| [691be4] | 268 | boost::bind(&Extractors::gatherDistancesFromFragment, | 
|---|
|  | 269 | boost::bind(&Fragment::getPositions, _1), | 
|---|
|  | 270 | boost::bind(&Fragment::getCharges, _1), | 
|---|
|  | 271 | boost::cref(h2o), | 
|---|
|  | 272 | _2) | 
|---|
| [b17e0f] | 273 | ); | 
|---|
|  | 274 | MorseData(homologies.getHomologousGraphs(graph)); | 
|---|
|  | 275 | LOG(1, "INFO: I gathered the following training data: " << MorseData); | 
|---|
|  | 276 | // NOTICE that distance are in bohrradi as they come from MPQC! | 
|---|
|  | 277 |  | 
|---|
|  | 278 | // now perform the function approximation by optimizing the model function | 
|---|
|  | 279 | FunctionModel::parameters_t params(PairPotential_Morse::MAXPARAMS, 0.); | 
|---|
|  | 280 | params[PairPotential_Morse::dissociation_energy] =  0.5; | 
|---|
|  | 281 | params[PairPotential_Morse::energy_offset] =  -1.; | 
|---|
|  | 282 | params[PairPotential_Morse::spring_constant] =  1.; | 
|---|
|  | 283 | params[PairPotential_Morse::equilibrium_distance] =  2.9; | 
|---|
|  | 284 | PairPotential_Morse morse; | 
|---|
|  | 285 | LOG(0, "INFO: Initial parameters are " << params << "."); | 
|---|
|  | 286 | morse.setParameters(params); | 
|---|
|  | 287 | FunctionModel &model = morse; | 
|---|
|  | 288 | FunctionApproximation approximator(MorseData, model); // we only give CC distance, hence 1 input dim | 
|---|
|  | 289 | if (model.isBoxConstraint() && approximator.checkParameterDerivatives()) | 
|---|
|  | 290 | approximator(FunctionApproximation::ParameterDerivative); | 
|---|
|  | 291 | else { | 
|---|
|  | 292 | ELOG(0, "We require parameter derivatives for a box constraint minimization."); | 
|---|
|  | 293 | return 1; | 
|---|
|  | 294 | } | 
|---|
|  | 295 | params = model.getParameters(); | 
|---|
|  | 296 |  | 
|---|
|  | 297 | LOG(0, "RESULT: Best parameters are " << params << "."); | 
|---|
|  | 298 | } | 
|---|
| [f06d52] | 299 | } | 
|---|
| [eb1efe] | 300 |  | 
|---|
| [40fff1] | 301 | /******************* SATURATION TRAINING *******************/ | 
|---|
|  | 302 | FunctionModel::parameters_t params(SaturationPotential::MAXPARAMS, 0.); | 
|---|
| [c62f96] | 303 | { | 
|---|
| [eb1efe] | 304 | // then we ought to pick the right HomologyGraph ... | 
|---|
| [edac7c] | 305 | const HomologyGraph graph = getFirstGraphwithTimesSpecificElement(homologies,8,1); | 
|---|
| [b17e0f] | 306 | if (graph != HomologyGraph()) { | 
|---|
|  | 307 | LOG(1, "First representative graph containing one saturated carbon is " << graph << "."); | 
|---|
|  | 308 |  | 
|---|
|  | 309 | // Afterwards we go through all of this type and gather the distance and the energy value | 
|---|
| [691be4] | 310 | Fragment::charges_t h2o; | 
|---|
|  | 311 | h2o += 8,1,1; | 
|---|
| [b17e0f] | 312 | TrainingData TersoffData( | 
|---|
| [691be4] | 313 | boost::bind(&Extractors::gatherDistancesFromFragment, | 
|---|
|  | 314 | boost::bind(&Fragment::getPositions, _1), | 
|---|
|  | 315 | boost::bind(&Fragment::getCharges, _1), | 
|---|
|  | 316 | boost::cref(h2o), | 
|---|
|  | 317 | _2) | 
|---|
| [b17e0f] | 318 | ); | 
|---|
| [691be4] | 319 | //          TrainingData::extractor_t(&Extractors::gatherAllDistances) // gather first carbon pair | 
|---|
|  | 320 | //          ); | 
|---|
| [b17e0f] | 321 | TersoffData( homologies.getHomologousGraphs(graph) ); | 
|---|
|  | 322 | LOG(1, "INFO: I gathered the following training data: " << TersoffData); | 
|---|
|  | 323 | // NOTICE that distance are in bohrradi as they come from MPQC! | 
|---|
|  | 324 |  | 
|---|
|  | 325 | // now perform the function approximation by optimizing the model function | 
|---|
|  | 326 | boost::function< std::vector<FunctionModel::arguments_t>(const argument_t &, const double)> triplefunction = | 
|---|
|  | 327 | boost::bind(&getTripleFromArgument, boost::cref(TersoffData.getTrainingInputs()), _1, _2); | 
|---|
|  | 328 | srand((unsigned)time(0)); // seed with current time | 
|---|
| [dd8094] | 329 | params[SaturationPotential::all_energy_offset] = | 
|---|
|  | 330 | TersoffData.getTrainingOutputAverage()[0]; //1e+1*rand()/(double)RAND_MAX;//3.487900e+00; | 
|---|
| [b17e0f] | 331 | params[SaturationPotential::morse_spring_constant] = 1e+1*rand()/(double)RAND_MAX;//1.393600e+03; | 
|---|
|  | 332 | params[SaturationPotential::morse_equilibrium_distance] = 1e+1*rand()/(double)RAND_MAX;//3.467000e+02; | 
|---|
|  | 333 | params[SaturationPotential::morse_dissociation_energy] = 1e+1*rand()/(double)RAND_MAX;//3.487900e+00; | 
|---|
| [2ba2ed] | 334 | params[SaturationPotential::angle_spring_constant] = 1e+1*rand()/(double)RAND_MAX;//3.487900e+00; | 
|---|
|  | 335 | params[SaturationPotential::angle_equilibrium_distance] = 2e+0*rand()/(double)RAND_MAX - 1.;//3.487900e+00; | 
|---|
| [b17e0f] | 336 | LOG(0, "INFO: Initial parameters are " << params << "."); | 
|---|
|  | 337 |  | 
|---|
| [2ba2ed] | 338 | SaturationPotential saturation(2.5, triplefunction); | 
|---|
| [b17e0f] | 339 | saturation.setParameters(params); | 
|---|
|  | 340 | FunctionModel &model = saturation; | 
|---|
|  | 341 | FunctionApproximation approximator(TersoffData, model); // CH4 has 5 atoms, hence 5*4/2 distances | 
|---|
|  | 342 | if (model.isBoxConstraint() && approximator.checkParameterDerivatives()) | 
|---|
|  | 343 | approximator(FunctionApproximation::ParameterDerivative); | 
|---|
|  | 344 | else { | 
|---|
|  | 345 | ELOG(0, "We require parameter derivatives for a box constraint minimization."); | 
|---|
|  | 346 | return 1; | 
|---|
|  | 347 | } | 
|---|
|  | 348 |  | 
|---|
|  | 349 | params = model.getParameters(); | 
|---|
|  | 350 | LOG(0, "RESULT: Best parameters are " << params << "."); | 
|---|
|  | 351 |  | 
|---|
|  | 352 | //    std::cout << "\tsaturationparticle:"; | 
|---|
|  | 353 | //    std::cout << "\tparticle_type=C,"; | 
|---|
|  | 354 | //    std::cout << "\tA=" << params[SaturationPotential::A] << ","; | 
|---|
|  | 355 | //    std::cout << "\tB=" << params[SaturationPotential::B] << ","; | 
|---|
|  | 356 | //    std::cout << "\tlambda=" << params[SaturationPotential::lambda] << ","; | 
|---|
|  | 357 | //    std::cout << "\tmu=" << params[SaturationPotential::mu] << ","; | 
|---|
|  | 358 | //    std::cout << "\tbeta=" << params[SaturationPotential::beta] << ","; | 
|---|
|  | 359 | //    std::cout << "\tn=" << params[SaturationPotential::n] << ","; | 
|---|
|  | 360 | //    std::cout << "\tc=" << params[SaturationPotential::c] << ","; | 
|---|
|  | 361 | //    std::cout << "\td=" << params[SaturationPotential::d] << ","; | 
|---|
|  | 362 | //    std::cout << "\th=" << params[SaturationPotential::h] << ","; | 
|---|
|  | 363 | ////    std::cout << "\toffset=" << params[SaturationPotential::offset] << ","; | 
|---|
|  | 364 | //    std::cout << "\tR=" << saturation.R << ","; | 
|---|
|  | 365 | //    std::cout << "\tS=" << saturation.S << ";"; | 
|---|
|  | 366 | //    std::cout << std::endl; | 
|---|
|  | 367 |  | 
|---|
|  | 368 | // check L2 and Lmax error against training set | 
|---|
|  | 369 | LOG(1, "INFO: L2sum = " << TersoffData.getL2Error(model) | 
|---|
|  | 370 | << ", LMax = " << TersoffData.getLMaxError(model) << "."); | 
|---|
|  | 371 | } | 
|---|
|  | 372 |  | 
|---|
| [f06d52] | 373 | } | 
|---|
|  | 374 |  | 
|---|
|  | 375 | return 0; | 
|---|
|  | 376 | } | 
|---|