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 |
|
namespace oopse { |
55 |
|
|
56 |
< |
ForceField::ForceField() { |
56 |
> |
ForceField::ForceField() { |
57 |
|
char* tempPath; |
58 |
|
tempPath = getenv("FORCE_PARAM_PATH"); |
59 |
|
|
60 |
|
if (tempPath == NULL) { |
61 |
< |
//convert a macro from compiler to a string in c++ |
62 |
< |
STR_DEFINE(ffPath_, FRC_PATH ); |
61 |
> |
//convert a macro from compiler to a string in c++ |
62 |
> |
STR_DEFINE(ffPath_, FRC_PATH ); |
63 |
|
} else { |
64 |
< |
ffPath_ = tempPath; |
64 |
> |
ffPath_ = tempPath; |
65 |
|
} |
66 |
< |
} |
66 |
> |
} |
67 |
|
|
68 |
< |
AtomType* ForceField::getAtomType(const std::string &at) { |
68 |
> |
|
69 |
> |
ForceField::~ForceField() { |
70 |
> |
deleteAtypes(); |
71 |
> |
} |
72 |
> |
|
73 |
> |
AtomType* ForceField::getAtomType(const std::string &at) { |
74 |
|
std::vector<std::string> keys; |
75 |
|
keys.push_back(at); |
76 |
|
return atomTypeCont_.find(keys); |
77 |
< |
} |
77 |
> |
} |
78 |
|
|
79 |
< |
BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { |
79 |
> |
BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { |
80 |
|
std::vector<std::string> keys; |
81 |
|
keys.push_back(at1); |
82 |
|
keys.push_back(at2); |
84 |
|
//try exact match first |
85 |
|
BondType* bondType = bondTypeCont_.find(keys); |
86 |
|
if (bondType) { |
87 |
< |
return bondType; |
87 |
> |
return bondType; |
88 |
|
} else { |
89 |
< |
//if no exact match found, try wild card match |
90 |
< |
return bondTypeCont_.find(keys, wildCardAtomTypeName_); |
89 |
> |
//if no exact match found, try wild card match |
90 |
> |
return bondTypeCont_.find(keys, wildCardAtomTypeName_); |
91 |
|
} |
92 |
|
|
93 |
< |
} |
93 |
> |
} |
94 |
|
|
95 |
< |
BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, |
96 |
< |
const std::string &at3) { |
95 |
> |
BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, |
96 |
> |
const std::string &at3) { |
97 |
|
std::vector<std::string> keys; |
98 |
|
keys.push_back(at1); |
99 |
|
keys.push_back(at2); |
102 |
|
//try exact match first |
103 |
|
BendType* bendType = bendTypeCont_.find(keys); |
104 |
|
if (bendType) { |
105 |
< |
return bendType; |
105 |
> |
return bendType; |
106 |
|
} else { |
107 |
< |
//if no exact match found, try wild card match |
108 |
< |
return bendTypeCont_.find(keys, wildCardAtomTypeName_); |
107 |
> |
//if no exact match found, try wild card match |
108 |
> |
return bendTypeCont_.find(keys, wildCardAtomTypeName_); |
109 |
|
} |
110 |
< |
} |
110 |
> |
} |
111 |
|
|
112 |
< |
TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, |
113 |
< |
const std::string &at3, const std::string &at4) { |
112 |
> |
TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, |
113 |
> |
const std::string &at3, const std::string &at4) { |
114 |
|
std::vector<std::string> keys; |
115 |
|
keys.push_back(at1); |
116 |
|
keys.push_back(at2); |
119 |
|
|
120 |
|
TorsionType* torsionType = torsionTypeCont_.find(keys); |
121 |
|
if (torsionType) { |
122 |
< |
return torsionType; |
122 |
> |
return torsionType; |
123 |
|
} else { |
124 |
< |
//if no exact match found, try wild card match |
125 |
< |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
124 |
> |
//if no exact match found, try wild card match |
125 |
> |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
126 |
|
} |
127 |
|
|
128 |
|
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
129 |
|
|
130 |
< |
} |
130 |
> |
} |
131 |
|
|
132 |
< |
BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ |
132 |
> |
BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ |
133 |
|
std::vector<std::string> keys; |
134 |
|
keys.push_back(at1); |
135 |
|
keys.push_back(at2); |
136 |
|
return bondTypeCont_.find(keys); |
137 |
< |
} |
137 |
> |
} |
138 |
|
|
139 |
< |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
140 |
< |
const std::string &at3){ |
139 |
> |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
140 |
> |
const std::string &at3){ |
141 |
|
std::vector<std::string> keys; |
142 |
|
keys.push_back(at1); |
143 |
|
keys.push_back(at2); |
144 |
|
keys.push_back(at3); |
145 |
|
return bendTypeCont_.find(keys); |
146 |
< |
} |
146 |
> |
} |
147 |
|
|
148 |
< |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
149 |
< |
const std::string &at3, const std::string &at4){ |
148 |
> |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
149 |
> |
const std::string &at3, const std::string &at4){ |
150 |
|
std::vector<std::string> keys; |
151 |
|
keys.push_back(at1); |
152 |
|
keys.push_back(at2); |
153 |
|
keys.push_back(at3); |
154 |
|
keys.push_back(at4); |
155 |
|
return torsionTypeCont_.find(keys); |
156 |
< |
} |
157 |
< |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
156 |
> |
} |
157 |
> |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
158 |
|
std::vector<std::string> keys; |
159 |
|
keys.push_back(at); |
160 |
|
return atomTypeCont_.add(keys, atomType); |
161 |
< |
} |
161 |
> |
} |
162 |
|
|
163 |
< |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
163 |
> |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
164 |
|
std::vector<std::string> keys; |
165 |
|
keys.push_back(at1); |
166 |
|
keys.push_back(at2); |
167 |
|
return bondTypeCont_.add(keys, bondType); |
168 |
|
|
169 |
< |
} |
169 |
> |
} |
170 |
|
|
171 |
< |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
172 |
< |
const std::string &at3, BendType* bendType) { |
171 |
> |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
172 |
> |
const std::string &at3, BendType* bendType) { |
173 |
|
std::vector<std::string> keys; |
174 |
|
keys.push_back(at1); |
175 |
|
keys.push_back(at2); |
176 |
|
keys.push_back(at3); |
177 |
|
return bendTypeCont_.add(keys, bendType); |
178 |
< |
} |
178 |
> |
} |
179 |
|
|
180 |
< |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
181 |
< |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
180 |
> |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
181 |
> |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
182 |
|
std::vector<std::string> keys; |
183 |
|
keys.push_back(at1); |
184 |
|
keys.push_back(at2); |
185 |
|
keys.push_back(at3); |
186 |
|
keys.push_back(at4); |
187 |
|
return torsionTypeCont_.add(keys, torsionType); |
188 |
< |
} |
188 |
> |
} |
189 |
|
|
190 |
< |
double ForceField::getRcutFromAtomType(AtomType* at) { |
190 |
> |
double ForceField::getRcutFromAtomType(AtomType* at) { |
191 |
|
/**@todo */ |
192 |
|
GenericData* data; |
193 |
|
double rcut = 0.0; |
194 |
|
|
195 |
|
if (at->isLennardJones()) { |
196 |
< |
data = at->getPropertyByName("LennardJones"); |
197 |
< |
if (data != NULL) { |
198 |
< |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
196 |
> |
data = at->getPropertyByName("LennardJones"); |
197 |
> |
if (data != NULL) { |
198 |
> |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
199 |
|
|
200 |
< |
if (ljData != NULL) { |
201 |
< |
LJParam ljParam = ljData->getData(); |
200 |
> |
if (ljData != NULL) { |
201 |
> |
LJParam ljParam = ljData->getData(); |
202 |
|
|
203 |
< |
//by default use 2.5*sigma as cutoff radius |
204 |
< |
rcut = 2.5 * ljParam.sigma; |
203 |
> |
//by default use 2.5*sigma as cutoff radius |
204 |
> |
rcut = 2.5 * ljParam.sigma; |
205 |
|
|
206 |
< |
} else { |
207 |
< |
sprintf( painCave.errMsg, |
208 |
< |
"Can not cast GenericData to LJParam\n"); |
209 |
< |
painCave.severity = OOPSE_ERROR; |
210 |
< |
painCave.isFatal = 1; |
211 |
< |
simError(); |
212 |
< |
} |
213 |
< |
} else { |
214 |
< |
sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); |
215 |
< |
painCave.severity = OOPSE_ERROR; |
216 |
< |
painCave.isFatal = 1; |
217 |
< |
simError(); |
218 |
< |
} |
206 |
> |
} else { |
207 |
> |
sprintf( painCave.errMsg, |
208 |
> |
"Can not cast GenericData to LJParam\n"); |
209 |
> |
painCave.severity = OOPSE_ERROR; |
210 |
> |
painCave.isFatal = 1; |
211 |
> |
simError(); |
212 |
> |
} |
213 |
> |
} else { |
214 |
> |
sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); |
215 |
> |
painCave.severity = OOPSE_ERROR; |
216 |
> |
painCave.isFatal = 1; |
217 |
> |
simError(); |
218 |
> |
} |
219 |
|
} |
220 |
|
|
221 |
|
return rcut; |
222 |
< |
} |
222 |
> |
} |
223 |
|
|
224 |
|
|
225 |
< |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
225 |
> |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
226 |
|
std::string forceFieldFilename(filename); |
227 |
|
ifstrstream* ffStream = new ifstrstream(); |
228 |
|
|
230 |
|
ffStream->open(forceFieldFilename.c_str()); |
231 |
|
if(!ffStream->is_open()){ |
232 |
|
|
233 |
< |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
234 |
< |
ffStream->open( forceFieldFilename.c_str() ); |
233 |
> |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
234 |
> |
ffStream->open( forceFieldFilename.c_str() ); |
235 |
|
|
236 |
< |
//if current directory does not contain the force field file, |
237 |
< |
//try to open it in the path |
238 |
< |
if(!ffStream->is_open()){ |
236 |
> |
//if current directory does not contain the force field file, |
237 |
> |
//try to open it in the path |
238 |
> |
if(!ffStream->is_open()){ |
239 |
|
|
240 |
< |
sprintf( painCave.errMsg, |
241 |
< |
"Error opening the force field parameter file:\n" |
242 |
< |
"\t%s\n" |
243 |
< |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
244 |
< |
"variable?\n", |
245 |
< |
forceFieldFilename.c_str() ); |
246 |
< |
painCave.severity = OOPSE_ERROR; |
247 |
< |
painCave.isFatal = 1; |
248 |
< |
simError(); |
249 |
< |
} |
240 |
> |
sprintf( painCave.errMsg, |
241 |
> |
"Error opening the force field parameter file:\n" |
242 |
> |
"\t%s\n" |
243 |
> |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
244 |
> |
"variable?\n", |
245 |
> |
forceFieldFilename.c_str() ); |
246 |
> |
painCave.severity = OOPSE_ERROR; |
247 |
> |
painCave.isFatal = 1; |
248 |
> |
simError(); |
249 |
> |
} |
250 |
|
} |
251 |
|
|
252 |
|
return ffStream; |
253 |
|
|
254 |
< |
} |
254 |
> |
} |
255 |
|
|
256 |
+ |
void ForceField::setFortranForceOptions(){ |
257 |
+ |
ForceOptions theseFortranOptions; |
258 |
+ |
forceFieldOptions_.makeFortranOptions(theseFortranOptions); |
259 |
+ |
setfForceOptions(&theseFortranOptions); |
260 |
+ |
} |
261 |
|
} //end namespace oopse |