ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/UseTheForce/DUFF.cpp
(Generate patch)

Comparing branches/new_design/OOPSE-3.0/src/UseTheForce/DUFF.cpp (file contents):
Revision 1757 by tim, Fri Nov 19 00:11:33 2004 UTC vs.
Revision 1765 by tim, Mon Nov 22 20:55:52 2004 UTC

# Line 25 | Line 25
25  
26   #include "UseTheForce/DUFF.hpp"
27   #include "UseTheForce/DarkSide/lj_interface.h"
28 + #include "UseTheForce/DarkSide/charge_interface.h"
29 + #include "UseTheForce/DarkSide/dipole_interface.h"
30 + #include "UseTheForce/DarkSide/sticky_interface.h"
31  
32   namespace oopse {
33  
# Line 33 | Line 36 | ForceField* createDUFF() {
36      return new DUFF();
37   }
38  
39 < //register createDUFF to ForceFieldCreator
39 > //register createDUFF to ForceFieldFactory
40   ForceFieldFactory::getInstance()->registerForceField("DUFF", createDUFF);
41  
42  
# Line 44 | Line 47 | ParseState DUFF::getSection(const std::string& section
47          case "AtomTypes" :
48              result = DUFF::AtomTypeSection;
49              break;
50 +        case "DirectionalAtomTypes" :
51 +            result = DUFF::DirectionalAtomTypeSection;
52 +            break;
53  
54          case "BondTypes" :
55              result = DUFF::BondTypeSection;
# Line 70 | Line 76 | void DUFF::parse(const std::string& filename) {
76      std::string line;
77      char buffer[bufferSize];
78      int lineNo = 0;
79 +    int atomIdent = getNAtomType() + 1;  //atom's indent begins from 1 (since only fortran's array begins from 1)
80      ParseState currentSection = DUFF::UnknownSection;
81      
82      while(ffStream.getline(buffer, bufferSize)){
# Line 83 | Line 90 | void DUFF::parse(const std::string& filename) {
90  
91              switch(currentSection) {
92                  case DUFF::AtomTypeSection :
93 <                    parseAtomType(line, lineNo);
93 >                    parseAtomType(line, lineNo, atomIdent);
94                      break;
95  
96 +                case DUFF::DirectionalAtomTypeSection :
97 +                    parseDirectionalAtomType(line, lineNo);
98 +                    break;
99 +                    
100                  case DUFF::BondTypeSection :
101                      parseBondType(line, lineNo);
102                      break;
# Line 135 | Line 146 | void DUFF::parse(const std::string& filename) {
146      delete ffStream;
147   }
148  
149 <
139 < void DUFF::parseAtomType(const std::string& line, int lineNo){
149 > void DUFF::parseAtomType(const std::string& line, int lineNo, int& ident){
150      StringTokenizer tokenizer(line);
151 <    
142 <    if (tokenizer.countTokens() >= 4) {
143 <        atomTypeName = tokenizer.nextToken();
144 <        mass = tokenizer.nextTokenAsFloat();
145 <        epsilon = tokenizer.nextTokenAsFloat();
146 <        sigma = tokenizer.nextTokenAsFloat();
151 >    int nTokens = tokenizer.countTokens();    
152  
153 <        atomType = new AtomType();
153 >    //in AtomTypeSection, a line at least contains 5 tokens
154 >    //atomTypeName, is Directional, isLJ, isCharge and mass
155 >    if (nTokens < 5)  {
156 >                      
157 >    } else {
158 >
159 >        std::string atomTypeName = tokenizer.nextToken();
160 >        bool isDirectional = tokenizer.nextTokenAsBool();
161 >        bool isLJ = tokenizer.nextTokenAsBool();
162 >        bool isCharge = tokenizer.nextTokenAsBool();        
163 >        double mass = tokenizer.nextTokenAsDouble();
164 >        double epsilon;
165 >        double sigma;
166 >        double charge;
167 >        nTokens -= 5;
168 >
169 >        //parse epsilon and sigma
170 >        if (isLJ) {
171 >            if (nTokens >= 2) {
172 >                epsilon = tokenizer.nextTokenAsDouble();
173 >                sigma = tokenizer.nextTokenAsDouble();
174 >                nTokens -= 2;
175 >            } else {
176 >
177 >            }
178 >        }
179 >
180 >        //parse charge
181 >        if (isCharge) {
182 >            if (nTokens >= 1) {
183 >                charge = tokenizer.nextTokenAsDouble();
184 >                nTokens -= 1;
185 >            } else {
186 >
187 >            }
188 >        }
189 >        
190 >        AtomType* atomType;
191 >        if (isDirectional) {
192 >            atomType = new DirectionalAtomType();        
193 >        } else {
194 >            atomType = new AtomType();
195 >        }
196 >        
197          atomType->setName(atomTypeName);
198          atomType->setMass(mass);
199          
200 <        //by default, all of the properties in AtomTypeProperties is set to 0
201 <        //In  Lennard-Jones Force Field, we only need to set Lennard-Jones to true
202 <        atomType->setLennardJones();
200 >        if (isLJ) {
201 >            atomType->setLennardJones();
202 >        }
203  
204 <        atomType->setIdent(ident);
205 <        atomType->addProperty(new DoubleGenericData("Epsilon", epsilon));                                
206 <        atomType->addProperty(new DoubleGenericData("Sigma", sigma));                                
204 >        if (isCharge) {
205 >            atomType->setCharge();
206 >        }
207 >        
208 >        atomType->setIdent(ident);
209 >        
210          atomType->complete();
160        //notify a new LJtype atom type is created
161        newLJtype(&ident, &sigma, &epsilon, &status);
211  
212 <        //add atom type to AtomTypeContainer
164 <        addAtomType(atomTypeName, atomType);
165 <        ++ident;
212 >        int setLJStatus;
213          
214 <    } else {
215 <        sprintf( painCave.errMsg,
216 <               "Not enough tokens when parsing Lennard-Jones Force Field : %s\n"
217 <               "in line %d : %s\n",
218 <               filename.c_str(), lineNo, line);
219 <        painCave.severity = OOPSE_ERROR;
220 <        painCave.isFatal = 1;
221 <        simError();                
214 >        //notify a new LJtype atom type is created
215 >        if (isLJ) {
216 >            newLJtype(&ident, &sigma, &epsilon, &setLJStatus);
217 >        }
218 >
219 >        int setChargeStatus;
220 >        if (isCharge) {
221 >            newChargeType(&ident, &charge, &setChargeStatus)
222 >        }
223 >
224 >        if (setLJStatus && setChargeStatus) {
225 >            //add atom type to AtomTypeContainer
226 >            addAtomType(atomTypeName, atomType);
227 >            ++ident;
228 >        } else {
229 >            //error in notifying fortran
230 >            delete atomType;
231 >        }
232      }    
233 +    
234 + }
235 +
236 +
237 + void DUFF::parseDirectionalAtomType(const std::string& line, int lineNo) {
238 +    StringTokenizer tokenizer(line);
239 +    int nTokens = tokenizer.countTokens();  
240 +    
241 +    //in DirectionalAtomTypeSection, a line at least contains 6 tokens
242 +    //AtomTypeName, isDipole, isSticky, I_xx, I_yy and I_zz
243 +    if (nTokens < 6) {
244 +        std::cerr << "Not enought tokens" << std::endl;
245 +    } else {
246 +
247 +
248 +        std::string atomTypeName = tokenizer.nextToken();
249 +        bool isDipole = tokenizer.nextTokenAsBool();
250 +        bool isSticky = tokenizer.nextTokenAsBool();
251 +        double Ixx = tokenizer.nextTokenAsDouble();
252 +        double Iyy = tokenizer.nextTokenAsDouble();
253 +        double Izz = tokenizer.nextTokenAsDouble();
254 +        nTokens -= 6;
255 +
256 +        AtomType* atomType = getAtomType(atomTypeName);
257 +        if (atomType == NULL) {
258 +
259 +        }
260 +        
261 +        DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
262 +        if (dAtomType == NULL) {
263 +
264 +
265 +        }
266 +
267 +        if (isDipole) {
268 +            dAtomType->setDipole();
269 +        }
270 +
271 +        if (isSticky) {
272 +            dAtomType->setSticky();
273 +        }
274 +        
275 +        Mat3x3d inertialMat;
276 +        inertialMat(0, 0) = Ixx;
277 +        inertialMat(1, 1) = Iyy;
278 +        inertialMat(2, 2) = Izz;        
279 +        dAtomType->setI(inertialMat);
280 +
281 +        //read dipole moment
282 +        double dipole;
283 +        if (isDipole) {
284 +            if (nTokens >= 1) {
285 +                dipole = tokenizer.nextTokenAsDouble();
286 +                nTokens -= 1;
287 +            } else {
288 +
289 +            }
290 +        }
291 +
292 +        //read sticky parameters
293 +        double w0;
294 +        double v0;
295 +        double v0p;
296 +        double rl;
297 +        double ru;
298 +        double rlp;
299 +        double rup;        
300 +        if (isSticky) {
301 +            if (nTokens >= 7) {
302 +                w0 = tokenizer.nextTokenAsDouble();
303 +                v0 = tokenizer.nextTokenAsDouble();
304 +                v0p = tokenizer.nextTokenAsDouble();
305 +                rl = tokenizer.nextTokenAsDouble();
306 +                ru = tokenizer.nextTokenAsDouble();
307 +                rlp = tokenizer.nextTokenAsDouble();
308 +                rup = tokenizer.nextTokenAsDouble();    
309 +                nTokens -= 7;
310 +            } else {
311 +
312 +            }
313 +        }
314 +
315 +
316 +        //notify fotran a newDipoleType is created
317 +        int ident = dAtomType->getIdent();
318 +        int setDipoleStatus;
319 +        if (isDipole) {
320 +            newDipoleType(&ident, &dipole, &setDipoleStatus);
321 +        }              
322 +
323 +        //notify fotran a StickyType is created
324 +        int setStickyStatus;
325 +        if (isSticky) {
326 +            makeStickyType( &w0, &v0, &v0p, &rl, &ru, &rlp, &rup);
327 +        }
328 +
329 +
330 +        if (!setDipoleStatus || !setStickyStatus) {
331 +
332 +        }
333 +        
334 +    }
335   }
336  
337   void DUFF::parseBondType(const std::string& line, int lineNo){
# Line 256 | Line 415 | void DUFF::parseBondType(const std::string& line, int
415                  for (int i = 0; i < nPairs; ++i) {
416                      power = tokenizer.nextTokenAsInt();
417                      coefficient = tokenizer.nextTokenAsDouble();
418 <
260 <                    if (power < 0) {
261 <
262 <                    } else {
263 <                        pbt->setCoefficient(power, coefficient);
264 <                    }
418 >                    pbt->setCoefficient(power, coefficient);
419                  }
420              }
421              
# Line 374 | Line 528 | void DUFF::parseBendType(const std::string& line, int
528                  for (int i = 0; i < nPairs; ++i) {
529                      power = tokenizer.nextTokenAsInt();
530                      coefficient = tokenizer.nextTokenAsDouble();
531 <
378 <                    if (power < 0) {
379 <
380 <                    } else {
381 <                        pbt->setCoefficient(power, coefficient);
382 <                    }
531 >                    pbt->setCoefficient(power, coefficient);
532                  }
533              }
534              
# Line 463 | Line 612 | void DUFF::parseTorsionType(const std::string& line, i
612                  for (int i = 0; i < nPairs; ++i) {
613                      power = tokenizer.nextTokenAsInt();
614                      coefficient = tokenizer.nextTokenAsDouble();
615 <
467 <                    if (power < 0) {
468 <
469 <                    } else {
470 <                        pbt->setCoefficient(power, coefficient);
471 <                    }
615 >                    pbt->setCoefficient(power, coefficient);
616                  }
617              }
618              
# Line 480 | Line 624 | void DUFF::parseTorsionType(const std::string& line, i
624              } else {
625                  int nSets = nTokens / 3;
626    
483                double kchi;
484                int n;
485                double delta;                
627                  CharmmTorsionType* ctt = new CharmmTorsionType();
628                  
629                  for (int i = 0; i < nSets; ++i) {
630 <                    kchi = tokenizer.nextTokenAsDouble();
631 <                    n = tokenizer.nextTokenAsInt();
632 <                    delta = tokenizer.nextTokenAsDouble();
630 >                    double kchi = tokenizer.nextTokenAsDouble();
631 >                    int n = tokenizer.nextTokenAsInt();
632 >                    double delta = tokenizer.nextTokenAsDouble();
633      
634 <                    if (n < 0 || n > 6) {
494 <
495 <                    } else {
496 <                        ctt->setCharmmTorsionParameter(kchi, n, delta);
497 <                    }
634 >                    ctt->setCharmmTorsionParameter(kchi, n, delta);
635                  }
636              }
637          default:
# Line 507 | Line 644 | void DUFF::parseTorsionType(const std::string& line, i
644   }
645  
646   } //end namespace oopse
510

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines