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

Comparing trunk/OOPSE/libmdtools/TraPPE_ExFF.cpp (file contents):
Revision 394 by gezelter, Mon Mar 24 21:55:34 2003 UTC vs.
Revision 442 by mmeineke, Wed Apr 2 15:01:06 2003 UTC

# Line 85 | Line 85 | namespace TPE {  // restrict the access of the folowin
85  
86   #endif
87  
88 +  class LinkedAtomType {
89 +  public:
90 +    LinkedAtomType(){
91 +      next = NULL;
92 +      name[0] = '\0';
93 +    }
94 +    ~LinkedAtomType(){ if( next != NULL ) delete next; }
95 +
96 +    LinkedAtomType* find(char* key){
97 +      if( !strcmp(name, key) ) return this;
98 +      if( next != NULL ) return next->find(key);
99 +      return NULL;
100 +    }
101 +    
102 +    void printMe( void ){
103 +      
104 +      std::cerr << "LinkedAtype " << name << ": ident = " << ident << "\n";
105 +      if( next != NULL ) next->printMe();
106 +
107 +    }
108 +
109 +    void add( atomStruct &info ){
110 +
111 +      // check for duplicates
112 +      
113 +      if( !strcmp( info.name, name ) ){
114 +        sprintf( painCave.errMsg,
115 +                 "Duplicate TraPPE_Ex atom type \"%s\" found in "
116 +                 "the TraPPE_ExFF param file./n",
117 +                 name );
118 +        painCave.isFatal = 1;
119 +        simError();
120 +      }
121 +
122 +      if( next != NULL ) next->add(info);
123 +      else{
124 +        next = new LinkedAtomType();
125 +        strcpy(next->name, info.name);
126 +        next->isDipole = info.isDipole;
127 +        next->isSSD    = info.isSSD;
128 +        next->mass     = info.mass;
129 +        next->epslon   = info.epslon;
130 +        next->sigma    = info.sigma;
131 +        next->dipole   = info.dipole;
132 +        next->w0       = info.w0;
133 +        next->v0       = info.v0;
134 +        next->ident    = info.ident;
135 +      }
136 +    }
137 +
138 + #ifdef IS_MPI
139 +    
140 +    void duplicate( atomStruct &info ){
141 +      strcpy(info.name, name);
142 +      info.isDipole = isDipole;
143 +      info.isSSD    = isSSD;
144 +      info.mass     = mass;
145 +      info.epslon   = epslon;
146 +      info.sigma    = sigma;
147 +      info.dipole   = dipole;
148 +      info.w0       = w0;
149 +      info.v0       = v0;
150 +      info.ident    = ident;
151 +      info.last     = 0;
152 +    }
153 +
154 +
155 + #endif
156 +
157 +    char name[15];
158 +    int isDipole;
159 +    int isSSD;
160 +    double mass;
161 +    double epslon;
162 +    double sigma;
163 +    double dipole;
164 +    double w0;
165 +    double v0;
166 +    int ident;
167 +    LinkedAtomType* next;
168 +  };
169 +
170 +  class LinkedBondType {
171 +  public:
172 +    LinkedBondType(){
173 +      next = NULL;
174 +      nameA[0] = '\0';
175 +      nameB[0] = '\0';
176 +      type[0] = '\0';
177 +    }
178 +    ~LinkedBondType(){ if( next != NULL ) delete next; }
179 +
180 +    LinkedBondType* find(char* key1, char* key2){
181 +      if( !strcmp(nameA, key1 ) && !strcmp( nameB, key2 ) ) return this;
182 +      if( !strcmp(nameA, key2 ) && !strcmp( nameB, key1 ) ) return this;
183 +      if( next != NULL ) return next->find(key1, key2);
184 +      return NULL;
185 +    }
186 +    
187 +
188 +    void add( bondStruct &info ){
189 +      
190 +      // check for duplicates
191 +      int dup = 0;
192 +
193 +      if( !strcmp(nameA, info.nameA ) && !strcmp( nameB, info.nameB ) ) dup = 1;
194 +      if( !strcmp(nameA, info.nameB ) && !strcmp( nameB, info.nameA ) ) dup = 1;
195 +      
196 +      if(dup){
197 +        sprintf( painCave.errMsg,
198 +                 "Duplicate TraPPE_Ex bond type \"%s - %s\" found in "
199 +                 "the TraPPE_ExFF param file./n",
200 +                 nameA, nameB );
201 +        painCave.isFatal = 1;
202 +        simError();
203 +      }
204 +
205 +        
206 +      if( next != NULL ) next->add(info);
207 +      else{
208 +        next = new LinkedBondType();
209 +        strcpy(next->nameA, info.nameA);
210 +        strcpy(next->nameB, info.nameB);
211 +        strcpy(next->type,  info.type);
212 +        next->d0 = info.d0;
213 +      }
214 +    }
215 +    
216 + #ifdef IS_MPI
217 +    void duplicate( bondStruct &info ){
218 +      strcpy(info.nameA, nameA);
219 +      strcpy(info.nameB, nameB);
220 +      strcpy(info.type,  type);
221 +      info.d0   = d0;
222 +      info.last = 0;
223 +    }
224 +
225 +
226 + #endif
227 +
228 +    char nameA[15];
229 +    char nameB[15];
230 +    char type[30];
231 +    double d0;
232 +
233 +    LinkedBondType* next;
234 +  };
235 +
236 +  class LinkedBendType {
237 +  public:
238 +    LinkedBendType(){
239 +      next = NULL;
240 +      nameA[0] = '\0';
241 +      nameB[0] = '\0';
242 +      nameC[0] = '\0';
243 +      type[0] = '\0';
244 +    }
245 +    ~LinkedBendType(){ if( next != NULL ) delete next; }
246 +
247 +    LinkedBendType* find( char* key1, char* key2, char* key3 ){
248 +      if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 )
249 +          && !strcmp( nameC, key3 ) ) return this;
250 +      if( !strcmp( nameA, key3 ) && !strcmp( nameB, key2 )
251 +          && !strcmp( nameC, key1 ) ) return this;
252 +      if( next != NULL ) return next->find(key1, key2, key3);
253 +      return NULL;
254 +    }
255 +    
256 +    void add( bendStruct &info ){
257 +
258 +      // check for duplicates
259 +      int dup = 0;
260 +      
261 +      if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB )
262 +          && !strcmp( nameC, info.nameC ) ) dup = 1;
263 +      if( !strcmp( nameA, info.nameC ) && !strcmp( nameB, info.nameB )
264 +          && !strcmp( nameC, info.nameA ) ) dup = 1;
265 +
266 +      if(dup){
267 +        sprintf( painCave.errMsg,
268 +                 "Duplicate TraPPE_Ex bend type \"%s - %s - %s\" found in "
269 +                 "the TraPPE_ExFF param file./n",
270 +                 nameA, nameB, nameC );
271 +        painCave.isFatal = 1;
272 +        simError();
273 +      }
274 +
275 +      if( next != NULL ) next->add(info);
276 +      else{
277 +        next = new LinkedBendType();
278 +        strcpy(next->nameA, info.nameA);
279 +        strcpy(next->nameB, info.nameB);
280 +        strcpy(next->nameC, info.nameC);
281 +        strcpy(next->type,  info.type);
282 +        next->k1 = info.k1;
283 +        next->k2 = info.k2;
284 +        next->k3 = info.k3;
285 +        next->t0 = info.t0;
286 +      }
287 +    }
288 +
289 + #ifdef IS_MPI    
290 +
291 +    void duplicate( bendStruct &info ){
292 +      strcpy(info.nameA, nameA);
293 +      strcpy(info.nameB, nameB);
294 +      strcpy(info.nameC, nameC);
295 +      strcpy(info.type,  type);
296 +      info.k1   = k1;
297 +      info.k2   = k2;
298 +      info.k3   = k3;
299 +      info.t0   = t0;
300 +      info.last = 0;
301 +    }
302 +
303 + #endif // is_mpi
304 +
305 +    char nameA[15];
306 +    char nameB[15];
307 +    char nameC[15];
308 +    char type[30];
309 +    double k1, k2, k3, t0;
310 +
311 +    LinkedBendType* next;
312 +  };
313 +
314 +  class LinkedTorsionType {
315 +  public:
316 +    LinkedTorsionType(){
317 +      next = NULL;
318 +      nameA[0] = '\0';
319 +      nameB[0] = '\0';
320 +      nameC[0] = '\0';
321 +      type[0] = '\0';
322 +    }
323 +    ~LinkedTorsionType(){ if( next != NULL ) delete next; }
324 +
325 +    LinkedTorsionType* find( char* key1, char* key2, char* key3, char* key4 ){
326 +      
327 +
328 +
329 +
330 +      if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) &&
331 +          !strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this;
332 +
333 +      if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) &&
334 +          !strcmp( nameC, key2 ) && !strcmp( nameD, key1 ) ) return this;
335 +
336 +      if( next != NULL ) return next->find(key1, key2, key3, key4);
337 +      return NULL;
338 +    }
339 +
340 +    void add( torsionStruct &info ){
341 +
342 +      // check for duplicates
343 +      int dup = 0;
344 +
345 +      if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) &&
346 +          !strcmp( nameC, info.nameC ) && !strcmp( nameD, info.nameD ) ) dup = 1;
347 +      
348 +      if( !strcmp( nameA, info.nameD ) && !strcmp( nameB, info.nameC ) &&
349 +          !strcmp( nameC, info.nameB ) && !strcmp( nameD, info.nameA ) ) dup = 1;
350 +      
351 +      if(dup){
352 +        sprintf( painCave.errMsg,
353 +                 "Duplicate TraPPE_Ex torsion type \"%s - %s - %s - %s\" found in "
354 +                 "the TraPPE_ExFF param file./n", nameA, nameB, nameC, nameD );
355 +        painCave.isFatal = 1;
356 +        simError();
357 +      }
358 +
359 +      if( next != NULL ) next->add(info);
360 +      else{
361 +        next = new LinkedTorsionType();
362 +        strcpy(next->nameA, info.nameA);
363 +        strcpy(next->nameB, info.nameB);
364 +        strcpy(next->nameC, info.nameC);
365 +        strcpy(next->nameD, info.nameD);
366 +        strcpy(next->type,  info.type);
367 +        next->k1 = info.k1;
368 +        next->k2 = info.k2;
369 +        next->k3 = info.k3;
370 +        next->k4 = info.k4;
371 +
372 +      }
373 +    }
374 +
375 + #ifdef IS_MPI
376 +    
377 +    void duplicate( torsionStruct &info ){
378 +      strcpy(info.nameA, nameA);
379 +      strcpy(info.nameB, nameB);
380 +      strcpy(info.nameC, nameC);
381 +      strcpy(info.nameD, nameD);
382 +      strcpy(info.type,  type);
383 +      info.k1   = k1;
384 +      info.k2   = k2;
385 +      info.k3   = k3;
386 +      info.k4   = k4;
387 +      info.last = 0;
388 +    }
389 +
390 + #endif
391 +
392 +    char nameA[15];
393 +    char nameB[15];
394 +    char nameC[15];
395 +    char nameD[15];
396 +    char type[30];
397 +    double k1, k2, k3, k4;
398 +
399 +    LinkedTorsionType* next;
400 +  };
401 +
402 +
403 +  LinkedAtomType* headAtomType;
404 +  LinkedAtomType* currentAtomType;
405 +  LinkedBondType* headBondType;
406 +  LinkedBondType* currentBondType;
407 +  LinkedBendType* headBendType;
408 +  LinkedBendType* currentBendType;
409 +  LinkedTorsionType* headTorsionType;
410 +  LinkedTorsionType* currentTorsionType;
411 +
412   } // namespace
413  
414   using namespace TPE;
# Line 103 | Line 427 | TraPPE_ExFF::TraPPE_ExFF(){
427    char temp[200];
428    char errMsg[1000];
429  
430 +  headAtomType       = NULL;
431 +  currentAtomType    = NULL;
432 +  headBondType       = NULL;
433 +  currentBondType    = NULL;
434 +  headBendType       = NULL;
435 +  currentBendType    = NULL;
436 +  headTorsionType    = NULL;
437 +  currentTorsionType = NULL;
438 +
439    // do the funtion wrapping
440    wrapMeFF( this );
441  
# Line 253 | Line 586 | TraPPE_ExFF::~TraPPE_ExFF(){
586  
587   TraPPE_ExFF::~TraPPE_ExFF(){
588  
589 +  if( headAtomType != NULL ) delete headAtomType;
590 +  if( headBondType != NULL ) delete headBondType;
591 +  if( headBendType != NULL ) delete headBendType;
592 +  if( headTorsionType != NULL ) delete headTorsionType;
593 +
594   #ifdef IS_MPI
595    if( worldRank == 0 ){
596   #endif // is_mpi
# Line 264 | Line 602 | void TraPPE_ExFF::initForceField( int ljMixRule ){
602   #endif // is_mpi
603   }
604  
605 + void TraPPE_ExFF::cleanMe( void ){
606 +
607 + #ifdef IS_MPI
608 +  
609 +  // keep the linked lists in the mpi version
610 +
611 + #else // is_mpi
612 +
613 +  // delete the linked lists in the single processor version
614 +
615 +  if( headAtomType != NULL ) delete headAtomType;
616 +  if( headBondType != NULL ) delete headBondType;
617 +  if( headBendType != NULL ) delete headBendType;
618 +  if( headTorsionType != NULL ) delete headTorsionType;
619 +
620 + #endif // is_mpi
621 + }
622 +
623 +
624   void TraPPE_ExFF::initForceField( int ljMixRule ){
625    
626    initFortran( ljMixRule, entry_plug->useReactionField );
627   }
628  
629  
630 < void TraPPE_ExFF::initializeAtoms( void ){
274 <  
275 <  class LinkedType {
276 <  public:
277 <    LinkedType(){
278 <      next = NULL;
279 <      name[0] = '\0';
280 <    }
281 <    ~LinkedType(){ if( next != NULL ) delete next; }
630 > void TraPPE_ExFF::readParams( void ){
631  
632 <    LinkedType* find(char* key){
284 <      if( !strcmp(name, key) ) return this;
285 <      if( next != NULL ) return next->find(key);
286 <      return NULL;
287 <    }
288 <    
289 <    void add( atomStruct &info ){
290 <
291 <      // check for duplicates
292 <      
293 <      if( !strcmp( info.name, name ) ){
294 <        sprintf( painCave.errMsg,
295 <                 "Duplicate TraPPE_Ex atom type \"%s\" found in "
296 <                 "the TraPPE_ExFF param file./n",
297 <                 name );
298 <        painCave.isFatal = 1;
299 <        simError();
300 <      }
301 <
302 <      if( next != NULL ) next->add(info);
303 <      else{
304 <        next = new LinkedType();
305 <        strcpy(next->name, info.name);
306 <        next->isDipole = info.isDipole;
307 <        next->isSSD    = info.isSSD;
308 <        next->mass     = info.mass;
309 <        next->epslon   = info.epslon;
310 <        next->sigma    = info.sigma;
311 <        next->dipole   = info.dipole;
312 <        next->w0       = info.w0;
313 <        next->v0       = info.v0;
314 <        next->ident    = info.ident;
315 <      }
316 <    }
317 <
318 < #ifdef IS_MPI
319 <    
320 <    void duplicate( atomStruct &info ){
321 <      strcpy(info.name, name);
322 <      info.isDipole = isDipole;
323 <      info.isSSD    = isSSD;
324 <      info.mass     = mass;
325 <      info.epslon   = epslon;
326 <      info.sigma    = sigma;
327 <      info.dipole   = dipole;
328 <      info.w0       = w0;
329 <      info.v0       = v0;
330 <      info.last     = 0;
331 <    }
332 <
333 <
334 < #endif
335 <
336 <    char name[15];
337 <    int isDipole;
338 <    int isSSD;
339 <    double mass;
340 <    double epslon;
341 <    double sigma;
342 <    double dipole;
343 <    double w0;
344 <    double v0;
345 <    int ident;
346 <    LinkedType* next;
347 <  };
348 <  
349 <  LinkedType* headAtomType;
350 <  LinkedType* currentAtomType;
351 <  atomStruct info;
352 <  info.last = 1; // initialize last to have the last set.
353 <                 // if things go well, last will be set to 0
354 <
355 <  
356 <
357 <  int i;
632 >  int i, a, b, c, d;
633    int identNum;
634 +  char* atomA;
635 +  char* atomB;
636 +  char* atomC;
637 +  char* atomD;
638    
639 <  Atom** the_atoms;
640 <  int nAtoms;
641 <  the_atoms = entry_plug->atoms;
642 <  nAtoms = entry_plug->n_atoms;
639 >  atomStruct atomInfo;
640 >  bondStruct bondInfo;
641 >  bendStruct bendInfo;
642 >  torsionStruct torsionInfo;
643    
644 <  //////////////////////////////////////////////////
366 <  // a quick water fix
644 >  bigSigma = 0.0;
645  
646 <  double waterI[3][3];
647 <  waterI[0][0] = 1.76958347772500;
648 <  waterI[0][1] = 0.0;
649 <  waterI[0][2] = 0.0;
646 >  atomInfo.last = 1;
647 >  bondInfo.last = 1;
648 >  bendInfo.last = 1;
649 >  torsionInfo.last = 1;
650  
651 <  waterI[1][0] = 0.0;
374 <  waterI[1][1] = 0.614537057924513;
375 <  waterI[1][2] = 0.0;
376 <
377 <  waterI[2][0] = 0.0;
378 <  waterI[2][1] = 0.0;
379 <  waterI[2][2] = 1.15504641980049;
380 <
381 <
382 <  double headI[3][3];
383 <  headI[0][0] = 1125;
384 <  headI[0][1] = 0.0;
385 <  headI[0][2] = 0.0;
386 <
387 <  headI[1][0] = 0.0;
388 <  headI[1][1] = 1125;
389 <  headI[1][2] = 0.0;
390 <
391 <  headI[2][0] = 0.0;
392 <  headI[2][1] = 0.0;
393 <  headI[2][2] = 250;
394 <
651 >  // read in the atom info
652    
396
397  //////////////////////////////////////////////////
398
399
653   #ifdef IS_MPI
654    if( worldRank == 0 ){
655   #endif
656      
657      // read in the atom types.
405
406    headAtomType = new LinkedType;
658      
659 +    headAtomType = new LinkedAtomType;
660 +    
661      fastForward( "AtomTypes", "initializeAtoms" );
662  
663      // we are now at the AtomTypes section.
# Line 431 | Line 684 | void TraPPE_ExFF::initializeAtoms( void ){
684        if( readLine[0] != '!' ){
685          
686          // the parser returns 0 if the line was blank
687 <        if( parseAtom( readLine, lineNum, info ) ){
688 <          info.ident = identNum;
689 <          headAtomType->add( info );;
687 >        if( parseAtom( readLine, lineNum, atomInfo ) ){
688 >          atomInfo.ident = identNum;
689 >          headAtomType->add( atomInfo );;
690            identNum++;
691          }
692        }
# Line 451 | Line 704 | void TraPPE_ExFF::initializeAtoms( void ){
704  
705      currentAtomType = headAtomType->next; //skip the first element who is a place holder.
706      while( currentAtomType != NULL ){
707 <      currentAtomType->duplicate( info );
707 >      currentAtomType->duplicate( atomInfo );
708  
709  
710  
711 <      sendFrcStruct( &info, mpiAtomStructType );
711 >      sendFrcStruct( &atomInfo, mpiAtomStructType );
712  
713        sprintf( checkPointMsg,
714                 "successfully sent TraPPE_Ex force type: \"%s\"\n",
715 <               info.name );
715 >               atomInfo.name );
716        MPIcheckPoint();
717  
718        currentAtomType = currentAtomType->next;
719      }
720 <    info.last = 1;
721 <    sendFrcStruct( &info, mpiAtomStructType );
720 >    atomInfo.last = 1;
721 >    sendFrcStruct( &atomInfo, mpiAtomStructType );
722      
723    }
724  
# Line 475 | Line 728 | void TraPPE_ExFF::initializeAtoms( void ){
728      
729      MPIcheckPoint();
730  
731 <    headAtomType = new LinkedType;
732 <    recieveFrcStruct( &info, mpiAtomStructType );
731 >    headAtomType = new LinkedAtomType;
732 >    recieveFrcStruct( &atomInfo, mpiAtomStructType );
733      
734 <    while( !info.last ){
734 >    while( !atomInfo.last ){
735  
736  
737  
738 <      headAtomType->add( info );
738 >      headAtomType->add( atomInfo );
739        
740        MPIcheckPoint();
741  
742 <      recieveFrcStruct( &info, mpiAtomStructType );
742 >      recieveFrcStruct( &atomInfo, mpiAtomStructType );
743      }
744    }
745 +
746   #endif // is_mpi
747  
748 +
749 +
750    // call new A_types in fortran
751    
752    int isError;
# Line 545 | Line 801 | void TraPPE_ExFF::initializeAtoms( void ){
801   #endif // is_mpi
802  
803    
804 <  // initialize the atoms
804 >
805 >  // read in the bonds
806    
807 <  double bigSigma = 0.0;
808 <  DirectionalAtom* dAtom;
807 > #ifdef IS_MPI
808 >  if( worldRank == 0 ){
809 > #endif
810 >    
811 >    // read in the bond types.
812 >    
813 >    headBondType = new LinkedBondType;
814 >    
815 >    fastForward( "BondTypes", "initializeBonds" );
816  
817 <  for( i=0; i<nAtoms; i++ ){
817 >    // we are now at the bondTypes section
818  
819 +    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
820 +    lineNum++;
821      
822 <    currentAtomType = headAtomType->find( the_atoms[i]->getType() );
823 <    if( currentAtomType == NULL ){
822 >    
823 >    // read a line, and start parseing out the atom types
824 >
825 >    if( eof_test == NULL ){
826        sprintf( painCave.errMsg,
827 <               "AtomType error, %s not found in force file.\n",
828 <               the_atoms[i]->getType() );
827 >               "Error in reading bonds from force file at line %d.\n",
828 >               lineNum );
829        painCave.isFatal = 1;
830        simError();
831      }
832      
833 <    the_atoms[i]->setMass( currentAtomType->mass );
834 <    the_atoms[i]->setEpslon( currentAtomType->epslon );
567 <    the_atoms[i]->setSigma( currentAtomType->sigma );
568 <    the_atoms[i]->setIdent( currentAtomType->ident );
569 <    the_atoms[i]->setLJ();
833 >    // stop reading at end of file, or at next section
834 >    while( readLine[0] != '#' && eof_test != NULL ){
835  
836 <    if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma;
837 <
573 <    if( currentAtomType->isDipole ){
574 <      if( the_atoms[i]->isDirectional() ){
836 >      // toss comment lines
837 >      if( readLine[0] != '!' ){
838          
839 <        dAtom = (DirectionalAtom *) the_atoms[i];
840 <        dAtom->setMu( currentAtomType->dipole );
841 <        dAtom->setHasDipole( 1 );
579 <        dAtom->setJx( 0.0 );
580 <        dAtom->setJy( 0.0 );
581 <        dAtom->setJz( 0.0 );
582 <        
583 <        if(!strcmp("SSD",the_atoms[i]->getType())){
584 <          dAtom->setI( waterI );
585 <          dAtom->setSSD( 1 );
839 >        // the parser returns 0 if the line was blank
840 >        if( parseBond( readLine, lineNum, bondInfo ) ){
841 >          headBondType->add( bondInfo );
842          }
587        else if(!strcmp("HEAD",the_atoms[i]->getType())){
588          dAtom->setI( headI );
589          dAtom->setSSD( 0 );
590        }
591        else{
592          sprintf(painCave.errMsg,
593                  "AtmType error, %s does not have a moment of inertia set.\n",
594                  the_atoms[i]->getType() );
595          painCave.isFatal = 1;
596          simError();
597        }
598        entry_plug->n_dipoles++;
843        }
844 <      else{
845 <        
602 <        sprintf( painCave.errMsg,
603 <                "TraPPE_ExFF error: Atom \"%s\" is a dipole, yet no standard"
604 <                 " orientation was specifed in the BASS file.\n",
605 <                 currentAtomType->name );
606 <        painCave.isFatal = 1;
607 <        simError();
608 <      }
844 >      eof_test = fgets( readLine, sizeof(readLine), frcFile );
845 >      lineNum++;
846      }
847 <    else{
848 <      if( the_atoms[i]->isDirectional() ){
849 <        sprintf( painCave.errMsg,
850 <                 "TraPPE_ExFF error: Atom \"%s\" was given a standard"
851 <                 "orientation in the BASS file, yet it is not a dipole.\n",
852 <                 currentAtomType->name);
853 <        painCave.isFatal = 1;
854 <        simError();
855 <      }
847 >        
848 > #ifdef IS_MPI
849 >    
850 >    // send out the linked list to all the other processes
851 >    
852 >    sprintf( checkPointMsg,
853 >             "TraPPE_Ex bond structures read successfully." );
854 >    MPIcheckPoint();
855 >    
856 >    currentBondType = headBondType->next;
857 >    while( currentBondType != NULL ){
858 >      currentBondType->duplicate( bondInfo );
859 >      sendFrcStruct( &bondInfo, mpiBondStructType );
860 >      currentBondType = currentBondType->next;
861      }
862 +    bondInfo.last = 1;
863 +    sendFrcStruct( &bondInfo, mpiBondStructType );
864 +    
865    }
866  
867 < #ifdef IS_MPI
868 <  double tempBig = bigSigma;
869 <  MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX );
870 < #endif  //is_mpi
867 >  else{
868 >    
869 >    // listen for node 0 to send out the force params
870 >    
871 >    MPIcheckPoint();
872  
873 <  //calc rCut and rList
873 >    headBondType = new LinkedBondType;
874 >    recieveFrcStruct( &bondInfo, mpiBondStructType );
875 >    while( !bondInfo.last ){
876  
877 <  entry_plug->rCut = 2.5 * bigSigma;
877 >      headBondType->add( bondInfo );
878 >      recieveFrcStruct( &bondInfo, mpiBondStructType );
879 >    }
880 >  }
881 > #endif // is_mpi
882    
631  if(entry_plug->rCut > (entry_plug->box_x / 2.0))
632    entry_plug->rCut = entry_plug->box_x / 2.0;
633  
634  if(entry_plug->rCut > (entry_plug->box_y / 2.0))
635    entry_plug->rCut = entry_plug->box_y / 2.0;
636  
637  if(entry_plug->rCut > (entry_plug->box_z / 2.0))
638    entry_plug->rCut = entry_plug->box_z / 2.0;
883  
884 <  entry_plug->rList = entry_plug->rCut + 1.0;
884 >  // read in the bends
885  
642  entry_plug->useLJ = 1; // use Lennard Jones is on by default
643
644  // clean up the memory
645  
646  delete headAtomType;
647
886   #ifdef IS_MPI
887 <  sprintf( checkPointMsg, "TraPPE_Ex atoms initialized succesfully" );
888 <  MPIcheckPoint();
651 < #endif // is_mpi
887 >  if( worldRank == 0 ){
888 > #endif
889  
890 < }
890 >    // read in the bend types.
891  
892 < void TraPPE_ExFF::initializeBonds( bond_pair* the_bonds ){
656 <  
657 <  class LinkedType {
658 <  public:
659 <    LinkedType(){
660 <      next = NULL;
661 <      nameA[0] = '\0';
662 <      nameB[0] = '\0';
663 <      type[0] = '\0';
664 <    }
665 <    ~LinkedType(){ if( next != NULL ) delete next; }
666 <
667 <    LinkedType* find(char* key1, char* key2){
668 <      if( !strcmp(nameA, key1 ) && !strcmp( nameB, key2 ) ) return this;
669 <      if( !strcmp(nameA, key2 ) && !strcmp( nameB, key1 ) ) return this;
670 <      if( next != NULL ) return next->find(key1, key2);
671 <      return NULL;
672 <    }
892 >    headBendType = new LinkedBendType;
893      
894 +    fastForward( "BendTypes", "initializeBends" );
895  
896 <    void add( bondStruct &info ){
676 <      
677 <      // check for duplicates
678 <      int dup = 0;
896 >    // we are now at the bendTypes section
897  
898 <      if( !strcmp(nameA, info.nameA ) && !strcmp( nameB, info.nameB ) ) dup = 1;
899 <      if( !strcmp(nameA, info.nameB ) && !strcmp( nameB, info.nameA ) ) dup = 1;
900 <      
901 <      if(dup){
684 <        sprintf( painCave.errMsg,
685 <                 "Duplicate TraPPE_Ex bond type \"%s - %s\" found in "
686 <                 "the TraPPE_ExFF param file./n",
687 <                 nameA, nameB );
688 <        painCave.isFatal = 1;
689 <        simError();
690 <      }
898 >    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
899 >    lineNum++;
900 >        
901 >    // read a line, and start parseing out the bend types
902  
903 +    if( eof_test == NULL ){
904 +      sprintf( painCave.errMsg,
905 +               "Error in reading bends from force file at line %d.\n",
906 +               lineNum );
907 +      painCave.isFatal = 1;
908 +      simError();
909 +    }
910 +    
911 +    // stop reading at end of file, or at next section
912 +    while( readLine[0] != '#' && eof_test != NULL ){
913 +      
914 +      // toss comment lines
915 +      if( readLine[0] != '!' ){
916          
917 <      if( next != NULL ) next->add(info);
918 <      else{
919 <        next = new LinkedType();
920 <        strcpy(next->nameA, info.nameA);
697 <        strcpy(next->nameB, info.nameB);
698 <        strcpy(next->type,  info.type);
699 <        next->d0 = info.d0;
917 >        // the parser returns 0 if the line was blank
918 >        if( parseBend( readLine, lineNum, bendInfo ) ){
919 >          headBendType->add( bendInfo );
920 >        }
921        }
922 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
923 +      lineNum++;
924      }
925      
926   #ifdef IS_MPI
927 <    void duplicate( bondStruct &info ){
928 <      strcpy(info.nameA, nameA);
706 <      strcpy(info.nameB, nameB);
707 <      strcpy(info.type,  type);
708 <      info.d0   = d0;
709 <      info.last = 0;
710 <    }
927 >    
928 >    // send out the linked list to all the other processes
929  
930 +    sprintf( checkPointMsg,
931 +             "TraPPE_Ex bend structures read successfully." );
932 +    MPIcheckPoint();
933  
934 < #endif
934 >    currentBendType = headBendType->next;
935 >    while( currentBendType != NULL ){
936 >      currentBendType->duplicate( bendInfo );
937 >      sendFrcStruct( &bendInfo, mpiBendStructType );
938 >      currentBendType = currentBendType->next;
939 >    }
940 >    bendInfo.last = 1;
941 >    sendFrcStruct( &bendInfo, mpiBendStructType );
942 >    
943 >  }
944  
945 <    char nameA[15];
946 <    char nameB[15];
947 <    char type[30];
948 <    double d0;
945 >  else{
946 >    
947 >    // listen for node 0 to send out the force params
948 >    
949 >    MPIcheckPoint();
950  
951 <    LinkedType* next;
952 <  };
951 >    headBendType = new LinkedBendType;
952 >    recieveFrcStruct( &bendInfo, mpiBendStructType );
953 >    while( !bendInfo.last ){
954  
955 +      headBendType->add( bendInfo );
956 +      recieveFrcStruct( &bendInfo, mpiBendStructType );
957 +    }
958 +  }
959 + #endif // is_mpi
960  
724  
725  LinkedType* headBondType;
726  LinkedType* currentBondType;
727  bondStruct info;
728  info.last = 1; // initialize last to have the last set.
729                 // if things go well, last will be set to 0
961  
962 <  SRI **the_sris;
732 <  Atom** the_atoms;
733 <  int nBonds;
734 <  the_sris = entry_plug->sr_interactions;
735 <  the_atoms = entry_plug->atoms;
736 <  nBonds = entry_plug->n_bonds;
962 >  // read in the torsions
963  
738  int i, a, b;
739  char* atomA;
740  char* atomB;
741  
964   #ifdef IS_MPI
965    if( worldRank == 0 ){
966   #endif
967 +
968 +    // read in the torsion types.
969 +
970 +    headTorsionType = new LinkedTorsionType;
971      
972 <    // read in the bond types.
747 <    
748 <    headBondType = new LinkedType;
749 <    
750 <    fastForward( "BondTypes", "initializeBonds" );
972 >    fastForward( "TorsionTypes", "initializeTorsions" );
973  
974 <    // we are now at the bondTypes section
974 >    // we are now at the torsionTypes section
975  
976      eof_test =  fgets( readLine, sizeof(readLine), frcFile );
977      lineNum++;
# Line 759 | Line 981 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
981  
982      if( eof_test == NULL ){
983        sprintf( painCave.errMsg,
984 <               "Error in reading bonds from force file at line %d.\n",
984 >               "Error in reading torsions from force file at line %d.\n",
985                 lineNum );
986        painCave.isFatal = 1;
987        simError();
# Line 772 | Line 994 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
994        if( readLine[0] != '!' ){
995          
996          // the parser returns 0 if the line was blank
997 <        if( parseBond( readLine, lineNum, info ) ){
998 <          headBondType->add( info );
997 >        if( parseTorsion( readLine, lineNum, torsionInfo ) ){
998 >          headTorsionType->add( torsionInfo );
999 >
1000          }
1001        }
1002        eof_test = fgets( readLine, sizeof(readLine), frcFile );
1003        lineNum++;
1004      }
1005 <        
1005 >
1006   #ifdef IS_MPI
1007      
1008      // send out the linked list to all the other processes
1009      
1010      sprintf( checkPointMsg,
1011 <             "TraPPE_Ex bond structures read successfully." );
1011 >             "TraPPE_Ex torsion structures read successfully." );
1012      MPIcheckPoint();
1013      
1014 <    currentBondType = headBondType;
1015 <    while( currentBondType != NULL ){
1016 <      currentBondType->duplicate( info );
1017 <      sendFrcStruct( &info, mpiBondStructType );
1018 <      currentBondType = currentBondType->next;
1014 >    currentTorsionType = headTorsionType->next;
1015 >    while( currentTorsionType != NULL ){
1016 >      currentTorsionType->duplicate( torsionInfo );
1017 >      sendFrcStruct( &torsionInfo, mpiTorsionStructType );
1018 >      currentTorsionType = currentTorsionType->next;
1019      }
1020 <    info.last = 1;
1021 <    sendFrcStruct( &info, mpiBondStructType );
1020 >    torsionInfo.last = 1;
1021 >    sendFrcStruct( &torsionInfo, mpiTorsionStructType );
1022      
1023    }
1024  
# Line 805 | Line 1028 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
1028      
1029      MPIcheckPoint();
1030  
1031 <    headBondType = new LinkedType;
1032 <    recieveFrcStruct( &info, mpiBondStructType );
1033 <    while( !info.last ){
1031 >    headTorsionType = new LinkedTorsionType;
1032 >    recieveFrcStruct( &torsionInfo, mpiTorsionStructType );
1033 >    while( !torsionInfo.last ){
1034  
1035 <      headBondType->add( info );
1036 <      recieveFrcStruct( &info, mpiBondStructType );
1035 >      headTorsionType->add( torsionInfo );
1036 >      recieveFrcStruct( &torsionInfo, mpiTorsionStructType );
1037      }
1038    }
1039   #endif // is_mpi
1040 +
1041 +  entry_plug->useLJ = 1;
1042 + }
1043 +
1044 +
1045 +
1046 + void TraPPE_ExFF::initializeAtoms( int nAtoms, Atom** the_atoms ){
1047    
1048    
1049 <  // initialize the Bonds
1049 >  //////////////////////////////////////////////////
1050 >  // a quick water fix
1051 >
1052 >  double waterI[3][3];
1053 >  waterI[0][0] = 1.76958347772500;
1054 >  waterI[0][1] = 0.0;
1055 >  waterI[0][2] = 0.0;
1056 >
1057 >  waterI[1][0] = 0.0;
1058 >  waterI[1][1] = 0.614537057924513;
1059 >  waterI[1][2] = 0.0;
1060 >
1061 >  waterI[2][0] = 0.0;
1062 >  waterI[2][1] = 0.0;
1063 >  waterI[2][2] = 1.15504641980049;
1064 >
1065 >
1066 >  double headI[3][3];
1067 >  headI[0][0] = 1125;
1068 >  headI[0][1] = 0.0;
1069 >  headI[0][2] = 0.0;
1070 >
1071 >  headI[1][0] = 0.0;
1072 >  headI[1][1] = 1125;
1073 >  headI[1][2] = 0.0;
1074 >
1075 >  headI[2][0] = 0.0;
1076 >  headI[2][1] = 0.0;
1077 >  headI[2][2] = 250;
1078 >
1079 >  //////////////////////////////////////////////////
1080 >
1081    
1082 +  // initialize the atoms
1083 +  
1084 +  DirectionalAtom* dAtom;
1085  
1086 +  for(int i=0; i<nAtoms; i++ ){
1087 +
1088 +    currentAtomType = headAtomType->find( the_atoms[i]->getType() );
1089 +    if( currentAtomType == NULL ){
1090 +      sprintf( painCave.errMsg,
1091 +               "AtomType error, %s not found in force file.\n",
1092 +               the_atoms[i]->getType() );
1093 +      painCave.isFatal = 1;
1094 +      simError();
1095 +    }
1096 +    
1097 +    the_atoms[i]->setMass( currentAtomType->mass );
1098 +    the_atoms[i]->setEpslon( currentAtomType->epslon );
1099 +    the_atoms[i]->setSigma( currentAtomType->sigma );
1100 +    the_atoms[i]->setIdent( currentAtomType->ident );
1101 +    the_atoms[i]->setLJ();
1102 +
1103 +    if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma;
1104 +
1105 +    if( currentAtomType->isDipole ){
1106 +      if( the_atoms[i]->isDirectional() ){
1107 +        
1108 +        dAtom = (DirectionalAtom *) the_atoms[i];
1109 +        dAtom->setMu( currentAtomType->dipole );
1110 +        dAtom->setHasDipole( 1 );
1111 +        dAtom->setJx( 0.0 );
1112 +        dAtom->setJy( 0.0 );
1113 +        dAtom->setJz( 0.0 );
1114 +        
1115 +        if(!strcmp("SSD",the_atoms[i]->getType())){
1116 +          dAtom->setI( waterI );
1117 +          dAtom->setSSD( 1 );
1118 +        }
1119 +        else if(!strcmp("HEAD",the_atoms[i]->getType())){
1120 +          dAtom->setI( headI );
1121 +          dAtom->setSSD( 0 );
1122 +        }
1123 +        else{
1124 +          sprintf(painCave.errMsg,
1125 +                  "AtmType error, %s does not have a moment of inertia set.\n",
1126 +                  the_atoms[i]->getType() );
1127 +          painCave.isFatal = 1;
1128 +          simError();
1129 +        }
1130 +        entry_plug->n_dipoles++;
1131 +      }
1132 +      else{
1133 +        
1134 +        sprintf( painCave.errMsg,
1135 +                "TraPPE_ExFF error: Atom \"%s\" is a dipole, yet no standard"
1136 +                 " orientation was specifed in the BASS file.\n",
1137 +                 currentAtomType->name );
1138 +        painCave.isFatal = 1;
1139 +        simError();
1140 +      }
1141 +    }
1142 +    else{
1143 +      if( the_atoms[i]->isDirectional() ){
1144 +        sprintf( painCave.errMsg,
1145 +                 "TraPPE_ExFF error: Atom \"%s\" was given a standard"
1146 +                 "orientation in the BASS file, yet it is not a dipole.\n",
1147 +                 currentAtomType->name);
1148 +        painCave.isFatal = 1;
1149 +        simError();
1150 +      }
1151 +    }
1152 +  }
1153 + }
1154 +
1155 + void TraPPE_ExFF::initializeBonds( int nBonds, Bond** bondArray,
1156 +                                   bond_pair* the_bonds ){
1157 +  int i,a,b;
1158 +  char* atomA;
1159 +  char* atomB;
1160 +  
1161 +  Atom** the_atoms;
1162 +  the_atoms = entry_plug->atoms;
1163 +  
1164 +
1165 +  // initialize the Bonds
1166 +  
1167    for( i=0; i<nBonds; i++ ){
1168      
1169      a = the_bonds[i].a;
# Line 837 | Line 1182 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
1182      
1183      if( !strcmp( currentBondType->type, "fixed" ) ){
1184        
1185 <      the_sris[i] = new ConstrainedBond( *the_atoms[a],
1186 <                                         *the_atoms[b],
1187 <                                         currentBondType->d0 );
1185 >      bondArray[i] = new ConstrainedBond( *the_atoms[a],
1186 >                                          *the_atoms[b],
1187 >                                          currentBondType->d0 );
1188        entry_plug->n_constraints++;
1189      }
1190    }
846
847
848  // clean up the memory
849  
850  delete headBondType;
851
852 #ifdef IS_MPI
853  sprintf( checkPointMsg, "TraPPE_Ex bonds initialized succesfully" );
854  MPIcheckPoint();
855 #endif // is_mpi
856
1191   }
1192  
1193 < void TraPPE_ExFF::initializeBends( bend_set* the_bends ){
1194 <  
861 <  class LinkedType {
862 <  public:
863 <    LinkedType(){
864 <      next = NULL;
865 <      nameA[0] = '\0';
866 <      nameB[0] = '\0';
867 <      nameC[0] = '\0';
868 <      type[0] = '\0';
869 <    }
870 <    ~LinkedType(){ if( next != NULL ) delete next; }
871 <
872 <    LinkedType* find( char* key1, char* key2, char* key3 ){
873 <      if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 )
874 <          && !strcmp( nameC, key3 ) ) return this;
875 <      if( !strcmp( nameA, key3 ) && !strcmp( nameB, key2 )
876 <          && !strcmp( nameC, key1 ) ) return this;
877 <      if( next != NULL ) return next->find(key1, key2, key3);
878 <      return NULL;
879 <    }
880 <    
881 <    void add( bendStruct &info ){
882 <
883 <      // check for duplicates
884 <      int dup = 0;
885 <      
886 <      if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB )
887 <          && !strcmp( nameC, info.nameC ) ) dup = 1;
888 <      if( !strcmp( nameA, info.nameC ) && !strcmp( nameB, info.nameB )
889 <          && !strcmp( nameC, info.nameA ) ) dup = 1;
890 <
891 <      if(dup){
892 <        sprintf( painCave.errMsg,
893 <                 "Duplicate TraPPE_Ex bend type \"%s - %s - %s\" found in "
894 <                 "the TraPPE_ExFF param file./n",
895 <                 nameA, nameB, nameC );
896 <        painCave.isFatal = 1;
897 <        simError();
898 <      }
899 <
900 <      if( next != NULL ) next->add(info);
901 <      else{
902 <        next = new LinkedType();
903 <        strcpy(next->nameA, info.nameA);
904 <        strcpy(next->nameB, info.nameB);
905 <        strcpy(next->nameC, info.nameC);
906 <        strcpy(next->type,  info.type);
907 <        next->k1 = info.k1;
908 <        next->k2 = info.k2;
909 <        next->k3 = info.k3;
910 <        next->t0 = info.t0;
911 <      }
912 <    }
913 <
914 < #ifdef IS_MPI    
915 <
916 <    void duplicate( bendStruct &info ){
917 <      strcpy(info.nameA, nameA);
918 <      strcpy(info.nameB, nameB);
919 <      strcpy(info.nameC, nameC);
920 <      strcpy(info.type,  type);
921 <      info.k1   = k1;
922 <      info.k2   = k2;
923 <      info.k3   = k3;
924 <      info.t0   = t0;
925 <      info.last = 0;
926 <    }
927 <
928 < #endif // is_mpi
929 <
930 <    char nameA[15];
931 <    char nameB[15];
932 <    char nameC[15];
933 <    char type[30];
934 <    double k1, k2, k3, t0;
935 <
936 <    LinkedType* next;
937 <  };
1193 > void TraPPE_ExFF::initializeBends( int nBends, Bend** bendArray,
1194 >                                   bend_set* the_bends ){
1195    
939  LinkedType* headBendType;
940  LinkedType* currentBendType;
941  bendStruct info;
942  info.last = 1; // initialize last to have the last set.
943                 // if things go well, last will be set to 0
944
1196    QuadraticBend* qBend;
1197    GhostBend* gBend;
947  SRI **the_sris;
1198    Atom** the_atoms;
949  int nBends;
950  the_sris = entry_plug->sr_interactions;
1199    the_atoms = entry_plug->atoms;
1200 <  nBends = entry_plug->n_bends;
953 <
1200 >  
1201    int i, a, b, c;
1202    char* atomA;
1203    char* atomB;
1204    char* atomC;
958
959
960 #ifdef IS_MPI
961  if( worldRank == 0 ){
962 #endif
963
964    // read in the bend types.
965
966    headBendType = new LinkedType;
967    
968    fastForward( "BendTypes", "initializeBends" );
969
970    // we are now at the bendTypes section
971
972    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
973    lineNum++;
974        
975    // read a line, and start parseing out the bend types
976
977    if( eof_test == NULL ){
978      sprintf( painCave.errMsg,
979               "Error in reading bends from force file at line %d.\n",
980               lineNum );
981      painCave.isFatal = 1;
982      simError();
983    }
984    
985    // stop reading at end of file, or at next section
986    while( readLine[0] != '#' && eof_test != NULL ){
987      
988      // toss comment lines
989      if( readLine[0] != '!' ){
990        
991        // the parser returns 0 if the line was blank
992        if( parseBend( readLine, lineNum, info ) ){
993          headBendType->add( info );
994        }
995      }
996      eof_test = fgets( readLine, sizeof(readLine), frcFile );
997      lineNum++;
998    }
999    
1000 #ifdef IS_MPI
1001    
1002    // send out the linked list to all the other processes
1003
1004    sprintf( checkPointMsg,
1005             "TraPPE_Ex bend structures read successfully." );
1006    MPIcheckPoint();
1007
1008    currentBendType = headBendType;
1009    while( currentBendType != NULL ){
1010      currentBendType->duplicate( info );
1011      sendFrcStruct( &info, mpiBendStructType );
1012      currentBendType = currentBendType->next;
1013    }
1014    info.last = 1;
1015    sendFrcStruct( &info, mpiBendStructType );
1016    
1017  }
1018
1019  else{
1020    
1021    // listen for node 0 to send out the force params
1022    
1023    MPIcheckPoint();
1024
1025    headBendType = new LinkedType;
1026    recieveFrcStruct( &info, mpiBendStructType );
1027    while( !info.last ){
1028
1029      headBendType->add( info );
1030      recieveFrcStruct( &info, mpiBendStructType );
1031    }
1032  }
1033 #endif // is_mpi
1205    
1206    // initialize the Bends
1036  
1037  int index;
1207  
1208    for( i=0; i<nBends; i++ ){
1209      
# Line 1059 | Line 1228 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1228      
1229      if( !strcmp( currentBendType->type, "quadratic" ) ){
1230        
1062      index = i + entry_plug->n_bonds;
1063      
1231        if( the_bends[i].isGhost){
1232          
1233          if( the_bends[i].ghost == b ){
# Line 1088 | Line 1255 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1255                               currentBendType->k2,
1256                               currentBendType->k3,
1257                               currentBendType->t0 );
1258 <        the_sris[index] = gBend;
1258 >        bendArray[i] = gBend;
1259        }
1260        else{
1261          qBend = new QuadraticBend( *the_atoms[a],
# Line 1098 | Line 1265 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
1265                               currentBendType->k2,
1266                               currentBendType->k3,
1267                               currentBendType->t0 );
1268 <        the_sris[index] = qBend;
1268 >        bendArray[i] = qBend;
1269        }
1270      }
1271    }
1105
1106
1107  // clean up the memory
1108  
1109  delete headBendType;
1110
1111 #ifdef IS_MPI
1112  sprintf( checkPointMsg, "TraPPE_Ex bends initialized succesfully" );
1113  MPIcheckPoint();
1114 #endif // is_mpi
1115
1272   }
1273  
1274 < void TraPPE_ExFF::initializeTorsions( torsion_set* the_torsions ){
1274 > void TraPPE_ExFF::initializeTorsions( int nTorsions, Torsion** torsionArray,
1275 >                                      torsion_set* the_torsions ){
1276  
1277 <  class LinkedType {
1121 <  public:
1122 <    LinkedType(){
1123 <      next = NULL;
1124 <      nameA[0] = '\0';
1125 <      nameB[0] = '\0';
1126 <      nameC[0] = '\0';
1127 <      type[0] = '\0';
1128 <    }
1129 <    ~LinkedType(){ if( next != NULL ) delete next; }
1130 <
1131 <    LinkedType* find( char* key1, char* key2, char* key3, char* key4 ){
1132 <      
1133 <
1134 <
1135 <
1136 <      if( !strcmp( nameA, key1 ) && !strcmp( nameB, key2 ) &&
1137 <          !strcmp( nameC, key3 ) && !strcmp( nameD, key4 ) ) return this;
1138 <
1139 <      if( !strcmp( nameA, key4 ) && !strcmp( nameB, key3 ) &&
1140 <          !strcmp( nameC, key2 ) && !strcmp( nameD, key1 ) ) return this;
1141 <
1142 <      if( next != NULL ) return next->find(key1, key2, key3, key4);
1143 <      return NULL;
1144 <    }
1145 <
1146 <    void add( torsionStruct &info ){
1147 <
1148 <      // check for duplicates
1149 <      int dup = 0;
1150 <
1151 <      if( !strcmp( nameA, info.nameA ) && !strcmp( nameB, info.nameB ) &&
1152 <          !strcmp( nameC, info.nameC ) && !strcmp( nameD, info.nameD ) ) dup = 1;
1153 <      
1154 <      if( !strcmp( nameA, info.nameD ) && !strcmp( nameB, info.nameC ) &&
1155 <          !strcmp( nameC, info.nameB ) && !strcmp( nameD, info.nameA ) ) dup = 1;
1156 <      
1157 <      if(dup){
1158 <        sprintf( painCave.errMsg,
1159 <                 "Duplicate TraPPE_Ex torsion type \"%s - %s - %s - %s\" found in "
1160 <                 "the TraPPE_ExFF param file./n", nameA, nameB, nameC, nameD );
1161 <        painCave.isFatal = 1;
1162 <        simError();
1163 <      }
1164 <
1165 <      if( next != NULL ) next->add(info);
1166 <      else{
1167 <        next = new LinkedType();
1168 <        strcpy(next->nameA, info.nameA);
1169 <        strcpy(next->nameB, info.nameB);
1170 <        strcpy(next->nameC, info.nameC);
1171 <        strcpy(next->nameD, info.nameD);
1172 <        strcpy(next->type,  info.type);
1173 <        next->k1 = info.k1;
1174 <        next->k2 = info.k2;
1175 <        next->k3 = info.k3;
1176 <        next->k4 = info.k4;
1177 <
1178 <      }
1179 <    }
1180 <
1181 < #ifdef IS_MPI
1182 <    
1183 <    void duplicate( torsionStruct &info ){
1184 <      strcpy(info.nameA, nameA);
1185 <      strcpy(info.nameB, nameB);
1186 <      strcpy(info.nameC, nameC);
1187 <      strcpy(info.nameD, nameD);
1188 <      strcpy(info.type,  type);
1189 <      info.k1   = k1;
1190 <      info.k2   = k2;
1191 <      info.k3   = k3;
1192 <      info.k4   = k4;
1193 <      info.last = 0;
1194 <    }
1195 <
1196 < #endif
1197 <
1198 <    char nameA[15];
1199 <    char nameB[15];
1200 <    char nameC[15];
1201 <    char nameD[15];
1202 <    char type[30];
1203 <    double k1, k2, k3, k4;
1204 <
1205 <    LinkedType* next;
1206 <  };
1207 <  
1208 <  LinkedType* headTorsionType;
1209 <  LinkedType* currentTorsionType;
1210 <  torsionStruct info;
1211 <  info.last = 1; // initialize last to have the last set.
1212 <                 // if things go well, last will be set to 0
1213 <
1214 <  int i, a, b, c, d, index;
1277 >  int i, a, b, c, d;
1278    char* atomA;
1279    char* atomB;
1280    char* atomC;
1281    char* atomD;
1219  CubicTorsion* cTors;
1282  
1283 <  SRI **the_sris;
1283 >  CubicTorsion* cTors;
1284    Atom** the_atoms;
1223  int nTorsions;
1224  the_sris = entry_plug->sr_interactions;
1285    the_atoms = entry_plug->atoms;
1226  nTorsions = entry_plug->n_torsions;
1286  
1228 #ifdef IS_MPI
1229  if( worldRank == 0 ){
1230 #endif
1231
1232    // read in the torsion types.
1233
1234    headTorsionType = new LinkedType;
1235    
1236    fastForward( "TorsionTypes", "initializeTorsions" );
1237
1238    // we are now at the torsionTypes section
1239
1240    eof_test =  fgets( readLine, sizeof(readLine), frcFile );
1241    lineNum++;
1242    
1243    
1244    // read a line, and start parseing out the atom types
1245
1246    if( eof_test == NULL ){
1247      sprintf( painCave.errMsg,
1248               "Error in reading torsions from force file at line %d.\n",
1249               lineNum );
1250      painCave.isFatal = 1;
1251      simError();
1252    }
1253    
1254    // stop reading at end of file, or at next section
1255    while( readLine[0] != '#' && eof_test != NULL ){
1256
1257      // toss comment lines
1258      if( readLine[0] != '!' ){
1259        
1260        // the parser returns 0 if the line was blank
1261        if( parseTorsion( readLine, lineNum, info ) ){
1262          headTorsionType->add( info );
1263
1264        }
1265      }
1266      eof_test = fgets( readLine, sizeof(readLine), frcFile );
1267      lineNum++;
1268    }
1269
1270 #ifdef IS_MPI
1271    
1272    // send out the linked list to all the other processes
1273    
1274    sprintf( checkPointMsg,
1275             "TraPPE_Ex torsion structures read successfully." );
1276    MPIcheckPoint();
1277    
1278    currentTorsionType = headTorsionType;
1279    while( currentTorsionType != NULL ){
1280      currentTorsionType->duplicate( info );
1281      sendFrcStruct( &info, mpiTorsionStructType );
1282      currentTorsionType = currentTorsionType->next;
1283    }
1284    info.last = 1;
1285    sendFrcStruct( &info, mpiTorsionStructType );
1286    
1287  }
1288
1289  else{
1290    
1291    // listen for node 0 to send out the force params
1292    
1293    MPIcheckPoint();
1294
1295    headTorsionType = new LinkedType;
1296    recieveFrcStruct( &info, mpiTorsionStructType );
1297    while( !info.last ){
1298
1299      headTorsionType->add( info );
1300      recieveFrcStruct( &info, mpiTorsionStructType );
1301    }
1302  }
1303 #endif // is_mpi
1304  
1287    // initialize the Torsions
1288  
1289    for( i=0; i<nTorsions; i++ ){
# Line 1326 | Line 1308 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1308      }
1309      
1310      if( !strcmp( currentTorsionType->type, "cubic" ) ){
1329      index = i + entry_plug->n_bonds + entry_plug->n_bends;
1311        
1312        cTors = new CubicTorsion( *the_atoms[a], *the_atoms[b],
1313                                  *the_atoms[c], *the_atoms[d] );
1314        cTors->setConstants( currentTorsionType->k1, currentTorsionType->k2,
1315                             currentTorsionType->k3, currentTorsionType->k4 );
1316 <      the_sris[index] = cTors;
1316 >      torsionArray[i] = cTors;
1317      }
1318    }
1338
1339
1340  // clean up the memory
1341  
1342  delete headTorsionType;
1343
1344 #ifdef IS_MPI
1345  sprintf( checkPointMsg, "TraPPE_Ex torsions initialized succesfully" );
1346  MPIcheckPoint();
1347 #endif // is_mpi
1348
1319   }
1320  
1321   void TraPPE_ExFF::fastForward( char* stopText, char* searchOwner ){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines