ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/brains/ForceField.cpp
(Generate patch)

Comparing trunk/src/UseTheForce/ForceField.cpp (file contents):
Revision 1195 by cpuglis, Thu Dec 6 20:04:02 2007 UTC vs.
Revision 1269 by gezelter, Tue Jul 1 13:28:23 2008 UTC

# Line 47 | Line 47
47   * @version 1.0
48   */
49    
50 + #include <algorithm>
51   #include "UseTheForce/ForceField.hpp"
52   #include "utils/simError.h"
53 + #include "utils/Tuple.hpp"
54   #include "UseTheForce/DarkSide/atype_interface.h"
55   #include "UseTheForce/DarkSide/fForceOptions_interface.h"
56   #include "UseTheForce/DarkSide/switcheroo_interface.h"
# Line 89 | Line 91 | namespace oopse {
91      if (bondType) {
92        return bondType;
93      } else {
94 <      //if no exact match found, try wild card match
95 <      return bondTypeCont_.find(keys, wildCardAtomTypeName_);
94 >      AtomType* atype1;
95 >      AtomType* atype2;
96 >      std::vector<std::string> at1key;
97 >      at1key.push_back(at1);
98 >      atype1 = atomTypeCont_.find(at1key);
99 >  
100 >      std::vector<std::string> at2key;
101 >      at2key.push_back(at2);
102 >      atype2 = atomTypeCont_.find(at2key);
103 >
104 >      // query atom types for their chains of responsibility
105 >      std::vector<AtomType*> at1Chain = atype1->allYourBase();
106 >      std::vector<AtomType*> at2Chain = atype2->allYourBase();
107 >
108 >      std::vector<AtomType*>::iterator i;
109 >      std::vector<AtomType*>::iterator j;
110 >
111 >      int ii = 0;
112 >      int jj = 0;
113 >      int bondTypeScore;
114 >
115 >      std::vector<std::pair<int, std::vector<std::string> > > foundBonds;
116 >
117 >      for (i = at1Chain.begin(); i != at1Chain.end(); i++) {
118 >        jj = 0;
119 >        for (j = at2Chain.begin(); j != at2Chain.end(); j++) {
120 >
121 >          bondTypeScore = ii + jj;
122 >
123 >          std::vector<std::string> myKeys;
124 >          myKeys.push_back((*i)->getName());
125 >          myKeys.push_back((*j)->getName());
126 >
127 >          BondType* bondType = bondTypeCont_.find(myKeys);
128 >          if (bondType) {
129 >            foundBonds.push_back(std::make_pair(bondTypeScore, myKeys));
130 >          }
131 >          jj++;
132 >        }
133 >        ii++;
134 >      }
135 >
136 >      // sort the foundBonds by the score:
137 >
138 >      std::sort(foundBonds.begin(), foundBonds.end());
139 >      
140 >      int bestScore = foundBonds[0].first;
141 >      std::vector<std::string> theKeys = foundBonds[0].second;
142 >
143 >      std::cout << "best matching bond = " << theKeys[0] << "\t" << theKeys[1]  << "\t(score = "<< bestScore << ")\n";      
144 >      BondType* bestType = bondTypeCont_.find(theKeys);
145 >      if (bestType)
146 >        return bestType;
147 >      else {
148 >        //if no exact match found, try wild card match
149 >        return bondTypeCont_.find(keys, wildCardAtomTypeName_);      
150 >      }
151      }
152    }
153 <
153 >  
154    BendType* ForceField::getBendType(const std::string &at1,
155                                      const std::string &at2,
156                                      const std::string &at3) {
# Line 107 | Line 164 | namespace oopse {
164      if (bendType) {
165        return bendType;
166      } else {
167 <      //if no exact match found, try wild card match
168 <      return bendTypeCont_.find(keys, wildCardAtomTypeName_);
167 >
168 >      AtomType* atype1;
169 >      AtomType* atype2;
170 >      AtomType* atype3;
171 >      std::vector<std::string> at1key;
172 >      at1key.push_back(at1);
173 >      atype1 = atomTypeCont_.find(at1key);
174 >  
175 >      std::vector<std::string> at2key;
176 >      at2key.push_back(at2);
177 >      atype2 = atomTypeCont_.find(at2key);
178 >
179 >      std::vector<std::string> at3key;
180 >      at3key.push_back(at3);
181 >      atype3 = atomTypeCont_.find(at3key);
182 >
183 >      // query atom types for their chains of responsibility
184 >      std::vector<AtomType*> at1Chain = atype1->allYourBase();
185 >      std::vector<AtomType*> at2Chain = atype2->allYourBase();
186 >      std::vector<AtomType*> at3Chain = atype3->allYourBase();
187 >
188 >      std::vector<AtomType*>::iterator i;
189 >      std::vector<AtomType*>::iterator j;
190 >      std::vector<AtomType*>::iterator k;
191 >
192 >      int ii = 0;
193 >      int jj = 0;
194 >      int kk = 0;
195 >      int IKscore;
196 >
197 >      std::vector<tuple3<int, int, std::vector<std::string> > > foundBends;
198 >
199 >      for (j = at2Chain.begin(); j != at2Chain.end(); j++) {
200 >        ii = 0;
201 >        for (i = at1Chain.begin(); i != at1Chain.end(); i++) {
202 >          kk = 0;
203 >          for (k = at3Chain.begin(); k != at3Chain.end(); k++) {
204 >          
205 >            IKscore = ii + kk;
206 >
207 >            std::vector<std::string> myKeys;
208 >            myKeys.push_back((*i)->getName());
209 >            myKeys.push_back((*j)->getName());
210 >            myKeys.push_back((*k)->getName());
211 >
212 >            BendType* bendType = bendTypeCont_.find(myKeys);
213 >            if (bendType) {
214 >              foundBends.push_back( make_tuple3(jj, IKscore, myKeys) );
215 >            }
216 >            kk++;
217 >          }
218 >          ii++;
219 >        }
220 >        jj++;
221 >      }
222 >      
223 >      std::sort(foundBends.begin(), foundBends.end());
224 >
225 >      int jscore = foundBends[0].first;
226 >      int ikscore = foundBends[0].second;
227 >      std::vector<std::string> theKeys = foundBends[0].third;
228 >
229 >      std::cout << "best matching bend = " << theKeys[0] << "\t" <<theKeys[1]  << "\t" << theKeys[2] << "\t(scores = "<< jscore << "\t" << ikscore << ")\n";      
230 >
231 >      BendType* bestType = bendTypeCont_.find(theKeys);  
232 >      if (bestType)
233 >        return bestType;
234 >      else {
235 >      
236 >        //if no exact match found, try wild card match
237 >        return bendTypeCont_.find(keys, wildCardAtomTypeName_);      
238 >      }
239      }
240    }
241  
242 +
243    TorsionType* ForceField::getTorsionType(const std::string &at1,
244                                            const std::string &at2,
245                                            const std::string &at3,
# Line 122 | Line 250 | namespace oopse {
250      keys.push_back(at3);    
251      keys.push_back(at4);    
252  
253 +
254 +    //try exact match first
255      TorsionType* torsionType = torsionTypeCont_.find(keys);
256      if (torsionType) {
257        return torsionType;
258      } else {
259 <      //if no exact match found, try wild card match
260 <      return torsionTypeCont_.find(keys, wildCardAtomTypeName_);
259 >
260 >      AtomType* atype1;
261 >      AtomType* atype2;
262 >      AtomType* atype3;
263 >      AtomType* atype4;
264 >      std::vector<std::string> at1key;
265 >      at1key.push_back(at1);
266 >      atype1 = atomTypeCont_.find(at1key);
267 >  
268 >      std::vector<std::string> at2key;
269 >      at2key.push_back(at2);
270 >      atype2 = atomTypeCont_.find(at2key);
271 >
272 >      std::vector<std::string> at3key;
273 >      at3key.push_back(at3);
274 >      atype3 = atomTypeCont_.find(at3key);
275 >
276 >      std::vector<std::string> at4key;
277 >      at4key.push_back(at4);
278 >      atype4 = atomTypeCont_.find(at4key);
279 >
280 >      // query atom types for their chains of responsibility
281 >      std::vector<AtomType*> at1Chain = atype1->allYourBase();
282 >      std::vector<AtomType*> at2Chain = atype2->allYourBase();
283 >      std::vector<AtomType*> at3Chain = atype3->allYourBase();
284 >      std::vector<AtomType*> at4Chain = atype4->allYourBase();
285 >
286 >      std::vector<AtomType*>::iterator i;
287 >      std::vector<AtomType*>::iterator j;
288 >      std::vector<AtomType*>::iterator k;
289 >      std::vector<AtomType*>::iterator l;
290 >
291 >      int ii = 0;
292 >      int jj = 0;
293 >      int kk = 0;
294 >      int ll = 0;
295 >      int ILscore;
296 >      int JKscore;
297 >
298 >      std::vector<tuple3<int, int, std::vector<std::string> > > foundTorsions;
299 >
300 >      for (j = at2Chain.begin(); j != at2Chain.end(); j++) {
301 >        kk = 0;
302 >        for (k = at3Chain.begin(); k != at3Chain.end(); k++) {
303 >          ii = 0;      
304 >          for (i = at1Chain.begin(); i != at1Chain.end(); i++) {
305 >            ll = 0;
306 >            for (l = at4Chain.begin(); l != at4Chain.end(); l++) {
307 >          
308 >              ILscore = ii + ll;
309 >              JKscore = jj + kk;
310 >
311 >              std::vector<std::string> myKeys;
312 >              myKeys.push_back((*i)->getName());
313 >              myKeys.push_back((*j)->getName());
314 >              myKeys.push_back((*k)->getName());
315 >              myKeys.push_back((*l)->getName());
316 >
317 >              TorsionType* torsionType = torsionTypeCont_.find(myKeys);
318 >              if (torsionType) {
319 >                foundTorsions.push_back( make_tuple3(JKscore, ILscore, myKeys) );
320 >              }
321 >              ll++;
322 >            }
323 >            ii++;
324 >          }
325 >          kk++;
326 >        }
327 >        jj++;
328 >      }
329 >      
330 >      std::sort(foundTorsions.begin(), foundTorsions.end());
331 >
332 >      int jkscore = foundTorsions[0].first;
333 >      int ilscore = foundTorsions[0].second;
334 >      std::vector<std::string> theKeys = foundTorsions[0].third;
335 >
336 >      std::cout << "best matching torsion = " << theKeys[0] << "\t" <<theKeys[1]  << "\t" << theKeys[2] << "\t" << theKeys[3] << "\t(scores = "<< jkscore << "\t" << ilscore << ")\n";
337 >
338 >      
339 >      TorsionType* bestType = torsionTypeCont_.find(theKeys);
340 >      if (bestType) {
341 >        return bestType;
342 >      } else {
343 >        //if no exact match found, try wild card match
344 >        return torsionTypeCont_.find(keys, wildCardAtomTypeName_);
345 >      }
346      }
132    
133    return torsionTypeCont_.find(keys, wildCardAtomTypeName_);
347    }
348  
349    NonBondedInteractionType* ForceField::getNonBondedInteractionType(const std::string &at1, const std::string &at2) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines