ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE_old/src/mdtools/libmdCode/TraPPE_ExFF.cpp
Revision: 321
Committed: Wed Mar 12 15:12:24 2003 UTC (21 years, 3 months ago) by mmeineke
File size: 42109 byte(s)
Log Message:
added the force parameter files into the distribution

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