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 |
1720 |
namespace oopse { |
36 |
gezelter |
1711 |
|
37 |
tim |
1720 |
ForceField::ForceField() : hasVariant_(false){ |
38 |
|
|
char* tempPath; |
39 |
|
|
tempPath = getenv("FORCE_PARAM_PATH"); |
40 |
gezelter |
1711 |
|
41 |
tim |
1720 |
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 |
gezelter |
1711 |
} |
48 |
|
|
|
49 |
tim |
1720 |
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 |
gezelter |
1711 |
|
55 |
tim |
1720 |
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 |
gezelter |
1711 |
|
61 |
tim |
1720 |
} |
62 |
gezelter |
1711 |
|
63 |
tim |
1720 |
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 |
gezelter |
1711 |
|
72 |
tim |
1720 |
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 |
gezelter |
1711 |
|
81 |
tim |
1720 |
} |
82 |
gezelter |
1711 |
|
83 |
tim |
1720 |
void ForceField::addAtomType(const std::string &at, AtomType* atomType) { |
84 |
|
|
std::vector<std::string> keys; |
85 |
|
|
keys.push_back(at); |
86 |
|
|
return atomTypeCont_.add(keys); |
87 |
|
|
} |
88 |
gezelter |
1711 |
|
89 |
tim |
1720 |
void ForceField::addBondType(const std::string &at1, const std::string &at2, BondType* bondType) { |
90 |
|
|
std::vector<std::string> keys; |
91 |
|
|
keys.push_back(at1); |
92 |
|
|
keys.push_back(at2); |
93 |
|
|
return bondTypeCont_.add(keys); |
94 |
gezelter |
1711 |
|
95 |
tim |
1720 |
} |
96 |
gezelter |
1711 |
|
97 |
tim |
1720 |
void ForceField::addBendType(const std::string &at1, const std::string &at2, |
98 |
|
|
const std::string &at3, BendType* bendType) { |
99 |
|
|
std::vector<std::string> keys; |
100 |
|
|
keys.push_back(at1); |
101 |
|
|
keys.push_back(at2); |
102 |
|
|
keys.push_back(at3); |
103 |
|
|
return bendTypeCont_.add(keys); |
104 |
|
|
} |
105 |
gezelter |
1711 |
|
106 |
tim |
1720 |
void ForceField::addTorsionType(const std::string &at1, const std::string &at2, |
107 |
|
|
const std::string &at3, const std::string &at4, TorsionType* torsionType) { |
108 |
|
|
std::vector<std::string> keys; |
109 |
|
|
keys.push_back(at1); |
110 |
|
|
keys.push_back(at2); |
111 |
|
|
keys.push_back(at3); |
112 |
|
|
keys.push_back(at4); |
113 |
|
|
return torsionTypeCont_.add(keys); |
114 |
|
|
} |
115 |
gezelter |
1711 |
|
116 |
tim |
1735 |
double ForceField::getRcutFromAtomType(AtomType* at) { |
117 |
|
|
|
118 |
tim |
1720 |
} |
119 |
gezelter |
1711 |
|
120 |
tim |
1740 |
|
121 |
|
|
ifstrstream* ForceField::openForceFiledFile(const std::string& filename) { |
122 |
|
|
std::string forceFieldFilename(filename); |
123 |
|
|
ifstrstream* ffStream = new ifstrstream(); |
124 |
|
|
|
125 |
|
|
//try to open the force filed file in current directory first |
126 |
|
|
ffStream.open(forceFieldFilename.c_str()); |
127 |
|
|
if(!ffStream.is_open()){ |
128 |
|
|
|
129 |
|
|
forceFieldFilename = ffPath_ + "/" + forceFieldFilename; |
130 |
|
|
ffStream.open( forceFieldFilename.c_str() ); |
131 |
|
|
|
132 |
|
|
//if current directory does not contain the force field file, |
133 |
|
|
//try to open it in the path |
134 |
|
|
if(!ffStream.is_open()){ |
135 |
|
|
|
136 |
|
|
sprintf( painCave.errMsg, |
137 |
|
|
"Error opening the force field parameter file:\n" |
138 |
|
|
"\t%s\n" |
139 |
|
|
"\tHave you tried setting the FORCE_PARAM_PATH environment " |
140 |
|
|
"variable?\n", |
141 |
|
|
forceFieldFilename.c_str() ); |
142 |
|
|
painCave.severity = OOPSE_ERROR; |
143 |
|
|
painCave.isFatal = 1; |
144 |
|
|
simError(); |
145 |
|
|
} |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
return ffStream; |
149 |
|
|
|
150 |
|
|
} |
151 |
|
|
|
152 |
tim |
1720 |
} //end namespace oopse |