ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE_old/src/mdtools/libmdCode/TraPPE_ExFF.cpp
(Generate patch)

Comparing trunk/OOPSE_old/src/mdtools/libmdCode/TraPPE_ExFF.cpp (file contents):
Revision 270 by mmeineke, Fri Feb 14 17:08:46 2003 UTC vs.
Revision 296 by mmeineke, Thu Mar 6 20:05:39 2003 UTC

# Line 9 | Line 9 | using namespace std;
9   #include "SRI.hpp"
10   #include "simError.h"
11  
12 + #include <fortranWrappers.hpp>
13  
14   #ifdef IS_MPI
14
15   #include "mpiForceField.h"
16 + #endif // is_mpi
17  
18 + namespace TPE {  // restrict the access of the folowing to this file only.
19  
18 // Declare the structures that will be passed by MPI
20  
21 < typedef struct{
22 <  char name[15];
23 <  double mass;
24 <  double epslon;
25 <  double sigma;
26 <  double dipole;
27 <  int isDipole;
28 <  int last;      //  0  -> default
29 <                 //  1  -> tells nodes to stop listening
30 < } atomStruct;
31 < MPI_Datatype mpiAtomStructType;
21 >  // Declare the structures that will be passed by MPI
22 >  
23 >  typedef struct{
24 >    char name[15];
25 >    double mass;
26 >    double epslon;
27 >    double sigma;
28 >    double dipole;
29 >    double w0;
30 >    double v0;
31 >    int isSSD;
32 >    int isDipole;
33 >    int ident;
34 >    int last;      //  0  -> default
35 >                   //  1  -> tells nodes to stop listening
36 >  } atomStruct;
37 >  
38 >  
39 >  typedef struct{
40 >    char nameA[15];
41 >    char nameB[15];
42 >    char type[30];
43 >    double d0;
44 >    int last;      //  0  -> default
45 >                   //  1  -> tells nodes to stop listening
46 >  } bondStruct;
47 >  
48 >  
49 >  typedef struct{
50 >    char nameA[15];
51 >    char nameB[15];
52 >    char nameC[15];
53 >    char type[30];
54 >    double k1, k2, k3, t0;
55 >    int last;      //  0  -> default
56 >                   //  1  -> tells nodes to stop listening
57 >  } bendStruct;
58 >  
59  
60 < typedef struct{
61 <  char nameA[15];
62 <  char nameB[15];
63 <  char type[30];
64 <  double d0;
65 <  int last;      //  0  -> default
66 <                 //  1  -> tells nodes to stop listening
67 < } bondStruct;
68 < MPI_Datatype mpiBondStructType;
69 <
70 < typedef struct{
71 <  char nameA[15];
72 <  char nameB[15];
73 <  char nameC[15];
74 <  char type[30];
75 <  double k1, k2, k3, t0;
76 <  int last;      //  0  -> default
77 <                 //  1  -> tells nodes to stop listening
78 < } bendStruct;
51 < MPI_Datatype mpiBendStructType;
60 >  typedef struct{
61 >    char nameA[15];
62 >    char nameB[15];
63 >    char nameC[15];
64 >    char nameD[15];
65 >    char type[30];
66 >    double k1, k2, k3, k4;
67 >    int last;      //  0  -> default
68 >                   //  1  -> tells nodes to stop listening
69 >  } torsionStruct;
70 >  
71 >  
72 >  int parseAtom(    char *lineBuffer, int lineNum, atomStruct     &info );
73 >  int parseBond(    char *lineBuffer, int lineNum, bondStruct     &info );
74 >  int parseBend(    char *lineBuffer, int lineNum, bendStruct     &info );
75 >  int parseTorsion( char *lineBuffer, int lineNum, torsionStruct  &info );
76 >  
77 >  
78 > #ifdef IS_MPI
79  
80 < typedef struct{
81 <  char nameA[15];
82 <  char nameB[15];
83 <  char nameC[15];
57 <  char nameD[15];
58 <  char type[30];
59 <  double k1, k2, k3, k4;
60 <  int last;      //  0  -> default
61 <                 //  1  -> tells nodes to stop listening
62 < } torsionStruct;
63 < MPI_Datatype mpiTorsionStructType;
80 >  MPI_Datatype mpiAtomStructType;
81 >  MPI_Datatype mpiBondStructType;
82 >  MPI_Datatype mpiBendStructType;
83 >  MPI_Datatype mpiTorsionStructType;
84  
85   #endif
86  
87 + } // namespace
88  
89 + using namespace TPE;
90  
91 +
92 + //****************************************************************
93 + // begins the actual forcefield stuff.  
94 + //****************************************************************
95 +
96 +
97   TraPPE_ExFF::TraPPE_ExFF(){
98  
99    char fileName[200];
# Line 74 | Line 102 | TraPPE_ExFF::TraPPE_ExFF(){
102    char temp[200];
103    char errMsg[1000];
104  
105 +  // do the funtion wrapping
106 +  wrapMeFF( this );
107 +
108 +
109   #ifdef IS_MPI
110    int i;
111    
112 <   // **********************************************************************
112 >  // **********************************************************************
113    // Init the atomStruct mpi type
114  
115    atomStruct atomProto; // mpiPrototype
116 <  int atomBC[3] = {15,4,2};  // block counts
116 >  int atomBC[3] = {15,6,4};  // block counts
117    MPI_Aint atomDspls[3];           // displacements
118    MPI_Datatype atomMbrTypes[3];    // member mpi types
119  
120    MPI_Address(&atomProto.name, &atomDspls[0]);
121    MPI_Address(&atomProto.mass, &atomDspls[1]);
122 <  MPI_Address(&atomProto.isDipole, &atomDspls[2]);
122 >  MPI_Address(&atomProto.isSSD, &atomDspls[2]);
123    
124    atomMbrTypes[0] = MPI_CHAR;
125    atomMbrTypes[1] = MPI_DOUBLE;
# Line 237 | Line 269 | void TraPPE_ExFF::initializeAtoms( void ){
269   #endif // is_mpi
270   }
271  
272 + void TraPPE_ExFF::doForces( int calcPot ){
273 +
274 +  int i, isError;
275 +  double* frc;
276 +  double* pos;
277 +  double* tau;
278 +  short int passedCalcPot = (short int)calcPot;
279 +
280 +  // forces are zeroed here, before any are acumulated.
281 +  // NOTE: do not rezero the forces in Fortran.
282 +
283 +  for(i=0; i<entry_plug->n_atoms; i++){
284 +    entry_plug->atoms[i]->zeroForces();
285 +  }
286 +
287 +  frc = Atom::getFrcArray();
288 +  pos = Atom::getPosArray();
289 +  tau = entry_plug->tau;
290 +
291 +  isError = 0;
292 +  fortranForceLoop( pos, frc, &(entry_plug->lrPot), tau,
293 +                    &passedCalcPot, &isError );
294 +
295 +
296 +  if( isError ){
297 +    sprintf( painCave.errMsg,
298 +             "Error returned from the fortran force calculation.\n" );
299 +    painCave.isFatal = 1;
300 +    simError();
301 +  }
302 +
303 + #ifdef IS_MPI
304 +  sprintf( checkPointMsg,
305 +           "successfully returned from the force calculation.\n" );
306 +  MPIcheckPoint();
307 + #endif // is_mpi
308 +
309 + }
310 +  
311 + void TraPPE_ExFF::initFortran( void ){
312 +  
313 +  int nLocal = entry_plug->n_atoms;
314 +  int *ident;
315 +  int isError;
316 +  int i;
317 +
318 +  ident = new int[nLocal];
319 +
320 +  for(i=0; i<nLocal; i++){
321 +    ident[i] = entry_plug->atoms[i]->getIdent();
322 +  }
323 +
324 +  isError = 0;
325 +  initfortran( &nLocal, ident, &isError );
326 +  
327 +  if(isError){
328 +    sprintf( painCave.errMsg,
329 +             "TraPPE_ExFF error: There was an error initializing the component list in fortran.\n" );
330 +    painCave.isFatal = 1;
331 +    simError();
332 +  }
333 +
334 +  
335 + #ifdef IS_MPI
336 +  sprintf( checkPointMsg, "TraPPE_ExFF successfully initialized the fortran component list.\n" );
337 +  MPIcheckPoint();
338 + #endif // is_mpi
339 +  
340 +  delete[] ident;
341 +
342 + }
343 +
344 +
345 +
346 +
347   void TraPPE_ExFF::initializeAtoms( void ){
348    
349    class LinkedType {
# Line 253 | Line 360 | void TraPPE_ExFF::initializeAtoms( void ){
360        return NULL;
361      }
362      
256 #ifdef IS_MPI
363      void add( atomStruct &info ){
364 +
365 +      // check for duplicates
366 +      
367 +      if( !strcmp( info.name, name ) ){
368 +        sprintf( painCave.errMsg,
369 +                 "Duplicate TraPPE_Ex atom type \"%s\" found in "
370 +                 "the TraPPE_ExFF param file./n",
371 +                 name );
372 +        painCave.isFatal = 1;
373 +        simError();
374 +      }
375 +
376        if( next != NULL ) next->add(info);
377        else{
378          next = new LinkedType();
379          strcpy(next->name, info.name);
380 <        next->isDipole = info.dipole;
380 >        next->isDipole = info.isDipole;
381 >        next->isSSD    = info.isSSD;
382          next->mass     = info.mass;
383          next->epslon   = info.epslon;
384          next->sigma    = info.sigma;
385          next->dipole   = info.dipole;
386 +        next->w0       = info.w0;
387 +        next->v0       = info.v0;
388 +        next->ident    = info.ident;
389        }
390      }
391 +
392 + #ifdef IS_MPI
393      
394      void duplicate( atomStruct &info ){
395        strcpy(info.name, name);
396 <      info.isDipole = dipole;
396 >      info.isDipole = isDipole;
397 >      info.isSSD    = isSSD;
398        info.mass     = mass;
399        info.epslon   = epslon;
400        info.sigma    = sigma;
401        info.dipole   = dipole;
402 +      info.w0       = w0;
403 +      info.v0       = v0;
404        info.last     = 0;
405      }
406  
# Line 282 | Line 409 | void TraPPE_ExFF::initializeAtoms( void ){
409  
410      char name[15];
411      int isDipole;
412 +    int isSSD;
413      double mass;
414      double epslon;
415      double sigma;
416      double dipole;
417 +    double w0;
418 +    double v0;
419 +    int ident;
420      LinkedType* next;
421    };
422    
423    LinkedType* headAtomType;
424    LinkedType* currentAtomType;
294  LinkedType* tempAtomType;
295
296 #ifdef IS_MPI
425    atomStruct info;
426    info.last = 1; // initialize last to have the last set.
427                   // if things go well, last will be set to 0
428 < #endif
428 >
429    
430  
303  char readLine[500];
304  char* the_token;
305  char* eof_test;
306  int foundAtom = 0;
307  int lineNum = 0;
431    int i;
432 <
432 >  int identNum;
433    
434 +  Atom** the_atoms;
435 +  int nAtoms;
436 +  the_atoms = entry_plug->atoms;
437 +  nAtoms = entry_plug->n_atoms;
438 +  
439 +  
440    //////////////////////////////////////////////////
441    // a quick water fix
442  
# Line 342 | Line 471 | void TraPPE_ExFF::initializeAtoms( void ){
471  
472    //////////////////////////////////////////////////
473  
474 <  Atom** the_atoms;
346 <  int nAtoms;
347 <  the_atoms = entry_plug->atoms;
348 <  nAtoms = entry_plug->n_atoms;
349 <  
350 <  
474 >
475   #ifdef IS_MPI
476    if( worldRank == 0 ){
477   #endif
478      
479      // read in the atom types.
480 <    
357 <    rewind( frcFile );
480 >
481      headAtomType = new LinkedType;
359    currentAtomType = headAtomType;
482      
483 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
484 <    lineNum++;
363 <    if( eof_test == NULL ){
364 <      sprintf( painCave.errMsg, "Error in reading Atoms from force file.\n" );
365 <      painCave.isFatal = 1;
366 <      simError();
367 <    }
368 <    
369 <    
370 <    while( !foundAtom ){
371 <      while( eof_test != NULL && readLine[0] != '#' ){
372 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
373 <        lineNum++;
374 <      }
375 <      if( eof_test == NULL ){
376 <        sprintf( painCave.errMsg,
377 <                 "Error in reading Atoms from force file at line %d.\n",
378 <                 lineNum );
379 <        painCave.isFatal = 1;
380 <        simError();
381 <      }
382 <      
383 <      the_token = strtok( readLine, " ,;\t#\n" );
384 <      foundAtom = !strcmp( "AtomTypes", the_token );
385 <      
386 <      if( !foundAtom ){
387 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
388 <        lineNum++;
389 <        
390 <        if( eof_test == NULL ){
391 <          sprintf( painCave.errMsg,
392 <                   "Error in reading Atoms from force file at line %d.\n",
393 <                   lineNum );
394 <          painCave.isFatal = 1;
395 <          simError();
396 <        }
397 <      }
398 <    }
399 <    
483 >    fastForward( "AtomTypes", "initializeAtoms" );
484 >
485      // we are now at the AtomTypes section.
486      
487      eof_test = fgets( readLine, sizeof(readLine), frcFile );
488      lineNum++;
489      
490 +    
491 +    // read a line, and start parseing out the atom types
492 +
493      if( eof_test == NULL ){
494        sprintf( painCave.errMsg,
495                 "Error in reading Atoms from force file at line %d.\n",
# Line 410 | Line 498 | void TraPPE_ExFF::initializeAtoms( void ){
498        simError();
499      }
500      
501 +    identNum = 1;
502 +    // stop reading at end of file, or at next section
503      while( readLine[0] != '#' && eof_test != NULL ){
504 <      
504 >
505 >      // toss comment lines
506        if( readLine[0] != '!' ){
507          
508 <        the_token = strtok( readLine, " \n\t,;" );
509 <        if( the_token != NULL ){
510 <          
511 <          strcpy( currentAtomType->name, the_token );
512 <          
422 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
423 <            sprintf( painCave.errMsg,
424 <                     "Error parseing AtomTypes: line %d\n", lineNum );
425 <            painCave.isFatal = 1;
426 <            simError();
427 <          }
428 <          
429 <          sscanf( the_token, "%d", &currentAtomType->isDipole );
430 <          
431 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
432 <            sprintf( painCave.errMsg,
433 <                     "Error parseing AtomTypes: line %d\n", lineNum );
434 <            painCave.isFatal = 1;
435 <            simError();
436 <          }
437 <          
438 <          sscanf( the_token, "%lf", &currentAtomType->mass );
439 <          
440 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
441 <            sprintf( painCave.errMsg,
442 <                     "Error parseing AtomTypes: line %d\n", lineNum );
443 <            painCave.isFatal = 1;
444 <            simError();
445 <          }
446 <          
447 <          sscanf( the_token, "%lf", &currentAtomType->epslon );
448 <          
449 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
450 <            sprintf( painCave.errMsg,
451 <                     "Error parseing AtomTypes: line %d\n", lineNum );
452 <            painCave.isFatal = 1;
453 <            simError();
454 <          }
455 <          
456 <          sscanf( the_token, "%lf", &currentAtomType->sigma );
457 <          
458 <          if( currentAtomType->isDipole ){
459 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
460 <              sprintf( painCave.errMsg,
461 <                       "Error parseing AtomTypes: line %d\n",
462 <                       lineNum );
463 <              painCave.isFatal = 1;
464 <              simError();
465 <            }
466 <            
467 <            sscanf( the_token, "%lf", &currentAtomType->dipole );
468 <          }
508 >        // the parser returns 0 if the line was blank
509 >        if( parseAtom( readLine, lineNum, info ) ){
510 >          info.ident = identNum;
511 >          headAtomType->add( info );;
512 >          identNum++;
513          }
514        }
471      
472      tempAtomType = new LinkedType;
473      currentAtomType->next = tempAtomType;
474      currentAtomType = tempAtomType;
475      
515        eof_test = fgets( readLine, sizeof(readLine), frcFile );
516        lineNum++;
517      }
# Line 482 | Line 521 | void TraPPE_ExFF::initializeAtoms( void ){
521      // send out the linked list to all the other processes
522  
523      sprintf( checkPointMsg,
524 <             "TraPPE_Ex atom structures read successfully." );
524 >             "TraPPE_ExFF atom structures read successfully." );
525      MPIcheckPoint();
526  
527 <    currentAtomType = headAtomType;
527 >    currentAtomType = headAtomType->next; //skip the first element who is a place holder.
528      while( currentAtomType != NULL ){
529        currentAtomType->duplicate( info );
530 +
531 +
532 +
533        sendFrcStruct( &info, mpiAtomStructType );
534 +
535 +      sprintf( checkPointMsg,
536 +               "successfully sent TraPPE_Ex force type: \"%s\"\n",
537 +               info.name );
538 +      MPIcheckPoint();
539 +
540        currentAtomType = currentAtomType->next;
541      }
542      info.last = 1;
# Line 504 | Line 552 | void TraPPE_ExFF::initializeAtoms( void ){
552  
553      headAtomType = new LinkedType;
554      recieveFrcStruct( &info, mpiAtomStructType );
555 +    
556      while( !info.last ){
557  
558 +
559 +
560        headAtomType->add( info );
561 +      
562 +      MPIcheckPoint();
563 +
564        recieveFrcStruct( &info, mpiAtomStructType );
565      }
566    }
567   #endif // is_mpi
568  
569 +  // call new A_types in fortran
570    
571 +  int isError;
572 +  
573 +  // dummy variables
574 +  
575 +  int isGB = 0;
576 +  int isLJ = 1;
577 +  
578 +  
579 +  currentAtomType = headAtomType;
580 +  while( currentAtomType != NULL ){
581 +    
582 +    if( currentAtomType->name[0] != '\0' ){
583 +      isError = 0;
584 +          newTPEtype( &(currentAtomType->ident),
585 +                      &(currentAtomType->mass),
586 +                      &(currentAtomType->epslon),
587 +                      &(currentAtomType->sigma),
588 +                      &isLJ,
589 +                      &(currentAtomType->isSSD),
590 +                      &(currentAtomType->isDipole),
591 +                      &isGB,
592 +                      &(currentAtomType->w0),
593 +                      &(currentAtomType->v0),
594 +                      &(currentAtomType->dipole),
595 +                      &isError );
596 +      if( isError ){
597 +        sprintf( painCave.errMsg,
598 +                 "Error initializing the \"%s\" atom type in fortran\n",
599 +                 currentAtomType->name );
600 +        painCave.isFatal = 1;
601 +        simError();
602 +      }
603 +    }
604 +    currentAtomType = currentAtomType->next;
605 +  }
606 +      
607 + #ifdef IS_MPI
608 +  sprintf( checkPointMsg,
609 +           "TraPPE_ExFF atom structures successfully sent to fortran\n" );
610 +  MPIcheckPoint();
611 + #endif // is_mpi
612 +
613 +  
614    // initialize the atoms
615    
616 +  double bigSigma = 0.0;
617    DirectionalAtom* dAtom;
618  
619    for( i=0; i<nAtoms; i++ ){
# Line 533 | Line 632 | void TraPPE_ExFF::initializeAtoms( void ){
632      the_atoms[i]->setSigma( currentAtomType->sigma );
633      the_atoms[i]->setLJ();
634  
635 +    if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma;
636 +
637      if( currentAtomType->isDipole ){
638        if( the_atoms[i]->isDirectional() ){
639          
# Line 581 | Line 682 | void TraPPE_ExFF::initializeAtoms( void ){
682        }
683      }
684    }
685 +
686 + #ifdef IS_MPI
687 +  double tempBig = bigSigma;
688 +  MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX );
689 + #endif  //is_mpi
690 +
691 +  //calc rCut and rList
692 +
693 +  entry_plug->rCut = 2.5 * bigSigma;
694 +  
695 +  if(entry_plug->rCut > (entry_plug->box_x / 2.0))
696 +    entry_plug->rCut = entry_plug->box_x / 2.0;
697 +  
698 +  if(entry_plug->rCut > (entry_plug->box_y / 2.0))
699 +    entry_plug->rCut = entry_plug->box_y / 2.0;
700 +  
701 +  if(entry_plug->rCut > (entry_plug->box_z / 2.0))
702 +    entry_plug->rCut = entry_plug->box_z / 2.0;
703  
704 +  entry_plug->rList = entry_plug->rCut + 1.0;
705  
706 +
707    // clean up the memory
708    
709    delete headAtomType;
# Line 592 | Line 713 | void TraPPE_ExFF::initializeAtoms( void ){
713    MPIcheckPoint();
714   #endif // is_mpi
715  
716 +  initFortran();
717 +  entry_plug->refreshSim();
718 +
719   }
720  
721   void TraPPE_ExFF::initializeBonds( bond_pair* the_bonds ){
# Line 613 | Line 737 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
737        return NULL;
738      }
739      
740 < #ifdef IS_MPI
740 >
741      void add( bondStruct &info ){
742 +      
743 +      // check for duplicates
744 +      int dup = 0;
745 +
746 +      if( !strcmp(nameA, info.nameA ) && !strcmp( nameB, info.nameB ) ) dup = 1;
747 +      if( !strcmp(nameA, info.nameB ) && !strcmp( nameB, info.nameA ) ) dup = 1;
748 +      
749 +      if(dup){
750 +        sprintf( painCave.errMsg,
751 +                 "Duplicate TraPPE_Ex bond type \"%s - %s\" found in "
752 +                 "the TraPPE_ExFF param file./n",
753 +                 nameA, nameB );
754 +        painCave.isFatal = 1;
755 +        simError();
756 +      }
757 +
758 +        
759        if( next != NULL ) next->add(info);
760        else{
761          next = new LinkedType();
# Line 625 | Line 766 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
766        }
767      }
768      
769 + #ifdef IS_MPI
770      void duplicate( bondStruct &info ){
771        strcpy(info.nameA, nameA);
772        strcpy(info.nameB, nameB);
# Line 648 | Line 790 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
790    
791    LinkedType* headBondType;
792    LinkedType* currentBondType;
651  LinkedType* tempBondType;
652
653 #ifdef IS_MPI
793    bondStruct info;
794    info.last = 1; // initialize last to have the last set.
795                   // if things go well, last will be set to 0
657 #endif
796  
659  char readLine[500];
660  char* the_token;
661  char* eof_test;
662  int foundBond = 0;
663  int lineNum = 0;
664  int i, a, b;
665  char* atomA;
666  char* atomB;
667
797    SRI **the_sris;
798    Atom** the_atoms;
799    int nBonds;
# Line 672 | Line 801 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
801    the_atoms = entry_plug->atoms;
802    nBonds = entry_plug->n_bonds;
803  
804 +  int i, a, b;
805 +  char* atomA;
806 +  char* atomB;
807    
808   #ifdef IS_MPI
809    if( worldRank == 0 ){
# Line 679 | Line 811 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
811      
812      // read in the bond types.
813      
682    rewind( frcFile );
814      headBondType = new LinkedType;
684    currentBondType = headBondType;
815      
816 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
816 >    fastForward( "BondTypes", "initializeBonds" );
817 >
818 >    // we are now at the bondTypes section
819 >
820 >    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
821      lineNum++;
688    if( eof_test == NULL ){
689      sprintf( painCave.errMsg, "Error in reading Bonds from force file.\n" );
690      painCave.isFatal = 1;
691      simError();
692    }
822      
823      
824 <    while( !foundBond ){
825 <      while( eof_test != NULL && readLine[0] != '#' ){
697 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
698 <        lineNum++;
699 <      }
700 <      if( eof_test == NULL ){
701 <        sprintf( painCave.errMsg,
702 <                 "Error in reading Bonds from force file at line %d.\n",
703 <                 lineNum );
704 <        painCave.isFatal = 1;
705 <        simError();
706 <      }
707 <      
708 <      the_token = strtok( readLine, " ,;\t#\n" );
709 <      foundBond = !strcmp( "BondTypes", the_token );
710 <      
711 <      if( !foundBond ){
712 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
713 <        lineNum++;
714 <        
715 <        if( eof_test == NULL ){
716 <          sprintf( painCave.errMsg,
717 <                   "Error in reading Bonds from force file at line %d.\n",
718 <                   lineNum );
719 <          painCave.isFatal = 1;
720 <          simError();
721 <        }
722 <      }
723 <    }
724 <    
725 <    // we are now at the BondTypes section.
726 <    
727 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
728 <    lineNum++;
729 <    
824 >    // read a line, and start parseing out the atom types
825 >
826      if( eof_test == NULL ){
827        sprintf( painCave.errMsg,
828 <               "Error in reading Bonds from force file at line %d.\n",
828 >               "Error in reading bonds from force file at line %d.\n",
829                 lineNum );
830        painCave.isFatal = 1;
831        simError();
832      }
833      
834 +    // stop reading at end of file, or at next section
835      while( readLine[0] != '#' && eof_test != NULL ){
836 <      
836 >
837 >      // toss comment lines
838        if( readLine[0] != '!' ){
839          
840 <        the_token = strtok( readLine, " \n\t,;" );
841 <        if( the_token != NULL ){
842 <          
745 <          strcpy( currentBondType->nameA, the_token );
746 <          
747 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
748 <            sprintf( painCave.errMsg,
749 <                     "Error parseing BondTypes: line %d\n", lineNum );
750 <            painCave.isFatal = 1;
751 <            simError();
752 <          }
753 <          
754 <          strcpy( currentBondType->nameB, the_token );
755 <          
756 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
757 <            sprintf( painCave.errMsg,
758 <                     "Error parseing BondTypes: line %d\n", lineNum );
759 <            painCave.isFatal = 1;
760 <            simError();
761 <          }
762 <          
763 <          strcpy( currentBondType->type, the_token );
764 <          
765 <          if( !strcmp( currentBondType->type, "fixed" ) ){
766 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
767 <              sprintf( painCave.errMsg,
768 <                       "Error parseing BondTypes: line %d\n", lineNum );
769 <              painCave.isFatal = 1;
770 <              simError();
771 <            }
772 <            
773 <            sscanf( the_token, "%lf", &currentBondType->d0 );
774 <          }
775 <          
776 <          else{
777 <            sprintf( painCave.errMsg,
778 <                     "Unknown TraPPE_Ex bond type \"%s\" at line %d\n",
779 <                     currentBondType->type,
780 <                     lineNum );
781 <            painCave.isFatal = 1;
782 <            simError();
783 <          }              
840 >        // the parser returns 0 if the line was blank
841 >        if( parseBond( readLine, lineNum, info ) ){
842 >          headBondType->add( info );
843          }
844        }
786      
787      tempBondType = new LinkedType;
788      currentBondType->next = tempBondType;
789      currentBondType = tempBondType;
790      
845        eof_test = fgets( readLine, sizeof(readLine), frcFile );
846        lineNum++;
847      }
848 <    
848 >        
849   #ifdef IS_MPI
850      
851      // send out the linked list to all the other processes
# Line 890 | Line 944 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
944        return NULL;
945      }
946      
893 #ifdef IS_MPI
894
947      void add( bendStruct &info ){
948 +
949 +      // check for duplicates
950 +      int dup = 0;
951 +      
952 +      if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB )
953 +          && !strcmp( nameC, info.nameC ) ) dup = 1;
954 +      if( !strcmp( nameA, info.nameC ) && !strcmp( nameB, info.nameB )
955 +          && !strcmp( nameC, info.nameA ) ) dup = 1;
956 +
957 +      if(dup){
958 +        sprintf( painCave.errMsg,
959 +                 "Duplicate TraPPE_Ex bend type \"%s - %s - %s\" found in "
960 +                 "the TraPPE_ExFF param file./n",
961 +                 nameA, nameB, nameC );
962 +        painCave.isFatal = 1;
963 +        simError();
964 +      }
965 +
966        if( next != NULL ) next->add(info);
967        else{
968          next = new LinkedType();
# Line 906 | Line 976 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
976          next->t0 = info.t0;
977        }
978      }
979 <    
979 >
980 > #ifdef IS_MPI    
981 >
982      void duplicate( bendStruct &info ){
983        strcpy(info.nameA, nameA);
984        strcpy(info.nameB, nameB);
# Line 932 | Line 1004 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1004    
1005    LinkedType* headBendType;
1006    LinkedType* currentBendType;
935  LinkedType* tempBendType;
936
937 #ifdef IS_MPI
1007    bendStruct info;
1008    info.last = 1; // initialize last to have the last set.
1009                   // if things go well, last will be set to 0
941 #endif
1010  
943  char readLine[500];
944  char* the_token;
945  char* eof_test;
946  int foundBend = 0;
947  int lineNum = 0;
948  int i, a, b, c, index;
949  char* atomA;
950  char* atomB;
951  char* atomC;
1011    QuadraticBend* qBend;
953
1012    SRI **the_sris;
1013    Atom** the_atoms;
1014    int nBends;
# Line 958 | Line 1016 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1016    the_atoms = entry_plug->atoms;
1017    nBends = entry_plug->n_bends;
1018  
1019 +  int i, a, b, c;
1020 +  char* atomA;
1021 +  char* atomB;
1022 +  char* atomC;
1023  
1024 +
1025   #ifdef IS_MPI
1026    if( worldRank == 0 ){
1027   #endif
1028  
1029      // read in the bend types.
1030  
968    rewind( frcFile );
1031      headBendType = new LinkedType;
970    currentBendType = headBendType;
971  
972    eof_test = fgets( readLine, sizeof(readLine), frcFile );
973    lineNum++;
974    if( eof_test == NULL ){
975      sprintf( painCave.errMsg, "Error in reading Bends from force file.\n" );
976      painCave.isFatal = 1;
977      simError();
978    }
979
980  
981    while( !foundBend ){
982      while( eof_test != NULL && readLine[0] != '#' ){
983        eof_test = fgets( readLine, sizeof(readLine), frcFile );
984        lineNum++;
985      }
986      if( eof_test == NULL ){
987        sprintf( painCave.errMsg,
988                 "Error in reading Bends from force file at line %d.\n",
989                 lineNum );
990        painCave.isFatal = 1;
991        simError();
992      }
993
994      the_token = strtok( readLine, " ,;\t#\n" );
995      foundBend = !strcmp( "BendTypes", the_token );
1032      
1033 <      if( !foundBend ){
998 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
999 <        lineNum++;
1033 >    fastForward( "BendTypes", "initializeBends" );
1034  
1035 <        if( eof_test == NULL ){
1002 <          sprintf( painCave.errMsg,
1003 <                   "Error in reading Bends from force file at line %d.\n",
1004 <                   lineNum );
1005 <          painCave.isFatal = 1;
1006 <          simError();
1007 <        }
1008 <      }
1009 <    }
1035 >    // we are now at the bendTypes section
1036  
1037 <    // we are now at the BendTypes section.
1012 <
1013 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
1037 >    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
1038      lineNum++;
1039 <  
1039 >        
1040 >    // read a line, and start parseing out the bend types
1041 >
1042      if( eof_test == NULL ){
1043        sprintf( painCave.errMsg,
1044 <               "Error in reading Bends from force file at line %d.\n",
1044 >               "Error in reading bends from force file at line %d.\n",
1045                 lineNum );
1046        painCave.isFatal = 1;
1047        simError();
1048      }
1023
1024    while( readLine[0] != '#' && eof_test != NULL ){
1049      
1050 <      if( readLine[0] != '!' ){
1050 >    // stop reading at end of file, or at next section
1051 >    while( readLine[0] != '#' && eof_test != NULL ){
1052        
1053 <        the_token = strtok( readLine, " \n\t,;" );
1054 <        if( the_token != NULL ){
1053 >      // toss comment lines
1054 >      if( readLine[0] != '!' ){
1055          
1056 <          strcpy( currentBendType->nameA, the_token );
1057 <        
1058 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1034 <            sprintf( painCave.errMsg,
1035 <                     "Error parseing BendTypes: line %d\n", lineNum );
1036 <            painCave.isFatal = 1;
1037 <            simError();
1038 <          }
1039 <
1040 <          strcpy( currentBendType->nameB, the_token );
1041 <
1042 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1043 <            sprintf( painCave.errMsg,
1044 <                     "Error parseing BendTypes: line %d\n", lineNum );
1045 <            painCave.isFatal = 1;
1046 <            simError();
1047 <          }
1048 <
1049 <          strcpy( currentBendType->nameC, the_token );
1050 <
1051 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1052 <            sprintf( painCave.errMsg,
1053 <                     "Error parseing BendTypes: line %d\n", lineNum );
1054 <            painCave.isFatal = 1;
1055 <            simError();
1056 <          }
1057 <
1058 <          strcpy( currentBendType->type, the_token );
1059 <
1060 <          if( !strcmp( currentBendType->type, "quadratic" ) ){
1061 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1062 <              sprintf( painCave.errMsg,
1063 <                       "Error parseing BendTypes: line %d\n", lineNum );
1064 <              painCave.isFatal = 1;
1065 <              simError();
1066 <            }
1067 <          
1068 <            sscanf( the_token, "%lf", &currentBendType->k1 );
1069 <
1070 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1071 <              sprintf( painCave.errMsg,
1072 <                       "Error parseing BendTypes: line %d\n", lineNum );
1073 <              painCave.isFatal = 1;
1074 <              simError();
1075 <            }
1076 <          
1077 <            sscanf( the_token, "%lf", &currentBendType->k2 );
1078 <
1079 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1080 <              sprintf( painCave.errMsg,
1081 <                       "Error parseing BendTypes: line %d\n", lineNum );
1082 <              painCave.isFatal = 1;
1083 <              simError();
1084 <            }
1085 <          
1086 <            sscanf( the_token, "%lf", &currentBendType->k3 );
1087 <
1088 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1089 <              sprintf( painCave.errMsg,
1090 <                       "Error parseing BendTypes: line %d\n", lineNum );
1091 <              painCave.isFatal = 1;
1092 <              simError();
1093 <            }
1094 <          
1095 <            sscanf( the_token, "%lf", &currentBendType->t0 );
1096 <          }
1097 <        
1098 <          else{
1099 <            sprintf( painCave.errMsg,
1100 <                     "Unknown TraPPE_Ex bend type \"%s\" at line %d\n",
1101 <                     currentBendType->type,
1102 <                     lineNum );
1103 <            painCave.isFatal = 1;
1104 <            simError();
1105 <          }              
1056 >        // the parser returns 0 if the line was blank
1057 >        if( parseBend( readLine, lineNum, info ) ){
1058 >          headBendType->add( info );
1059          }
1060        }
1108    
1109      tempBendType = new LinkedType;
1110      currentBendType->next = tempBendType;
1111      currentBendType = tempBendType;
1112    
1061        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1062        lineNum++;
1063      }
1064 <
1064 >    
1065   #ifdef IS_MPI
1066      
1067      // send out the linked list to all the other processes
# Line 1150 | Line 1098 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1098   #endif // is_mpi
1099    
1100    // initialize the Bends
1101 +  
1102 +  int index;
1103  
1104    for( i=0; i<nBends; i++ ){
1105      
# Line 1213 | Line 1163 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1163            !strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this;
1164  
1165        if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) &&
1166 <          !strcmp( nameC, key2 ) && !strcmp( nameD, key4 ) ) return this;
1166 >          !strcmp( nameC, key2 ) && !strcmp( nameD, key1 ) ) return this;
1167  
1168        if( next != NULL ) return next->find(key1, key2, key3, key4);
1169        return NULL;
1170      }
1221    
1222 #ifdef IS_MPI
1171  
1172      void add( torsionStruct &info ){
1173 +
1174 +      // check for duplicates
1175 +      int dup = 0;
1176 +
1177 +      if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) &&
1178 +          !strcmp( nameC, info.nameC ) && !strcmp( nameD, info.nameD ) ) dup = 1;
1179 +      
1180 +      if( !strcmp( nameA, info.nameD ) && !strcmp( nameB, info.nameC ) &&
1181 +          !strcmp( nameC, info.nameB ) && !strcmp( nameD, info.nameA ) ) dup = 1;
1182 +      
1183 +      if(dup){
1184 +        sprintf( painCave.errMsg,
1185 +                 "Duplicate TraPPE_Ex torsion type \"%s - %s - %s - %s\" found in "
1186 +                 "the TraPPE_ExFF param file./n", nameA, nameB, nameC, nameD );
1187 +        painCave.isFatal = 1;
1188 +        simError();
1189 +      }
1190 +
1191        if( next != NULL ) next->add(info);
1192        else{
1193          next = new LinkedType();
# Line 1235 | Line 1201 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1201          next->k4 = info.k4;
1202        }
1203      }
1204 +
1205 + #ifdef IS_MPI
1206      
1207      void duplicate( torsionStruct &info ){
1208        strcpy(info.nameA, nameA);
# Line 1263 | Line 1231 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1231    
1232    LinkedType* headTorsionType;
1233    LinkedType* currentTorsionType;
1266  LinkedType* tempTorsionType;
1267
1268 #ifdef IS_MPI
1234    torsionStruct info;
1235    info.last = 1; // initialize last to have the last set.
1236                   // if things go well, last will be set to 0
1272 #endif
1237  
1274  char readLine[500];
1275  char* the_token;
1276  char* eof_test;
1277  int foundTorsion = 0;
1278  int lineNum = 0;
1238    int i, a, b, c, d, index;
1239    char* atomA;
1240    char* atomB;
# Line 1296 | Line 1255 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1255  
1256      // read in the torsion types.
1257  
1299    rewind( frcFile );
1258      headTorsionType = new LinkedType;
1259 <    currentTorsionType = headTorsionType;
1260 <  
1303 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
1304 <    lineNum++;
1305 <    if( eof_test == NULL ){
1306 <      sprintf( painCave.errMsg,
1307 <               "Error in reading Torsions from force file.\n" );
1308 <      painCave.isFatal = 1;
1309 <      simError();
1310 <    }
1259 >    
1260 >    fastForward( "TorsionTypes", "initializeTorsions" );
1261  
1262 <  
1313 <    while( !foundTorsion ){
1314 <      while( eof_test != NULL && readLine[0] != '#' ){
1315 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1316 <        lineNum++;
1317 <      }
1318 <      if( eof_test == NULL ){
1319 <        sprintf( painCave.errMsg,
1320 <                 "Error in reading Torsions from force file at line %d.\n",
1321 <                 lineNum );
1322 <        painCave.isFatal = 1;
1323 <        simError();
1324 <      }
1262 >    // we are now at the torsionTypes section
1263  
1264 <      the_token = strtok( readLine, " ,;\t#\n" );
1265 <      foundTorsion = !strcmp( "TorsionTypes", the_token );
1264 >    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
1265 >    lineNum++;
1266      
1267 <      if( !foundTorsion ){
1268 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1331 <        lineNum++;
1332 <
1333 <        if( eof_test == NULL ){
1334 <          sprintf( painCave.errMsg,
1335 <                   "Error in reading Torsions from force file at line %d.\n",
1336 <                   lineNum );
1337 <          painCave.isFatal = 1;
1338 <          simError();
1339 <        }
1340 <      }
1341 <    }
1267 >    
1268 >    // read a line, and start parseing out the atom types
1269  
1343    // we are now at the TorsionTypes section.
1344
1345    eof_test = fgets( readLine, sizeof(readLine), frcFile );
1346    lineNum++;
1347  
1270      if( eof_test == NULL ){
1271        sprintf( painCave.errMsg,
1272 <               "Error in reading Torsions from force file at line %d.\n",
1272 >               "Error in reading torsions from force file at line %d.\n",
1273                 lineNum );
1274        painCave.isFatal = 1;
1275        simError();
1276      }
1355
1356    while( readLine[0] != '#' && eof_test != NULL ){
1277      
1278 +    // stop reading at end of file, or at next section
1279 +    while( readLine[0] != '#' && eof_test != NULL ){
1280 +
1281 +      // toss comment lines
1282        if( readLine[0] != '!' ){
1359      
1360        the_token = strtok( readLine, " \n\t,;" );
1361        if( the_token != NULL ){
1283          
1284 <          strcpy( currentTorsionType->nameA, the_token );
1285 <        
1286 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1366 <            sprintf( painCave.errMsg,
1367 <                     "Error parseing TorsionTypes: line %d\n", lineNum );
1368 <            painCave.isFatal = 1;
1369 <            simError();
1370 <          }
1371 <
1372 <          strcpy( currentTorsionType->nameB, the_token );
1373 <
1374 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1375 <            sprintf( painCave.errMsg,
1376 <                     "Error parseing TorsionTypes: line %d\n", lineNum );
1377 <            painCave.isFatal = 1;
1378 <            simError();
1379 <          }
1380 <
1381 <          strcpy( currentTorsionType->nameC, the_token );
1382 <
1383 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1384 <            sprintf( painCave.errMsg,
1385 <                     "Error parseing TorsionTypes: line %d\n", lineNum );
1386 <            painCave.isFatal = 1;
1387 <            simError();
1388 <          }
1389 <
1390 <          strcpy( currentTorsionType->nameD, the_token );
1391 <
1392 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1393 <            sprintf( painCave.errMsg,
1394 <                     "Error parseing TorsionTypes: line %d\n", lineNum );
1395 <            painCave.isFatal = 1;
1396 <            simError();
1397 <          }
1398 <
1399 <          strcpy( currentTorsionType->type, the_token );
1400 <
1401 <          if( !strcmp( currentTorsionType->type, "cubic" ) ){
1402 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1403 <              sprintf( painCave.errMsg,
1404 <                       "Error parseing TorsionTypes: line %d\n", lineNum );
1405 <              painCave.isFatal = 1;
1406 <              simError();
1407 <            }
1408 <          
1409 <            sscanf( the_token, "%lf", &currentTorsionType->k1 );
1410 <
1411 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1412 <              sprintf( painCave.errMsg,
1413 <                       "Error parseing TorsionTypes: line %d\n", lineNum );
1414 <              painCave.isFatal = 1;
1415 <              simError();
1416 <            }
1417 <          
1418 <            sscanf( the_token, "%lf", &currentTorsionType->k2 );
1419 <
1420 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1421 <              sprintf( painCave.errMsg,
1422 <                       "Error parseing TorsionTypes: line %d\n", lineNum );
1423 <              painCave.isFatal = 1;
1424 <              simError();
1425 <            }
1426 <          
1427 <            sscanf( the_token, "%lf", &currentTorsionType->k3 );
1428 <
1429 <            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1430 <              sprintf( painCave.errMsg,
1431 <                       "Error parseing TorsionTypes: line %d\n", lineNum );
1432 <              painCave.isFatal = 1;
1433 <              simError();
1434 <            }
1435 <          
1436 <            sscanf( the_token, "%lf", &currentTorsionType->k4 );
1437 <          }
1438 <        
1439 <          else{
1440 <            sprintf( painCave.errMsg,
1441 <                     "Unknown TraPPE_Ex torsion type \"%s\" at line %d\n",
1442 <                     currentTorsionType->type,
1443 <                     lineNum );
1444 <            painCave.isFatal = 1;
1445 <            simError();
1446 <          }              
1284 >        // the parser returns 0 if the line was blank
1285 >        if( parseTorsion( readLine, lineNum, info ) ){
1286 >          headTorsionType->add( info );
1287          }
1288        }
1449    
1450      tempTorsionType = new LinkedType;
1451      currentTorsionType->next = tempTorsionType;
1452      currentTorsionType = tempTorsionType;
1453    
1289        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1290        lineNum++;
1291      }
# Line 1533 | Line 1368 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1368    sprintf( checkPointMsg, "TraPPE_Ex torsions initialized succesfully" );
1369    MPIcheckPoint();
1370   #endif // is_mpi
1371 +
1372 + }
1373 +
1374 + void TraPPE_ExFF::fastForward( char* stopText, char* searchOwner ){
1375 +
1376 +  int foundText = 0;
1377 +  char* the_token;
1378 +
1379 +  rewind( frcFile );
1380 +  lineNum = 0;
1381 +
1382 +  eof_test = fgets( readLine, sizeof(readLine), frcFile );
1383 +  lineNum++;
1384 +  if( eof_test == NULL ){
1385 +    sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
1386 +             " file is empty.\n",
1387 +             searchOwner );
1388 +    painCave.isFatal = 1;
1389 +    simError();
1390 +  }
1391 +  
1392 +  
1393 +  while( !foundText ){
1394 +    while( eof_test != NULL && readLine[0] != '#' ){
1395 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1396 +      lineNum++;
1397 +    }
1398 +    if( eof_test == NULL ){
1399 +      sprintf( painCave.errMsg,
1400 +               "Error fast forwarding force file for %s at "
1401 +               "line %d: file ended unexpectedly.\n",
1402 +               searchOwner,
1403 +               lineNum );
1404 +      painCave.isFatal = 1;
1405 +      simError();
1406 +    }
1407 +    
1408 +    the_token = strtok( readLine, " ,;\t#\n" );
1409 +    foundText = !strcmp( stopText, the_token );
1410 +    
1411 +    if( !foundText ){
1412 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1413 +      lineNum++;
1414 +      
1415 +      if( eof_test == NULL ){
1416 +        sprintf( painCave.errMsg,
1417 +                 "Error fast forwarding force file for %s at "
1418 +                 "line %d: file ended unexpectedly.\n",
1419 +                 searchOwner,
1420 +                 lineNum );
1421 +        painCave.isFatal = 1;
1422 +        simError();
1423 +      }
1424 +    }
1425 +  }  
1426 + }
1427  
1428 +
1429 + int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){
1430 +
1431 +  char* the_token;
1432 +  
1433 +  the_token = strtok( lineBuffer, " \n\t,;" );
1434 +  if( the_token != NULL ){
1435 +    
1436 +    strcpy( info.name, the_token );
1437 +
1438 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1439 +      sprintf( painCave.errMsg,
1440 +               "Error parseing AtomTypes: line %d\n", lineNum );
1441 +      painCave.isFatal = 1;
1442 +      simError();
1443 +    }
1444 +    
1445 +    info.isDipole = atoi( the_token );
1446 +
1447 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1448 +      sprintf( painCave.errMsg,
1449 +               "Error parseing AtomTypes: line %d\n", lineNum );
1450 +      painCave.isFatal = 1;
1451 +      simError();
1452 +    }
1453 +
1454 +    info.isSSD = atoi( the_token );
1455 +
1456 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1457 +      sprintf( painCave.errMsg,
1458 +               "Error parseing AtomTypes: line %d\n", lineNum );
1459 +      painCave.isFatal = 1;
1460 +      simError();
1461 +    }
1462 +    
1463 +    info.mass = atof( the_token );
1464 +    
1465 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1466 +      sprintf( painCave.errMsg,
1467 +               "Error parseing AtomTypes: line %d\n", lineNum );
1468 +      painCave.isFatal = 1;
1469 +      simError();
1470 +    }
1471 +        
1472 +    info.epslon = atof( the_token );
1473 +          
1474 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1475 +      sprintf( painCave.errMsg,
1476 +               "Error parseing AtomTypes: line %d\n", lineNum );
1477 +      painCave.isFatal = 1;
1478 +      simError();
1479 +    }
1480 +        
1481 +    info.sigma = atof( the_token );
1482 +
1483 +    if( info.isDipole ){
1484 +      
1485 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1486 +        sprintf( painCave.errMsg,
1487 +                 "Error parseing AtomTypes: line %d\n", lineNum );
1488 +        painCave.isFatal = 1;
1489 +        simError();
1490 +      }
1491 +      
1492 +      info.dipole = atof( the_token );
1493 +    }
1494 +    else info.dipole = 0.0;
1495 +
1496 +    if( info.isSSD ){
1497 +
1498 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1499 +        sprintf( painCave.errMsg,
1500 +                 "Error parseing AtomTypes: line %d\n", lineNum );
1501 +        painCave.isFatal = 1;
1502 +        simError();
1503 +      }
1504 +      
1505 +      info.w0 = atof( the_token );
1506 +
1507 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1508 +        sprintf( painCave.errMsg,
1509 +                 "Error parseing AtomTypes: line %d\n", lineNum );
1510 +        painCave.isFatal = 1;
1511 +        simError();
1512 +      }
1513 +      
1514 +      info.v0 = atof( the_token );
1515 +    }
1516 +    else info.v0 = info.w0 = 0.0;
1517 +
1518 +    return 1;
1519 +  }
1520 +  else return 0;
1521   }
1522 +
1523 + int parseBond( char *lineBuffer, int lineNum, bondStruct &info ){
1524 +
1525 +  char* the_token;
1526 +  
1527 +  the_token = strtok( lineBuffer, " \n\t,;" );
1528 +  if( the_token != NULL ){
1529 +    
1530 +    strcpy( info.nameA, the_token );
1531 +
1532 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1533 +      sprintf( painCave.errMsg,
1534 +               "Error parseing BondTypes: line %d\n", lineNum );
1535 +      painCave.isFatal = 1;
1536 +      simError();
1537 +    }
1538 +    
1539 +    strcpy( info.nameB, the_token );
1540 +
1541 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1542 +      sprintf( painCave.errMsg,
1543 +               "Error parseing BondTypes: line %d\n", lineNum );
1544 +      painCave.isFatal = 1;
1545 +      simError();
1546 +    }
1547 +    
1548 +    strcpy( info.type, the_token );
1549 +    
1550 +    if( !strcmp( info.type, "fixed" ) ){
1551 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1552 +        sprintf( painCave.errMsg,
1553 +                 "Error parseing BondTypes: line %d\n", lineNum );
1554 +        painCave.isFatal = 1;
1555 +        simError();
1556 +      }
1557 +      
1558 +      info.d0 = atof( the_token );
1559 +    }
1560 +    else{
1561 +      sprintf( painCave.errMsg,
1562 +               "Unknown TraPPE_Ex bond type \"%s\" at line %d\n",
1563 +               info.type,
1564 +               lineNum );
1565 +      painCave.isFatal = 1;
1566 +      simError();
1567 +    }            
1568 +    
1569 +    return 1;
1570 +  }
1571 +  else return 0;
1572 + }
1573 +
1574 +
1575 + int parseBend( char *lineBuffer, int lineNum, bendStruct &info ){
1576 +
1577 +  char* the_token;
1578 +  
1579 +  the_token = strtok( lineBuffer, " \n\t,;" );
1580 +  if( the_token != NULL ){
1581 +    
1582 +    strcpy( info.nameA, the_token );
1583 +
1584 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1585 +      sprintf( painCave.errMsg,
1586 +               "Error parseing BondTypes: line %d\n", lineNum );
1587 +      painCave.isFatal = 1;
1588 +      simError();
1589 +    }
1590 +    
1591 +    strcpy( info.nameB, the_token );
1592 +
1593 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1594 +      sprintf( painCave.errMsg,
1595 +               "Error parseing BondTypes: line %d\n", lineNum );
1596 +      painCave.isFatal = 1;
1597 +      simError();
1598 +    }
1599 +    
1600 +    strcpy( info.nameC, the_token );
1601 +
1602 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1603 +      sprintf( painCave.errMsg,
1604 +               "Error parseing BondTypes: line %d\n", lineNum );
1605 +      painCave.isFatal = 1;
1606 +      simError();
1607 +    }
1608 +    
1609 +    strcpy( info.type, the_token );
1610 +
1611 +    if( !strcmp( info.type, "quadratic" ) ){
1612 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1613 +        sprintf( painCave.errMsg,
1614 +                 "Error parseing BendTypes: line %d\n", lineNum );
1615 +        painCave.isFatal = 1;
1616 +        simError();
1617 +      }
1618 +        
1619 +      info.k1 = atof( the_token );
1620 +      
1621 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1622 +        sprintf( painCave.errMsg,
1623 +                 "Error parseing BendTypes: line %d\n", lineNum );
1624 +        painCave.isFatal = 1;
1625 +        simError();
1626 +      }
1627 +      
1628 +      info.k2 = atof( the_token );
1629 +      
1630 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1631 +        sprintf( painCave.errMsg,
1632 +                 "Error parseing BendTypes: line %d\n", lineNum );
1633 +        painCave.isFatal = 1;
1634 +        simError();
1635 +      }
1636 +        
1637 +      info.k3 = atof( the_token );
1638 +      
1639 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1640 +        sprintf( painCave.errMsg,
1641 +                 "Error parseing BendTypes: line %d\n", lineNum );
1642 +        painCave.isFatal = 1;
1643 +        simError();
1644 +      }
1645 +      
1646 +      info.t0 = atof( the_token );
1647 +    }
1648 +    
1649 +    else{
1650 +      sprintf( painCave.errMsg,
1651 +               "Unknown TraPPE_Ex bend type \"%s\" at line %d\n",
1652 +               info.type,
1653 +               lineNum );
1654 +      painCave.isFatal = 1;
1655 +      simError();
1656 +    }            
1657 +        
1658 +    return 1;
1659 +  }
1660 +  else return 0;
1661 + }
1662 +
1663 + int parseTorsion( char *lineBuffer, int lineNum, torsionStruct &info ){
1664 +  
1665 +  char*  the_token;
1666 +
1667 +  the_token = strtok( lineBuffer, " \n\t,;" );
1668 +  if( the_token != NULL ){
1669 +    
1670 +    strcpy( info.nameA, the_token );
1671 +        
1672 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1673 +      sprintf( painCave.errMsg,
1674 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1675 +      painCave.isFatal = 1;
1676 +      simError();
1677 +    }
1678 +    
1679 +    strcpy( info.nameB, the_token );
1680 +
1681 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1682 +      sprintf( painCave.errMsg,
1683 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1684 +      painCave.isFatal = 1;
1685 +      simError();
1686 +    }
1687 +    
1688 +    strcpy( info.nameC, the_token );
1689 +    
1690 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1691 +      sprintf( painCave.errMsg,
1692 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1693 +      painCave.isFatal = 1;
1694 +      simError();
1695 +    }
1696 +    
1697 +    strcpy( info.nameD, the_token );
1698 +    
1699 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1700 +      sprintf( painCave.errMsg,
1701 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1702 +      painCave.isFatal = 1;
1703 +      simError();
1704 +    }
1705 +    
1706 +    strcpy( info.type, the_token );
1707 +    
1708 +    if( !strcmp( info.type, "cubic" ) ){
1709 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1710 +        sprintf( painCave.errMsg,
1711 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1712 +        painCave.isFatal = 1;
1713 +        simError();
1714 +      }
1715 +      
1716 +      info.k1 = atof( the_token );
1717 +      
1718 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1719 +        sprintf( painCave.errMsg,
1720 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1721 +        painCave.isFatal = 1;
1722 +        simError();
1723 +      }
1724 +      
1725 +      info.k2 = atof( the_token );
1726 +      
1727 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1728 +        sprintf( painCave.errMsg,
1729 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1730 +        painCave.isFatal = 1;
1731 +        simError();
1732 +      }
1733 +      
1734 +      info.k3 = atof( the_token );
1735 +      
1736 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1737 +        sprintf( painCave.errMsg,
1738 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1739 +        painCave.isFatal = 1;
1740 +        simError();
1741 +      }
1742 +      
1743 +      info.k4 = atof( the_token );
1744 +    
1745 +    }
1746 +    
1747 +    else{
1748 +      sprintf( painCave.errMsg,
1749 +               "Unknown TraPPE_Ex torsion type \"%s\" at line %d\n",
1750 +               info.type,
1751 +               lineNum );
1752 +      painCave.isFatal = 1;
1753 +      simError();
1754 +    }            
1755 +    
1756 +    return 1;
1757 +  }
1758 +  
1759 +  else return 0;
1760 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines