ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/UseTheForce/ForceField.cpp
Revision: 2172
Committed: Tue Apr 12 18:30:37 2005 UTC (19 years, 3 months ago) by tim
File size: 8524 byte(s)
Log Message:
destory atom type in fortran side

File Contents

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