ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/Morse.cpp
Revision: 1502
Committed: Sat Oct 2 19:53:32 2010 UTC (14 years, 7 months ago) by gezelter
File size: 7805 byte(s)
Log Message:
Many changes, and we're not quite done with this phase yet.

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 RealType myPot = 0.0;
150 RealType myPotC = 0.0;
151 RealType myDeriv = 0.0;
152 RealType myDerivC = 0.0;
153
154 pair<AtomType*, AtomType*> key = make_pair(idat.atype1, idat.atype2);
155 MorseInteractionData mixer = MixingMap[key];
156
157 RealType De = mixer.De;
158 RealType Re = mixer.Re;
159 RealType beta = mixer.beta;
160 MorseInteractionType interactionType = mixer.interactionType;
161
162 // V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2)
163
164 RealType expt = -beta*(idat.rij - Re);
165 RealType expfnc = exp(expt);
166 RealType expfnc2 = expfnc*expfnc;
167
168 RealType exptC = 0.0;
169 RealType expfncC = 0.0;
170 RealType expfnc2C = 0.0;
171
172 if (Morse::shiftedPot_ || Morse::shiftedFrc_) {
173 exptC = -beta*(idat.rcut - Re);
174 expfncC = exp(exptC);
175 expfnc2C = expfncC*expfncC;
176 }
177
178
179 switch(interactionType) {
180 case shiftedMorse : {
181
182 myPot = De * (expfnc2 - 2.0 * expfnc);
183 myDeriv = 2.0 * De * beta * (expfnc - expfnc2);
184
185 if (Morse::shiftedPot_) {
186 myPotC = De * (expfnc2C - 2.0 * expfncC);
187 myDerivC = 0.0;
188 } else if (Morse::shiftedFrc_) {
189 myPotC = De * (expfnc2C - 2.0 * expfncC);
190 myDerivC = 2.0 * De * beta * (expfnc2C - expfnc2C);
191 myPotC += myDerivC * (idat.rij - idat.rcut);
192 } else {
193 myPotC = 0.0;
194 myDerivC = 0.0;
195 }
196
197 break;
198 }
199 case repulsiveMorse : {
200
201 myPot = De * expfnc2;
202 myDeriv = -2.0 * De * beta * expfnc2;
203
204 if (Morse::shiftedPot_) {
205 myPotC = De * expfnc2C;
206 myDerivC = 0.0;
207 } else if (Morse::shiftedFrc_) {
208 myPotC = De * expfnc2C;
209 myDerivC = -2.0 * De * beta * expfnc2C;
210 myPotC += myDerivC * (idat.rij - idat.rcut);
211 } else {
212 myPotC = 0.0;
213 myDerivC = 0.0;
214 }
215
216 break;
217 }
218 }
219
220 RealType pot_temp = idat.vdwMult * (myPot - myPotC);
221 idat.vpair += pot_temp;
222
223 RealType dudr = idat.sw * idat.vdwMult * (myDeriv - myDerivC);
224
225 idat.pot += idat.sw * pot_temp;
226 idat.f1 = idat.d * dudr / idat.rij;
227
228 return;
229
230 }
231
232 }
233

Properties

Name Value
svn:eol-style native