ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DUFF.cpp
Revision: 707
Committed: Wed Aug 20 19:42:31 2003 UTC (20 years, 10 months ago) by mmeineke
File size: 43546 byte(s)
Log Message:
updated the Changelog.

added some bug fixes for setting the random number generator seed value.

fixed a bug where ghostbend atom b was not being set. ( recent bug from SimState conversion)

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