ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE_old/src/mdtools/libmdCode/TraPPE_ExFF.cpp
Revision: 270
Committed: Fri Feb 14 17:08:46 2003 UTC (21 years, 4 months ago) by mmeineke
File size: 37044 byte(s)
Log Message:
added libmdCode and a couple help scripts

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