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 941 by gezelter, Tue Jan 13 23:01:43 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines