ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/Morse.cpp
Revision: 1583
Committed: Thu Jun 16 22:00:08 2011 UTC (13 years, 10 months ago) by gezelter
File size: 8807 byte(s)
Log Message:
Bug squashing

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
28 * arising out of the use of or inability to use software, even if the
29 * University of Notre Dame has been advised of the possibility of
30 * such damages.
31 *
32 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33 * research, please cite the appropriate papers when you publish your
34 * work. Good starting points are:
35 *
36 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 * [4] Vardeman & Gezelter, in progress (2009).
40 */
41
42 #include <stdio.h>
43 #include <string.h>
44
45 #include <cmath>
46 #include "nonbonded/Morse.hpp"
47 #include "utils/simError.h"
48 #include "types/NonBondedInteractionType.hpp"
49
50 using namespace std;
51
52 namespace OpenMD {
53
54 Morse::Morse() : name_("Morse"), initialized_(false), forceField_(NULL) {}
55
56 void Morse::initialize() {
57
58 stringToEnumMap_["shiftedMorse"] = shiftedMorse;
59 stringToEnumMap_["repulsiveMorse"] = repulsiveMorse;
60
61 ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
62 ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
63 NonBondedInteractionType* nbt;
64
65 for (nbt = nbiTypes->beginType(j); nbt != NULL;
66 nbt = nbiTypes->nextType(j)) {
67
68 if (nbt->isMorse()) {
69
70 pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
71
72 GenericData* data = nbt->getPropertyByName("Morse");
73 if (data == NULL) {
74 sprintf( painCave.errMsg, "Morse::initialize could not find\n"
75 "\tMorse parameters for %s - %s interaction.\n",
76 atypes.first->getName().c_str(),
77 atypes.second->getName().c_str());
78 painCave.severity = OPENMD_ERROR;
79 painCave.isFatal = 1;
80 simError();
81 }
82
83 MorseData* morseData = dynamic_cast<MorseData*>(data);
84 if (morseData == NULL) {
85 sprintf( painCave.errMsg,
86 "Morse::initialize could not convert GenericData to\n"
87 "\tMorseData for %s - %s interaction.\n",
88 atypes.first->getName().c_str(),
89 atypes.second->getName().c_str());
90 painCave.severity = OPENMD_ERROR;
91 painCave.isFatal = 1;
92 simError();
93 }
94
95 MorseParam morseParam = morseData->getData();
96
97 RealType De = morseParam.De;
98 RealType Re = morseParam.Re;
99 RealType beta = morseParam.beta;
100 string interactionType = morseParam.interactionType;
101
102 toUpper(interactionType);
103 map<string, MorseInteractionType>::iterator i;
104 i = stringToEnumMap_.find(interactionType);
105 if (i != stringToEnumMap_.end()) {
106 addExplicitInteraction(atypes.first, atypes.second,
107 De, Re, beta, i->second );
108 } else {
109 sprintf( painCave.errMsg,
110 "Morse::initialize found unknown Morse interaction type\n"
111 "\t(%s) for %s - %s interaction.\n",
112 morseParam.interactionType.c_str(),
113 atypes.first->getName().c_str(),
114 atypes.second->getName().c_str());
115 painCave.severity = OPENMD_ERROR;
116 painCave.isFatal = 1;
117 simError();
118 }
119 }
120 }
121 initialized_ = true;
122 }
123
124 void Morse::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
125 RealType De, RealType Re, RealType beta,
126 MorseInteractionType mit) {
127
128 MorseInteractionData mixer;
129 mixer.De = De;
130 mixer.Re = Re;
131 mixer.beta = beta;
132 mixer.interactionType = mit;
133
134 pair<AtomType*, AtomType*> key1, key2;
135 key1 = make_pair(atype1, atype2);
136 key2 = make_pair(atype2, atype1);
137
138 MixingMap[key1] = mixer;
139 if (key2 != key1) {
140 MixingMap[key2] = mixer;
141 }
142 }
143
144 void Morse::calcForce(InteractionData &idat) {
145
146 if (!initialized_) initialize();
147
148 map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it;
149 it = MixingMap.find( idat.atypes );
150 if (it != MixingMap.end()) {
151 MorseInteractionData mixer = (*it).second;
152
153 RealType myPot = 0.0;
154 RealType myPotC = 0.0;
155 RealType myDeriv = 0.0;
156 RealType myDerivC = 0.0;
157
158 RealType De = mixer.De;
159 RealType Re = mixer.Re;
160 RealType beta = mixer.beta;
161 MorseInteractionType interactionType = mixer.interactionType;
162
163 // V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2)
164
165 RealType expt = -beta*( *(idat.rij) - Re);
166 RealType expfnc = exp(expt);
167 RealType expfnc2 = expfnc*expfnc;
168
169 RealType exptC = 0.0;
170 RealType expfncC = 0.0;
171 RealType expfnc2C = 0.0;
172
173 if (idat.shiftedPot || idat.shiftedForce) {
174 exptC = -beta*( *(idat.rcut) - Re);
175 expfncC = exp(exptC);
176 expfnc2C = expfncC*expfncC;
177 }
178
179
180 switch(interactionType) {
181 case shiftedMorse : {
182
183 myPot = De * (expfnc2 - 2.0 * expfnc);
184 myDeriv = 2.0 * De * beta * (expfnc - expfnc2);
185
186 if (idat.shiftedPot) {
187 myPotC = De * (expfnc2C - 2.0 * expfncC);
188 myDerivC = 0.0;
189 } else if (idat.shiftedForce) {
190 myPotC = De * (expfnc2C - 2.0 * expfncC);
191 myDerivC = 2.0 * De * beta * (expfnc2C - expfnc2C);
192 myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut) );
193 } else {
194 myPotC = 0.0;
195 myDerivC = 0.0;
196 }
197
198 break;
199 }
200 case repulsiveMorse : {
201
202 myPot = De * expfnc2;
203 myDeriv = -2.0 * De * beta * expfnc2;
204
205 if (idat.shiftedPot) {
206 myPotC = De * expfnc2C;
207 myDerivC = 0.0;
208 } else if (idat.shiftedForce) {
209 myPotC = De * expfnc2C;
210 myDerivC = -2.0 * De * beta * expfnc2C;
211 myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut));
212 } else {
213 myPotC = 0.0;
214 myDerivC = 0.0;
215 }
216
217 break;
218 }
219 }
220
221 RealType pot_temp = *(idat.vdwMult) * (myPot - myPotC);
222 *(idat.vpair) += pot_temp;
223
224 RealType dudr = *(idat.sw) * *(idat.vdwMult) * (myDeriv - myDerivC);
225
226 (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
227 *(idat.f1) = *(idat.d) * dudr / *(idat.rij);
228 }
229 return;
230
231 }
232
233 RealType Morse::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
234 if (!initialized_) initialize();
235 map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it;
236 it = MixingMap.find(atypes);
237 if (it == MixingMap.end())
238 return 0.0;
239 else {
240 MorseInteractionData mixer = (*it).second;
241
242 RealType Re = mixer.Re;
243 RealType beta = mixer.beta;
244 // This value of the r corresponds to an energy about 1.48% of
245 // the energy at the bottom of the Morse well. For comparison, the
246 // Lennard-Jones function is about 1.63% of it's minimum value at
247 // a distance of 2.5 sigma.
248 return (4.9 + beta * Re) / beta;
249 }
250 }
251 }
252

Properties

Name Value
svn:eol-style native