source: src/Potentials/Specifics/PairPotential_Angle.cpp@ 7b019a

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 Candidate_v1.7.0 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 7b019a was 7b019a, checked in by Frederik Heber <heber@…>, 13 years ago

Extended FunctionModel by getFragmentSpecificExtractor() definition.

  • shifted extractor_t from TrainingData to FunctionModel.
  • implemented function for every specific potential.
  • this is preparatory for generalizing function approximation in LevMartester.
  • we make use of the newly introduced extractors in the potentials and the required number of charges is ASSERT'd.
  • Property mode set to 100644
File size: 7.1 KB
RevLine 
[a63187]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_Angle.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 "PairPotential_Angle.hpp"
40
[ed2551]41#include <boost/assign/list_of.hpp> // for 'map_list_of()'
[7b019a]42#include <boost/bind.hpp>
[ed2551]43#include <string>
44
[a63187]45#include "CodePatterns/Assert.hpp"
46
[7b019a]47#include "FunctionApproximation/Extractors.hpp"
[a63187]48#include "Potentials/helpers.hpp"
[b760bc3]49#include "Potentials/ParticleTypeCheckers.hpp"
[a63187]50
[7b019a]51class Fragment;
52
[ed2551]53// static definitions
54const PairPotential_Angle::ParameterNames_t
55PairPotential_Angle::ParameterNames =
56 boost::assign::list_of<std::string>
57 ("spring_constant")
58 ("equilibrium_distance")
59 ("") //energy_offset
60 ;
61const std::string PairPotential_Angle::potential_token("harmonic_angle");
62
63PairPotential_Angle::PairPotential_Angle(
64 const ParticleTypes_t &_ParticleTypes
65 ) :
66 SerializablePotential(_ParticleTypes),
[a63187]67 params(parameters_t(MAXPARAMS, 0.))
[dbf8c8]68{
69 // have some decent defaults for parameter_derivative checking
70 params[spring_constant] = 1.;
71 params[equilibrium_distance] = 0.1;
72 params[energy_offset] = 0.1;
73}
[a63187]74
75PairPotential_Angle::PairPotential_Angle(
[ed2551]76 const ParticleTypes_t &_ParticleTypes,
[a63187]77 const double _spring_constant,
78 const double _equilibrium_distance,
79 const double _energy_offset) :
[ed2551]80 SerializablePotential(_ParticleTypes),
81 params(parameters_t(MAXPARAMS, 0.))
[a63187]82{
83 params[spring_constant] = _spring_constant;
84 params[equilibrium_distance] = _equilibrium_distance;
85 params[energy_offset] = _energy_offset;
86}
87
[086070]88void PairPotential_Angle::setParameters(const parameters_t &_params)
89{
90 const size_t paramsDim = _params.size();
91 ASSERT( paramsDim <= getParameterDimension(),
92 "PairPotential_Angle::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_Angle::setParameters() - failed, mismatch in to be set "
102 +toString(_params)+" and set "+toString(check_params)+" params.");
103#endif
104}
105
[a63187]106PairPotential_Angle::result_t
107PairPotential_Angle::function_theta(
108 const double &r_ij,
109 const double &r_ik,
110 const double &r_jk
111 ) const
112{
113// Info info(__func__);
114 const double angle = Helpers::pow(r_ij,2) + Helpers::pow(r_ik,2) - Helpers::pow(r_jk,2);
115 const double divisor = 2.* r_ij * r_ik;
116
117// LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
118 if (divisor == 0.)
119 return 0.;
120 else
121 return angle/divisor;
122}
123
124PairPotential_Angle::results_t
125PairPotential_Angle::operator()(
126 const arguments_t &arguments
127 ) const
128{
129 ASSERT( arguments.size() == 3,
130 "PairPotential_Angle::operator() - requires exactly three arguments.");
[b760bc3]131 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypesStrictOrdering(
132 arguments, getParticleTypes()),
133 "PairPotential_Angle::operator() - types don't match with ones in arguments.");
[a63187]134 const argument_t &r_ij = arguments[0];
135 const argument_t &r_ik = arguments[1];
136 const argument_t &r_jk = arguments[2];
137 const result_t result =
138 params[spring_constant]
139 * Helpers::pow( function_theta(r_ij.distance, r_ik.distance, r_jk.distance) - params[equilibrium_distance], 2 )
140 + params[energy_offset];
141 return std::vector<result_t>(1, result);
142}
143
144PairPotential_Angle::derivative_components_t
145PairPotential_Angle::derivative(
146 const arguments_t &arguments
147 ) const
148{
149 ASSERT( arguments.size() == 3,
150 "PairPotential_Angle::operator() - requires exactly three arguments.");
[b760bc3]151 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypesStrictOrdering(
152 arguments, getParticleTypes()),
153 "PairPotential_Angle::operator() - types don't match with ones in arguments.");
[a63187]154 derivative_components_t result;
155 const argument_t &r_ij = arguments[0];
[c92c0d]156 const argument_t &r_ik = arguments[1];
157 const argument_t &r_jk = arguments[2];
158 result.push_back( 2. * params[spring_constant] * ( function_theta(r_ij.distance, r_ik.distance, r_jk.distance) - params[equilibrium_distance]) );
[a63187]159 ASSERT( result.size() == 1,
160 "PairPotential_Angle::operator() - we did not create exactly one component.");
161 return result;
162}
163
164PairPotential_Angle::results_t
165PairPotential_Angle::parameter_derivative(
166 const arguments_t &arguments,
167 const size_t index
168 ) const
169{
170 ASSERT( arguments.size() == 3,
171 "PairPotential_Angle::parameter_derivative() - requires exactly three arguments.");
[b760bc3]172 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypesStrictOrdering(
173 arguments, getParticleTypes()),
174 "PairPotential_Angle::operator() - types don't match with ones in arguments.");
[a63187]175 const argument_t &r_ij = arguments[0];
176 const argument_t &r_ik = arguments[1];
177 const argument_t &r_jk = arguments[2];
178 switch (index) {
179 case spring_constant:
180 {
181 const result_t result =
182 Helpers::pow( function_theta(r_ij.distance, r_ik.distance, r_jk.distance) - params[equilibrium_distance], 2 );
183 return std::vector<result_t>(1, result);
184 break;
185 }
186 case equilibrium_distance:
187 {
188 const result_t result =
189 -2. * params[spring_constant]
190 * ( function_theta(r_ij.distance, r_ik.distance, r_jk.distance) - params[equilibrium_distance]);
191 return std::vector<result_t>(1, result);
192 break;
193 }
194 case energy_offset:
195 {
196 const result_t result = +1.;
197 return std::vector<result_t>(1, result);
198 break;
199 }
200 default:
[086070]201 return PairPotential_Angle::results_t(1, 0.);
[a63187]202 break;
203 }
204}
[7b019a]205
206FunctionModel::extractor_t
207PairPotential_Angle::getFragmentSpecificExtractor(
208 const charges_t &charges) const
209{
210 ASSERT(charges.size() == (size_t)3,
211 "PairPotential_Angle::getFragmentSpecificExtractor() - requires 3 charges.");
212 FunctionModel::extractor_t returnfunction =
213 boost::bind(&Extractors::gatherDistancesFromFragment,
214 boost::bind(&Fragment::getPositions, _1),
215 boost::bind(&Fragment::getCharges, _1),
216 boost::cref(charges),
217 _2);
218 return returnfunction;
219}
220
Note: See TracBrowser for help on using the repository browser.