source: src/Potentials/Specifics/FourBodyPotential_Torsion.cpp@ a2a2f7

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

Huge warning fix.

  • fixed unused variables.
  • fixed set but unused variables.
  • fixed signed vs. unsigned int comparison.
  • fixed static_warning_test<false, 98> (commented out _IMPLEMENT).
  • Property mode set to 100644
File size: 9.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 Frederik Heber. 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 * FourBodyPotential_Torsion.cpp
26 *
27 * Created on: Jul 08, 2013
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 "FourBodyPotential_Torsion.hpp"
40
41#include <boost/assign/list_of.hpp> // for 'map_list_of()'
42#include <boost/bind.hpp>
43#include <boost/lambda/lambda.hpp>
44#include <string>
45
46#include "CodePatterns/Assert.hpp"
47
48#include "FunctionApproximation/Extractors.hpp"
49#include "FunctionApproximation/TrainingData.hpp"
50#include "Potentials/helpers.hpp"
51#include "Potentials/InternalCoordinates/FourBody_TorsionAngle.hpp"
52#include "Potentials/ParticleTypeCheckers.hpp"
53
54class Fragment;
55
56// static definitions
57const FourBodyPotential_Torsion::ParameterNames_t
58FourBodyPotential_Torsion::ParameterNames =
59 boost::assign::list_of<std::string>
60 ("spring_constant")
61 ("equilibrium_distance")
62 ;
63const std::string FourBodyPotential_Torsion::potential_token("torsion");
64Coordinator::ptr FourBodyPotential_Torsion::coordinator(new FourBody_TorsionAngle());
65
66FourBodyPotential_Torsion::FourBodyPotential_Torsion() :
67 EmpiricalPotential(),
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] = 0.1;
73}
74
75FourBodyPotential_Torsion::FourBodyPotential_Torsion(
76 const ParticleTypes_t &_ParticleTypes
77 ) :
78 EmpiricalPotential(_ParticleTypes),
79 params(parameters_t(MAXPARAMS, 0.))
80{
81 // have some decent defaults for parameter_derivative checking
82 params[spring_constant] = 1.;
83 params[equilibrium_distance] = 0.1;
84}
85
86FourBodyPotential_Torsion::FourBodyPotential_Torsion(
87 const ParticleTypes_t &_ParticleTypes,
88 const double _spring_constant,
89 const double _equilibrium_distance) :
90 EmpiricalPotential(_ParticleTypes),
91 params(parameters_t(MAXPARAMS, 0.))
92{
93 params[spring_constant] = _spring_constant;
94 params[equilibrium_distance] = _equilibrium_distance;
95}
96
97void FourBodyPotential_Torsion::setParameters(const parameters_t &_params)
98{
99 const size_t paramsDim = _params.size();
100 ASSERT( paramsDim <= getParameterDimension(),
101 "FourBodyPotential_Torsion::setParameters() - we need not more than "
102 +toString(getParameterDimension())+" parameters.");
103 for(size_t i=0;i<paramsDim;++i)
104 params[i] = _params[i];
105
106#ifndef NDEBUG
107 parameters_t check_params(getParameters());
108 check_params.resize(paramsDim); // truncate to same size
109 ASSERT( check_params == _params,
110 "FourBodyPotential_Torsion::setParameters() - failed, mismatch in to be set "
111 +toString(_params)+" and set "+toString(check_params)+" params.");
112#endif
113}
114
115FourBodyPotential_Torsion::result_t
116FourBodyPotential_Torsion::function_theta(
117 const double &r_ij,
118 const double &r_ik,
119 const double &r_il,
120 const double &r_jk,
121 const double &r_jl,
122 const double &r_kl
123 ) const
124{
125// Info info(__func__);
126 const double h_1 = .5*sqrt(2.*(Helpers::pow(r_ij,2)+Helpers::pow(r_ik,2))-Helpers::pow(r_jk,2));
127 const double h_2 = .5*sqrt(2.*(Helpers::pow(r_jl,2)+Helpers::pow(r_kl,2))-Helpers::pow(r_jk,2));
128 const double angle = Helpers::pow(h_1,2) + Helpers::pow(h_2,2) - Helpers::pow(r_il,2);
129 const double divisor = 2.* h_1 * h_2;
130
131// LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
132 if (divisor == 0.)
133 return 0.;
134 else
135 return angle/divisor;
136}
137
138FourBodyPotential_Torsion::results_t
139FourBodyPotential_Torsion::operator()(
140 const arguments_t &arguments
141 ) const
142{
143 ASSERT( arguments.size() == getSpecificArgumentCount(),
144 "FourBodyPotential_Torsion::operator() - requires exactly three arguments.");
145 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
146 arguments, getParticleTypes()),
147 "FourBodyPotential_Torsion::operator() - types don't match with ones in arguments.");
148 const argument_t &r_ij = arguments[0]; // 01
149 const argument_t &r_ik = arguments[1]; // 02
150 const argument_t &r_il = arguments[2]; // 03
151 const argument_t &r_jk = arguments[3]; // 12
152 const argument_t &r_jl = arguments[4]; // 13
153 const argument_t &r_kl = arguments[5]; // 23
154 const result_t result =
155 params[spring_constant]
156 * Helpers::pow( function_theta(r_ij.distance, r_ik.distance, r_il.distance, r_jk.distance, r_jl.distance, r_kl.distance) - params[equilibrium_distance], 2 );
157 return std::vector<result_t>(1, result);
158}
159
160FourBodyPotential_Torsion::derivative_components_t
161FourBodyPotential_Torsion::derivative(
162 const arguments_t &arguments
163 ) const
164{
165 ASSERT( arguments.size() == getSpecificArgumentCount(),
166 "FourBodyPotential_Torsion::operator() - requires exactly three arguments.");
167 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
168 arguments, getParticleTypes()),
169 "FourBodyPotential_Torsion::operator() - types don't match with ones in arguments.");
170 derivative_components_t result;
171 const argument_t &r_ij = arguments[0]; // 01
172 const argument_t &r_ik = arguments[1]; // 02
173 const argument_t &r_il = arguments[2]; // 03
174 const argument_t &r_jk = arguments[3]; // 12
175 const argument_t &r_jl = arguments[4]; // 13
176 const argument_t &r_kl = arguments[5]; // 23
177 result.push_back( 2. * params[spring_constant] * ( function_theta(r_ij.distance, r_ik.distance, r_il.distance, r_jk.distance, r_jl.distance, r_kl.distance) - params[equilibrium_distance]) );
178 ASSERT( result.size() == 1,
179 "FourBodyPotential_Torsion::operator() - we did not create exactly one component.");
180 return result;
181}
182
183FourBodyPotential_Torsion::results_t
184FourBodyPotential_Torsion::parameter_derivative(
185 const arguments_t &arguments,
186 const size_t index
187 ) const
188{
189 ASSERT( arguments.size() == getSpecificArgumentCount(),
190 "FourBodyPotential_Torsion::parameter_derivative() - requires exactly three arguments.");
191 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
192 arguments, getParticleTypes()),
193 "FourBodyPotential_Torsion::operator() - types don't match with ones in arguments.");
194 const argument_t &r_ij = arguments[0]; // 01
195 const argument_t &r_ik = arguments[1]; // 02
196 const argument_t &r_il = arguments[2]; // 03
197 const argument_t &r_jk = arguments[3]; // 12
198 const argument_t &r_jl = arguments[4]; // 13
199 const argument_t &r_kl = arguments[5]; // 23
200 switch (index) {
201 case spring_constant:
202 {
203 const result_t result =
204 Helpers::pow( function_theta(r_ij.distance, r_ik.distance, r_il.distance, r_jk.distance, r_jl.distance, r_kl.distance) - params[equilibrium_distance], 2 );
205 return std::vector<result_t>(1, result);
206 break;
207 }
208 case equilibrium_distance:
209 {
210 const result_t result =
211 -2. * params[spring_constant]
212 * ( function_theta(r_ij.distance, r_ik.distance, r_il.distance, r_jk.distance, r_jl.distance, r_kl.distance) - params[equilibrium_distance]);
213 return std::vector<result_t>(1, result);
214 break;
215 }
216 default:
217 ASSERT(0, "FourBodyPotential_Torsion::parameter_derivative() - derivative to unknown parameter desired.");
218 break;
219 }
220 return std::vector<result_t>(1);
221}
222
223FunctionModel::extractor_t
224FourBodyPotential_Torsion::getSpecificExtractor() const
225{
226 Fragment::charges_t charges;
227 charges.resize(getParticleTypes().size());
228 std::transform(getParticleTypes().begin(), getParticleTypes().end(),
229 charges.begin(), boost::lambda::_1);
230 FunctionModel::extractor_t returnfunction =
231 boost::bind(&Extractors::gatherDistancesFromFragment,
232 boost::bind(&Fragment::getPositions, _1),
233 boost::bind(&Fragment::getCharges, _1),
234 charges,
235 _2);
236 return returnfunction;
237}
238
239FunctionModel::filter_t
240FourBodyPotential_Torsion::getSpecificFilter() const
241{
242 FunctionModel::filter_t returnfunction =
243 boost::bind(&Extractors::reorderArgumentsByParticleTypes,
244 boost::bind(&Extractors::filterArgumentsByParticleTypes,
245 _1,
246 getParticleTypes()),
247 getParticleTypes()
248 );
249 return returnfunction;
250}
251
252void
253FourBodyPotential_Torsion::setParametersToRandomInitialValues(
254 const TrainingData &data)
255{
256 params[FourBodyPotential_Torsion::spring_constant] = 2.*rand()/(double)RAND_MAX;
257 params[FourBodyPotential_Torsion::equilibrium_distance] = -.5+1.*rand()/(double)RAND_MAX;
258}
259
Note: See TracBrowser for help on using the repository browser.