source: src/Potentials/Specifics/PairPotential_Harmonic.cpp@ 713888

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 713888 was acc9b1, checked in by Frederik Heber <heber@…>, 11 years ago

FIX: Added new copyright lines to files in src/Potentials, too.

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