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 321 by mmeineke, Wed Mar 12 15:12:24 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 185 | Line 217 | TraPPE_ExFF::TraPPE_ExFF(){
217        
218        ffPath = getenv( ffPath_env );
219        if( ffPath == NULL ) {
220 <        sprintf( painCave.errMsg,
189 <                 "Error opening the force field parameter file: %s\n"
190 <                 "Have you tried setting the FORCE_PARAM_PATH environment "
191 <                 "vairable?\n",
192 <                 fileName );
193 <        painCave.isFatal = 1;
194 <        simError();
220 >        STR_DEFINE(ffPath, FRC_PATH );
221        }
222        
223        
# Line 237 | Line 263 | void TraPPE_ExFF::initializeAtoms( void ){
263   #endif // is_mpi
264   }
265  
266 + void TraPPE_ExFF::doForces( int calcPot ){
267 +
268 +  int i, isError;
269 +  double* frc;
270 +  double* pos;
271 +  double* tau;
272 +  short int passedCalcPot = (short int)calcPot;
273 +
274 +  // forces are zeroed here, before any are acumulated.
275 +  // NOTE: do not rezero the forces in Fortran.
276 +
277 +  for(i=0; i<entry_plug->n_atoms; i++){
278 +    entry_plug->atoms[i]->zeroForces();
279 +  }
280 +
281 +  frc = Atom::getFrcArray();
282 +  pos = Atom::getPosArray();
283 +  tau = entry_plug->tau;
284 +
285 +  isError = 0;
286 +  fortranForceLoop( pos, frc, &(entry_plug->lrPot), tau,
287 +                    &passedCalcPot, &isError );
288 +
289 +
290 +  if( isError ){
291 +    sprintf( painCave.errMsg,
292 +             "Error returned from the fortran force calculation.\n" );
293 +    painCave.isFatal = 1;
294 +    simError();
295 +  }
296 +
297 + #ifdef IS_MPI
298 +  sprintf( checkPointMsg,
299 +           "successfully returned from the force calculation.\n" );
300 +  MPIcheckPoint();
301 + #endif // is_mpi
302 +
303 + }
304 +  
305 + void TraPPE_ExFF::initFortran( void ){
306 +  
307 +  int nLocal = entry_plug->n_atoms;
308 +  int *ident;
309 +  int isError;
310 +  int i;
311 +
312 +  ident = new int[nLocal];
313 +
314 +  for(i=0; i<nLocal; i++){
315 +    ident[i] = entry_plug->atoms[i]->getIdent();
316 +  }
317 +
318 +  isError = 0;
319 +  initfortran( &nLocal, ident, &isError );
320 +  
321 +  if(isError){
322 +    sprintf( painCave.errMsg,
323 +             "TraPPE_ExFF error: There was an error initializing the component list in fortran.\n" );
324 +    painCave.isFatal = 1;
325 +    simError();
326 +  }
327 +
328 +  
329 + #ifdef IS_MPI
330 +  sprintf( checkPointMsg, "TraPPE_ExFF successfully initialized the fortran component list.\n" );
331 +  MPIcheckPoint();
332 + #endif // is_mpi
333 +  
334 +  delete[] ident;
335 +
336 + }
337 +
338 +
339 +
340 +
341   void TraPPE_ExFF::initializeAtoms( void ){
342    
343    class LinkedType {
# Line 253 | Line 354 | void TraPPE_ExFF::initializeAtoms( void ){
354        return NULL;
355      }
356      
256 #ifdef IS_MPI
357      void add( atomStruct &info ){
358 +
359 +      // check for duplicates
360 +      
361 +      if( !strcmp( info.name, name ) ){
362 +        sprintf( painCave.errMsg,
363 +                 "Duplicate TraPPE_Ex atom type \"%s\" found in "
364 +                 "the TraPPE_ExFF param file./n",
365 +                 name );
366 +        painCave.isFatal = 1;
367 +        simError();
368 +      }
369 +
370        if( next != NULL ) next->add(info);
371        else{
372          next = new LinkedType();
373          strcpy(next->name, info.name);
374 <        next->isDipole = info.dipole;
374 >        next->isDipole = info.isDipole;
375 >        next->isSSD    = info.isSSD;
376          next->mass     = info.mass;
377          next->epslon   = info.epslon;
378          next->sigma    = info.sigma;
379          next->dipole   = info.dipole;
380 +        next->w0       = info.w0;
381 +        next->v0       = info.v0;
382 +        next->ident    = info.ident;
383        }
384      }
385 +
386 + #ifdef IS_MPI
387      
388      void duplicate( atomStruct &info ){
389        strcpy(info.name, name);
390 <      info.isDipole = dipole;
390 >      info.isDipole = isDipole;
391 >      info.isSSD    = isSSD;
392        info.mass     = mass;
393        info.epslon   = epslon;
394        info.sigma    = sigma;
395        info.dipole   = dipole;
396 +      info.w0       = w0;
397 +      info.v0       = v0;
398        info.last     = 0;
399      }
400  
# Line 282 | Line 403 | void TraPPE_ExFF::initializeAtoms( void ){
403  
404      char name[15];
405      int isDipole;
406 +    int isSSD;
407      double mass;
408      double epslon;
409      double sigma;
410      double dipole;
411 +    double w0;
412 +    double v0;
413 +    int ident;
414      LinkedType* next;
415    };
416    
417    LinkedType* headAtomType;
418    LinkedType* currentAtomType;
294  LinkedType* tempAtomType;
295
296 #ifdef IS_MPI
419    atomStruct info;
420    info.last = 1; // initialize last to have the last set.
421                   // if things go well, last will be set to 0
422 < #endif
422 >
423    
424  
303  char readLine[500];
304  char* the_token;
305  char* eof_test;
306  int foundAtom = 0;
307  int lineNum = 0;
425    int i;
426 <
426 >  int identNum;
427    
428 +  Atom** the_atoms;
429 +  int nAtoms;
430 +  the_atoms = entry_plug->atoms;
431 +  nAtoms = entry_plug->n_atoms;
432 +  
433 +  
434    //////////////////////////////////////////////////
435    // a quick water fix
436  
# Line 342 | Line 465 | void TraPPE_ExFF::initializeAtoms( void ){
465  
466    //////////////////////////////////////////////////
467  
468 <  Atom** the_atoms;
346 <  int nAtoms;
347 <  the_atoms = entry_plug->atoms;
348 <  nAtoms = entry_plug->n_atoms;
349 <  
350 <  
468 >
469   #ifdef IS_MPI
470    if( worldRank == 0 ){
471   #endif
472      
473      // read in the atom types.
474 <    
357 <    rewind( frcFile );
474 >
475      headAtomType = new LinkedType;
359    currentAtomType = headAtomType;
476      
477 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
478 <    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 <    
477 >    fastForward( "AtomTypes", "initializeAtoms" );
478 >
479      // we are now at the AtomTypes section.
480      
481      eof_test = fgets( readLine, sizeof(readLine), frcFile );
482      lineNum++;
483      
484 +    
485 +    // read a line, and start parseing out the atom types
486 +
487      if( eof_test == NULL ){
488        sprintf( painCave.errMsg,
489                 "Error in reading Atoms from force file at line %d.\n",
# Line 410 | Line 492 | void TraPPE_ExFF::initializeAtoms( void ){
492        simError();
493      }
494      
495 +    identNum = 1;
496 +    // stop reading at end of file, or at next section
497      while( readLine[0] != '#' && eof_test != NULL ){
498 <      
498 >
499 >      // toss comment lines
500        if( readLine[0] != '!' ){
501          
502 <        the_token = strtok( readLine, " \n\t,;" );
503 <        if( the_token != NULL ){
504 <          
505 <          strcpy( currentAtomType->name, the_token );
506 <          
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 <          }
502 >        // the parser returns 0 if the line was blank
503 >        if( parseAtom( readLine, lineNum, info ) ){
504 >          info.ident = identNum;
505 >          headAtomType->add( info );;
506 >          identNum++;
507          }
508        }
471      
472      tempAtomType = new LinkedType;
473      currentAtomType->next = tempAtomType;
474      currentAtomType = tempAtomType;
475      
509        eof_test = fgets( readLine, sizeof(readLine), frcFile );
510        lineNum++;
511      }
# Line 482 | Line 515 | void TraPPE_ExFF::initializeAtoms( void ){
515      // send out the linked list to all the other processes
516  
517      sprintf( checkPointMsg,
518 <             "TraPPE_Ex atom structures read successfully." );
518 >             "TraPPE_ExFF atom structures read successfully." );
519      MPIcheckPoint();
520  
521 <    currentAtomType = headAtomType;
521 >    currentAtomType = headAtomType->next; //skip the first element who is a place holder.
522      while( currentAtomType != NULL ){
523        currentAtomType->duplicate( info );
524 +
525 +
526 +
527        sendFrcStruct( &info, mpiAtomStructType );
528 +
529 +      sprintf( checkPointMsg,
530 +               "successfully sent TraPPE_Ex force type: \"%s\"\n",
531 +               info.name );
532 +      MPIcheckPoint();
533 +
534        currentAtomType = currentAtomType->next;
535      }
536      info.last = 1;
# Line 504 | Line 546 | void TraPPE_ExFF::initializeAtoms( void ){
546  
547      headAtomType = new LinkedType;
548      recieveFrcStruct( &info, mpiAtomStructType );
549 +    
550      while( !info.last ){
551  
552 +
553 +
554        headAtomType->add( info );
555 +      
556 +      MPIcheckPoint();
557 +
558        recieveFrcStruct( &info, mpiAtomStructType );
559      }
560    }
561   #endif // is_mpi
562  
563 +  // call new A_types in fortran
564    
565 +  int isError;
566 +  
567 +  // dummy variables
568 +  
569 +  int isGB = 0;
570 +  int isLJ = 1;
571 +  
572 +  
573 +  currentAtomType = headAtomType;
574 +  while( currentAtomType != NULL ){
575 +    
576 +    if( currentAtomType->name[0] != '\0' ){
577 +      isError = 0;
578 +          newTPEtype( &(currentAtomType->ident),
579 +                      &(currentAtomType->mass),
580 +                      &(currentAtomType->epslon),
581 +                      &(currentAtomType->sigma),
582 +                      &isLJ,
583 +                      &(currentAtomType->isSSD),
584 +                      &(currentAtomType->isDipole),
585 +                      &isGB,
586 +                      &(currentAtomType->w0),
587 +                      &(currentAtomType->v0),
588 +                      &(currentAtomType->dipole),
589 +                      &isError );
590 +      if( isError ){
591 +        sprintf( painCave.errMsg,
592 +                 "Error initializing the \"%s\" atom type in fortran\n",
593 +                 currentAtomType->name );
594 +        painCave.isFatal = 1;
595 +        simError();
596 +      }
597 +    }
598 +    currentAtomType = currentAtomType->next;
599 +  }
600 +      
601 + #ifdef IS_MPI
602 +  sprintf( checkPointMsg,
603 +           "TraPPE_ExFF atom structures successfully sent to fortran\n" );
604 +  MPIcheckPoint();
605 + #endif // is_mpi
606 +
607 +  
608    // initialize the atoms
609    
610 +  double bigSigma = 0.0;
611    DirectionalAtom* dAtom;
612  
613    for( i=0; i<nAtoms; i++ ){
# Line 533 | Line 626 | void TraPPE_ExFF::initializeAtoms( void ){
626      the_atoms[i]->setSigma( currentAtomType->sigma );
627      the_atoms[i]->setLJ();
628  
629 +    if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma;
630 +
631      if( currentAtomType->isDipole ){
632        if( the_atoms[i]->isDirectional() ){
633          
# Line 582 | Line 677 | void TraPPE_ExFF::initializeAtoms( void ){
677      }
678    }
679  
680 + #ifdef IS_MPI
681 +  double tempBig = bigSigma;
682 +  MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX );
683 + #endif  //is_mpi
684  
685 +  //calc rCut and rList
686 +
687 +  entry_plug->rCut = 2.5 * bigSigma;
688 +  
689 +  if(entry_plug->rCut > (entry_plug->box_x / 2.0))
690 +    entry_plug->rCut = entry_plug->box_x / 2.0;
691 +  
692 +  if(entry_plug->rCut > (entry_plug->box_y / 2.0))
693 +    entry_plug->rCut = entry_plug->box_y / 2.0;
694 +  
695 +  if(entry_plug->rCut > (entry_plug->box_z / 2.0))
696 +    entry_plug->rCut = entry_plug->box_z / 2.0;
697 +
698 +  entry_plug->rList = entry_plug->rCut + 1.0;
699 +
700 +
701    // clean up the memory
702    
703    delete headAtomType;
# Line 591 | Line 706 | void TraPPE_ExFF::initializeAtoms( void ){
706    sprintf( checkPointMsg, "TraPPE_Ex atoms initialized succesfully" );
707    MPIcheckPoint();
708   #endif // is_mpi
709 +
710 +  initFortran();
711 +  entry_plug->refreshSim();
712  
713   }
714  
# Line 613 | Line 731 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
731        return NULL;
732      }
733      
734 < #ifdef IS_MPI
734 >
735      void add( bondStruct &info ){
736 +      
737 +      // check for duplicates
738 +      int dup = 0;
739 +
740 +      if( !strcmp(nameA, info.nameA ) && !strcmp( nameB, info.nameB ) ) dup = 1;
741 +      if( !strcmp(nameA, info.nameB ) && !strcmp( nameB, info.nameA ) ) dup = 1;
742 +      
743 +      if(dup){
744 +        sprintf( painCave.errMsg,
745 +                 "Duplicate TraPPE_Ex bond type \"%s - %s\" found in "
746 +                 "the TraPPE_ExFF param file./n",
747 +                 nameA, nameB );
748 +        painCave.isFatal = 1;
749 +        simError();
750 +      }
751 +
752 +        
753        if( next != NULL ) next->add(info);
754        else{
755          next = new LinkedType();
# Line 625 | Line 760 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
760        }
761      }
762      
763 + #ifdef IS_MPI
764      void duplicate( bondStruct &info ){
765        strcpy(info.nameA, nameA);
766        strcpy(info.nameB, nameB);
# Line 648 | Line 784 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
784    
785    LinkedType* headBondType;
786    LinkedType* currentBondType;
651  LinkedType* tempBondType;
652
653 #ifdef IS_MPI
787    bondStruct info;
788    info.last = 1; // initialize last to have the last set.
789                   // if things go well, last will be set to 0
657 #endif
790  
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
791    SRI **the_sris;
792    Atom** the_atoms;
793    int nBonds;
# Line 672 | Line 795 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
795    the_atoms = entry_plug->atoms;
796    nBonds = entry_plug->n_bonds;
797  
798 +  int i, a, b;
799 +  char* atomA;
800 +  char* atomB;
801    
802   #ifdef IS_MPI
803    if( worldRank == 0 ){
# Line 679 | Line 805 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
805      
806      // read in the bond types.
807      
682    rewind( frcFile );
808      headBondType = new LinkedType;
684    currentBondType = headBondType;
809      
810 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
810 >    fastForward( "BondTypes", "initializeBonds" );
811 >
812 >    // we are now at the bondTypes section
813 >
814 >    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
815      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    }
816      
817      
818 <    while( !foundBond ){
819 <      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 <    
818 >    // read a line, and start parseing out the atom types
819 >
820      if( eof_test == NULL ){
821        sprintf( painCave.errMsg,
822 <               "Error in reading Bonds from force file at line %d.\n",
822 >               "Error in reading bonds from force file at line %d.\n",
823                 lineNum );
824        painCave.isFatal = 1;
825        simError();
826      }
827      
828 +    // stop reading at end of file, or at next section
829      while( readLine[0] != '#' && eof_test != NULL ){
830 <      
830 >
831 >      // toss comment lines
832        if( readLine[0] != '!' ){
833          
834 <        the_token = strtok( readLine, " \n\t,;" );
835 <        if( the_token != NULL ){
836 <          
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 <          }              
834 >        // the parser returns 0 if the line was blank
835 >        if( parseBond( readLine, lineNum, info ) ){
836 >          headBondType->add( info );
837          }
838        }
786      
787      tempBondType = new LinkedType;
788      currentBondType->next = tempBondType;
789      currentBondType = tempBondType;
790      
839        eof_test = fgets( readLine, sizeof(readLine), frcFile );
840        lineNum++;
841      }
842 <    
842 >        
843   #ifdef IS_MPI
844      
845      // send out the linked list to all the other processes
# Line 890 | Line 938 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
938        return NULL;
939      }
940      
893 #ifdef IS_MPI
894
941      void add( bendStruct &info ){
942 +
943 +      // check for duplicates
944 +      int dup = 0;
945 +      
946 +      if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB )
947 +          && !strcmp( nameC, info.nameC ) ) dup = 1;
948 +      if( !strcmp( nameA, info.nameC ) && !strcmp( nameB, info.nameB )
949 +          && !strcmp( nameC, info.nameA ) ) dup = 1;
950 +
951 +      if(dup){
952 +        sprintf( painCave.errMsg,
953 +                 "Duplicate TraPPE_Ex bend type \"%s - %s - %s\" found in "
954 +                 "the TraPPE_ExFF param file./n",
955 +                 nameA, nameB, nameC );
956 +        painCave.isFatal = 1;
957 +        simError();
958 +      }
959 +
960        if( next != NULL ) next->add(info);
961        else{
962          next = new LinkedType();
# Line 906 | Line 970 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
970          next->t0 = info.t0;
971        }
972      }
973 <    
973 >
974 > #ifdef IS_MPI    
975 >
976      void duplicate( bendStruct &info ){
977        strcpy(info.nameA, nameA);
978        strcpy(info.nameB, nameB);
# Line 932 | Line 998 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
998    
999    LinkedType* headBendType;
1000    LinkedType* currentBendType;
935  LinkedType* tempBendType;
936
937 #ifdef IS_MPI
1001    bendStruct info;
1002    info.last = 1; // initialize last to have the last set.
1003                   // if things go well, last will be set to 0
941 #endif
1004  
1005 <  char readLine[500];
1006 <  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 <
1005 >  QuadraticBend* qBend;
1006 >  GhostBend* gBend;
1007    SRI **the_sris;
1008    Atom** the_atoms;
1009    int nBends;
# Line 958 | Line 1011 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1011    the_atoms = entry_plug->atoms;
1012    nBends = entry_plug->n_bends;
1013  
1014 +  int i, a, b, c;
1015 +  char* atomA;
1016 +  char* atomB;
1017 +  char* atomC;
1018  
1019 +
1020   #ifdef IS_MPI
1021    if( worldRank == 0 ){
1022   #endif
1023  
1024      // read in the bend types.
1025  
968    rewind( frcFile );
1026      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 );
1027      
1028 <      if( !foundBend ){
998 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
999 <        lineNum++;
1028 >    fastForward( "BendTypes", "initializeBends" );
1029  
1030 <        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 <    }
1030 >    // we are now at the bendTypes section
1031  
1032 <    // we are now at the BendTypes section.
1012 <
1013 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
1032 >    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
1033      lineNum++;
1034 <  
1034 >        
1035 >    // read a line, and start parseing out the bend types
1036 >
1037      if( eof_test == NULL ){
1038        sprintf( painCave.errMsg,
1039 <               "Error in reading Bends from force file at line %d.\n",
1039 >               "Error in reading bends from force file at line %d.\n",
1040                 lineNum );
1041        painCave.isFatal = 1;
1042        simError();
1043      }
1023
1024    while( readLine[0] != '#' && eof_test != NULL ){
1044      
1045 <      if( readLine[0] != '!' ){
1045 >    // stop reading at end of file, or at next section
1046 >    while( readLine[0] != '#' && eof_test != NULL ){
1047        
1048 <        the_token = strtok( readLine, " \n\t,;" );
1049 <        if( the_token != NULL ){
1048 >      // toss comment lines
1049 >      if( readLine[0] != '!' ){
1050          
1051 <          strcpy( currentBendType->nameA, the_token );
1052 <        
1053 <          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 <          }              
1051 >        // the parser returns 0 if the line was blank
1052 >        if( parseBend( readLine, lineNum, info ) ){
1053 >          headBendType->add( info );
1054          }
1055        }
1108    
1109      tempBendType = new LinkedType;
1110      currentBendType->next = tempBendType;
1111      currentBendType = tempBendType;
1112    
1056        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1057        lineNum++;
1058      }
1059 <
1059 >    
1060   #ifdef IS_MPI
1061      
1062      // send out the linked list to all the other processes
# Line 1150 | Line 1093 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1093   #endif // is_mpi
1094    
1095    // initialize the Bends
1096 +  
1097 +  int index;
1098  
1099    for( i=0; i<nBends; i++ ){
1100      
# Line 1159 | Line 1104 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1104  
1105      atomA = the_atoms[a]->getType();
1106      atomB = the_atoms[b]->getType();
1107 <    atomC = the_atoms[c]->getType();
1107 >
1108 >    if( the_bends[i].isGhost ) atomC = "GHOST";
1109 >    else atomC = the_atoms[c]->getType();
1110 >
1111      currentBendType = headBendType->find( atomA, atomB, atomC );
1112      if( currentBendType == NULL ){
1113        sprintf( painCave.errMsg, "BendType error, %s - %s - %s not found"
# Line 1172 | Line 1120 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1120      if( !strcmp( currentBendType->type, "quadratic" ) ){
1121        
1122        index = i + entry_plug->n_bonds;
1123 <      qBend = new QuadraticBend( *the_atoms[a],
1124 <                                 *the_atoms[b],
1125 <                                 *the_atoms[c] );
1126 <      qBend->setConstants( currentBendType->k1,
1127 <                           currentBendType->k2,
1128 <                           currentBendType->k3,
1129 <                           currentBendType->t0 );
1130 <      the_sris[index] = qBend;
1123 >      
1124 >      if( the_bends[i].isGhost){
1125 >        
1126 >        if( the_bends[i].ghost == b ){
1127 >          // do nothing
1128 >        }
1129 >        else if( the_bends[i].ghost == a ){
1130 >          c = a;
1131 >          a = b;
1132 >          b = a;
1133 >        }
1134 >        else{
1135 >          sprintf( painCave.errMsg,
1136 >                   "BendType error, %s - %s - %s,\n"
1137 >                   "  --> central atom is not "
1138 >                   "correctly identified with the "
1139 >                   "\"ghostVectorSource = \" tag.\n",
1140 >                   atomA, atomB, atomC );
1141 >          painCave.isFatal = 1;
1142 >          simError();
1143 >        }
1144 >        
1145 >        gBend = new GhostBend( *the_atoms[a],
1146 >                               *the_atoms[b] );                        
1147 >        gBend->setConstants( currentBendType->k1,
1148 >                             currentBendType->k2,
1149 >                             currentBendType->k3,
1150 >                             currentBendType->t0 );
1151 >        the_sris[index] = gBend;
1152 >      }
1153 >      else{
1154 >        qBend = new QuadraticBend( *the_atoms[a],
1155 >                                   *the_atoms[b],
1156 >                                   *the_atoms[c] );
1157 >        qBend->setConstants( currentBendType->k1,
1158 >                             currentBendType->k2,
1159 >                             currentBendType->k3,
1160 >                             currentBendType->t0 );
1161 >        the_sris[index] = qBend;
1162 >      }
1163      }
1164    }
1165  
# Line 1213 | Line 1193 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1193            !strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this;
1194  
1195        if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) &&
1196 <          !strcmp( nameC, key2 ) && !strcmp( nameD, key4 ) ) return this;
1196 >          !strcmp( nameC, key2 ) && !strcmp( nameD, key1 ) ) return this;
1197  
1198        if( next != NULL ) return next->find(key1, key2, key3, key4);
1199        return NULL;
1200      }
1221    
1222 #ifdef IS_MPI
1201  
1202      void add( torsionStruct &info ){
1203 +
1204 +      // check for duplicates
1205 +      int dup = 0;
1206 +
1207 +      if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) &&
1208 +          !strcmp( nameC, info.nameC ) && !strcmp( nameD, info.nameD ) ) dup = 1;
1209 +      
1210 +      if( !strcmp( nameA, info.nameD ) && !strcmp( nameB, info.nameC ) &&
1211 +          !strcmp( nameC, info.nameB ) && !strcmp( nameD, info.nameA ) ) dup = 1;
1212 +      
1213 +      if(dup){
1214 +        sprintf( painCave.errMsg,
1215 +                 "Duplicate TraPPE_Ex torsion type \"%s - %s - %s - %s\" found in "
1216 +                 "the TraPPE_ExFF param file./n", nameA, nameB, nameC, nameD );
1217 +        painCave.isFatal = 1;
1218 +        simError();
1219 +      }
1220 +
1221        if( next != NULL ) next->add(info);
1222        else{
1223          next = new LinkedType();
# Line 1235 | Line 1231 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1231          next->k4 = info.k4;
1232        }
1233      }
1234 +
1235 + #ifdef IS_MPI
1236      
1237      void duplicate( torsionStruct &info ){
1238        strcpy(info.nameA, nameA);
# Line 1263 | Line 1261 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1261    
1262    LinkedType* headTorsionType;
1263    LinkedType* currentTorsionType;
1266  LinkedType* tempTorsionType;
1267
1268 #ifdef IS_MPI
1264    torsionStruct info;
1265    info.last = 1; // initialize last to have the last set.
1266                   // if things go well, last will be set to 0
1272 #endif
1267  
1274  char readLine[500];
1275  char* the_token;
1276  char* eof_test;
1277  int foundTorsion = 0;
1278  int lineNum = 0;
1268    int i, a, b, c, d, index;
1269    char* atomA;
1270    char* atomB;
# Line 1296 | Line 1285 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1285  
1286      // read in the torsion types.
1287  
1299    rewind( frcFile );
1288      headTorsionType = new LinkedType;
1289 <    currentTorsionType = headTorsionType;
1290 <  
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 <    }
1289 >    
1290 >    fastForward( "TorsionTypes", "initializeTorsions" );
1291  
1292 <  
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 <      }
1292 >    // we are now at the torsionTypes section
1293  
1294 <      the_token = strtok( readLine, " ,;\t#\n" );
1295 <      foundTorsion = !strcmp( "TorsionTypes", the_token );
1294 >    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
1295 >    lineNum++;
1296      
1297 <      if( !foundTorsion ){
1298 <        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1331 <        lineNum++;
1297 >    
1298 >    // read a line, and start parseing out the atom types
1299  
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  
1300      if( eof_test == NULL ){
1301        sprintf( painCave.errMsg,
1302 <               "Error in reading Torsions from force file at line %d.\n",
1302 >               "Error in reading torsions from force file at line %d.\n",
1303                 lineNum );
1304        painCave.isFatal = 1;
1305        simError();
1306      }
1355
1356    while( readLine[0] != '#' && eof_test != NULL ){
1307      
1308 +    // stop reading at end of file, or at next section
1309 +    while( readLine[0] != '#' && eof_test != NULL ){
1310 +
1311 +      // toss comment lines
1312        if( readLine[0] != '!' ){
1359      
1360        the_token = strtok( readLine, " \n\t,;" );
1361        if( the_token != NULL ){
1313          
1314 <          strcpy( currentTorsionType->nameA, the_token );
1315 <        
1316 <          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 <          }              
1314 >        // the parser returns 0 if the line was blank
1315 >        if( parseTorsion( readLine, lineNum, info ) ){
1316 >          headTorsionType->add( info );
1317          }
1318        }
1449    
1450      tempTorsionType = new LinkedType;
1451      currentTorsionType->next = tempTorsionType;
1452      currentTorsionType = tempTorsionType;
1453    
1319        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1320        lineNum++;
1321      }
# Line 1533 | Line 1398 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1398    sprintf( checkPointMsg, "TraPPE_Ex torsions initialized succesfully" );
1399    MPIcheckPoint();
1400   #endif // is_mpi
1401 +
1402 + }
1403 +
1404 + void TraPPE_ExFF::fastForward( char* stopText, char* searchOwner ){
1405 +
1406 +  int foundText = 0;
1407 +  char* the_token;
1408 +
1409 +  rewind( frcFile );
1410 +  lineNum = 0;
1411 +
1412 +  eof_test = fgets( readLine, sizeof(readLine), frcFile );
1413 +  lineNum++;
1414 +  if( eof_test == NULL ){
1415 +    sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
1416 +             " file is empty.\n",
1417 +             searchOwner );
1418 +    painCave.isFatal = 1;
1419 +    simError();
1420 +  }
1421 +  
1422 +  
1423 +  while( !foundText ){
1424 +    while( eof_test != NULL && readLine[0] != '#' ){
1425 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1426 +      lineNum++;
1427 +    }
1428 +    if( eof_test == NULL ){
1429 +      sprintf( painCave.errMsg,
1430 +               "Error fast forwarding force file for %s at "
1431 +               "line %d: file ended unexpectedly.\n",
1432 +               searchOwner,
1433 +               lineNum );
1434 +      painCave.isFatal = 1;
1435 +      simError();
1436 +    }
1437 +    
1438 +    the_token = strtok( readLine, " ,;\t#\n" );
1439 +    foundText = !strcmp( stopText, the_token );
1440 +    
1441 +    if( !foundText ){
1442 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1443 +      lineNum++;
1444 +      
1445 +      if( eof_test == NULL ){
1446 +        sprintf( painCave.errMsg,
1447 +                 "Error fast forwarding force file for %s at "
1448 +                 "line %d: file ended unexpectedly.\n",
1449 +                 searchOwner,
1450 +                 lineNum );
1451 +        painCave.isFatal = 1;
1452 +        simError();
1453 +      }
1454 +    }
1455 +  }  
1456 + }
1457  
1458 +
1459 + int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){
1460 +
1461 +  char* the_token;
1462 +  
1463 +  the_token = strtok( lineBuffer, " \n\t,;" );
1464 +  if( the_token != NULL ){
1465 +    
1466 +    strcpy( info.name, the_token );
1467 +
1468 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1469 +      sprintf( painCave.errMsg,
1470 +               "Error parseing AtomTypes: line %d\n", lineNum );
1471 +      painCave.isFatal = 1;
1472 +      simError();
1473 +    }
1474 +    
1475 +    info.isDipole = atoi( the_token );
1476 +
1477 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1478 +      sprintf( painCave.errMsg,
1479 +               "Error parseing AtomTypes: line %d\n", lineNum );
1480 +      painCave.isFatal = 1;
1481 +      simError();
1482 +    }
1483 +
1484 +    info.isSSD = atoi( the_token );
1485 +
1486 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1487 +      sprintf( painCave.errMsg,
1488 +               "Error parseing AtomTypes: line %d\n", lineNum );
1489 +      painCave.isFatal = 1;
1490 +      simError();
1491 +    }
1492 +    
1493 +    info.mass = atof( the_token );
1494 +    
1495 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1496 +      sprintf( painCave.errMsg,
1497 +               "Error parseing AtomTypes: line %d\n", lineNum );
1498 +      painCave.isFatal = 1;
1499 +      simError();
1500 +    }
1501 +        
1502 +    info.epslon = atof( the_token );
1503 +          
1504 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1505 +      sprintf( painCave.errMsg,
1506 +               "Error parseing AtomTypes: line %d\n", lineNum );
1507 +      painCave.isFatal = 1;
1508 +      simError();
1509 +    }
1510 +        
1511 +    info.sigma = atof( the_token );
1512 +
1513 +    if( info.isDipole ){
1514 +      
1515 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1516 +        sprintf( painCave.errMsg,
1517 +                 "Error parseing AtomTypes: line %d\n", lineNum );
1518 +        painCave.isFatal = 1;
1519 +        simError();
1520 +      }
1521 +      
1522 +      info.dipole = atof( the_token );
1523 +    }
1524 +    else info.dipole = 0.0;
1525 +
1526 +    if( info.isSSD ){
1527 +
1528 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1529 +        sprintf( painCave.errMsg,
1530 +                 "Error parseing AtomTypes: line %d\n", lineNum );
1531 +        painCave.isFatal = 1;
1532 +        simError();
1533 +      }
1534 +      
1535 +      info.w0 = atof( the_token );
1536 +
1537 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1538 +        sprintf( painCave.errMsg,
1539 +                 "Error parseing AtomTypes: line %d\n", lineNum );
1540 +        painCave.isFatal = 1;
1541 +        simError();
1542 +      }
1543 +      
1544 +      info.v0 = atof( the_token );
1545 +    }
1546 +    else info.v0 = info.w0 = 0.0;
1547 +
1548 +    return 1;
1549 +  }
1550 +  else return 0;
1551   }
1552 +
1553 + int parseBond( char *lineBuffer, int lineNum, bondStruct &info ){
1554 +
1555 +  char* the_token;
1556 +  
1557 +  the_token = strtok( lineBuffer, " \n\t,;" );
1558 +  if( the_token != NULL ){
1559 +    
1560 +    strcpy( info.nameA, the_token );
1561 +
1562 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1563 +      sprintf( painCave.errMsg,
1564 +               "Error parseing BondTypes: line %d\n", lineNum );
1565 +      painCave.isFatal = 1;
1566 +      simError();
1567 +    }
1568 +    
1569 +    strcpy( info.nameB, the_token );
1570 +
1571 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1572 +      sprintf( painCave.errMsg,
1573 +               "Error parseing BondTypes: line %d\n", lineNum );
1574 +      painCave.isFatal = 1;
1575 +      simError();
1576 +    }
1577 +    
1578 +    strcpy( info.type, the_token );
1579 +    
1580 +    if( !strcmp( info.type, "fixed" ) ){
1581 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1582 +        sprintf( painCave.errMsg,
1583 +                 "Error parseing BondTypes: line %d\n", lineNum );
1584 +        painCave.isFatal = 1;
1585 +        simError();
1586 +      }
1587 +      
1588 +      info.d0 = atof( the_token );
1589 +    }
1590 +    else{
1591 +      sprintf( painCave.errMsg,
1592 +               "Unknown TraPPE_Ex bond type \"%s\" at line %d\n",
1593 +               info.type,
1594 +               lineNum );
1595 +      painCave.isFatal = 1;
1596 +      simError();
1597 +    }            
1598 +    
1599 +    return 1;
1600 +  }
1601 +  else return 0;
1602 + }
1603 +
1604 +
1605 + int parseBend( char *lineBuffer, int lineNum, bendStruct &info ){
1606 +
1607 +  char* the_token;
1608 +  
1609 +  the_token = strtok( lineBuffer, " \n\t,;" );
1610 +  if( the_token != NULL ){
1611 +    
1612 +    strcpy( info.nameA, the_token );
1613 +
1614 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1615 +      sprintf( painCave.errMsg,
1616 +               "Error parseing BondTypes: line %d\n", lineNum );
1617 +      painCave.isFatal = 1;
1618 +      simError();
1619 +    }
1620 +    
1621 +    strcpy( info.nameB, the_token );
1622 +
1623 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1624 +      sprintf( painCave.errMsg,
1625 +               "Error parseing BondTypes: line %d\n", lineNum );
1626 +      painCave.isFatal = 1;
1627 +      simError();
1628 +    }
1629 +    
1630 +    strcpy( info.nameC, the_token );
1631 +
1632 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1633 +      sprintf( painCave.errMsg,
1634 +               "Error parseing BondTypes: line %d\n", lineNum );
1635 +      painCave.isFatal = 1;
1636 +      simError();
1637 +    }
1638 +    
1639 +    strcpy( info.type, the_token );
1640 +
1641 +    if( !strcmp( info.type, "quadratic" ) ){
1642 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1643 +        sprintf( painCave.errMsg,
1644 +                 "Error parseing BendTypes: line %d\n", lineNum );
1645 +        painCave.isFatal = 1;
1646 +        simError();
1647 +      }
1648 +        
1649 +      info.k1 = atof( the_token );
1650 +      
1651 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1652 +        sprintf( painCave.errMsg,
1653 +                 "Error parseing BendTypes: line %d\n", lineNum );
1654 +        painCave.isFatal = 1;
1655 +        simError();
1656 +      }
1657 +      
1658 +      info.k2 = atof( the_token );
1659 +      
1660 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1661 +        sprintf( painCave.errMsg,
1662 +                 "Error parseing BendTypes: line %d\n", lineNum );
1663 +        painCave.isFatal = 1;
1664 +        simError();
1665 +      }
1666 +        
1667 +      info.k3 = atof( the_token );
1668 +      
1669 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1670 +        sprintf( painCave.errMsg,
1671 +                 "Error parseing BendTypes: line %d\n", lineNum );
1672 +        painCave.isFatal = 1;
1673 +        simError();
1674 +      }
1675 +      
1676 +      info.t0 = atof( the_token );
1677 +    }
1678 +    
1679 +    else{
1680 +      sprintf( painCave.errMsg,
1681 +               "Unknown TraPPE_Ex bend type \"%s\" at line %d\n",
1682 +               info.type,
1683 +               lineNum );
1684 +      painCave.isFatal = 1;
1685 +      simError();
1686 +    }            
1687 +        
1688 +    return 1;
1689 +  }
1690 +  else return 0;
1691 + }
1692 +
1693 + int parseTorsion( char *lineBuffer, int lineNum, torsionStruct &info ){
1694 +  
1695 +  char*  the_token;
1696 +
1697 +  the_token = strtok( lineBuffer, " \n\t,;" );
1698 +  if( the_token != NULL ){
1699 +    
1700 +    strcpy( info.nameA, the_token );
1701 +        
1702 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1703 +      sprintf( painCave.errMsg,
1704 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1705 +      painCave.isFatal = 1;
1706 +      simError();
1707 +    }
1708 +    
1709 +    strcpy( info.nameB, the_token );
1710 +
1711 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1712 +      sprintf( painCave.errMsg,
1713 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1714 +      painCave.isFatal = 1;
1715 +      simError();
1716 +    }
1717 +    
1718 +    strcpy( info.nameC, the_token );
1719 +    
1720 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1721 +      sprintf( painCave.errMsg,
1722 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1723 +      painCave.isFatal = 1;
1724 +      simError();
1725 +    }
1726 +    
1727 +    strcpy( info.nameD, the_token );
1728 +    
1729 +    if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1730 +      sprintf( painCave.errMsg,
1731 +               "Error parseing TorsionTypes: line %d\n", lineNum );
1732 +      painCave.isFatal = 1;
1733 +      simError();
1734 +    }
1735 +    
1736 +    strcpy( info.type, the_token );
1737 +    
1738 +    if( !strcmp( info.type, "cubic" ) ){
1739 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1740 +        sprintf( painCave.errMsg,
1741 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1742 +        painCave.isFatal = 1;
1743 +        simError();
1744 +      }
1745 +      
1746 +      info.k1 = atof( the_token );
1747 +      
1748 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1749 +        sprintf( painCave.errMsg,
1750 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1751 +        painCave.isFatal = 1;
1752 +        simError();
1753 +      }
1754 +      
1755 +      info.k2 = atof( the_token );
1756 +      
1757 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1758 +        sprintf( painCave.errMsg,
1759 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1760 +        painCave.isFatal = 1;
1761 +        simError();
1762 +      }
1763 +      
1764 +      info.k3 = atof( the_token );
1765 +      
1766 +      if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1767 +        sprintf( painCave.errMsg,
1768 +                 "Error parseing TorsionTypes: line %d\n", lineNum );
1769 +        painCave.isFatal = 1;
1770 +        simError();
1771 +      }
1772 +      
1773 +      info.k4 = atof( the_token );
1774 +    
1775 +    }
1776 +    
1777 +    else{
1778 +      sprintf( painCave.errMsg,
1779 +               "Unknown TraPPE_Ex torsion type \"%s\" at line %d\n",
1780 +               info.type,
1781 +               lineNum );
1782 +      painCave.isFatal = 1;
1783 +      simError();
1784 +    }            
1785 +    
1786 +    return 1;
1787 +  }
1788 +  
1789 +  else return 0;
1790 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines