1 |
/* |
2 |
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
3 |
* |
4 |
* Contact: oopse@oopse.org |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU Lesser General Public License |
8 |
* as published by the Free Software Foundation; either version 2.1 |
9 |
* of the License, or (at your option) any later version. |
10 |
* All we ask is that proper credit is given for our work, which includes |
11 |
* - but is not limited to - adding the above copyright notice to the beginning |
12 |
* of your source code files, and to any copyright notice that you may distribute |
13 |
* with programs based on this work. |
14 |
* |
15 |
* This program is distributed in the hope that it will be useful, |
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
* GNU Lesser General Public License for more details. |
19 |
* |
20 |
* You should have received a copy of the GNU Lesser General Public License |
21 |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
* |
24 |
*/ |
25 |
|
26 |
/** |
27 |
* @file ForceField.cpp |
28 |
* @author tlin |
29 |
* @date 11/04/2004 |
30 |
* @time 22:51am |
31 |
* @version 1.0 |
32 |
*/ |
33 |
|
34 |
#include "UseTheForce/ForceField.hpp" |
35 |
#include "utils/simError.h" |
36 |
namespace oopse { |
37 |
|
38 |
ForceField::ForceField() { |
39 |
char* tempPath; |
40 |
tempPath = getenv("FORCE_PARAM_PATH"); |
41 |
|
42 |
if (tempPath == NULL) { |
43 |
//convert a macro from compiler to a string in c++ |
44 |
STR_DEFINE(ffPath_, FRC_PATH ); |
45 |
} else { |
46 |
ffPath_ = tempPath; |
47 |
} |
48 |
} |
49 |
|
50 |
AtomType* ForceField::getAtomType(const std::string &at) { |
51 |
std::vector<std::string> keys; |
52 |
keys.push_back(at); |
53 |
return atomTypeCont_.find(keys); |
54 |
} |
55 |
|
56 |
BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { |
57 |
std::vector<std::string> keys; |
58 |
keys.push_back(at1); |
59 |
keys.push_back(at2); |
60 |
|
61 |
//try exact match first |
62 |
BondType* bondType = bondTypeCont_.find(keys); |
63 |
if (bondType) { |
64 |
return bondType; |
65 |
} else { |
66 |
//if no exact match found, try wild card match |
67 |
return bondTypeCont_.find(keys, wildCardAtomTypeName_); |
68 |
} |
69 |
|
70 |
} |
71 |
|
72 |
BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, |
73 |
const std::string &at3) { |
74 |
std::vector<std::string> keys; |
75 |
keys.push_back(at1); |
76 |
keys.push_back(at2); |
77 |
keys.push_back(at3); |
78 |
|
79 |
//try exact match first |
80 |
BendType* bendType = bendTypeCont_.find(keys); |
81 |
if (bendType) { |
82 |
return bendType; |
83 |
} else { |
84 |
//if no exact match found, try wild card match |
85 |
return bendTypeCont_.find(keys, wildCardAtomTypeName_); |
86 |
} |
87 |
} |
88 |
|
89 |
TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, |
90 |
const std::string &at3, const std::string &at4) { |
91 |
std::vector<std::string> keys; |
92 |
keys.push_back(at1); |
93 |
keys.push_back(at2); |
94 |
keys.push_back(at3); |
95 |
keys.push_back(at4); |
96 |
|
97 |
TorsionType* torsionType = torsionTypeCont_.find(keys); |
98 |
if (torsionType) { |
99 |
return torsionType; |
100 |
} else { |
101 |
//if no exact match found, try wild card match |
102 |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
103 |
} |
104 |
|
105 |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
106 |
|
107 |
} |
108 |
|
109 |
BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ |
110 |
std::vector<std::string> keys; |
111 |
keys.push_back(at1); |
112 |
keys.push_back(at2); |
113 |
return bondTypeCont_.find(keys); |
114 |
} |
115 |
|
116 |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
117 |
const std::string &at3){ |
118 |
std::vector<std::string> keys; |
119 |
keys.push_back(at1); |
120 |
keys.push_back(at2); |
121 |
keys.push_back(at3); |
122 |
return bendTypeCont_.find(keys); |
123 |
} |
124 |
|
125 |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
126 |
const std::string &at3, const std::string &at4){ |
127 |
std::vector<std::string> keys; |
128 |
keys.push_back(at1); |
129 |
keys.push_back(at2); |
130 |
keys.push_back(at3); |
131 |
keys.push_back(at4); |
132 |
return torsionTypeCont_.find(keys); |
133 |
} |
134 |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
135 |
std::vector<std::string> keys; |
136 |
keys.push_back(at); |
137 |
return atomTypeCont_.add(keys, atomType); |
138 |
} |
139 |
|
140 |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
141 |
std::vector<std::string> keys; |
142 |
keys.push_back(at1); |
143 |
keys.push_back(at2); |
144 |
return bondTypeCont_.add(keys, bondType); |
145 |
|
146 |
} |
147 |
|
148 |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
149 |
const std::string &at3, BendType* bendType) { |
150 |
std::vector<std::string> keys; |
151 |
keys.push_back(at1); |
152 |
keys.push_back(at2); |
153 |
keys.push_back(at3); |
154 |
return bendTypeCont_.add(keys, bendType); |
155 |
} |
156 |
|
157 |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
158 |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
159 |
std::vector<std::string> keys; |
160 |
keys.push_back(at1); |
161 |
keys.push_back(at2); |
162 |
keys.push_back(at3); |
163 |
keys.push_back(at4); |
164 |
return torsionTypeCont_.add(keys, torsionType); |
165 |
} |
166 |
|
167 |
double ForceField::getRcutFromAtomType(AtomType* at) { |
168 |
/**@todo */ |
169 |
GenericData* data; |
170 |
double rcut = 0.0; |
171 |
|
172 |
if (at->isLennardJones()) { |
173 |
data = at->getPropertyByName("LennardJones"); |
174 |
if (data != NULL) { |
175 |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
176 |
|
177 |
if (ljData != NULL) { |
178 |
LJParam ljParam = ljData->getData(); |
179 |
|
180 |
//by default use 2.5*sigma as cutoff radius |
181 |
rcut = 2.5 * ljParam.sigma; |
182 |
|
183 |
} else { |
184 |
sprintf( painCave.errMsg, |
185 |
"Can not cast GenericData to LJParam\n"); |
186 |
painCave.severity = OOPSE_ERROR; |
187 |
painCave.isFatal = 1; |
188 |
simError(); |
189 |
} |
190 |
} else { |
191 |
sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); |
192 |
painCave.severity = OOPSE_ERROR; |
193 |
painCave.isFatal = 1; |
194 |
simError(); |
195 |
} |
196 |
} |
197 |
|
198 |
return rcut; |
199 |
} |
200 |
|
201 |
|
202 |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
203 |
std::string forceFieldFilename(filename); |
204 |
ifstrstream* ffStream = new ifstrstream(); |
205 |
|
206 |
//try to open the force filed file in current directory first |
207 |
ffStream->open(forceFieldFilename.c_str()); |
208 |
if(!ffStream->is_open()){ |
209 |
|
210 |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
211 |
ffStream->open( forceFieldFilename.c_str() ); |
212 |
|
213 |
//if current directory does not contain the force field file, |
214 |
//try to open it in the path |
215 |
if(!ffStream->is_open()){ |
216 |
|
217 |
sprintf( painCave.errMsg, |
218 |
"Error opening the force field parameter file:\n" |
219 |
"\t%s\n" |
220 |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
221 |
"variable?\n", |
222 |
forceFieldFilename.c_str() ); |
223 |
painCave.severity = OOPSE_ERROR; |
224 |
painCave.isFatal = 1; |
225 |
simError(); |
226 |
} |
227 |
} |
228 |
|
229 |
return ffStream; |
230 |
|
231 |
} |
232 |
|
233 |
} //end namespace oopse |