source: src/Potentials/Specifics/SaturationPotential.cpp@ 55fe788

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 55fe788 was b3eabc, checked in by Frederik Heber <heber@…>, 12 years ago

SaturationPotential now requires symmetric distances.

  • Property mode set to 100644
File size: 10.0 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 * SaturationPotential.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 "SaturationPotential.hpp"
40
41#include <boost/assign/list_of.hpp> // for 'map_list_of()'
42#include <iostream>
43#include <string>
44
45#include "CodePatterns/Assert.hpp"
46#include "CodePatterns/Log.hpp"
47
48#include "Potentials/helpers.hpp"
49
50// static definitions
51const SaturationPotential::ParameterNames_t
52SaturationPotential::ParameterNames =
53 boost::assign::list_of<std::string>
54 ("all_energy_offset")
55 ("")
56 ("")
57 ("")
58 ("")
59 ("")
60 ;
61const std::string SaturationPotential::potential_token("saturation");
62
63SaturationPotential::SaturationPotential(
64 const ParticleTypes_t &_ParticleTypes,
65 const double _saturation_cutoff,
66 boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction) :
67 SerializablePotential(_ParticleTypes),
68 morse(_ParticleTypes),
69 angle(_ParticleTypes),
70 energy_offset(0.),
71 triplefunction(_triplefunction),
72 saturation_cutoff(_saturation_cutoff)
73{}
74
75SaturationPotential::SaturationPotential(
76 const ParticleTypes_t &_ParticleTypes,
77 const double _all_energy_offset,
78 const double _morse_spring_constant,
79 const double _morse_equilibrium_distance,
80 const double _morse_dissociation_energy,
81 const double _angle_spring_constant,
82 const double _angle_equilibrium_distance,
83 const double _saturation_cutoff,
84 boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction) :
85 SerializablePotential(_ParticleTypes),
86 morse(_ParticleTypes),
87 angle(_ParticleTypes),
88 energy_offset(_all_energy_offset),
89 triplefunction(_triplefunction),
90 saturation_cutoff(_saturation_cutoff)
91{
92 parameters_t morse_params(morse.getParameterDimension());
93 morse_params[PairPotential_Morse::spring_constant] = _morse_spring_constant;
94 morse_params[PairPotential_Morse::equilibrium_distance] = _morse_equilibrium_distance;
95 morse_params[PairPotential_Morse::dissociation_energy] = _morse_dissociation_energy;
96 morse_params[PairPotential_Morse::energy_offset] = 0.;
97 morse.setParameters(morse_params);
98 parameters_t angle_params(angle.getParameterDimension());
99 angle_params[PairPotential_Angle::spring_constant] = _angle_spring_constant;
100 angle_params[PairPotential_Angle::equilibrium_distance] = _angle_equilibrium_distance;
101 angle_params[PairPotential_Angle::energy_offset] = 0.;
102 angle.setParameters(angle_params);
103}
104
105void SaturationPotential::setParameters(const parameters_t &_params)
106{
107 const size_t paramsDim = _params.size();
108 ASSERT( paramsDim <= getParameterDimension(),
109 "SaturationPotential::setParameters() - we need not more than "
110 +toString(getParameterDimension())+" parameters.");
111// LOG(1, "INFO: Setting new SaturationPotential params: " << _params);
112
113
114 // offsets
115 if (paramsDim > all_energy_offset)
116 energy_offset = _params[all_energy_offset];
117
118 // Morse
119 {
120 parameters_t morse_params(morse.getParameters());
121 if (paramsDim > morse_spring_constant)
122 morse_params[PairPotential_Morse::spring_constant] = _params[morse_spring_constant];
123 if (paramsDim > morse_equilibrium_distance)
124 morse_params[PairPotential_Morse::equilibrium_distance] = _params[morse_equilibrium_distance];
125 if (paramsDim > morse_dissociation_energy)
126 morse_params[PairPotential_Morse::dissociation_energy] = _params[morse_dissociation_energy];
127 morse_params[PairPotential_Morse::energy_offset] = 0.;
128 morse.setParameters(morse_params);
129 }
130
131 // Angle
132 {
133 parameters_t angle_params(angle.getParameters());
134 if (paramsDim > angle_spring_constant)
135 angle_params[PairPotential_Angle::spring_constant] = _params[angle_spring_constant];
136 if (paramsDim > angle_equilibrium_distance)
137 angle_params[PairPotential_Angle::equilibrium_distance] = _params[angle_equilibrium_distance];
138 angle_params[PairPotential_Angle::energy_offset] = 0.;
139 angle.setParameters(angle_params);
140 }
141#ifndef NDEBUG
142 parameters_t check_params(getParameters());
143 check_params.resize(paramsDim); // truncate to same size
144 ASSERT( check_params == _params,
145 "SaturationPotential::setParameters() - failed, mismatch in to be set "
146 +toString(_params)+" and set "+toString(check_params)+" params.");
147#endif
148}
149
150SaturationPotential::parameters_t SaturationPotential::getParameters() const
151{
152 parameters_t params(getParameterDimension());
153 const parameters_t morse_params = morse.getParameters();
154 const parameters_t angle_params = angle.getParameters();
155
156 params[all_energy_offset] = energy_offset;
157
158 params[morse_spring_constant] = morse_params[PairPotential_Morse::spring_constant];
159 params[morse_equilibrium_distance] = morse_params[PairPotential_Morse::equilibrium_distance];
160 params[morse_dissociation_energy] = morse_params[PairPotential_Morse::dissociation_energy];
161
162 params[angle_spring_constant] = angle_params[PairPotential_Angle::spring_constant];
163 params[angle_equilibrium_distance] = angle_params[PairPotential_Angle::equilibrium_distance];
164 return params;
165}
166
167SaturationPotential::results_t
168SaturationPotential::operator()(
169 const arguments_t &arguments
170 ) const
171{
172 double result = 0.;
173 for(arguments_t::const_iterator argiter = arguments.begin();
174 argiter != arguments.end();
175 ++argiter) {
176 const argument_t &r_ij = *argiter;
177 if ((r_ij.indices.first == 0)) { // first item must be the non-hydrogen
178 arguments_t args(1, r_ij);
179
180 // Morse contribution
181 result += morse(args)[0];
182 if (result != result)
183 ELOG(1, "result is NAN.");
184 }
185 }
186 // Angle contribution
187 result += angle(arguments)[0]; // as we have all distances we get both jk and kj
188 if (result != result)
189 ELOG(1, "result is NAN.");
190//
191// // Angle contribution
192// std::vector<arguments_t> triples = triplefunction(r_ij, saturation_cutoff);
193// args.resize(3, r_ij);
194// for (std::vector<arguments_t>::const_iterator iter = triples.begin();
195// iter != triples.end(); ++iter) {
196// ASSERT( iter->size() == 2,
197// "SaturationPotential::function_derivative_c() - the triples result must contain exactly two distances.");
198// const argument_t &r_ik = (*iter)[0];
199// const argument_t &r_jk = (*iter)[1];
200// args[1] = r_ik;
201// args[2] = r_jk;
202// result += .5*angle(args)[0]; // as we have all distances we get both jk and kj
203// if (result != result)
204// ELOG(1, "result is NAN.");
205// }
206// }
207// }
208 return std::vector<result_t>(1, energy_offset + result);
209}
210
211SaturationPotential::derivative_components_t
212SaturationPotential::derivative(
213 const arguments_t &arguments
214 ) const
215{
216 ASSERT( 0,
217 "SaturationPotential::operator() - not implemented.");
218 derivative_components_t result;
219 return result;
220}
221
222SaturationPotential::results_t
223SaturationPotential::parameter_derivative(
224 const arguments_t &arguments,
225 const size_t index
226 ) const
227{
228 double result = 0.;
229 switch (index) {
230 case all_energy_offset:
231 {
232 result = 1.;
233 break;
234 }
235 case morse_spring_constant:
236 case morse_equilibrium_distance:
237 case morse_dissociation_energy:
238 {
239 const ParticleTypes_t &morse_types = morse.getParticleTypes();
240 for(arguments_t::const_iterator argiter = arguments.begin();
241 argiter != arguments.end();
242 ++argiter) {
243 const argument_t &r_ij = *argiter;
244 if (((r_ij.types.first == morse_types[0]) && (r_ij.types.second == morse_types[1]))
245 || ((r_ij.types.first == morse_types[1]) && (r_ij.types.second == morse_types[0]))) {
246 arguments_t args(1, r_ij);
247 switch (index) {
248 case morse_spring_constant:
249 result += morse.parameter_derivative(args, PairPotential_Morse::spring_constant)[0];
250 break;
251 case morse_equilibrium_distance:
252 result += morse.parameter_derivative(args, PairPotential_Morse::equilibrium_distance)[0];
253 break;
254 case morse_dissociation_energy:
255 result += morse.parameter_derivative(args, PairPotential_Morse::dissociation_energy)[0];
256 break;
257 default:
258 ASSERT( 0, "SaturationPotential::parameter_derivative() - impossible to get here.");
259 break;
260 }
261 }
262 }
263 break;
264 }
265 case angle_spring_constant:
266 {
267 result = angle.parameter_derivative(arguments, PairPotential_Angle::spring_constant)[0];
268 break;
269 }
270 case angle_equilibrium_distance:
271 {
272 result = angle.parameter_derivative(arguments, PairPotential_Angle::equilibrium_distance)[0];
273 break;
274 }
275 default:
276 ELOG(1, "SaturationPotential::parameter_derivative() - index " << index << " invalid.");
277 break;
278 }
279 return SaturationPotential::results_t(1, result);
280}
281
282std::ostream& operator<<(std::ostream &ost, const SaturationPotential &potential)
283{
284 ost << potential.morse;
285 ost << potential.angle;
286 return ost;
287}
288
289std::istream& operator>>(std::istream &ist, SaturationPotential &potential)
290{
291 ist >> potential.morse;
292 ist >> potential.angle;
293 return ist;
294}
Note: See TracBrowser for help on using the repository browser.