ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp
(Generate patch)

Comparing:
branches/mmeineke/mdtools/interface_implementation/TraPPE_ExFF.cpp (file contents), Revision 10 by mmeineke, Tue Jul 9 18:40:59 2002 UTC vs.
trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp (file contents), Revision 147 by mmeineke, Fri Oct 18 20:35:33 2002 UTC

# Line 9 | Line 9 | TraPPE_ExFF::TraPPE_ExFF(){
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];
# Line 16 | Line 77 | TraPPE_ExFF::TraPPE_ExFF(){
77    char* ffPath;
78    char temp[200];
79  
80 <  // generate the force file name
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 <  strcpy( fileName, "TraPPE_Ex.frc" );
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  
23  // attempt to open the file in the current directory first.
94    
25  frcFile = fopen( fileName, "r" );
95    
96 <  if( frcFile == NULL ){
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  
29    // next see if the force path enviorment variable is set
30    
31    ffPath = getenv( ffPath_env );
32    strcpy( temp, ffPath );
33    strcat( temp, "/" );
34    strcat( temp, fileName );
35    strcpy( fileName, temp );
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 <      fprintf( stderr,
193 <               "Error opening the force field parameter file: %s\n"
194 <               "Have you tried setting the FORCE_PARAM_PATH environment "
195 <               "vairable?\n",
196 <               fileName );
197 <      exit( 8 );
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 );
# Line 69 | Line 246 | void TraPPE_ExFF::initializeAtoms( void ){
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;
# Line 128 | Line 332 | void TraPPE_ExFF::initializeAtoms( void ){
332    the_atoms = entry_plug->atoms;
333    nAtoms = entry_plug->n_atoms;
334    
131  // read in the atom types.
132
133  rewind( frcFile );
134  headAtomType = new LinkedType;
135  currentAtomType = headAtomType;
335    
336 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
337 <  lineNum++;
338 <  if( eof_test == NULL ){
339 <    fprintf( stderr, "Error in reading Atoms from force file.\n" );
340 <    exit(8);
341 <  }
342 <
343 <  
344 <  while( !foundAtom ){
345 <    while( eof_test != NULL && readLine[0] != '#' ){
346 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
347 <      lineNum++;
149 <    }
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,
152 <               "Error in reading Atoms from force file at line %d.\n",
153 <               lineNum );
349 >      fprintf( stderr, "Error in reading Atoms from force file.\n" );
350        exit(8);
351      }
156
157    the_token = strtok( readLine, " ,;\t#\n" );
158    foundAtom = !strcmp( "AtomTypes", the_token );
352      
353 <    if( !foundAtom ){
354 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
355 <      lineNum++;
356 <
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 <      }
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      }
171  }
172
173  // we are now at the AtomTypes section.
174
175  eof_test = fgets( readLine, sizeof(readLine), frcFile );
176  lineNum++;
177  
178  if( eof_test == NULL ){
179    fprintf( stderr,
180             "Error in reading Atoms from force file at line %d.\n",
181             lineNum );
182    exit(8);
183  }
184
185  while( readLine[0] != '#' && eof_test != NULL ){
381      
382 <    if( readLine[0] != '!' ){
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 <      the_token = strtok( readLine, " \n\t,;" );
190 <      if( the_token != NULL ){
396 >      if( readLine[0] != '!' ){
397          
398 <        strcpy( currentAtomType->name, the_token );
399 <
400 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
401 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
402 <          exit(8);
197 <        }
198 <
199 <        sscanf( the_token, "%d", &currentAtomType->isDipole );
200 <
201 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
202 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
203 <          exit(8);
204 <        }
205 <
206 <        sscanf( the_token, "%lf", &currentAtomType->mass );
207 <
208 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
209 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
210 <          exit(8);
211 <        }
212 <        
213 <        sscanf( the_token, "%lf", &currentAtomType->epslon );
214 <        
215 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
216 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
217 <          exit(8);
218 <        }
219 <
220 <        sscanf( the_token, "%lf", &currentAtomType->sigma );
221 <        
222 <        if( currentAtomType->isDipole ){
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, "%lf", &currentAtomType->dipole );
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 <    tempAtomType = new LinkedType;
234 <    currentAtomType->next = tempAtomType;
235 <    currentAtomType = tempAtomType;
455 >    // listen for the structs
456      
237    eof_test = fgets( readLine, sizeof(readLine), frcFile );
238    lineNum++;
457    }
458 + #endif
459  
460    
461    // initialize the atoms
# Line 325 | Line 544 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
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];
# Line 517 | Line 759 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
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];
# Line 743 | Line 1016 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
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];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines