1 |
tim |
1720 |
/* |
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 |
gezelter |
1711 |
#include "UseTheForce/ForceField.hpp" |
35 |
tim |
1783 |
#include "utils/simError.h" |
36 |
tim |
1720 |
namespace oopse { |
37 |
gezelter |
1711 |
|
38 |
tim |
1720 |
ForceField::ForceField() : hasVariant_(false){ |
39 |
|
|
char* tempPath; |
40 |
|
|
tempPath = getenv("FORCE_PARAM_PATH"); |
41 |
gezelter |
1711 |
|
42 |
tim |
1720 |
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 |
gezelter |
1711 |
} |
49 |
|
|
|
50 |
tim |
1720 |
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 |
gezelter |
1711 |
|
56 |
tim |
1720 |
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 |
|
|
return bondTypeCont_.find(keys, wildCardAtomTypeName_); |
61 |
gezelter |
1711 |
|
62 |
tim |
1720 |
} |
63 |
gezelter |
1711 |
|
64 |
tim |
1720 |
BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, |
65 |
|
|
const std::string &at3) { |
66 |
|
|
std::vector<std::string> keys; |
67 |
|
|
keys.push_back(at1); |
68 |
|
|
keys.push_back(at2); |
69 |
|
|
keys.push_back(at3); |
70 |
|
|
return bendTypeCont_.find(keys, wildCardAtomTypeName_); |
71 |
|
|
} |
72 |
gezelter |
1711 |
|
73 |
tim |
1720 |
TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, |
74 |
|
|
const std::string &at3, const std::string &at4) { |
75 |
|
|
std::vector<std::string> keys; |
76 |
|
|
keys.push_back(at1); |
77 |
|
|
keys.push_back(at2); |
78 |
|
|
keys.push_back(at3); |
79 |
|
|
keys.push_back(at4); |
80 |
|
|
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
81 |
gezelter |
1711 |
|
82 |
tim |
1720 |
} |
83 |
gezelter |
1711 |
|
84 |
tim |
1783 |
BondType* ForceField::getExactBondType(const std::string &at1, const std::string &at2){ |
85 |
tim |
1770 |
std::vector<std::string> keys; |
86 |
|
|
keys.push_back(at1); |
87 |
|
|
keys.push_back(at2); |
88 |
|
|
return bondTypeCont_.find(keys); |
89 |
|
|
} |
90 |
|
|
|
91 |
tim |
1783 |
BendType* ForceField::getExactBendType(const std::string &at1, const std::string &at2, |
92 |
tim |
1770 |
const std::string &at3){ |
93 |
|
|
std::vector<std::string> keys; |
94 |
|
|
keys.push_back(at1); |
95 |
|
|
keys.push_back(at2); |
96 |
|
|
keys.push_back(at3); |
97 |
|
|
return bendTypeCont_.find(keys); |
98 |
|
|
} |
99 |
|
|
|
100 |
tim |
1783 |
TorsionType* ForceField::getExactTorsionType(const std::string &at1, const std::string &at2, |
101 |
tim |
1770 |
const std::string &at3, const std::string &at4){ |
102 |
|
|
std::vector<std::string> keys; |
103 |
|
|
keys.push_back(at1); |
104 |
|
|
keys.push_back(at2); |
105 |
|
|
keys.push_back(at3); |
106 |
|
|
keys.push_back(at4); |
107 |
|
|
return torsionTypeCont_.find(keys); |
108 |
|
|
} |
109 |
tim |
1758 |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
110 |
tim |
1720 |
std::vector<std::string> keys; |
111 |
|
|
keys.push_back(at); |
112 |
tim |
1783 |
return atomTypeCont_.add(keys, atomType); |
113 |
tim |
1720 |
} |
114 |
gezelter |
1711 |
|
115 |
tim |
1758 |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
116 |
tim |
1720 |
std::vector<std::string> keys; |
117 |
|
|
keys.push_back(at1); |
118 |
|
|
keys.push_back(at2); |
119 |
tim |
1783 |
return bondTypeCont_.add(keys, bondType); |
120 |
gezelter |
1711 |
|
121 |
tim |
1720 |
} |
122 |
gezelter |
1711 |
|
123 |
tim |
1758 |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
124 |
tim |
1720 |
const std::string &at3, BendType* bendType) { |
125 |
|
|
std::vector<std::string> keys; |
126 |
|
|
keys.push_back(at1); |
127 |
|
|
keys.push_back(at2); |
128 |
|
|
keys.push_back(at3); |
129 |
tim |
1783 |
return bendTypeCont_.add(keys, bendType); |
130 |
tim |
1720 |
} |
131 |
gezelter |
1711 |
|
132 |
tim |
1758 |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
133 |
tim |
1720 |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
134 |
|
|
std::vector<std::string> keys; |
135 |
|
|
keys.push_back(at1); |
136 |
|
|
keys.push_back(at2); |
137 |
|
|
keys.push_back(at3); |
138 |
|
|
keys.push_back(at4); |
139 |
tim |
1783 |
return torsionTypeCont_.add(keys, torsionType); |
140 |
tim |
1720 |
} |
141 |
gezelter |
1711 |
|
142 |
tim |
1735 |
double ForceField::getRcutFromAtomType(AtomType* at) { |
143 |
tim |
1783 |
/**@todo */ |
144 |
|
|
GenericData* data; |
145 |
|
|
double rcut = 0.0; |
146 |
|
|
|
147 |
|
|
if (at->isLennardJones()) { |
148 |
|
|
data = at->getPropertyByName("LennardJones"); |
149 |
|
|
if (data != NULL) { |
150 |
|
|
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
151 |
|
|
|
152 |
|
|
if (ljData != NULL) { |
153 |
|
|
LJParam ljParam = ljData->getData(); |
154 |
|
|
|
155 |
|
|
//by default use 2.5*sigma as cutoff radius |
156 |
|
|
rcut = 2.5 * ljParam.sigma; |
157 |
|
|
|
158 |
|
|
} else { |
159 |
|
|
sprintf( painCave.errMsg, |
160 |
|
|
"Can not cast GenericData to LJParam\n"); |
161 |
|
|
painCave.severity = OOPSE_ERROR; |
162 |
|
|
painCave.isFatal = 1; |
163 |
|
|
simError(); |
164 |
|
|
} |
165 |
|
|
} else { |
166 |
|
|
sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n"); |
167 |
|
|
painCave.severity = OOPSE_ERROR; |
168 |
|
|
painCave.isFatal = 1; |
169 |
|
|
simError(); |
170 |
|
|
} |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
return rcut; |
174 |
tim |
1720 |
} |
175 |
gezelter |
1711 |
|
176 |
tim |
1740 |
|
177 |
tim |
1783 |
ifstrstream* ForceField::openForceFieldFile(const std::string& filename) { |
178 |
tim |
1740 |
std::string forceFieldFilename(filename); |
179 |
|
|
ifstrstream* ffStream = new ifstrstream(); |
180 |
|
|
|
181 |
|
|
//try to open the force filed file in current directory first |
182 |
tim |
1783 |
ffStream->open(forceFieldFilename.c_str()); |
183 |
|
|
if(!ffStream->is_open()){ |
184 |
tim |
1740 |
|
185 |
|
|
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
186 |
tim |
1783 |
ffStream->open( forceFieldFilename.c_str() ); |
187 |
tim |
1740 |
|
188 |
|
|
//if current directory does not contain the force field file, |
189 |
|
|
//try to open it in the path |
190 |
tim |
1783 |
if(!ffStream->is_open()){ |
191 |
tim |
1740 |
|
192 |
|
|
sprintf( painCave.errMsg, |
193 |
|
|
"Error opening the force field parameter file:\n" |
194 |
|
|
"\t%s\n" |
195 |
|
|
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
196 |
|
|
"variable?\n", |
197 |
|
|
forceFieldFilename.c_str() ); |
198 |
|
|
painCave.severity = OOPSE_ERROR; |
199 |
|
|
painCave.isFatal = 1; |
200 |
|
|
simError(); |
201 |
|
|
} |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
return ffStream; |
205 |
|
|
|
206 |
|
|
} |
207 |
|
|
|
208 |
tim |
1720 |
} //end namespace oopse |