ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DUFF.cpp
Revision: 704
Committed: Wed Aug 20 19:11:51 2003 UTC (20 years, 10 months ago) by tim
File size: 43573 byte(s)
Log Message:
bug fixed in ghost bend class

File Contents

# Content
1 #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
19 // define some bond Types
20
21 #define FIXED_BOND 0
22 #define HARMONIC_BOND 1
23
24
25 namespace DUFF_NS { // restrict the access of the folowing to this file only.
26
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 double v0p;
39 double rl;
40 double ru;
41 double rlp;
42 double rup;
43 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 double k0;
56 int last; // 0 -> default
57 // 1 -> tells nodes to stop listening
58 int type;
59 } 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 "Duplicate DUFF atom type \"%s\" found in "
128 "the DUFF param file./n",
129 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 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 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 info.v0p = v0p;
168 info.rl = rl;
169 info.ru = ru;
170 info.rlp = rlp;
171 info.rup = rup;
172 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 double v0p;
189 double rl;
190 double ru;
191 double rlp;
192 double rup;
193 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 "Duplicate DUFF bond type \"%s - %s\" found in "
225 "the DUFF param file./n",
226 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 next->type = info.type;
238 next->d0 = info.d0;
239 next->k0 = info.k0;
240 }
241 }
242
243 #ifdef IS_MPI
244 void duplicate( bondStruct &info ){
245 strcpy(info.nameA, nameA);
246 strcpy(info.nameB, nameB);
247 info.type = type;
248 info.d0 = d0;
249 info.k0 = k0;
250 info.last = 0;
251 }
252
253
254 #endif
255
256 char nameA[15];
257 char nameB[15];
258 int type;
259 double d0;
260 double k0;
261
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 "Duplicate DUFF bend type \"%s - %s - %s\" found in "
298 "the DUFF param file./n",
299 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 "Duplicate DUFF torsion type \"%s - %s - %s - %s\" found in "
383 "the DUFF param file./n", nameA, nameB, nameC, nameD );
384 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 using namespace DUFF_NS;
444
445
446 //****************************************************************
447 // begins the actual forcefield stuff.
448 //****************************************************************
449
450
451 DUFF::DUFF(){
452
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 int bondBC[3] = {30,2,2}; // block counts
502 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 strcpy( fileName, "DUFF.frc" );
571 // 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 sprintf( checkPointMsg, "DUFF file opened sucessfully." );
610 MPIcheckPoint();
611
612 #endif // is_mpi
613 }
614
615
616 DUFF::~DUFF(){
617
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 void DUFF::cleanMe( void ){
635
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 void DUFF::initForceField( int ljMixRule ){
654
655 initFortran( ljMixRule, entry_plug->useReactionField );
656 }
657
658
659 void DUFF::readParams( void ){
660
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 "DUFF atom structures read successfully." );
732 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 "successfully sent DUFF force type: \"%s\"\n",
744 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 int isEAM =0;
788 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 set_sticky_params( &(currentAtomType->w0), &(currentAtomType->v0),
798 &(currentAtomType->v0p),
799 &(currentAtomType->rl), &(currentAtomType->ru),
800 &(currentAtomType->rlp), &(currentAtomType->rup));
801 }
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 &isEAM,
811 &(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 "DUFF atom structures successfully sent to fortran\n" );
829 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 "DUFF bond structures read successfully." );
883 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 "DUFF bond structures broadcast successfully." );
913 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 "DUFF bend structures read successfully." );
966 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 "DUFF bend structures broadcast successfully." );
996 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 "DUFF torsion structures read successfully." );
1051 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 "DUFF torsion structures broadcast successfully." );
1081 MPIcheckPoint();
1082
1083 #endif // is_mpi
1084
1085 entry_plug->useLJ = 1;
1086 }
1087
1088
1089
1090 void DUFF::initializeAtoms( int nAtoms, Atom** the_atoms ){
1091
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 "DUFF error: Atom \"%s\" is a dipole, yet no standard"
1180 " 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 "DUFF error: Atom \"%s\" was given a standard"
1190 "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 void DUFF::initializeBonds( int nBonds, Bond** bondArray,
1200 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 switch( currentBondType->type ){
1228
1229 case FIXED_BOND:
1230
1231 bondArray[i] = new ConstrainedBond( *the_atoms[a],
1232 *the_atoms[b],
1233 currentBondType->d0 );
1234 entry_plug->n_constraints++;
1235 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 }
1250 }
1251 }
1252
1253 void DUFF::initializeBends( int nBends, Bend** bendArray,
1254 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 *the_atoms[b],
1314 *the_atoms[c] );
1315
1316 gBend->setConstants( currentBendType->k1,
1317 currentBendType->k2,
1318 currentBendType->k3,
1319 currentBendType->t0 );
1320 bendArray[i] = gBend;
1321 }
1322 else{
1323 qBend = new QuadraticBend( *the_atoms[a],
1324 *the_atoms[b],
1325 *the_atoms[c] );
1326 qBend->setConstants( currentBendType->k1,
1327 currentBendType->k2,
1328 currentBendType->k3,
1329 currentBendType->t0 );
1330 bendArray[i] = qBend;
1331 }
1332 }
1333 }
1334 }
1335
1336 void DUFF::initializeTorsions( int nTorsions, Torsion** torsionArray,
1337 torsion_set* the_torsions ){
1338
1339 int i, a, b, c, d;
1340 char* atomA;
1341 char* atomB;
1342 char* atomC;
1343 char* atomD;
1344
1345 CubicTorsion* cTors;
1346 Atom** the_atoms;
1347 the_atoms = entry_plug->atoms;
1348
1349 // initialize the Torsions
1350
1351 for( i=0; i<nTorsions; i++ ){
1352
1353 a = the_torsions[i].a;
1354 b = the_torsions[i].b;
1355 c = the_torsions[i].c;
1356 d = the_torsions[i].d;
1357
1358 atomA = the_atoms[a]->getType();
1359 atomB = the_atoms[b]->getType();
1360 atomC = the_atoms[c]->getType();
1361 atomD = the_atoms[d]->getType();
1362 currentTorsionType = headTorsionType->find( atomA, atomB, atomC, atomD );
1363 if( currentTorsionType == NULL ){
1364 sprintf( painCave.errMsg,
1365 "TorsionType error, %s - %s - %s - %s not found"
1366 " in force file.\n",
1367 atomA, atomB, atomC, atomD );
1368 painCave.isFatal = 1;
1369 simError();
1370 }
1371
1372 if( !strcmp( currentTorsionType->type, "cubic" ) ){
1373
1374 cTors = new CubicTorsion( *the_atoms[a], *the_atoms[b],
1375 *the_atoms[c], *the_atoms[d] );
1376 cTors->setConstants( currentTorsionType->k1, currentTorsionType->k2,
1377 currentTorsionType->k3, currentTorsionType->k4 );
1378 torsionArray[i] = cTors;
1379 }
1380 }
1381 }
1382
1383 void DUFF::fastForward( char* stopText, char* searchOwner ){
1384
1385 int foundText = 0;
1386 char* the_token;
1387
1388 rewind( frcFile );
1389 lineNum = 0;
1390
1391 eof_test = fgets( readLine, sizeof(readLine), frcFile );
1392 lineNum++;
1393 if( eof_test == NULL ){
1394 sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
1395 " file is empty.\n",
1396 searchOwner );
1397 painCave.isFatal = 1;
1398 simError();
1399 }
1400
1401
1402 while( !foundText ){
1403 while( eof_test != NULL && readLine[0] != '#' ){
1404 eof_test = fgets( readLine, sizeof(readLine), frcFile );
1405 lineNum++;
1406 }
1407 if( eof_test == NULL ){
1408 sprintf( painCave.errMsg,
1409 "Error fast forwarding force file for %s at "
1410 "line %d: file ended unexpectedly.\n",
1411 searchOwner,
1412 lineNum );
1413 painCave.isFatal = 1;
1414 simError();
1415 }
1416
1417 the_token = strtok( readLine, " ,;\t#\n" );
1418 foundText = !strcmp( stopText, the_token );
1419
1420 if( !foundText ){
1421 eof_test = fgets( readLine, sizeof(readLine), frcFile );
1422 lineNum++;
1423
1424 if( eof_test == NULL ){
1425 sprintf( painCave.errMsg,
1426 "Error fast forwarding force file for %s at "
1427 "line %d: file ended unexpectedly.\n",
1428 searchOwner,
1429 lineNum );
1430 painCave.isFatal = 1;
1431 simError();
1432 }
1433 }
1434 }
1435 }
1436
1437
1438 int DUFF_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){
1439
1440 char* the_token;
1441
1442 the_token = strtok( lineBuffer, " \n\t,;" );
1443 if( the_token != NULL ){
1444
1445 strcpy( info.name, the_token );
1446
1447 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1448 sprintf( painCave.errMsg,
1449 "Error parseing AtomTypes: line %d\n", lineNum );
1450 painCave.isFatal = 1;
1451 simError();
1452 }
1453
1454 info.isDipole = atoi( the_token );
1455
1456 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1457 sprintf( painCave.errMsg,
1458 "Error parseing AtomTypes: line %d\n", lineNum );
1459 painCave.isFatal = 1;
1460 simError();
1461 }
1462
1463 info.isSSD = atoi( the_token );
1464
1465 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1466 sprintf( painCave.errMsg,
1467 "Error parseing AtomTypes: line %d\n", lineNum );
1468 painCave.isFatal = 1;
1469 simError();
1470 }
1471
1472 info.mass = atof( the_token );
1473
1474 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1475 sprintf( painCave.errMsg,
1476 "Error parseing AtomTypes: line %d\n", lineNum );
1477 painCave.isFatal = 1;
1478 simError();
1479 }
1480
1481 info.epslon = atof( the_token );
1482
1483 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1484 sprintf( painCave.errMsg,
1485 "Error parseing AtomTypes: line %d\n", lineNum );
1486 painCave.isFatal = 1;
1487 simError();
1488 }
1489
1490 info.sigma = atof( the_token );
1491
1492 if( info.isDipole ){
1493
1494 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1495 sprintf( painCave.errMsg,
1496 "Error parseing AtomTypes: line %d\n", lineNum );
1497 painCave.isFatal = 1;
1498 simError();
1499 }
1500
1501 info.dipole = atof( the_token );
1502 }
1503 else info.dipole = 0.0;
1504
1505 if( info.isSSD ){
1506
1507 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1508 sprintf( painCave.errMsg,
1509 "Error parseing AtomTypes: line %d\n", lineNum );
1510 painCave.isFatal = 1;
1511 simError();
1512 }
1513
1514 info.w0 = atof( the_token );
1515
1516 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1517 sprintf( painCave.errMsg,
1518 "Error parseing AtomTypes: line %d\n", lineNum );
1519 painCave.isFatal = 1;
1520 simError();
1521 }
1522
1523 info.v0 = atof( the_token );
1524 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1525 sprintf( painCave.errMsg,
1526 "Error parseing AtomTypes: line %d\n", lineNum );
1527 painCave.isFatal = 1;
1528 simError();
1529 }
1530
1531 info.v0p = atof( the_token );
1532
1533 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1534 sprintf( painCave.errMsg,
1535 "Error parseing AtomTypes: line %d\n", lineNum );
1536 painCave.isFatal = 1;
1537 simError();
1538 }
1539
1540 info.rl = atof( the_token );
1541
1542 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1543 sprintf( painCave.errMsg,
1544 "Error parseing AtomTypes: line %d\n", lineNum );
1545 painCave.isFatal = 1;
1546 simError();
1547 }
1548
1549 info.ru = atof( the_token );
1550
1551 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1552 sprintf( painCave.errMsg,
1553 "Error parseing AtomTypes: line %d\n", lineNum );
1554 painCave.isFatal = 1;
1555 simError();
1556 }
1557
1558 info.rlp = atof( the_token );
1559
1560 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1561 sprintf( painCave.errMsg,
1562 "Error parseing AtomTypes: line %d\n", lineNum );
1563 painCave.isFatal = 1;
1564 simError();
1565 }
1566
1567 info.rup = atof( the_token );
1568 }
1569 else info.v0 = info.w0 = info.v0p = info.rl = info.ru = info.rlp = info.rup = 0.0;
1570
1571 return 1;
1572 }
1573 else return 0;
1574 }
1575
1576 int DUFF_NS::parseBond( char *lineBuffer, int lineNum, bondStruct &info ){
1577
1578 char* the_token;
1579 char bondType[30];
1580
1581 the_token = strtok( lineBuffer, " \n\t,;" );
1582 if( the_token != NULL ){
1583
1584 strcpy( info.nameA, the_token );
1585
1586 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1587 sprintf( painCave.errMsg,
1588 "Error parseing BondTypes: line %d\n", lineNum );
1589 painCave.isFatal = 1;
1590 simError();
1591 }
1592
1593 strcpy( info.nameB, the_token );
1594
1595 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1596 sprintf( painCave.errMsg,
1597 "Error parseing BondTypes: line %d\n", lineNum );
1598 painCave.isFatal = 1;
1599 simError();
1600 }
1601
1602 strcpy( bondType, the_token );
1603
1604 if( !strcmp( bondType, "fixed" ) ){
1605 info.type = FIXED_BOND;
1606
1607 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1608 sprintf( painCave.errMsg,
1609 "Error parseing BondTypes: line %d\n", lineNum );
1610 painCave.isFatal = 1;
1611 simError();
1612 }
1613
1614 info.d0 = atof( the_token );
1615
1616 info.k0=0.0;
1617 }
1618 else if( !strcmp( bondType, "harmonic" ) ){
1619 info.type = HARMONIC_BOND;
1620
1621 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1622 sprintf( painCave.errMsg,
1623 "Error parseing BondTypes: line %d\n", lineNum );
1624 painCave.isFatal = 1;
1625 simError();
1626 }
1627
1628 info.d0 = atof( the_token );
1629
1630 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1631 sprintf( painCave.errMsg,
1632 "Error parseing BondTypes: line %d\n", lineNum );
1633 painCave.isFatal = 1;
1634 simError();
1635 }
1636
1637 info.k0 = atof( the_token );
1638 }
1639
1640 else{
1641 sprintf( painCave.errMsg,
1642 "Unknown DUFF bond type \"%s\" at line %d\n",
1643 info.type,
1644 lineNum );
1645 painCave.isFatal = 1;
1646 simError();
1647 }
1648
1649 return 1;
1650 }
1651 else return 0;
1652 }
1653
1654
1655 int DUFF_NS::parseBend( char *lineBuffer, int lineNum, bendStruct &info ){
1656
1657 char* the_token;
1658
1659 the_token = strtok( lineBuffer, " \n\t,;" );
1660 if( the_token != NULL ){
1661
1662 strcpy( info.nameA, the_token );
1663
1664 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1665 sprintf( painCave.errMsg,
1666 "Error parseing BendTypes: line %d\n", lineNum );
1667 painCave.isFatal = 1;
1668 simError();
1669 }
1670
1671 strcpy( info.nameB, the_token );
1672
1673 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1674 sprintf( painCave.errMsg,
1675 "Error parseing BendTypes: line %d\n", lineNum );
1676 painCave.isFatal = 1;
1677 simError();
1678 }
1679
1680 strcpy( info.nameC, the_token );
1681
1682 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1683 sprintf( painCave.errMsg,
1684 "Error parseing BendTypes: line %d\n", lineNum );
1685 painCave.isFatal = 1;
1686 simError();
1687 }
1688
1689 strcpy( info.type, the_token );
1690
1691 if( !strcmp( info.type, "quadratic" ) ){
1692 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1693 sprintf( painCave.errMsg,
1694 "Error parseing BendTypes: line %d\n", lineNum );
1695 painCave.isFatal = 1;
1696 simError();
1697 }
1698
1699 info.k1 = atof( the_token );
1700
1701 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1702 sprintf( painCave.errMsg,
1703 "Error parseing BendTypes: line %d\n", lineNum );
1704 painCave.isFatal = 1;
1705 simError();
1706 }
1707
1708 info.k2 = atof( the_token );
1709
1710 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1711 sprintf( painCave.errMsg,
1712 "Error parseing BendTypes: line %d\n", lineNum );
1713 painCave.isFatal = 1;
1714 simError();
1715 }
1716
1717 info.k3 = atof( the_token );
1718
1719 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1720 sprintf( painCave.errMsg,
1721 "Error parseing BendTypes: line %d\n", lineNum );
1722 painCave.isFatal = 1;
1723 simError();
1724 }
1725
1726 info.t0 = atof( the_token );
1727 }
1728
1729 else{
1730 sprintf( painCave.errMsg,
1731 "Unknown DUFF bend type \"%s\" at line %d\n",
1732 info.type,
1733 lineNum );
1734 painCave.isFatal = 1;
1735 simError();
1736 }
1737
1738 return 1;
1739 }
1740 else return 0;
1741 }
1742
1743 int DUFF_NS::parseTorsion( char *lineBuffer, int lineNum, torsionStruct &info ){
1744
1745 char* the_token;
1746
1747 the_token = strtok( lineBuffer, " \n\t,;" );
1748 if( the_token != NULL ){
1749
1750 strcpy( info.nameA, the_token );
1751
1752 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1753 sprintf( painCave.errMsg,
1754 "Error parseing TorsionTypes: line %d\n", lineNum );
1755 painCave.isFatal = 1;
1756 simError();
1757 }
1758
1759 strcpy( info.nameB, the_token );
1760
1761 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1762 sprintf( painCave.errMsg,
1763 "Error parseing TorsionTypes: line %d\n", lineNum );
1764 painCave.isFatal = 1;
1765 simError();
1766 }
1767
1768 strcpy( info.nameC, the_token );
1769
1770 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1771 sprintf( painCave.errMsg,
1772 "Error parseing TorsionTypes: line %d\n", lineNum );
1773 painCave.isFatal = 1;
1774 simError();
1775 }
1776
1777 strcpy( info.nameD, the_token );
1778
1779 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1780 sprintf( painCave.errMsg,
1781 "Error parseing TorsionTypes: line %d\n", lineNum );
1782 painCave.isFatal = 1;
1783 simError();
1784 }
1785
1786 strcpy( info.type, the_token );
1787
1788 if( !strcmp( info.type, "cubic" ) ){
1789 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1790 sprintf( painCave.errMsg,
1791 "Error parseing TorsionTypes: line %d\n", lineNum );
1792 painCave.isFatal = 1;
1793 simError();
1794 }
1795
1796 info.k1 = atof( the_token );
1797
1798 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1799 sprintf( painCave.errMsg,
1800 "Error parseing TorsionTypes: line %d\n", lineNum );
1801 painCave.isFatal = 1;
1802 simError();
1803 }
1804
1805 info.k2 = atof( the_token );
1806
1807 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1808 sprintf( painCave.errMsg,
1809 "Error parseing TorsionTypes: line %d\n", lineNum );
1810 painCave.isFatal = 1;
1811 simError();
1812 }
1813
1814 info.k3 = atof( the_token );
1815
1816 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1817 sprintf( painCave.errMsg,
1818 "Error parseing TorsionTypes: line %d\n", lineNum );
1819 painCave.isFatal = 1;
1820 simError();
1821 }
1822
1823 info.k4 = atof( the_token );
1824
1825 }
1826
1827 else{
1828 sprintf( painCave.errMsg,
1829 "Unknown DUFF torsion type \"%s\" at line %d\n",
1830 info.type,
1831 lineNum );
1832 painCave.isFatal = 1;
1833 simError();
1834 }
1835
1836 return 1;
1837 }
1838
1839 else return 0;
1840 }