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 1759 by tim, Fri Nov 19 18:02:33 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 = 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 136 | Line 147 | void DUFF::parseAtomType(const std::string& line, int
147   }
148  
149  
150 < void DUFF::parseAtomType(const std::string& line, int lineNo){
150 > void DUFF::parseAtomType(const std::string& line, int lineNo, int& ident){
151      StringTokenizer tokenizer(line);
152 <    
142 <    if (tokenizer.countTokens() >= 4) {
143 <        atomTypeName = tokenizer.nextToken();
144 <        mass = tokenizer.nextTokenAsFloat();
145 <        epsilon = tokenizer.nextTokenAsFloat();
146 <        sigma = tokenizer.nextTokenAsFloat();
152 >    int nTokens = tokenizer.countTokens();    
153  
154 <        atomType = new AtomType();
154 >    //in AtomTypeSection, a line at least contains 5 tokens
155 >    //atomTypeName, is Directional, isLJ, isCharge and mass
156 >    if (nTokens < 5)  {
157 >                      
158 >    } else {
159 >
160 >        std::string atomTypeName = tokenizer.nextToken();
161 >        bool isDirectional = tokenizer.nextTokenAsBool();
162 >        bool isLJ = tokenizer.nextTokenAsBool();
163 >        bool isCharge = tokenizer.nextTokenAsBool();        
164 >        double mass = tokenizer.nextTokenAsDouble();
165 >        double epsilon;
166 >        double sigma;
167 >        double charge;
168 >        nTokens -= 5;
169 >
170 >        //parse epsilon and sigma
171 >        if (isLJ) {
172 >            if (nTokens >= 2) {
173 >                epsilon = tokenizer.nextTokenAsDouble();
174 >                sigma = tokenizer.nextTokenAsDouble();
175 >                nTokens -= 2;
176 >            } else {
177 >
178 >            }
179 >        }
180 >
181 >        //parse charge
182 >        if (isCharge) {
183 >            if (nTokens >= 1) {
184 >                charge = tokenizer.nextTokenAsDouble();
185 >                nTokens -= 1;
186 >            } else {
187 >
188 >            }
189 >        }
190 >        
191 >        AtomType* atomType;
192 >        if (isDirectional) {
193 >            atomType = new DirectionalAtomType();        
194 >        } else {
195 >            atomType = new AtomType();
196 >        }
197 >        
198          atomType->setName(atomTypeName);
199          atomType->setMass(mass);
200          
# Line 153 | Line 202 | void DUFF::parseAtomType(const std::string& line, int
202          //In  Lennard-Jones Force Field, we only need to set Lennard-Jones to true
203          atomType->setLennardJones();
204  
205 <        atomType->setIdent(ident);
206 <        atomType->addProperty(new DoubleGenericData("Epsilon", epsilon));                                
158 <        atomType->addProperty(new DoubleGenericData("Sigma", sigma));                                
205 >        atomType->setIdent(ident);
206 >        
207          atomType->complete();
160        //notify a new LJtype atom type is created
161        newLJtype(&ident, &sigma, &epsilon, &status);
208  
209 <        //add atom type to AtomTypeContainer
164 <        addAtomType(atomTypeName, atomType);
165 <        ++ident;
209 >        int setLJStatus;
210          
211 <    } else {
212 <        sprintf( painCave.errMsg,
213 <               "Not enough tokens when parsing Lennard-Jones Force Field : %s\n"
214 <               "in line %d : %s\n",
215 <               filename.c_str(), lineNo, line);
216 <        painCave.severity = OOPSE_ERROR;
217 <        painCave.isFatal = 1;
218 <        simError();                
211 >        //notify a new LJtype atom type is created
212 >        if (isLJ) {
213 >            newLJtype(&ident, &sigma, &epsilon, &setLJStatus);
214 >        }
215 >
216 >        int setChargeStatus;
217 >        if (isCharge) {
218 >            newChargeType(&ident, &charge, &setChargeStatus)
219 >        }
220 >
221 >        if (setLJStatus && setChargeStatus) {
222 >            //add atom type to AtomTypeContainer
223 >            addAtomType(atomTypeName, atomType);
224 >            ++ident;
225 >        } else {
226 >            //error in notifying fortran
227 >            delete atomType;
228 >        }
229      }    
230 +    
231 + }
232 +
233 +
234 + void DUFF::parseDirectionalAtomType(const std::string& line, int lineNo) {
235 +    StringTokenizer tokenizer(line);
236 +    int nTokens = tokenizer.countTokens();  
237 +    
238 +    //in irectionalAtomTypeSection, a line at least contains 6 tokens
239 +    //AtomTypeName, isDipole, isSticky, I_xx, I_yy and I_zz
240 +    if (nTokens < 6) {
241 +
242 +    } else {
243 +
244 +
245 +        std::string atomTypeName = tokenizer.nextToken();
246 +        bool isDipole = tokenizer.nextTokenAsBool();
247 +        bool isSticky = tokenizer.nextTokenAsBool();
248 +        double Ixx = tokenizer.nextTokenAsDouble();
249 +        double Iyy = tokenizer.nextTokenAsDouble();
250 +        double Izz = tokenizer.nextTokenAsDouble();
251 +        nTokens -= 6;
252 +
253 +        AtomType* atomType = getAtomType(atomTypeName);
254 +        if (atomType == NULL) {
255 +
256 +        }
257 +        
258 +        DirectionalAtomType* dAtomType = dynamic_cast<DirectionalAtomType*>(atomType);
259 +        if (dAtomType == NULL) {
260 +
261 +
262 +        }
263 +
264 +        dAtomType->setDipole(isDipole);
265 +        dAtomType->setSticky(isSticky);
266 +
267 +        Mat3x3d inertialMat;
268 +        inertialMat(0, 0) = Ixx;
269 +        inertialMat(1, 1) = Ixx;
270 +        inertialMat(2, 2) = Ixx;        
271 +        dAtomType->setI(inertialMat);
272 +
273 +        //read dipole moment
274 +        double dipole;
275 +        if (isDipole) {
276 +            if (nTokens >= 1) {
277 +                dipole = tokenizer.nextTokenAsDouble();
278 +                nTokens -= 1;
279 +            } else {
280 +
281 +            }
282 +        }
283 +
284 +        //read sticky parameters
285 +        double w0;
286 +        double v0;
287 +        double v0p;
288 +        double rl;
289 +        double ru;
290 +        double rlp;
291 +        double rup;        
292 +        if (isSticky) {
293 +            if (nTokens >= 7) {
294 +                w0 = tokenizer.nextTokenAsDouble();
295 +                v0 = tokenizer.nextTokenAsDouble();
296 +                v0p = tokenizer.nextTokenAsDouble();
297 +                rl = tokenizer.nextTokenAsDouble();
298 +                ru = tokenizer.nextTokenAsDouble();
299 +                rlp = tokenizer.nextTokenAsDouble();
300 +                rup = tokenizer.nextTokenAsDouble();    
301 +                nTokens -= 7;
302 +            } else {
303 +
304 +            }
305 +        }
306 +
307 +
308 +        //notify fotran a newDipoleType is created
309 +        int ident = dAtomType->getIdent();
310 +        int setDipoleStatus;
311 +        if (isDipole) {
312 +            newDipoleType(&ident, &dipole, &setDipoleStatus);
313 +        }              
314 +
315 +        //notify fotran a StickyType is created
316 +        int setStickyStatus;
317 +        if (isSticky) {
318 +            makeStickyType( &w0, &v0, &v0p, &rl, &ru, &rlp, &rup);
319 +        }
320 +
321 +
322 +        if (!setDipoleStatus || !setStickyStatus) {
323 +
324 +        }
325 +        
326 +    }
327   }
328  
329   void DUFF::parseBondType(const std::string& line, int lineNo){
# Line 256 | Line 407 | void DUFF::parseBondType(const std::string& line, int
407                  for (int i = 0; i < nPairs; ++i) {
408                      power = tokenizer.nextTokenAsInt();
409                      coefficient = tokenizer.nextTokenAsDouble();
410 <
260 <                    if (power < 0) {
261 <
262 <                    } else {
263 <                        pbt->setCoefficient(power, coefficient);
264 <                    }
410 >                    pbt->setCoefficient(power, coefficient);
411                  }
412              }
413              
# Line 374 | Line 520 | void DUFF::parseBendType(const std::string& line, int
520                  for (int i = 0; i < nPairs; ++i) {
521                      power = tokenizer.nextTokenAsInt();
522                      coefficient = tokenizer.nextTokenAsDouble();
523 <
378 <                    if (power < 0) {
379 <
380 <                    } else {
381 <                        pbt->setCoefficient(power, coefficient);
382 <                    }
523 >                    pbt->setCoefficient(power, coefficient);
524                  }
525              }
526              
# Line 463 | Line 604 | void DUFF::parseTorsionType(const std::string& line, i
604                  for (int i = 0; i < nPairs; ++i) {
605                      power = tokenizer.nextTokenAsInt();
606                      coefficient = tokenizer.nextTokenAsDouble();
607 <
467 <                    if (power < 0) {
468 <
469 <                    } else {
470 <                        pbt->setCoefficient(power, coefficient);
471 <                    }
607 >                    pbt->setCoefficient(power, coefficient);
608                  }
609              }
610              
# Line 480 | Line 616 | void DUFF::parseTorsionType(const std::string& line, i
616              } else {
617                  int nSets = nTokens / 3;
618    
483                double kchi;
484                int n;
485                double delta;                
619                  CharmmTorsionType* ctt = new CharmmTorsionType();
620                  
621                  for (int i = 0; i < nSets; ++i) {
622 <                    kchi = tokenizer.nextTokenAsDouble();
623 <                    n = tokenizer.nextTokenAsInt();
624 <                    delta = tokenizer.nextTokenAsDouble();
622 >                    double kchi = tokenizer.nextTokenAsDouble();
623 >                    int n = tokenizer.nextTokenAsInt();
624 >                    double delta = tokenizer.nextTokenAsDouble();
625      
626 <                    if (n < 0 || n > 6) {
494 <
495 <                    } else {
496 <                        ctt->setCharmmTorsionParameter(kchi, n, delta);
497 <                    }
626 >                    ctt->setCharmmTorsionParameter(kchi, n, delta);
627                  }
628              }
629          default:
# Line 507 | Line 636 | void DUFF::parseTorsionType(const std::string& line, i
636   }
637  
638   } //end namespace oopse
510

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines