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 |
|
|
70 |
< |
ForceField::~ForceField() { |
70 |
> |
ForceField::~ForceField() { |
71 |
|
deleteAtypes(); |
72 |
< |
} |
72 |
> |
deleteSwitch(); |
73 |
> |
} |
74 |
|
|
75 |
< |
AtomType* ForceField::getAtomType(const std::string &at) { |
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 |
> |
BondType* ForceField::getExactBondType(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 |
|
return bondTypeCont_.find(keys); |
139 |
< |
} |
139 |
> |
} |
140 |
|
|
141 |
< |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
142 |
< |
const std::string &at3){ |
141 |
> |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
142 |
> |
const std::string &at3){ |
143 |
|
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 |
< |
} |
148 |
> |
} |
149 |
|
|
150 |
< |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
151 |
< |
const std::string &at3, const std::string &at4){ |
150 |
> |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
151 |
> |
const std::string &at3, const std::string &at4){ |
152 |
|
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 |
< |
} |
159 |
< |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
158 |
> |
} |
159 |
> |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
160 |
|
std::vector<std::string> keys; |
161 |
|
keys.push_back(at); |
162 |
|
return atomTypeCont_.add(keys, atomType); |
163 |
< |
} |
163 |
> |
} |
164 |
|
|
165 |
< |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
165 |
> |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
166 |
|
std::vector<std::string> keys; |
167 |
|
keys.push_back(at1); |
168 |
|
keys.push_back(at2); |
169 |
|
return bondTypeCont_.add(keys, bondType); |
170 |
|
|
171 |
< |
} |
171 |
> |
} |
172 |
|
|
173 |
< |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
174 |
< |
const std::string &at3, BendType* bendType) { |
173 |
> |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
174 |
> |
const std::string &at3, BendType* bendType) { |
175 |
|
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 |
< |
} |
180 |
> |
} |
181 |
|
|
182 |
< |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
183 |
< |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
182 |
> |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
183 |
> |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
184 |
|
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 |
< |
} |
190 |
> |
} |
191 |
|
|
192 |
< |
double ForceField::getRcutFromAtomType(AtomType* at) { |
192 |
> |
double ForceField::getRcutFromAtomType(AtomType* at) { |
193 |
|
/**@todo */ |
194 |
|
GenericData* data; |
195 |
|
double rcut = 0.0; |
196 |
|
|
197 |
|
if (at->isLennardJones()) { |
198 |
< |
data = at->getPropertyByName("LennardJones"); |
199 |
< |
if (data != NULL) { |
200 |
< |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
198 |
> |
data = at->getPropertyByName("LennardJones"); |
199 |
> |
if (data != NULL) { |
200 |
> |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
201 |
|
|
202 |
< |
if (ljData != NULL) { |
203 |
< |
LJParam ljParam = ljData->getData(); |
202 |
> |
if (ljData != NULL) { |
203 |
> |
LJParam ljParam = ljData->getData(); |
204 |
|
|
205 |
< |
//by default use 2.5*sigma as cutoff radius |
206 |
< |
rcut = 2.5 * ljParam.sigma; |
205 |
> |
//by default use 2.5*sigma as cutoff radius |
206 |
> |
rcut = 2.5 * ljParam.sigma; |
207 |
|
|
208 |
< |
} 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 |
< |
} |
208 |
> |
} 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 |
|
} |
222 |
|
|
223 |
|
return rcut; |
224 |
< |
} |
224 |
> |
} |
225 |
|
|
226 |
|
|
227 |
< |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
227 |
> |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
228 |
|
std::string forceFieldFilename(filename); |
229 |
|
ifstrstream* ffStream = new ifstrstream(); |
230 |
|
|
232 |
|
ffStream->open(forceFieldFilename.c_str()); |
233 |
|
if(!ffStream->is_open()){ |
234 |
|
|
235 |
< |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
236 |
< |
ffStream->open( forceFieldFilename.c_str() ); |
235 |
> |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
236 |
> |
ffStream->open( forceFieldFilename.c_str() ); |
237 |
|
|
238 |
< |
//if current directory does not contain the force field file, |
239 |
< |
//try to open it in the path |
240 |
< |
if(!ffStream->is_open()){ |
238 |
> |
//if current directory does not contain the force field file, |
239 |
> |
//try to open it in the path |
240 |
> |
if(!ffStream->is_open()){ |
241 |
|
|
242 |
< |
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 |
< |
} |
242 |
> |
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 |
|
} |
253 |
|
|
254 |
|
return ffStream; |
255 |
|
|
256 |
< |
} |
256 |
> |
} |
257 |
|
|
258 |
+ |
void ForceField::setFortranForceOptions(){ |
259 |
+ |
ForceOptions theseFortranOptions; |
260 |
+ |
forceFieldOptions_.makeFortranOptions(theseFortranOptions); |
261 |
+ |
setfForceOptions(&theseFortranOptions); |
262 |
+ |
} |
263 |
|
} //end namespace oopse |