ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp
Revision: 147
Committed: Fri Oct 18 20:35:33 2002 UTC (21 years, 9 months ago) by mmeineke
File size: 30137 byte(s)
Log Message:

more minor changes to the mpi structs

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