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

Comparing trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp (file contents):
Revision 146 by mmeineke, Fri Oct 18 16:15:05 2002 UTC vs.
Revision 176 by mmeineke, Thu Nov 14 22:00:44 2002 UTC

# Line 7 | Line 7 | using namespace std;
7  
8   #include "ForceFields.hpp"
9   #include "SRI.hpp"
10 + #include "simError.h"
11  
12  
13   #ifdef IS_MPI
14  
15 < int myNode;
15 > #include "mpiForceField.h"
16  
17 +
18   // Declare the structures that will be passed by MPI
19  
20   typedef struct{
# Line 24 | Line 26 | typedef struct{
26    int isDipole;
27    int last;      //  0  -> default
28                   //  1  -> tells nodes to stop listening
27                 // -1  -> an error has occured. (handled in mpiForceField)
29   } atomStruct;
30   MPI_Datatype mpiAtomStructType;
31  
# Line 35 | Line 36 | typedef struct{
36    double d0;
37    int last;      //  0  -> default
38                   //  1  -> tells nodes to stop listening
38                 // -1  -> an error has occured. (handled in mpiForceField)
39   } bondStruct;
40   MPI_Datatype mpiBondStructType;
41  
# Line 47 | Line 47 | typedef struct{
47    double k1, k2, k3, t0;
48    int last;      //  0  -> default
49                   //  1  -> tells nodes to stop listening
50                 // -1  -> an error has occured. (handled in mpiForceField)
50   } bendStruct;
51   MPI_Datatype mpiBendStructType;
52  
# Line 60 | Line 59 | typedef struct{
59    double k1, k2, k3, k4;
60    int last;      //  0  -> default
61                   //  1  -> tells nodes to stop listening
62 <                 // -1  -> an error has occured. (handled in mpiForceField)
64 < } TorsionStruct;
62 > } torsionStruct;
63   MPI_Datatype mpiTorsionStructType;
64  
65   #endif
# Line 74 | Line 72 | TraPPE_ExFF::TraPPE_ExFF(){
72    char* ffPath_env = "FORCE_PARAM_PATH";
73    char* ffPath;
74    char temp[200];
75 +  char errMsg[1000];
76  
77   #ifdef IS_MPI
78    int i;
79 <  int mpiError;
79 >  
80 >   // **********************************************************************
81 >  // Init the atomStruct mpi type
82  
82  mpiError = MPI_Comm_rank(MPI_COMM_WORLD,&myNode);
83
83    atomStruct atomProto; // mpiPrototype
84    int atomBC[3] = {15,4,2};  // block counts
85    MPI_Aint atomDspls[3];           // displacements
86    MPI_Datatype atomMbrTypes[3];    // member mpi types
87  
89  
90  
88    MPI_Address(&atomProto.name, &atomDspls[0]);
89    MPI_Address(&atomProto.mass, &atomDspls[1]);
90    MPI_Address(&atomProto.isDipole, &atomDspls[2]);
# Line 102 | Line 99 | TraPPE_ExFF::TraPPE_ExFF(){
99    MPI_Type_commit(&mpiAtomStructType);
100  
101  
102 +  // **********************************************************************
103 +  // Init the bondStruct mpi type
104 +  
105 +  bondStruct bondProto; // mpiPrototype
106 +  int bondBC[3] = {60,1,1};  // block counts
107 +  MPI_Aint bondDspls[3];           // displacements
108 +  MPI_Datatype bondMbrTypes[3];    // member mpi types
109 +  
110 +  MPI_Address(&bondProto.nameA, &bondDspls[0]);
111 +  MPI_Address(&bondProto.d0,    &bondDspls[1]);
112 +  MPI_Address(&bondProto.last,  &bondDspls[2]);
113 +  
114 +  bondMbrTypes[0] = MPI_CHAR;
115 +  bondMbrTypes[1] = MPI_DOUBLE;
116 +  bondMbrTypes[2] = MPI_INT;
117 +  
118 +  for (i=2; i >= 0; i--) bondDspls[i] -= bondDspls[0];
119 +  
120 +  MPI_Type_struct(3, bondBC, bondDspls, bondMbrTypes, &mpiBondStructType);
121 +  MPI_Type_commit(&mpiBondStructType);
122  
123  
124 <  if( myNode == 0 ){
124 >  // **********************************************************************
125 >  // Init the bendStruct mpi type
126 >  
127 >  bendStruct bendProto; // mpiPrototype
128 >  int bendBC[3] = {75,4,1};  // block counts
129 >  MPI_Aint bendDspls[3];           // displacements
130 >  MPI_Datatype bendMbrTypes[3];    // member mpi types
131 >  
132 >  MPI_Address(&bendProto.nameA, &bendDspls[0]);
133 >  MPI_Address(&bendProto.k1,    &bendDspls[1]);
134 >  MPI_Address(&bendProto.last,  &bendDspls[2]);
135 >  
136 >  bendMbrTypes[0] = MPI_CHAR;
137 >  bendMbrTypes[1] = MPI_DOUBLE;
138 >  bendMbrTypes[2] = MPI_INT;
139 >  
140 >  for (i=2; i >= 0; i--) bendDspls[i] -= bendDspls[0];
141 >  
142 >  MPI_Type_struct(3, bendBC, bendDspls, bendMbrTypes, &mpiBendStructType);
143 >  MPI_Type_commit(&mpiBendStructType);
144 >
145 >
146 >  // **********************************************************************
147 >  // Init the torsionStruct mpi type
148 >  
149 >  torsionStruct torsionProto; // mpiPrototype
150 >  int torsionBC[3] = {90,4,1};  // block counts
151 >  MPI_Aint torsionDspls[3];           // displacements
152 >  MPI_Datatype torsionMbrTypes[3];    // member mpi types
153 >  
154 >  MPI_Address(&torsionProto.nameA, &torsionDspls[0]);
155 >  MPI_Address(&torsionProto.k1,    &torsionDspls[1]);
156 >  MPI_Address(&torsionProto.last,  &torsionDspls[2]);
157 >  
158 >  torsionMbrTypes[0] = MPI_CHAR;
159 >  torsionMbrTypes[1] = MPI_DOUBLE;
160 >  torsionMbrTypes[2] = MPI_INT;
161 >  
162 >  for (i=2; i >= 0; i--) torsionDspls[i] -= torsionDspls[0];
163 >  
164 >  MPI_Type_struct(3, torsionBC, torsionDspls, torsionMbrTypes,
165 >                  &mpiTorsionStructType);
166 >  MPI_Type_commit(&mpiTorsionStructType);
167 >
168 >  // ***********************************************************************
169 >  
170 >  if( worldRank == 0 ){
171   #endif
172      
173      // generate the force file name
174      
175      strcpy( fileName, "TraPPE_Ex.frc" );
176 <    fprintf( stderr,"Trying to open %s\n", fileName );
176 >    //    fprintf( stderr,"Trying to open %s\n", fileName );
177      
178      // attempt to open the file in the current directory first.
179      
# Line 122 | Line 185 | TraPPE_ExFF::TraPPE_ExFF(){
185        
186        ffPath = getenv( ffPath_env );
187        if( ffPath == NULL ) {
188 <        fprintf( stderr,
188 >        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 <        exit( 8 );
193 >        painCave.isFatal = 1;
194 >        simError();
195        }
196        
197        
# Line 140 | Line 204 | TraPPE_ExFF::TraPPE_ExFF(){
204        
205        if( frcFile == NULL ){
206          
207 <        fprintf( stderr,
207 >        sprintf( painCave.errMsg,
208                   "Error opening the force field parameter file: %s\n"
209                   "Have you tried setting the FORCE_PARAM_PATH environment "
210                   "vairable?\n",
211                   fileName );
212 <        exit( 8 );
212 >        painCave.isFatal = 1;
213 >        simError();
214        }
215      }
216 +    
217   #ifdef IS_MPI
218    }
219 < #endif
219 >  
220 >  sprintf( checkPointMsg, "TraPPE_ExFF file opened sucessfully." );
221 >  MPIcheckPoint();
222 >  
223 > #endif // is_mpi
224   }
225  
226  
227   TraPPE_ExFF::~TraPPE_ExFF(){
228 <  
229 <  fclose( frcFile );
228 >
229 > #ifdef IS_MPI
230 >  if( worldRank == 0 ){
231 > #endif // is_mpi
232 >    
233 >    fclose( frcFile );
234 >    
235 > #ifdef IS_MPI
236 >  }
237 > #endif // is_mpi
238   }
239  
240   void TraPPE_ExFF::initializeAtoms( void ){
# Line 215 | Line 293 | void TraPPE_ExFF::initializeAtoms( void ){
293    LinkedType* currentAtomType;
294    LinkedType* tempAtomType;
295  
296 + #ifdef IS_MPI
297 +  atomStruct info;
298 +  info.last = 1; // initialize last to have the last set.
299 +                 // if things go well, last will be set to 0
300 + #endif
301 +  
302 +
303    char readLine[500];
304    char* the_token;
305    char* eof_test;
306    int foundAtom = 0;
307    int lineNum = 0;
308    int i;
309 +
310    
311    //////////////////////////////////////////////////
312    // a quick water fix
# Line 261 | Line 347 | void TraPPE_ExFF::initializeAtoms( void ){
347    the_atoms = entry_plug->atoms;
348    nAtoms = entry_plug->n_atoms;
349    
264  // read in the atom types.
265
266  rewind( frcFile );
267  headAtomType = new LinkedType;
268  currentAtomType = headAtomType;
350    
351 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
352 <  lineNum++;
353 <  if( eof_test == NULL ){
354 <    fprintf( stderr, "Error in reading Atoms from force file.\n" );
355 <    exit(8);
356 <  }
357 <
358 <  
359 <  while( !foundAtom ){
360 <    while( eof_test != NULL && readLine[0] != '#' ){
361 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
362 <      lineNum++;
282 <    }
351 > #ifdef IS_MPI
352 >  if( worldRank == 0 ){
353 > #endif
354 >    
355 >    // read in the atom types.
356 >    
357 >    rewind( frcFile );
358 >    headAtomType = new LinkedType;
359 >    currentAtomType = headAtomType;
360 >    
361 >    eof_test = fgets( readLine, sizeof(readLine), frcFile );
362 >    lineNum++;
363      if( eof_test == NULL ){
364 <      fprintf( stderr,
365 <               "Error in reading Atoms from force file at line %d.\n",
366 <               lineNum );
287 <      exit(8);
364 >      sprintf( painCave.errMsg, "Error in reading Atoms from force file.\n" );
365 >      painCave.isFatal = 1;
366 >      simError();
367      }
289
290    the_token = strtok( readLine, " ,;\t#\n" );
291    foundAtom = !strcmp( "AtomTypes", the_token );
368      
369 <    if( !foundAtom ){
370 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
371 <      lineNum++;
372 <
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 <        fprintf( stderr,
376 >        sprintf( painCave.errMsg,
377                   "Error in reading Atoms from force file at line %d.\n",
378                   lineNum );
379 <        exit(8);
380 <      }
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      }
304  }
305
306  // we are now at the AtomTypes section.
307
308  eof_test = fgets( readLine, sizeof(readLine), frcFile );
309  lineNum++;
310  
311  if( eof_test == NULL ){
312    fprintf( stderr,
313             "Error in reading Atoms from force file at line %d.\n",
314             lineNum );
315    exit(8);
316  }
317
318  while( readLine[0] != '#' && eof_test != NULL ){
399      
400 <    if( readLine[0] != '!' ){
400 >    // we are now at the AtomTypes section.
401 >    
402 >    eof_test = fgets( readLine, sizeof(readLine), frcFile );
403 >    lineNum++;
404 >    
405 >    if( eof_test == NULL ){
406 >      sprintf( painCave.errMsg,
407 >               "Error in reading Atoms from force file at line %d.\n",
408 >               lineNum );
409 >      painCave.isFatal = 1;
410 >      simError();
411 >    }
412 >    
413 >    while( readLine[0] != '#' && eof_test != NULL ){
414        
415 <      the_token = strtok( readLine, " \n\t,;" );
323 <      if( the_token != NULL ){
415 >      if( readLine[0] != '!' ){
416          
417 <        strcpy( currentAtomType->name, the_token );
418 <
419 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
420 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
421 <          exit(8);
330 <        }
331 <
332 <        sscanf( the_token, "%d", &currentAtomType->isDipole );
333 <
334 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
335 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
336 <          exit(8);
337 <        }
338 <
339 <        sscanf( the_token, "%lf", &currentAtomType->mass );
340 <
341 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
342 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
343 <          exit(8);
344 <        }
345 <        
346 <        sscanf( the_token, "%lf", &currentAtomType->epslon );
347 <        
348 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
349 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
350 <          exit(8);
351 <        }
352 <
353 <        sscanf( the_token, "%lf", &currentAtomType->sigma );
354 <        
355 <        if( currentAtomType->isDipole ){
417 >        the_token = strtok( readLine, " \n\t,;" );
418 >        if( the_token != NULL ){
419 >          
420 >          strcpy( currentAtomType->name, the_token );
421 >          
422            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
423 <            fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
424 <            exit(8);
423 >            sprintf( painCave.errMsg,
424 >                     "Error parseing AtomTypes: line %d\n", lineNum );
425 >            painCave.isFatal = 1;
426 >            simError();
427            }
428            
429 <          sscanf( the_token, "%lf", &currentAtomType->dipole );
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 >          }
469          }
470        }
471 +      
472 +      tempAtomType = new LinkedType;
473 +      currentAtomType->next = tempAtomType;
474 +      currentAtomType = tempAtomType;
475 +      
476 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
477 +      lineNum++;
478      }
479 +
480 + #ifdef IS_MPI
481      
482 <    tempAtomType = new LinkedType;
483 <    currentAtomType->next = tempAtomType;
484 <    currentAtomType = tempAtomType;
485 <    
486 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
487 <    lineNum++;
482 >    // send out the linked list to all the other processes
483 >
484 >    sprintf( checkPointMsg,
485 >             "TraPPE_Ex atom structures read successfully." );
486 >    MPIcheckPoint();
487 >
488 >    currentAtomType = headAtomType;
489 >    while( currentAtomType != NULL ){
490 >      currentAtomType->duplicate( info );
491 >      sendFrcStruct( &info, mpiAtomStructType );
492 >      currentAtomType = currentAtomType->next;
493 >    }
494 >    info.last = 1;
495 >    sendFrcStruct( &info, mpiAtomStructType );
496 >    
497    }
498  
499 +  else{
500 +    
501 +    // listen for node 0 to send out the force params
502 +    
503 +    MPIcheckPoint();
504 +
505 +    headAtomType = new LinkedType;
506 +    recieveFrcStruct( &info, mpiAtomStructType );
507 +    while( !info.last ){
508 +
509 +      headAtomType->add( info );
510 +      recieveFrcStruct( &info, mpiAtomStructType );
511 +    }
512 +  }
513 + #endif // is_mpi
514 +
515    
516    // initialize the atoms
517    
# Line 380 | Line 521 | void TraPPE_ExFF::initializeAtoms( void ){
521      
522      currentAtomType = headAtomType->find( the_atoms[i]->getType() );
523      if( currentAtomType == NULL ){
524 <      fprintf( stderr, "AtomType error, %s not found in force file.\n",
524 >      sprintf( painCave.errMsg,
525 >               "AtomType error, %s not found in force file.\n",
526                 the_atoms[i]->getType() );
527 <      exit(8);
527 >      painCave.isFatal = 1;
528 >      simError();
529      }
530      
531      the_atoms[i]->setMass( currentAtomType->mass );
# Line 409 | Line 552 | void TraPPE_ExFF::initializeAtoms( void ){
552            dAtom->setSSD( 0 );
553          }
554          else{
555 <          fprintf(stderr,
555 >          sprintf(painCave.errMsg,
556                    "AtmType error, %s does not have a moment of inertia set.\n",
557                    the_atoms[i]->getType() );
558 <          exit(8);
558 >          painCave.isFatal = 1;
559 >          simError();
560          }
561          entry_plug->n_dipoles++;
562        }
563        else{
564 <        std::cerr
565 <          << "TraPPE_ExFF error: Atom \""
566 <          << currentAtomType->name << "\" is a dipole, yet no standard"
567 <          << " orientation was specifed in the BASS file.\n";
568 <        exit(8);
564 >        
565 >        sprintf( painCave.errMsg,
566 >                "TraPPE_ExFF error: Atom \"%s\" is a dipole, yet no standard"
567 >                 " orientation was specifed in the BASS file.\n",
568 >                 currentAtomType->name );
569 >        painCave.isFatal = 1;
570 >        simError();
571        }
572      }
573      else{
574        if( the_atoms[i]->isDirectional() ){
575 <        std::cerr
576 <          << "TraPPE_ExFF error: Atom \""
577 <          << currentAtomType->name << "\" was given a standard orientation"
578 <          << " in the BASS file, yet it is not a dipole.\n";
579 <        exit(8);
575 >        sprintf( painCave.errMsg,
576 >                 "TraPPE_ExFF error: Atom \"%s\" was given a standard"
577 >                 "orientation in the BASS file, yet it is not a dipole.\n",
578 >                 currentAtomType->name);
579 >        painCave.isFatal = 1;
580 >        simError();
581        }
582      }
583    }
# Line 439 | Line 586 | void TraPPE_ExFF::initializeAtoms( void ){
586    // clean up the memory
587    
588    delete headAtomType;
589 +
590 + #ifdef IS_MPI
591 +  sprintf( checkPointMsg, "TraPPE_Ex atoms initialized succesfully" );
592 +  MPIcheckPoint();
593 + #endif // is_mpi
594 +
595   }
596  
597   void TraPPE_ExFF::initializeBonds( bond_pair* the_bonds ){
# Line 497 | Line 650 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
650    LinkedType* currentBondType;
651    LinkedType* tempBondType;
652  
653 + #ifdef IS_MPI
654 +  bondStruct info;
655 +  info.last = 1; // initialize last to have the last set.
656 +                 // if things go well, last will be set to 0
657 + #endif
658 +
659    char readLine[500];
660    char* the_token;
661    char* eof_test;
# Line 513 | Line 672 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
672    the_atoms = entry_plug->atoms;
673    nBonds = entry_plug->n_bonds;
674  
516  // read in the bond types.
517
518  rewind( frcFile );
519  headBondType = new LinkedType;
520  currentBondType = headBondType;
675    
676 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
677 <  lineNum++;
678 <  if( eof_test == NULL ){
679 <    fprintf( stderr, "Error in reading Bonds from force file.\n" );
680 <    exit(8);
681 <  }
682 <
683 <  
684 <  while( !foundBond ){
685 <    while( eof_test != NULL && readLine[0] != '#' ){
686 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
687 <      lineNum++;
534 <    }
676 > #ifdef IS_MPI
677 >  if( worldRank == 0 ){
678 > #endif
679 >    
680 >    // read in the bond types.
681 >    
682 >    rewind( frcFile );
683 >    headBondType = new LinkedType;
684 >    currentBondType = headBondType;
685 >    
686 >    eof_test = fgets( readLine, sizeof(readLine), frcFile );
687 >    lineNum++;
688      if( eof_test == NULL ){
689 <      fprintf( stderr,
690 <               "Error in reading Bonds from force file at line %d.\n",
691 <               lineNum );
539 <      exit(8);
689 >      sprintf( painCave.errMsg, "Error in reading Bonds from force file.\n" );
690 >      painCave.isFatal = 1;
691 >      simError();
692      }
541
542    the_token = strtok( readLine, " ,;\t#\n" );
543    foundBond = !strcmp( "BondTypes", the_token );
693      
694 <    if( !foundBond ){
695 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
696 <      lineNum++;
697 <
694 >    
695 >    while( !foundBond ){
696 >      while( eof_test != NULL && readLine[0] != '#' ){
697 >        eof_test = fgets( readLine, sizeof(readLine), frcFile );
698 >        lineNum++;
699 >      }
700        if( eof_test == NULL ){
701 <        fprintf( stderr,
701 >        sprintf( painCave.errMsg,
702                   "Error in reading Bonds from force file at line %d.\n",
703                   lineNum );
704 <        exit(8);
705 <      }
706 <    }
556 <  }
557 <
558 <  // we are now at the BondTypes section.
559 <
560 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
561 <  lineNum++;
562 <  
563 <  if( eof_test == NULL ){
564 <    fprintf( stderr,
565 <             "Error in reading Bonds from force file at line %d.\n",
566 <             lineNum );
567 <    exit(8);
568 <  }
569 <
570 <  while( readLine[0] != '#' && eof_test != NULL ){
571 <    
572 <    if( readLine[0] != '!' ){
704 >        painCave.isFatal = 1;
705 >        simError();
706 >      }
707        
708 <      the_token = strtok( readLine, " \n\t,;" );
709 <      if( the_token != NULL ){
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 <        strcpy( currentBondType->nameA, the_token );
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 >    
730 >    if( eof_test == NULL ){
731 >      sprintf( painCave.errMsg,
732 >               "Error in reading Bonds from force file at line %d.\n",
733 >               lineNum );
734 >      painCave.isFatal = 1;
735 >      simError();
736 >    }
737 >    
738 >    while( readLine[0] != '#' && eof_test != NULL ){
739 >      
740 >      if( readLine[0] != '!' ){
741          
742 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
743 <          fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum );
744 <          exit(8);
745 <        }
746 <
584 <        strcpy( currentBondType->nameB, the_token );
585 <
586 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
587 <          fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum );
588 <          exit(8);
589 <        }
590 <
591 <        strcpy( currentBondType->type, the_token );
592 <
593 <        if( !strcmp( currentBondType->type, "fixed" ) ){
742 >        the_token = strtok( readLine, " \n\t,;" );
743 >        if( the_token != NULL ){
744 >          
745 >          strcpy( currentBondType->nameA, the_token );
746 >          
747            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
748 <            fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum );
749 <            exit(8);
748 >            sprintf( painCave.errMsg,
749 >                     "Error parseing BondTypes: line %d\n", lineNum );
750 >            painCave.isFatal = 1;
751 >            simError();
752            }
753            
754 <          sscanf( the_token, "%lf", &currentBondType->d0 );
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 >          }              
784          }
601        
602        else{
603          fprintf(stderr,
604                  "Unknown TraPPE_Ex bond type \"%s\" at line %d\n",
605                  currentBondType->type,
606                  lineNum );
607          exit(8);
608        }                
785        }
786 +      
787 +      tempBondType = new LinkedType;
788 +      currentBondType->next = tempBondType;
789 +      currentBondType = tempBondType;
790 +      
791 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
792 +      lineNum++;
793      }
794      
795 <    tempBondType = new LinkedType;
613 <    currentBondType->next = tempBondType;
614 <    currentBondType = tempBondType;
795 > #ifdef IS_MPI
796      
797 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
798 <    lineNum++;
797 >    // send out the linked list to all the other processes
798 >    
799 >    sprintf( checkPointMsg,
800 >             "TraPPE_Ex bond structures read successfully." );
801 >    MPIcheckPoint();
802 >    
803 >    currentBondType = headBondType;
804 >    while( currentBondType != NULL ){
805 >      currentBondType->duplicate( info );
806 >      sendFrcStruct( &info, mpiBondStructType );
807 >      currentBondType = currentBondType->next;
808 >    }
809 >    info.last = 1;
810 >    sendFrcStruct( &info, mpiBondStructType );
811 >    
812    }
813  
814 +  else{
815 +    
816 +    // listen for node 0 to send out the force params
817 +    
818 +    MPIcheckPoint();
819 +
820 +    headBondType = new LinkedType;
821 +    recieveFrcStruct( &info, mpiBondStructType );
822 +    while( !info.last ){
823 +
824 +      headBondType->add( info );
825 +      recieveFrcStruct( &info, mpiBondStructType );
826 +    }
827 +  }
828 + #endif // is_mpi
829    
830 +  
831    // initialize the Bonds
832    
833  
# Line 630 | Line 840 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
840      atomB = the_atoms[b]->getType();
841      currentBondType = headBondType->find( atomA, atomB );
842      if( currentBondType == NULL ){
843 <      fprintf( stderr, "BondType error, %s - %s not found in force file.\n",
843 >      sprintf( painCave.errMsg,
844 >               "BondType error, %s - %s not found in force file.\n",
845                 atomA, atomB );
846 <      exit(8);
846 >      painCave.isFatal = 1;
847 >      simError();
848      }
849      
850      if( !strcmp( currentBondType->type, "fixed" ) ){
# Line 649 | Line 861 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
861    
862    delete headBondType;
863  
864 + #ifdef IS_MPI
865 +  sprintf( checkPointMsg, "TraPPE_Ex bonds initialized succesfully" );
866 +  MPIcheckPoint();
867 + #endif // is_mpi
868 +
869   }
870  
871   void TraPPE_ExFF::initializeBends( bend_set* the_bends ){
# Line 702 | Line 919 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
919        info.last = 0;
920      }
921  
922 < #endif
922 > #endif // is_mpi
923  
924      char nameA[15];
925      char nameB[15];
# Line 717 | Line 934 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
934    LinkedType* currentBendType;
935    LinkedType* tempBendType;
936  
937 + #ifdef IS_MPI
938 +  bendStruct info;
939 +  info.last = 1; // initialize last to have the last set.
940 +                 // if things go well, last will be set to 0
941 + #endif
942 +
943    char readLine[500];
944    char* the_token;
945    char* eof_test;
# Line 735 | Line 958 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
958    the_atoms = entry_plug->atoms;
959    nBends = entry_plug->n_bends;
960  
738  // read in the bend types.
961  
962 <  rewind( frcFile );
963 <  headBendType = new LinkedType;
964 <  currentBendType = headBendType;
743 <  
744 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
745 <  lineNum++;
746 <  if( eof_test == NULL ){
747 <    fprintf( stderr, "Error in reading Bends from force file.\n" );
748 <    exit(8);
749 <  }
962 > #ifdef IS_MPI
963 >  if( worldRank == 0 ){
964 > #endif
965  
966 +    // read in the bend types.
967 +
968 +    rewind( frcFile );
969 +    headBendType = new LinkedType;
970 +    currentBendType = headBendType;
971    
972 <  while( !foundBend ){
973 <    while( eof_test != NULL && readLine[0] != '#' ){
754 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
755 <      lineNum++;
756 <    }
972 >    eof_test = fgets( readLine, sizeof(readLine), frcFile );
973 >    lineNum++;
974      if( eof_test == NULL ){
975 <      fprintf( stderr,
976 <               "Error in reading Bends from force file at line %d.\n",
977 <               lineNum );
761 <      exit(8);
975 >      sprintf( painCave.errMsg, "Error in reading Bends from force file.\n" );
976 >      painCave.isFatal = 1;
977 >      simError();
978      }
979  
980 <    the_token = strtok( readLine, " ,;\t#\n" );
981 <    foundBend = !strcmp( "BendTypes", the_token );
982 <    
983 <    if( !foundBend ){
984 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
985 <      lineNum++;
770 <
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 <        fprintf( stderr,
987 >        sprintf( painCave.errMsg,
988                   "Error in reading Bends from force file at line %d.\n",
989                   lineNum );
990 <        exit(8);
991 <      }
990 >        painCave.isFatal = 1;
991 >        simError();
992 >      }
993 >
994 >      the_token = strtok( readLine, " ,;\t#\n" );
995 >      foundBend = !strcmp( "BendTypes", the_token );
996 >    
997 >      if( !foundBend ){
998 >        eof_test = fgets( readLine, sizeof(readLine), frcFile );
999 >        lineNum++;
1000 >
1001 >        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      }
778  }
1010  
1011 <  // we are now at the BendTypes section.
1011 >    // we are now at the BendTypes section.
1012  
1013 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
1014 <  lineNum++;
1013 >    eof_test = fgets( readLine, sizeof(readLine), frcFile );
1014 >    lineNum++;
1015    
1016 <  if( eof_test == NULL ){
1017 <    fprintf( stderr,
1018 <             "Error in reading Bends from force file at line %d.\n",
1019 <             lineNum );
1020 <    exit(8);
1021 <  }
1016 >    if( eof_test == NULL ){
1017 >      sprintf( painCave.errMsg,
1018 >               "Error in reading Bends from force file at line %d.\n",
1019 >               lineNum );
1020 >      painCave.isFatal = 1;
1021 >      simError();
1022 >    }
1023  
1024 <  while( readLine[0] != '#' && eof_test != NULL ){
1024 >    while( readLine[0] != '#' && eof_test != NULL ){
1025      
1026 <    if( readLine[0] != '!' ){
1026 >      if( readLine[0] != '!' ){
1027        
1028 <      the_token = strtok( readLine, " \n\t,;" );
1029 <      if( the_token != NULL ){
1028 >        the_token = strtok( readLine, " \n\t,;" );
1029 >        if( the_token != NULL ){
1030          
1031 <        strcpy( currentBendType->nameA, the_token );
1031 >          strcpy( currentBendType->nameA, the_token );
1032          
801        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
802          fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
803          exit(8);
804        }
805
806        strcpy( currentBendType->nameB, the_token );
807
808        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
809          fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
810          exit(8);
811        }
812
813        strcpy( currentBendType->nameC, the_token );
814
815        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
816          fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
817          exit(8);
818        }
819
820        strcpy( currentBendType->type, the_token );
821
822        if( !strcmp( currentBendType->type, "quadratic" ) ){
1033            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1034 <            fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
1035 <            exit(8);
1034 >            sprintf( painCave.errMsg,
1035 >                     "Error parseing BendTypes: line %d\n", lineNum );
1036 >            painCave.isFatal = 1;
1037 >            simError();
1038            }
827          
828          sscanf( the_token, "%lf", &currentBendType->k1 );
1039  
1040 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
831 <            fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
832 <            exit(8);
833 <          }
834 <          
835 <          sscanf( the_token, "%lf", &currentBendType->k2 );
1040 >          strcpy( currentBendType->nameB, the_token );
1041  
1042            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1043 <            fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
1044 <            exit(8);
1043 >            sprintf( painCave.errMsg,
1044 >                     "Error parseing BendTypes: line %d\n", lineNum );
1045 >            painCave.isFatal = 1;
1046 >            simError();
1047            }
841          
842          sscanf( the_token, "%lf", &currentBendType->k3 );
1048  
1049 +          strcpy( currentBendType->nameC, the_token );
1050 +
1051            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1052 <            fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
1053 <            exit(8);
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->t0 );
1069 <        }
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 <          fprintf(stderr,
1100 <                  "Unknown TraPPE_Ex bend type \"%s\" at line %d\n",
1101 <                  currentBendType->type,
1102 <                  lineNum );
1103 <          exit(8);
1104 <        }                
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 >          }              
1106 >        }
1107        }
1108 +    
1109 +      tempBendType = new LinkedType;
1110 +      currentBendType->next = tempBendType;
1111 +      currentBendType = tempBendType;
1112 +    
1113 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1114 +      lineNum++;
1115      }
1116 +
1117 + #ifdef IS_MPI
1118      
1119 <    tempBendType = new LinkedType;
1120 <    currentBendType->next = tempBendType;
1121 <    currentBendType = tempBendType;
1119 >    // send out the linked list to all the other processes
1120 >
1121 >    sprintf( checkPointMsg,
1122 >             "TraPPE_Ex bend structures read successfully." );
1123 >    MPIcheckPoint();
1124 >
1125 >    currentBendType = headBendType;
1126 >    while( currentBendType != NULL ){
1127 >      currentBendType->duplicate( info );
1128 >      sendFrcStruct( &info, mpiBendStructType );
1129 >      currentBendType = currentBendType->next;
1130 >    }
1131 >    info.last = 1;
1132 >    sendFrcStruct( &info, mpiBendStructType );
1133      
866    eof_test = fgets( readLine, sizeof(readLine), frcFile );
867    lineNum++;
1134    }
1135  
1136 +  else{
1137 +    
1138 +    // listen for node 0 to send out the force params
1139 +    
1140 +    MPIcheckPoint();
1141 +
1142 +    headBendType = new LinkedType;
1143 +    recieveFrcStruct( &info, mpiBendStructType );
1144 +    while( !info.last ){
1145 +
1146 +      headBendType->add( info );
1147 +      recieveFrcStruct( &info, mpiBendStructType );
1148 +    }
1149 +  }
1150 + #endif // is_mpi
1151    
1152    // initialize the Bends
1153  
# Line 881 | Line 1162 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1162      atomC = the_atoms[c]->getType();
1163      currentBendType = headBendType->find( atomA, atomB, atomC );
1164      if( currentBendType == NULL ){
1165 <      fprintf( stderr, "BendType error, %s - %s - %s not found"
1165 >      sprintf( painCave.errMsg, "BendType error, %s - %s - %s not found"
1166                 " in force file.\n",
1167                 atomA, atomB, atomC );
1168 <      exit(8);
1168 >      painCave.isFatal = 1;
1169 >      simError();
1170      }
1171      
1172      if( !strcmp( currentBendType->type, "quadratic" ) ){
# Line 906 | Line 1188 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1188    
1189    delete headBendType;
1190  
1191 + #ifdef IS_MPI
1192 +  sprintf( checkPointMsg, "TraPPE_Ex bends initialized succesfully" );
1193 +  MPIcheckPoint();
1194 + #endif // is_mpi
1195 +
1196   }
1197  
1198   void TraPPE_ExFF::initializeTorsions( torsion_set* the_torsions ){
# Line 978 | Line 1265 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1265    LinkedType* currentTorsionType;
1266    LinkedType* tempTorsionType;
1267  
1268 + #ifdef IS_MPI
1269 +  torsionStruct info;
1270 +  info.last = 1; // initialize last to have the last set.
1271 +                 // 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;
# Line 997 | Line 1290 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1290    the_atoms = entry_plug->atoms;
1291    nTorsions = entry_plug->n_torsions;
1292  
1293 <  // read in the torsion types.
1293 > #ifdef IS_MPI
1294 >  if( worldRank == 0 ){
1295 > #endif
1296  
1297 <  rewind( frcFile );
1298 <  headTorsionType = new LinkedType;
1299 <  currentTorsionType = headTorsionType;
1297 >    // read in the torsion types.
1298 >
1299 >    rewind( frcFile );
1300 >    headTorsionType = new LinkedType;
1301 >    currentTorsionType = headTorsionType;
1302    
1303 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
1304 <  lineNum++;
1305 <  if( eof_test == NULL ){
1306 <    fprintf( stderr, "Error in reading Torsions from force file.\n" );
1307 <    exit(8);
1308 <  }
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 >    }
1311  
1312    
1313 <  while( !foundTorsion ){
1314 <    while( eof_test != NULL && readLine[0] != '#' ){
1315 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1316 <      lineNum++;
1317 <    }
1019 <    if( eof_test == NULL ){
1020 <      fprintf( stderr,
1021 <               "Error in reading Torsions from force file at line %d.\n",
1022 <               lineNum );
1023 <      exit(8);
1024 <    }
1025 <
1026 <    the_token = strtok( readLine, " ,;\t#\n" );
1027 <    foundTorsion = !strcmp( "TorsionTypes", the_token );
1028 <    
1029 <    if( !foundTorsion ){
1030 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1031 <      lineNum++;
1032 <
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 <        fprintf( stderr,
1319 >        sprintf( painCave.errMsg,
1320                   "Error in reading Torsions from force file at line %d.\n",
1321                   lineNum );
1322 <        exit(8);
1323 <      }
1322 >        painCave.isFatal = 1;
1323 >        simError();
1324 >      }
1325 >
1326 >      the_token = strtok( readLine, " ,;\t#\n" );
1327 >      foundTorsion = !strcmp( "TorsionTypes", the_token );
1328 >    
1329 >      if( !foundTorsion ){
1330 >        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1331 >        lineNum++;
1332 >
1333 >        if( eof_test == NULL ){
1334 >          sprintf( painCave.errMsg,
1335 >                   "Error in reading Torsions from force file at line %d.\n",
1336 >                   lineNum );
1337 >          painCave.isFatal = 1;
1338 >          simError();
1339 >        }
1340 >      }
1341      }
1040  }
1342  
1343 <  // we are now at the TorsionTypes section.
1343 >    // we are now at the TorsionTypes section.
1344  
1345 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
1346 <  lineNum++;
1345 >    eof_test = fgets( readLine, sizeof(readLine), frcFile );
1346 >    lineNum++;
1347    
1348 <  if( eof_test == NULL ){
1349 <    fprintf( stderr,
1350 <             "Error in reading Torsions from force file at line %d.\n",
1351 <             lineNum );
1352 <    exit(8);
1353 <  }
1348 >    if( eof_test == NULL ){
1349 >      sprintf( painCave.errMsg,
1350 >               "Error in reading Torsions from force file at line %d.\n",
1351 >               lineNum );
1352 >      painCave.isFatal = 1;
1353 >      simError();
1354 >    }
1355  
1356 <  while( readLine[0] != '#' && eof_test != NULL ){
1356 >    while( readLine[0] != '#' && eof_test != NULL ){
1357      
1358 <    if( readLine[0] != '!' ){
1358 >      if( readLine[0] != '!' ){
1359        
1360 <      the_token = strtok( readLine, " \n\t,;" );
1361 <      if( the_token != NULL ){
1360 >        the_token = strtok( readLine, " \n\t,;" );
1361 >        if( the_token != NULL ){
1362          
1363 <        strcpy( currentTorsionType->nameA, the_token );
1363 >          strcpy( currentTorsionType->nameA, the_token );
1364          
1365 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1366 <          fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum );
1367 <          exit(8);
1368 <        }
1365 >          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 );
1372 >          strcpy( currentTorsionType->nameB, the_token );
1373  
1374 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1375 <          fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum );
1376 <          exit(8);
1377 <        }
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 );
1381 >          strcpy( currentTorsionType->nameC, the_token );
1382  
1383 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1384 <          fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum );
1385 <          exit(8);
1386 <        }
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 );
1390 >          strcpy( currentTorsionType->nameD, the_token );
1391  
1084        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1085          fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum );
1086          exit(8);
1087        }
1088
1089        strcpy( currentTorsionType->type, the_token );
1090
1091        if( !strcmp( currentTorsionType->type, "cubic" ) ){
1392            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1393 <            fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum );
1394 <            exit(8);
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 );
1409 >            sscanf( the_token, "%lf", &currentTorsionType->k1 );
1410  
1411 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1412 <            fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum );
1413 <            exit(8);
1414 <          }
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 );
1418 >            sscanf( the_token, "%lf", &currentTorsionType->k2 );
1419  
1420 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1421 <            fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum );
1422 <            exit(8);
1423 <          }
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 );
1427 >            sscanf( the_token, "%lf", &currentTorsionType->k3 );
1428  
1429 <          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1430 <            fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum );
1431 <            exit(8);
1432 <          }
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 <        }
1436 >            sscanf( the_token, "%lf", &currentTorsionType->k4 );
1437 >          }
1438          
1439 <        else{
1440 <          fprintf(stderr,
1441 <                  "Unknown TraPPE_Ex torsion type \"%s\" at line %d\n",
1442 <                  currentTorsionType->type,
1443 <                  lineNum );
1444 <          exit(8);
1445 <        }                
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 >          }              
1447 >        }
1448        }
1449 +    
1450 +      tempTorsionType = new LinkedType;
1451 +      currentTorsionType->next = tempTorsionType;
1452 +      currentTorsionType = tempTorsionType;
1453 +    
1454 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1455 +      lineNum++;
1456      }
1457 +
1458 + #ifdef IS_MPI
1459      
1460 <    tempTorsionType = new LinkedType;
1132 <    currentTorsionType->next = tempTorsionType;
1133 <    currentTorsionType = tempTorsionType;
1460 >    // send out the linked list to all the other processes
1461      
1462 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
1463 <    lineNum++;
1462 >    sprintf( checkPointMsg,
1463 >             "TraPPE_Ex torsion structures read successfully." );
1464 >    MPIcheckPoint();
1465 >    
1466 >    currentTorsionType = headTorsionType;
1467 >    while( currentTorsionType != NULL ){
1468 >      currentTorsionType->duplicate( info );
1469 >      sendFrcStruct( &info, mpiTorsionStructType );
1470 >      currentTorsionType = currentTorsionType->next;
1471 >    }
1472 >    info.last = 1;
1473 >    sendFrcStruct( &info, mpiTorsionStructType );
1474 >    
1475    }
1476  
1477 +  else{
1478 +    
1479 +    // listen for node 0 to send out the force params
1480 +    
1481 +    MPIcheckPoint();
1482 +
1483 +    headTorsionType = new LinkedType;
1484 +    recieveFrcStruct( &info, mpiTorsionStructType );
1485 +    while( !info.last ){
1486 +
1487 +      headTorsionType->add( info );
1488 +      recieveFrcStruct( &info, mpiTorsionStructType );
1489 +    }
1490 +  }
1491 + #endif // is_mpi
1492    
1493    // initialize the Torsions
1494  
# Line 1152 | Line 1505 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1505      atomD = the_atoms[d]->getType();
1506      currentTorsionType = headTorsionType->find( atomA, atomB, atomC, atomD );
1507      if( currentTorsionType == NULL ){
1508 <      fprintf( stderr, "TorsionType error, %s - %s - %s - %s not found"
1508 >      sprintf( painCave.errMsg,
1509 >               "TorsionType error, %s - %s - %s - %s not found"
1510                 " in force file.\n",
1511                 atomA, atomB, atomC, atomD );
1512 <      exit(8);
1512 >      painCave.isFatal = 1;
1513 >      simError();
1514      }
1515      
1516      if( !strcmp( currentTorsionType->type, "cubic" ) ){
# Line 1174 | Line 1529 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1529    
1530    delete headTorsionType;
1531  
1532 + #ifdef IS_MPI
1533 +  sprintf( checkPointMsg, "TraPPE_Ex torsions initialized succesfully" );
1534 +  MPIcheckPoint();
1535 + #endif // is_mpi
1536 +
1537   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines