ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/Morse.cpp
Revision: 1505
Committed: Sun Oct 3 22:18:59 2010 UTC (14 years, 7 months ago) by gezelter
File size: 8922 byte(s)
Log Message:
Less busted than it was on last check-in, but still won't completely
build.


File Contents

# User Rev Content
1 gezelter 1501 /*
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 gezelter 1502 Morse::Morse() : name_("Morse"), initialized_(false), forceField_(NULL),
55     shiftedPot_(false), shiftedFrc_(false) {}
56 gezelter 1501
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 gezelter 1502 void Morse::calcForce(InteractionData idat) {
146 gezelter 1501
147     if (!initialized_) initialize();
148    
149 gezelter 1505 pair<AtomType*, AtomType*> key = make_pair(idat.atype1, idat.atype2);
150     map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it;
151     it = MixingMap.find(key);
152     if (it != MixingMap.end()) {
153     MorseInteractionData mixer = (*it).second;
154    
155     RealType myPot = 0.0;
156     RealType myPotC = 0.0;
157     RealType myDeriv = 0.0;
158     RealType myDerivC = 0.0;
159    
160     RealType De = mixer.De;
161     RealType Re = mixer.Re;
162     RealType beta = mixer.beta;
163     MorseInteractionType interactionType = mixer.interactionType;
164    
165     // V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2)
166    
167     RealType expt = -beta*(idat.rij - Re);
168     RealType expfnc = exp(expt);
169     RealType expfnc2 = expfnc*expfnc;
170    
171     RealType exptC = 0.0;
172     RealType expfncC = 0.0;
173     RealType expfnc2C = 0.0;
174    
175     if (Morse::shiftedPot_ || Morse::shiftedFrc_) {
176     exptC = -beta*(idat.rcut - Re);
177     expfncC = exp(exptC);
178     expfnc2C = expfncC*expfncC;
179 gezelter 1501 }
180 gezelter 1505
181    
182     switch(interactionType) {
183     case shiftedMorse : {
184    
185     myPot = De * (expfnc2 - 2.0 * expfnc);
186     myDeriv = 2.0 * De * beta * (expfnc - expfnc2);
187    
188     if (Morse::shiftedPot_) {
189     myPotC = De * (expfnc2C - 2.0 * expfncC);
190     myDerivC = 0.0;
191     } else if (Morse::shiftedFrc_) {
192     myPotC = De * (expfnc2C - 2.0 * expfncC);
193     myDerivC = 2.0 * De * beta * (expfnc2C - expfnc2C);
194     myPotC += myDerivC * (idat.rij - idat.rcut);
195     } else {
196     myPotC = 0.0;
197     myDerivC = 0.0;
198     }
199    
200     break;
201 gezelter 1501 }
202 gezelter 1505 case repulsiveMorse : {
203    
204     myPot = De * expfnc2;
205     myDeriv = -2.0 * De * beta * expfnc2;
206    
207     if (Morse::shiftedPot_) {
208     myPotC = De * expfnc2C;
209     myDerivC = 0.0;
210     } else if (Morse::shiftedFrc_) {
211     myPotC = De * expfnc2C;
212     myDerivC = -2.0 * De * beta * expfnc2C;
213     myPotC += myDerivC * (idat.rij - idat.rcut);
214     } else {
215     myPotC = 0.0;
216     myDerivC = 0.0;
217     }
218    
219     break;
220     }
221     }
222    
223     RealType pot_temp = idat.vdwMult * (myPot - myPotC);
224     idat.vpair += pot_temp;
225    
226     RealType dudr = idat.sw * idat.vdwMult * (myDeriv - myDerivC);
227    
228     idat.pot += idat.sw * pot_temp;
229     idat.f1 = idat.d * dudr / idat.rij;
230 gezelter 1501 }
231 gezelter 1505 return;
232 gezelter 1501
233 gezelter 1505 }
234    
235     RealType Morse::getSuggestedCutoffRadius(AtomType* at1, AtomType* at2) {
236     if (!initialized_) initialize();
237     pair<AtomType*, AtomType*> key = make_pair(at1, at2);
238     map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it;
239     it = MixingMap.find(key);
240     if (it == MixingMap.end())
241     return 0.0;
242     else {
243     MorseInteractionData mixer = (*it).second;
244 gezelter 1501
245 gezelter 1505 RealType Re = mixer.Re;
246     RealType beta = mixer.beta;
247     // This value of the r corresponds to an energy about 1.48% of
248     // the energy at the bottom of the Morse well. For comparison, the
249     // Lennard-Jones function is about 1.63% of it's minimum value at
250     // a distance of 2.5 sigma.
251     return (4.9 + beta * Re) / beta;
252     }
253 gezelter 1501 }
254     }
255    

Properties

Name Value
svn:eol-style native