1 |
gezelter |
507 |
/* |
2 |
gezelter |
246 |
* 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. Acknowledgement of the program authors must be made in any |
10 |
|
|
* publication of scientific results based in part on use of the |
11 |
|
|
* program. An acceptable form of acknowledgement is citation of |
12 |
|
|
* the article in which the program was described (Matthew |
13 |
|
|
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
|
|
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
|
|
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
|
|
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
|
|
* |
18 |
|
|
* 2. Redistributions of source code must retain the above copyright |
19 |
|
|
* notice, this list of conditions and the following disclaimer. |
20 |
|
|
* |
21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
23 |
|
|
* documentation and/or other materials provided with the |
24 |
|
|
* distribution. |
25 |
|
|
* |
26 |
|
|
* This software is provided "AS IS," without a warranty of any |
27 |
|
|
* kind. All express or implied conditions, representations and |
28 |
|
|
* warranties, including any implied warranty of merchantability, |
29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
31 |
|
|
* be liable for any damages suffered by licensee as a result of |
32 |
|
|
* using, modifying or distributing the software or its |
33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
36 |
|
|
* damages, however caused and regardless of the theory of liability, |
37 |
|
|
* arising out of the use of or inability to use software, even if the |
38 |
|
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
|
* such damages. |
40 |
|
|
*/ |
41 |
|
|
|
42 |
gezelter |
507 |
/** |
43 |
|
|
* @file ForceField.cpp |
44 |
|
|
* @author tlin |
45 |
|
|
* @date 11/04/2004 |
46 |
|
|
* @time 22:51am |
47 |
|
|
* @version 1.0 |
48 |
|
|
*/ |
49 |
gezelter |
246 |
|
50 |
gezelter |
206 |
#include "UseTheForce/ForceField.hpp" |
51 |
gezelter |
246 |
#include "utils/simError.h" |
52 |
tim |
475 |
#include "UseTheForce/DarkSide/atype_interface.h" |
53 |
chuckv |
821 |
#include "UseTheForce/DarkSide/fForceOptions_interface.h" |
54 |
gezelter |
939 |
#include "UseTheForce/DarkSide/switcheroo_interface.h" |
55 |
gezelter |
246 |
namespace oopse { |
56 |
gezelter |
206 |
|
57 |
gezelter |
507 |
ForceField::ForceField() { |
58 |
gezelter |
246 |
char* tempPath; |
59 |
|
|
tempPath = getenv("FORCE_PARAM_PATH"); |
60 |
gezelter |
206 |
|
61 |
gezelter |
246 |
if (tempPath == NULL) { |
62 |
gezelter |
507 |
//convert a macro from compiler to a string in c++ |
63 |
|
|
STR_DEFINE(ffPath_, FRC_PATH ); |
64 |
gezelter |
246 |
} else { |
65 |
gezelter |
507 |
ffPath_ = tempPath; |
66 |
gezelter |
246 |
} |
67 |
gezelter |
507 |
} |
68 |
gezelter |
206 |
|
69 |
tim |
475 |
|
70 |
gezelter |
507 |
ForceField::~ForceField() { |
71 |
tim |
475 |
deleteAtypes(); |
72 |
gezelter |
939 |
deleteSwitch(); |
73 |
gezelter |
507 |
} |
74 |
tim |
475 |
|
75 |
gezelter |
507 |
AtomType* ForceField::getAtomType(const std::string &at) { |
76 |
gezelter |
246 |
std::vector<std::string> keys; |
77 |
|
|
keys.push_back(at); |
78 |
|
|
return atomTypeCont_.find(keys); |
79 |
gezelter |
507 |
} |
80 |
gezelter |
206 |
|
81 |
gezelter |
507 |
BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { |
82 |
gezelter |
246 |
std::vector<std::string> keys; |
83 |
|
|
keys.push_back(at1); |
84 |
|
|
keys.push_back(at2); |
85 |
gezelter |
206 |
|
86 |
gezelter |
246 |
//try exact match first |
87 |
|
|
BondType* bondType = bondTypeCont_.find(keys); |
88 |
|
|
if (bondType) { |
89 |
gezelter |
507 |
return bondType; |
90 |
gezelter |
246 |
} else { |
91 |
gezelter |
507 |
//if no exact match found, try wild card match |
92 |
|
|
return bondTypeCont_.find(keys, wildCardAtomTypeName_); |
93 |
gezelter |
246 |
} |
94 |
gezelter |
206 |
|
95 |
gezelter |
507 |
} |
96 |
gezelter |
206 |
|
97 |
gezelter |
507 |
BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, |
98 |
|
|
const std::string &at3) { |
99 |
gezelter |
246 |
std::vector<std::string> keys; |
100 |
|
|
keys.push_back(at1); |
101 |
|
|
keys.push_back(at2); |
102 |
|
|
keys.push_back(at3); |
103 |
gezelter |
206 |
|
104 |
gezelter |
246 |
//try exact match first |
105 |
|
|
BendType* bendType = bendTypeCont_.find(keys); |
106 |
|
|
if (bendType) { |
107 |
gezelter |
507 |
return bendType; |
108 |
gezelter |
246 |
} else { |
109 |
gezelter |
507 |
//if no exact match found, try wild card match |
110 |
|
|
return bendTypeCont_.find(keys, wildCardAtomTypeName_); |
111 |
gezelter |
246 |
} |
112 |
gezelter |
507 |
} |
113 |
gezelter |
206 |
|
114 |
gezelter |
507 |
TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, |
115 |
|
|
const std::string &at3, const std::string &at4) { |
116 |
gezelter |
246 |
std::vector<std::string> keys; |
117 |
|
|
keys.push_back(at1); |
118 |
|
|
keys.push_back(at2); |
119 |
|
|
keys.push_back(at3); |
120 |
|
|
keys.push_back(at4); |
121 |
gezelter |
206 |
|
122 |
gezelter |
246 |
TorsionType* torsionType = torsionTypeCont_.find(keys); |
123 |
|
|
if (torsionType) { |
124 |
gezelter |
507 |
return torsionType; |
125 |
gezelter |
246 |
} else { |
126 |
gezelter |
507 |
//if no exact match found, try wild card match |
127 |
|
|
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
128 |
gezelter |
246 |
} |
129 |
gezelter |
206 |
|
130 |
gezelter |
246 |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
131 |
gezelter |
206 |
|
132 |
gezelter |
507 |
} |
133 |
gezelter |
206 |
|
134 |
gezelter |
507 |
BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ |
135 |
gezelter |
246 |
std::vector<std::string> keys; |
136 |
|
|
keys.push_back(at1); |
137 |
|
|
keys.push_back(at2); |
138 |
|
|
return bondTypeCont_.find(keys); |
139 |
gezelter |
507 |
} |
140 |
gezelter |
206 |
|
141 |
gezelter |
507 |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
142 |
|
|
const std::string &at3){ |
143 |
gezelter |
246 |
std::vector<std::string> keys; |
144 |
|
|
keys.push_back(at1); |
145 |
|
|
keys.push_back(at2); |
146 |
|
|
keys.push_back(at3); |
147 |
|
|
return bendTypeCont_.find(keys); |
148 |
gezelter |
507 |
} |
149 |
gezelter |
206 |
|
150 |
gezelter |
507 |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
151 |
|
|
const std::string &at3, const std::string &at4){ |
152 |
gezelter |
246 |
std::vector<std::string> keys; |
153 |
|
|
keys.push_back(at1); |
154 |
|
|
keys.push_back(at2); |
155 |
|
|
keys.push_back(at3); |
156 |
|
|
keys.push_back(at4); |
157 |
|
|
return torsionTypeCont_.find(keys); |
158 |
gezelter |
507 |
} |
159 |
|
|
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
160 |
gezelter |
246 |
std::vector<std::string> keys; |
161 |
|
|
keys.push_back(at); |
162 |
|
|
return atomTypeCont_.add(keys, atomType); |
163 |
gezelter |
507 |
} |
164 |
gezelter |
206 |
|
165 |
gezelter |
507 |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
166 |
gezelter |
246 |
std::vector<std::string> keys; |
167 |
|
|
keys.push_back(at1); |
168 |
|
|
keys.push_back(at2); |
169 |
|
|
return bondTypeCont_.add(keys, bondType); |
170 |
gezelter |
206 |
|
171 |
gezelter |
507 |
} |
172 |
gezelter |
206 |
|
173 |
gezelter |
507 |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
174 |
|
|
const std::string &at3, BendType* bendType) { |
175 |
gezelter |
246 |
std::vector<std::string> keys; |
176 |
|
|
keys.push_back(at1); |
177 |
|
|
keys.push_back(at2); |
178 |
|
|
keys.push_back(at3); |
179 |
|
|
return bendTypeCont_.add(keys, bendType); |
180 |
gezelter |
507 |
} |
181 |
gezelter |
206 |
|
182 |
gezelter |
507 |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
183 |
|
|
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
184 |
gezelter |
246 |
std::vector<std::string> keys; |
185 |
|
|
keys.push_back(at1); |
186 |
|
|
keys.push_back(at2); |
187 |
|
|
keys.push_back(at3); |
188 |
|
|
keys.push_back(at4); |
189 |
|
|
return torsionTypeCont_.add(keys, torsionType); |
190 |
gezelter |
507 |
} |
191 |
gezelter |
206 |
|
192 |
tim |
963 |
RealType ForceField::getRcutFromAtomType(AtomType* at) { |
193 |
gezelter |
246 |
/**@todo */ |
194 |
|
|
GenericData* data; |
195 |
tim |
963 |
RealType rcut = 0.0; |
196 |
gezelter |
206 |
|
197 |
gezelter |
246 |
if (at->isLennardJones()) { |
198 |
gezelter |
507 |
data = at->getPropertyByName("LennardJones"); |
199 |
|
|
if (data != NULL) { |
200 |
|
|
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
201 |
gezelter |
206 |
|
202 |
gezelter |
507 |
if (ljData != NULL) { |
203 |
|
|
LJParam ljParam = ljData->getData(); |
204 |
gezelter |
206 |
|
205 |
gezelter |
507 |
//by default use 2.5*sigma as cutoff radius |
206 |
|
|
rcut = 2.5 * ljParam.sigma; |
207 |
gezelter |
246 |
|
208 |
gezelter |
507 |
} else { |
209 |
|
|
sprintf( painCave.errMsg, |
210 |
|
|
"Can not cast GenericData to LJParam\n"); |
211 |
|
|
painCave.severity = OOPSE_ERROR; |
212 |
|
|
painCave.isFatal = 1; |
213 |
|
|
simError(); |
214 |
|
|
} |
215 |
|
|
} else { |
216 |
|
|
sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); |
217 |
|
|
painCave.severity = OOPSE_ERROR; |
218 |
|
|
painCave.isFatal = 1; |
219 |
|
|
simError(); |
220 |
|
|
} |
221 |
gezelter |
246 |
} |
222 |
gezelter |
206 |
|
223 |
gezelter |
246 |
return rcut; |
224 |
gezelter |
507 |
} |
225 |
gezelter |
206 |
|
226 |
gezelter |
246 |
|
227 |
gezelter |
507 |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
228 |
gezelter |
246 |
std::string forceFieldFilename(filename); |
229 |
|
|
ifstrstream* ffStream = new ifstrstream(); |
230 |
|
|
|
231 |
|
|
//try to open the force filed file in current directory first |
232 |
|
|
ffStream->open(forceFieldFilename.c_str()); |
233 |
|
|
if(!ffStream->is_open()){ |
234 |
|
|
|
235 |
gezelter |
507 |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
236 |
|
|
ffStream->open( forceFieldFilename.c_str() ); |
237 |
gezelter |
246 |
|
238 |
gezelter |
507 |
//if current directory does not contain the force field file, |
239 |
|
|
//try to open it in the path |
240 |
|
|
if(!ffStream->is_open()){ |
241 |
gezelter |
246 |
|
242 |
gezelter |
507 |
sprintf( painCave.errMsg, |
243 |
|
|
"Error opening the force field parameter file:\n" |
244 |
|
|
"\t%s\n" |
245 |
|
|
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
246 |
|
|
"variable?\n", |
247 |
|
|
forceFieldFilename.c_str() ); |
248 |
|
|
painCave.severity = OOPSE_ERROR; |
249 |
|
|
painCave.isFatal = 1; |
250 |
|
|
simError(); |
251 |
|
|
} |
252 |
gezelter |
246 |
} |
253 |
|
|
|
254 |
|
|
return ffStream; |
255 |
|
|
|
256 |
gezelter |
507 |
} |
257 |
gezelter |
246 |
|
258 |
chuckv |
821 |
void ForceField::setFortranForceOptions(){ |
259 |
|
|
ForceOptions theseFortranOptions; |
260 |
|
|
forceFieldOptions_.makeFortranOptions(theseFortranOptions); |
261 |
|
|
setfForceOptions(&theseFortranOptions); |
262 |
|
|
} |
263 |
gezelter |
246 |
} //end namespace oopse |