source: src/Potentials/Specifics/SaturationPotential.cpp@ 1f06896

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 1f06896 was 4ffbb7, checked in by Frederik Heber <heber@…>, 12 years ago

Added SaturatonPotential that combines a Morse and a Angle potential.

  • Property mode set to 100644
File size: 8.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 * 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 "CodePatterns/Assert.hpp"
42
43#include "Potentials/helpers.hpp"
44
45SaturationPotential::SaturationPotential(
46 boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction) :
47 energy_offset(0.),
48 triplefunction(_triplefunction),
49 saturation_cutoff(2.5)
50{}
51
52SaturationPotential::SaturationPotential(
53 const double _morse_spring_constant,
54 const double _morse_equilibrium_distance,
55 const double _morse_dissociation_energy,
56 const double _angle_spring_constant,
57 const double _angle_equilibrium_distance,
58 const double _all_energy_offset,
59 boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction) :
60 energy_offset(_all_energy_offset),
61 triplefunction(_triplefunction),
62 saturation_cutoff(2.5)
63{
64 parameters_t morse_params(morse.getParameterDimension());
65 morse_params[PairPotential_Morse::spring_constant] = _morse_spring_constant;
66 morse_params[PairPotential_Morse::equilibrium_distance] = _morse_equilibrium_distance;
67 morse_params[PairPotential_Morse::dissociation_energy] = _morse_dissociation_energy;
68 morse_params[PairPotential_Morse::energy_offset] = 0.;
69 morse.setParameters(morse_params);
70 parameters_t angle_params(angle.getParameterDimension());
71 angle_params[PairPotential_Angle::spring_constant] = _angle_spring_constant;
72 angle_params[PairPotential_Angle::equilibrium_distance] = _angle_equilibrium_distance;
73 angle_params[PairPotential_Angle::energy_offset] = 0.;
74 angle.setParameters(angle_params);
75}
76
77void SaturationPotential::setParameters(const parameters_t &_params)
78{
79 const size_t paramsDim = _params.size();
80 ASSERT( paramsDim <= getParameterDimension(),
81 "SaturationPotential::setParameters() - we need not more than "
82 +toString(getParameterDimension())+" parameters.");
83// LOG(1, "INFO: Setting new SaturationPotential params: " << _params);
84
85
86 // offsets
87 if (paramsDim > all_energy_offset)
88 energy_offset = _params[all_energy_offset];
89
90 // Morse
91 {
92 parameters_t morse_params(morse.getParameters());
93 if (paramsDim > morse_spring_constant)
94 morse_params[PairPotential_Morse::spring_constant] = _params[morse_spring_constant];
95 if (paramsDim > morse_equilibrium_distance)
96 morse_params[PairPotential_Morse::equilibrium_distance] = _params[morse_equilibrium_distance];
97 if (paramsDim > morse_dissociation_energy)
98 morse_params[PairPotential_Morse::dissociation_energy] = _params[morse_dissociation_energy];
99 morse_params[PairPotential_Morse::energy_offset] = 0.;
100 morse.setParameters(morse_params);
101 }
102
103 // Angle
104 {
105 parameters_t angle_params(angle.getParameters());
106 if (paramsDim > angle_spring_constant)
107 angle_params[PairPotential_Angle::spring_constant] = _params[angle_spring_constant];
108 if (paramsDim > angle_equilibrium_distance)
109 angle_params[PairPotential_Angle::equilibrium_distance] = _params[angle_equilibrium_distance];
110 angle_params[PairPotential_Angle::energy_offset] = 0.;
111 angle.setParameters(angle_params);
112 }
113#ifndef NDEBUG
114 parameters_t check_params(getParameters());
115 check_params.resize(paramsDim); // truncate to same size
116 ASSERT( check_params == _params,
117 "SaturationPotential::setParameters() - failed, mismatch in to be set "
118 +toString(_params)+" and set "+toString(check_params)+" params.");
119#endif
120}
121
122SaturationPotential::parameters_t SaturationPotential::getParameters() const
123{
124 parameters_t params(getParameterDimension());
125 const parameters_t morse_params = morse.getParameters();
126 const parameters_t angle_params = angle.getParameters();
127
128 params[all_energy_offset] = energy_offset;
129
130 params[morse_spring_constant] = morse_params[PairPotential_Morse::spring_constant];
131 params[morse_equilibrium_distance] = morse_params[PairPotential_Morse::equilibrium_distance];
132 params[morse_dissociation_energy] = morse_params[PairPotential_Morse::dissociation_energy];
133
134 params[angle_spring_constant] = angle_params[PairPotential_Angle::spring_constant];
135 params[angle_equilibrium_distance] = angle_params[PairPotential_Angle::equilibrium_distance];
136 return params;
137}
138
139SaturationPotential::results_t
140SaturationPotential::operator()(
141 const arguments_t &arguments
142 ) const
143{
144 double result = 0.;
145 for(arguments_t::const_iterator argiter = arguments.begin();
146 argiter != arguments.end();
147 ++argiter) {
148 const argument_t &r_ij = *argiter;
149 arguments_t args(1, r_ij);
150 if ((r_ij.indices.first == 0)) { // || (r_ij.indices.second == 0)) {
151 result += morse(args)[0];
152 std::vector<arguments_t> triples = triplefunction(r_ij, saturation_cutoff);
153 for (std::vector<arguments_t>::const_iterator iter = triples.begin();
154 iter != triples.end(); ++iter) {
155 ASSERT( iter->size() == 2,
156 "ManyBodyPotential_Tersoff::function_derivative_c() - the triples result must contain exactly two distances.");
157 const argument_t &r_ik = (*iter)[0];
158 const argument_t &r_jk = (*iter)[1];
159 arguments_t args;
160 args.push_back(r_ij);
161 args.push_back(r_ik);
162 args.push_back(r_jk);
163 result += .5 * angle(args)[0];
164 }
165 }
166 }
167 return std::vector<result_t>(1, energy_offset + result);
168}
169
170SaturationPotential::derivative_components_t
171SaturationPotential::derivative(
172 const arguments_t &arguments
173 ) const
174{
175 ASSERT( 0,
176 "SaturationPotential::operator() - not implemented.");
177 derivative_components_t result;
178 return result;
179}
180
181SaturationPotential::results_t
182SaturationPotential::parameter_derivative(
183 const arguments_t &arguments,
184 const size_t index
185 ) const
186{
187 double result = 0.;
188 for(arguments_t::const_iterator argiter = arguments.begin();
189 argiter != arguments.end();
190 ++argiter) {
191 const argument_t &r_ij = *argiter;
192 arguments_t args(1, r_ij);
193 if ((r_ij.indices.first == 0)) { // || (r_ij.indices.second == 0)) {
194 switch (index) {
195 case morse_spring_constant:
196 {
197 result += morse.parameter_derivative(args, PairPotential_Morse::spring_constant)[0];
198 break;
199 }
200 case morse_equilibrium_distance:
201 {
202 result += morse.parameter_derivative(args, PairPotential_Morse::equilibrium_distance)[0];
203 break;
204 }
205 case morse_dissociation_energy:
206 {
207 result += morse.parameter_derivative(args, PairPotential_Morse::dissociation_energy)[0];
208 break;
209 }
210 default:
211 {
212 std::vector<arguments_t> triples = triplefunction(r_ij, saturation_cutoff);
213 for (std::vector<arguments_t>::const_iterator iter = triples.begin();
214 iter != triples.end(); ++iter) {
215 ASSERT( iter->size() == 2,
216 "ManyBodyPotential_Tersoff::function_derivative_c() - the triples result must contain exactly two distances.");
217 const argument_t &r_ik = (*iter)[0];
218 const argument_t &r_jk = (*iter)[1];
219 arguments_t args;
220 args.push_back(r_ij);
221 args.push_back(r_ik);
222 args.push_back(r_jk);
223 switch (index) {
224 case angle_spring_constant:
225 {
226 result += .5*angle.parameter_derivative(args, PairPotential_Angle::spring_constant)[0];
227 break;
228 }
229 case angle_equilibrium_distance:
230 {
231 result += .5*angle.parameter_derivative(args, PairPotential_Angle::equilibrium_distance)[0];
232 break;
233 }
234 default:
235 break;
236 }
237 }
238 }
239 }
240 }
241 }
242 if (index == all_energy_offset)
243 result = 1.;
244 return SaturationPotential::results_t(1, result);
245}
Note: See TracBrowser for help on using the repository browser.