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 |
namespace oopse { |
36 |
|
37 |
ForceField::ForceField() : hasVariant_(false){ |
38 |
char* tempPath; |
39 |
tempPath = getenv("FORCE_PARAM_PATH"); |
40 |
|
41 |
if (tempPath == NULL) { |
42 |
//convert a macro from compiler to a string in c++ |
43 |
STR_DEFINE(ffPath_, FRC_PATH ); |
44 |
} else { |
45 |
ffPath_ = tempPath; |
46 |
} |
47 |
} |
48 |
|
49 |
AtomType* ForceField::getAtomType(const std::string &at) { |
50 |
std::vector<std::string> keys; |
51 |
keys.push_back(at); |
52 |
return atomTypeCont_.find(keys); |
53 |
} |
54 |
|
55 |
BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { |
56 |
std::vector<std::string> keys; |
57 |
keys.push_back(at1); |
58 |
keys.push_back(at2); |
59 |
return bondTypeCont_.find(keys, wildCardAtomTypeName_); |
60 |
|
61 |
} |
62 |
|
63 |
BendType* ForceField::getBendType(const std::string &at1, const std::string &at2, |
64 |
const std::string &at3) { |
65 |
std::vector<std::string> keys; |
66 |
keys.push_back(at1); |
67 |
keys.push_back(at2); |
68 |
keys.push_back(at3); |
69 |
return bendTypeCont_.find(keys, wildCardAtomTypeName_); |
70 |
} |
71 |
|
72 |
TorsionType* ForceField::getTorsionType(const std::string &at1, const std::string &at2, |
73 |
const std::string &at3, const std::string &at4) { |
74 |
std::vector<std::string> keys; |
75 |
keys.push_back(at1); |
76 |
keys.push_back(at2); |
77 |
keys.push_back(at3); |
78 |
keys.push_back(at4); |
79 |
return torsionTypeCont_.find(keys, wildCardAtomTypeName_); |
80 |
|
81 |
} |
82 |
|
83 |
BondType* getExactBondType(const std::string &at1, const std::string &at2){ |
84 |
std::vector<std::string> keys; |
85 |
keys.push_back(at1); |
86 |
keys.push_back(at2); |
87 |
return bondTypeCont_.find(keys); |
88 |
} |
89 |
|
90 |
BendType* getExactBendType(const std::string &at1, const std::string &at2, |
91 |
const std::string &at3){ |
92 |
std::vector<std::string> keys; |
93 |
keys.push_back(at1); |
94 |
keys.push_back(at2); |
95 |
keys.push_back(at3); |
96 |
return bendTypeCont_.find(keys); |
97 |
} |
98 |
|
99 |
TorsionType* getExactTorsionType(const std::string &at1, const std::string &at2, |
100 |
const std::string &at3, const std::string &at4){ |
101 |
std::vector<std::string> keys; |
102 |
keys.push_back(at1); |
103 |
keys.push_back(at2); |
104 |
keys.push_back(at3); |
105 |
keys.push_back(at4); |
106 |
return torsionTypeCont_.find(keys); |
107 |
} |
108 |
bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
109 |
std::vector<std::string> keys; |
110 |
keys.push_back(at); |
111 |
return atomTypeCont_.add(keys); |
112 |
} |
113 |
|
114 |
bool ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
115 |
std::vector<std::string> keys; |
116 |
keys.push_back(at1); |
117 |
keys.push_back(at2); |
118 |
return bondTypeCont_.add(keys); |
119 |
|
120 |
} |
121 |
|
122 |
bool ForceField::addBendType(const std::string &at1, const std::string &at2, |
123 |
const std::string &at3, BendType* bendType) { |
124 |
std::vector<std::string> keys; |
125 |
keys.push_back(at1); |
126 |
keys.push_back(at2); |
127 |
keys.push_back(at3); |
128 |
return bendTypeCont_.add(keys); |
129 |
} |
130 |
|
131 |
bool ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
132 |
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
133 |
std::vector<std::string> keys; |
134 |
keys.push_back(at1); |
135 |
keys.push_back(at2); |
136 |
keys.push_back(at3); |
137 |
keys.push_back(at4); |
138 |
return torsionTypeCont_.add(keys); |
139 |
} |
140 |
|
141 |
double ForceField::getRcutFromAtomType(AtomType* at) { |
142 |
|
143 |
} |
144 |
|
145 |
|
146 |
ifstrstream* ForceField::openForceFiledFile(const std::string& filename) { |
147 |
std::string forceFieldFilename(filename); |
148 |
ifstrstream* ffStream = new ifstrstream(); |
149 |
|
150 |
//try to open the force filed file in current directory first |
151 |
ffStream.open(forceFieldFilename.c_str()); |
152 |
if(!ffStream.is_open()){ |
153 |
|
154 |
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
155 |
ffStream.open( forceFieldFilename.c_str() ); |
156 |
|
157 |
//if current directory does not contain the force field file, |
158 |
//try to open it in the path |
159 |
if(!ffStream.is_open()){ |
160 |
|
161 |
sprintf( painCave.errMsg, |
162 |
"Error opening the force field parameter file:\n" |
163 |
"\t%s\n" |
164 |
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
165 |
"variable?\n", |
166 |
forceFieldFilename.c_str() ); |
167 |
painCave.severity = OOPSE_ERROR; |
168 |
painCave.isFatal = 1; |
169 |
simError(); |
170 |
} |
171 |
} |
172 |
|
173 |
return ffStream; |
174 |
|
175 |
} |
176 |
|
177 |
} //end namespace oopse |