ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/TraPPE_ExFF.cpp
Revision: 420
Committed: Thu Mar 27 17:32:03 2003 UTC (21 years, 3 months ago) by mmeineke
File size: 42230 byte(s)
Log Message:
LJ_FF has been converted to the new Molecule model. TraPPE_Ex is currently being updated.
SimSetups routines are writtten, but not yet called.

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