ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp
Revision: 152
Committed: Mon Oct 21 22:03:00 2002 UTC (21 years, 8 months ago) by mmeineke
File size: 32105 byte(s)
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 mmeineke 10 #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    
11    
12 chuckv 141 #ifdef IS_MPI
13    
14 mmeineke 147 #include "mpiForceField.h"
15    
16 chuckv 141 int myNode;
17    
18     // Declare the structures that will be passed by MPI
19    
20     typedef struct{
21     char name[15];
22     double mass;
23     double epslon;
24     double sigma;
25     double dipole;
26     int isDipole;
27     int last; // 0 -> default
28     // 1 -> tells nodes to stop listening
29     // -1 -> an error has occured. (handled in mpiForceField)
30     } atomStruct;
31     MPI_Datatype mpiAtomStructType;
32    
33 mmeineke 146 typedef struct{
34     char nameA[15];
35     char nameB[15];
36     char type[30];
37     double d0;
38     int last; // 0 -> default
39     // 1 -> tells nodes to stop listening
40     // -1 -> an error has occured. (handled in mpiForceField)
41     } bondStruct;
42     MPI_Datatype mpiBondStructType;
43    
44     typedef struct{
45     char nameA[15];
46     char nameB[15];
47     char nameC[15];
48     char type[30];
49     double k1, k2, k3, t0;
50     int last; // 0 -> default
51     // 1 -> tells nodes to stop listening
52     // -1 -> an error has occured. (handled in mpiForceField)
53     } bendStruct;
54     MPI_Datatype mpiBendStructType;
55    
56     typedef struct{
57     char nameA[15];
58     char nameB[15];
59     char nameC[15];
60     char nameD[15];
61     char type[30];
62     double k1, k2, k3, k4;
63     int last; // 0 -> default
64     // 1 -> tells nodes to stop listening
65     // -1 -> an error has occured. (handled in mpiForceField)
66     } TorsionStruct;
67     MPI_Datatype mpiTorsionStructType;
68    
69 chuckv 141 #endif
70    
71    
72    
73 mmeineke 10 TraPPE_ExFF::TraPPE_ExFF(){
74    
75     char fileName[200];
76     char* ffPath_env = "FORCE_PARAM_PATH";
77     char* ffPath;
78     char temp[200];
79 mmeineke 152 char errMsg[1000];
80 mmeineke 10
81 chuckv 141 #ifdef IS_MPI
82     int i;
83     int mpiError;
84 mmeineke 152 int cleanOpen = 0;
85 mmeineke 147
86 chuckv 141 mpiError = MPI_Comm_rank(MPI_COMM_WORLD,&myNode);
87 mmeineke 147
88     // **********************************************************************
89     // Init the atomStruct mpi type
90 chuckv 141
91     atomStruct atomProto; // mpiPrototype
92     int atomBC[3] = {15,4,2}; // block counts
93     MPI_Aint atomDspls[3]; // displacements
94     MPI_Datatype atomMbrTypes[3]; // member mpi types
95    
96 chuckv 137
97    
98 chuckv 141 MPI_Address(&atomProto.name, &atomDspls[0]);
99     MPI_Address(&atomProto.mass, &atomDspls[1]);
100     MPI_Address(&atomProto.isDipole, &atomDspls[2]);
101 mmeineke 10
102 chuckv 141 atomMbrTypes[0] = MPI_CHAR;
103     atomMbrTypes[1] = MPI_DOUBLE;
104     atomMbrTypes[2] = MPI_INT;
105 mmeineke 10
106 chuckv 141 for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0];
107    
108     MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType);
109     MPI_Type_commit(&mpiAtomStructType);
110 mmeineke 10
111 chuckv 137
112 mmeineke 147 // **********************************************************************
113     // Init the bondStruct mpi type
114    
115     bondStruct bondProto; // mpiPrototype
116     int bondBC[3] = {60,1,1}; // block counts
117     MPI_Aint bondDspls[3]; // displacements
118     MPI_Datatype bondMbrTypes[3]; // member mpi types
119    
120     MPI_Address(&bondProto.nameA, &bondDspls[0]);
121     MPI_Address(&bondProto.d0, &bondDspls[1]);
122     MPI_Address(&bondProto.last, &bondDspls[2]);
123    
124     bondMbrTypes[0] = MPI_CHAR;
125     bondMbrTypes[1] = MPI_DOUBLE;
126     bondMbrTypes[2] = MPI_INT;
127    
128     for (i=2; i >= 0; i--) bondDspls[i] -= bondDspls[0];
129    
130     MPI_Type_struct(3, bondBC, bondDspls, bondMbrTypes, &mpiBondStructType);
131     MPI_Type_commit(&mpiBondStructType);
132 chuckv 137
133 mmeineke 10
134 mmeineke 147 // **********************************************************************
135     // Init the bendStruct mpi type
136    
137     bendStruct bendProto; // mpiPrototype
138     int bendBC[3] = {75,4,1}; // block counts
139     MPI_Aint bendDspls[3]; // displacements
140     MPI_Datatype bendMbrTypes[3]; // member mpi types
141    
142     MPI_Address(&bendProto.nameA, &bendDspls[0]);
143     MPI_Address(&bendProto.k1, &bendDspls[1]);
144     MPI_Address(&bendProto.last, &bendDspls[2]);
145    
146     bendMbrTypes[0] = MPI_CHAR;
147     bendMbrTypes[1] = MPI_DOUBLE;
148     bendMbrTypes[2] = MPI_INT;
149    
150     for (i=2; i >= 0; i--) bendDspls[i] -= bendDspls[0];
151    
152     MPI_Type_struct(3, bendBC, bendDspls, bendMbrTypes, &mpiBendStructType);
153     MPI_Type_commit(&mpiBendStructType);
154    
155    
156     // **********************************************************************
157     // Init the torsionStruct mpi type
158    
159     torsionStruct torsionProto; // mpiPrototype
160     int torsionBC[3] = {90,4,1}; // block counts
161     MPI_Aint torsionDspls[3]; // displacements
162     MPI_Datatype torsionMbrTypes[3]; // member mpi types
163    
164     MPI_Address(&torsionProto.nameA, &torsionDspls[0]);
165     MPI_Address(&torsionProto.k1, &torsionDspls[1]);
166     MPI_Address(&torsionProto.last, &torsionDspls[2]);
167    
168     torsionMbrTypes[0] = MPI_CHAR;
169     torsionMbrTypes[1] = MPI_DOUBLE;
170     torsionMbrTypes[2] = MPI_INT;
171    
172     for (i=2; i >= 0; i--) torsionDspls[i] -= torsionDspls[0];
173    
174     MPI_Type_struct(3, torsionBC, torsionDspls, torsionMbrTypes,
175     &mpiTorsionStructType);
176     MPI_Type_commit(&mpiTorsionStructType);
177    
178     // ***********************************************************************
179    
180 chuckv 141 if( myNode == 0 ){
181     #endif
182    
183     // generate the force file name
184    
185     strcpy( fileName, "TraPPE_Ex.frc" );
186 mmeineke 152 // fprintf( stderr,"Trying to open %s\n", fileName );
187 chuckv 141
188     // attempt to open the file in the current directory first.
189    
190 mmeineke 10 frcFile = fopen( fileName, "r" );
191    
192     if( frcFile == NULL ){
193    
194 chuckv 141 // next see if the force path enviorment variable is set
195    
196     ffPath = getenv( ffPath_env );
197     if( ffPath == NULL ) {
198 mmeineke 152 sprintf( errMsg,
199 chuckv 141 "Error opening the force field parameter file: %s\n"
200     "Have you tried setting the FORCE_PARAM_PATH environment "
201     "vairable?\n",
202     fileName );
203 mmeineke 152 #ifdef IS_MPI
204     cleanOpen = 0;
205     mpiError = MPI_Bcast(cleanOpen,1,MPI_INT,0,MPI_COMM_WORLD);
206     #endif
207     ffError( errMsg );
208 chuckv 141 }
209    
210    
211     strcpy( temp, ffPath );
212     strcat( temp, "/" );
213     strcat( temp, fileName );
214     strcpy( fileName, temp );
215    
216     frcFile = fopen( fileName, "r" );
217    
218     if( frcFile == NULL ){
219    
220 mmeineke 152 sprintf( errMsg,
221 chuckv 141 "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 mmeineke 152 #ifdef IS_MPI
226     cleanOpen = 0;
227     mpiError = MPI_Bcast(cleanOpen,1,MPI_INT,0,MPI_COMM_WORLD);
228     #endif
229     ffError( errMsg );
230 chuckv 141 }
231 mmeineke 10 }
232 mmeineke 152 cleanOpen = 1;
233 chuckv 141 #ifdef IS_MPI
234 mmeineke 10 }
235 mmeineke 152
236     mpiError = MPI_Bcast(cleanOpen,1,MPI_INT,0,MPI_COMM_WORLD);
237     if( !cleanOpen ) fferror( NULL );
238 chuckv 141 #endif
239 mmeineke 10 }
240    
241 chuckv 141
242 mmeineke 10 TraPPE_ExFF::~TraPPE_ExFF(){
243    
244     fclose( frcFile );
245     }
246    
247     void TraPPE_ExFF::initializeAtoms( void ){
248    
249     class LinkedType {
250     public:
251     LinkedType(){
252     next = NULL;
253     name[0] = '\0';
254     }
255     ~LinkedType(){ if( next != NULL ) delete next; }
256    
257     LinkedType* find(char* key){
258     if( !strcmp(name, key) ) return this;
259     if( next != NULL ) return next->find(key);
260     return NULL;
261     }
262    
263 chuckv 141 #ifdef IS_MPI
264     void add( atomStruct &info ){
265     if( next != NULL ) next->add(info);
266     else{
267     next = new LinkedType();
268     strcpy(next->name, info.name);
269     next->isDipole = info.dipole;
270     next->mass = info.mass;
271     next->epslon = info.epslon;
272     next->sigma = info.sigma;
273     next->dipole = info.dipole;
274     }
275     }
276    
277     void duplicate( atomStruct &info ){
278     strcpy(info.name, name);
279     info.isDipole = dipole;
280     info.mass = mass;
281     info.epslon = epslon;
282     info.sigma = sigma;
283     info.dipole = dipole;
284     info.last = 0;
285     }
286    
287    
288     #endif
289    
290 mmeineke 10 char name[15];
291     int isDipole;
292     double mass;
293     double epslon;
294     double sigma;
295     double dipole;
296     LinkedType* next;
297     };
298    
299     LinkedType* headAtomType;
300     LinkedType* currentAtomType;
301     LinkedType* tempAtomType;
302    
303 mmeineke 152 #ifdef IS_MPI
304     atomStruct info;
305     info.last = -1; // initialize last to have the error set.
306     // if things go well, last will be set to 0
307     #endif
308    
309    
310 mmeineke 10 char readLine[500];
311     char* the_token;
312     char* eof_test;
313     int foundAtom = 0;
314     int lineNum = 0;
315     int i;
316 mmeineke 152 char errMsg[1000];
317    
318 mmeineke 10
319     //////////////////////////////////////////////////
320     // a quick water fix
321    
322     double waterI[3][3];
323     waterI[0][0] = 1.76958347772500;
324     waterI[0][1] = 0.0;
325     waterI[0][2] = 0.0;
326    
327     waterI[1][0] = 0.0;
328     waterI[1][1] = 0.614537057924513;
329     waterI[1][2] = 0.0;
330    
331     waterI[2][0] = 0.0;
332     waterI[2][1] = 0.0;
333     waterI[2][2] = 1.15504641980049;
334    
335    
336     double headI[3][3];
337     headI[0][0] = 1125;
338     headI[0][1] = 0.0;
339     headI[0][2] = 0.0;
340    
341     headI[1][0] = 0.0;
342     headI[1][1] = 1125;
343     headI[1][2] = 0.0;
344    
345     headI[2][0] = 0.0;
346     headI[2][1] = 0.0;
347     headI[2][2] = 250;
348    
349    
350    
351     //////////////////////////////////////////////////
352    
353     Atom** the_atoms;
354     int nAtoms;
355     the_atoms = entry_plug->atoms;
356     nAtoms = entry_plug->n_atoms;
357    
358    
359 mmeineke 147 #ifdef IS_MPI
360     if( myNode == 0 ){
361     #endif
362    
363     // read in the atom types.
364    
365     rewind( frcFile );
366     headAtomType = new LinkedType;
367     currentAtomType = headAtomType;
368    
369     eof_test = fgets( readLine, sizeof(readLine), frcFile );
370     lineNum++;
371 mmeineke 10 if( eof_test == NULL ){
372 mmeineke 152 sprintf( errMsg, "Error in reading Atoms from force file.\n" );
373     #ifdef IS_MPI
374     sendFrcStruct( &info, mpiAtomStructType );
375     #endif
376     ffError(errMsg);
377 mmeineke 10 }
378    
379 mmeineke 147
380     while( !foundAtom ){
381     while( eof_test != NULL && readLine[0] != '#' ){
382     eof_test = fgets( readLine, sizeof(readLine), frcFile );
383     lineNum++;
384     }
385 mmeineke 10 if( eof_test == NULL ){
386 mmeineke 152 sprintf( errMsg,
387 mmeineke 10 "Error in reading Atoms from force file at line %d.\n",
388     lineNum );
389 mmeineke 152 #ifdef IS_MPI
390     sendFrcStruct( &info, mpiAtomStructType );
391     #endif
392     ffError(errMsg);
393 mmeineke 147 }
394    
395     the_token = strtok( readLine, " ,;\t#\n" );
396     foundAtom = !strcmp( "AtomTypes", the_token );
397    
398     if( !foundAtom ){
399     eof_test = fgets( readLine, sizeof(readLine), frcFile );
400     lineNum++;
401    
402     if( eof_test == NULL ){
403 mmeineke 152 sprintf( errMsg,
404 mmeineke 147 "Error in reading Atoms from force file at line %d.\n",
405     lineNum );
406 mmeineke 152 #ifdef IS_MPI
407     sendFrcStruct( &info, mpiAtomStructType );
408     #endif
409     ffError(errMsg);
410 mmeineke 147 }
411     }
412 mmeineke 10 }
413    
414 mmeineke 147 // we are now at the AtomTypes section.
415    
416     eof_test = fgets( readLine, sizeof(readLine), frcFile );
417     lineNum++;
418    
419     if( eof_test == NULL ){
420 mmeineke 152 sprintf( errMsg,
421 mmeineke 147 "Error in reading Atoms from force file at line %d.\n",
422     lineNum );
423 mmeineke 152 #ifdef IS_MPI
424     sendFrcStruct( &info, mpiAtomStructType );
425     #endif
426     ffError(errMsg);
427 mmeineke 147 }
428    
429     while( readLine[0] != '#' && eof_test != NULL ){
430 mmeineke 10
431 mmeineke 147 if( readLine[0] != '!' ){
432 mmeineke 10
433 mmeineke 147 the_token = strtok( readLine, " \n\t,;" );
434     if( the_token != NULL ){
435    
436     strcpy( currentAtomType->name, the_token );
437    
438 mmeineke 10 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
439 mmeineke 152 sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum );
440     #ifdef IS_MPI
441     sendFrcStruct( &info, mpiAtomStructType );
442     #endif
443     ffError(errMsg);
444 mmeineke 10 }
445    
446 mmeineke 147 sscanf( the_token, "%d", &currentAtomType->isDipole );
447    
448     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
449 mmeineke 152 sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum );
450     #ifdef IS_MPI
451     sendFrcStruct( &info, mpiAtomStructType );
452     #endif
453     ffError(errMsg);
454 mmeineke 147 }
455    
456     sscanf( the_token, "%lf", &currentAtomType->mass );
457    
458     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
459 mmeineke 152 sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum );
460     #ifdef IS_MPI
461     sendFrcStruct( &info, mpiAtomStructType );
462     #endif
463     ffError(errMsg);
464 mmeineke 147 }
465    
466     sscanf( the_token, "%lf", &currentAtomType->epslon );
467    
468     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
469 mmeineke 152 sprintf( errMsg, "Error parseing AtomTypes: line %d\n", lineNum );
470     #ifdef IS_MPI
471     sendFrcStruct( &info, mpiAtomStructType );
472     #endif
473     ffError(errMsg);
474 mmeineke 147 }
475    
476     sscanf( the_token, "%lf", &currentAtomType->sigma );
477    
478     if( currentAtomType->isDipole ){
479     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
480 mmeineke 152 sprintf( errMsg, "Error parseing AtomTypes: line %d\n",
481     lineNum );
482     #ifdef IS_MPI
483     sendFrcStruct( &info, mpiAtomStructType );
484     #endif
485     ffError(errMsg);
486 mmeineke 147 }
487    
488     sscanf( the_token, "%lf", &currentAtomType->dipole );
489     }
490 mmeineke 10 }
491     }
492 mmeineke 147
493     tempAtomType = new LinkedType;
494     currentAtomType->next = tempAtomType;
495     currentAtomType = tempAtomType;
496    
497     eof_test = fgets( readLine, sizeof(readLine), frcFile );
498     lineNum++;
499 mmeineke 10 }
500 mmeineke 147
501     #ifdef IS_MPI
502 mmeineke 152
503     // send out the linked list to all the other processes
504    
505     currentAtomType = headAtomType;
506     while( currentAtomType != NULL ){
507     currentAtomType->duplicate( info );
508     sendFrcStruct( &info, mpiAtomStructType );
509     currentAtomType = currentAtomType->next;
510     }
511     info.last = 1;
512     sendFrcStruct( &info, mpiAtomStructType );
513    
514 mmeineke 147 }
515    
516     else{
517 mmeineke 10
518 mmeineke 152 // listen for node 0 to send out the force params
519    
520     headAtomType = new LinkedType;
521     recieveFrcStruct( &info, mpiAtomStructType );
522     while( !info.last ){
523    
524     headAtomType->add( info );
525     recieveFrcStruct( &info, mpiAtomStructType );
526     }
527    
528     if( info.last < 0 ) ffError( NULL ); // an error has occured, exit quietly.
529    
530 mmeineke 10
531     }
532 mmeineke 147 #endif
533 mmeineke 10
534    
535     // initialize the atoms
536    
537     DirectionalAtom* dAtom;
538    
539     for( i=0; i<nAtoms; i++ ){
540    
541     currentAtomType = headAtomType->find( the_atoms[i]->getType() );
542     if( currentAtomType == NULL ){
543 mmeineke 152 sprintf( errMsg, "AtomType error, %s not found in force file.\n",
544 mmeineke 10 the_atoms[i]->getType() );
545 mmeineke 152 ffError(errMsg);
546 mmeineke 10 }
547    
548     the_atoms[i]->setMass( currentAtomType->mass );
549     the_atoms[i]->setEpslon( currentAtomType->epslon );
550     the_atoms[i]->setSigma( currentAtomType->sigma );
551     the_atoms[i]->setLJ();
552    
553     if( currentAtomType->isDipole ){
554     if( the_atoms[i]->isDirectional() ){
555    
556     dAtom = (DirectionalAtom *) the_atoms[i];
557     dAtom->setMu( currentAtomType->dipole );
558     dAtom->setHasDipole( 1 );
559     dAtom->setJx( 0.0 );
560     dAtom->setJy( 0.0 );
561     dAtom->setJz( 0.0 );
562    
563     if(!strcmp("SSD",the_atoms[i]->getType())){
564     dAtom->setI( waterI );
565     dAtom->setSSD( 1 );
566     }
567     else if(!strcmp("HEAD",the_atoms[i]->getType())){
568     dAtom->setI( headI );
569     dAtom->setSSD( 0 );
570     }
571     else{
572 mmeineke 152 sprintf(errMsg,
573 mmeineke 10 "AtmType error, %s does not have a moment of inertia set.\n",
574     the_atoms[i]->getType() );
575 mmeineke 152 ffError(errMsg);
576 mmeineke 10 }
577     entry_plug->n_dipoles++;
578     }
579     else{
580 mmeineke 152
581     sprintf( errMsg,
582     "TraPPE_ExFF error: Atom \"%s\" is a dipole, yet no standard"
583     " orientation was specifed in the BASS file.\n",
584     currentAtomType->name );
585    
586     ffError(errMsg);
587 mmeineke 10 }
588     }
589     else{
590     if( the_atoms[i]->isDirectional() ){
591 mmeineke 152 sprintf( errMsg,
592     "TraPPE_ExFF error: Atom \"%s\" was given a standard"
593     "orientation in the BASS file, yet it is not a dipole.\n",
594     currentAtomType->name);
595     ffError(errMsg);
596 mmeineke 10 }
597     }
598     }
599    
600    
601     // clean up the memory
602    
603     delete headAtomType;
604     }
605    
606     void TraPPE_ExFF::initializeBonds( bond_pair* the_bonds ){
607    
608     class LinkedType {
609     public:
610     LinkedType(){
611     next = NULL;
612     nameA[0] = '\0';
613     nameB[0] = '\0';
614     type[0] = '\0';
615     }
616     ~LinkedType(){ if( next != NULL ) delete next; }
617    
618     LinkedType* find(char* key1, char* key2){
619     if( !strcmp(nameA, key1 ) && !strcmp( nameB, key2 ) ) return this;
620     if( !strcmp(nameA, key2 ) && !strcmp( nameB, key1 ) ) return this;
621     if( next != NULL ) return next->find(key1, key2);
622     return NULL;
623     }
624    
625 mmeineke 146 #ifdef IS_MPI
626     void add( bondStruct &info ){
627     if( next != NULL ) next->add(info);
628     else{
629     next = new LinkedType();
630     strcpy(next->nameA, info.nameA);
631     strcpy(next->nameB, info.nameB);
632     strcpy(next->type, info.type);
633     next->d0 = info.d0;
634     }
635     }
636    
637     void duplicate( bondStruct &info ){
638     strcpy(info.nameA, nameA);
639     strcpy(info.nameB, nameB);
640     strcpy(info.type, type);
641     info.d0 = d0;
642     info.last = 0;
643     }
644    
645    
646     #endif
647    
648 mmeineke 10 char nameA[15];
649     char nameB[15];
650     char type[30];
651     double d0;
652    
653     LinkedType* next;
654     };
655    
656    
657    
658     LinkedType* headBondType;
659     LinkedType* currentBondType;
660     LinkedType* tempBondType;
661    
662     char readLine[500];
663     char* the_token;
664     char* eof_test;
665     int foundBond = 0;
666     int lineNum = 0;
667     int i, a, b;
668     char* atomA;
669     char* atomB;
670    
671     SRI **the_sris;
672     Atom** the_atoms;
673     int nBonds;
674     the_sris = entry_plug->sr_interactions;
675     the_atoms = entry_plug->atoms;
676     nBonds = entry_plug->n_bonds;
677    
678     // read in the bond types.
679    
680     rewind( frcFile );
681     headBondType = new LinkedType;
682     currentBondType = headBondType;
683    
684     eof_test = fgets( readLine, sizeof(readLine), frcFile );
685     lineNum++;
686     if( eof_test == NULL ){
687     fprintf( stderr, "Error in reading Bonds from force file.\n" );
688     exit(8);
689     }
690    
691    
692     while( !foundBond ){
693     while( eof_test != NULL && readLine[0] != '#' ){
694     eof_test = fgets( readLine, sizeof(readLine), frcFile );
695     lineNum++;
696     }
697     if( eof_test == NULL ){
698     fprintf( stderr,
699     "Error in reading Bonds from force file at line %d.\n",
700     lineNum );
701     exit(8);
702     }
703    
704     the_token = strtok( readLine, " ,;\t#\n" );
705     foundBond = !strcmp( "BondTypes", the_token );
706    
707     if( !foundBond ){
708     eof_test = fgets( readLine, sizeof(readLine), frcFile );
709     lineNum++;
710    
711     if( eof_test == NULL ){
712     fprintf( stderr,
713     "Error in reading Bonds from force file at line %d.\n",
714     lineNum );
715     exit(8);
716     }
717     }
718     }
719    
720     // we are now at the BondTypes section.
721    
722     eof_test = fgets( readLine, sizeof(readLine), frcFile );
723     lineNum++;
724    
725     if( eof_test == NULL ){
726     fprintf( stderr,
727     "Error in reading Bonds from force file at line %d.\n",
728     lineNum );
729     exit(8);
730     }
731    
732     while( readLine[0] != '#' && eof_test != NULL ){
733    
734     if( readLine[0] != '!' ){
735    
736     the_token = strtok( readLine, " \n\t,;" );
737     if( the_token != NULL ){
738    
739     strcpy( currentBondType->nameA, the_token );
740    
741     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
742     fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum );
743     exit(8);
744     }
745    
746     strcpy( currentBondType->nameB, the_token );
747    
748     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
749     fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum );
750     exit(8);
751     }
752    
753     strcpy( currentBondType->type, the_token );
754    
755     if( !strcmp( currentBondType->type, "fixed" ) ){
756     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
757     fprintf( stderr, "Error parseing BondTypes: line %d\n", lineNum );
758     exit(8);
759     }
760    
761     sscanf( the_token, "%lf", &currentBondType->d0 );
762     }
763    
764     else{
765     fprintf(stderr,
766     "Unknown TraPPE_Ex bond type \"%s\" at line %d\n",
767     currentBondType->type,
768     lineNum );
769     exit(8);
770     }
771     }
772     }
773    
774     tempBondType = new LinkedType;
775     currentBondType->next = tempBondType;
776     currentBondType = tempBondType;
777    
778     eof_test = fgets( readLine, sizeof(readLine), frcFile );
779     lineNum++;
780     }
781    
782    
783     // initialize the Bonds
784    
785    
786     for( i=0; i<nBonds; i++ ){
787    
788     a = the_bonds[i].a;
789     b = the_bonds[i].b;
790    
791     atomA = the_atoms[a]->getType();
792     atomB = the_atoms[b]->getType();
793     currentBondType = headBondType->find( atomA, atomB );
794     if( currentBondType == NULL ){
795     fprintf( stderr, "BondType error, %s - %s not found in force file.\n",
796     atomA, atomB );
797     exit(8);
798     }
799    
800     if( !strcmp( currentBondType->type, "fixed" ) ){
801    
802     the_sris[i] = new ConstrainedBond( *the_atoms[a],
803     *the_atoms[b],
804     currentBondType->d0 );
805     entry_plug->n_constraints++;
806     }
807     }
808    
809    
810     // clean up the memory
811    
812     delete headBondType;
813    
814     }
815    
816     void TraPPE_ExFF::initializeBends( bend_set* the_bends ){
817    
818     class LinkedType {
819     public:
820     LinkedType(){
821     next = NULL;
822     nameA[0] = '\0';
823     nameB[0] = '\0';
824     nameC[0] = '\0';
825     type[0] = '\0';
826     }
827     ~LinkedType(){ if( next != NULL ) delete next; }
828    
829     LinkedType* find( char* key1, char* key2, char* key3 ){
830     if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 )
831     && !strcmp( nameC, key3 ) ) return this;
832     if( !strcmp( nameA, key3 ) && !strcmp( nameB, key2 )
833     && !strcmp( nameC, key1 ) ) return this;
834     if( next != NULL ) return next->find(key1, key2, key3);
835     return NULL;
836     }
837    
838 mmeineke 146 #ifdef IS_MPI
839    
840     void add( bendStruct &info ){
841     if( next != NULL ) next->add(info);
842     else{
843     next = new LinkedType();
844     strcpy(next->nameA, info.nameA);
845     strcpy(next->nameB, info.nameB);
846     strcpy(next->nameC, info.nameC);
847     strcpy(next->type, info.type);
848     next->k1 = info.k1;
849     next->k2 = info.k2;
850     next->k3 = info.k3;
851     next->t0 = info.t0;
852     }
853     }
854    
855     void duplicate( bendStruct &info ){
856     strcpy(info.nameA, nameA);
857     strcpy(info.nameB, nameB);
858     strcpy(info.nameC, nameC);
859     strcpy(info.type, type);
860     info.k1 = k1;
861     info.k2 = k2;
862     info.k3 = k3;
863     info.t0 = t0;
864     info.last = 0;
865     }
866    
867     #endif
868    
869 mmeineke 10 char nameA[15];
870     char nameB[15];
871     char nameC[15];
872     char type[30];
873     double k1, k2, k3, t0;
874    
875     LinkedType* next;
876     };
877    
878     LinkedType* headBendType;
879     LinkedType* currentBendType;
880     LinkedType* tempBendType;
881    
882     char readLine[500];
883     char* the_token;
884     char* eof_test;
885     int foundBend = 0;
886     int lineNum = 0;
887     int i, a, b, c, index;
888     char* atomA;
889     char* atomB;
890     char* atomC;
891     QuadraticBend* qBend;
892    
893     SRI **the_sris;
894     Atom** the_atoms;
895     int nBends;
896     the_sris = entry_plug->sr_interactions;
897     the_atoms = entry_plug->atoms;
898     nBends = entry_plug->n_bends;
899    
900     // read in the bend types.
901    
902     rewind( frcFile );
903     headBendType = new LinkedType;
904     currentBendType = headBendType;
905    
906     eof_test = fgets( readLine, sizeof(readLine), frcFile );
907     lineNum++;
908     if( eof_test == NULL ){
909     fprintf( stderr, "Error in reading Bends from force file.\n" );
910     exit(8);
911     }
912    
913    
914     while( !foundBend ){
915     while( eof_test != NULL && readLine[0] != '#' ){
916     eof_test = fgets( readLine, sizeof(readLine), frcFile );
917     lineNum++;
918     }
919     if( eof_test == NULL ){
920     fprintf( stderr,
921     "Error in reading Bends from force file at line %d.\n",
922     lineNum );
923     exit(8);
924     }
925    
926     the_token = strtok( readLine, " ,;\t#\n" );
927     foundBend = !strcmp( "BendTypes", the_token );
928    
929     if( !foundBend ){
930     eof_test = fgets( readLine, sizeof(readLine), frcFile );
931     lineNum++;
932    
933     if( eof_test == NULL ){
934     fprintf( stderr,
935     "Error in reading Bends from force file at line %d.\n",
936     lineNum );
937     exit(8);
938     }
939     }
940     }
941    
942     // we are now at the BendTypes section.
943    
944     eof_test = fgets( readLine, sizeof(readLine), frcFile );
945     lineNum++;
946    
947     if( eof_test == NULL ){
948     fprintf( stderr,
949     "Error in reading Bends from force file at line %d.\n",
950     lineNum );
951     exit(8);
952     }
953    
954     while( readLine[0] != '#' && eof_test != NULL ){
955    
956     if( readLine[0] != '!' ){
957    
958     the_token = strtok( readLine, " \n\t,;" );
959     if( the_token != NULL ){
960    
961     strcpy( currentBendType->nameA, the_token );
962    
963     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
964     fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
965     exit(8);
966     }
967    
968     strcpy( currentBendType->nameB, the_token );
969    
970     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
971     fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
972     exit(8);
973     }
974    
975     strcpy( currentBendType->nameC, the_token );
976    
977     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
978     fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
979     exit(8);
980     }
981    
982     strcpy( currentBendType->type, the_token );
983    
984     if( !strcmp( currentBendType->type, "quadratic" ) ){
985     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
986     fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
987     exit(8);
988     }
989    
990     sscanf( the_token, "%lf", &currentBendType->k1 );
991    
992     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
993     fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
994     exit(8);
995     }
996    
997     sscanf( the_token, "%lf", &currentBendType->k2 );
998    
999     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1000     fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
1001     exit(8);
1002     }
1003    
1004     sscanf( the_token, "%lf", &currentBendType->k3 );
1005    
1006     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1007     fprintf( stderr, "Error parseing BendTypes: line %d\n", lineNum );
1008     exit(8);
1009     }
1010    
1011     sscanf( the_token, "%lf", &currentBendType->t0 );
1012     }
1013    
1014     else{
1015     fprintf(stderr,
1016     "Unknown TraPPE_Ex bend type \"%s\" at line %d\n",
1017     currentBendType->type,
1018     lineNum );
1019     exit(8);
1020     }
1021     }
1022     }
1023    
1024     tempBendType = new LinkedType;
1025     currentBendType->next = tempBendType;
1026     currentBendType = tempBendType;
1027    
1028     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1029     lineNum++;
1030     }
1031    
1032    
1033     // initialize the Bends
1034    
1035     for( i=0; i<nBends; i++ ){
1036    
1037     a = the_bends[i].a;
1038     b = the_bends[i].b;
1039     c = the_bends[i].c;
1040    
1041     atomA = the_atoms[a]->getType();
1042     atomB = the_atoms[b]->getType();
1043     atomC = the_atoms[c]->getType();
1044     currentBendType = headBendType->find( atomA, atomB, atomC );
1045     if( currentBendType == NULL ){
1046     fprintf( stderr, "BendType error, %s - %s - %s not found"
1047     " in force file.\n",
1048     atomA, atomB, atomC );
1049     exit(8);
1050     }
1051    
1052     if( !strcmp( currentBendType->type, "quadratic" ) ){
1053    
1054     index = i + entry_plug->n_bonds;
1055     qBend = new QuadraticBend( *the_atoms[a],
1056     *the_atoms[b],
1057     *the_atoms[c] );
1058     qBend->setConstants( currentBendType->k1,
1059     currentBendType->k2,
1060     currentBendType->k3,
1061     currentBendType->t0 );
1062     the_sris[index] = qBend;
1063     }
1064     }
1065    
1066    
1067     // clean up the memory
1068    
1069     delete headBendType;
1070    
1071     }
1072    
1073     void TraPPE_ExFF::initializeTorsions( torsion_set* the_torsions ){
1074    
1075     class LinkedType {
1076     public:
1077     LinkedType(){
1078     next = NULL;
1079     nameA[0] = '\0';
1080     nameB[0] = '\0';
1081     nameC[0] = '\0';
1082     type[0] = '\0';
1083     }
1084     ~LinkedType(){ if( next != NULL ) delete next; }
1085    
1086     LinkedType* find( char* key1, char* key2, char* key3, char* key4 ){
1087     if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) &&
1088     !strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this;
1089    
1090     if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) &&
1091     !strcmp( nameC, key2 ) && !strcmp( nameD, key4 ) ) return this;
1092    
1093     if( next != NULL ) return next->find(key1, key2, key3, key4);
1094     return NULL;
1095     }
1096    
1097 mmeineke 146 #ifdef IS_MPI
1098    
1099     void add( torsionStruct &info ){
1100     if( next != NULL ) next->add(info);
1101     else{
1102     next = new LinkedType();
1103     strcpy(next->nameA, info.nameA);
1104     strcpy(next->nameB, info.nameB);
1105     strcpy(next->nameC, info.nameC);
1106     strcpy(next->type, info.type);
1107     next->k1 = info.k1;
1108     next->k2 = info.k2;
1109     next->k3 = info.k3;
1110     next->k4 = info.k4;
1111     }
1112     }
1113    
1114     void duplicate( torsionStruct &info ){
1115     strcpy(info.nameA, nameA);
1116     strcpy(info.nameB, nameB);
1117     strcpy(info.nameC, nameC);
1118     strcpy(info.nameD, nameD);
1119     strcpy(info.type, type);
1120     info.k1 = k1;
1121     info.k2 = k2;
1122     info.k3 = k3;
1123     info.k4 = k4;
1124     info.last = 0;
1125     }
1126    
1127     #endif
1128    
1129 mmeineke 10 char nameA[15];
1130     char nameB[15];
1131     char nameC[15];
1132     char nameD[15];
1133     char type[30];
1134     double k1, k2, k3, k4;
1135    
1136     LinkedType* next;
1137     };
1138    
1139     LinkedType* headTorsionType;
1140     LinkedType* currentTorsionType;
1141     LinkedType* tempTorsionType;
1142    
1143     char readLine[500];
1144     char* the_token;
1145     char* eof_test;
1146     int foundTorsion = 0;
1147     int lineNum = 0;
1148     int i, a, b, c, d, index;
1149     char* atomA;
1150     char* atomB;
1151     char* atomC;
1152     char* atomD;
1153     CubicTorsion* cTors;
1154    
1155     SRI **the_sris;
1156     Atom** the_atoms;
1157     int nTorsions;
1158     the_sris = entry_plug->sr_interactions;
1159     the_atoms = entry_plug->atoms;
1160     nTorsions = entry_plug->n_torsions;
1161    
1162     // read in the torsion types.
1163    
1164     rewind( frcFile );
1165     headTorsionType = new LinkedType;
1166     currentTorsionType = headTorsionType;
1167    
1168     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1169     lineNum++;
1170     if( eof_test == NULL ){
1171     fprintf( stderr, "Error in reading Torsions from force file.\n" );
1172     exit(8);
1173     }
1174    
1175    
1176     while( !foundTorsion ){
1177     while( eof_test != NULL && readLine[0] != '#' ){
1178     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1179     lineNum++;
1180     }
1181     if( eof_test == NULL ){
1182     fprintf( stderr,
1183     "Error in reading Torsions from force file at line %d.\n",
1184     lineNum );
1185     exit(8);
1186     }
1187    
1188     the_token = strtok( readLine, " ,;\t#\n" );
1189     foundTorsion = !strcmp( "TorsionTypes", the_token );
1190    
1191     if( !foundTorsion ){
1192     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1193     lineNum++;
1194    
1195     if( eof_test == NULL ){
1196     fprintf( stderr,
1197     "Error in reading Torsions from force file at line %d.\n",
1198     lineNum );
1199     exit(8);
1200     }
1201     }
1202     }
1203    
1204     // we are now at the TorsionTypes section.
1205    
1206     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1207     lineNum++;
1208    
1209     if( eof_test == NULL ){
1210     fprintf( stderr,
1211     "Error in reading Torsions from force file at line %d.\n",
1212     lineNum );
1213     exit(8);
1214     }
1215    
1216     while( readLine[0] != '#' && eof_test != NULL ){
1217    
1218     if( readLine[0] != '!' ){
1219    
1220     the_token = strtok( readLine, " \n\t,;" );
1221     if( the_token != NULL ){
1222    
1223     strcpy( currentTorsionType->nameA, the_token );
1224    
1225     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1226     fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum );
1227     exit(8);
1228     }
1229    
1230     strcpy( currentTorsionType->nameB, the_token );
1231    
1232     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1233     fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum );
1234     exit(8);
1235     }
1236    
1237     strcpy( currentTorsionType->nameC, the_token );
1238    
1239     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1240     fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum );
1241     exit(8);
1242     }
1243    
1244     strcpy( currentTorsionType->nameD, the_token );
1245    
1246     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1247     fprintf( stderr, "Error parseing TorsionTypes: line %d\n", lineNum );
1248     exit(8);
1249     }
1250    
1251     strcpy( currentTorsionType->type, the_token );
1252    
1253     if( !strcmp( currentTorsionType->type, "cubic" ) ){
1254     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1255     fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum );
1256     exit(8);
1257     }
1258    
1259     sscanf( the_token, "%lf", &currentTorsionType->k1 );
1260    
1261     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1262     fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum );
1263     exit(8);
1264     }
1265    
1266     sscanf( the_token, "%lf", &currentTorsionType->k2 );
1267    
1268     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1269     fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum );
1270     exit(8);
1271     }
1272    
1273     sscanf( the_token, "%lf", &currentTorsionType->k3 );
1274    
1275     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1276     fprintf(stderr,"Error parseing TorsionTypes: line %d\n", lineNum );
1277     exit(8);
1278     }
1279    
1280     sscanf( the_token, "%lf", &currentTorsionType->k4 );
1281     }
1282    
1283     else{
1284     fprintf(stderr,
1285     "Unknown TraPPE_Ex torsion type \"%s\" at line %d\n",
1286     currentTorsionType->type,
1287     lineNum );
1288     exit(8);
1289     }
1290     }
1291     }
1292    
1293     tempTorsionType = new LinkedType;
1294     currentTorsionType->next = tempTorsionType;
1295     currentTorsionType = tempTorsionType;
1296    
1297     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1298     lineNum++;
1299     }
1300    
1301    
1302     // initialize the Torsions
1303    
1304     for( i=0; i<nTorsions; i++ ){
1305    
1306     a = the_torsions[i].a;
1307     b = the_torsions[i].b;
1308     c = the_torsions[i].c;
1309     d = the_torsions[i].d;
1310    
1311     atomA = the_atoms[a]->getType();
1312     atomB = the_atoms[b]->getType();
1313     atomC = the_atoms[c]->getType();
1314     atomD = the_atoms[d]->getType();
1315     currentTorsionType = headTorsionType->find( atomA, atomB, atomC, atomD );
1316     if( currentTorsionType == NULL ){
1317     fprintf( stderr, "TorsionType error, %s - %s - %s - %s not found"
1318     " in force file.\n",
1319     atomA, atomB, atomC, atomD );
1320     exit(8);
1321     }
1322    
1323     if( !strcmp( currentTorsionType->type, "cubic" ) ){
1324     index = i + entry_plug->n_bonds + entry_plug->n_bends;
1325    
1326     cTors = new CubicTorsion( *the_atoms[a], *the_atoms[b],
1327     *the_atoms[c], *the_atoms[d] );
1328     cTors->setConstants( currentTorsionType->k1, currentTorsionType->k2,
1329     currentTorsionType->k3, currentTorsionType->k4 );
1330     the_sris[index] = cTors;
1331     }
1332     }
1333    
1334    
1335     // clean up the memory
1336    
1337     delete headTorsionType;
1338    
1339     }