source: src/Potentials/Specifics/PairPotential_Morse.cpp@ ed2551

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

All Pair_.. and ManyBodyPotentials are now also derived from SerializablePotential.

  • added static ParameterNames, skipping "energy_offset" which should not go to file.
  • overrode operator<<() and ..>>() for SaturationPotential to print both potentials independently.
  • adapted LevMartest and all unit tests.
  • Property mode set to 100644
File size: 6.1 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 * PairPotential_Morse.cpp
26 *
27 * Created on: Oct 03, 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_Morse.hpp"
40
41#include <boost/assign/list_of.hpp> // for 'map_list_of()'
42#include <cmath>
43#include <string>
44
45#include "CodePatterns/Assert.hpp"
46
47#include "Potentials/helpers.hpp"
48
49// static definitions
50const PairPotential_Morse::ParameterNames_t
51PairPotential_Morse::ParameterNames =
52 boost::assign::list_of<std::string>
53 ("spring_constant")
54 ("equilibrium_distance")
55 ("dissociation_energy")
56 ("") //energy_offset
57 ;
58const std::string PairPotential_Morse::potential_token("morse");
59
60PairPotential_Morse::PairPotential_Morse(
61 const ParticleTypes_t &_ParticleTypes
62 ) :
63 SerializablePotential(_ParticleTypes),
64 params(parameters_t(MAXPARAMS, 0.))
65{}
66
67PairPotential_Morse::PairPotential_Morse(
68 const ParticleTypes_t &_ParticleTypes,
69 const double _spring_constant,
70 const double _equilibrium_distance,
71 const double _dissociation_energy,
72 const double _energy_offset) :
73 SerializablePotential(_ParticleTypes),
74 params(parameters_t(MAXPARAMS, 0.))
75{
76 params[spring_constant] = _spring_constant;
77 params[equilibrium_distance] = _equilibrium_distance;
78 params[dissociation_energy] = _dissociation_energy;
79 params[energy_offset] = _energy_offset;
80}
81
82void PairPotential_Morse::setParameters(const parameters_t &_params)
83{
84 const size_t paramsDim = _params.size();
85 ASSERT( paramsDim <= getParameterDimension(),
86 "PairPotential_Morse::setParameters() - we need not more than "
87 +toString(getParameterDimension())+" parameters.");
88 for(size_t i=0;i<paramsDim;++i)
89 params[i] = _params[i];
90
91#ifndef NDEBUG
92 parameters_t check_params(getParameters());
93 check_params.resize(paramsDim); // truncate to same size
94 ASSERT( check_params == _params,
95 "PairPotential_Morse::setParameters() - failed, mismatch in to be set "
96 +toString(_params)+" and set "+toString(check_params)+" params.");
97#endif
98}
99
100PairPotential_Morse::results_t
101PairPotential_Morse::operator()(
102 const arguments_t &arguments
103 ) const
104{
105 ASSERT( arguments.size() == 1,
106 "PairPotential_Morse::operator() - requires exactly one argument.");
107 const argument_t &r_ij = arguments[0];
108 // Maple: f(r,D,k,R,c) := D * (1 - exp(-k*(r-R)))^(2)+c
109 const result_t result =
110 params[dissociation_energy] * Helpers::pow( 1.
111 - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])),2)
112 + params[energy_offset];
113 return std::vector<result_t>(1, result);
114}
115
116PairPotential_Morse::derivative_components_t
117PairPotential_Morse::derivative(
118 const arguments_t &arguments
119 ) const
120{
121 ASSERT( arguments.size() == 1,
122 "PairPotential_Morse::operator() - requires exactly one argument.");
123 derivative_components_t result;
124 const argument_t &r_ij = arguments[0];
125 // Maple result: 2*D*(1-exp(-k*(r-R)))*k*exp(-k*(r-R))
126 result.push_back(
127 2. * params[dissociation_energy]
128 * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
129 * (- params[spring_constant]) * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]))
130 );
131 ASSERT( result.size() == 1,
132 "PairPotential_Morse::operator() - we did not create exactly one component.");
133 return result;
134}
135
136PairPotential_Morse::results_t
137PairPotential_Morse::parameter_derivative(
138 const arguments_t &arguments,
139 const size_t index
140 ) const
141{
142 ASSERT( arguments.size() == 1,
143 "PairPotential_Morse::parameter_derivative() - requires exactly one argument.");
144 const argument_t &r_ij = arguments[0];
145 switch (index) {
146 case spring_constant:
147 {
148 // Maple result: -2*D*(1-exp(-k*(r-R)))*(-r+R)*exp(-k*(r-R))
149 const result_t result =
150 - 2. * params[dissociation_energy]
151 * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
152 * (- r_ij.distance + params[equilibrium_distance])
153 * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]))
154 ;
155 return std::vector<result_t>(1, result);
156 break;
157 }
158 case equilibrium_distance:
159 {
160 // Maple result: -2*D*(1-exp(-k*(r-R)))*k*exp(-k*(r-R))
161 const result_t result =
162 - 2. * params[dissociation_energy]
163 * ( 1. - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])))
164 * params[spring_constant] * exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]))
165 ;
166 return std::vector<result_t>(1, result);
167 break;
168 }
169 case dissociation_energy:
170 {
171 // Maple result: (1-exp(-k*(r-R)))^2
172 const result_t result =
173 Helpers::pow(1.
174 - exp( - params[spring_constant] * ( r_ij.distance - params[equilibrium_distance])),2);
175 return std::vector<result_t>(1, result);
176 break;
177 }
178 case energy_offset:
179 {
180 // Maple result: 1
181 const result_t result = +1.;
182 return std::vector<result_t>(1, result);
183 break;
184 }
185 default:
186 break;
187 }
188 return std::vector<result_t>(1, 0.);
189}
Note: See TracBrowser for help on using the repository browser.