ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/UseTheForce/ForceField.cpp
Revision: 3286
Committed: Thu Dec 6 20:04:02 2007 UTC (16 years, 7 months ago) by cpuglis
File size: 9648 byte(s)
Log Message:
Many fixes for Charmm-type torsions.

File Contents

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