ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE_old/src/mdtools/libmdCode/TraPPE_ExFF.cpp
Revision: 311
Committed: Tue Mar 11 16:27:34 2003 UTC (21 years, 3 months ago) by mmeineke
File size: 42291 byte(s)
Log Message:
finished adding the ghostBend into the TraPPE_Ex force Field

File Contents

# User Rev Content
1 mmeineke 270 #include <cstdlib>
2     #include <cstdio>
3     #include <cstring>
4    
5     #include <iostream>
6     using namespace std;
7    
8     #include "ForceFields.hpp"
9     #include "SRI.hpp"
10     #include "simError.h"
11    
12 mmeineke 294 #include <fortranWrappers.hpp>
13    
14 mmeineke 291 #ifdef IS_MPI
15     #include "mpiForceField.h"
16     #endif // is_mpi
17 mmeineke 270
18 mmeineke 291 namespace TPE { // restrict the access of the folowing to this file only.
19    
20    
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 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 mmeineke 270 #ifdef IS_MPI
79    
80 mmeineke 291 MPI_Datatype mpiAtomStructType;
81     MPI_Datatype mpiBondStructType;
82     MPI_Datatype mpiBendStructType;
83     MPI_Datatype mpiTorsionStructType;
84 mmeineke 270
85 mmeineke 291 #endif
86 mmeineke 270
87 mmeineke 291 } // namespace
88 mmeineke 270
89 mmeineke 291 using namespace TPE;
90    
91    
92     //****************************************************************
93     // begins the actual forcefield stuff.
94     //****************************************************************
95    
96    
97 mmeineke 270 TraPPE_ExFF::TraPPE_ExFF(){
98    
99     char fileName[200];
100     char* ffPath_env = "FORCE_PARAM_PATH";
101     char* ffPath;
102     char temp[200];
103     char errMsg[1000];
104    
105 mmeineke 291 // do the funtion wrapping
106 mmeineke 294 wrapMeFF( this );
107 mmeineke 291
108    
109 mmeineke 270 #ifdef IS_MPI
110     int i;
111    
112 mmeineke 291 // **********************************************************************
113 mmeineke 270 // Init the atomStruct mpi type
114    
115     atomStruct atomProto; // mpiPrototype
116 mmeineke 291 int atomBC[3] = {15,6,4}; // block counts
117 mmeineke 270 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 mmeineke 291 MPI_Address(&atomProto.isSSD, &atomDspls[2]);
123 mmeineke 270
124     atomMbrTypes[0] = MPI_CHAR;
125     atomMbrTypes[1] = MPI_DOUBLE;
126     atomMbrTypes[2] = MPI_INT;
127    
128     for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0];
129    
130     MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType);
131     MPI_Type_commit(&mpiAtomStructType);
132    
133    
134     // **********************************************************************
135     // Init the bondStruct mpi type
136    
137     bondStruct bondProto; // mpiPrototype
138     int bondBC[3] = {60,1,1}; // block counts
139     MPI_Aint bondDspls[3]; // displacements
140     MPI_Datatype bondMbrTypes[3]; // member mpi types
141    
142     MPI_Address(&bondProto.nameA, &bondDspls[0]);
143     MPI_Address(&bondProto.d0, &bondDspls[1]);
144     MPI_Address(&bondProto.last, &bondDspls[2]);
145    
146     bondMbrTypes[0] = MPI_CHAR;
147     bondMbrTypes[1] = MPI_DOUBLE;
148     bondMbrTypes[2] = MPI_INT;
149    
150     for (i=2; i >= 0; i--) bondDspls[i] -= bondDspls[0];
151    
152     MPI_Type_struct(3, bondBC, bondDspls, bondMbrTypes, &mpiBondStructType);
153     MPI_Type_commit(&mpiBondStructType);
154    
155    
156     // **********************************************************************
157     // Init the bendStruct mpi type
158    
159     bendStruct bendProto; // mpiPrototype
160     int bendBC[3] = {75,4,1}; // block counts
161     MPI_Aint bendDspls[3]; // displacements
162     MPI_Datatype bendMbrTypes[3]; // member mpi types
163    
164     MPI_Address(&bendProto.nameA, &bendDspls[0]);
165     MPI_Address(&bendProto.k1, &bendDspls[1]);
166     MPI_Address(&bendProto.last, &bendDspls[2]);
167    
168     bendMbrTypes[0] = MPI_CHAR;
169     bendMbrTypes[1] = MPI_DOUBLE;
170     bendMbrTypes[2] = MPI_INT;
171    
172     for (i=2; i >= 0; i--) bendDspls[i] -= bendDspls[0];
173    
174     MPI_Type_struct(3, bendBC, bendDspls, bendMbrTypes, &mpiBendStructType);
175     MPI_Type_commit(&mpiBendStructType);
176    
177    
178     // **********************************************************************
179     // Init the torsionStruct mpi type
180    
181     torsionStruct torsionProto; // mpiPrototype
182     int torsionBC[3] = {90,4,1}; // block counts
183     MPI_Aint torsionDspls[3]; // displacements
184     MPI_Datatype torsionMbrTypes[3]; // member mpi types
185    
186     MPI_Address(&torsionProto.nameA, &torsionDspls[0]);
187     MPI_Address(&torsionProto.k1, &torsionDspls[1]);
188     MPI_Address(&torsionProto.last, &torsionDspls[2]);
189    
190     torsionMbrTypes[0] = MPI_CHAR;
191     torsionMbrTypes[1] = MPI_DOUBLE;
192     torsionMbrTypes[2] = MPI_INT;
193    
194     for (i=2; i >= 0; i--) torsionDspls[i] -= torsionDspls[0];
195    
196     MPI_Type_struct(3, torsionBC, torsionDspls, torsionMbrTypes,
197     &mpiTorsionStructType);
198     MPI_Type_commit(&mpiTorsionStructType);
199    
200     // ***********************************************************************
201    
202     if( worldRank == 0 ){
203     #endif
204    
205     // generate the force file name
206    
207     strcpy( fileName, "TraPPE_Ex.frc" );
208     // fprintf( stderr,"Trying to open %s\n", fileName );
209    
210     // attempt to open the file in the current directory first.
211    
212     frcFile = fopen( fileName, "r" );
213    
214     if( frcFile == NULL ){
215    
216     // next see if the force path enviorment variable is set
217    
218     ffPath = getenv( ffPath_env );
219     if( ffPath == NULL ) {
220     sprintf( painCave.errMsg,
221     "Error opening the force field parameter file: %s\n"
222     "Have you tried setting the FORCE_PARAM_PATH environment "
223     "vairable?\n",
224     fileName );
225     painCave.isFatal = 1;
226     simError();
227     }
228    
229    
230     strcpy( temp, ffPath );
231     strcat( temp, "/" );
232     strcat( temp, fileName );
233     strcpy( fileName, temp );
234    
235     frcFile = fopen( fileName, "r" );
236    
237     if( frcFile == NULL ){
238    
239     sprintf( painCave.errMsg,
240     "Error opening the force field parameter file: %s\n"
241     "Have you tried setting the FORCE_PARAM_PATH environment "
242     "vairable?\n",
243     fileName );
244     painCave.isFatal = 1;
245     simError();
246     }
247     }
248    
249     #ifdef IS_MPI
250     }
251    
252     sprintf( checkPointMsg, "TraPPE_ExFF file opened sucessfully." );
253     MPIcheckPoint();
254    
255     #endif // is_mpi
256     }
257    
258    
259     TraPPE_ExFF::~TraPPE_ExFF(){
260    
261     #ifdef IS_MPI
262     if( worldRank == 0 ){
263     #endif // is_mpi
264    
265     fclose( frcFile );
266    
267     #ifdef IS_MPI
268     }
269     #endif // is_mpi
270     }
271    
272 mmeineke 296 void TraPPE_ExFF::doForces( int calcPot ){
273 mmeineke 291
274 mmeineke 296 int i, isError;
275     double* frc;
276     double* pos;
277     double* tau;
278     short int passedCalcPot = (short int)calcPot;
279    
280     // forces are zeroed here, before any are acumulated.
281     // NOTE: do not rezero the forces in Fortran.
282    
283     for(i=0; i<entry_plug->n_atoms; i++){
284     entry_plug->atoms[i]->zeroForces();
285     }
286    
287     frc = Atom::getFrcArray();
288     pos = Atom::getPosArray();
289     tau = entry_plug->tau;
290    
291     isError = 0;
292     fortranForceLoop( pos, frc, &(entry_plug->lrPot), tau,
293     &passedCalcPot, &isError );
294    
295    
296     if( isError ){
297     sprintf( painCave.errMsg,
298     "Error returned from the fortran force calculation.\n" );
299     painCave.isFatal = 1;
300     simError();
301     }
302    
303     #ifdef IS_MPI
304     sprintf( checkPointMsg,
305     "successfully returned from the force calculation.\n" );
306     MPIcheckPoint();
307     #endif // is_mpi
308    
309     }
310    
311     void TraPPE_ExFF::initFortran( void ){
312    
313     int nLocal = entry_plug->n_atoms;
314     int *ident;
315     int isError;
316     int i;
317    
318     ident = new int[nLocal];
319    
320     for(i=0; i<nLocal; i++){
321     ident[i] = entry_plug->atoms[i]->getIdent();
322     }
323    
324     isError = 0;
325     initfortran( &nLocal, ident, &isError );
326    
327     if(isError){
328     sprintf( painCave.errMsg,
329     "TraPPE_ExFF error: There was an error initializing the component list in fortran.\n" );
330     painCave.isFatal = 1;
331     simError();
332     }
333    
334    
335     #ifdef IS_MPI
336     sprintf( checkPointMsg, "TraPPE_ExFF successfully initialized the fortran component list.\n" );
337     MPIcheckPoint();
338     #endif // is_mpi
339    
340     delete[] ident;
341    
342     }
343    
344    
345    
346    
347 mmeineke 270 void TraPPE_ExFF::initializeAtoms( void ){
348    
349     class LinkedType {
350     public:
351     LinkedType(){
352     next = NULL;
353     name[0] = '\0';
354     }
355     ~LinkedType(){ if( next != NULL ) delete next; }
356    
357     LinkedType* find(char* key){
358     if( !strcmp(name, key) ) return this;
359     if( next != NULL ) return next->find(key);
360     return NULL;
361     }
362    
363     void add( atomStruct &info ){
364 mmeineke 291
365     // check for duplicates
366    
367     if( !strcmp( info.name, name ) ){
368     sprintf( painCave.errMsg,
369     "Duplicate TraPPE_Ex atom type \"%s\" found in "
370     "the TraPPE_ExFF param file./n",
371     name );
372     painCave.isFatal = 1;
373     simError();
374     }
375    
376 mmeineke 270 if( next != NULL ) next->add(info);
377     else{
378     next = new LinkedType();
379     strcpy(next->name, info.name);
380 mmeineke 291 next->isDipole = info.isDipole;
381     next->isSSD = info.isSSD;
382 mmeineke 270 next->mass = info.mass;
383     next->epslon = info.epslon;
384     next->sigma = info.sigma;
385     next->dipole = info.dipole;
386 mmeineke 291 next->w0 = info.w0;
387     next->v0 = info.v0;
388     next->ident = info.ident;
389 mmeineke 270 }
390     }
391 mmeineke 291
392     #ifdef IS_MPI
393 mmeineke 270
394     void duplicate( atomStruct &info ){
395     strcpy(info.name, name);
396 mmeineke 291 info.isDipole = isDipole;
397     info.isSSD = isSSD;
398 mmeineke 270 info.mass = mass;
399     info.epslon = epslon;
400     info.sigma = sigma;
401     info.dipole = dipole;
402 mmeineke 291 info.w0 = w0;
403     info.v0 = v0;
404 mmeineke 270 info.last = 0;
405     }
406    
407    
408     #endif
409    
410     char name[15];
411     int isDipole;
412 mmeineke 291 int isSSD;
413 mmeineke 270 double mass;
414     double epslon;
415     double sigma;
416     double dipole;
417 mmeineke 291 double w0;
418     double v0;
419     int ident;
420 mmeineke 270 LinkedType* next;
421     };
422    
423     LinkedType* headAtomType;
424     LinkedType* currentAtomType;
425     atomStruct info;
426     info.last = 1; // initialize last to have the last set.
427     // if things go well, last will be set to 0
428 mmeineke 291
429 mmeineke 270
430    
431     int i;
432 mmeineke 291 int identNum;
433 mmeineke 270
434 mmeineke 291 Atom** the_atoms;
435     int nAtoms;
436     the_atoms = entry_plug->atoms;
437     nAtoms = entry_plug->n_atoms;
438    
439    
440 mmeineke 270 //////////////////////////////////////////////////
441     // a quick water fix
442    
443     double waterI[3][3];
444     waterI[0][0] = 1.76958347772500;
445     waterI[0][1] = 0.0;
446     waterI[0][2] = 0.0;
447    
448     waterI[1][0] = 0.0;
449     waterI[1][1] = 0.614537057924513;
450     waterI[1][2] = 0.0;
451    
452     waterI[2][0] = 0.0;
453     waterI[2][1] = 0.0;
454     waterI[2][2] = 1.15504641980049;
455    
456    
457     double headI[3][3];
458     headI[0][0] = 1125;
459     headI[0][1] = 0.0;
460     headI[0][2] = 0.0;
461    
462     headI[1][0] = 0.0;
463     headI[1][1] = 1125;
464     headI[1][2] = 0.0;
465    
466     headI[2][0] = 0.0;
467     headI[2][1] = 0.0;
468     headI[2][2] = 250;
469    
470    
471    
472     //////////////////////////////////////////////////
473    
474 mmeineke 291
475 mmeineke 270 #ifdef IS_MPI
476     if( worldRank == 0 ){
477     #endif
478    
479     // read in the atom types.
480 mmeineke 291
481 mmeineke 270 headAtomType = new LinkedType;
482    
483 mmeineke 291 fastForward( "AtomTypes", "initializeAtoms" );
484    
485 mmeineke 270 // we are now at the AtomTypes section.
486    
487     eof_test = fgets( readLine, sizeof(readLine), frcFile );
488     lineNum++;
489    
490 mmeineke 291
491     // read a line, and start parseing out the atom types
492    
493 mmeineke 270 if( eof_test == NULL ){
494     sprintf( painCave.errMsg,
495     "Error in reading Atoms from force file at line %d.\n",
496     lineNum );
497     painCave.isFatal = 1;
498     simError();
499     }
500    
501 mmeineke 291 identNum = 1;
502     // stop reading at end of file, or at next section
503 mmeineke 270 while( readLine[0] != '#' && eof_test != NULL ){
504 mmeineke 291
505     // toss comment lines
506 mmeineke 270 if( readLine[0] != '!' ){
507    
508 mmeineke 291 // the parser returns 0 if the line was blank
509     if( parseAtom( readLine, lineNum, info ) ){
510     info.ident = identNum;
511     headAtomType->add( info );;
512     identNum++;
513 mmeineke 270 }
514     }
515     eof_test = fgets( readLine, sizeof(readLine), frcFile );
516     lineNum++;
517     }
518    
519     #ifdef IS_MPI
520    
521     // send out the linked list to all the other processes
522    
523     sprintf( checkPointMsg,
524 mmeineke 291 "TraPPE_ExFF atom structures read successfully." );
525 mmeineke 270 MPIcheckPoint();
526    
527 mmeineke 291 currentAtomType = headAtomType->next; //skip the first element who is a place holder.
528 mmeineke 270 while( currentAtomType != NULL ){
529     currentAtomType->duplicate( info );
530 mmeineke 291
531    
532    
533 mmeineke 270 sendFrcStruct( &info, mpiAtomStructType );
534 mmeineke 291
535     sprintf( checkPointMsg,
536     "successfully sent TraPPE_Ex force type: \"%s\"\n",
537     info.name );
538     MPIcheckPoint();
539    
540 mmeineke 270 currentAtomType = currentAtomType->next;
541     }
542     info.last = 1;
543     sendFrcStruct( &info, mpiAtomStructType );
544    
545     }
546    
547     else{
548    
549     // listen for node 0 to send out the force params
550    
551     MPIcheckPoint();
552    
553     headAtomType = new LinkedType;
554     recieveFrcStruct( &info, mpiAtomStructType );
555 mmeineke 291
556 mmeineke 270 while( !info.last ){
557    
558 mmeineke 291
559    
560 mmeineke 270 headAtomType->add( info );
561 mmeineke 291
562     MPIcheckPoint();
563    
564 mmeineke 270 recieveFrcStruct( &info, mpiAtomStructType );
565     }
566     }
567     #endif // is_mpi
568    
569 mmeineke 291 // call new A_types in fortran
570 mmeineke 270
571 mmeineke 291 int isError;
572 mmeineke 296
573     // dummy variables
574    
575     int isGB = 0;
576     int isLJ = 1;
577    
578    
579 mmeineke 291 currentAtomType = headAtomType;
580     while( currentAtomType != NULL ){
581    
582     if( currentAtomType->name[0] != '\0' ){
583     isError = 0;
584     newTPEtype( &(currentAtomType->ident),
585     &(currentAtomType->mass),
586     &(currentAtomType->epslon),
587     &(currentAtomType->sigma),
588 mmeineke 296 &isLJ,
589     &(currentAtomType->isSSD),
590 mmeineke 291 &(currentAtomType->isDipole),
591 mmeineke 296 &isGB,
592 mmeineke 291 &(currentAtomType->w0),
593     &(currentAtomType->v0),
594 mmeineke 296 &(currentAtomType->dipole),
595 mmeineke 291 &isError );
596     if( isError ){
597     sprintf( painCave.errMsg,
598     "Error initializing the \"%s\" atom type in fortran\n",
599     currentAtomType->name );
600     painCave.isFatal = 1;
601     simError();
602     }
603     }
604     currentAtomType = currentAtomType->next;
605     }
606    
607     #ifdef IS_MPI
608     sprintf( checkPointMsg,
609     "TraPPE_ExFF atom structures successfully sent to fortran\n" );
610     MPIcheckPoint();
611     #endif // is_mpi
612    
613    
614 mmeineke 270 // initialize the atoms
615    
616 mmeineke 291 double bigSigma = 0.0;
617 mmeineke 270 DirectionalAtom* dAtom;
618    
619     for( i=0; i<nAtoms; i++ ){
620    
621     currentAtomType = headAtomType->find( the_atoms[i]->getType() );
622     if( currentAtomType == NULL ){
623     sprintf( painCave.errMsg,
624     "AtomType error, %s not found in force file.\n",
625     the_atoms[i]->getType() );
626     painCave.isFatal = 1;
627     simError();
628     }
629    
630     the_atoms[i]->setMass( currentAtomType->mass );
631     the_atoms[i]->setEpslon( currentAtomType->epslon );
632     the_atoms[i]->setSigma( currentAtomType->sigma );
633     the_atoms[i]->setLJ();
634    
635 mmeineke 291 if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma;
636    
637 mmeineke 270 if( currentAtomType->isDipole ){
638     if( the_atoms[i]->isDirectional() ){
639    
640     dAtom = (DirectionalAtom *) the_atoms[i];
641     dAtom->setMu( currentAtomType->dipole );
642     dAtom->setHasDipole( 1 );
643     dAtom->setJx( 0.0 );
644     dAtom->setJy( 0.0 );
645     dAtom->setJz( 0.0 );
646    
647     if(!strcmp("SSD",the_atoms[i]->getType())){
648     dAtom->setI( waterI );
649     dAtom->setSSD( 1 );
650     }
651     else if(!strcmp("HEAD",the_atoms[i]->getType())){
652     dAtom->setI( headI );
653     dAtom->setSSD( 0 );
654     }
655     else{
656     sprintf(painCave.errMsg,
657     "AtmType error, %s does not have a moment of inertia set.\n",
658     the_atoms[i]->getType() );
659     painCave.isFatal = 1;
660     simError();
661     }
662     entry_plug->n_dipoles++;
663     }
664     else{
665    
666     sprintf( painCave.errMsg,
667     "TraPPE_ExFF error: Atom \"%s\" is a dipole, yet no standard"
668     " orientation was specifed in the BASS file.\n",
669     currentAtomType->name );
670     painCave.isFatal = 1;
671     simError();
672     }
673     }
674     else{
675     if( the_atoms[i]->isDirectional() ){
676     sprintf( painCave.errMsg,
677     "TraPPE_ExFF error: Atom \"%s\" was given a standard"
678     "orientation in the BASS file, yet it is not a dipole.\n",
679     currentAtomType->name);
680     painCave.isFatal = 1;
681     simError();
682     }
683     }
684     }
685    
686 mmeineke 291 #ifdef IS_MPI
687     double tempBig = bigSigma;
688     MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX );
689     #endif //is_mpi
690 mmeineke 270
691 mmeineke 291 //calc rCut and rList
692    
693     entry_plug->rCut = 2.5 * bigSigma;
694    
695     if(entry_plug->rCut > (entry_plug->box_x / 2.0))
696     entry_plug->rCut = entry_plug->box_x / 2.0;
697    
698     if(entry_plug->rCut > (entry_plug->box_y / 2.0))
699     entry_plug->rCut = entry_plug->box_y / 2.0;
700    
701     if(entry_plug->rCut > (entry_plug->box_z / 2.0))
702     entry_plug->rCut = entry_plug->box_z / 2.0;
703    
704     entry_plug->rList = entry_plug->rCut + 1.0;
705    
706    
707 mmeineke 270 // clean up the memory
708    
709     delete headAtomType;
710    
711     #ifdef IS_MPI
712     sprintf( checkPointMsg, "TraPPE_Ex atoms initialized succesfully" );
713     MPIcheckPoint();
714     #endif // is_mpi
715    
716 mmeineke 296 initFortran();
717     entry_plug->refreshSim();
718    
719 mmeineke 270 }
720    
721     void TraPPE_ExFF::initializeBonds( bond_pair* the_bonds ){
722    
723     class LinkedType {
724     public:
725     LinkedType(){
726     next = NULL;
727     nameA[0] = '\0';
728     nameB[0] = '\0';
729     type[0] = '\0';
730     }
731     ~LinkedType(){ if( next != NULL ) delete next; }
732    
733     LinkedType* find(char* key1, char* key2){
734     if( !strcmp(nameA, key1 ) && !strcmp( nameB, key2 ) ) return this;
735     if( !strcmp(nameA, key2 ) && !strcmp( nameB, key1 ) ) return this;
736     if( next != NULL ) return next->find(key1, key2);
737     return NULL;
738     }
739    
740 mmeineke 291
741 mmeineke 270 void add( bondStruct &info ){
742 mmeineke 291
743     // check for duplicates
744     int dup = 0;
745    
746     if( !strcmp(nameA, info.nameA ) && !strcmp( nameB, info.nameB ) ) dup = 1;
747     if( !strcmp(nameA, info.nameB ) && !strcmp( nameB, info.nameA ) ) dup = 1;
748    
749     if(dup){
750     sprintf( painCave.errMsg,
751     "Duplicate TraPPE_Ex bond type \"%s - %s\" found in "
752     "the TraPPE_ExFF param file./n",
753     nameA, nameB );
754     painCave.isFatal = 1;
755     simError();
756     }
757    
758    
759 mmeineke 270 if( next != NULL ) next->add(info);
760     else{
761     next = new LinkedType();
762     strcpy(next->nameA, info.nameA);
763     strcpy(next->nameB, info.nameB);
764     strcpy(next->type, info.type);
765     next->d0 = info.d0;
766     }
767     }
768    
769 mmeineke 291 #ifdef IS_MPI
770 mmeineke 270 void duplicate( bondStruct &info ){
771     strcpy(info.nameA, nameA);
772     strcpy(info.nameB, nameB);
773     strcpy(info.type, type);
774     info.d0 = d0;
775     info.last = 0;
776     }
777    
778    
779     #endif
780    
781     char nameA[15];
782     char nameB[15];
783     char type[30];
784     double d0;
785    
786     LinkedType* next;
787     };
788    
789    
790    
791     LinkedType* headBondType;
792     LinkedType* currentBondType;
793     bondStruct info;
794     info.last = 1; // initialize last to have the last set.
795     // if things go well, last will be set to 0
796    
797     SRI **the_sris;
798     Atom** the_atoms;
799     int nBonds;
800     the_sris = entry_plug->sr_interactions;
801     the_atoms = entry_plug->atoms;
802     nBonds = entry_plug->n_bonds;
803    
804 mmeineke 291 int i, a, b;
805     char* atomA;
806     char* atomB;
807 mmeineke 270
808     #ifdef IS_MPI
809     if( worldRank == 0 ){
810     #endif
811    
812     // read in the bond types.
813    
814     headBondType = new LinkedType;
815    
816 mmeineke 291 fastForward( "BondTypes", "initializeBonds" );
817    
818     // we are now at the bondTypes section
819    
820     eof_test = fgets( readLine, sizeof(readLine), frcFile );
821 mmeineke 270 lineNum++;
822    
823    
824 mmeineke 291 // read a line, and start parseing out the atom types
825    
826 mmeineke 270 if( eof_test == NULL ){
827     sprintf( painCave.errMsg,
828 mmeineke 291 "Error in reading bonds from force file at line %d.\n",
829 mmeineke 270 lineNum );
830     painCave.isFatal = 1;
831     simError();
832     }
833    
834 mmeineke 291 // stop reading at end of file, or at next section
835 mmeineke 270 while( readLine[0] != '#' && eof_test != NULL ){
836 mmeineke 291
837     // toss comment lines
838 mmeineke 270 if( readLine[0] != '!' ){
839    
840 mmeineke 291 // the parser returns 0 if the line was blank
841     if( parseBond( readLine, lineNum, info ) ){
842     headBondType->add( info );
843 mmeineke 270 }
844     }
845     eof_test = fgets( readLine, sizeof(readLine), frcFile );
846     lineNum++;
847     }
848 mmeineke 291
849 mmeineke 270 #ifdef IS_MPI
850    
851     // send out the linked list to all the other processes
852    
853     sprintf( checkPointMsg,
854     "TraPPE_Ex bond structures read successfully." );
855     MPIcheckPoint();
856    
857     currentBondType = headBondType;
858     while( currentBondType != NULL ){
859     currentBondType->duplicate( info );
860     sendFrcStruct( &info, mpiBondStructType );
861     currentBondType = currentBondType->next;
862     }
863     info.last = 1;
864     sendFrcStruct( &info, mpiBondStructType );
865    
866     }
867    
868     else{
869    
870     // listen for node 0 to send out the force params
871    
872     MPIcheckPoint();
873    
874     headBondType = new LinkedType;
875     recieveFrcStruct( &info, mpiBondStructType );
876     while( !info.last ){
877    
878     headBondType->add( info );
879     recieveFrcStruct( &info, mpiBondStructType );
880     }
881     }
882     #endif // is_mpi
883    
884    
885     // initialize the Bonds
886    
887    
888     for( i=0; i<nBonds; i++ ){
889    
890     a = the_bonds[i].a;
891     b = the_bonds[i].b;
892    
893     atomA = the_atoms[a]->getType();
894     atomB = the_atoms[b]->getType();
895     currentBondType = headBondType->find( atomA, atomB );
896     if( currentBondType == NULL ){
897     sprintf( painCave.errMsg,
898     "BondType error, %s - %s not found in force file.\n",
899     atomA, atomB );
900     painCave.isFatal = 1;
901     simError();
902     }
903    
904     if( !strcmp( currentBondType->type, "fixed" ) ){
905    
906     the_sris[i] = new ConstrainedBond( *the_atoms[a],
907     *the_atoms[b],
908     currentBondType->d0 );
909     entry_plug->n_constraints++;
910     }
911     }
912    
913    
914     // clean up the memory
915    
916     delete headBondType;
917    
918     #ifdef IS_MPI
919     sprintf( checkPointMsg, "TraPPE_Ex bonds initialized succesfully" );
920     MPIcheckPoint();
921     #endif // is_mpi
922    
923     }
924    
925     void TraPPE_ExFF::initializeBends( bend_set* the_bends ){
926    
927     class LinkedType {
928     public:
929     LinkedType(){
930     next = NULL;
931     nameA[0] = '\0';
932     nameB[0] = '\0';
933     nameC[0] = '\0';
934     type[0] = '\0';
935     }
936     ~LinkedType(){ if( next != NULL ) delete next; }
937    
938     LinkedType* find( char* key1, char* key2, char* key3 ){
939     if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 )
940     && !strcmp( nameC, key3 ) ) return this;
941     if( !strcmp( nameA, key3 ) && !strcmp( nameB, key2 )
942     && !strcmp( nameC, key1 ) ) return this;
943     if( next != NULL ) return next->find(key1, key2, key3);
944     return NULL;
945     }
946    
947 mmeineke 291 void add( bendStruct &info ){
948 mmeineke 270
949 mmeineke 291 // check for duplicates
950     int dup = 0;
951    
952     if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB )
953     && !strcmp( nameC, info.nameC ) ) dup = 1;
954     if( !strcmp( nameA, info.nameC ) && !strcmp( nameB, info.nameB )
955     && !strcmp( nameC, info.nameA ) ) dup = 1;
956    
957     if(dup){
958     sprintf( painCave.errMsg,
959     "Duplicate TraPPE_Ex bend type \"%s - %s - %s\" found in "
960     "the TraPPE_ExFF param file./n",
961     nameA, nameB, nameC );
962     painCave.isFatal = 1;
963     simError();
964     }
965    
966 mmeineke 270 if( next != NULL ) next->add(info);
967     else{
968     next = new LinkedType();
969     strcpy(next->nameA, info.nameA);
970     strcpy(next->nameB, info.nameB);
971     strcpy(next->nameC, info.nameC);
972     strcpy(next->type, info.type);
973     next->k1 = info.k1;
974     next->k2 = info.k2;
975     next->k3 = info.k3;
976     next->t0 = info.t0;
977     }
978     }
979 mmeineke 291
980     #ifdef IS_MPI
981    
982 mmeineke 270 void duplicate( bendStruct &info ){
983     strcpy(info.nameA, nameA);
984     strcpy(info.nameB, nameB);
985     strcpy(info.nameC, nameC);
986     strcpy(info.type, type);
987     info.k1 = k1;
988     info.k2 = k2;
989     info.k3 = k3;
990     info.t0 = t0;
991     info.last = 0;
992     }
993    
994     #endif // is_mpi
995    
996     char nameA[15];
997     char nameB[15];
998     char nameC[15];
999     char type[30];
1000     double k1, k2, k3, t0;
1001    
1002     LinkedType* next;
1003     };
1004    
1005     LinkedType* headBendType;
1006     LinkedType* currentBendType;
1007     bendStruct info;
1008     info.last = 1; // initialize last to have the last set.
1009     // if things go well, last will be set to 0
1010    
1011     QuadraticBend* qBend;
1012 mmeineke 311 GhostBend* gBend;
1013 mmeineke 270 SRI **the_sris;
1014     Atom** the_atoms;
1015     int nBends;
1016     the_sris = entry_plug->sr_interactions;
1017     the_atoms = entry_plug->atoms;
1018     nBends = entry_plug->n_bends;
1019    
1020 mmeineke 291 int i, a, b, c;
1021     char* atomA;
1022     char* atomB;
1023     char* atomC;
1024 mmeineke 270
1025 mmeineke 291
1026 mmeineke 270 #ifdef IS_MPI
1027     if( worldRank == 0 ){
1028     #endif
1029    
1030     // read in the bend types.
1031    
1032     headBendType = new LinkedType;
1033    
1034 mmeineke 291 fastForward( "BendTypes", "initializeBends" );
1035 mmeineke 270
1036 mmeineke 291 // we are now at the bendTypes section
1037 mmeineke 270
1038 mmeineke 291 eof_test = fgets( readLine, sizeof(readLine), frcFile );
1039     lineNum++;
1040    
1041     // read a line, and start parseing out the bend types
1042 mmeineke 270
1043     if( eof_test == NULL ){
1044     sprintf( painCave.errMsg,
1045 mmeineke 291 "Error in reading bends from force file at line %d.\n",
1046 mmeineke 270 lineNum );
1047     painCave.isFatal = 1;
1048     simError();
1049     }
1050 mmeineke 291
1051     // stop reading at end of file, or at next section
1052 mmeineke 270 while( readLine[0] != '#' && eof_test != NULL ){
1053 mmeineke 291
1054     // toss comment lines
1055 mmeineke 270 if( readLine[0] != '!' ){
1056    
1057 mmeineke 291 // the parser returns 0 if the line was blank
1058     if( parseBend( readLine, lineNum, info ) ){
1059     headBendType->add( info );
1060 mmeineke 270 }
1061     }
1062     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1063     lineNum++;
1064     }
1065 mmeineke 291
1066 mmeineke 270 #ifdef IS_MPI
1067    
1068     // send out the linked list to all the other processes
1069    
1070     sprintf( checkPointMsg,
1071     "TraPPE_Ex bend structures read successfully." );
1072     MPIcheckPoint();
1073    
1074     currentBendType = headBendType;
1075     while( currentBendType != NULL ){
1076     currentBendType->duplicate( info );
1077     sendFrcStruct( &info, mpiBendStructType );
1078     currentBendType = currentBendType->next;
1079     }
1080     info.last = 1;
1081     sendFrcStruct( &info, mpiBendStructType );
1082    
1083     }
1084    
1085     else{
1086    
1087     // listen for node 0 to send out the force params
1088    
1089     MPIcheckPoint();
1090    
1091     headBendType = new LinkedType;
1092     recieveFrcStruct( &info, mpiBendStructType );
1093     while( !info.last ){
1094    
1095     headBendType->add( info );
1096     recieveFrcStruct( &info, mpiBendStructType );
1097     }
1098     }
1099     #endif // is_mpi
1100    
1101     // initialize the Bends
1102 mmeineke 291
1103     int index;
1104 mmeineke 270
1105     for( i=0; i<nBends; i++ ){
1106    
1107     a = the_bends[i].a;
1108     b = the_bends[i].b;
1109     c = the_bends[i].c;
1110    
1111     atomA = the_atoms[a]->getType();
1112     atomB = the_atoms[b]->getType();
1113 mmeineke 311
1114     if( the_bends[i].isGhost ) atomC = "GHOST";
1115     else atomC = the_atoms[c]->getType();
1116    
1117 mmeineke 270 currentBendType = headBendType->find( atomA, atomB, atomC );
1118     if( currentBendType == NULL ){
1119     sprintf( painCave.errMsg, "BendType error, %s - %s - %s not found"
1120     " in force file.\n",
1121     atomA, atomB, atomC );
1122     painCave.isFatal = 1;
1123     simError();
1124     }
1125    
1126     if( !strcmp( currentBendType->type, "quadratic" ) ){
1127    
1128     index = i + entry_plug->n_bonds;
1129 mmeineke 311
1130     if( the_bends[i].isGhost){
1131    
1132     if( the_bends[i].ghost == b ){
1133     // do nothing
1134     }
1135     else if( the_bends[i].ghost == a ){
1136     c = a;
1137     a = b;
1138     b = a;
1139     }
1140     else{
1141     sprintf( painCave.errMsg,
1142     "BendType error, %s - %s - %s,\n"
1143     " --> central atom is not "
1144     "correctly identified with the "
1145     "\"ghostVectorSource = \" tag.\n",
1146     atomA, atomB, atomC );
1147     painCave.isFatal = 1;
1148     simError();
1149     }
1150    
1151     gBend = new GhostBend( *the_atoms[a],
1152     *the_atoms[b] );
1153     gBend->setConstants( currentBendType->k1,
1154     currentBendType->k2,
1155     currentBendType->k3,
1156     currentBendType->t0 );
1157     the_sris[index] = gBend;
1158     }
1159     else{
1160     qBend = new QuadraticBend( *the_atoms[a],
1161     *the_atoms[b],
1162     *the_atoms[c] );
1163     qBend->setConstants( currentBendType->k1,
1164     currentBendType->k2,
1165     currentBendType->k3,
1166     currentBendType->t0 );
1167     the_sris[index] = qBend;
1168     }
1169 mmeineke 270 }
1170     }
1171    
1172    
1173     // clean up the memory
1174    
1175     delete headBendType;
1176    
1177     #ifdef IS_MPI
1178     sprintf( checkPointMsg, "TraPPE_Ex bends initialized succesfully" );
1179     MPIcheckPoint();
1180     #endif // is_mpi
1181    
1182     }
1183    
1184     void TraPPE_ExFF::initializeTorsions( torsion_set* the_torsions ){
1185    
1186     class LinkedType {
1187     public:
1188     LinkedType(){
1189     next = NULL;
1190     nameA[0] = '\0';
1191     nameB[0] = '\0';
1192     nameC[0] = '\0';
1193     type[0] = '\0';
1194     }
1195     ~LinkedType(){ if( next != NULL ) delete next; }
1196    
1197     LinkedType* find( char* key1, char* key2, char* key3, char* key4 ){
1198     if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) &&
1199     !strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this;
1200    
1201     if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) &&
1202 mmeineke 291 !strcmp( nameC, key2 ) && !strcmp( nameD, key1 ) ) return this;
1203 mmeineke 270
1204     if( next != NULL ) return next->find(key1, key2, key3, key4);
1205     return NULL;
1206     }
1207    
1208     void add( torsionStruct &info ){
1209 mmeineke 291
1210     // check for duplicates
1211     int dup = 0;
1212    
1213     if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) &&
1214     !strcmp( nameC, info.nameC ) && !strcmp( nameD, info.nameD ) ) dup = 1;
1215    
1216     if( !strcmp( nameA, info.nameD ) && !strcmp( nameB, info.nameC ) &&
1217     !strcmp( nameC, info.nameB ) && !strcmp( nameD, info.nameA ) ) dup = 1;
1218    
1219     if(dup){
1220     sprintf( painCave.errMsg,
1221     "Duplicate TraPPE_Ex torsion type \"%s - %s - %s - %s\" found in "
1222     "the TraPPE_ExFF param file./n", nameA, nameB, nameC, nameD );
1223     painCave.isFatal = 1;
1224     simError();
1225     }
1226    
1227 mmeineke 270 if( next != NULL ) next->add(info);
1228     else{
1229     next = new LinkedType();
1230     strcpy(next->nameA, info.nameA);
1231     strcpy(next->nameB, info.nameB);
1232     strcpy(next->nameC, info.nameC);
1233     strcpy(next->type, info.type);
1234     next->k1 = info.k1;
1235     next->k2 = info.k2;
1236     next->k3 = info.k3;
1237     next->k4 = info.k4;
1238     }
1239     }
1240 mmeineke 291
1241     #ifdef IS_MPI
1242 mmeineke 270
1243     void duplicate( torsionStruct &info ){
1244     strcpy(info.nameA, nameA);
1245     strcpy(info.nameB, nameB);
1246     strcpy(info.nameC, nameC);
1247     strcpy(info.nameD, nameD);
1248     strcpy(info.type, type);
1249     info.k1 = k1;
1250     info.k2 = k2;
1251     info.k3 = k3;
1252     info.k4 = k4;
1253     info.last = 0;
1254     }
1255    
1256     #endif
1257    
1258     char nameA[15];
1259     char nameB[15];
1260     char nameC[15];
1261     char nameD[15];
1262     char type[30];
1263     double k1, k2, k3, k4;
1264    
1265     LinkedType* next;
1266     };
1267    
1268     LinkedType* headTorsionType;
1269     LinkedType* currentTorsionType;
1270     torsionStruct info;
1271     info.last = 1; // initialize last to have the last set.
1272     // if things go well, last will be set to 0
1273    
1274     int i, a, b, c, d, index;
1275     char* atomA;
1276     char* atomB;
1277     char* atomC;
1278     char* atomD;
1279     CubicTorsion* cTors;
1280    
1281     SRI **the_sris;
1282     Atom** the_atoms;
1283     int nTorsions;
1284     the_sris = entry_plug->sr_interactions;
1285     the_atoms = entry_plug->atoms;
1286     nTorsions = entry_plug->n_torsions;
1287    
1288     #ifdef IS_MPI
1289     if( worldRank == 0 ){
1290     #endif
1291    
1292     // read in the torsion types.
1293    
1294     headTorsionType = new LinkedType;
1295 mmeineke 291
1296     fastForward( "TorsionTypes", "initializeTorsions" );
1297 mmeineke 270
1298 mmeineke 291 // we are now at the torsionTypes section
1299 mmeineke 270
1300 mmeineke 291 eof_test = fgets( readLine, sizeof(readLine), frcFile );
1301     lineNum++;
1302 mmeineke 270
1303 mmeineke 291
1304     // read a line, and start parseing out the atom types
1305 mmeineke 270
1306     if( eof_test == NULL ){
1307     sprintf( painCave.errMsg,
1308 mmeineke 291 "Error in reading torsions from force file at line %d.\n",
1309 mmeineke 270 lineNum );
1310     painCave.isFatal = 1;
1311     simError();
1312     }
1313 mmeineke 291
1314     // stop reading at end of file, or at next section
1315     while( readLine[0] != '#' && eof_test != NULL ){
1316 mmeineke 270
1317 mmeineke 291 // toss comment lines
1318 mmeineke 270 if( readLine[0] != '!' ){
1319    
1320 mmeineke 291 // the parser returns 0 if the line was blank
1321     if( parseTorsion( readLine, lineNum, info ) ){
1322     headTorsionType->add( info );
1323 mmeineke 270 }
1324     }
1325     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1326     lineNum++;
1327     }
1328    
1329     #ifdef IS_MPI
1330    
1331     // send out the linked list to all the other processes
1332    
1333     sprintf( checkPointMsg,
1334     "TraPPE_Ex torsion structures read successfully." );
1335     MPIcheckPoint();
1336    
1337     currentTorsionType = headTorsionType;
1338     while( currentTorsionType != NULL ){
1339     currentTorsionType->duplicate( info );
1340     sendFrcStruct( &info, mpiTorsionStructType );
1341     currentTorsionType = currentTorsionType->next;
1342     }
1343     info.last = 1;
1344     sendFrcStruct( &info, mpiTorsionStructType );
1345    
1346     }
1347    
1348     else{
1349    
1350     // listen for node 0 to send out the force params
1351    
1352     MPIcheckPoint();
1353    
1354     headTorsionType = new LinkedType;
1355     recieveFrcStruct( &info, mpiTorsionStructType );
1356     while( !info.last ){
1357    
1358     headTorsionType->add( info );
1359     recieveFrcStruct( &info, mpiTorsionStructType );
1360     }
1361     }
1362     #endif // is_mpi
1363    
1364     // initialize the Torsions
1365    
1366     for( i=0; i<nTorsions; i++ ){
1367    
1368     a = the_torsions[i].a;
1369     b = the_torsions[i].b;
1370     c = the_torsions[i].c;
1371     d = the_torsions[i].d;
1372    
1373     atomA = the_atoms[a]->getType();
1374     atomB = the_atoms[b]->getType();
1375     atomC = the_atoms[c]->getType();
1376     atomD = the_atoms[d]->getType();
1377     currentTorsionType = headTorsionType->find( atomA, atomB, atomC, atomD );
1378     if( currentTorsionType == NULL ){
1379     sprintf( painCave.errMsg,
1380     "TorsionType error, %s - %s - %s - %s not found"
1381     " in force file.\n",
1382     atomA, atomB, atomC, atomD );
1383     painCave.isFatal = 1;
1384     simError();
1385     }
1386    
1387     if( !strcmp( currentTorsionType->type, "cubic" ) ){
1388     index = i + entry_plug->n_bonds + entry_plug->n_bends;
1389    
1390     cTors = new CubicTorsion( *the_atoms[a], *the_atoms[b],
1391     *the_atoms[c], *the_atoms[d] );
1392     cTors->setConstants( currentTorsionType->k1, currentTorsionType->k2,
1393     currentTorsionType->k3, currentTorsionType->k4 );
1394     the_sris[index] = cTors;
1395     }
1396     }
1397    
1398    
1399     // clean up the memory
1400    
1401     delete headTorsionType;
1402    
1403     #ifdef IS_MPI
1404     sprintf( checkPointMsg, "TraPPE_Ex torsions initialized succesfully" );
1405     MPIcheckPoint();
1406     #endif // is_mpi
1407    
1408     }
1409 mmeineke 291
1410     void TraPPE_ExFF::fastForward( char* stopText, char* searchOwner ){
1411    
1412     int foundText = 0;
1413     char* the_token;
1414    
1415     rewind( frcFile );
1416     lineNum = 0;
1417    
1418     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1419     lineNum++;
1420     if( eof_test == NULL ){
1421     sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
1422     " file is empty.\n",
1423     searchOwner );
1424     painCave.isFatal = 1;
1425     simError();
1426     }
1427    
1428    
1429     while( !foundText ){
1430     while( eof_test != NULL && readLine[0] != '#' ){
1431     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1432     lineNum++;
1433     }
1434     if( eof_test == NULL ){
1435     sprintf( painCave.errMsg,
1436     "Error fast forwarding force file for %s at "
1437     "line %d: file ended unexpectedly.\n",
1438     searchOwner,
1439     lineNum );
1440     painCave.isFatal = 1;
1441     simError();
1442     }
1443    
1444     the_token = strtok( readLine, " ,;\t#\n" );
1445     foundText = !strcmp( stopText, the_token );
1446    
1447     if( !foundText ){
1448     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1449     lineNum++;
1450    
1451     if( eof_test == NULL ){
1452     sprintf( painCave.errMsg,
1453     "Error fast forwarding force file for %s at "
1454     "line %d: file ended unexpectedly.\n",
1455     searchOwner,
1456     lineNum );
1457     painCave.isFatal = 1;
1458     simError();
1459     }
1460     }
1461     }
1462     }
1463    
1464    
1465     int parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){
1466    
1467     char* the_token;
1468    
1469     the_token = strtok( lineBuffer, " \n\t,;" );
1470     if( the_token != NULL ){
1471    
1472     strcpy( info.name, the_token );
1473    
1474     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1475     sprintf( painCave.errMsg,
1476     "Error parseing AtomTypes: line %d\n", lineNum );
1477     painCave.isFatal = 1;
1478     simError();
1479     }
1480    
1481     info.isDipole = atoi( the_token );
1482    
1483     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1484     sprintf( painCave.errMsg,
1485     "Error parseing AtomTypes: line %d\n", lineNum );
1486     painCave.isFatal = 1;
1487     simError();
1488     }
1489    
1490     info.isSSD = atoi( the_token );
1491    
1492     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1493     sprintf( painCave.errMsg,
1494     "Error parseing AtomTypes: line %d\n", lineNum );
1495     painCave.isFatal = 1;
1496     simError();
1497     }
1498    
1499     info.mass = atof( the_token );
1500    
1501     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1502     sprintf( painCave.errMsg,
1503     "Error parseing AtomTypes: line %d\n", lineNum );
1504     painCave.isFatal = 1;
1505     simError();
1506     }
1507    
1508     info.epslon = atof( the_token );
1509    
1510     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1511     sprintf( painCave.errMsg,
1512     "Error parseing AtomTypes: line %d\n", lineNum );
1513     painCave.isFatal = 1;
1514     simError();
1515     }
1516    
1517     info.sigma = atof( the_token );
1518    
1519     if( info.isDipole ){
1520    
1521     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1522     sprintf( painCave.errMsg,
1523     "Error parseing AtomTypes: line %d\n", lineNum );
1524     painCave.isFatal = 1;
1525     simError();
1526     }
1527    
1528     info.dipole = atof( the_token );
1529     }
1530     else info.dipole = 0.0;
1531    
1532     if( info.isSSD ){
1533    
1534     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1535     sprintf( painCave.errMsg,
1536     "Error parseing AtomTypes: line %d\n", lineNum );
1537     painCave.isFatal = 1;
1538     simError();
1539     }
1540    
1541     info.w0 = atof( the_token );
1542    
1543     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1544     sprintf( painCave.errMsg,
1545     "Error parseing AtomTypes: line %d\n", lineNum );
1546     painCave.isFatal = 1;
1547     simError();
1548     }
1549    
1550     info.v0 = atof( the_token );
1551     }
1552     else info.v0 = info.w0 = 0.0;
1553    
1554     return 1;
1555     }
1556     else return 0;
1557     }
1558    
1559     int parseBond( char *lineBuffer, int lineNum, bondStruct &info ){
1560    
1561     char* the_token;
1562    
1563     the_token = strtok( lineBuffer, " \n\t,;" );
1564     if( the_token != NULL ){
1565    
1566     strcpy( info.nameA, the_token );
1567    
1568     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1569     sprintf( painCave.errMsg,
1570     "Error parseing BondTypes: line %d\n", lineNum );
1571     painCave.isFatal = 1;
1572     simError();
1573     }
1574    
1575     strcpy( info.nameB, the_token );
1576    
1577     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1578     sprintf( painCave.errMsg,
1579     "Error parseing BondTypes: line %d\n", lineNum );
1580     painCave.isFatal = 1;
1581     simError();
1582     }
1583    
1584     strcpy( info.type, the_token );
1585    
1586     if( !strcmp( info.type, "fixed" ) ){
1587     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1588     sprintf( painCave.errMsg,
1589     "Error parseing BondTypes: line %d\n", lineNum );
1590     painCave.isFatal = 1;
1591     simError();
1592     }
1593    
1594     info.d0 = atof( the_token );
1595     }
1596     else{
1597     sprintf( painCave.errMsg,
1598     "Unknown TraPPE_Ex bond type \"%s\" at line %d\n",
1599     info.type,
1600     lineNum );
1601     painCave.isFatal = 1;
1602     simError();
1603     }
1604    
1605     return 1;
1606     }
1607     else return 0;
1608     }
1609    
1610    
1611     int parseBend( char *lineBuffer, int lineNum, bendStruct &info ){
1612    
1613     char* the_token;
1614    
1615     the_token = strtok( lineBuffer, " \n\t,;" );
1616     if( the_token != NULL ){
1617    
1618     strcpy( info.nameA, the_token );
1619    
1620     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1621     sprintf( painCave.errMsg,
1622     "Error parseing BondTypes: line %d\n", lineNum );
1623     painCave.isFatal = 1;
1624     simError();
1625     }
1626    
1627     strcpy( info.nameB, the_token );
1628    
1629     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1630     sprintf( painCave.errMsg,
1631     "Error parseing BondTypes: line %d\n", lineNum );
1632     painCave.isFatal = 1;
1633     simError();
1634     }
1635    
1636     strcpy( info.nameC, the_token );
1637    
1638     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1639     sprintf( painCave.errMsg,
1640     "Error parseing BondTypes: line %d\n", lineNum );
1641     painCave.isFatal = 1;
1642     simError();
1643     }
1644    
1645     strcpy( info.type, the_token );
1646    
1647     if( !strcmp( info.type, "quadratic" ) ){
1648     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1649     sprintf( painCave.errMsg,
1650     "Error parseing BendTypes: line %d\n", lineNum );
1651     painCave.isFatal = 1;
1652     simError();
1653     }
1654    
1655     info.k1 = atof( the_token );
1656    
1657     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1658     sprintf( painCave.errMsg,
1659     "Error parseing BendTypes: line %d\n", lineNum );
1660     painCave.isFatal = 1;
1661     simError();
1662     }
1663    
1664     info.k2 = atof( the_token );
1665    
1666     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1667     sprintf( painCave.errMsg,
1668     "Error parseing BendTypes: line %d\n", lineNum );
1669     painCave.isFatal = 1;
1670     simError();
1671     }
1672    
1673     info.k3 = atof( the_token );
1674    
1675     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1676     sprintf( painCave.errMsg,
1677     "Error parseing BendTypes: line %d\n", lineNum );
1678     painCave.isFatal = 1;
1679     simError();
1680     }
1681    
1682     info.t0 = atof( the_token );
1683     }
1684    
1685     else{
1686     sprintf( painCave.errMsg,
1687     "Unknown TraPPE_Ex bend type \"%s\" at line %d\n",
1688     info.type,
1689     lineNum );
1690     painCave.isFatal = 1;
1691     simError();
1692     }
1693    
1694     return 1;
1695     }
1696     else return 0;
1697     }
1698    
1699     int parseTorsion( char *lineBuffer, int lineNum, torsionStruct &info ){
1700    
1701     char* the_token;
1702    
1703     the_token = strtok( lineBuffer, " \n\t,;" );
1704     if( the_token != NULL ){
1705    
1706     strcpy( info.nameA, the_token );
1707    
1708     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1709     sprintf( painCave.errMsg,
1710     "Error parseing TorsionTypes: line %d\n", lineNum );
1711     painCave.isFatal = 1;
1712     simError();
1713     }
1714    
1715     strcpy( info.nameB, the_token );
1716    
1717     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1718     sprintf( painCave.errMsg,
1719     "Error parseing TorsionTypes: line %d\n", lineNum );
1720     painCave.isFatal = 1;
1721     simError();
1722     }
1723    
1724     strcpy( info.nameC, the_token );
1725    
1726     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1727     sprintf( painCave.errMsg,
1728     "Error parseing TorsionTypes: line %d\n", lineNum );
1729     painCave.isFatal = 1;
1730     simError();
1731     }
1732    
1733     strcpy( info.nameD, the_token );
1734    
1735     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1736     sprintf( painCave.errMsg,
1737     "Error parseing TorsionTypes: line %d\n", lineNum );
1738     painCave.isFatal = 1;
1739     simError();
1740     }
1741    
1742     strcpy( info.type, the_token );
1743    
1744     if( !strcmp( info.type, "cubic" ) ){
1745     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1746     sprintf( painCave.errMsg,
1747     "Error parseing TorsionTypes: line %d\n", lineNum );
1748     painCave.isFatal = 1;
1749     simError();
1750     }
1751    
1752     info.k1 = atof( the_token );
1753    
1754     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1755     sprintf( painCave.errMsg,
1756     "Error parseing TorsionTypes: line %d\n", lineNum );
1757     painCave.isFatal = 1;
1758     simError();
1759     }
1760    
1761     info.k2 = atof( the_token );
1762    
1763     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1764     sprintf( painCave.errMsg,
1765     "Error parseing TorsionTypes: line %d\n", lineNum );
1766     painCave.isFatal = 1;
1767     simError();
1768     }
1769    
1770     info.k3 = atof( the_token );
1771    
1772     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1773     sprintf( painCave.errMsg,
1774     "Error parseing TorsionTypes: line %d\n", lineNum );
1775     painCave.isFatal = 1;
1776     simError();
1777     }
1778    
1779     info.k4 = atof( the_token );
1780    
1781     }
1782    
1783     else{
1784     sprintf( painCave.errMsg,
1785     "Unknown TraPPE_Ex torsion type \"%s\" at line %d\n",
1786     info.type,
1787     lineNum );
1788     painCave.isFatal = 1;
1789     simError();
1790     }
1791    
1792     return 1;
1793     }
1794    
1795     else return 0;
1796     }