1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
39 |
|
* such damages. |
40 |
|
*/ |
41 |
|
|
42 |
< |
/** |
43 |
< |
* @file ForceField.cpp |
44 |
< |
* @author tlin |
45 |
< |
* @date 11/04/2004 |
46 |
< |
* @time 22:51am |
47 |
< |
* @version 1.0 |
48 |
< |
*/ |
42 |
> |
/** |
43 |
> |
* @file ForceField.cpp |
44 |
> |
* @author tlin |
45 |
> |
* @date 11/04/2004 |
46 |
> |
* @time 22:51am |
47 |
> |
* @version 1.0 |
48 |
> |
*/ |
49 |
|
|
50 |
|
#include "UseTheForce/ForceField.hpp" |
51 |
|
#include "utils/simError.h" |
52 |
+ |
#include "UseTheForce/DarkSide/atype_interface.h" |
53 |
+ |
#include "UseTheForce/DarkSide/fForceOptions_interface.h" |
54 |
+ |
#include "UseTheForce/DarkSide/switcheroo_interface.h" |
55 |
|
namespace oopse { |
56 |
|
|
57 |
< |
ForceField::ForceField() { |
57 |
> |
ForceField::ForceField() { |
58 |
|
char* tempPath; |
59 |
|
tempPath = getenv("FORCE_PARAM_PATH"); |
60 |
|
|
61 |
|
if (tempPath == NULL) { |
62 |
< |
//convert a macro from compiler to a string in c++ |
63 |
< |
STR_DEFINE(ffPath_, FRC_PATH ); |
62 |
> |
//convert a macro from compiler to a string in c++ |
63 |
> |
STR_DEFINE(ffPath_, FRC_PATH ); |
64 |
|
} else { |
65 |
< |
ffPath_ = tempPath; |
65 |
> |
ffPath_ = tempPath; |
66 |
|
} |
67 |
< |
} |
67 |
> |
} |
68 |
|
|
69 |
< |
AtomType* ForceField::getAtomType(const std::string &at) { |
69 |
> |
|
70 |
> |
ForceField::~ForceField() { |
71 |
> |
deleteAtypes(); |
72 |
> |
deleteSwitch(); |
73 |
> |
} |
74 |
> |
|
75 |
> |
AtomType* ForceField::getAtomType(const std::string &at) { |
76 |
|
std::vector<std::string> keys; |
77 |
|
keys.push_back(at); |
78 |
|
return atomTypeCont_.find(keys); |
79 |
< |
} |
79 |
> |
} |
80 |
|
|
81 |
< |
BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { |
81 |
> |
BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { |
82 |
|
std::vector<std::string> keys; |
83 |
|
keys.push_back(at1); |
84 |
|
keys.push_back(at2); |
86 |
|
//try exact match first |
87 |
|
BondType* bondType = bondTypeCont_.find(keys); |
88 |
|
if (bondType) { |
89 |
< |
return bondType; |
89 |
> |
return bondType; |
90 |
|
} else { |
91 |
< |
//if no exact match found, try wild card match |
92 |
< |
return bondTypeCont_.find(keys, wildCardAtomTypeName_); |
91 |
> |
//if no exact match found, try wild card match |
92 |
> |
return bondTypeCont_.find(keys, wildCardAtomTypeName_); |
93 |
|
} |
94 |
|
|
95 |
< |
} |
95 |
> |
} |
96 |
|
|
97 |
< |
BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, |
98 |
< |
const std::string &at3) { |
97 |
> |
BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, |
98 |
> |
const std::string &at3) { |
99 |
|
std::vector<std::string> keys; |
100 |
|
keys.push_back(at1); |
101 |
|
keys.push_back(at2); |
104 |
|
//try exact match first |
105 |
|
BendType* bendType = bendTypeCont_.find(keys); |
106 |
|
if (bendType) { |
107 |
< |
return bendType; |
107 |
> |
return bendType; |
108 |
|
} else { |
109 |
< |
//if no exact match found, try wild card match |
110 |
< |
return bendTypeCont_.find(keys, wildCardAtomTypeName_); |
109 |
> |
//if no exact match found, try wild card match |
110 |
> |
return bendTypeCont_.find(keys, wildCardAtomTypeName_); |
111 |
|
} |
112 |
< |
} |
112 |
> |
} |
113 |
|
|
114 |
< |
TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, |
115 |
< |
const std::string &at3, const std::string &at4) { |
114 |
> |
TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, |
115 |
> |
const std::string &at3, const std::string &at4) { |
116 |
|
std::vector<std::string> keys; |
117 |
|
keys.push_back(at1); |
118 |
|
keys.push_back(at2); |
121 |
|
|
122 |
|
TorsionType* torsionType = torsionTypeCont_.find(keys); |
123 |
|
if (torsionType) { |
124 |
< |
return torsionType; |
124 |
> |
return torsionType; |
125 |
|
} else { |
126 |
< |
//if no exact match found, try wild card match |
127 |
< |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
126 |
> |
//if no exact match found, try wild card match |
127 |
> |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
128 |
|
} |
129 |
|
|
130 |
|
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
131 |
|
|
132 |
< |
} |
132 |
> |
} |
133 |
|
|
134 |
< |
BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ |
134 |
> |
NonBondedInteractionType* ForceField::getNonBondedInteractionType(const std::string &at1, const std::string &at2) { |
135 |
|
std::vector<std::string> keys; |
136 |
|
keys.push_back(at1); |
137 |
|
keys.push_back(at2); |
138 |
+ |
|
139 |
+ |
//try exact match first |
140 |
+ |
NonBondedInteractionType* nbiType = nonBondedInteractionTypeCont_.find(keys); |
141 |
+ |
if (nbiType) { |
142 |
+ |
return nbiType; |
143 |
+ |
} else { |
144 |
+ |
//if no exact match found, try wild card match |
145 |
+ |
return nonBondedInteractionTypeCont_.find(keys, wildCardAtomTypeName_); |
146 |
+ |
} |
147 |
+ |
|
148 |
+ |
} |
149 |
+ |
|
150 |
+ |
BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ |
151 |
+ |
std::vector<std::string> keys; |
152 |
+ |
keys.push_back(at1); |
153 |
+ |
keys.push_back(at2); |
154 |
|
return bondTypeCont_.find(keys); |
155 |
< |
} |
155 |
> |
} |
156 |
|
|
157 |
< |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
158 |
< |
const std::string &at3){ |
157 |
> |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
158 |
> |
const std::string &at3){ |
159 |
|
std::vector<std::string> keys; |
160 |
|
keys.push_back(at1); |
161 |
|
keys.push_back(at2); |
162 |
|
keys.push_back(at3); |
163 |
|
return bendTypeCont_.find(keys); |
164 |
< |
} |
164 |
> |
} |
165 |
|
|
166 |
< |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
167 |
< |
const std::string &at3, const std::string &at4){ |
166 |
> |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
167 |
> |
const std::string &at3, const std::string &at4){ |
168 |
|
std::vector<std::string> keys; |
169 |
|
keys.push_back(at1); |
170 |
|
keys.push_back(at2); |
171 |
|
keys.push_back(at3); |
172 |
|
keys.push_back(at4); |
173 |
|
return torsionTypeCont_.find(keys); |
174 |
< |
} |
175 |
< |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
174 |
> |
} |
175 |
> |
|
176 |
> |
NonBondedInteractionType* ForceField::getExactNonBondedInteractionType(const std::string &at1, const std::string &at2){ |
177 |
|
std::vector<std::string> keys; |
178 |
+ |
keys.push_back(at1); |
179 |
+ |
keys.push_back(at2); |
180 |
+ |
return nonBondedInteractionTypeCont_.find(keys); |
181 |
+ |
} |
182 |
+ |
|
183 |
+ |
|
184 |
+ |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
185 |
+ |
std::vector<std::string> keys; |
186 |
|
keys.push_back(at); |
187 |
|
return atomTypeCont_.add(keys, atomType); |
188 |
< |
} |
188 |
> |
} |
189 |
|
|
190 |
< |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
190 |
> |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
191 |
|
std::vector<std::string> keys; |
192 |
|
keys.push_back(at1); |
193 |
|
keys.push_back(at2); |
194 |
|
return bondTypeCont_.add(keys, bondType); |
195 |
|
|
196 |
< |
} |
196 |
> |
} |
197 |
|
|
198 |
< |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
199 |
< |
const std::string &at3, BendType* bendType) { |
198 |
> |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
199 |
> |
const std::string &at3, BendType* bendType) { |
200 |
|
std::vector<std::string> keys; |
201 |
|
keys.push_back(at1); |
202 |
|
keys.push_back(at2); |
203 |
|
keys.push_back(at3); |
204 |
|
return bendTypeCont_.add(keys, bendType); |
205 |
< |
} |
205 |
> |
} |
206 |
|
|
207 |
< |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
208 |
< |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
207 |
> |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
208 |
> |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
209 |
|
std::vector<std::string> keys; |
210 |
|
keys.push_back(at1); |
211 |
|
keys.push_back(at2); |
212 |
|
keys.push_back(at3); |
213 |
|
keys.push_back(at4); |
214 |
|
return torsionTypeCont_.add(keys, torsionType); |
215 |
< |
} |
215 |
> |
} |
216 |
|
|
217 |
< |
double ForceField::getRcutFromAtomType(AtomType* at) { |
217 |
> |
bool ForceField::addNonBondedInteractionType(const std::string &at1, const std::string &at2, NonBondedInteractionType* nbiType) { |
218 |
> |
std::vector<std::string> keys; |
219 |
> |
keys.push_back(at1); |
220 |
> |
keys.push_back(at2); |
221 |
> |
return nonBondedInteractionTypeCont_.add(keys, nbiType); |
222 |
> |
|
223 |
> |
} |
224 |
> |
|
225 |
> |
RealType ForceField::getRcutFromAtomType(AtomType* at) { |
226 |
|
/**@todo */ |
227 |
|
GenericData* data; |
228 |
< |
double rcut = 0.0; |
228 |
> |
RealType rcut = 0.0; |
229 |
|
|
230 |
|
if (at->isLennardJones()) { |
231 |
< |
data = at->getPropertyByName("LennardJones"); |
232 |
< |
if (data != NULL) { |
233 |
< |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
231 |
> |
data = at->getPropertyByName("LennardJones"); |
232 |
> |
if (data != NULL) { |
233 |
> |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
234 |
|
|
235 |
< |
if (ljData != NULL) { |
236 |
< |
LJParam ljParam = ljData->getData(); |
235 |
> |
if (ljData != NULL) { |
236 |
> |
LJParam ljParam = ljData->getData(); |
237 |
|
|
238 |
< |
//by default use 2.5*sigma as cutoff radius |
239 |
< |
rcut = 2.5 * ljParam.sigma; |
238 |
> |
//by default use 2.5*sigma as cutoff radius |
239 |
> |
rcut = 2.5 * ljParam.sigma; |
240 |
|
|
241 |
< |
} else { |
242 |
< |
sprintf( painCave.errMsg, |
243 |
< |
"Can not cast GenericData to LJParam\n"); |
244 |
< |
painCave.severity = OOPSE_ERROR; |
245 |
< |
painCave.isFatal = 1; |
246 |
< |
simError(); |
247 |
< |
} |
248 |
< |
} else { |
249 |
< |
sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); |
250 |
< |
painCave.severity = OOPSE_ERROR; |
251 |
< |
painCave.isFatal = 1; |
252 |
< |
simError(); |
253 |
< |
} |
241 |
> |
} else { |
242 |
> |
sprintf( painCave.errMsg, |
243 |
> |
"Can not cast GenericData to LJParam\n"); |
244 |
> |
painCave.severity = OOPSE_ERROR; |
245 |
> |
painCave.isFatal = 1; |
246 |
> |
simError(); |
247 |
> |
} |
248 |
> |
} else { |
249 |
> |
sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); |
250 |
> |
painCave.severity = OOPSE_ERROR; |
251 |
> |
painCave.isFatal = 1; |
252 |
> |
simError(); |
253 |
> |
} |
254 |
|
} |
255 |
|
|
256 |
|
return rcut; |
257 |
< |
} |
257 |
> |
} |
258 |
|
|
259 |
|
|
260 |
< |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
260 |
> |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
261 |
|
std::string forceFieldFilename(filename); |
262 |
|
ifstrstream* ffStream = new ifstrstream(); |
263 |
|
|
265 |
|
ffStream->open(forceFieldFilename.c_str()); |
266 |
|
if(!ffStream->is_open()){ |
267 |
|
|
268 |
< |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
269 |
< |
ffStream->open( forceFieldFilename.c_str() ); |
268 |
> |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
269 |
> |
ffStream->open( forceFieldFilename.c_str() ); |
270 |
|
|
271 |
< |
//if current directory does not contain the force field file, |
272 |
< |
//try to open it in the path |
273 |
< |
if(!ffStream->is_open()){ |
271 |
> |
//if current directory does not contain the force field file, |
272 |
> |
//try to open it in the path |
273 |
> |
if(!ffStream->is_open()){ |
274 |
|
|
275 |
< |
sprintf( painCave.errMsg, |
276 |
< |
"Error opening the force field parameter file:\n" |
277 |
< |
"\t%s\n" |
278 |
< |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
279 |
< |
"variable?\n", |
280 |
< |
forceFieldFilename.c_str() ); |
281 |
< |
painCave.severity = OOPSE_ERROR; |
282 |
< |
painCave.isFatal = 1; |
283 |
< |
simError(); |
284 |
< |
} |
275 |
> |
sprintf( painCave.errMsg, |
276 |
> |
"Error opening the force field parameter file:\n" |
277 |
> |
"\t%s\n" |
278 |
> |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
279 |
> |
"variable?\n", |
280 |
> |
forceFieldFilename.c_str() ); |
281 |
> |
painCave.severity = OOPSE_ERROR; |
282 |
> |
painCave.isFatal = 1; |
283 |
> |
simError(); |
284 |
> |
} |
285 |
|
} |
286 |
|
|
287 |
|
return ffStream; |
288 |
|
|
289 |
< |
} |
289 |
> |
} |
290 |
|
|
291 |
+ |
void ForceField::setFortranForceOptions(){ |
292 |
+ |
ForceOptions theseFortranOptions; |
293 |
+ |
forceFieldOptions_.makeFortranOptions(theseFortranOptions); |
294 |
+ |
setfForceOptions(&theseFortranOptions); |
295 |
+ |
} |
296 |
|
} //end namespace oopse |