source: src/Potentials/Specifics/PairPotential_Harmonic.cpp@ 39a07a

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 39a07a was d52819, checked in by Frederik Heber <heber@…>, 12 years ago

Extracted initial parameter setting per specific potential to FunctionModel::setParametersToRandomInitialValues().

  • this is preparatory for generalizing potential fitting.
  • Property mode set to 100644
File size: 6.7 KB
Line 
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 * PairPotential_Harmonic.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 "PairPotential_Harmonic.hpp"
40
41#include <boost/assign/list_of.hpp> // for 'map_list_of()'
42#include <boost/bind.hpp>
43#include <string>
44
45#include "CodePatterns/Assert.hpp"
46
47#include "FunctionApproximation/Extractors.hpp"
48#include "FunctionApproximation/TrainingData.hpp"
49#include "Potentials/helpers.hpp"
50#include "Potentials/ParticleTypeCheckers.hpp"
51
52class Fragment;
53
54// static definitions
55const PairPotential_Harmonic::ParameterNames_t
56PairPotential_Harmonic::ParameterNames =
57 boost::assign::list_of<std::string>
58 ("spring_constant")
59 ("equilibrium_distance")
60 ("") //energy_offset
61 ;
62const std::string PairPotential_Harmonic::potential_token("harmonic_bond");
63
64PairPotential_Harmonic::PairPotential_Harmonic(
65 const ParticleTypes_t &_ParticleTypes) :
66 SerializablePotential(_ParticleTypes),
67 params(parameters_t(MAXPARAMS, 0.))
68{
69 // have some decent defaults for parameter_derivative checking
70 params[spring_constant] = 1.;
71 params[equilibrium_distance] = 1.;
72 params[energy_offset] = 0.1;
73}
74
75PairPotential_Harmonic::PairPotential_Harmonic(
76 const ParticleTypes_t &_ParticleTypes,
77 const double _spring_constant,
78 const double _equilibrium_distance,
79 const double _energy_offset) :
80 SerializablePotential(_ParticleTypes),
81 params(parameters_t(MAXPARAMS, 0.))
82{
83 params[spring_constant] = _spring_constant;
84 params[equilibrium_distance] = _equilibrium_distance;
85 params[energy_offset] = _energy_offset;
86}
87
88void PairPotential_Harmonic::setParameters(const parameters_t &_params)
89{
90 const size_t paramsDim = _params.size();
91 ASSERT( paramsDim <= getParameterDimension(),
92 "PairPotential_Harmonic::setParameters() - we need not more than "
93 +toString(getParameterDimension())+" parameters.");
94 for(size_t i=0;i<paramsDim;++i)
95 params[i] = _params[i];
96
97#ifndef NDEBUG
98 parameters_t check_params(getParameters());
99 check_params.resize(paramsDim); // truncate to same size
100 ASSERT( check_params == _params,
101 "PairPotential_Harmonic::setParameters() - failed, mismatch in to be set "
102 +toString(_params)+" and set "+toString(check_params)+" params.");
103#endif
104}
105
106PairPotential_Harmonic::results_t
107PairPotential_Harmonic::operator()(
108 const arguments_t &arguments
109 ) const
110{
111 ASSERT( arguments.size() == 1,
112 "PairPotential_Harmonic::operator() - requires exactly one argument.");
113 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypesStrictOrdering(
114 arguments, getParticleTypes()),
115 "PairPotential_Harmonic::operator() - types don't match with ones in arguments.");
116 const argument_t &r_ij = arguments[0];
117 const result_t result =
118 params[spring_constant]
119 * Helpers::pow( r_ij.distance - params[equilibrium_distance], 2 )
120 + params[energy_offset];
121 return std::vector<result_t>(1, result);
122}
123
124PairPotential_Harmonic::derivative_components_t
125PairPotential_Harmonic::derivative(
126 const arguments_t &arguments
127 ) const
128{
129 ASSERT( arguments.size() == 1,
130 "PairPotential_Harmonic::operator() - requires exactly one argument.");
131 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypesStrictOrdering(
132 arguments, getParticleTypes()),
133 "PairPotential_Harmonic::operator() - types don't match with ones in arguments.");
134 derivative_components_t result;
135 const argument_t &r_ij = arguments[0];
136 result.push_back( 2. * params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]) );
137 ASSERT( result.size() == 1,
138 "PairPotential_Harmonic::operator() - we did not create exactly one component.");
139 return result;
140}
141
142PairPotential_Harmonic::results_t
143PairPotential_Harmonic::parameter_derivative(
144 const arguments_t &arguments,
145 const size_t index
146 ) const
147{
148 ASSERT( arguments.size() == 1,
149 "PairPotential_Harmonic::parameter_derivative() - requires exactly one argument.");
150 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypesStrictOrdering(
151 arguments, getParticleTypes()),
152 "PairPotential_Harmonic::operator() - types don't match with ones in arguments.");
153 const argument_t &r_ij = arguments[0];
154 switch (index) {
155 case spring_constant:
156 {
157 const result_t result =
158 Helpers::pow( r_ij.distance - params[equilibrium_distance], 2 );
159 return std::vector<result_t>(1, result);
160 break;
161 }
162 case equilibrium_distance:
163 {
164 const result_t result =
165 -2. * params[spring_constant]
166 * ( r_ij.distance - params[equilibrium_distance]);
167 return std::vector<result_t>(1, result);
168 break;
169 }
170 case energy_offset:
171 {
172 const result_t result = +1.;
173 return std::vector<result_t>(1, result);
174 break;
175 }
176 default:
177 break;
178 }
179
180 return PairPotential_Harmonic::results_t(1, 0.);
181}
182
183FunctionModel::extractor_t
184PairPotential_Harmonic::getFragmentSpecificExtractor(
185 const charges_t &charges) const
186{
187 ASSERT(charges.size() == (size_t)2,
188 "PairPotential_Harmonic::getFragmentSpecificExtractor() - requires 2 charges.");
189 FunctionModel::extractor_t returnfunction =
190 boost::bind(&Extractors::gatherDistancesFromFragment,
191 boost::bind(&Fragment::getPositions, _1),
192 boost::bind(&Fragment::getCharges, _1),
193 boost::cref(charges),
194 _2);
195 return returnfunction;
196}
197
198void
199PairPotential_Harmonic::setParametersToRandomInitialValues(
200 const TrainingData &data)
201{
202 params[PairPotential_Harmonic::energy_offset] =
203 data.getTrainingOutputAverage()[0];// -1.;
204 params[PairPotential_Harmonic::equilibrium_distance] = 3e+0*rand()/(double)RAND_MAX + .5;// 1.;
205 params[PairPotential_Harmonic::spring_constant] = 1e+0*rand()/(double)RAND_MAX;// 0.2;
206}
207
Note: See TracBrowser for help on using the repository browser.