ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DUFF.cpp
Revision: 727
Committed: Wed Aug 27 16:16:01 2003 UTC (20 years, 10 months ago) by tim
File size: 43546 byte(s)
Log Message:
fix bug in calc_dipole_dipole.F90 and calc_stikcy_pair.F90
molMembershipList use global index instead of local index

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 mmeineke 721 int atomBC[3] = {15,11,4}; // block counts
480 mmeineke 559 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 tim 727
790 mmeineke 559 currentAtomType = headAtomType->next;;
791     while( currentAtomType != NULL ){
792    
793     if(currentAtomType->isDipole) entry_plug->useDipole = 1;
794     if(currentAtomType->isSSD) {
795     entry_plug->useSticky = 1;
796 gezelter 635 set_sticky_params( &(currentAtomType->w0), &(currentAtomType->v0),
797     &(currentAtomType->v0p),
798     &(currentAtomType->rl), &(currentAtomType->ru),
799     &(currentAtomType->rlp), &(currentAtomType->rup));
800 mmeineke 559 }
801    
802     if( currentAtomType->name[0] != '\0' ){
803     isError = 0;
804     makeAtype( &(currentAtomType->ident),
805     &isLJ,
806     &(currentAtomType->isSSD),
807     &(currentAtomType->isDipole),
808     &isGB,
809 chuckv 631 &isEAM,
810 mmeineke 559 &(currentAtomType->epslon),
811     &(currentAtomType->sigma),
812     &(currentAtomType->dipole),
813     &isError );
814     if( isError ){
815     sprintf( painCave.errMsg,
816     "Error initializing the \"%s\" atom type in fortran\n",
817     currentAtomType->name );
818     painCave.isFatal = 1;
819     simError();
820     }
821     }
822     currentAtomType = currentAtomType->next;
823     }
824    
825     #ifdef IS_MPI
826     sprintf( checkPointMsg,
827 mmeineke 561 "DUFF atom structures successfully sent to fortran\n" );
828 mmeineke 559 MPIcheckPoint();
829     #endif // is_mpi
830    
831    
832    
833     // read in the bonds
834    
835     #ifdef IS_MPI
836     if( worldRank == 0 ){
837     #endif
838    
839     // read in the bond types.
840    
841     headBondType = new LinkedBondType;
842    
843     fastForward( "BondTypes", "initializeBonds" );
844    
845     // we are now at the bondTypes section
846    
847     eof_test = fgets( readLine, sizeof(readLine), frcFile );
848     lineNum++;
849    
850    
851     // read a line, and start parseing out the atom types
852    
853     if( eof_test == NULL ){
854     sprintf( painCave.errMsg,
855     "Error in reading bonds from force file at line %d.\n",
856     lineNum );
857     painCave.isFatal = 1;
858     simError();
859     }
860    
861     // stop reading at end of file, or at next section
862     while( readLine[0] != '#' && eof_test != NULL ){
863    
864     // toss comment lines
865     if( readLine[0] != '!' ){
866    
867     // the parser returns 0 if the line was blank
868     if( parseBond( readLine, lineNum, bondInfo ) ){
869     headBondType->add( bondInfo );
870     }
871     }
872     eof_test = fgets( readLine, sizeof(readLine), frcFile );
873     lineNum++;
874     }
875    
876     #ifdef IS_MPI
877    
878     // send out the linked list to all the other processes
879    
880     sprintf( checkPointMsg,
881 mmeineke 561 "DUFF bond structures read successfully." );
882 mmeineke 559 MPIcheckPoint();
883    
884     currentBondType = headBondType->next;
885     while( currentBondType != NULL ){
886     currentBondType->duplicate( bondInfo );
887     sendFrcStruct( &bondInfo, mpiBondStructType );
888     currentBondType = currentBondType->next;
889     }
890     bondInfo.last = 1;
891     sendFrcStruct( &bondInfo, mpiBondStructType );
892    
893     }
894    
895     else{
896    
897     // listen for node 0 to send out the force params
898    
899     MPIcheckPoint();
900    
901     headBondType = new LinkedBondType;
902     recieveFrcStruct( &bondInfo, mpiBondStructType );
903     while( !bondInfo.last ){
904    
905     headBondType->add( bondInfo );
906     recieveFrcStruct( &bondInfo, mpiBondStructType );
907     }
908     }
909    
910     sprintf( checkPointMsg,
911 mmeineke 561 "DUFF bond structures broadcast successfully." );
912 mmeineke 559 MPIcheckPoint();
913    
914     #endif // is_mpi
915    
916    
917     // read in the bends
918    
919     #ifdef IS_MPI
920     if( worldRank == 0 ){
921     #endif
922    
923     // read in the bend types.
924    
925     headBendType = new LinkedBendType;
926    
927     fastForward( "BendTypes", "initializeBends" );
928    
929     // we are now at the bendTypes section
930    
931     eof_test = fgets( readLine, sizeof(readLine), frcFile );
932     lineNum++;
933    
934     // read a line, and start parseing out the bend types
935    
936     if( eof_test == NULL ){
937     sprintf( painCave.errMsg,
938     "Error in reading bends from force file at line %d.\n",
939     lineNum );
940     painCave.isFatal = 1;
941     simError();
942     }
943    
944     // stop reading at end of file, or at next section
945     while( readLine[0] != '#' && eof_test != NULL ){
946    
947     // toss comment lines
948     if( readLine[0] != '!' ){
949    
950     // the parser returns 0 if the line was blank
951     if( parseBend( readLine, lineNum, bendInfo ) ){
952     headBendType->add( bendInfo );
953     }
954     }
955     eof_test = fgets( readLine, sizeof(readLine), frcFile );
956     lineNum++;
957     }
958    
959     #ifdef IS_MPI
960    
961     // send out the linked list to all the other processes
962    
963     sprintf( checkPointMsg,
964 mmeineke 561 "DUFF bend structures read successfully." );
965 mmeineke 559 MPIcheckPoint();
966    
967     currentBendType = headBendType->next;
968     while( currentBendType != NULL ){
969     currentBendType->duplicate( bendInfo );
970     sendFrcStruct( &bendInfo, mpiBendStructType );
971     currentBendType = currentBendType->next;
972     }
973     bendInfo.last = 1;
974     sendFrcStruct( &bendInfo, mpiBendStructType );
975    
976     }
977    
978     else{
979    
980     // listen for node 0 to send out the force params
981    
982     MPIcheckPoint();
983    
984     headBendType = new LinkedBendType;
985     recieveFrcStruct( &bendInfo, mpiBendStructType );
986     while( !bendInfo.last ){
987    
988     headBendType->add( bendInfo );
989     recieveFrcStruct( &bendInfo, mpiBendStructType );
990     }
991     }
992    
993     sprintf( checkPointMsg,
994 mmeineke 561 "DUFF bend structures broadcast successfully." );
995 mmeineke 559 MPIcheckPoint();
996    
997     #endif // is_mpi
998    
999    
1000     // read in the torsions
1001    
1002     #ifdef IS_MPI
1003     if( worldRank == 0 ){
1004     #endif
1005    
1006     // read in the torsion types.
1007    
1008     headTorsionType = new LinkedTorsionType;
1009    
1010     fastForward( "TorsionTypes", "initializeTorsions" );
1011    
1012     // we are now at the torsionTypes section
1013    
1014     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1015     lineNum++;
1016    
1017    
1018     // read a line, and start parseing out the atom types
1019    
1020     if( eof_test == NULL ){
1021     sprintf( painCave.errMsg,
1022     "Error in reading torsions from force file at line %d.\n",
1023     lineNum );
1024     painCave.isFatal = 1;
1025     simError();
1026     }
1027    
1028     // stop reading at end of file, or at next section
1029     while( readLine[0] != '#' && eof_test != NULL ){
1030    
1031     // toss comment lines
1032     if( readLine[0] != '!' ){
1033    
1034     // the parser returns 0 if the line was blank
1035     if( parseTorsion( readLine, lineNum, torsionInfo ) ){
1036     headTorsionType->add( torsionInfo );
1037    
1038     }
1039     }
1040     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1041     lineNum++;
1042     }
1043    
1044     #ifdef IS_MPI
1045    
1046     // send out the linked list to all the other processes
1047    
1048     sprintf( checkPointMsg,
1049 mmeineke 561 "DUFF torsion structures read successfully." );
1050 mmeineke 559 MPIcheckPoint();
1051    
1052     currentTorsionType = headTorsionType->next;
1053     while( currentTorsionType != NULL ){
1054     currentTorsionType->duplicate( torsionInfo );
1055     sendFrcStruct( &torsionInfo, mpiTorsionStructType );
1056     currentTorsionType = currentTorsionType->next;
1057     }
1058     torsionInfo.last = 1;
1059     sendFrcStruct( &torsionInfo, mpiTorsionStructType );
1060    
1061     }
1062    
1063     else{
1064    
1065     // listen for node 0 to send out the force params
1066    
1067     MPIcheckPoint();
1068    
1069     headTorsionType = new LinkedTorsionType;
1070     recieveFrcStruct( &torsionInfo, mpiTorsionStructType );
1071     while( !torsionInfo.last ){
1072    
1073     headTorsionType->add( torsionInfo );
1074     recieveFrcStruct( &torsionInfo, mpiTorsionStructType );
1075     }
1076     }
1077    
1078     sprintf( checkPointMsg,
1079 mmeineke 561 "DUFF torsion structures broadcast successfully." );
1080 mmeineke 559 MPIcheckPoint();
1081    
1082     #endif // is_mpi
1083    
1084     entry_plug->useLJ = 1;
1085     }
1086    
1087    
1088    
1089 mmeineke 561 void DUFF::initializeAtoms( int nAtoms, Atom** the_atoms ){
1090 mmeineke 559
1091    
1092     //////////////////////////////////////////////////
1093     // a quick water fix
1094    
1095     double waterI[3][3];
1096     waterI[0][0] = 1.76958347772500;
1097     waterI[0][1] = 0.0;
1098     waterI[0][2] = 0.0;
1099    
1100     waterI[1][0] = 0.0;
1101     waterI[1][1] = 0.614537057924513;
1102     waterI[1][2] = 0.0;
1103    
1104     waterI[2][0] = 0.0;
1105     waterI[2][1] = 0.0;
1106     waterI[2][2] = 1.15504641980049;
1107    
1108    
1109     double headI[3][3];
1110     headI[0][0] = 1125;
1111     headI[0][1] = 0.0;
1112     headI[0][2] = 0.0;
1113    
1114     headI[1][0] = 0.0;
1115     headI[1][1] = 1125;
1116     headI[1][2] = 0.0;
1117    
1118     headI[2][0] = 0.0;
1119     headI[2][1] = 0.0;
1120     headI[2][2] = 250;
1121    
1122     //////////////////////////////////////////////////
1123    
1124    
1125     // initialize the atoms
1126    
1127     DirectionalAtom* dAtom;
1128    
1129     for(int i=0; i<nAtoms; i++ ){
1130    
1131     currentAtomType = headAtomType->find( the_atoms[i]->getType() );
1132     if( currentAtomType == NULL ){
1133     sprintf( painCave.errMsg,
1134     "AtomType error, %s not found in force file.\n",
1135     the_atoms[i]->getType() );
1136     painCave.isFatal = 1;
1137     simError();
1138     }
1139    
1140     the_atoms[i]->setMass( currentAtomType->mass );
1141     the_atoms[i]->setEpslon( currentAtomType->epslon );
1142     the_atoms[i]->setSigma( currentAtomType->sigma );
1143     the_atoms[i]->setIdent( currentAtomType->ident );
1144     the_atoms[i]->setLJ();
1145    
1146     if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma;
1147    
1148     if( currentAtomType->isDipole ){
1149     if( the_atoms[i]->isDirectional() ){
1150    
1151     dAtom = (DirectionalAtom *) the_atoms[i];
1152     dAtom->setMu( currentAtomType->dipole );
1153     dAtom->setHasDipole( 1 );
1154     dAtom->setJx( 0.0 );
1155     dAtom->setJy( 0.0 );
1156     dAtom->setJz( 0.0 );
1157    
1158     if(!strcmp("SSD",the_atoms[i]->getType())){
1159     dAtom->setI( waterI );
1160     dAtom->setSSD( 1 );
1161     }
1162     else if(!strcmp("HEAD",the_atoms[i]->getType())){
1163     dAtom->setI( headI );
1164     dAtom->setSSD( 0 );
1165     }
1166     else{
1167     sprintf(painCave.errMsg,
1168     "AtmType error, %s does not have a moment of inertia set.\n",
1169     the_atoms[i]->getType() );
1170     painCave.isFatal = 1;
1171     simError();
1172     }
1173     entry_plug->n_dipoles++;
1174     }
1175     else{
1176    
1177     sprintf( painCave.errMsg,
1178 mmeineke 561 "DUFF error: Atom \"%s\" is a dipole, yet no standard"
1179 mmeineke 559 " orientation was specifed in the BASS file.\n",
1180     currentAtomType->name );
1181     painCave.isFatal = 1;
1182     simError();
1183     }
1184     }
1185     else{
1186     if( the_atoms[i]->isDirectional() ){
1187     sprintf( painCave.errMsg,
1188 mmeineke 561 "DUFF error: Atom \"%s\" was given a standard"
1189 mmeineke 559 "orientation in the BASS file, yet it is not a dipole.\n",
1190     currentAtomType->name);
1191     painCave.isFatal = 1;
1192     simError();
1193     }
1194     }
1195     }
1196     }
1197    
1198 mmeineke 561 void DUFF::initializeBonds( int nBonds, Bond** bondArray,
1199 mmeineke 559 bond_pair* the_bonds ){
1200     int i,a,b;
1201     char* atomA;
1202     char* atomB;
1203    
1204     Atom** the_atoms;
1205     the_atoms = entry_plug->atoms;
1206    
1207    
1208     // initialize the Bonds
1209    
1210     for( i=0; i<nBonds; i++ ){
1211    
1212     a = the_bonds[i].a;
1213     b = the_bonds[i].b;
1214    
1215     atomA = the_atoms[a]->getType();
1216     atomB = the_atoms[b]->getType();
1217     currentBondType = headBondType->find( atomA, atomB );
1218     if( currentBondType == NULL ){
1219     sprintf( painCave.errMsg,
1220     "BondType error, %s - %s not found in force file.\n",
1221     atomA, atomB );
1222     painCave.isFatal = 1;
1223     simError();
1224     }
1225    
1226 mmeineke 564 switch( currentBondType->type ){
1227    
1228     case FIXED_BOND:
1229    
1230 mmeineke 559 bondArray[i] = new ConstrainedBond( *the_atoms[a],
1231     *the_atoms[b],
1232     currentBondType->d0 );
1233     entry_plug->n_constraints++;
1234 mmeineke 564 break;
1235    
1236     case HARMONIC_BOND:
1237    
1238     bondArray[i] = new HarmonicBond( *the_atoms[a],
1239     *the_atoms[b],
1240     currentBondType->d0,
1241     currentBondType->k0 );
1242     break;
1243    
1244     default:
1245    
1246     break;
1247     // do nothing
1248 mmeineke 559 }
1249     }
1250     }
1251    
1252 mmeineke 561 void DUFF::initializeBends( int nBends, Bend** bendArray,
1253 mmeineke 559 bend_set* the_bends ){
1254    
1255     QuadraticBend* qBend;
1256     GhostBend* gBend;
1257     Atom** the_atoms;
1258     the_atoms = entry_plug->atoms;
1259    
1260     int i, a, b, c;
1261     char* atomA;
1262     char* atomB;
1263     char* atomC;
1264    
1265     // initialize the Bends
1266    
1267     for( i=0; i<nBends; i++ ){
1268    
1269     a = the_bends[i].a;
1270     b = the_bends[i].b;
1271     c = the_bends[i].c;
1272    
1273     atomA = the_atoms[a]->getType();
1274     atomB = the_atoms[b]->getType();
1275    
1276     if( the_bends[i].isGhost ) atomC = "GHOST";
1277     else atomC = the_atoms[c]->getType();
1278    
1279     currentBendType = headBendType->find( atomA, atomB, atomC );
1280     if( currentBendType == NULL ){
1281     sprintf( painCave.errMsg, "BendType error, %s - %s - %s not found"
1282     " in force file.\n",
1283     atomA, atomB, atomC );
1284     painCave.isFatal = 1;
1285     simError();
1286     }
1287    
1288     if( !strcmp( currentBendType->type, "quadratic" ) ){
1289    
1290     if( the_bends[i].isGhost){
1291    
1292     if( the_bends[i].ghost == b ){
1293     // do nothing
1294     }
1295     else if( the_bends[i].ghost == a ){
1296     c = a;
1297     a = b;
1298     b = c;
1299     }
1300     else{
1301     sprintf( painCave.errMsg,
1302     "BendType error, %s - %s - %s,\n"
1303     " --> central atom is not "
1304     "correctly identified with the "
1305     "\"ghostVectorSource = \" tag.\n",
1306     atomA, atomB, atomC );
1307     painCave.isFatal = 1;
1308     simError();
1309     }
1310    
1311     gBend = new GhostBend( *the_atoms[a],
1312 mmeineke 707 *the_atoms[b]);
1313 tim 704
1314 mmeineke 559 gBend->setConstants( currentBendType->k1,
1315     currentBendType->k2,
1316     currentBendType->k3,
1317     currentBendType->t0 );
1318     bendArray[i] = gBend;
1319     }
1320     else{
1321     qBend = new QuadraticBend( *the_atoms[a],
1322     *the_atoms[b],
1323     *the_atoms[c] );
1324     qBend->setConstants( currentBendType->k1,
1325     currentBendType->k2,
1326     currentBendType->k3,
1327     currentBendType->t0 );
1328     bendArray[i] = qBend;
1329 tim 704 }
1330 mmeineke 559 }
1331     }
1332     }
1333    
1334 mmeineke 561 void DUFF::initializeTorsions( int nTorsions, Torsion** torsionArray,
1335 mmeineke 559 torsion_set* the_torsions ){
1336    
1337     int i, a, b, c, d;
1338     char* atomA;
1339     char* atomB;
1340     char* atomC;
1341     char* atomD;
1342    
1343     CubicTorsion* cTors;
1344     Atom** the_atoms;
1345     the_atoms = entry_plug->atoms;
1346    
1347     // initialize the Torsions
1348    
1349     for( i=0; i<nTorsions; i++ ){
1350    
1351     a = the_torsions[i].a;
1352     b = the_torsions[i].b;
1353     c = the_torsions[i].c;
1354     d = the_torsions[i].d;
1355    
1356     atomA = the_atoms[a]->getType();
1357     atomB = the_atoms[b]->getType();
1358     atomC = the_atoms[c]->getType();
1359     atomD = the_atoms[d]->getType();
1360     currentTorsionType = headTorsionType->find( atomA, atomB, atomC, atomD );
1361     if( currentTorsionType == NULL ){
1362     sprintf( painCave.errMsg,
1363     "TorsionType error, %s - %s - %s - %s not found"
1364     " in force file.\n",
1365     atomA, atomB, atomC, atomD );
1366     painCave.isFatal = 1;
1367     simError();
1368     }
1369    
1370     if( !strcmp( currentTorsionType->type, "cubic" ) ){
1371    
1372     cTors = new CubicTorsion( *the_atoms[a], *the_atoms[b],
1373     *the_atoms[c], *the_atoms[d] );
1374     cTors->setConstants( currentTorsionType->k1, currentTorsionType->k2,
1375     currentTorsionType->k3, currentTorsionType->k4 );
1376     torsionArray[i] = cTors;
1377     }
1378     }
1379     }
1380    
1381 mmeineke 561 void DUFF::fastForward( char* stopText, char* searchOwner ){
1382 mmeineke 559
1383     int foundText = 0;
1384     char* the_token;
1385    
1386     rewind( frcFile );
1387     lineNum = 0;
1388    
1389     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1390     lineNum++;
1391     if( eof_test == NULL ){
1392     sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
1393     " file is empty.\n",
1394     searchOwner );
1395     painCave.isFatal = 1;
1396     simError();
1397     }
1398    
1399    
1400     while( !foundText ){
1401     while( eof_test != NULL && readLine[0] != '#' ){
1402     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1403     lineNum++;
1404     }
1405     if( eof_test == NULL ){
1406     sprintf( painCave.errMsg,
1407     "Error fast forwarding force file for %s at "
1408     "line %d: file ended unexpectedly.\n",
1409     searchOwner,
1410     lineNum );
1411     painCave.isFatal = 1;
1412     simError();
1413     }
1414    
1415     the_token = strtok( readLine, " ,;\t#\n" );
1416     foundText = !strcmp( stopText, the_token );
1417    
1418     if( !foundText ){
1419     eof_test = fgets( readLine, sizeof(readLine), frcFile );
1420     lineNum++;
1421    
1422     if( eof_test == NULL ){
1423     sprintf( painCave.errMsg,
1424     "Error fast forwarding force file for %s at "
1425     "line %d: file ended unexpectedly.\n",
1426     searchOwner,
1427     lineNum );
1428     painCave.isFatal = 1;
1429     simError();
1430     }
1431     }
1432     }
1433     }
1434    
1435    
1436 mmeineke 594 int DUFF_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){
1437 mmeineke 559
1438     char* the_token;
1439    
1440     the_token = strtok( lineBuffer, " \n\t,;" );
1441     if( the_token != NULL ){
1442    
1443     strcpy( info.name, the_token );
1444    
1445     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1446     sprintf( painCave.errMsg,
1447     "Error parseing AtomTypes: line %d\n", lineNum );
1448     painCave.isFatal = 1;
1449     simError();
1450     }
1451    
1452     info.isDipole = atoi( the_token );
1453    
1454     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1455     sprintf( painCave.errMsg,
1456     "Error parseing AtomTypes: line %d\n", lineNum );
1457     painCave.isFatal = 1;
1458     simError();
1459     }
1460    
1461     info.isSSD = atoi( the_token );
1462    
1463     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1464     sprintf( painCave.errMsg,
1465     "Error parseing AtomTypes: line %d\n", lineNum );
1466     painCave.isFatal = 1;
1467     simError();
1468     }
1469    
1470     info.mass = atof( the_token );
1471    
1472     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1473     sprintf( painCave.errMsg,
1474     "Error parseing AtomTypes: line %d\n", lineNum );
1475     painCave.isFatal = 1;
1476     simError();
1477     }
1478    
1479     info.epslon = atof( the_token );
1480    
1481     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1482     sprintf( painCave.errMsg,
1483     "Error parseing AtomTypes: line %d\n", lineNum );
1484     painCave.isFatal = 1;
1485     simError();
1486     }
1487    
1488     info.sigma = atof( the_token );
1489    
1490     if( info.isDipole ){
1491    
1492     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1493     sprintf( painCave.errMsg,
1494     "Error parseing AtomTypes: line %d\n", lineNum );
1495     painCave.isFatal = 1;
1496     simError();
1497     }
1498    
1499     info.dipole = atof( the_token );
1500     }
1501     else info.dipole = 0.0;
1502    
1503     if( info.isSSD ){
1504    
1505     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1506     sprintf( painCave.errMsg,
1507     "Error parseing AtomTypes: line %d\n", lineNum );
1508     painCave.isFatal = 1;
1509     simError();
1510     }
1511    
1512     info.w0 = atof( the_token );
1513    
1514     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1515     sprintf( painCave.errMsg,
1516     "Error parseing AtomTypes: line %d\n", lineNum );
1517     painCave.isFatal = 1;
1518     simError();
1519     }
1520    
1521     info.v0 = atof( the_token );
1522 gezelter 635 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1523     sprintf( painCave.errMsg,
1524     "Error parseing AtomTypes: line %d\n", lineNum );
1525     painCave.isFatal = 1;
1526     simError();
1527     }
1528    
1529     info.v0p = atof( the_token );
1530    
1531     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1532     sprintf( painCave.errMsg,
1533     "Error parseing AtomTypes: line %d\n", lineNum );
1534     painCave.isFatal = 1;
1535     simError();
1536     }
1537    
1538     info.rl = atof( the_token );
1539    
1540     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1541     sprintf( painCave.errMsg,
1542     "Error parseing AtomTypes: line %d\n", lineNum );
1543     painCave.isFatal = 1;
1544     simError();
1545     }
1546    
1547     info.ru = atof( the_token );
1548    
1549     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1550     sprintf( painCave.errMsg,
1551     "Error parseing AtomTypes: line %d\n", lineNum );
1552     painCave.isFatal = 1;
1553     simError();
1554     }
1555    
1556     info.rlp = atof( the_token );
1557    
1558     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1559     sprintf( painCave.errMsg,
1560     "Error parseing AtomTypes: line %d\n", lineNum );
1561     painCave.isFatal = 1;
1562     simError();
1563     }
1564    
1565     info.rup = atof( the_token );
1566 mmeineke 559 }
1567 gezelter 635 else info.v0 = info.w0 = info.v0p = info.rl = info.ru = info.rlp = info.rup = 0.0;
1568 mmeineke 559
1569     return 1;
1570     }
1571     else return 0;
1572     }
1573    
1574 mmeineke 594 int DUFF_NS::parseBond( char *lineBuffer, int lineNum, bondStruct &info ){
1575 mmeineke 559
1576     char* the_token;
1577 mmeineke 564 char bondType[30];
1578 mmeineke 559
1579     the_token = strtok( lineBuffer, " \n\t,;" );
1580     if( the_token != NULL ){
1581    
1582     strcpy( info.nameA, the_token );
1583    
1584     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1585     sprintf( painCave.errMsg,
1586     "Error parseing BondTypes: line %d\n", lineNum );
1587     painCave.isFatal = 1;
1588     simError();
1589     }
1590    
1591     strcpy( info.nameB, the_token );
1592    
1593     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1594     sprintf( painCave.errMsg,
1595     "Error parseing BondTypes: line %d\n", lineNum );
1596     painCave.isFatal = 1;
1597     simError();
1598     }
1599    
1600 mmeineke 564 strcpy( bondType, the_token );
1601 mmeineke 559
1602 mmeineke 564 if( !strcmp( bondType, "fixed" ) ){
1603     info.type = FIXED_BOND;
1604    
1605 mmeineke 559 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1606     sprintf( painCave.errMsg,
1607     "Error parseing BondTypes: line %d\n", lineNum );
1608     painCave.isFatal = 1;
1609     simError();
1610     }
1611    
1612     info.d0 = atof( the_token );
1613 mmeineke 690
1614     info.k0=0.0;
1615 mmeineke 559 }
1616 mmeineke 564 else if( !strcmp( bondType, "harmonic" ) ){
1617     info.type = HARMONIC_BOND;
1618    
1619     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1620     sprintf( painCave.errMsg,
1621     "Error parseing BondTypes: line %d\n", lineNum );
1622     painCave.isFatal = 1;
1623     simError();
1624     }
1625    
1626     info.d0 = atof( the_token );
1627    
1628     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1629     sprintf( painCave.errMsg,
1630     "Error parseing BondTypes: line %d\n", lineNum );
1631     painCave.isFatal = 1;
1632     simError();
1633     }
1634    
1635     info.k0 = atof( the_token );
1636     }
1637    
1638 mmeineke 559 else{
1639     sprintf( painCave.errMsg,
1640 mmeineke 561 "Unknown DUFF bond type \"%s\" at line %d\n",
1641 mmeineke 559 info.type,
1642     lineNum );
1643     painCave.isFatal = 1;
1644     simError();
1645     }
1646    
1647     return 1;
1648     }
1649     else return 0;
1650     }
1651    
1652    
1653 mmeineke 594 int DUFF_NS::parseBend( char *lineBuffer, int lineNum, bendStruct &info ){
1654 mmeineke 559
1655     char* the_token;
1656    
1657     the_token = strtok( lineBuffer, " \n\t,;" );
1658     if( the_token != NULL ){
1659    
1660     strcpy( info.nameA, the_token );
1661    
1662     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1663     sprintf( painCave.errMsg,
1664     "Error parseing BendTypes: line %d\n", lineNum );
1665     painCave.isFatal = 1;
1666     simError();
1667     }
1668    
1669     strcpy( info.nameB, the_token );
1670    
1671     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1672     sprintf( painCave.errMsg,
1673     "Error parseing BendTypes: line %d\n", lineNum );
1674     painCave.isFatal = 1;
1675     simError();
1676     }
1677    
1678     strcpy( info.nameC, the_token );
1679    
1680     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1681     sprintf( painCave.errMsg,
1682     "Error parseing BendTypes: line %d\n", lineNum );
1683     painCave.isFatal = 1;
1684     simError();
1685     }
1686    
1687     strcpy( info.type, the_token );
1688    
1689     if( !strcmp( info.type, "quadratic" ) ){
1690     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1691     sprintf( painCave.errMsg,
1692     "Error parseing BendTypes: line %d\n", lineNum );
1693     painCave.isFatal = 1;
1694     simError();
1695     }
1696    
1697     info.k1 = atof( the_token );
1698    
1699     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1700     sprintf( painCave.errMsg,
1701     "Error parseing BendTypes: line %d\n", lineNum );
1702     painCave.isFatal = 1;
1703     simError();
1704     }
1705    
1706     info.k2 = atof( the_token );
1707    
1708     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1709     sprintf( painCave.errMsg,
1710     "Error parseing BendTypes: line %d\n", lineNum );
1711     painCave.isFatal = 1;
1712     simError();
1713     }
1714    
1715     info.k3 = atof( the_token );
1716    
1717     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1718     sprintf( painCave.errMsg,
1719     "Error parseing BendTypes: line %d\n", lineNum );
1720     painCave.isFatal = 1;
1721     simError();
1722     }
1723    
1724     info.t0 = atof( the_token );
1725     }
1726    
1727     else{
1728     sprintf( painCave.errMsg,
1729 mmeineke 561 "Unknown DUFF bend type \"%s\" at line %d\n",
1730 mmeineke 559 info.type,
1731     lineNum );
1732     painCave.isFatal = 1;
1733     simError();
1734     }
1735    
1736     return 1;
1737     }
1738     else return 0;
1739     }
1740    
1741 mmeineke 594 int DUFF_NS::parseTorsion( char *lineBuffer, int lineNum, torsionStruct &info ){
1742 mmeineke 559
1743     char* the_token;
1744    
1745     the_token = strtok( lineBuffer, " \n\t,;" );
1746     if( the_token != NULL ){
1747    
1748     strcpy( info.nameA, the_token );
1749    
1750     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1751     sprintf( painCave.errMsg,
1752     "Error parseing TorsionTypes: line %d\n", lineNum );
1753     painCave.isFatal = 1;
1754     simError();
1755     }
1756    
1757     strcpy( info.nameB, the_token );
1758    
1759     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1760     sprintf( painCave.errMsg,
1761     "Error parseing TorsionTypes: line %d\n", lineNum );
1762     painCave.isFatal = 1;
1763     simError();
1764     }
1765    
1766     strcpy( info.nameC, the_token );
1767    
1768     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1769     sprintf( painCave.errMsg,
1770     "Error parseing TorsionTypes: line %d\n", lineNum );
1771     painCave.isFatal = 1;
1772     simError();
1773     }
1774    
1775     strcpy( info.nameD, the_token );
1776    
1777     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1778     sprintf( painCave.errMsg,
1779     "Error parseing TorsionTypes: line %d\n", lineNum );
1780     painCave.isFatal = 1;
1781     simError();
1782     }
1783    
1784     strcpy( info.type, the_token );
1785    
1786     if( !strcmp( info.type, "cubic" ) ){
1787     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1788     sprintf( painCave.errMsg,
1789     "Error parseing TorsionTypes: line %d\n", lineNum );
1790     painCave.isFatal = 1;
1791     simError();
1792     }
1793    
1794     info.k1 = atof( the_token );
1795    
1796     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1797     sprintf( painCave.errMsg,
1798     "Error parseing TorsionTypes: line %d\n", lineNum );
1799     painCave.isFatal = 1;
1800     simError();
1801     }
1802    
1803     info.k2 = atof( the_token );
1804    
1805     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1806     sprintf( painCave.errMsg,
1807     "Error parseing TorsionTypes: line %d\n", lineNum );
1808     painCave.isFatal = 1;
1809     simError();
1810     }
1811    
1812     info.k3 = atof( the_token );
1813    
1814     if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1815     sprintf( painCave.errMsg,
1816     "Error parseing TorsionTypes: line %d\n", lineNum );
1817     painCave.isFatal = 1;
1818     simError();
1819     }
1820    
1821     info.k4 = atof( the_token );
1822    
1823     }
1824    
1825     else{
1826     sprintf( painCave.errMsg,
1827 mmeineke 561 "Unknown DUFF torsion type \"%s\" at line %d\n",
1828 mmeineke 559 info.type,
1829     lineNum );
1830     painCave.isFatal = 1;
1831     simError();
1832     }
1833    
1834     return 1;
1835     }
1836    
1837     else return 0;
1838     }