ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/UseTheForce/ForceField.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/UseTheForce/ForceField.cpp (file contents):
Revision 1711 by gezelter, Thu Nov 4 20:51:23 2004 UTC vs.
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC

# Line 1 | Line 1
1 + /*
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   #include "UseTheForce/ForceField.hpp"
51 + #include "utils/simError.h"
52 + #include "UseTheForce/DarkSide/atype_interface.h"
53 + namespace oopse {
54  
55 < AtomType* ForceField::getMatchingAtomType(const string &at) {
55 >  ForceField::ForceField() {
56 >    char* tempPath;
57 >    tempPath = getenv("FORCE_PARAM_PATH");
58  
59 <  map<string, AtomType*>::iterator iter;
60 <  
61 <  iter = atomTypeMap.find(at);
62 <  if (iter != atomTypeMap.end()) {
63 <    return iter->second;
64 <  } else {
11 <    return NULL;
59 >    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    }
13 }
66  
15 BondType* ForceField::getMatchingBondType(const string &at1,
16                                          const string &at2) {
67  
68 <  map<pair<string,string>, BondType*>::iterator iter;
69 <  vector<BondType*> foundTypes;
68 >  ForceField::~ForceField() {
69 >    deleteAtypes();
70 >  }
71  
72 <  iter = bondTypeMap.find(pair<at1, at2>);
73 <  if (iter != bondTypeMap.end()) {
74 <    // exact match, so just return it
75 <    return iter->second;
76 <  }
72 >  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  
78 <  iter = bondTypeMap.find(pair<at2, at1>);
79 <  if (iter != bondTypeMap.end()) {
80 <    // exact match in reverse order, so just return it
81 <    return iter->second;
31 <  }
78 >  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  
83 <  iter = bondTypeMap.find(pair<at1, wildCardAtomTypeName>);
84 <  if (iter != bondTypeMap.end()) {
85 <    foundTypes.push_back(iter->second);
83 >    //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 >
92    }
93  
94 <  iter = bondTypeMap.find(pair<at2, wildCardAtomTypeName>);
95 <  if (iter != bondTypeMap.end()) {
96 <    foundTypes.push_back(iter->second);
94 >  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 >
101 >    //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  
111 <  iter = bondTypeMap.find(pair<wildCardAtomTypeName, at1>);
112 <  if (iter != bondTypeMap.end()) {
113 <    foundTypes.push_back(iter->second);
111 >  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 >
119 >    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 >    
127 >    return torsionTypeCont_.find(keys, wildCardAtomTypeName_);
128 >
129    }
130  
131 <  iter = bondTypeMap.find(pair<wildCardAtomTypeName, at2>);
132 <  if (iter != bondTypeMap.end()) {
133 <    foundTypes.push_back(iter->second);
131 >  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    }
52  
53  if (foundTypes.empty()) {
54    return NULL;
55  } else {
56    
137  
138 <
138 >  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  
147 +  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  
162 +  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  
168 <  
168 >  }
169  
170 +  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  
179 < BendType* ForceField::getMatchingBendType(const string &at1, const string &at2,
180 <                                          const string &at3);
181 < TorsionType* ForceField::getMatchingTorsionType(const string &at1, const string &at2,
182 <                                                const string &at3, const string &at4);
179 >  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  
189 < double ForceField::getRcutForAtomType(AtomType* at);
189 >  double ForceField::getRcutFromAtomType(AtomType* at) {
190 >    /**@todo */
191 >    GenericData* data;
192 >    double rcut = 0.0;
193  
194 +    if (at->isLennardJones()) {
195 +      data = at->getPropertyByName("LennardJones");
196 +      if (data != NULL) {
197 +        LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
198  
199 < vector<vector<string> > generateWildcardSequence(const vector<string> atomTypes) {
200 <  
75 <   vector<vector<string> > results;
199 >        if (ljData != NULL) {
200 >          LJParam ljParam = ljData->getData();
201  
202 <  
202 >          //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  
220 +    return rcut;    
221 +  }
222  
80   vector<vector< string> > getAllWildcardPermutations(const vector<string> myAts) {
81    
82     int nStrings;
83     vector<string> oneResult;
84     vector<vector<string> > allResults;
223  
224 <     nStrings = myAts.size();
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 <     if (nStrings == 1) {
233 <       oneResult.push_back(wildcardCharacter);
234 <       allResults.push_back(oneResult);
235 <       return allResults;
236 <     } else {
237 <      
238 <       for (i=0; i < nStrings; i++) {
239 <         oneResult = myAts;
240 <         replace(oneResult.begin(), oneResult.end(),
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines