ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/UseTheForce/WATER.cpp
Revision: 1878
Committed: Thu Dec 9 23:09:17 2004 UTC (19 years, 9 months ago) by tim
File size: 27340 byte(s)
Log Message:
fix a bug in WATER.cpp when initializing the new Charge AtomType

File Contents

# Content
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include <iostream>
6 using namespace std;
7
8 #ifdef IS_MPI
9 #include <mpi.h>
10 #endif //is_mpi
11
12 #include "UseTheForce/ForceFields.hpp"
13 #include "primitives/SRI.hpp"
14 #include "utils/simError.h"
15 #include "types/AtomType.hpp"
16 #include "types/DirectionalAtomType.hpp"
17 #include "UseTheForce/DarkSide/lj_interface.h"
18 #include "UseTheForce/DarkSide/charge_interface.h"
19 #include "UseTheForce/DarkSide/dipole_interface.h"
20 #include "UseTheForce/DarkSide/sticky_interface.h"
21
22 #ifdef IS_MPI
23 #include "UseTheForce/mpiForceField.h"
24 #endif // is_mpi
25
26
27
28 namespace WATER_NS{
29
30 // Declare the structures that will be passed by the parser and MPI
31
32 typedef struct{
33 char name[15];
34 double mass;
35 double epslon;
36 double sigma;
37 double charge;
38 int isDirectional;
39 int isLJ;
40 int isCharge;
41 int ident;
42 int last; // 0 -> default
43 // 1 -> in MPI: tells nodes to stop listening
44 } atomStruct;
45
46 typedef struct{
47 char name[15];
48 double Ixx;
49 double Iyy;
50 double Izz;
51 double dipole;
52 double w0;
53 double v0;
54 double v0p;
55 double rl;
56 double ru;
57 double rlp;
58 double rup;
59 int isDipole;
60 int isSticky;
61 int last; // 0 -> default
62 // 1 -> in MPI: tells nodes to stop listening
63 } directionalStruct;
64
65 int parseAtom( char *lineBuffer, int lineNum, atomStruct &info );
66 int parseDirectional( char *lineBuffer, int lineNum, directionalStruct &info );
67
68
69 #ifdef IS_MPI
70
71 MPI_Datatype mpiAtomStructType;
72 MPI_Datatype mpiDirectionalStructType;
73
74 #endif
75
76 class LinkedAtomType {
77 public:
78 LinkedAtomType(){
79 next = NULL;
80 name[0] = '\0';
81 }
82 ~LinkedAtomType(){ if( next != NULL ) delete next; }
83
84 LinkedAtomType* find(char* key){
85 if( !strcmp(name, key) ) return this;
86 if( next != NULL ) return next->find(key);
87 return NULL;
88 }
89
90
91 void add( atomStruct &info ){
92
93 // check for duplicates
94
95 if( !strcmp( info.name, name ) ){
96 sprintf( painCave.errMsg,
97 "Duplicate WATER atom type \"%s\" found in "
98 "the WATER param file./n",
99 name );
100 painCave.isFatal = 1;
101 simError();
102 }
103
104 if( next != NULL ) next->add(info);
105 else{
106 next = new LinkedAtomType();
107 strcpy(next->name, info.name);
108 next->isDirectional = info.isDirectional;
109 next->isLJ = info.isLJ;
110 next->isCharge = info.isCharge;
111 next->mass = info.mass;
112 next->epslon = info.epslon;
113 next->sigma = info.sigma;
114 next->charge = info.charge;
115 next->ident = info.ident;
116 }
117 }
118
119 #ifdef IS_MPI
120
121 void duplicate( atomStruct &info ){
122 strcpy(info.name, name);
123 info.isDirectional = isDirectional;
124 info.isLJ = isLJ;
125 info.isCharge = isCharge;
126 info.mass = mass;
127 info.epslon = epslon;
128 info.sigma = sigma;
129 info.charge = charge;
130 info.ident = ident;
131 info.last = 0;
132 }
133
134 #endif
135
136 char name[15];
137 int isDirectional;
138 int isLJ;
139 int isCharge;
140 double mass;
141 double epslon;
142 double sigma;
143 double charge;
144 int ident;
145 LinkedAtomType* next;
146 };
147
148 class LinkedDirectionalType {
149 public:
150 LinkedDirectionalType(){
151 next = NULL;
152 name[0] = '\0';
153 }
154 ~LinkedDirectionalType(){ if( next != NULL ) delete next; }
155
156 LinkedDirectionalType* find(char* key){
157 if( !strcmp(name, key) ) return this;
158 if( next != NULL ) return next->find(key);
159 return NULL;
160 }
161
162
163 void add( directionalStruct &info ){
164
165 // check for duplicates
166
167 if( !strcmp( info.name, name ) ){
168 sprintf( painCave.errMsg,
169 "Duplicate WATER directional type \"%s\" found in "
170 "the WATER param file./n",
171 name );
172 painCave.isFatal = 1;
173 simError();
174 }
175
176 if( next != NULL ) next->add(info);
177 else{
178 next = new LinkedDirectionalType();
179 strcpy(next->name, info.name);
180 next->isDipole = info.isDipole;
181 next->isSticky = info.isSticky;
182 next->Ixx = info.Ixx;
183 next->Iyy = info.Iyy;
184 next->Izz = info.Izz;
185 next->dipole = info.dipole;
186 next->w0 = info.w0;
187 next->v0 = info.v0;
188 next->v0p = info.v0p;
189 next->rl = info.rl;
190 next->ru = info.ru;
191 next->rlp = info.rlp;
192 next->rup = info.rup;
193 }
194 }
195
196 #ifdef IS_MPI
197
198 void duplicate( directionalStruct &info ){
199 strcpy(info.name, name);
200 info.isDipole = isDipole;
201 info.isSticky = isSticky;
202 info.Ixx = Ixx;
203 info.Iyy = Iyy;
204 info.Izz = Izz;
205 info.dipole = dipole;
206 info.w0 = w0;
207 info.v0 = v0;
208 info.v0p = v0p;
209 info.rl = rl;
210 info.ru = ru;
211 info.rlp = rlp;
212 info.rup = rup;
213 info.last = 0;
214 }
215
216 #endif
217
218 char name[15];
219 int isDipole;
220 int isSticky;
221 double Ixx;
222 double Iyy;
223 double Izz;
224 double dipole;
225 double w0;
226 double v0;
227 double v0p;
228 double rl;
229 double ru;
230 double rlp;
231 double rup;
232 LinkedDirectionalType* next;
233 };
234
235 LinkedAtomType* headAtomType;
236 LinkedAtomType* currentAtomType;
237 LinkedDirectionalType* headDirectionalType;
238 LinkedDirectionalType* currentDirectionalType;
239 } // namespace
240
241 using namespace WATER_NS;
242
243 //****************************************************************
244 // begins the actual forcefield stuff.
245 //****************************************************************
246
247
248 WATER::WATER(){
249
250 string fileName;
251 string tempString;
252
253 headAtomType = NULL;
254 currentAtomType = NULL;
255 headDirectionalType = NULL;
256 currentDirectionalType = NULL;
257
258 #ifdef IS_MPI
259 int i;
260
261 // **********************************************************************
262 // Init the atomStruct mpi type
263
264 atomStruct atomProto; // mpiPrototype
265 int atomBC[3] = {15,4,5}; // block counts
266 MPI_Aint atomDspls[3]; // displacements
267 MPI_Datatype atomMbrTypes[3]; // member mpi types
268
269 MPI_Address(&atomProto.name, &atomDspls[0]);
270 MPI_Address(&atomProto.mass, &atomDspls[1]);
271 MPI_Address(&atomProto.isDirectional, &atomDspls[2]);
272
273 atomMbrTypes[0] = MPI_CHAR;
274 atomMbrTypes[1] = MPI_DOUBLE;
275 atomMbrTypes[2] = MPI_INT;
276
277 for (i=2; i >= 0; i--) atomDspls[i] -= atomDspls[0];
278
279 MPI_Type_struct(3, atomBC, atomDspls, atomMbrTypes, &mpiAtomStructType);
280 MPI_Type_commit(&mpiAtomStructType);
281
282 // ***********************************************************************
283
284 // **********************************************************************
285 // Init the directionalStruct mpi type
286
287 directionalStruct directionalProto; // mpiPrototype
288 int directionalBC[3] = {15,11,3}; // block counts
289 MPI_Aint directionalDspls[3]; // displacements
290 MPI_Datatype directionalMbrTypes[3]; // member mpi types
291
292 MPI_Address(&directionalProto.name, &directionalDspls[0]);
293 MPI_Address(&directionalProto.Ixx, &directionalDspls[1]);
294 MPI_Address(&directionalProto.isDipole, &directionalDspls[2]);
295
296 directionalMbrTypes[0] = MPI_CHAR;
297 directionalMbrTypes[1] = MPI_DOUBLE;
298 directionalMbrTypes[2] = MPI_INT;
299
300 for (i=2; i >= 0; i--) directionalDspls[i] -= directionalDspls[0];
301
302 MPI_Type_struct(3, directionalBC, directionalDspls, directionalMbrTypes,
303 &mpiDirectionalStructType);
304 MPI_Type_commit(&mpiDirectionalStructType);
305
306 // ***********************************************************************
307
308 if( worldRank == 0 ){
309 #endif
310
311 // generate the force file name
312
313 fileName = "WATER.frc";
314
315 // fprintf( stderr,"Trying to open %s\n", fileName );
316
317 // attempt to open the file in the current directory first.
318
319 frcFile = fopen( fileName.c_str(), "r" );
320
321 if( frcFile == NULL ){
322
323 tempString = ffPath + "/" + fileName;
324 fileName = tempString;
325
326 frcFile = fopen( fileName.c_str(), "r" );
327
328 if( frcFile == NULL ){
329
330 sprintf( painCave.errMsg,
331 "Error opening the force field parameter file:\n"
332 "\t%s\n"
333 "\tHave you tried setting the FORCE_PARAM_PATH environment "
334 "variable?\n",
335 fileName.c_str() );
336 painCave.severity = OOPSE_ERROR;
337 painCave.isFatal = 1;
338 simError();
339 }
340 }
341
342 #ifdef IS_MPI
343 }
344
345 sprintf( checkPointMsg, "WATER file opened sucessfully." );
346 MPIcheckPoint();
347
348 #endif // is_mpi
349 }
350
351
352 WATER::~WATER(){
353
354 if( headAtomType != NULL ) delete headAtomType;
355 if( headDirectionalType != NULL ) delete headDirectionalType;
356
357 #ifdef IS_MPI
358 if( worldRank == 0 ){
359 #endif // is_mpi
360
361 fclose( frcFile );
362
363 #ifdef IS_MPI
364 }
365 #endif // is_mpi
366 }
367
368 void WATER::cleanMe( void ){
369
370 #ifdef IS_MPI
371
372 // keep the linked list in the mpi version
373
374 #else // is_mpi
375
376 // delete the linked list in the single processor version
377
378 if( headAtomType != NULL ) delete headAtomType;
379 if( headDirectionalType != NULL ) delete headDirectionalType;
380
381 #endif // is_mpi
382 }
383
384
385 void WATER::initForceField(){
386
387 initFortran(entry_plug->useReactionField );
388 }
389
390
391 void WATER::readParams( void ){
392
393 int identNum, isError;
394 int tempDirect0, tempDirect1;
395
396 atomStruct atomInfo;
397 directionalStruct directionalInfo;
398 fpos_t *atomPos;
399 AtomType* at;
400
401 atomInfo.last = 1; // initialize last to have the last set.
402 directionalInfo.last = 1; // if things go well, last will be set to 0
403
404 atomPos = new fpos_t;
405 bigSigma = 0.0;
406
407 #ifdef IS_MPI
408 if( worldRank == 0 ){
409 #endif
410
411 // read in the atom types.
412
413 headAtomType = new LinkedAtomType;
414 headDirectionalType = new LinkedDirectionalType;
415
416 fastForward( "AtomTypes", "initializeAtoms" );
417
418 // we are now at the AtomTypes section.
419
420 eof_test = fgets( readLine, sizeof(readLine), frcFile );
421 lineNum++;
422
423
424 // read a line, and start parsing out the atom types
425
426 if( eof_test == NULL ){
427 sprintf( painCave.errMsg,
428 "Error in reading Atoms from force file at line %d.\n",
429 lineNum );
430 painCave.isFatal = 1;
431 simError();
432 }
433
434 identNum = 1;
435 // stop reading at end of file, or at next section
436 while( readLine[0] != '#' && eof_test != NULL ){
437
438 // toss comment lines
439 if( readLine[0] != '!' ){
440
441 // the parser returns 0 if the line was blank
442 if( parseAtom( readLine, lineNum, atomInfo ) ){
443 atomInfo.ident = identNum;
444 headAtomType->add( atomInfo );
445 if ( atomInfo.isDirectional ) {
446
447 // if the atom is directional, skip to the directional section
448 // and parse directional info.
449 fgetpos( frcFile, atomPos );
450 sectionSearch( "DirectionalTypes", atomInfo.name,
451 "initializeDirectional" );
452 parseDirectional( readLine, lineNum, directionalInfo );
453 headDirectionalType->add( directionalInfo );
454
455 // return to the AtomTypes section
456 fsetpos( frcFile, atomPos );
457 }
458 identNum++;
459 }
460 }
461 eof_test = fgets( readLine, sizeof(readLine), frcFile );
462 lineNum++;
463 }
464
465 #ifdef IS_MPI
466
467 // send out the linked list to all the other processes
468
469 sprintf( checkPointMsg,
470 "WATER atom and directional structures read successfully." );
471 MPIcheckPoint();
472 currentAtomType = headAtomType->next; //skip the first element place holder
473 currentDirectionalType = headDirectionalType->next; // same w/ directional
474
475 while( currentAtomType != NULL ){
476 currentAtomType->duplicate( atomInfo );
477
478 sendFrcStruct( &atomInfo, mpiAtomStructType );
479
480 sprintf( checkPointMsg,
481 "successfully sent WATER force type: \"%s\"\n",
482 atomInfo.name );
483
484 if ( atomInfo.isDirectional ){
485 // send out the directional linked list to all the other processes
486
487 currentDirectionalType->duplicate( directionalInfo );
488 sendFrcStruct( &directionalInfo, mpiDirectionalStructType );
489
490 sprintf( checkPointMsg,
491 "successfully sent WATER directional type: \"%s\"\n",
492 directionalInfo.name );
493 }
494
495 MPIcheckPoint();
496 tempDirect0 = atomInfo.isDirectional;
497 currentAtomType = currentAtomType->next;
498 if( tempDirect0 )
499 currentDirectionalType = currentDirectionalType->next;
500 }
501
502 atomInfo.last = 1;
503 sendFrcStruct( &atomInfo, mpiAtomStructType );
504 directionalInfo.last = 1;
505 if ( atomInfo.isDirectional )
506 sendFrcStruct( &directionalInfo, mpiDirectionalStructType );
507 }
508
509 else{
510 // listen for node 0 to send out the force params
511
512 MPIcheckPoint();
513
514 headAtomType = new LinkedAtomType;
515 headDirectionalType = new LinkedDirectionalType;
516 receiveFrcStruct( &atomInfo, mpiAtomStructType );
517
518 if ( atomInfo.isDirectional )
519 receiveFrcStruct( &directionalInfo, mpiDirectionalStructType );
520
521 while( !atomInfo.last ){
522
523 headAtomType->add( atomInfo );
524
525 MPIcheckPoint();
526
527 receiveFrcStruct( &atomInfo, mpiAtomStructType );
528
529 if( atomInfo.isDirectional ){
530 headDirectionalType->add( directionalInfo );
531
532 receiveFrcStruct( &directionalInfo, mpiDirectionalStructType );
533 }
534 }
535 }
536
537 #endif // is_mpi
538
539 // dummy variables
540
541 currentAtomType = headAtomType->next;
542 currentDirectionalType = headDirectionalType->next;
543
544 while( currentAtomType != NULL ){
545 if( currentAtomType->name[0] != '\0' ){
546 if (currentAtomType->isDirectional)
547 at = new DirectionalAtomType();
548 else
549 at = new AtomType();
550
551 if (currentAtomType->isLJ) {
552 at->setLennardJones();
553 }
554
555 if (currentAtomType->isCharge) {
556 at->setCharge();
557 }
558
559 if (currentAtomType->isDirectional) {
560 if (currentDirectionalType->isDipole) {
561 ((DirectionalAtomType*)at)->setDipole();
562 }
563
564 if (currentDirectionalType->isSticky) {
565 ((DirectionalAtomType*)at)->setSticky();
566 }
567 }
568
569 at->setIdent(currentAtomType->ident);
570 at->setName(currentAtomType->name);
571 at->complete();
572 }
573 currentAtomType = currentAtomType->next;
574 }
575
576 currentAtomType = headAtomType->next;
577 currentDirectionalType = headDirectionalType->next;
578
579 while( currentAtomType != NULL ){
580
581 currentDirectionalType = headDirectionalType->find(currentAtomType->name);
582
583 if( currentAtomType->isLJ ){
584 isError = 0;
585 newLJtype( &(currentAtomType->ident), &(currentAtomType->sigma),
586 &(currentAtomType->epslon), &isError);
587 if( isError ){
588 sprintf( painCave.errMsg,
589 "Error initializing the \"%s\" LJ type in fortran\n",
590 currentAtomType->name );
591 painCave.isFatal = 1;
592 simError();
593 }
594 }
595
596 if (currentAtomType->isCharge) {
597 newChargeType(&(currentAtomType->ident), &(currentAtomType->charge),
598 &isError);
599 if( isError ){
600 sprintf( painCave.errMsg,
601 "Error initializing the \"%s\" charge type in fortran\n",
602 currentAtomType->name );
603 painCave.isFatal = 1;
604 simError();
605 }
606 }
607
608 if (currentAtomType->isDirectional){
609 if (currentDirectionalType->isDipole) {
610 newDipoleType(&(currentAtomType->ident),
611 &(currentDirectionalType->dipole),
612 &isError);
613 if( isError ){
614 sprintf( painCave.errMsg,
615 "Error initializing the \"%s\" dipole type in fortran\n",
616 currentDirectionalType->name );
617 painCave.isFatal = 1;
618 simError();
619 }
620 }
621
622 if(currentDirectionalType->isSticky) {
623 makeStickyType( &(currentDirectionalType->w0),
624 &(currentDirectionalType->v0),
625 &(currentDirectionalType->v0p),
626 &(currentDirectionalType->rl),
627 &(currentDirectionalType->ru),
628 &(currentDirectionalType->rlp),
629 &(currentDirectionalType->rup));
630 }
631 }
632 currentAtomType = currentAtomType->next;
633 }
634
635 #ifdef IS_MPI
636 sprintf( checkPointMsg,
637 "WATER atom and directional structures successfully"
638 "sent to fortran\n" );
639 MPIcheckPoint();
640 #endif // is_mpi
641
642 }
643
644
645 void WATER::initializeAtoms( int nAtoms, Atom** the_atoms ){
646
647 int i,j,k;
648
649 // initialize the atoms
650 DirectionalAtom* dAtom;
651 double ji[3];
652 double inertialMat[3][3];
653
654 for( i=0; i<nAtoms; i++ ){
655 currentAtomType = headAtomType->find( the_atoms[i]->getType() );
656 if( currentAtomType == NULL ){
657 sprintf( painCave.errMsg,
658 "AtomType error, %s not found in force file.\n",
659 the_atoms[i]->getType() );
660 painCave.isFatal = 1;
661 simError();
662 }
663 the_atoms[i]->setMass( currentAtomType->mass );
664 the_atoms[i]->setIdent( currentAtomType->ident );
665
666 if (currentAtomType->isLJ) entry_plug->useLennardJones = 1;
667 if (currentAtomType->isCharge) entry_plug->useCharges = 1;
668 if (currentAtomType->isDirectional) {
669 if (currentDirectionalType->isDipole) entry_plug->useDipoles = 1;
670 if (currentDirectionalType->isSticky) entry_plug->useSticky = 1;
671 }
672
673 if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma;
674
675 the_atoms[i]->setHasCharge(currentAtomType->isCharge);
676
677 if( currentAtomType->isDirectional ){
678 currentDirectionalType =
679 headDirectionalType->find( the_atoms[i]->getType() );
680 if( currentDirectionalType == NULL ){
681 sprintf( painCave.errMsg,
682 "DirectionalType error, %s not found in force file.\n",
683 the_atoms[i]->getType() );
684 painCave.isFatal = 1;
685 simError();
686 }
687
688 // zero out the moments of inertia matrix
689 for( j=0; j<3; j++ )
690 for( k=0; k<3; k++ )
691 inertialMat[j][k] = 0.0;
692
693 // load the force file moments of inertia
694 inertialMat[0][0] = currentDirectionalType->Ixx;
695 inertialMat[1][1] = currentDirectionalType->Iyy;
696 inertialMat[2][2] = currentDirectionalType->Izz;
697
698 dAtom = (DirectionalAtom *) the_atoms[i];
699 dAtom->setHasDipole( currentDirectionalType->isDipole );
700
701 ji[0] = 0.0;
702 ji[1] = 0.0;
703 ji[2] = 0.0;
704 dAtom->setJ( ji );
705 dAtom->setI( inertialMat );
706
707 entry_plug->n_dipoles++;
708 }
709 }
710 }
711
712 void WATER::initializeBonds( int nBonds, Bond** BondArray,
713 bond_pair* the_bonds ){
714
715 if( nBonds ){
716 sprintf( painCave.errMsg,
717 "WATER does not support bonds.\n" );
718 painCave.isFatal = 1;
719 simError();
720 }
721 }
722
723 void WATER::initializeBends( int nBends, Bend** bendArray,
724 bend_set* the_bends ){
725
726 if( nBends ){
727 sprintf( painCave.errMsg,
728 "WATER does not support bends.\n" );
729 painCave.isFatal = 1;
730 simError();
731 }
732 }
733
734 void WATER::initializeTorsions( int nTorsions, Torsion** torsionArray,
735 torsion_set* the_torsions ){
736
737 if( nTorsions ){
738 sprintf( painCave.errMsg,
739 "WATER does not support torsions.\n" );
740 painCave.isFatal = 1;
741 simError();
742 }
743 }
744
745 void WATER::fastForward( char* stopText, char* searchOwner ){
746
747 int foundText = 0;
748 char* the_token;
749
750 rewind( frcFile );
751 lineNum = 0;
752
753 eof_test = fgets( readLine, sizeof(readLine), frcFile );
754 lineNum++;
755 if( eof_test == NULL ){
756 sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
757 " file is empty.\n",
758 searchOwner );
759 painCave.isFatal = 1;
760 simError();
761 }
762
763
764 while( !foundText ){
765 while( eof_test != NULL && readLine[0] != '#' ){
766 eof_test = fgets( readLine, sizeof(readLine), frcFile );
767 lineNum++;
768 }
769 if( eof_test == NULL ){
770 sprintf( painCave.errMsg,
771 "Error fast forwarding force file for %s at "
772 "line %d: file ended unexpectedly.\n",
773 searchOwner,
774 lineNum );
775 painCave.isFatal = 1;
776 simError();
777 }
778
779 the_token = strtok( readLine, " ,;\t#\n" );
780 foundText = !strcmp( stopText, the_token );
781
782 if( !foundText ){
783 eof_test = fgets( readLine, sizeof(readLine), frcFile );
784 lineNum++;
785
786 if( eof_test == NULL ){
787 sprintf( painCave.errMsg,
788 "Error fast forwarding force file for %s at "
789 "line %d: file ended unexpectedly.\n",
790 searchOwner,
791 lineNum );
792 painCave.isFatal = 1;
793 simError();
794 }
795 }
796 }
797 }
798
799 void WATER::sectionSearch( char* secHead, char* stopText, char* searchOwner ){
800
801 int foundSection = 0;
802 int foundText = 0;
803 char* the_token;
804 fpos_t *tempPos;
805
806 rewind( frcFile );
807 lineNum = 0;
808 tempPos = new fpos_t;
809
810 eof_test = fgets( readLine, sizeof(readLine), frcFile );
811 lineNum++;
812 if( eof_test == NULL ){
813 sprintf( painCave.errMsg, "Error fast forwarding force file for %s: "
814 " file is empty.\n",
815 searchOwner );
816 painCave.isFatal = 1;
817 simError();
818 }
819
820 while( !foundSection ){
821 while( eof_test != NULL && readLine[0] != '#' ){
822 eof_test = fgets( readLine, sizeof(readLine), frcFile );
823 lineNum++;
824 }
825 if( eof_test == NULL ){
826 sprintf( painCave.errMsg,
827 "Error fast forwarding force file for %s at "
828 "line %d: file ended unexpectedly.\n",
829 searchOwner,
830 lineNum );
831 painCave.isFatal = 1;
832 simError();
833 }
834 the_token = strtok( readLine, " ,;\t#\n" );
835 foundSection = !strcmp( secHead, the_token );
836
837 if( !foundSection ){
838 eof_test = fgets( readLine, sizeof(readLine), frcFile );
839 lineNum++;
840
841 if( eof_test == NULL ){
842 sprintf( painCave.errMsg,
843 "Error section searching force file for %s at "
844 "line %d: file ended unexpectedly.\n",
845 searchOwner,
846 lineNum );
847 painCave.isFatal = 1;
848 simError();
849 }
850 }
851 }
852
853 while( !foundText ){
854
855 fgetpos( frcFile, tempPos );
856 eof_test = fgets( readLine, sizeof(readLine), frcFile );
857 lineNum++;
858
859 if( eof_test == NULL ){
860 sprintf( painCave.errMsg,
861 "Error fast forwarding force file for %s at "
862 "line %d: file ended unexpectedly.\n",
863 searchOwner,
864 lineNum );
865 painCave.isFatal = 1;
866 simError();
867 }
868
869 the_token = strtok( readLine, " ,;\t#\n" );
870 if( the_token != NULL ){
871 foundText = !strcmp( stopText, the_token );
872 }
873 }
874 fsetpos( frcFile, tempPos );
875 eof_test = fgets( readLine, sizeof(readLine), frcFile );
876 lineNum++;
877 }
878
879
880 int WATER_NS::parseAtom( char *lineBuffer, int lineNum, atomStruct &info ){
881
882 char* the_token;
883
884 the_token = strtok( lineBuffer, " \n\t,;" );
885 if( the_token != NULL ){
886
887 strcpy( info.name, the_token );
888
889 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
890 sprintf( painCave.errMsg,
891 "Error parseing AtomTypes: line %d\n", lineNum );
892 painCave.isFatal = 1;
893 simError();
894 }
895
896 info.isDirectional = atoi( the_token );
897
898 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
899 sprintf( painCave.errMsg,
900 "Error parseing AtomTypes: line %d\n", lineNum );
901 painCave.isFatal = 1;
902 simError();
903 }
904
905 info.isLJ = atoi( the_token );
906
907 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
908 sprintf( painCave.errMsg,
909 "Error parseing AtomTypes: line %d\n", lineNum );
910 painCave.isFatal = 1;
911 simError();
912 }
913
914 info.isCharge = atoi( the_token );
915
916 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
917 sprintf( painCave.errMsg,
918 "Error parseing AtomTypes: line %d\n", lineNum );
919 painCave.isFatal = 1;
920 simError();
921 }
922
923 info.mass = atof( the_token );
924
925 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
926 sprintf( painCave.errMsg,
927 "Error parseing AtomTypes: line %d\n", lineNum );
928 painCave.isFatal = 1;
929 simError();
930 }
931
932 info.epslon = atof( the_token );
933
934 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
935 sprintf( painCave.errMsg,
936 "Error parseing AtomTypes: line %d\n", lineNum );
937 painCave.isFatal = 1;
938 simError();
939 }
940
941 info.sigma = atof( the_token );
942
943 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
944 sprintf( painCave.errMsg,
945 "Error parseing AtomTypes: line %d\n", lineNum );
946 painCave.isFatal = 1;
947 simError();
948 }
949
950 info.charge = atof( the_token );
951
952 return 1;
953 }
954 else return 0;
955 }
956
957 int WATER_NS::parseDirectional( char *lineBuffer, int lineNum, directionalStruct &info ){
958
959 char* the_token;
960
961 the_token = strtok( lineBuffer, " \n\t,;" );
962 if( the_token != NULL ){
963
964 strcpy( info.name, the_token );
965
966 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
967 sprintf( painCave.errMsg,
968 "Error parseing DirectionalTypes: line %d\n", lineNum );
969 painCave.isFatal = 1;
970 simError();
971 }
972
973 info.isDipole = atoi( the_token );
974
975 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
976 sprintf( painCave.errMsg,
977 "Error parseing DirectionalTypes: line %d\n", lineNum );
978 painCave.isFatal = 1;
979 simError();
980 }
981
982 info.isSticky = atoi( the_token );
983
984 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
985 sprintf( painCave.errMsg,
986 "Error parseing DirectionalTypes: line %d\n", lineNum );
987 painCave.isFatal = 1;
988 simError();
989 }
990
991 info.Ixx = atof( the_token );
992
993 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
994 sprintf( painCave.errMsg,
995 "Error parseing DirectionalTypes: line %d\n", lineNum );
996 painCave.isFatal = 1;
997 simError();
998 }
999
1000 info.Iyy = atof( the_token );
1001
1002 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1003 sprintf( painCave.errMsg,
1004 "Error parseing DirectionalTypes: line %d\n", lineNum );
1005 painCave.isFatal = 1;
1006 simError();
1007 }
1008
1009 info.Izz = atof( the_token );
1010
1011 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1012 sprintf( painCave.errMsg,
1013 "Error parseing DirectionalTypes: line %d\n", lineNum );
1014 painCave.isFatal = 1;
1015 simError();
1016 }
1017
1018
1019 info.dipole = atof( the_token );
1020
1021 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1022 sprintf( painCave.errMsg,
1023 "Error parseing DirectionalTypes: line %d\n", lineNum );
1024 painCave.isFatal = 1;
1025 simError();
1026 }
1027
1028 info.w0 = atof( the_token );
1029
1030 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1031 sprintf( painCave.errMsg,
1032 "Error parseing DirectionalTypes: line %d\n", lineNum );
1033 painCave.isFatal = 1;
1034 simError();
1035 }
1036
1037 info.v0 = atof( the_token );
1038
1039 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1040 sprintf( painCave.errMsg,
1041 "Error parseing DirectionalTypes: line %d\n", lineNum );
1042 painCave.isFatal = 1;
1043 simError();
1044 }
1045
1046 info.v0p = atof( the_token );
1047
1048 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1049 sprintf( painCave.errMsg,
1050 "Error parseing DirectionalTypes: line %d\n", lineNum );
1051 painCave.isFatal = 1;
1052 simError();
1053 }
1054
1055 info.rl = atof( the_token );
1056
1057 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1058 sprintf( painCave.errMsg,
1059 "Error parseing DirectionalTypes: line %d\n", lineNum );
1060 painCave.isFatal = 1;
1061 simError();
1062 }
1063
1064 info.ru = atof( the_token );
1065
1066 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1067 sprintf( painCave.errMsg,
1068 "Error parseing DirectionalTypes: line %d\n", lineNum );
1069 painCave.isFatal = 1;
1070 simError();
1071 }
1072
1073 info.rlp = atof( the_token );
1074
1075 if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
1076 sprintf( painCave.errMsg,
1077 "Error parseing DirectionalTypes: line %d\n", lineNum );
1078 painCave.isFatal = 1;
1079 simError();
1080 }
1081
1082 info.rup = atof( the_token );
1083
1084 return 1;
1085 }
1086 else return 0;
1087 }