ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE_old/src/mdtools/libmdCode/TraPPE_ExFF.cpp
Revision: 293
Committed: Thu Mar 6 16:07:57 2003 UTC (21 years, 4 months ago) by mmeineke
File size: 40914 byte(s)
Log Message:
cleaning up all of the function wrapping

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