ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/LJ_FF.cpp
(Generate patch)

Comparing trunk/mdtools/interface_implementation/LJ_FF.cpp (file contents):
Revision 215 by chuckv, Thu Dec 19 21:59:51 2002 UTC vs.
Revision 224 by mmeineke, Wed Jan 8 21:53:53 2003 UTC

# Line 10 | Line 10 | using namespace std;
10   #include "simError.h"
11  
12  
13 < #ifdef IS_MPI
13 > // Declare the structures that will be passed by the parser and  MPI
14  
15 #include "mpiForceField.h"
16
17
18 // Declare the structures that will be passed by MPI
19
15   typedef struct{
16    char name[15];
17    double mass;
18    double epslon;
19    double sigma;
20 +  int ident;
21    int last;      //  0  -> default
22 <                 //  1  -> tells nodes to stop listening
22 >                 //  1  -> in MPI: tells nodes to stop listening
23   } atomStruct;
24 +
25 + int parseAtomLJ( char *lineBuffer, int lineNum, atomStruct &info );
26 +
27 + #ifdef IS_MPI
28 +
29 + #include "mpiForceField.h"
30 +
31   MPI_Datatype mpiAtomStructType;
32  
33   #endif
34  
35  
33
36   LJ_FF::LJ_FF(){
37  
38    char fileName[200];
# Line 46 | Line 48 | LJ_FF::LJ_FF(){
48    // Init the atomStruct mpi type
49  
50    atomStruct atomProto; // mpiPrototype
51 <  int atomBC[3] = {15,3,1};  // block counts
51 >  int atomBC[3] = {15,3,2};  // block counts
52    MPI_Aint atomDspls[3];           // displacements
53    MPI_Datatype atomMbrTypes[3];    // member mpi types
54  
55    MPI_Address(&atomProto.name, &atomDspls[0]);
56    MPI_Address(&atomProto.mass, &atomDspls[1]);
57 <  MPI_Address(&atomProto.last, &atomDspls[2]);
57 >  MPI_Address(&atomProto.ident, &atomDspls[2]);
58    
59    atomMbrTypes[0] = MPI_CHAR;
60    atomMbrTypes[1] = MPI_DOUBLE;
# Line 151 | Line 153 | void LJ_FF::initializeAtoms( void ){
153        return NULL;
154      }
155      
156 < #ifdef IS_MPI
156 >
157      void add( atomStruct &info ){
158 +    
159 +      // check for duplicates
160 +      
161 +      if( !strcmp( info.name, name ) ){
162 +        sprintf( simError.painCave,
163 +                 "Duplicate LJ atom type \"%s\" found in "
164 +                 "the LJ_FF param file./n",
165 +                 name );
166 +        painCave.isFatal = 1;
167 +        simError();
168 +      }
169 +      
170        if( next != NULL ) next->add(info);
171        else{
172          next = new LinkedType();
# Line 160 | Line 174 | void LJ_FF::initializeAtoms( void ){
174          next->mass     = info.mass;
175          next->epslon   = info.epslon;
176          next->sigma    = info.sigma;
177 +        next->ident    = info.ident;
178        }
179      }
180      
181 +
182 + #ifdef IS_MPI
183 +    
184      void duplicate( atomStruct &info ){
185        strcpy(info.name, name);
186        info.mass     = mass;
187        info.epslon   = epslon;
188        info.sigma    = sigma;
189 +      info.ident    = ident;
190        info.last     = 0;
191      }
192  
# Line 178 | Line 197 | void LJ_FF::initializeAtoms( void ){
197      double mass;
198      double epslon;
199      double sigma;
200 +    int ident;
201      LinkedType* next;
202    };
203    
204    LinkedType* headAtomType;
205    LinkedType* currentAtomType;
186  LinkedType* tempAtomType;
187
188 #ifdef IS_MPI
206    atomStruct info;
207    info.last = 1; // initialize last to have the last set.
208                   // if things go well, last will be set to 0
192 #endif
193  
209  
195  char readLine[500];
196  char* the_token;
197  char* eof_test;
198  int foundAtom = 0;
199  int lineNum = 0;
210    int i;
211 <
202 <  
203 <  //////////////////////////////////////////////////
204 <  // a quick water fix
205 <
206 <  double waterI[3][3];
207 <  waterI[0][0] = 1.76958347772500;
208 <  waterI[0][1] = 0.0;
209 <  waterI[0][2] = 0.0;
210 <
211 <  waterI[1][0] = 0.0;
212 <  waterI[1][1] = 0.614537057924513;
213 <  waterI[1][2] = 0.0;
214 <
215 <  waterI[2][0] = 0.0;
216 <  waterI[2][1] = 0.0;
217 <  waterI[2][2] = 1.15504641980049;
218 <
219 <
220 <  double headI[3][3];
221 <  headI[0][0] = 1125;
222 <  headI[0][1] = 0.0;
223 <  headI[0][2] = 0.0;
224 <
225 <  headI[1][0] = 0.0;
226 <  headI[1][1] = 1125;
227 <  headI[1][2] = 0.0;
228 <
229 <  headI[2][0] = 0.0;
230 <  headI[2][1] = 0.0;
231 <  headI[2][2] = 250;
232 <
211 >  int identNum;
212    
234
235  //////////////////////////////////////////////////
236
213    Atom** the_atoms;
214    int nAtoms;
215    the_atoms = entry_plug->atoms;
# Line 245 | Line 221 | void LJ_FF::initializeAtoms( void ){
221   #endif
222      
223      // read in the atom types.
224 <    
249 <    rewind( frcFile );
224 >
225      headAtomType = new LinkedType;
251    currentAtomType = headAtomType;
226      
227 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
228 <    lineNum++;
255 <    if( eof_test == NULL ){
256 <      sprintf( painCave.errMsg, "Error in reading Atoms from force file.\n" );
257 <      painCave.isFatal = 1;
258 <      simError();
259 <    }
260 <    
261 <    
262 <    while( !foundAtom ){
263 <      while( eof_test != NULL && readLine[0] != '#' ){
264 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
265 <        lineNum++;
266 <      }
267 <      if( eof_test == NULL ){
268 <        sprintf( painCave.errMsg,
269 <                 "Error in reading Atoms from force file at line %d.\n",
270 <                 lineNum );
271 <        painCave.isFatal = 1;
272 <        simError();
273 <      }
274 <      
275 <      the_token = strtok( readLine, " ,;\t#\n" );
276 <      foundAtom = !strcmp( "AtomTypes", the_token );
277 <      
278 <      if( !foundAtom ){
279 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
280 <        lineNum++;
281 <        
282 <        if( eof_test == NULL ){
283 <          sprintf( painCave.errMsg,
284 <                   "Error in reading Atoms from force file at line %d.\n",
285 <                   lineNum );
286 <          painCave.isFatal = 1;
287 <          simError();
288 <        }
289 <      }
290 <    }
291 <    
227 >    fastFoward( "AtomTypes", "initializeAtoms" );
228 >
229      // we are now at the AtomTypes section.
230      
231      eof_test = fgets( readLine, sizeof(readLine), frcFile );
232      lineNum++;
233      
234 +    
235 +    // read a line, and start parseing out the atom types
236 +
237      if( eof_test == NULL ){
238        sprintf( painCave.errMsg,
239                 "Error in reading Atoms from force file at line %d.\n",
# Line 302 | Line 242 | void LJ_FF::initializeAtoms( void ){
242        simError();
243      }
244      
245 +    identNum = 1;
246 +    // stop reading at end of file, or at next section
247      while( readLine[0] != '#' && eof_test != NULL ){
248 <      
248 >
249 >      // toss comment lines
250        if( readLine[0] != '!' ){
251          
252 <        the_token = strtok( readLine, " \n\t,;" );
253 <        if( the_token != NULL ){
254 <          
255 <          strcpy( currentAtomType->name, the_token );
256 <          
314 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
315 <            sprintf( painCave.errMsg,
316 <                     "Error parseing AtomTypes: line %d\n", lineNum );
317 <            painCave.isFatal = 1;
318 <            simError();
319 <          }
320 <          
321 <          sscanf( the_token, "%lf", &currentAtomType->mass );
322 <          
323 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
324 <            sprintf( painCave.errMsg,
325 <                     "Error parseing AtomTypes: line %d\n", lineNum );
326 <            painCave.isFatal = 1;
327 <            simError();
328 <          }
329 <          
330 <          sscanf( the_token, "%lf", &currentAtomType->epslon );
331 <          
332 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
333 <            sprintf( painCave.errMsg,
334 <                     "Error parseing AtomTypes: line %d\n", lineNum );
335 <            painCave.isFatal = 1;
336 <            simError();
337 <          }
338 <          
339 <          sscanf( the_token, "%lf", &currentAtomType->sigma );
252 >        // the parser returns 0 if the line was blank
253 >        if( parseAtomLJ( readLine, lineNum, info ) ){
254 >          info.ident = identNum;
255 >          headAtomType->add( info );;
256 >          identNum++;
257          }
258        }
342      
343      tempAtomType = new LinkedType;
344      currentAtomType->next = tempAtomType;
345      currentAtomType = tempAtomType;
346      
259        eof_test = fgets( readLine, sizeof(readLine), frcFile );
260        lineNum++;
261      }
# Line 402 | Line 314 | void LJ_FF::initializeAtoms( void ){
314      the_atoms[i]->setMass( currentAtomType->mass );
315      the_atoms[i]->setEpslon( currentAtomType->epslon );
316      the_atoms[i]->setSigma( currentAtomType->sigma );
317 +    the_atoms[i]->setIdent( currentAtomType->ident );
318      the_atoms[i]->setLJ();
319    }
320  
# Line 458 | Line 371 | void LJ_FF::initializeTorsions( torsion_set* the_torsi
371   #endif // is_mpi
372  
373   }
374 +
375 +
376 + void LJ_FF::fastForward( char* stopText, char* searchOwner ){
377 +
378 +  int foundText = 0;
379 +  char* the_token;
380 +
381 +  rewind( frcFile );
382 +  lineNum = 0;
383 +
384 +  eof_test = fgets( readLine, sizeof(readLine), frcFile );
385 +  lineNum++;
386 +  if( eof_test == NULL ){
387 +    sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
388 +             " file is empty.\n",
389 +             searchOwner );
390 +    painCave.isFatal = 1;
391 +    simError();
392 +  }
393 +  
394 +  
395 +  while( !foundText ){
396 +    while( eof_test != NULL && readLine[0] != '#' ){
397 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
398 +      lineNum++;
399 +    }
400 +    if( eof_test == NULL ){
401 +      sprintf( painCave.errMsg,
402 +               "Error fast forwarding force file for %s at "
403 +               "line %d: file ended unexpectedly.\n",
404 +               searchOwner,
405 +               lineNum );
406 +      painCave.isFatal = 1;
407 +      simError();
408 +    }
409 +    
410 +    the_token = strtok( readLine, " ,;\t#\n" );
411 +    foundText = !strcmp( stopText, the_token );
412 +    
413 +    if( !foundText ){
414 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
415 +      lineNum++;
416 +      
417 +      if( eof_test == NULL ){
418 +        sprintf( painCave.errMsg,
419 +                 "Error fast forwarding force file for %s at "
420 +                 "line %d: file ended unexpectedly.\n",
421 +                 searchOwner,
422 +                 lineNum );
423 +        painCave.isFatal = 1;
424 +        simError();
425 +      }
426 +    }
427 +  }  
428 + }
429 +
430 +
431 +
432 + int parseAtomLJ( char *lineBuffer, int lineNum,  atomStruct &info ){
433 +
434 +  char* the_token;
435 +  
436 +  the_token = strtok( lineBuffer, " \n\t,;" );
437 +  if( the_token != NULL ){
438 +    
439 +    strcpy( info.name, the_token );
440 +          
441 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
442 +      sprintf( painCave.errMsg,
443 +               "Error parseing AtomTypes: line %d\n", lineNum );
444 +      painCave.isFatal = 1;
445 +      simError();
446 +    }
447 +    
448 +    info.mass = atof( the_token );
449 +    
450 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
451 +      sprintf( painCave.errMsg,
452 +               "Error parseing AtomTypes: line %d\n", lineNum );
453 +      painCave.isFatal = 1;
454 +      simError();
455 +    }
456 +        
457 +    info.epslon = atof( the_token );
458 +          
459 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
460 +      sprintf( painCave.errMsg,
461 +               "Error parseing AtomTypes: line %d\n", lineNum );
462 +      painCave.isFatal = 1;
463 +      simError();
464 +    }
465 +        
466 +    info.sigma = atof( the_token );
467 +    
468 +    return 1;
469 +  }
470 +  else return 0;
471 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines