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