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 311 by mmeineke, Tue Mar 11 16:27:34 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;
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];
46 <  char type[30];
47 <  double k1, k2, k3, t0;
48 <  int last;      //  0  -> default
49 <                 //  1  -> tells nodes to stop listening
50 < } bendStruct;
51 < MPI_Datatype mpiBendStructType;
52 <
53 < typedef struct{
54 <  char nameA[15];
55 <  char nameB[15];
56 <  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 582 | Line 683 | void TraPPE_ExFF::initializeAtoms( void ){
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  
1011 <  char readLine[500];
1012 <  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;
952 <  QuadraticBend* qBend;
953 <
1011 >  QuadraticBend* qBend;
1012 >  GhostBend* gBend;
1013    SRI **the_sris;
1014    Atom** the_atoms;
1015    int nBends;
# Line 958 | Line 1017 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1017    the_atoms = entry_plug->atoms;
1018    nBends = entry_plug->n_bends;
1019  
1020 +  int i, a, b, c;
1021 +  char* atomA;
1022 +  char* atomB;
1023 +  char* atomC;
1024  
1025 +
1026   #ifdef IS_MPI
1027    if( worldRank == 0 ){
1028   #endif
1029  
1030      // read in the bend types.
1031  
968    rewind( frcFile );
1032      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 );
1033      
1034 <      if( !foundBend ){
998 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
999 <        lineNum++;
1034 >    fastForward( "BendTypes", "initializeBends" );
1035  
1036 <        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 <    }
1036 >    // we are now at the bendTypes section
1037  
1038 <    // we are now at the BendTypes section.
1012 <
1013 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
1038 >    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
1039      lineNum++;
1040 <  
1040 >        
1041 >    // read a line, and start parseing out the bend types
1042 >
1043      if( eof_test == NULL ){
1044        sprintf( painCave.errMsg,
1045 <               "Error in reading Bends from force file at line %d.\n",
1045 >               "Error in reading bends from force file at line %d.\n",
1046                 lineNum );
1047        painCave.isFatal = 1;
1048        simError();
1049      }
1023
1024    while( readLine[0] != '#' && eof_test != NULL ){
1050      
1051 <      if( readLine[0] != '!' ){
1051 >    // stop reading at end of file, or at next section
1052 >    while( readLine[0] != '#' && eof_test != NULL ){
1053        
1054 <        the_token = strtok( readLine, " \n\t,;" );
1055 <        if( the_token != NULL ){
1054 >      // toss comment lines
1055 >      if( readLine[0] != '!' ){
1056          
1057 <          strcpy( currentBendType->nameA, the_token );
1058 <        
1059 <          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 <          }              
1057 >        // the parser returns 0 if the line was blank
1058 >        if( parseBend( readLine, lineNum, info ) ){
1059 >          headBendType->add( info );
1060          }
1061        }
1108    
1109      tempBendType = new LinkedType;
1110      currentBendType->next = tempBendType;
1111      currentBendType = tempBendType;
1112    
1062        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1063        lineNum++;
1064      }
1065 <
1065 >    
1066   #ifdef IS_MPI
1067      
1068      // send out the linked list to all the other processes
# Line 1150 | Line 1099 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1099   #endif // is_mpi
1100    
1101    // initialize the Bends
1102 +  
1103 +  int index;
1104  
1105    for( i=0; i<nBends; i++ ){
1106      
# Line 1159 | Line 1110 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1110  
1111      atomA = the_atoms[a]->getType();
1112      atomB = the_atoms[b]->getType();
1113 <    atomC = the_atoms[c]->getType();
1113 >
1114 >    if( the_bends[i].isGhost ) atomC = "GHOST";
1115 >    else atomC = the_atoms[c]->getType();
1116 >
1117      currentBendType = headBendType->find( atomA, atomB, atomC );
1118      if( currentBendType == NULL ){
1119        sprintf( painCave.errMsg, "BendType error, %s - %s - %s not found"
# Line 1172 | Line 1126 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1126      if( !strcmp( currentBendType->type, "quadratic" ) ){
1127        
1128        index = i + entry_plug->n_bonds;
1129 <      qBend = new QuadraticBend( *the_atoms[a],
1130 <                                 *the_atoms[b],
1131 <                                 *the_atoms[c] );
1132 <      qBend->setConstants( currentBendType->k1,
1133 <                           currentBendType->k2,
1134 <                           currentBendType->k3,
1135 <                           currentBendType->t0 );
1136 <      the_sris[index] = qBend;
1129 >      
1130 >      if( the_bends[i].isGhost){
1131 >        
1132 >        if( the_bends[i].ghost == b ){
1133 >          // do nothing
1134 >        }
1135 >        else if( the_bends[i].ghost == a ){
1136 >          c = a;
1137 >          a = b;
1138 >          b = a;
1139 >        }
1140 >        else{
1141 >          sprintf( painCave.errMsg,
1142 >                   "BendType error, %s - %s - %s,\n"
1143 >                   "  --> central atom is not "
1144 >                   "correctly identified with the "
1145 >                   "\"ghostVectorSource = \" tag.\n",
1146 >                   atomA, atomB, atomC );
1147 >          painCave.isFatal = 1;
1148 >          simError();
1149 >        }
1150 >        
1151 >        gBend = new GhostBend( *the_atoms[a],
1152 >                               *the_atoms[b] );                        
1153 >        gBend->setConstants( currentBendType->k1,
1154 >                             currentBendType->k2,
1155 >                             currentBendType->k3,
1156 >                             currentBendType->t0 );
1157 >        the_sris[index] = gBend;
1158 >      }
1159 >      else{
1160 >        qBend = new QuadraticBend( *the_atoms[a],
1161 >                                   *the_atoms[b],
1162 >                                   *the_atoms[c] );
1163 >        qBend->setConstants( currentBendType->k1,
1164 >                             currentBendType->k2,
1165 >                             currentBendType->k3,
1166 >                             currentBendType->t0 );
1167 >        the_sris[index] = qBend;
1168 >      }
1169      }
1170    }
1171  
# Line 1213 | Line 1199 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1199            !strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this;
1200  
1201        if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) &&
1202 <          !strcmp( nameC, key2 ) && !strcmp( nameD, key4 ) ) return this;
1202 >          !strcmp( nameC, key2 ) && !strcmp( nameD, key1 ) ) return this;
1203  
1204        if( next != NULL ) return next->find(key1, key2, key3, key4);
1205        return NULL;
1206      }
1221    
1222 #ifdef IS_MPI
1207  
1208      void add( torsionStruct &info ){
1209 +
1210 +      // check for duplicates
1211 +      int dup = 0;
1212 +
1213 +      if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) &&
1214 +          !strcmp( nameC, info.nameC ) && !strcmp( nameD, info.nameD ) ) dup = 1;
1215 +      
1216 +      if( !strcmp( nameA, info.nameD ) && !strcmp( nameB, info.nameC ) &&
1217 +          !strcmp( nameC, info.nameB ) && !strcmp( nameD, info.nameA ) ) dup = 1;
1218 +      
1219 +      if(dup){
1220 +        sprintf( painCave.errMsg,
1221 +                 "Duplicate TraPPE_Ex torsion type \"%s - %s - %s - %s\" found in "
1222 +                 "the TraPPE_ExFF param file./n", nameA, nameB, nameC, nameD );
1223 +        painCave.isFatal = 1;
1224 +        simError();
1225 +      }
1226 +
1227        if( next != NULL ) next->add(info);
1228        else{
1229          next = new LinkedType();
# Line 1235 | Line 1237 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1237          next->k4 = info.k4;
1238        }
1239      }
1240 +
1241 + #ifdef IS_MPI
1242      
1243      void duplicate( torsionStruct &info ){
1244        strcpy(info.nameA, nameA);
# Line 1263 | Line 1267 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1267    
1268    LinkedType* headTorsionType;
1269    LinkedType* currentTorsionType;
1266  LinkedType* tempTorsionType;
1267
1268 #ifdef IS_MPI
1270    torsionStruct info;
1271    info.last = 1; // initialize last to have the last set.
1272                   // if things go well, last will be set to 0
1272 #endif
1273  
1274  char readLine[500];
1275  char* the_token;
1276  char* eof_test;
1277  int foundTorsion = 0;
1278  int lineNum = 0;
1274    int i, a, b, c, d, index;
1275    char* atomA;
1276    char* atomB;
# Line 1296 | Line 1291 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1291  
1292      // read in the torsion types.
1293  
1299    rewind( frcFile );
1294      headTorsionType = new LinkedType;
1295 <    currentTorsionType = headTorsionType;
1296 <  
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 <    }
1295 >    
1296 >    fastForward( "TorsionTypes", "initializeTorsions" );
1297  
1298 <  
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 <      }
1298 >    // we are now at the torsionTypes section
1299  
1300 <      the_token = strtok( readLine, " ,;\t#\n" );
1301 <      foundTorsion = !strcmp( "TorsionTypes", the_token );
1300 >    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
1301 >    lineNum++;
1302      
1303 <      if( !foundTorsion ){
1304 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1331 <        lineNum++;
1303 >    
1304 >    // read a line, and start parseing out the atom types
1305  
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    }
1342
1343    // we are now at the TorsionTypes section.
1344
1345    eof_test = fgets( readLine, sizeof(readLine), frcFile );
1346    lineNum++;
1347  
1306      if( eof_test == NULL ){
1307        sprintf( painCave.errMsg,
1308 <               "Error in reading Torsions from force file at line %d.\n",
1308 >               "Error in reading torsions from force file at line %d.\n",
1309                 lineNum );
1310        painCave.isFatal = 1;
1311        simError();
1312      }
1355
1356    while( readLine[0] != '#' && eof_test != NULL ){
1313      
1314 +    // stop reading at end of file, or at next section
1315 +    while( readLine[0] != '#' && eof_test != NULL ){
1316 +
1317 +      // toss comment lines
1318        if( readLine[0] != '!' ){
1359      
1360        the_token = strtok( readLine, " \n\t,;" );
1361        if( the_token != NULL ){
1319          
1320 <          strcpy( currentTorsionType->nameA, the_token );
1321 <        
1322 <          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 <          }              
1320 >        // the parser returns 0 if the line was blank
1321 >        if( parseTorsion( readLine, lineNum, info ) ){
1322 >          headTorsionType->add( info );
1323          }
1324        }
1449    
1450      tempTorsionType = new LinkedType;
1451      currentTorsionType->next = tempTorsionType;
1452      currentTorsionType = tempTorsionType;
1453    
1325        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1326        lineNum++;
1327      }
# Line 1533 | Line 1404 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1404    sprintf( checkPointMsg, "TraPPE_Ex torsions initialized succesfully" );
1405    MPIcheckPoint();
1406   #endif // is_mpi
1407 +
1408 + }
1409 +
1410 + void TraPPE_ExFF::fastForward( char* stopText, char* searchOwner ){
1411 +
1412 +  int foundText = 0;
1413 +  char* the_token;
1414 +
1415 +  rewind( frcFile );
1416 +  lineNum = 0;
1417 +
1418 +  eof_test = fgets( readLine, sizeof(readLine), frcFile );
1419 +  lineNum++;
1420 +  if( eof_test == NULL ){
1421 +    sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
1422 +             " file is empty.\n",
1423 +             searchOwner );
1424 +    painCave.isFatal = 1;
1425 +    simError();
1426 +  }
1427 +  
1428 +  
1429 +  while( !foundText ){
1430 +    while( eof_test != NULL && readLine[0] != '#' ){
1431 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1432 +      lineNum++;
1433 +    }
1434 +    if( eof_test == NULL ){
1435 +      sprintf( painCave.errMsg,
1436 +               "Error fast forwarding force file for %s at "
1437 +               "line %d: file ended unexpectedly.\n",
1438 +               searchOwner,
1439 +               lineNum );
1440 +      painCave.isFatal = 1;
1441 +      simError();
1442 +    }
1443 +    
1444 +    the_token = strtok( readLine, " ,;\t#\n" );
1445 +    foundText = !strcmp( stopText, the_token );
1446 +    
1447 +    if( !foundText ){
1448 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1449 +      lineNum++;
1450 +      
1451 +      if( eof_test == NULL ){
1452 +        sprintf( painCave.errMsg,
1453 +                 "Error fast forwarding force file for %s at "
1454 +                 "line %d: file ended unexpectedly.\n",
1455 +                 searchOwner,
1456 +                 lineNum );
1457 +        painCave.isFatal = 1;
1458 +        simError();
1459 +      }
1460 +    }
1461 +  }  
1462 + }
1463  
1464 +
1465 + int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){
1466 +
1467 +  char* the_token;
1468 +  
1469 +  the_token = strtok( lineBuffer, " \n\t,;" );
1470 +  if( the_token != NULL ){
1471 +    
1472 +    strcpy( info.name, 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.isDipole = atoi( the_token );
1482 +
1483 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1484 +      sprintf( painCave.errMsg,
1485 +               "Error parseing AtomTypes: line %d\n", lineNum );
1486 +      painCave.isFatal = 1;
1487 +      simError();
1488 +    }
1489 +
1490 +    info.isSSD = atoi( the_token );
1491 +
1492 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1493 +      sprintf( painCave.errMsg,
1494 +               "Error parseing AtomTypes: line %d\n", lineNum );
1495 +      painCave.isFatal = 1;
1496 +      simError();
1497 +    }
1498 +    
1499 +    info.mass = atof( the_token );
1500 +    
1501 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1502 +      sprintf( painCave.errMsg,
1503 +               "Error parseing AtomTypes: line %d\n", lineNum );
1504 +      painCave.isFatal = 1;
1505 +      simError();
1506 +    }
1507 +        
1508 +    info.epslon = atof( the_token );
1509 +          
1510 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1511 +      sprintf( painCave.errMsg,
1512 +               "Error parseing AtomTypes: line %d\n", lineNum );
1513 +      painCave.isFatal = 1;
1514 +      simError();
1515 +    }
1516 +        
1517 +    info.sigma = atof( the_token );
1518 +
1519 +    if( info.isDipole ){
1520 +      
1521 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1522 +        sprintf( painCave.errMsg,
1523 +                 "Error parseing AtomTypes: line %d\n", lineNum );
1524 +        painCave.isFatal = 1;
1525 +        simError();
1526 +      }
1527 +      
1528 +      info.dipole = atof( the_token );
1529 +    }
1530 +    else info.dipole = 0.0;
1531 +
1532 +    if( info.isSSD ){
1533 +
1534 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1535 +        sprintf( painCave.errMsg,
1536 +                 "Error parseing AtomTypes: line %d\n", lineNum );
1537 +        painCave.isFatal = 1;
1538 +        simError();
1539 +      }
1540 +      
1541 +      info.w0 = atof( the_token );
1542 +
1543 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1544 +        sprintf( painCave.errMsg,
1545 +                 "Error parseing AtomTypes: line %d\n", lineNum );
1546 +        painCave.isFatal = 1;
1547 +        simError();
1548 +      }
1549 +      
1550 +      info.v0 = atof( the_token );
1551 +    }
1552 +    else info.v0 = info.w0 = 0.0;
1553 +
1554 +    return 1;
1555 +  }
1556 +  else return 0;
1557   }
1558 +
1559 + int parseBond( char *lineBuffer, int lineNum, bondStruct &info ){
1560 +
1561 +  char* the_token;
1562 +  
1563 +  the_token = strtok( lineBuffer, " \n\t,;" );
1564 +  if( the_token != NULL ){
1565 +    
1566 +    strcpy( info.nameA, the_token );
1567 +
1568 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1569 +      sprintf( painCave.errMsg,
1570 +               "Error parseing BondTypes: line %d\n", lineNum );
1571 +      painCave.isFatal = 1;
1572 +      simError();
1573 +    }
1574 +    
1575 +    strcpy( info.nameB, the_token );
1576 +
1577 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1578 +      sprintf( painCave.errMsg,
1579 +               "Error parseing BondTypes: line %d\n", lineNum );
1580 +      painCave.isFatal = 1;
1581 +      simError();
1582 +    }
1583 +    
1584 +    strcpy( info.type, the_token );
1585 +    
1586 +    if( !strcmp( info.type, "fixed" ) ){
1587 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1588 +        sprintf( painCave.errMsg,
1589 +                 "Error parseing BondTypes: line %d\n", lineNum );
1590 +        painCave.isFatal = 1;
1591 +        simError();
1592 +      }
1593 +      
1594 +      info.d0 = atof( the_token );
1595 +    }
1596 +    else{
1597 +      sprintf( painCave.errMsg,
1598 +               "Unknown TraPPE_Ex bond type \"%s\" at line %d\n",
1599 +               info.type,
1600 +               lineNum );
1601 +      painCave.isFatal = 1;
1602 +      simError();
1603 +    }            
1604 +    
1605 +    return 1;
1606 +  }
1607 +  else return 0;
1608 + }
1609 +
1610 +
1611 + int parseBend( char *lineBuffer, int lineNum, bendStruct &info ){
1612 +
1613 +  char* the_token;
1614 +  
1615 +  the_token = strtok( lineBuffer, " \n\t,;" );
1616 +  if( the_token != NULL ){
1617 +    
1618 +    strcpy( info.nameA, the_token );
1619 +
1620 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1621 +      sprintf( painCave.errMsg,
1622 +               "Error parseing BondTypes: line %d\n", lineNum );
1623 +      painCave.isFatal = 1;
1624 +      simError();
1625 +    }
1626 +    
1627 +    strcpy( info.nameB, the_token );
1628 +
1629 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1630 +      sprintf( painCave.errMsg,
1631 +               "Error parseing BondTypes: line %d\n", lineNum );
1632 +      painCave.isFatal = 1;
1633 +      simError();
1634 +    }
1635 +    
1636 +    strcpy( info.nameC, the_token );
1637 +
1638 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1639 +      sprintf( painCave.errMsg,
1640 +               "Error parseing BondTypes: line %d\n", lineNum );
1641 +      painCave.isFatal = 1;
1642 +      simError();
1643 +    }
1644 +    
1645 +    strcpy( info.type, the_token );
1646 +
1647 +    if( !strcmp( info.type, "quadratic" ) ){
1648 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1649 +        sprintf( painCave.errMsg,
1650 +                 "Error parseing BendTypes: line %d\n", lineNum );
1651 +        painCave.isFatal = 1;
1652 +        simError();
1653 +      }
1654 +        
1655 +      info.k1 = atof( the_token );
1656 +      
1657 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1658 +        sprintf( painCave.errMsg,
1659 +                 "Error parseing BendTypes: line %d\n", lineNum );
1660 +        painCave.isFatal = 1;
1661 +        simError();
1662 +      }
1663 +      
1664 +      info.k2 = atof( the_token );
1665 +      
1666 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1667 +        sprintf( painCave.errMsg,
1668 +                 "Error parseing BendTypes: line %d\n", lineNum );
1669 +        painCave.isFatal = 1;
1670 +        simError();
1671 +      }
1672 +        
1673 +      info.k3 = atof( the_token );
1674 +      
1675 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1676 +        sprintf( painCave.errMsg,
1677 +                 "Error parseing BendTypes: line %d\n", lineNum );
1678 +        painCave.isFatal = 1;
1679 +        simError();
1680 +      }
1681 +      
1682 +      info.t0 = atof( the_token );
1683 +    }
1684 +    
1685 +    else{
1686 +      sprintf( painCave.errMsg,
1687 +               "Unknown TraPPE_Ex bend type \"%s\" at line %d\n",
1688 +               info.type,
1689 +               lineNum );
1690 +      painCave.isFatal = 1;
1691 +      simError();
1692 +    }            
1693 +        
1694 +    return 1;
1695 +  }
1696 +  else return 0;
1697 + }
1698 +
1699 + int parseTorsion( char *lineBuffer, int lineNum, torsionStruct &info ){
1700 +  
1701 +  char*  the_token;
1702 +
1703 +  the_token = strtok( lineBuffer, " \n\t,;" );
1704 +  if( the_token != NULL ){
1705 +    
1706 +    strcpy( info.nameA, the_token );
1707 +        
1708 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1709 +      sprintf( painCave.errMsg,
1710 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1711 +      painCave.isFatal = 1;
1712 +      simError();
1713 +    }
1714 +    
1715 +    strcpy( info.nameB, the_token );
1716 +
1717 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1718 +      sprintf( painCave.errMsg,
1719 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1720 +      painCave.isFatal = 1;
1721 +      simError();
1722 +    }
1723 +    
1724 +    strcpy( info.nameC, the_token );
1725 +    
1726 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1727 +      sprintf( painCave.errMsg,
1728 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1729 +      painCave.isFatal = 1;
1730 +      simError();
1731 +    }
1732 +    
1733 +    strcpy( info.nameD, the_token );
1734 +    
1735 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1736 +      sprintf( painCave.errMsg,
1737 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1738 +      painCave.isFatal = 1;
1739 +      simError();
1740 +    }
1741 +    
1742 +    strcpy( info.type, the_token );
1743 +    
1744 +    if( !strcmp( info.type, "cubic" ) ){
1745 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1746 +        sprintf( painCave.errMsg,
1747 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1748 +        painCave.isFatal = 1;
1749 +        simError();
1750 +      }
1751 +      
1752 +      info.k1 = atof( the_token );
1753 +      
1754 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1755 +        sprintf( painCave.errMsg,
1756 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1757 +        painCave.isFatal = 1;
1758 +        simError();
1759 +      }
1760 +      
1761 +      info.k2 = atof( the_token );
1762 +      
1763 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1764 +        sprintf( painCave.errMsg,
1765 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1766 +        painCave.isFatal = 1;
1767 +        simError();
1768 +      }
1769 +      
1770 +      info.k3 = atof( the_token );
1771 +      
1772 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1773 +        sprintf( painCave.errMsg,
1774 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1775 +        painCave.isFatal = 1;
1776 +        simError();
1777 +      }
1778 +      
1779 +      info.k4 = atof( the_token );
1780 +    
1781 +    }
1782 +    
1783 +    else{
1784 +      sprintf( painCave.errMsg,
1785 +               "Unknown TraPPE_Ex torsion type \"%s\" at line %d\n",
1786 +               info.type,
1787 +               lineNum );
1788 +      painCave.isFatal = 1;
1789 +      simError();
1790 +    }            
1791 +    
1792 +    return 1;
1793 +  }
1794 +  
1795 +  else return 0;
1796 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines