ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DUFF.cpp
Revision: 631
Committed: Thu Jul 17 19:25:51 2003 UTC (20 years, 11 months ago) by chuckv
File size: 41658 byte(s)
Log Message:
Added massive changes for eam....

File Contents

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