ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/Morse.cpp
Revision: 1554
Committed: Sat Apr 30 02:54:02 2011 UTC (14 years ago) by gezelter
File size: 8877 byte(s)
Log Message:
For efficiency, pointers instead of objects will be passed during main
force loop. 


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 shiftedPot_(false), shiftedFrc_(false) {}
56
57 void Morse::initialize() {
58
59 stringToEnumMap_["shiftedMorse"] = shiftedMorse;
60 stringToEnumMap_["repulsiveMorse"] = repulsiveMorse;
61
62 ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
63 ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
64 NonBondedInteractionType* nbt;
65
66 for (nbt = nbiTypes->beginType(j); nbt != NULL;
67 nbt = nbiTypes->nextType(j)) {
68
69 if (nbt->isMorse()) {
70
71 pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
72
73 GenericData* data = nbt->getPropertyByName("Morse");
74 if (data == NULL) {
75 sprintf( painCave.errMsg, "Morse::initialize could not find\n"
76 "\tMorse parameters for %s - %s interaction.\n",
77 atypes.first->getName().c_str(),
78 atypes.second->getName().c_str());
79 painCave.severity = OPENMD_ERROR;
80 painCave.isFatal = 1;
81 simError();
82 }
83
84 MorseData* morseData = dynamic_cast<MorseData*>(data);
85 if (morseData == NULL) {
86 sprintf( painCave.errMsg,
87 "Morse::initialize could not convert GenericData to\n"
88 "\tMorseData for %s - %s interaction.\n",
89 atypes.first->getName().c_str(),
90 atypes.second->getName().c_str());
91 painCave.severity = OPENMD_ERROR;
92 painCave.isFatal = 1;
93 simError();
94 }
95
96 MorseParam morseParam = morseData->getData();
97
98 RealType De = morseParam.De;
99 RealType Re = morseParam.Re;
100 RealType beta = morseParam.beta;
101 string interactionType = morseParam.interactionType;
102
103 toUpper(interactionType);
104 map<string, MorseInteractionType>::iterator i;
105 i = stringToEnumMap_.find(interactionType);
106 if (i != stringToEnumMap_.end()) {
107 addExplicitInteraction(atypes.first, atypes.second,
108 De, Re, beta, i->second );
109 } else {
110 sprintf( painCave.errMsg,
111 "Morse::initialize found unknown Morse interaction type\n"
112 "\t(%s) for %s - %s interaction.\n",
113 morseParam.interactionType.c_str(),
114 atypes.first->getName().c_str(),
115 atypes.second->getName().c_str());
116 painCave.severity = OPENMD_ERROR;
117 painCave.isFatal = 1;
118 simError();
119 }
120 }
121 }
122 initialized_ = true;
123 }
124
125 void Morse::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
126 RealType De, RealType Re, RealType beta,
127 MorseInteractionType mit) {
128
129 MorseInteractionData mixer;
130 mixer.De = De;
131 mixer.Re = Re;
132 mixer.beta = beta;
133 mixer.interactionType = mit;
134
135 pair<AtomType*, AtomType*> key1, key2;
136 key1 = make_pair(atype1, atype2);
137 key2 = make_pair(atype2, atype1);
138
139 MixingMap[key1] = mixer;
140 if (key2 != key1) {
141 MixingMap[key2] = mixer;
142 }
143 }
144
145 void Morse::calcForce(InteractionData &idat) {
146
147 if (!initialized_) initialize();
148
149 map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it;
150 it = MixingMap.find( *(idat.atypes) );
151 if (it != MixingMap.end()) {
152 MorseInteractionData mixer = (*it).second;
153
154 RealType myPot = 0.0;
155 RealType myPotC = 0.0;
156 RealType myDeriv = 0.0;
157 RealType myDerivC = 0.0;
158
159 RealType De = mixer.De;
160 RealType Re = mixer.Re;
161 RealType beta = mixer.beta;
162 MorseInteractionType interactionType = mixer.interactionType;
163
164 // V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2)
165
166 RealType expt = -beta*( *(idat.rij) - Re);
167 RealType expfnc = exp(expt);
168 RealType expfnc2 = expfnc*expfnc;
169
170 RealType exptC = 0.0;
171 RealType expfncC = 0.0;
172 RealType expfnc2C = 0.0;
173
174 if (Morse::shiftedPot_ || Morse::shiftedFrc_) {
175 exptC = -beta*( *(idat.rcut) - Re);
176 expfncC = exp(exptC);
177 expfnc2C = expfncC*expfncC;
178 }
179
180
181 switch(interactionType) {
182 case shiftedMorse : {
183
184 myPot = De * (expfnc2 - 2.0 * expfnc);
185 myDeriv = 2.0 * De * beta * (expfnc - expfnc2);
186
187 if (Morse::shiftedPot_) {
188 myPotC = De * (expfnc2C - 2.0 * expfncC);
189 myDerivC = 0.0;
190 } else if (Morse::shiftedFrc_) {
191 myPotC = De * (expfnc2C - 2.0 * expfncC);
192 myDerivC = 2.0 * De * beta * (expfnc2C - expfnc2C);
193 myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut) );
194 } else {
195 myPotC = 0.0;
196 myDerivC = 0.0;
197 }
198
199 break;
200 }
201 case repulsiveMorse : {
202
203 myPot = De * expfnc2;
204 myDeriv = -2.0 * De * beta * expfnc2;
205
206 if (Morse::shiftedPot_) {
207 myPotC = De * expfnc2C;
208 myDerivC = 0.0;
209 } else if (Morse::shiftedFrc_) {
210 myPotC = De * expfnc2C;
211 myDerivC = -2.0 * De * beta * expfnc2C;
212 myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut));
213 } else {
214 myPotC = 0.0;
215 myDerivC = 0.0;
216 }
217
218 break;
219 }
220 }
221
222 RealType pot_temp = *(idat.vdwMult) * (myPot - myPotC);
223 *(idat.vpair) += pot_temp;
224
225 RealType dudr = *(idat.sw) * *(idat.vdwMult) * (myDeriv - myDerivC);
226
227 idat.pot[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
228 *(idat.f1) = *(idat.d) * dudr / *(idat.rij);
229 }
230 return;
231
232 }
233
234 RealType Morse::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
235 if (!initialized_) initialize();
236 map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it;
237 it = MixingMap.find(atypes);
238 if (it == MixingMap.end())
239 return 0.0;
240 else {
241 MorseInteractionData mixer = (*it).second;
242
243 RealType Re = mixer.Re;
244 RealType beta = mixer.beta;
245 // This value of the r corresponds to an energy about 1.48% of
246 // the energy at the bottom of the Morse well. For comparison, the
247 // Lennard-Jones function is about 1.63% of it's minimum value at
248 // a distance of 2.5 sigma.
249 return (4.9 + beta * Re) / beta;
250 }
251 }
252 }
253

Properties

Name Value
svn:eol-style native