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

Comparing trunk/OOPSE/libmdtools/SimSetup.cpp (file contents):
Revision 604 by gezelter, Tue Jul 15 03:08:00 2003 UTC vs.
Revision 1157 by tim, Tue May 11 20:33:41 2004 UTC

# Line 1 | Line 1
1 < #include <cstdlib>
1 > #include <algorithm>
2 > #include <stdlib.h>
3   #include <iostream>
4 < #include <cmath>
5 <
4 > #include <math.h>
5 > #include <string>
6 > #include <sprng.h>
7   #include "SimSetup.hpp"
8 + #include "ReadWrite.hpp"
9   #include "parse_me.h"
10   #include "Integrator.hpp"
11   #include "simError.h"
12 + #include "RigidBody.hpp"
13 + //#include "ConjugateMinimizer.hpp"
14 + #include "OOPSEMinimizer.hpp"
15  
16   #ifdef IS_MPI
17   #include "mpiBASS.h"
# Line 14 | Line 20
20  
21   // some defines for ensemble and Forcefield  cases
22  
23 < #define NVE_ENS   0
24 < #define NVT_ENS   1
25 < #define NPTi_ENS  2
26 < #define NPTf_ENS  3
27 < #define NPTim_ENS 4
22 < #define NPTfm_ENS 5
23 > #define NVE_ENS        0
24 > #define NVT_ENS        1
25 > #define NPTi_ENS       2
26 > #define NPTf_ENS       3
27 > #define NPTxyz_ENS     4
28  
29  
30 < #define FF_DUFF 0
31 < #define FF_LJ   1
30 > #define FF_DUFF  0
31 > #define FF_LJ    1
32 > #define FF_EAM   2
33 > #define FF_H2O   3
34  
35 + using namespace std;
36  
37 + /**
38 + * Check whether dividend is divisble by divisor or not
39 + */
40 + bool isDivisible(double dividend, double divisor){
41 +  double tolerance = 0.000001;
42 +  double quotient;
43 +  double diff;
44 +  int intQuotient;
45 +  
46 +  quotient = dividend / divisor;
47 +
48 +  if (quotient < 0)
49 +    quotient = -quotient;
50 +
51 +  intQuotient = int (quotient + tolerance);
52 +
53 +  diff = fabs(fabs(dividend) - intQuotient  * fabs(divisor));
54 +
55 +  if (diff <= tolerance)
56 +    return true;
57 +  else
58 +    return false;  
59 + }
60 +
61   SimSetup::SimSetup(){
62 +  
63 +  initSuspend = false;
64 +  isInfoArray = 0;
65 +  nInfo = 1;
66 +
67    stamps = new MakeStamps();
68    globals = new Globals();
69 <  
69 >
70 >
71   #ifdef IS_MPI
72 <  strcpy( checkPointMsg, "SimSetup creation successful" );
72 >  strcpy(checkPointMsg, "SimSetup creation successful");
73    MPIcheckPoint();
74   #endif // IS_MPI
75   }
# Line 41 | Line 79 | SimSetup::~SimSetup(){
79    delete globals;
80   }
81  
82 < void SimSetup::parseFile( char* fileName ){
82 > void SimSetup::setSimInfo(SimInfo* the_info, int theNinfo){
83 >  info = the_info;
84 >  nInfo = theNinfo;
85 >  isInfoArray = 1;
86 >  initSuspend = true;
87 > }
88  
89 +
90 + void SimSetup::parseFile(char* fileName){
91   #ifdef IS_MPI
92 <  if( worldRank == 0 ){
92 >  if (worldRank == 0){
93   #endif // is_mpi
94 <    
94 >
95      inFileName = fileName;
96 <    set_interface_stamps( stamps, globals );
97 <    
96 >    set_interface_stamps(stamps, globals);
97 >
98   #ifdef IS_MPI
99      mpiEventInit();
100   #endif
101  
102 <    yacc_BASS( fileName );
102 >    yacc_BASS(fileName);
103  
104   #ifdef IS_MPI
105      throwMPIEvent(NULL);
106    }
107 <  else receiveParse();
107 >  else{
108 >    receiveParse();
109 >  }
110   #endif
111  
112   }
113  
114   #ifdef IS_MPI
115   void SimSetup::receiveParse(void){
116 <
117 <    set_interface_stamps( stamps, globals );
118 <    mpiEventInit();
119 <    MPIcheckPoint();
73 <    mpiEventLoop();
74 <
116 >  set_interface_stamps(stamps, globals);
117 >  mpiEventInit();
118 >  MPIcheckPoint();
119 >  mpiEventLoop();
120   }
121  
122   #endif // is_mpi
123  
124 < void SimSetup::createSim( void ){
124 > void SimSetup::createSim(void){
125  
126 <  MakeStamps *the_stamps;
82 <  Globals* the_globals;
83 <  int i, j, k, globalAtomIndex;
84 <  
85 <  int ensembleCase;
86 <  int ffCase;
87 <  
88 <  ensembleCase = -1;
89 <  ffCase = -1;
126 >  // gather all of the information from the Bass file
127  
128 <  // get the stamps and globals;
92 <  the_stamps = stamps;
93 <  the_globals = globals;
128 >  gatherInfo();
129  
130 <  // set the easy ones first
96 <  simnfo->target_temp = the_globals->getTargetTemp();
97 <  simnfo->dt = the_globals->getDt();
98 <  simnfo->run_time = the_globals->getRunTime();
130 >  // creation of complex system objects
131  
132 <  // get the ones we know are there, yet still may need some work.
101 <  n_components = the_globals->getNComponents();
102 <  strcpy( force_field, the_globals->getForceField() );
132 >  sysObjectsCreation();
133  
134 <  if( !strcasecmp( force_field, "DUFF" )) ffCase = FF_DUFF;
105 <  else if( !strcasecmp( force_field, "LJ" )) ffCase = FF_LJ;
106 <  else{
107 <    sprintf( painCave.errMsg,
108 <             "SimSetup Error. Unrecognized force field -> %s\n",
109 <             force_field );
110 <    painCave.isFatal = 1;
111 <    simError();
112 <  }
134 >  // check on the post processing info
135  
136 <  // get the ensemble:
115 <  strcpy( ensemble, the_globals->getEnsemble() );
136 >  finalInfoCheck();
137  
138 <  if( !strcasecmp( ensemble, "NVE" ))      ensembleCase = NVE_ENS;
118 <  else if( !strcasecmp( ensemble, "NVT" )) ensembleCase = NVT_ENS;
119 <  else if( !strcasecmp( ensemble, "NPTi" ) || !strcasecmp( ensemble, "NPT") )
120 <    ensembleCase = NPTi_ENS;
121 <  else if( !strcasecmp( ensemble, "NPTf" )) ensembleCase = NPTf_ENS;
122 <  else if( !strcasecmp( ensemble, "NPTim" )) ensembleCase = NPTim_ENS;
123 <  else if( !strcasecmp( ensemble, "NPTfm" )) ensembleCase = NPTfm_ENS;
124 <  else{
125 <    sprintf( painCave.errMsg,
126 <             "SimSetup Warning. Unrecognized Ensemble -> %s, "
127 <             "reverting to NVE for this simulation.\n",
128 <             ensemble );
129 <    painCave.isFatal = 0;
130 <    simError();
131 <    strcpy( ensemble, "NVE" );
132 <    ensembleCase = NVE_ENS;
133 <  }  
134 <  strcpy( simnfo->ensemble, ensemble );
138 >  // initialize the system coordinates
139  
140 +  if ( !initSuspend ){
141 +    initSystemCoords();
142  
143 < //   if( !strcasecmp( ensemble, "NPT" ) ) {
144 < //     the_extendedsystem = new ExtendedSystem( simnfo );
145 < //     the_extendedsystem->setTargetTemp(the_globals->getTargetTemp());
140 < //     if (the_globals->haveTargetPressure())
141 < //       the_extendedsystem->setTargetPressure(the_globals->getTargetPressure());
142 < //     else {
143 < //       sprintf( painCave.errMsg,
144 < //                "SimSetup error: If you use the constant pressure\n"
145 < //                "    ensemble, you must set targetPressure.\n"
146 < //                "    This was found in the BASS file.\n");
147 < //       painCave.isFatal = 1;
148 < //       simError();
149 < //     }
143 >    if( !(globals->getUseInitTime()) )
144 >      info[0].currentTime = 0.0;
145 >  }  
146  
147 < //     if (the_globals->haveTauThermostat())
152 < //       the_extendedsystem->setTauThermostat(the_globals->getTauThermostat());
153 < //     else if (the_globals->haveQmass())
154 < //       the_extendedsystem->setQmass(the_globals->getQmass());
155 < //     else {
156 < //       sprintf( painCave.errMsg,
157 < //                "SimSetup error: If you use one of the constant temperature\n"
158 < //                "    ensembles, you must set either tauThermostat or qMass.\n"
159 < //                "    Neither of these was found in the BASS file.\n");
160 < //       painCave.isFatal = 1;
161 < //       simError();
162 < //     }
147 >  // make the output filenames
148  
149 < //     if (the_globals->haveTauBarostat())
150 < //       the_extendedsystem->setTauBarostat(the_globals->getTauBarostat());
166 < //     else {
167 < //       sprintf( painCave.errMsg,
168 < //                "SimSetup error: If you use the constant pressure\n"
169 < //                "    ensemble, you must set tauBarostat.\n"
170 < //                "    This was found in the BASS file.\n");
171 < //       painCave.isFatal = 1;
172 < //       simError();
173 < //     }
174 <
175 < //   } else if ( !strcasecmp( ensemble, "NVT") ) {
176 < //     the_extendedsystem = new ExtendedSystem( simnfo );
177 < //     the_extendedsystem->setTargetTemp(the_globals->getTargetTemp());
178 <
179 < //     if (the_globals->haveTauThermostat())
180 < //       the_extendedsystem->setTauThermostat(the_globals->getTauThermostat());
181 < //     else if (the_globals->haveQmass())
182 < //       the_extendedsystem->setQmass(the_globals->getQmass());
183 < //     else {
184 < //       sprintf( painCave.errMsg,
185 < //                "SimSetup error: If you use one of the constant temperature\n"
186 < //                "    ensembles, you must set either tauThermostat or qMass.\n"
187 < //                "    Neither of these was found in the BASS file.\n");
188 < //       painCave.isFatal = 1;
189 < //       simError();
190 < //     }
191 <
192 <  strcpy( simnfo->mixingRule, the_globals->getMixingRule() );
193 <  simnfo->usePBC = the_globals->getPBC();
194 <          
195 <  int usesDipoles = 0;
196 <  switch( ffCase ){
197 <
198 <  case FF_DUFF:
199 <    the_ff = new DUFF();
200 <    usesDipoles = 1;
201 <    break;
202 <
203 <  case FF_LJ:
204 <    the_ff = new LJFF();
205 <    break;
206 <
207 <  default:
208 <    sprintf( painCave.errMsg,
209 <             "SimSetup Error. Unrecognized force field in case statement.\n");
210 <    painCave.isFatal = 1;
211 <    simError();
212 <  }
213 <
149 >  makeOutNames();
150 >  
151   #ifdef IS_MPI
152 <  strcpy( checkPointMsg, "ForceField creation successful" );
153 <  MPIcheckPoint();
217 < #endif // is_mpi
152 >  mpiSim->mpiRefresh();
153 > #endif
154  
155 <  // get the components and calculate the tot_nMol and indvidual n_mol
220 <  the_components = the_globals->getComponents();
221 <  components_nmol = new int[n_components];
222 <  comp_stamps = new MoleculeStamp*[n_components];
155 >  // initialize the Fortran
156  
157 <  if( !the_globals->haveNMol() ){
225 <    // we don't have the total number of molecules, so we assume it is
226 <    // given in each component
157 >  initFortran();
158  
159 <    tot_nmol = 0;
160 <    for( i=0; i<n_components; i++ ){
159 >  if (globals->haveMinimizer())
160 >    // make minimizer
161 >    makeMinimizer();
162 >  else
163 >    // make the integrator
164 >    makeIntegrator();
165  
166 <      if( !the_components[i]->haveNMol() ){
232 <        // we have a problem
233 <        sprintf( painCave.errMsg,
234 <                 "SimSetup Error. No global NMol or component NMol"
235 <                 " given. Cannot calculate the number of atoms.\n" );
236 <        painCave.isFatal = 1;
237 <        simError();
238 <      }
166 > }
167  
240      tot_nmol += the_components[i]->getNMol();
241      components_nmol[i] = the_components[i]->getNMol();
242    }
243  }
244  else{
245    sprintf( painCave.errMsg,
246             "SimSetup error.\n"
247             "\tSorry, the ability to specify total"
248             " nMols and then give molfractions in the components\n"
249             "\tis not currently supported."
250             " Please give nMol in the components.\n" );
251    painCave.isFatal = 1;
252    simError();
253    
254    
255    //     tot_nmol = the_globals->getNMol();
256    
257    //   //we have the total number of molecules, now we check for molfractions
258    //     for( i=0; i<n_components; i++ ){
259    
260    //       if( !the_components[i]->haveMolFraction() ){
261    
262    //  if( !the_components[i]->haveNMol() ){
263    //    //we have a problem
264    //    std::cerr << "SimSetup error. Neither molFraction nor "
265    //              << " nMol was given in component
266    
267  }
168  
169 < #ifdef IS_MPI
170 <  strcpy( checkPointMsg, "Have the number of components" );
171 <  MPIcheckPoint();
172 < #endif // is_mpi
169 > void SimSetup::makeMolecules(void){
170 >  int i, j, k;
171 >  int exI, exJ, exK, exL, slI, slJ;
172 >  int tempI, tempJ, tempK, tempL;
173 >  int molI;
174 >  int stampID, atomOffset, rbOffset;
175 >  molInit molInfo;
176 >  DirectionalAtom* dAtom;
177 >  RigidBody* myRB;
178 >  StuntDouble* mySD;
179 >  LinkedAssign* extras;
180 >  LinkedAssign* current_extra;
181 >  AtomStamp* currentAtom;
182 >  BondStamp* currentBond;
183 >  BendStamp* currentBend;
184 >  TorsionStamp* currentTorsion;
185 >  RigidBodyStamp* currentRigidBody;
186 >  CutoffGroupStamp* currentCutoffGroup;
187 >  CutoffGroup* myCutoffGroup;
188 >  
189 >  bond_pair* theBonds;
190 >  bend_set* theBends;
191 >  torsion_set* theTorsions;
192  
193 <  // make an array of molecule stamps that match the components used.
275 <  // also extract the used stamps out into a separate linked list
193 >  set<int> skipList;
194  
195 <  simnfo->nComponents = n_components;
196 <  simnfo->componentsNmol = components_nmol;
197 <  simnfo->compStamps = comp_stamps;
280 <  simnfo->headStamp = new LinkedMolStamp();
281 <  
282 <  char* id;
283 <  LinkedMolStamp* headStamp = simnfo->headStamp;
284 <  LinkedMolStamp* currentStamp = NULL;
285 <  for( i=0; i<n_components; i++ ){
195 >  double phi, theta, psi;
196 >  char* molName;
197 >  char rbName[100];
198  
199 <    id = the_components[i]->getType();
288 <    comp_stamps[i] = NULL;
289 <    
290 <    // check to make sure the component isn't already in the list
199 >  //init the forceField paramters
200  
201 <    comp_stamps[i] = headStamp->match( id );
202 <    if( comp_stamps[i] == NULL ){
201 >  the_ff->readParams();
202 >
203 >  // init the atoms
204 >
205 >  int nMembers, nNew, rb1, rb2;
206 >
207 >  for (k = 0; k < nInfo; k++){
208 >    the_ff->setSimInfo(&(info[k]));
209 >
210 >    atomOffset = 0;
211 >
212 >    for (i = 0; i < info[k].n_mol; i++){
213 >      stampID = info[k].molecules[i].getStampID();
214 >      molName = comp_stamps[stampID]->getID();
215 >
216 >      molInfo.nAtoms = comp_stamps[stampID]->getNAtoms();
217 >      molInfo.nBonds = comp_stamps[stampID]->getNBonds();
218 >      molInfo.nBends = comp_stamps[stampID]->getNBends();
219 >      molInfo.nTorsions = comp_stamps[stampID]->getNTorsions();
220 >      molInfo.nRigidBodies = comp_stamps[stampID]->getNRigidBodies();
221 >      molInfo.nCutoffGroups = comp_stamps[stampID]->getNCutoffGroups();
222        
223 <      // extract the component from the list;
223 >      molInfo.myAtoms = &(info[k].atoms[atomOffset]);
224 >
225 >      if (molInfo.nBonds > 0)
226 >        molInfo.myBonds = new (Bond *) [molInfo.nBonds];
227 >      else
228 >        molInfo.myBonds = NULL;
229 >
230 >      if (molInfo.nBends > 0)
231 >        molInfo.myBends = new (Bend *) [molInfo.nBends];
232 >      else
233 >        molInfo.myBends = NULL;
234 >
235 >      if (molInfo.nTorsions > 0)
236 >        molInfo.myTorsions = new (Torsion *) [molInfo.nTorsions];
237 >      else
238 >        molInfo.myTorsions = NULL;
239 >
240 >      theBonds = new bond_pair[molInfo.nBonds];
241 >      theBends = new bend_set[molInfo.nBends];
242 >      theTorsions = new torsion_set[molInfo.nTorsions];
243        
244 <      currentStamp = the_stamps->extractMolStamp( id );
298 <      if( currentStamp == NULL ){
299 <        sprintf( painCave.errMsg,
300 <                 "SimSetup error: Component \"%s\" was not found in the "
301 <                 "list of declared molecules\n",
302 <                 id );
303 <        painCave.isFatal = 1;
304 <        simError();
305 <      }
306 <      
307 <      headStamp->add( currentStamp );
308 <      comp_stamps[i] = headStamp->match( id );
309 <    }
310 <  }
244 >      // make the Atoms
245  
246 < #ifdef IS_MPI
247 <  strcpy( checkPointMsg, "Component stamps successfully extracted\n" );
314 <  MPIcheckPoint();
315 < #endif // is_mpi
316 <  
246 >      for (j = 0; j < molInfo.nAtoms; j++){
247 >        currentAtom = comp_stamps[stampID]->getAtom(j);
248  
249 +        if (currentAtom->haveOrientation()){
250 +          dAtom = new DirectionalAtom((j + atomOffset),
251 +                                      info[k].getConfiguration());
252 +          info[k].n_oriented++;
253 +          molInfo.myAtoms[j] = dAtom;
254  
255 +          // Directional Atoms have standard unit vectors which are oriented
256 +          // in space using the three Euler angles.  We assume the standard
257 +          // unit vector was originally along the z axis below.
258  
259 <  // caclulate the number of atoms, bonds, bends and torsions
259 >          phi = currentAtom->getEulerPhi() * M_PI / 180.0;
260 >          theta = currentAtom->getEulerTheta() * M_PI / 180.0;
261 >          psi = currentAtom->getEulerPsi()* M_PI / 180.0;
262  
263 <  tot_atoms = 0;
264 <  tot_bonds = 0;
265 <  tot_bends = 0;
266 <  tot_torsions = 0;
326 <  for( i=0; i<n_components; i++ ){
327 <    
328 <    tot_atoms +=    components_nmol[i] * comp_stamps[i]->getNAtoms();
329 <    tot_bonds +=    components_nmol[i] * comp_stamps[i]->getNBonds();
330 <    tot_bends +=    components_nmol[i] * comp_stamps[i]->getNBends();
331 <    tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions();
332 <  }
263 >          dAtom->setUnitFrameFromEuler(phi, theta, psi);
264 >            
265 >        }
266 >        else{
267  
268 <  tot_SRI = tot_bonds + tot_bends + tot_torsions;
268 >          molInfo.myAtoms[j] = new Atom((j + atomOffset), info[k].getConfiguration());
269  
270 <  simnfo->n_atoms = tot_atoms;
337 <  simnfo->n_bonds = tot_bonds;
338 <  simnfo->n_bends = tot_bends;
339 <  simnfo->n_torsions = tot_torsions;
340 <  simnfo->n_SRI = tot_SRI;
341 <  simnfo->n_mol = tot_nmol;
342 <  
343 <  simnfo->molMembershipArray = new int[tot_atoms];
270 >        }
271  
272 +        molInfo.myAtoms[j]->setType(currentAtom->getType());
273   #ifdef IS_MPI
274  
275 <  // divide the molecules among processors here.
348 <  
349 <  mpiSim = new mpiSimulation( simnfo );
350 <  
351 <  globalIndex = mpiSim->divideLabor();
275 >        molInfo.myAtoms[j]->setGlobalIndex(globalAtomIndex[j + atomOffset]);
276  
277 <  // set up the local variables
278 <  
355 <  int localMol, allMol;
356 <  int local_atoms, local_bonds, local_bends, local_torsions, local_SRI;
277 > #endif // is_mpi
278 >      }
279  
280 <  int* mol2proc = mpiSim->getMolToProcMap();
281 <  int* molCompType = mpiSim->getMolComponentType();
282 <  
283 <  allMol = 0;
284 <  localMol = 0;
363 <  local_atoms = 0;
364 <  local_bonds = 0;
365 <  local_bends = 0;
366 <  local_torsions = 0;
367 <  globalAtomIndex = 0;
280 >      // make the bonds
281 >      for (j = 0; j < molInfo.nBonds; j++){
282 >        currentBond = comp_stamps[stampID]->getBond(j);
283 >        theBonds[j].a = currentBond->getA() + atomOffset;
284 >        theBonds[j].b = currentBond->getB() + atomOffset;
285  
286 +        tempI = theBonds[j].a;
287 +        tempJ = theBonds[j].b;
288  
289 <  for( i=0; i<n_components; i++ ){
289 > #ifdef IS_MPI
290 >        exI = info[k].atoms[tempI]->getGlobalIndex() + 1;
291 >        exJ = info[k].atoms[tempJ]->getGlobalIndex() + 1;
292 > #else
293 >        exI = tempI + 1;
294 >        exJ = tempJ + 1;
295 > #endif
296  
297 <    for( j=0; j<components_nmol[i]; j++ ){
373 <      
374 <      if( mol2proc[allMol] == worldRank ){
375 <        
376 <        local_atoms +=    comp_stamps[i]->getNAtoms();
377 <        local_bonds +=    comp_stamps[i]->getNBonds();
378 <        local_bends +=    comp_stamps[i]->getNBends();
379 <        local_torsions += comp_stamps[i]->getNTorsions();
380 <        localMol++;
381 <      }      
382 <      for (k = 0; k < comp_stamps[i]->getNAtoms(); k++) {
383 <        simnfo->molMembershipArray[globalAtomIndex] = allMol;
384 <        globalAtomIndex++;
297 >        info[k].excludes->addPair(exI, exJ);
298        }
299  
300 <      allMol++;      
301 <    }
302 <  }
303 <  local_SRI = local_bonds + local_bends + local_torsions;
304 <  
305 <  simnfo->n_atoms = mpiSim->getMyNlocal();  
393 <  
394 <  if( local_atoms != simnfo->n_atoms ){
395 <    sprintf( painCave.errMsg,
396 <             "SimSetup error: mpiSim's localAtom (%d) and SimSetup's"
397 <             " localAtom (%d) are not equal.\n",
398 <             simnfo->n_atoms,
399 <             local_atoms );
400 <    painCave.isFatal = 1;
401 <    simError();
402 <  }
300 >      //make the bends
301 >      for (j = 0; j < molInfo.nBends; j++){
302 >        currentBend = comp_stamps[stampID]->getBend(j);
303 >        theBends[j].a = currentBend->getA() + atomOffset;
304 >        theBends[j].b = currentBend->getB() + atomOffset;
305 >        theBends[j].c = currentBend->getC() + atomOffset;
306  
307 <  simnfo->n_bonds = local_bonds;
308 <  simnfo->n_bends = local_bends;
309 <  simnfo->n_torsions = local_torsions;
407 <  simnfo->n_SRI = local_SRI;
408 <  simnfo->n_mol = localMol;
307 >        if (currentBend->haveExtras()){
308 >          extras = currentBend->getExtras();
309 >          current_extra = extras;
310  
311 <  strcpy( checkPointMsg, "Passed nlocal consistency check." );
312 <  MPIcheckPoint();
313 <  
314 <  
315 < #endif // is_mpi
316 <  
311 >          while (current_extra != NULL){
312 >            if (!strcmp(current_extra->getlhs(), "ghostVectorSource")){
313 >              switch (current_extra->getType()){
314 >                case 0:
315 >                  theBends[j].ghost = current_extra->getInt() + atomOffset;
316 >                  theBends[j].isGhost = 1;
317 >                  break;
318  
319 <  // create the atom and short range interaction arrays
319 >                case 1:
320 >                  theBends[j].ghost = (int) current_extra->getDouble() +
321 >                                      atomOffset;
322 >                  theBends[j].isGhost = 1;
323 >                  break;
324  
325 <  Atom::createArrays(simnfo->n_atoms);
326 <  the_atoms = new Atom*[simnfo->n_atoms];
327 <  the_molecules = new Molecule[simnfo->n_mol];
328 <  int molIndex;
329 <
330 <  // initialize the molecule's stampID's
325 >                default:
326 >                  sprintf(painCave.errMsg,
327 >                          "SimSetup Error: ghostVectorSource was neither a "
328 >                          "double nor an int.\n"
329 >                          "-->Bend[%d] in %s\n",
330 >                          j, comp_stamps[stampID]->getID());
331 >                  painCave.isFatal = 1;
332 >                  simError();
333 >              }
334 >            }
335 >            else{
336 >              sprintf(painCave.errMsg,
337 >                      "SimSetup Error: unhandled bend assignment:\n"
338 >                      "    -->%s in Bend[%d] in %s\n",
339 >                      current_extra->getlhs(), j, comp_stamps[stampID]->getID());
340 >              painCave.isFatal = 1;
341 >              simError();
342 >            }
343  
344 +            current_extra = current_extra->getNext();
345 +          }
346 +        }
347 +
348 +        if (theBends[j].isGhost) {
349 +          
350 +          tempI = theBends[j].a;
351 +          tempJ = theBends[j].b;
352 +          
353   #ifdef IS_MPI
354 <  
354 >          exI = info[k].atoms[tempI]->getGlobalIndex() + 1;
355 >          exJ = info[k].atoms[tempJ]->getGlobalIndex() + 1;
356 > #else
357 >          exI = tempI + 1;
358 >          exJ = tempJ + 1;
359 > #endif          
360 >          info[k].excludes->addPair(exI, exJ);
361  
362 <  molIndex = 0;
430 <  for(i=0; i<mpiSim->getTotNmol(); i++){
431 <    
432 <    if(mol2proc[i] == worldRank ){
433 <      the_molecules[molIndex].setStampID( molCompType[i] );
434 <      the_molecules[molIndex].setMyIndex( molIndex );
435 <      the_molecules[molIndex].setGlobalIndex( i );
436 <      molIndex++;
437 <    }
438 <  }
362 >        } else {
363  
364 < #else // is_mpi
365 <  
366 <  molIndex = 0;
367 <  globalAtomIndex = 0;
368 <  for(i=0; i<n_components; i++){
369 <    for(j=0; j<components_nmol[i]; j++ ){
370 <      the_molecules[molIndex].setStampID( i );
371 <      the_molecules[molIndex].setMyIndex( molIndex );
372 <      the_molecules[molIndex].setGlobalIndex( molIndex );
373 <      for (k = 0; k < comp_stamps[i]->getNAtoms(); k++) {
374 <        simnfo->molMembershipArray[globalAtomIndex] = molIndex;
375 <        globalAtomIndex++;
364 >          tempI = theBends[j].a;
365 >          tempJ = theBends[j].b;
366 >          tempK = theBends[j].c;
367 >          
368 > #ifdef IS_MPI
369 >          exI = info[k].atoms[tempI]->getGlobalIndex() + 1;
370 >          exJ = info[k].atoms[tempJ]->getGlobalIndex() + 1;
371 >          exK = info[k].atoms[tempK]->getGlobalIndex() + 1;
372 > #else
373 >          exI = tempI + 1;
374 >          exJ = tempJ + 1;
375 >          exK = tempK + 1;
376 > #endif
377 >          
378 >          info[k].excludes->addPair(exI, exK);
379 >          info[k].excludes->addPair(exI, exJ);
380 >          info[k].excludes->addPair(exJ, exK);
381 >        }
382        }
453      molIndex++;
454    }
455  }
456    
383  
384 < #endif // is_mpi
384 >      for (j = 0; j < molInfo.nTorsions; j++){
385 >        currentTorsion = comp_stamps[stampID]->getTorsion(j);
386 >        theTorsions[j].a = currentTorsion->getA() + atomOffset;
387 >        theTorsions[j].b = currentTorsion->getB() + atomOffset;
388 >        theTorsions[j].c = currentTorsion->getC() + atomOffset;
389 >        theTorsions[j].d = currentTorsion->getD() + atomOffset;
390  
391 +        tempI = theTorsions[j].a;      
392 +        tempJ = theTorsions[j].b;
393 +        tempK = theTorsions[j].c;
394 +        tempL = theTorsions[j].d;
395  
396 <  if( simnfo->n_SRI ){
397 <    
398 <    Exclude::createArray(simnfo->n_SRI);
399 <    the_excludes = new Exclude*[simnfo->n_SRI];
400 <    for( int ex=0; ex<simnfo->n_SRI; ex++) the_excludes[ex] = new Exclude(ex);
401 <    simnfo->globalExcludes = new int;
402 <    simnfo->n_exclude = simnfo->n_SRI;
403 <  }
404 <  else{
405 <    
406 <    Exclude::createArray( 1 );
472 <    the_excludes = new Exclude*;
473 <    the_excludes[0] = new Exclude(0);
474 <    the_excludes[0]->setPair( 0,0 );
475 <    simnfo->globalExcludes = new int;
476 <    simnfo->globalExcludes[0] = 0;
477 <    simnfo->n_exclude = 0;
478 <  }
396 > #ifdef IS_MPI
397 >        exI = info[k].atoms[tempI]->getGlobalIndex() + 1;
398 >        exJ = info[k].atoms[tempJ]->getGlobalIndex() + 1;
399 >        exK = info[k].atoms[tempK]->getGlobalIndex() + 1;
400 >        exL = info[k].atoms[tempL]->getGlobalIndex() + 1;
401 > #else
402 >        exI = tempI + 1;
403 >        exJ = tempJ + 1;
404 >        exK = tempK + 1;
405 >        exL = tempL + 1;
406 > #endif
407  
408 <  // set the arrays into the SimInfo object
408 >        info[k].excludes->addPair(exI, exJ);
409 >        info[k].excludes->addPair(exI, exK);
410 >        info[k].excludes->addPair(exI, exL);        
411 >        info[k].excludes->addPair(exJ, exK);
412 >        info[k].excludes->addPair(exJ, exL);
413 >        info[k].excludes->addPair(exK, exL);
414 >      }
415  
416 <  simnfo->atoms = the_atoms;
417 <  simnfo->molecules = the_molecules;
418 <  simnfo->nGlobalExcludes = 0;
419 <  simnfo->excludes = the_excludes;
416 >      
417 >      molInfo.myRigidBodies.clear();
418 >      
419 >      for (j = 0; j < molInfo.nRigidBodies; j++){
420  
421 +        currentRigidBody = comp_stamps[stampID]->getRigidBody(j);
422 +        nMembers = currentRigidBody->getNMembers();
423  
424 <  // get some of the tricky things that may still be in the globals
424 >        // Create the Rigid Body:
425  
426 <  double boxVector[3];
491 <  if( the_globals->haveBox() ){
492 <    boxVector[0] = the_globals->getBox();
493 <    boxVector[1] = the_globals->getBox();
494 <    boxVector[2] = the_globals->getBox();
495 <    
496 <    simnfo->setBox( boxVector );
497 <  }
498 <  else if( the_globals->haveDensity() ){
426 >        myRB = new RigidBody();
427  
428 <    double vol;
429 <    vol = (double)tot_nmol / the_globals->getDensity();
430 <     boxVector[0] = pow( vol, ( 1.0 / 3.0 ) );
431 <     boxVector[1] = boxVector[0];
504 <     boxVector[2] = boxVector[0];
428 >        sprintf(rbName,"%s_RB_%d", molName, j);
429 >        myRB->setType(rbName);
430 >        
431 >        for (rb1 = 0; rb1 < nMembers; rb1++) {
432  
433 <    simnfo->setBox( boxVector );
434 <  }
508 <  else{
509 <    if( !the_globals->haveBoxX() ){
510 <      sprintf( painCave.errMsg,
511 <               "SimSetup error, no periodic BoxX size given.\n" );
512 <      painCave.isFatal = 1;
513 <      simError();
514 <    }
515 <    boxVector[0] = the_globals->getBoxX();
433 >          // molI is atom numbering inside this molecule
434 >          molI = currentRigidBody->getMember(rb1);    
435  
436 <    if( !the_globals->haveBoxY() ){
437 <      sprintf( painCave.errMsg,
519 <               "SimSetup error, no periodic BoxY size given.\n" );
520 <      painCave.isFatal = 1;
521 <      simError();
522 <    }
523 <    boxVector[1] = the_globals->getBoxY();
436 >          // tempI is atom numbering on local processor
437 >          tempI = molI + atomOffset;
438  
439 <    if( !the_globals->haveBoxZ() ){
440 <      sprintf( painCave.errMsg,
441 <               "SimSetup error, no periodic BoxZ size given.\n" );
528 <      painCave.isFatal = 1;
529 <      simError();
530 <    }
531 <    boxVector[2] = the_globals->getBoxZ();
439 >          // currentAtom is the AtomStamp (which we need for
440 >          // rigid body reference positions)
441 >          currentAtom = comp_stamps[stampID]->getAtom(molI);
442  
443 <    simnfo->setBox( boxVector );
444 <  }
443 >          // When we add to the rigid body, add the atom itself and
444 >          // the stamp info:
445  
446 +          myRB->addAtom(info[k].atoms[tempI], currentAtom);
447 +          
448 +          // Add this atom to the Skip List for the integrators
449   #ifdef IS_MPI
450 <  strcpy( checkPointMsg, "Box size set up" );
451 <  MPIcheckPoint();
452 < #endif // is_mpi
450 >          slI = info[k].atoms[tempI]->getGlobalIndex();
451 > #else
452 >          slI = tempI;
453 > #endif
454 >          skipList.insert(slI);
455 >          
456 >        }
457 >        
458 >        for(rb1 = 0; rb1 < nMembers - 1; rb1++) {
459 >          for(rb2 = rb1+1; rb2 < nMembers; rb2++) {
460 >            
461 >            tempI = currentRigidBody->getMember(rb1);
462 >            tempJ = currentRigidBody->getMember(rb2);
463 >            
464 >            // Some explanation is required here.
465 >            // Fortran indexing starts at 1, while c indexing starts at 0
466 >            // Also, in parallel computations, the GlobalIndex is
467 >            // used for the exclude list:
468 >            
469 > #ifdef IS_MPI
470 >            exI = molInfo.myAtoms[tempI]->getGlobalIndex() + 1;
471 >            exJ = molInfo.myAtoms[tempJ]->getGlobalIndex() + 1;
472 > #else
473 >            exI = molInfo.myAtoms[tempI]->getIndex() + 1;
474 >            exJ = molInfo.myAtoms[tempJ]->getIndex() + 1;
475 > #endif
476 >            
477 >            info[k].excludes->addPair(exI, exJ);
478 >            
479 >          }
480 >        }
481  
482 +        molInfo.myRigidBodies.push_back(myRB);
483 +        info[k].rigidBodies.push_back(myRB);
484 +      }
485 +      
486  
487 <  // initialize the arrays
487 >      //creat cutoff group for molecule
488 >      molInfo.myCutoffGroups.clear();
489 >      for (j = 0; j < molInfo.nCutoffGroups; j++){
490  
491 <  the_ff->setSimInfo( simnfo );
491 >        currentCutoffGroup = comp_stamps[stampID]->getCutoffGroup(j);
492 >        nMembers = currentCutoffGroup->getNMembers();
493  
494 <  makeMolecules();
495 <  simnfo->identArray = new int[simnfo->n_atoms];
496 <  for(i=0; i<simnfo->n_atoms; i++){
549 <    simnfo->identArray[i] = the_atoms[i]->getIdent();
550 <  }
551 <  
552 <  if (the_globals->getUseRF() ) {
553 <    simnfo->useReactionField = 1;
554 <  
555 <    if( !the_globals->haveECR() ){
556 <      sprintf( painCave.errMsg,
557 <               "SimSetup Warning: using default value of 1/2 the smallest "
558 <               "box length for the electrostaticCutoffRadius.\n"
559 <               "I hope you have a very fast processor!\n");
560 <      painCave.isFatal = 0;
561 <      simError();
562 <      double smallest;
563 <      smallest = simnfo->boxLx;
564 <      if (simnfo->boxLy <= smallest) smallest = simnfo->boxLy;
565 <      if (simnfo->boxLz <= smallest) smallest = simnfo->boxLz;
566 <      simnfo->ecr = 0.5 * smallest;
567 <    } else {
568 <      simnfo->ecr        = the_globals->getECR();
569 <    }
494 >        myCutoffGroup = new CutoffGroup();
495 >        
496 >        for (int cg = 0; cg < nMembers; cg++) {
497  
498 <    if( !the_globals->haveEST() ){
499 <      sprintf( painCave.errMsg,
500 <               "SimSetup Warning: using default value of 0.05 * the "
501 <               "electrostaticCutoffRadius for the electrostaticSkinThickness\n"
502 <               );
503 <      painCave.isFatal = 0;
504 <      simError();
505 <      simnfo->est = 0.05 * simnfo->ecr;
506 <    } else {
507 <      simnfo->est        = the_globals->getEST();
508 <    }
582 <    
583 <    if(!the_globals->haveDielectric() ){
584 <      sprintf( painCave.errMsg,
585 <               "SimSetup Error: You are trying to use Reaction Field without"
586 <               "setting a dielectric constant!\n"
587 <               );
588 <      painCave.isFatal = 1;
589 <      simError();
590 <    }
591 <    simnfo->dielectric = the_globals->getDielectric();  
592 <  } else {
593 <    if (usesDipoles) {
498 >          // molI is atom numbering inside this molecule
499 >          molI = currentCutoffGroup->getMember(cg);    
500 >
501 >          // tempI is atom numbering on local processor
502 >          tempI = molI + atomOffset;
503 >
504 >          myCutoffGroup->addAtom(info[k].atoms[tempI]);          
505 >        }
506 >
507 >        molInfo.myCutoffGroups.push_back(myCutoffGroup);
508 >      }//end for (j = 0; j < molInfo.nCutoffGroups; j++)
509        
510 <      if( !the_globals->haveECR() ){
511 <        sprintf( painCave.errMsg,
512 <                 "SimSetup Warning: using default value of 1/2 the smallest "
513 <                 "box length for the electrostaticCutoffRadius.\n"
514 <                 "I hope you have a very fast processor!\n");
515 <        painCave.isFatal = 0;
601 <        simError();
602 <        double smallest;
603 <        smallest = simnfo->boxLx;
604 <        if (simnfo->boxLy <= smallest) smallest = simnfo->boxLy;
605 <        if (simnfo->boxLz <= smallest) smallest = simnfo->boxLz;
606 <        simnfo->ecr = 0.5 * smallest;
607 <      } else {
608 <        simnfo->ecr        = the_globals->getECR();
609 <      }
510 >
511 >
512 >      // After this is all set up, scan through the atoms to
513 >      // see if they can be added to the integrableObjects:
514 >
515 >      molInfo.myIntegrableObjects.clear();
516        
611      if( !the_globals->haveEST() ){
612        sprintf( painCave.errMsg,
613                 "SimSetup Warning: using default value of 5%% of the "
614                 "electrostaticCutoffRadius for the "
615                 "electrostaticSkinThickness\n"
616                 );
617        painCave.isFatal = 0;
618        simError();
619        simnfo->est = 0.05 * simnfo->ecr;
620      } else {
621        simnfo->est        = the_globals->getEST();
622      }
623    }
624  }  
517  
518 < #ifdef IS_MPI
627 <  strcpy( checkPointMsg, "electrostatic parameters check out" );
628 <  MPIcheckPoint();
629 < #endif // is_mpi
518 >      for (j = 0; j < molInfo.nAtoms; j++){
519  
631 if( the_globals->haveInitialConfig() ){
632
633     InitializeFromFile* fileInit;
634 #ifdef IS_MPI // is_mpi
635     if( worldRank == 0 ){
636 #endif //is_mpi
637   fileInit = new InitializeFromFile( the_globals->getInitialConfig() );
520   #ifdef IS_MPI
521 <     }else fileInit = new InitializeFromFile( NULL );
521 >        slJ = molInfo.myAtoms[j]->getGlobalIndex();
522 > #else
523 >        slJ = j+atomOffset;
524   #endif
641   fileInit->read_xyz( simnfo ); // default velocities on
525  
526 <   delete fileInit;
644 < }
645 < else{
526 >        // if they aren't on the skip list, then they can be integrated
527  
528 < #ifdef IS_MPI
528 >        if (skipList.find(slJ) == skipList.end()) {
529 >          mySD = (StuntDouble *) molInfo.myAtoms[j];
530 >          info[k].integrableObjects.push_back(mySD);
531 >          molInfo.myIntegrableObjects.push_back(mySD);
532 >        }
533 >      }
534  
535 <  // no init from bass
650 <  
651 <  sprintf( painCave.errMsg,
652 <           "Cannot intialize a parallel simulation without an initial configuration file.\n" );
653 <  painCave.isFatal;
654 <  simError();
655 <  
656 < #else
535 >      // all rigid bodies are integrated:
536  
537 <  initFromBass();
537 >      for (j = 0; j < molInfo.nRigidBodies; j++) {
538 >        mySD = (StuntDouble *) molInfo.myRigidBodies[j];
539 >        info[k].integrableObjects.push_back(mySD);      
540 >        molInfo.myIntegrableObjects.push_back(mySD);
541 >      }
542 >    
543 >      
544 >      // send the arrays off to the forceField for init.
545 >      
546 >      the_ff->initializeAtoms(molInfo.nAtoms, molInfo.myAtoms);
547 >      the_ff->initializeBonds(molInfo.nBonds, molInfo.myBonds, theBonds);
548 >      the_ff->initializeBends(molInfo.nBends, molInfo.myBends, theBends);
549 >      the_ff->initializeTorsions(molInfo.nTorsions, molInfo.myTorsions,
550 >                                 theTorsions);
551  
552 +      info[k].molecules[i].initialize(molInfo);
553  
661 #endif
662 }
554  
555 +      atomOffset += molInfo.nAtoms;
556 +      delete[] theBonds;
557 +      delete[] theBends;
558 +      delete[] theTorsions;
559 +    }    
560 +  }
561 +
562   #ifdef IS_MPI
563 <  strcpy( checkPointMsg, "Successfully read in the initial configuration" );
563 >  sprintf(checkPointMsg, "all molecules initialized succesfully");
564    MPIcheckPoint();
565   #endif // is_mpi
566  
567 +  // clean up the forcefield
568  
569 <  
671 <
672 <  
569 >  if (!globals->haveRcut()){
570  
571 <  
572 < #ifdef IS_MPI
573 <  if( worldRank == 0 ){
677 < #endif // is_mpi
571 >    the_ff->calcRcut();
572 >
573 >  } else {
574      
575 <    if( the_globals->haveFinalConfig() ){
576 <      strcpy( simnfo->finalName, the_globals->getFinalConfig() );
575 >    the_ff->setRcut( globals->getRcut() );
576 >  }
577 >
578 >  the_ff->cleanMe();
579 > }
580 >
581 > void SimSetup::initFromBass(void){
582 >  int i, j, k;
583 >  int n_cells;
584 >  double cellx, celly, cellz;
585 >  double temp1, temp2, temp3;
586 >  int n_per_extra;
587 >  int n_extra;
588 >  int have_extra, done;
589 >
590 >  double vel[3];
591 >  vel[0] = 0.0;
592 >  vel[1] = 0.0;
593 >  vel[2] = 0.0;
594 >
595 >  temp1 = (double) tot_nmol / 4.0;
596 >  temp2 = pow(temp1, (1.0 / 3.0));
597 >  temp3 = ceil(temp2);
598 >
599 >  have_extra = 0;
600 >  if (temp2 < temp3){
601 >    // we have a non-complete lattice
602 >    have_extra = 1;
603 >
604 >    n_cells = (int) temp3 - 1;
605 >    cellx = info[0].boxL[0] / temp3;
606 >    celly = info[0].boxL[1] / temp3;
607 >    cellz = info[0].boxL[2] / temp3;
608 >    n_extra = tot_nmol - (4 * n_cells * n_cells * n_cells);
609 >    temp1 = ((double) n_extra) / (pow(temp3, 3.0) - pow(n_cells, 3.0));
610 >    n_per_extra = (int) ceil(temp1);
611 >
612 >    if (n_per_extra > 4){
613 >      sprintf(painCave.errMsg,
614 >              "SimSetup error. There has been an error in constructing"
615 >              " the non-complete lattice.\n");
616 >      painCave.isFatal = 1;
617 >      simError();
618      }
682    else{
683      strcpy( simnfo->finalName, inFileName );
684      char* endTest;
685      int nameLength = strlen( simnfo->finalName );
686      endTest = &(simnfo->finalName[nameLength - 5]);
687      if( !strcmp( endTest, ".bass" ) ){
688        strcpy( endTest, ".eor" );
689      }
690      else if( !strcmp( endTest, ".BASS" ) ){
691        strcpy( endTest, ".eor" );
692      }
693      else{
694        endTest = &(simnfo->finalName[nameLength - 4]);
695        if( !strcmp( endTest, ".bss" ) ){
696          strcpy( endTest, ".eor" );
697        }
698        else if( !strcmp( endTest, ".mdl" ) ){
699          strcpy( endTest, ".eor" );
700        }
701        else{
702          strcat( simnfo->finalName, ".eor" );
703        }
704      }
705    }
706    
707    // make the sample and status out names
708    
709    strcpy( simnfo->sampleName, inFileName );
710    char* endTest;
711    int nameLength = strlen( simnfo->sampleName );
712    endTest = &(simnfo->sampleName[nameLength - 5]);
713    if( !strcmp( endTest, ".bass" ) ){
714      strcpy( endTest, ".dump" );
715    }
716    else if( !strcmp( endTest, ".BASS" ) ){
717      strcpy( endTest, ".dump" );
718    }
719    else{
720      endTest = &(simnfo->sampleName[nameLength - 4]);
721      if( !strcmp( endTest, ".bss" ) ){
722        strcpy( endTest, ".dump" );
723      }
724      else if( !strcmp( endTest, ".mdl" ) ){
725        strcpy( endTest, ".dump" );
726      }
727      else{
728        strcat( simnfo->sampleName, ".dump" );
729      }
730    }
731    
732    strcpy( simnfo->statusName, inFileName );
733    nameLength = strlen( simnfo->statusName );
734    endTest = &(simnfo->statusName[nameLength - 5]);
735    if( !strcmp( endTest, ".bass" ) ){
736      strcpy( endTest, ".stat" );
737    }
738    else if( !strcmp( endTest, ".BASS" ) ){
739      strcpy( endTest, ".stat" );
740    }
741    else{
742      endTest = &(simnfo->statusName[nameLength - 4]);
743      if( !strcmp( endTest, ".bss" ) ){
744        strcpy( endTest, ".stat" );
745      }
746      else if( !strcmp( endTest, ".mdl" ) ){
747        strcpy( endTest, ".stat" );
748      }
749      else{
750        strcat( simnfo->statusName, ".stat" );
751      }
752    }
753    
754 #ifdef IS_MPI
619    }
756 #endif // is_mpi
757  
758  // set the status, sample, and themal kick times
759  
760  if( the_globals->haveSampleTime() ){
761    simnfo->sampleTime = the_globals->getSampleTime();
762    simnfo->statusTime = simnfo->sampleTime;
763    simnfo->thermalTime = simnfo->sampleTime;
764  }
620    else{
621 <    simnfo->sampleTime = the_globals->getRunTime();
622 <    simnfo->statusTime = simnfo->sampleTime;
623 <    simnfo->thermalTime = simnfo->sampleTime;
621 >    n_cells = (int) temp3;
622 >    cellx = info[0].boxL[0] / temp3;
623 >    celly = info[0].boxL[1] / temp3;
624 >    cellz = info[0].boxL[2] / temp3;
625    }
626  
627 <  if( the_globals->haveStatusTime() ){
628 <    simnfo->statusTime = the_globals->getStatusTime();
629 <  }
627 >  current_mol = 0;
628 >  current_comp_mol = 0;
629 >  current_comp = 0;
630 >  current_atom_ndx = 0;
631  
632 <  if( the_globals->haveThermalTime() ){
633 <    simnfo->thermalTime = the_globals->getThermalTime();
634 <  }
632 >  for (i = 0; i < n_cells ; i++){
633 >    for (j = 0; j < n_cells; j++){
634 >      for (k = 0; k < n_cells; k++){
635 >        makeElement(i * cellx, j * celly, k * cellz);
636  
637 <  // check for the temperature set flag
637 >        makeElement(i * cellx + 0.5 * cellx, j * celly + 0.5 * celly, k * cellz);
638  
639 <  if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet();
639 >        makeElement(i * cellx, j * celly + 0.5 * celly, k * cellz + 0.5 * cellz);
640  
641 +        makeElement(i * cellx + 0.5 * cellx, j * celly, k * cellz + 0.5 * cellz);
642 +      }
643 +    }
644 +  }
645  
646 <  // make the integrator
647 <  
786 <  
787 <  NVT*  myNVT = NULL;
788 <  NPTi* myNPTi = NULL;
789 <  NPTf* myNPTf = NULL;
790 <  NPTim* myNPTim = NULL;
646 >  if (have_extra){
647 >    done = 0;
648  
649 <  switch( ensembleCase ){
649 >    int start_ndx;
650 >    for (i = 0; i < (n_cells + 1) && !done; i++){
651 >      for (j = 0; j < (n_cells + 1) && !done; j++){
652 >        if (i < n_cells){
653 >          if (j < n_cells){
654 >            start_ndx = n_cells;
655 >          }
656 >          else
657 >            start_ndx = 0;
658 >        }
659 >        else
660 >          start_ndx = 0;
661  
662 <  case NVE_ENS:
663 <    new NVE( simnfo, the_ff );
664 <    break;
662 >        for (k = start_ndx; k < (n_cells + 1) && !done; k++){
663 >          makeElement(i * cellx, j * celly, k * cellz);
664 >          done = (current_mol >= tot_nmol);
665  
666 <  case NVT_ENS:
667 <    myNVT = new NVT( simnfo, the_ff );
668 <    myNVT->setTargetTemp(the_globals->getTargetTemp());
666 >          if (!done && n_per_extra > 1){
667 >            makeElement(i * cellx + 0.5 * cellx, j * celly + 0.5 * celly,
668 >                        k * cellz);
669 >            done = (current_mol >= tot_nmol);
670 >          }
671  
672 <    if (the_globals->haveTauThermostat())
673 <      myNVT->setTauThermostat(the_globals->getTauThermostat());
672 >          if (!done && n_per_extra > 2){
673 >            makeElement(i * cellx, j * celly + 0.5 * celly,
674 >                        k * cellz + 0.5 * cellz);
675 >            done = (current_mol >= tot_nmol);
676 >          }
677  
678 <    else {
679 <      sprintf( painCave.errMsg,
680 <               "SimSetup error: If you use the NVT\n"
681 <               "    ensemble, you must set tauThermostat.\n");
682 <      painCave.isFatal = 1;
683 <      simError();
678 >          if (!done && n_per_extra > 3){
679 >            makeElement(i * cellx + 0.5 * cellx, j * celly,
680 >                        k * cellz + 0.5 * cellz);
681 >            done = (current_mol >= tot_nmol);
682 >          }
683 >        }
684 >      }
685      }
686 <    break;
686 >  }
687  
688 <  case NPTi_ENS:
689 <    myNPTi = new NPTi( simnfo, the_ff );
690 <    myNPTi->setTargetTemp( the_globals->getTargetTemp());
688 >  for (i = 0; i < info[0].n_atoms; i++){
689 >    info[0].atoms[i]->setVel(vel);
690 >  }
691 > }
692  
693 <    if (the_globals->haveTargetPressure())
694 <      myNPTi->setTargetPressure(the_globals->getTargetPressure());
695 <    else {
696 <      sprintf( painCave.errMsg,
697 <               "SimSetup error: If you use a constant pressure\n"
698 <               "    ensemble, you must set targetPressure in the BASS file.\n");
824 <      painCave.isFatal = 1;
825 <      simError();
826 <    }
827 <    
828 <    if( the_globals->haveTauThermostat() )
829 <      myNPTi->setTauThermostat( the_globals->getTauThermostat() );
830 <    else{
831 <      sprintf( painCave.errMsg,
832 <               "SimSetup error: If you use an NPT\n"
833 <               "    ensemble, you must set tauThermostat.\n");
834 <      painCave.isFatal = 1;
835 <      simError();
836 <    }
693 > void SimSetup::makeElement(double x, double y, double z){
694 >  int k;
695 >  AtomStamp* current_atom;
696 >  DirectionalAtom* dAtom;
697 >  double rotMat[3][3];
698 >  double pos[3];
699  
700 <    if( the_globals->haveTauBarostat() )
701 <      myNPTi->setTauBarostat( the_globals->getTauBarostat() );
702 <    else{
703 <      sprintf( painCave.errMsg,
704 <               "SimSetup error: If you use an NPT\n"
705 <               "    ensemble, you must set tauBarostat.\n");
700 >  for (k = 0; k < comp_stamps[current_comp]->getNAtoms(); k++){
701 >    current_atom = comp_stamps[current_comp]->getAtom(k);
702 >    if (!current_atom->havePosition()){
703 >      sprintf(painCave.errMsg,
704 >              "SimSetup:initFromBass error.\n"
705 >              "\tComponent %s, atom %s does not have a position specified.\n"
706 >              "\tThe initialization routine is unable to give a start"
707 >              " position.\n",
708 >              comp_stamps[current_comp]->getID(), current_atom->getType());
709        painCave.isFatal = 1;
710        simError();
711      }
847    break;
712  
713 <  case NPTf_ENS:
714 <    myNPTf = new NPTf( simnfo, the_ff );
715 <    myNPTf->setTargetTemp( the_globals->getTargetTemp());
713 >    pos[0] = x + current_atom->getPosX();
714 >    pos[1] = y + current_atom->getPosY();
715 >    pos[2] = z + current_atom->getPosZ();
716  
717 <    if (the_globals->haveTargetPressure())
854 <      myNPTf->setTargetPressure(the_globals->getTargetPressure());
855 <    else {
856 <      sprintf( painCave.errMsg,
857 <               "SimSetup error: If you use a constant pressure\n"
858 <               "    ensemble, you must set targetPressure in the BASS file.\n");
859 <      painCave.isFatal = 1;
860 <      simError();
861 <    }    
717 >    info[0].atoms[current_atom_ndx]->setPos(pos);
718  
719 <    if( the_globals->haveTauThermostat() )
720 <      myNPTf->setTauThermostat( the_globals->getTauThermostat() );
865 <    else{
866 <      sprintf( painCave.errMsg,
867 <               "SimSetup error: If you use an NPT\n"
868 <               "    ensemble, you must set tauThermostat.\n");
869 <      painCave.isFatal = 1;
870 <      simError();
871 <    }
719 >    if (info[0].atoms[current_atom_ndx]->isDirectional()){
720 >      dAtom = (DirectionalAtom *) info[0].atoms[current_atom_ndx];
721  
722 <    if( the_globals->haveTauBarostat() )
723 <      myNPTf->setTauBarostat( the_globals->getTauBarostat() );
724 <    else{
876 <      sprintf( painCave.errMsg,
877 <               "SimSetup error: If you use an NPT\n"
878 <               "    ensemble, you must set tauBarostat.\n");
879 <      painCave.isFatal = 1;
880 <      simError();
881 <    }
882 <    break;
883 <    
884 <  case NPTim_ENS:
885 <    myNPTim = new NPTim( simnfo, the_ff );
886 <    myNPTim->setTargetTemp( the_globals->getTargetTemp());
722 >      rotMat[0][0] = 1.0;
723 >      rotMat[0][1] = 0.0;
724 >      rotMat[0][2] = 0.0;
725  
726 <    if (the_globals->haveTargetPressure())
727 <      myNPTim->setTargetPressure(the_globals->getTargetPressure());
728 <    else {
891 <      sprintf( painCave.errMsg,
892 <               "SimSetup error: If you use a constant pressure\n"
893 <               "    ensemble, you must set targetPressure in the BASS file.\n");
894 <      painCave.isFatal = 1;
895 <      simError();
896 <    }
897 <    
898 <    if( the_globals->haveTauThermostat() )
899 <      myNPTim->setTauThermostat( the_globals->getTauThermostat() );
900 <    else{
901 <      sprintf( painCave.errMsg,
902 <               "SimSetup error: If you use an NPT\n"
903 <               "    ensemble, you must set tauThermostat.\n");
904 <      painCave.isFatal = 1;
905 <      simError();
906 <    }
726 >      rotMat[1][0] = 0.0;
727 >      rotMat[1][1] = 1.0;
728 >      rotMat[1][2] = 0.0;
729  
730 <    if( the_globals->haveTauBarostat() )
731 <      myNPTim->setTauBarostat( the_globals->getTauBarostat() );
732 <    else{
733 <      sprintf( painCave.errMsg,
734 <               "SimSetup error: If you use an NPT\n"
913 <               "    ensemble, you must set tauBarostat.\n");
914 <      painCave.isFatal = 1;
915 <      simError();
730 >      rotMat[2][0] = 0.0;
731 >      rotMat[2][1] = 0.0;
732 >      rotMat[2][2] = 1.0;
733 >
734 >      dAtom->setA(rotMat);
735      }
917    break;
736  
737 <    
737 >    current_atom_ndx++;
738 >  }
739  
740 <  default:
741 <    sprintf( painCave.errMsg,
742 <             "SimSetup Error. Unrecognized ensemble in case statement.\n");
743 <    painCave.isFatal = 1;
744 <    simError();
740 >  current_mol++;
741 >  current_comp_mol++;
742 >
743 >  if (current_comp_mol >= components_nmol[current_comp]){
744 >    current_comp_mol = 0;
745 >    current_comp++;
746    }
747 + }
748  
749  
750 < #ifdef IS_MPI
751 <  mpiSim->mpiRefresh();
931 < #endif
750 > void SimSetup::gatherInfo(void){
751 >  int i;
752  
753 <  // initialize the Fortran
753 >  ensembleCase = -1;
754 >  ffCase = -1;
755  
756 +  // set the easy ones first
757  
758 <  simnfo->refreshSim();
759 <  
760 <  if( !strcmp( simnfo->mixingRule, "standard") ){
761 <    the_ff->initForceField( LB_MIXING_RULE );
758 >  for (i = 0; i < nInfo; i++){
759 >    info[i].target_temp = globals->getTargetTemp();
760 >    info[i].dt = globals->getDt();
761 >    info[i].run_time = globals->getRunTime();
762    }
763 <  else if( !strcmp( simnfo->mixingRule, "explicit") ){
764 <    the_ff->initForceField( EXPLICIT_MIXING_RULE );
763 >  n_components = globals->getNComponents();
764 >
765 >
766 >  // get the forceField
767 >
768 >  strcpy(force_field, globals->getForceField());
769 >
770 >  if (!strcasecmp(force_field, "DUFF")){
771 >    ffCase = FF_DUFF;
772    }
773 +  else if (!strcasecmp(force_field, "LJ")){
774 +    ffCase = FF_LJ;
775 +  }
776 +  else if (!strcasecmp(force_field, "EAM")){
777 +    ffCase = FF_EAM;
778 +  }
779 +  else if (!strcasecmp(force_field, "WATER")){
780 +    ffCase = FF_H2O;
781 +  }
782    else{
783 <    sprintf( painCave.errMsg,
784 <             "SimSetup Error: unknown mixing rule -> \"%s\"\n",
785 <             simnfo->mixingRule );
786 <    painCave.isFatal = 1;
949 <    simError();
783 >    sprintf(painCave.errMsg, "SimSetup Error. Unrecognized force field -> %s\n",
784 >            force_field);
785 >         painCave.isFatal = 1;
786 >         simError();
787    }
788  
789 +    // get the ensemble
790  
791 < #ifdef IS_MPI
954 <  strcpy( checkPointMsg,
955 <          "Successfully intialized the mixingRule for Fortran." );
956 <  MPIcheckPoint();
957 < #endif // is_mpi
958 < }
791 >  strcpy(ensemble, globals->getEnsemble());
792  
793 +  if (!strcasecmp(ensemble, "NVE")){
794 +    ensembleCase = NVE_ENS;
795 +  }
796 +  else if (!strcasecmp(ensemble, "NVT")){
797 +    ensembleCase = NVT_ENS;
798 +  }
799 +  else if (!strcasecmp(ensemble, "NPTi") || !strcasecmp(ensemble, "NPT")){
800 +    ensembleCase = NPTi_ENS;
801 +  }
802 +  else if (!strcasecmp(ensemble, "NPTf")){
803 +    ensembleCase = NPTf_ENS;
804 +  }
805 +  else if (!strcasecmp(ensemble, "NPTxyz")){
806 +    ensembleCase = NPTxyz_ENS;
807 +  }
808 +  else{
809 +    sprintf(painCave.errMsg,
810 +            "SimSetup Warning. Unrecognized Ensemble -> %s \n"
811 +            "\treverting to NVE for this simulation.\n",
812 +            ensemble);
813 +         painCave.isFatal = 0;
814 +         simError();
815 +         strcpy(ensemble, "NVE");
816 +         ensembleCase = NVE_ENS;
817 +  }  
818  
819 < void SimSetup::makeMolecules( void ){
819 >  for (i = 0; i < nInfo; i++){
820 >    strcpy(info[i].ensemble, ensemble);
821  
822 <  int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset;
964 <  molInit info;
965 <  DirectionalAtom* dAtom;
966 <  LinkedAssign* extras;
967 <  LinkedAssign* current_extra;
968 <  AtomStamp* currentAtom;
969 <  BondStamp* currentBond;
970 <  BendStamp* currentBend;
971 <  TorsionStamp* currentTorsion;
822 >    // get the mixing rule
823  
824 <  bond_pair* theBonds;
825 <  bend_set* theBends;
826 <  torsion_set* theTorsions;
824 >    strcpy(info[i].mixingRule, globals->getMixingRule());
825 >    info[i].usePBC = globals->getPBC();
826 >  }
827  
828 <  
978 <  //init the forceField paramters
828 >  // get the components and calculate the tot_nMol and indvidual n_mol
829  
830 <  the_ff->readParams();
830 >  the_components = globals->getComponents();
831 >  components_nmol = new int[n_components];
832  
982  
983  // init the atoms
833  
834 <  double ux, uy, uz, u, uSqr;
835 <  
836 <  atomOffset = 0;
988 <  excludeOffset = 0;
989 <  for(i=0; i<simnfo->n_mol; i++){
990 <    
991 <    stampID = the_molecules[i].getStampID();
834 >  if (!globals->haveNMol()){
835 >    // we don't have the total number of molecules, so we assume it is
836 >    // given in each component
837  
838 <    info.nAtoms    = comp_stamps[stampID]->getNAtoms();
839 <    info.nBonds    = comp_stamps[stampID]->getNBonds();
840 <    info.nBends    = comp_stamps[stampID]->getNBends();
841 <    info.nTorsions = comp_stamps[stampID]->getNTorsions();
842 <    info.nExcludes = info.nBonds + info.nBends + info.nTorsions;
838 >    tot_nmol = 0;
839 >    for (i = 0; i < n_components; i++){
840 >      if (!the_components[i]->haveNMol()){
841 >        // we have a problem
842 >        sprintf(painCave.errMsg,
843 >                "SimSetup Error. No global NMol or component NMol given.\n"
844 >                "\tCannot calculate the number of atoms.\n");
845 >        painCave.isFatal = 1;
846 >        simError();
847 >      }
848  
849 <    info.myAtoms = &the_atoms[atomOffset];
850 <    info.myExcludes = &the_excludes[excludeOffset];
851 <    info.myBonds = new Bond*[info.nBonds];
852 <    info.myBends = new Bend*[info.nBends];
853 <    info.myTorsions = new Torsion*[info.nTorsions];
849 >      tot_nmol += the_components[i]->getNMol();
850 >      components_nmol[i] = the_components[i]->getNMol();
851 >    }
852 >  }
853 >  else{
854 >    sprintf(painCave.errMsg,
855 >            "SimSetup error.\n"
856 >            "\tSorry, the ability to specify total"
857 >            " nMols and then give molfractions in the components\n"
858 >            "\tis not currently supported."
859 >            " Please give nMol in the components.\n");
860 >    painCave.isFatal = 1;
861 >    simError();
862 >  }
863  
864 <    theBonds = new bond_pair[info.nBonds];
865 <    theBends = new bend_set[info.nBends];
866 <    theTorsions = new torsion_set[info.nTorsions];
867 <    
868 <    // make the Atoms
869 <    
870 <    for(j=0; j<info.nAtoms; j++){
871 <      
872 <      currentAtom = comp_stamps[stampID]->getAtom( j );
873 <      if( currentAtom->haveOrientation() ){
874 <        
875 <        dAtom = new DirectionalAtom(j + atomOffset);
876 <        simnfo->n_oriented++;
877 <        info.myAtoms[j] = dAtom;
878 <        
879 <        ux = currentAtom->getOrntX();
880 <        uy = currentAtom->getOrntY();
881 <        uz = currentAtom->getOrntZ();
882 <        
883 <        uSqr = (ux * ux) + (uy * uy) + (uz * uz);
884 <        
885 <        u = sqrt( uSqr );
886 <        ux = ux / u;
887 <        uy = uy / u;
888 <        uz = uz / u;
889 <        
890 <        dAtom->setSUx( ux );
891 <        dAtom->setSUy( uy );
892 <        dAtom->setSUz( uz );
893 <      }
894 <      else{
895 <        info.myAtoms[j] = new GeneralAtom(j + atomOffset);
896 <      }
897 <      info.myAtoms[j]->setType( currentAtom->getType() );
864 >  //check whether sample time, status time, thermal time and reset time are divisble by dt
865 >  if (globals->haveSampleTime() && !isDivisible(globals->getSampleTime(), globals->getDt())){
866 >    sprintf(painCave.errMsg,
867 >            "Sample time is not divisible by dt.\n"
868 >            "\tThis will result in samples that are not uniformly\n"
869 >            "\tdistributed in time.  If this is a problem, change\n"
870 >            "\tyour sampleTime variable.\n");
871 >    painCave.isFatal = 0;
872 >    simError();    
873 >  }
874 >
875 >  if (globals->haveStatusTime() && !isDivisible(globals->getStatusTime(), globals->getDt())){
876 >    sprintf(painCave.errMsg,
877 >            "Status time is not divisible by dt.\n"
878 >            "\tThis will result in status reports that are not uniformly\n"
879 >            "\tdistributed in time.  If this is a problem, change \n"
880 >            "\tyour statusTime variable.\n");
881 >    painCave.isFatal = 0;
882 >    simError();    
883 >  }
884 >
885 >  if (globals->haveThermalTime() && !isDivisible(globals->getThermalTime(), globals->getDt())){
886 >    sprintf(painCave.errMsg,
887 >            "Thermal time is not divisible by dt.\n"
888 >            "\tThis will result in thermalizations that are not uniformly\n"
889 >            "\tdistributed in time.  If this is a problem, change \n"
890 >            "\tyour thermalTime variable.\n");
891 >    painCave.isFatal = 0;
892 >    simError();    
893 >  }  
894 >
895 >  if (globals->haveResetTime() && !isDivisible(globals->getResetTime(), globals->getDt())){
896 >    sprintf(painCave.errMsg,
897 >            "Reset time is not divisible by dt.\n"
898 >            "\tThis will result in integrator resets that are not uniformly\n"
899 >            "\tdistributed in time.  If this is a problem, change\n"
900 >            "\tyour resetTime variable.\n");
901 >    painCave.isFatal = 0;
902 >    simError();    
903 >  }
904 >
905 >  // set the status, sample, and thermal kick times
906 >
907 >  for (i = 0; i < nInfo; i++){
908 >    if (globals->haveSampleTime()){
909 >      info[i].sampleTime = globals->getSampleTime();
910 >      info[i].statusTime = info[i].sampleTime;
911 >    }
912 >    else{
913 >      info[i].sampleTime = globals->getRunTime();
914 >      info[i].statusTime = info[i].sampleTime;
915 >    }
916 >
917 >    if (globals->haveStatusTime()){
918 >      info[i].statusTime = globals->getStatusTime();
919 >    }
920 >
921 >    if (globals->haveThermalTime()){
922 >      info[i].thermalTime = globals->getThermalTime();
923 >    } else {
924 >      info[i].thermalTime = globals->getRunTime();
925 >    }
926 >
927 >    info[i].resetIntegrator = 0;
928 >    if( globals->haveResetTime() ){
929 >      info[i].resetTime = globals->getResetTime();
930 >      info[i].resetIntegrator = 1;
931 >    }
932 >
933 >    // check for the temperature set flag
934      
935 < #ifdef IS_MPI
936 <      
937 <      info.myAtoms[j]->setGlobalIndex( globalIndex[j+atomOffset] );
938 <      
939 < #endif // is_mpi
940 <    }
935 >    if (globals->haveTempSet())
936 >      info[i].setTemp = globals->getTempSet();
937 >
938 >    // check for the extended State init
939 >
940 >    info[i].useInitXSstate = globals->getUseInitXSstate();
941 >    info[i].orthoTolerance = globals->getOrthoBoxTolerance();
942      
943 <    // make the bonds
944 <    for(j=0; j<info.nBonds; j++){
945 <      
946 <      currentBond = comp_stamps[stampID]->getBond( j );
1051 <      theBonds[j].a = currentBond->getA() + atomOffset;
1052 <      theBonds[j].b = currentBond->getB() + atomOffset;
943 >  }
944 >  
945 >  //setup seed for random number generator
946 >  int seedValue;
947  
948 <      exI = theBonds[j].a;
949 <      exJ = theBonds[j].b;
948 >  if (globals->haveSeed()){
949 >    seedValue = globals->getSeed();
950  
951 <      // exclude_I must always be the smaller of the pair
952 <      if( exI > exJ ){
953 <        tempEx = exI;
954 <        exI = exJ;
955 <        exJ = tempEx;
951 >    if(seedValue / 1E9 == 0){
952 >      sprintf(painCave.errMsg,
953 >              "Seed for sprng library should contain at least 9 digits\n"
954 >              "OOPSE will generate a seed for user\n");
955 >      painCave.isFatal = 0;
956 >      simError();
957 >
958 >      //using seed generated by system instead of invalid seed set by user
959 > #ifndef IS_MPI
960 >      seedValue = make_sprng_seed();
961 > #else
962 >      if (worldRank == 0){
963 >        seedValue = make_sprng_seed();
964        }
965 +      MPI_Bcast(&seedValue, 1, MPI_INT, 0, MPI_COMM_WORLD);  
966 + #endif      
967 +    }
968 +  }//end of if branch of globals->haveSeed()
969 +  else{
970 +    
971 + #ifndef IS_MPI
972 +    seedValue = make_sprng_seed();
973 + #else
974 +    if (worldRank == 0){
975 +      seedValue = make_sprng_seed();
976 +    }
977 +    MPI_Bcast(&seedValue, 1, MPI_INT, 0, MPI_COMM_WORLD);  
978 + #endif
979 +  }//end of globals->haveSeed()
980 +
981 +  for (int i = 0; i < nInfo; i++){
982 +    info[i].setSeed(seedValue);
983 +  }
984 +  
985   #ifdef IS_MPI
986 <      tempEx = exI;
987 <      exI = the_atoms[tempEx]->getGlobalIndex() + 1;
988 <      tempEx = exJ;
989 <      exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
1068 <      
1069 <      the_excludes[j+excludeOffset]->setPair( exI, exJ );
1070 < #else  // isn't MPI
986 >  strcpy(checkPointMsg, "Successfully gathered all information from Bass\n");
987 >  MPIcheckPoint();
988 > #endif // is_mpi
989 > }
990  
991 <      the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
992 < #endif  //is_mpi
991 >
992 > void SimSetup::finalInfoCheck(void){
993 >  int index;
994 >  int usesDipoles;
995 >  int usesCharges;
996 >  int i;
997 >
998 >  for (i = 0; i < nInfo; i++){
999 >    // check electrostatic parameters
1000 >
1001 >    index = 0;
1002 >    usesDipoles = 0;
1003 >    while ((index < info[i].n_atoms) && !usesDipoles){
1004 >      usesDipoles = (info[i].atoms[index])->hasDipole();
1005 >      index++;
1006      }
1007 <    excludeOffset += info.nBonds;
1007 >    index = 0;
1008 >    usesCharges = 0;
1009 >    while ((index < info[i].n_atoms) && !usesCharges){
1010 >      usesCharges= (info[i].atoms[index])->hasCharge();
1011 >      index++;
1012 >    }
1013 > #ifdef IS_MPI
1014 >    int myUse = usesDipoles;
1015 >    MPI_Allreduce(&myUse, &usesDipoles, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
1016 > #endif //is_mpi
1017  
1018 <    //make the bends
1019 <    for(j=0; j<info.nBends; j++){
1020 <      
1021 <      currentBend = comp_stamps[stampID]->getBend( j );
1022 <      theBends[j].a = currentBend->getA() + atomOffset;
1023 <      theBends[j].b = currentBend->getB() + atomOffset;
1024 <      theBends[j].c = currentBend->getC() + atomOffset;
1025 <          
1026 <      if( currentBend->haveExtras() ){
1027 <            
1028 <        extras = currentBend->getExtras();
1029 <        current_extra = extras;
1030 <            
1090 <        while( current_extra != NULL ){
1091 <          if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){
1092 <                
1093 <            switch( current_extra->getType() ){
1094 <              
1095 <            case 0:
1096 <              theBends[j].ghost =
1097 <                current_extra->getInt() + atomOffset;
1098 <              theBends[j].isGhost = 1;
1099 <              break;
1100 <                  
1101 <            case 1:
1102 <              theBends[j].ghost =
1103 <                (int)current_extra->getDouble() + atomOffset;
1104 <              theBends[j].isGhost = 1;
1105 <              break;
1106 <              
1107 <            default:
1108 <              sprintf( painCave.errMsg,
1109 <                       "SimSetup Error: ghostVectorSource was neither a "
1110 <                       "double nor an int.\n"
1111 <                       "-->Bend[%d] in %s\n",
1112 <                       j, comp_stamps[stampID]->getID() );
1113 <              painCave.isFatal = 1;
1114 <              simError();
1115 <            }
1116 <          }
1117 <          
1118 <          else{
1119 <            
1120 <            sprintf( painCave.errMsg,
1121 <                     "SimSetup Error: unhandled bend assignment:\n"
1122 <                     "    -->%s in Bend[%d] in %s\n",
1123 <                     current_extra->getlhs(),
1124 <                     j, comp_stamps[stampID]->getID() );
1125 <            painCave.isFatal = 1;
1126 <            simError();
1127 <          }
1128 <          
1129 <          current_extra = current_extra->getNext();
1130 <        }
1018 >    double theRcut, theRsw;
1019 >
1020 >    if (globals->getUseRF()){
1021 >      info[i].useReactionField = 1;
1022 >
1023 >      if (!globals->haveRcut()){
1024 >        sprintf(painCave.errMsg,
1025 >                "SimSetup Warning: No value was set for the cutoffRadius.\n"
1026 >                "\tOOPSE will use a default value of 15.0 angstroms"
1027 >                "\tfor the cutoffRadius.\n");
1028 >        painCave.isFatal = 0;
1029 >        simError();
1030 >        theRcut = 15.0;
1031        }
1032 <          
1033 <      if( !theBends[j].isGhost ){
1134 <            
1135 <        exI = theBends[j].a;
1136 <        exJ = theBends[j].c;
1032 >      else{
1033 >        theRcut = globals->getRcut();
1034        }
1035 +
1036 +      if (!globals->haveRsw()){
1037 +        sprintf(painCave.errMsg,
1038 +                "SimSetup Warning: No value was set for switchingRadius.\n"
1039 +                "\tOOPSE will use a default value of\n"
1040 +                "\t0.95 * cutoffRadius for the switchingRadius\n");
1041 +        painCave.isFatal = 0;
1042 +        simError();
1043 +        theRsw = 0.95 * theRcut;
1044 +      }
1045        else{
1046 <        
1140 <        exI = theBends[j].a;
1141 <        exJ = theBends[j].b;
1046 >        theRsw = globals->getRsw();
1047        }
1048 <      
1049 <      // exclude_I must always be the smaller of the pair
1050 <      if( exI > exJ ){
1051 <        tempEx = exI;
1052 <        exI = exJ;
1053 <        exJ = tempEx;
1048 >
1049 >      info[i].setDefaultRcut(theRcut, theRsw);
1050 >
1051 >      if (!globals->haveDielectric()){
1052 >        sprintf(painCave.errMsg,
1053 >                "SimSetup Error: No Dielectric constant was set.\n"
1054 >                "\tYou are trying to use Reaction Field without"
1055 >                "\tsetting a dielectric constant!\n");
1056 >        painCave.isFatal = 1;
1057 >        simError();
1058        }
1059 < #ifdef IS_MPI
1151 <      tempEx = exI;
1152 <      exI = the_atoms[tempEx]->getGlobalIndex() + 1;
1153 <      tempEx = exJ;
1154 <      exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
1155 <      
1156 <      the_excludes[j+excludeOffset]->setPair( exI, exJ );
1157 < #else  // isn't MPI
1158 <      the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
1159 < #endif  //is_mpi
1059 >      info[i].dielectric = globals->getDielectric();
1060      }
1061 <    excludeOffset += info.nBends;
1061 >    else{
1062 >      if (usesDipoles || usesCharges){
1063  
1064 <    for(j=0; j<info.nTorsions; j++){
1065 <      
1066 <      currentTorsion = comp_stamps[stampID]->getTorsion( j );
1067 <      theTorsions[j].a = currentTorsion->getA() + atomOffset;
1068 <      theTorsions[j].b = currentTorsion->getB() + atomOffset;
1069 <      theTorsions[j].c = currentTorsion->getC() + atomOffset;
1070 <      theTorsions[j].d = currentTorsion->getD() + atomOffset;
1071 <      
1171 <      exI = theTorsions[j].a;
1172 <      exJ = theTorsions[j].d;
1173 <
1174 <      // exclude_I must always be the smaller of the pair
1175 <      if( exI > exJ ){
1176 <        tempEx = exI;
1177 <        exI = exJ;
1178 <        exJ = tempEx;
1064 >        if (!globals->haveRcut()){
1065 >          sprintf(painCave.errMsg,
1066 >                  "SimSetup Warning: No value was set for the cutoffRadius.\n"
1067 >                  "\tOOPSE will use a default value of 15.0 angstroms"
1068 >                  "\tfor the cutoffRadius.\n");
1069 >          painCave.isFatal = 0;
1070 >          simError();
1071 >          theRcut = 15.0;
1072        }
1073 < #ifdef IS_MPI
1074 <      tempEx = exI;
1075 <      exI = the_atoms[tempEx]->getGlobalIndex() + 1;
1076 <      tempEx = exJ;
1077 <      exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
1078 <      
1079 <      the_excludes[j+excludeOffset]->setPair( exI, exJ );
1080 < #else  // isn't MPI
1081 <      the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
1082 < #endif  //is_mpi
1073 >        else{
1074 >          theRcut = globals->getRcut();
1075 >        }
1076 >        
1077 >        if (!globals->haveRsw()){
1078 >          sprintf(painCave.errMsg,
1079 >                  "SimSetup Warning: No value was set for switchingRadius.\n"
1080 >                  "\tOOPSE will use a default value of\n"
1081 >                  "\t0.95 * cutoffRadius for the switchingRadius\n");
1082 >          painCave.isFatal = 0;
1083 >          simError();
1084 >          theRsw = 0.95 * theRcut;
1085 >        }
1086 >        else{
1087 >          theRsw = globals->getRsw();
1088 >        }
1089 >        
1090 >        info[i].setDefaultRcut(theRcut, theRsw);
1091 >        
1092 >      }
1093      }
1094 <    excludeOffset += info.nTorsions;
1094 >  }
1095 > #ifdef IS_MPI
1096 >  strcpy(checkPointMsg, "post processing checks out");
1097 >  MPIcheckPoint();
1098 > #endif // is_mpi
1099 > }
1100 >  
1101 > void SimSetup::initSystemCoords(void){
1102 >  int i;
1103  
1104 <    
1194 <    // send the arrays off to the forceField for init.
1104 >  char* inName;
1105  
1106 <    the_ff->initializeAtoms( info.nAtoms, info.myAtoms );
1197 <    the_ff->initializeBonds( info.nBonds, info.myBonds, theBonds );
1198 <    the_ff->initializeBends( info.nBends, info.myBends, theBends );
1199 <    the_ff->initializeTorsions( info.nTorsions, info.myTorsions, theTorsions );
1106 >  (info[0].getConfiguration())->createArrays(info[0].n_atoms);
1107  
1108 +  for (i = 0; i < info[0].n_atoms; i++)
1109 +    info[0].atoms[i]->setCoords();
1110  
1111 <    the_molecules[i].initialize( info );
1111 >  if (globals->haveInitialConfig()){
1112 >    InitializeFromFile* fileInit;
1113 > #ifdef IS_MPI // is_mpi
1114 >    if (worldRank == 0){
1115 > #endif //is_mpi
1116 >      inName = globals->getInitialConfig();
1117 >      fileInit = new InitializeFromFile(inName);
1118 > #ifdef IS_MPI
1119 >    }
1120 >    else
1121 >      fileInit = new InitializeFromFile(NULL);
1122 > #endif
1123 >    fileInit->readInit(info); // default velocities on
1124  
1125 <
1205 <    atomOffset += info.nAtoms;
1206 <    delete[] theBonds;
1207 <    delete[] theBends;
1208 <    delete[] theTorsions;
1125 >    delete fileInit;
1126    }
1127 +  else{
1128 +    
1129 +    // no init from bass
1130 +    
1131 +    sprintf(painCave.errMsg,
1132 +            "Cannot intialize a simulation without an initial configuration file.\n");
1133 +    painCave.isFatal = 1;;
1134 +    simError();
1135 +    
1136 +  }
1137  
1138   #ifdef IS_MPI
1139 <  sprintf( checkPointMsg, "all molecules initialized succesfully" );
1139 >  strcpy(checkPointMsg, "Successfully read in the initial configuration");
1140    MPIcheckPoint();
1141   #endif // is_mpi
1215
1216  // clean up the forcefield
1217  the_ff->calcRcut();
1218  the_ff->cleanMe();
1219
1142   }
1143  
1222 void SimSetup::initFromBass( void ){
1144  
1145 <  int i, j, k;
1146 <  int n_cells;
1226 <  double cellx, celly, cellz;
1227 <  double temp1, temp2, temp3;
1228 <  int n_per_extra;
1229 <  int n_extra;
1230 <  int have_extra, done;
1145 > void SimSetup::makeOutNames(void){
1146 >  int k;
1147  
1232  temp1 = (double)tot_nmol / 4.0;
1233  temp2 = pow( temp1, ( 1.0 / 3.0 ) );
1234  temp3 = ceil( temp2 );
1148  
1149 <  have_extra =0;
1150 <  if( temp2 < temp3 ){ // we have a non-complete lattice
1151 <    have_extra =1;
1149 >  for (k = 0; k < nInfo; k++){
1150 > #ifdef IS_MPI
1151 >    if (worldRank == 0){
1152 > #endif // is_mpi
1153  
1154 <    n_cells = (int)temp3 - 1;
1155 <    cellx = simnfo->boxLx / temp3;
1156 <    celly = simnfo->boxLy / temp3;
1157 <    cellz = simnfo->boxLz / temp3;
1158 <    n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells );
1159 <    temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) );
1160 <    n_per_extra = (int)ceil( temp1 );
1154 >      if (globals->haveFinalConfig()){
1155 >        strcpy(info[k].finalName, globals->getFinalConfig());
1156 >      }
1157 >      else{
1158 >        strcpy(info[k].finalName, inFileName);
1159 >        char* endTest;
1160 >        int nameLength = strlen(info[k].finalName);
1161 >        endTest = &(info[k].finalName[nameLength - 5]);
1162 >        if (!strcmp(endTest, ".bass")){
1163 >          strcpy(endTest, ".eor");
1164 >        }
1165 >        else if (!strcmp(endTest, ".BASS")){
1166 >          strcpy(endTest, ".eor");
1167 >        }
1168 >        else{
1169 >          endTest = &(info[k].finalName[nameLength - 4]);
1170 >          if (!strcmp(endTest, ".bss")){
1171 >            strcpy(endTest, ".eor");
1172 >          }
1173 >          else if (!strcmp(endTest, ".mdl")){
1174 >            strcpy(endTest, ".eor");
1175 >          }
1176 >          else{
1177 >            strcat(info[k].finalName, ".eor");
1178 >          }
1179 >        }
1180 >      }
1181  
1182 <    if( n_per_extra > 4){
1183 <      sprintf( painCave.errMsg,
1184 <               "SimSetup error. There has been an error in constructing"
1185 <               " the non-complete lattice.\n" );
1186 <      painCave.isFatal = 1;
1187 <      simError();
1182 >      // make the sample and status out names
1183 >
1184 >      strcpy(info[k].sampleName, inFileName);
1185 >      char* endTest;
1186 >      int nameLength = strlen(info[k].sampleName);
1187 >      endTest = &(info[k].sampleName[nameLength - 5]);
1188 >      if (!strcmp(endTest, ".bass")){
1189 >        strcpy(endTest, ".dump");
1190 >      }
1191 >      else if (!strcmp(endTest, ".BASS")){
1192 >        strcpy(endTest, ".dump");
1193 >      }
1194 >      else{
1195 >        endTest = &(info[k].sampleName[nameLength - 4]);
1196 >        if (!strcmp(endTest, ".bss")){
1197 >          strcpy(endTest, ".dump");
1198 >        }
1199 >        else if (!strcmp(endTest, ".mdl")){
1200 >          strcpy(endTest, ".dump");
1201 >        }
1202 >        else{
1203 >          strcat(info[k].sampleName, ".dump");
1204 >        }
1205 >      }
1206 >
1207 >      strcpy(info[k].statusName, inFileName);
1208 >      nameLength = strlen(info[k].statusName);
1209 >      endTest = &(info[k].statusName[nameLength - 5]);
1210 >      if (!strcmp(endTest, ".bass")){
1211 >        strcpy(endTest, ".stat");
1212 >      }
1213 >      else if (!strcmp(endTest, ".BASS")){
1214 >        strcpy(endTest, ".stat");
1215 >      }
1216 >      else{
1217 >        endTest = &(info[k].statusName[nameLength - 4]);
1218 >        if (!strcmp(endTest, ".bss")){
1219 >          strcpy(endTest, ".stat");
1220 >        }
1221 >        else if (!strcmp(endTest, ".mdl")){
1222 >          strcpy(endTest, ".stat");
1223 >        }
1224 >        else{
1225 >          strcat(info[k].statusName, ".stat");
1226 >        }
1227 >      }
1228 >
1229 > #ifdef IS_MPI
1230 >
1231      }
1232 + #endif // is_mpi
1233    }
1234 <  else{
1257 <    n_cells = (int)temp3;
1258 <    cellx = simnfo->boxLx / temp3;
1259 <    celly = simnfo->boxLy / temp3;
1260 <    cellz = simnfo->boxLz / temp3;
1261 <  }
1234 > }
1235  
1263  current_mol = 0;
1264  current_comp_mol = 0;
1265  current_comp = 0;
1266  current_atom_ndx = 0;
1236  
1237 <  for( i=0; i < n_cells ; i++ ){
1238 <    for( j=0; j < n_cells; j++ ){
1270 <      for( k=0; k < n_cells; k++ ){
1237 > void SimSetup::sysObjectsCreation(void){
1238 >  int i, k;
1239  
1240 <        makeElement( i * cellx,
1273 <                     j * celly,
1274 <                     k * cellz );
1240 >  // create the forceField
1241  
1242 <        makeElement( i * cellx + 0.5 * cellx,
1277 <                     j * celly + 0.5 * celly,
1278 <                     k * cellz );
1242 >  createFF();
1243  
1244 <        makeElement( i * cellx,
1281 <                     j * celly + 0.5 * celly,
1282 <                     k * cellz + 0.5 * cellz );
1244 >  // extract componentList
1245  
1246 <        makeElement( i * cellx + 0.5 * cellx,
1285 <                     j * celly,
1286 <                     k * cellz + 0.5 * cellz );
1287 <      }
1288 <    }
1289 <  }
1246 >  compList();
1247  
1248 <  if( have_extra ){
1292 <    done = 0;
1248 >  // calc the number of atoms, bond, bends, and torsions
1249  
1250 <    int start_ndx;
1295 <    for( i=0; i < (n_cells+1) && !done; i++ ){
1296 <      for( j=0; j < (n_cells+1) && !done; j++ ){
1250 >  calcSysValues();
1251  
1252 <        if( i < n_cells ){
1252 > #ifdef IS_MPI
1253 >  // divide the molecules among the processors
1254  
1255 <          if( j < n_cells ){
1256 <            start_ndx = n_cells;
1302 <          }
1303 <          else start_ndx = 0;
1304 <        }
1305 <        else start_ndx = 0;
1255 >  mpiMolDivide();
1256 > #endif //is_mpi
1257  
1258 <        for( k=start_ndx; k < (n_cells+1) && !done; k++ ){
1258 >  // create the atom and SRI arrays. Also initialize Molecule Stamp ID's
1259  
1260 <          makeElement( i * cellx,
1310 <                       j * celly,
1311 <                       k * cellz );
1312 <          done = ( current_mol >= tot_nmol );
1260 >  makeSysArrays();
1261  
1262 <          if( !done && n_per_extra > 1 ){
1315 <            makeElement( i * cellx + 0.5 * cellx,
1316 <                         j * celly + 0.5 * celly,
1317 <                         k * cellz );
1318 <            done = ( current_mol >= tot_nmol );
1319 <          }
1262 >  // make and initialize the molecules (all but atomic coordinates)
1263  
1264 <          if( !done && n_per_extra > 2){
1322 <            makeElement( i * cellx,
1323 <                         j * celly + 0.5 * celly,
1324 <                         k * cellz + 0.5 * cellz );
1325 <            done = ( current_mol >= tot_nmol );
1326 <          }
1264 >  makeMolecules();
1265  
1266 <          if( !done && n_per_extra > 3){
1267 <            makeElement( i * cellx + 0.5 * cellx,
1268 <                         j * celly,
1269 <                         k * cellz + 0.5 * cellz );
1332 <            done = ( current_mol >= tot_nmol );
1333 <          }
1334 <        }
1335 <      }
1266 >  for (k = 0; k < nInfo; k++){
1267 >    info[k].identArray = new int[info[k].n_atoms];
1268 >    for (i = 0; i < info[k].n_atoms; i++){
1269 >      info[k].identArray[i] = info[k].atoms[i]->getIdent();
1270      }
1271    }
1272 + }
1273  
1274  
1275 <  for( i=0; i<simnfo->n_atoms; i++ ){
1276 <    simnfo->atoms[i]->set_vx( 0.0 );
1277 <    simnfo->atoms[i]->set_vy( 0.0 );
1278 <    simnfo->atoms[i]->set_vz( 0.0 );
1279 <  }
1345 < }
1275 > void SimSetup::createFF(void){
1276 >  switch (ffCase){
1277 >    case FF_DUFF:
1278 >      the_ff = new DUFF();
1279 >      break;
1280  
1281 < void SimSetup::makeElement( double x, double y, double z ){
1281 >    case FF_LJ:
1282 >      the_ff = new LJFF();
1283 >      break;
1284  
1285 <  int k;
1286 <  AtomStamp* current_atom;
1287 <  DirectionalAtom* dAtom;
1352 <  double rotMat[3][3];
1285 >    case FF_EAM:
1286 >      the_ff = new EAM_FF();
1287 >      break;
1288  
1289 <  for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){
1289 >    case FF_H2O:
1290 >      the_ff = new WATER();
1291 >      break;
1292  
1293 <    current_atom = comp_stamps[current_comp]->getAtom( k );
1294 <    if( !current_atom->havePosition() ){
1295 <      sprintf( painCave.errMsg,
1359 <               "SimSetup:initFromBass error.\n"
1360 <               "\tComponent %s, atom %s does not have a position specified.\n"
1361 <               "\tThe initialization routine is unable to give a start"
1362 <               " position.\n",
1363 <               comp_stamps[current_comp]->getID(),
1364 <               current_atom->getType() );
1293 >    default:
1294 >      sprintf(painCave.errMsg,
1295 >              "SimSetup Error. Unrecognized force field in case statement.\n");
1296        painCave.isFatal = 1;
1297        simError();
1298 <    }
1298 >  }
1299  
1300 <    the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );
1301 <    the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() );
1302 <    the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() );
1300 > #ifdef IS_MPI
1301 >  strcpy(checkPointMsg, "ForceField creation successful");
1302 >  MPIcheckPoint();
1303 > #endif // is_mpi
1304 > }
1305  
1373    if( the_atoms[current_atom_ndx]->isDirectional() ){
1306  
1307 <      dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx];
1308 <
1309 <      rotMat[0][0] = 1.0;
1310 <      rotMat[0][1] = 0.0;
1311 <      rotMat[0][2] = 0.0;
1312 <
1313 <      rotMat[1][0] = 0.0;
1382 <      rotMat[1][1] = 1.0;
1383 <      rotMat[1][2] = 0.0;
1384 <
1385 <      rotMat[2][0] = 0.0;
1386 <      rotMat[2][1] = 0.0;
1387 <      rotMat[2][2] = 1.0;
1307 > void SimSetup::compList(void){
1308 >  int i;
1309 >  char* id;
1310 >  LinkedMolStamp* headStamp = new LinkedMolStamp();
1311 >  LinkedMolStamp* currentStamp = NULL;
1312 >  comp_stamps = new MoleculeStamp * [n_components];
1313 >  bool haveCutoffGroups;
1314  
1315 <      dAtom->setA( rotMat );
1315 >  haveCutoffGroups = false;
1316 >  
1317 >  // make an array of molecule stamps that match the components used.
1318 >  // also extract the used stamps out into a separate linked list
1319 >
1320 >  for (i = 0; i < nInfo; i++){
1321 >    info[i].nComponents = n_components;
1322 >    info[i].componentsNmol = components_nmol;
1323 >    info[i].compStamps = comp_stamps;
1324 >    info[i].headStamp = headStamp;
1325 >  }
1326 >
1327 >
1328 >  for (i = 0; i < n_components; i++){
1329 >    id = the_components[i]->getType();
1330 >    comp_stamps[i] = NULL;
1331 >
1332 >    // check to make sure the component isn't already in the list
1333 >
1334 >    comp_stamps[i] = headStamp->match(id);
1335 >    if (comp_stamps[i] == NULL){
1336 >      // extract the component from the list;
1337 >
1338 >      currentStamp = stamps->extractMolStamp(id);
1339 >      if (currentStamp == NULL){
1340 >        sprintf(painCave.errMsg,
1341 >                "SimSetup error: Component \"%s\" was not found in the "
1342 >                "list of declared molecules\n",
1343 >                id);
1344 >        painCave.isFatal = 1;
1345 >        simError();
1346 >      }
1347 >
1348 >      headStamp->add(currentStamp);
1349 >      comp_stamps[i] = headStamp->match(id);
1350      }
1351  
1352 <    current_atom_ndx++;
1352 >    if(comp_stamps[i]->getNCutoffGroups() > 0)
1353 >      haveCutoffGroups = true;    
1354    }
1355 +    
1356 +  for (i = 0; i < nInfo; i++)
1357 +    info[i].haveCutoffGroups = haveCutoffGroups;
1358  
1359 <  current_mol++;
1360 <  current_comp_mol++;
1359 > #ifdef IS_MPI
1360 >  strcpy(checkPointMsg, "Component stamps successfully extracted\n");
1361 >  MPIcheckPoint();
1362 > #endif // is_mpi
1363 > }
1364  
1365 <  if( current_comp_mol >= components_nmol[current_comp] ){
1365 > void SimSetup::calcSysValues(void){
1366 >  int i;
1367  
1368 <    current_comp_mol = 0;
1369 <    current_comp++;
1368 >  int* molMembershipArray;
1369 >
1370 >  tot_atoms = 0;
1371 >  tot_bonds = 0;
1372 >  tot_bends = 0;
1373 >  tot_torsions = 0;
1374 >  tot_rigid = 0;
1375 >  for (i = 0; i < n_components; i++){
1376 >    tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms();
1377 >    tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds();
1378 >    tot_bends += components_nmol[i] * comp_stamps[i]->getNBends();
1379 >    tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions();
1380 >    tot_rigid += components_nmol[i] * comp_stamps[i]->getNRigidBodies();
1381 >  }
1382 >  
1383 >  tot_SRI = tot_bonds + tot_bends + tot_torsions;
1384 >  molMembershipArray = new int[tot_atoms];
1385 >
1386 >  for (i = 0; i < nInfo; i++){
1387 >    info[i].n_atoms = tot_atoms;
1388 >    info[i].n_bonds = tot_bonds;
1389 >    info[i].n_bends = tot_bends;
1390 >    info[i].n_torsions = tot_torsions;
1391 >    info[i].n_SRI = tot_SRI;
1392 >    info[i].n_mol = tot_nmol;
1393 >
1394 >    info[i].molMembershipArray = molMembershipArray;
1395 >  }
1396 > }
1397 >
1398 > #ifdef IS_MPI
1399 >
1400 > void SimSetup::mpiMolDivide(void){
1401 >  int i, j, k;
1402 >  int localMol, allMol;
1403 >  int local_atoms, local_bonds, local_bends, local_torsions, local_SRI;
1404 >  int local_rigid;
1405 >  vector<int> globalMolIndex;
1406 >
1407 >  mpiSim = new mpiSimulation(info);
1408 >
1409 >  mpiSim->divideLabor();
1410 >  globalAtomIndex = mpiSim->getGlobalAtomIndex();
1411 >  //globalMolIndex = mpiSim->getGlobalMolIndex();
1412 >
1413 >  // set up the local variables
1414 >
1415 >  mol2proc = mpiSim->getMolToProcMap();
1416 >  molCompType = mpiSim->getMolComponentType();
1417 >
1418 >  allMol = 0;
1419 >  localMol = 0;
1420 >  local_atoms = 0;
1421 >  local_bonds = 0;
1422 >  local_bends = 0;
1423 >  local_torsions = 0;
1424 >  local_rigid = 0;
1425 >  globalAtomCounter = 0;
1426 >
1427 >  for (i = 0; i < n_components; i++){
1428 >    for (j = 0; j < components_nmol[i]; j++){
1429 >      if (mol2proc[allMol] == worldRank){
1430 >        local_atoms += comp_stamps[i]->getNAtoms();
1431 >        local_bonds += comp_stamps[i]->getNBonds();
1432 >        local_bends += comp_stamps[i]->getNBends();
1433 >        local_torsions += comp_stamps[i]->getNTorsions();
1434 >        local_rigid += comp_stamps[i]->getNRigidBodies();
1435 >        localMol++;
1436 >      }      
1437 >      for (k = 0; k < comp_stamps[i]->getNAtoms(); k++){
1438 >        info[0].molMembershipArray[globalAtomCounter] = allMol;
1439 >        globalAtomCounter++;
1440 >      }
1441 >
1442 >      allMol++;
1443 >    }
1444 >  }
1445 >  local_SRI = local_bonds + local_bends + local_torsions;
1446 >
1447 >  info[0].n_atoms = mpiSim->getMyNlocal();  
1448 >  
1449 >
1450 >  if (local_atoms != info[0].n_atoms){
1451 >    sprintf(painCave.errMsg,
1452 >            "SimSetup error: mpiSim's localAtom (%d) and SimSetup's\n"
1453 >            "\tlocalAtom (%d) are not equal.\n",
1454 >            info[0].n_atoms, local_atoms);
1455 >    painCave.isFatal = 1;
1456 >    simError();
1457 >  }
1458 >
1459 >  info[0].n_bonds = local_bonds;
1460 >  info[0].n_bends = local_bends;
1461 >  info[0].n_torsions = local_torsions;
1462 >  info[0].n_SRI = local_SRI;
1463 >  info[0].n_mol = localMol;
1464 >
1465 >  strcpy(checkPointMsg, "Passed nlocal consistency check.");
1466 >  MPIcheckPoint();
1467 > }
1468 >
1469 > #endif // is_mpi
1470 >
1471 >
1472 > void SimSetup::makeSysArrays(void){
1473 >
1474 > #ifndef IS_MPI
1475 >  int k, j;
1476 > #endif // is_mpi
1477 >  int i, l;
1478 >
1479 >  Atom** the_atoms;
1480 >  Molecule* the_molecules;
1481 >
1482 >  for (l = 0; l < nInfo; l++){
1483 >    // create the atom and short range interaction arrays
1484 >
1485 >    the_atoms = new Atom * [info[l].n_atoms];
1486 >    the_molecules = new Molecule[info[l].n_mol];
1487 >    int molIndex;
1488 >
1489 >    // initialize the molecule's stampID's
1490 >
1491 > #ifdef IS_MPI
1492 >
1493 >
1494 >    molIndex = 0;
1495 >    for (i = 0; i < mpiSim->getTotNmol(); i++){
1496 >      if (mol2proc[i] == worldRank){
1497 >        the_molecules[molIndex].setStampID(molCompType[i]);
1498 >        the_molecules[molIndex].setMyIndex(molIndex);
1499 >        the_molecules[molIndex].setGlobalIndex(i);
1500 >        molIndex++;
1501 >      }
1502 >    }
1503 >
1504 > #else // is_mpi
1505 >
1506 >    molIndex = 0;
1507 >    globalAtomCounter = 0;
1508 >    for (i = 0; i < n_components; i++){
1509 >      for (j = 0; j < components_nmol[i]; j++){
1510 >        the_molecules[molIndex].setStampID(i);
1511 >        the_molecules[molIndex].setMyIndex(molIndex);
1512 >        the_molecules[molIndex].setGlobalIndex(molIndex);
1513 >        for (k = 0; k < comp_stamps[i]->getNAtoms(); k++){
1514 >          info[l].molMembershipArray[globalAtomCounter] = molIndex;
1515 >          globalAtomCounter++;
1516 >        }
1517 >        molIndex++;
1518 >      }
1519 >    }
1520 >
1521 >
1522 > #endif // is_mpi
1523 >
1524 >    info[l].globalExcludes = new int;
1525 >    info[l].globalExcludes[0] = 0;
1526 >    
1527 >    // set the arrays into the SimInfo object
1528 >
1529 >    info[l].atoms = the_atoms;
1530 >    info[l].molecules = the_molecules;
1531 >    info[l].nGlobalExcludes = 0;
1532 >    
1533 >    the_ff->setSimInfo(info);
1534    }
1535   }
1536 +
1537 + void SimSetup::makeIntegrator(void){
1538 +  int k;
1539 +
1540 +  NVE<RealIntegrator>* myNVE = NULL;
1541 +  NVT<RealIntegrator>* myNVT = NULL;
1542 +  NPTi<NPT<RealIntegrator> >* myNPTi = NULL;
1543 +  NPTf<NPT<RealIntegrator> >* myNPTf = NULL;
1544 +  NPTxyz<NPT<RealIntegrator> >* myNPTxyz = NULL;
1545 +  
1546 +  for (k = 0; k < nInfo; k++){
1547 +    switch (ensembleCase){
1548 +      case NVE_ENS:
1549 +        if (globals->haveZconstraints()){
1550 +          setupZConstraint(info[k]);
1551 +          myNVE = new ZConstraint<NVE<RealIntegrator> >(&(info[k]), the_ff);
1552 +        }
1553 +        else{
1554 +          myNVE = new NVE<RealIntegrator>(&(info[k]), the_ff);
1555 +        }
1556 +        
1557 +        info->the_integrator = myNVE;
1558 +        break;
1559 +
1560 +      case NVT_ENS:
1561 +        if (globals->haveZconstraints()){
1562 +          setupZConstraint(info[k]);
1563 +          myNVT = new ZConstraint<NVT<RealIntegrator> >(&(info[k]), the_ff);
1564 +        }
1565 +        else
1566 +          myNVT = new NVT<RealIntegrator>(&(info[k]), the_ff);
1567 +
1568 +        myNVT->setTargetTemp(globals->getTargetTemp());
1569 +
1570 +        if (globals->haveTauThermostat())
1571 +          myNVT->setTauThermostat(globals->getTauThermostat());
1572 +        else{
1573 +          sprintf(painCave.errMsg,
1574 +                  "SimSetup error: If you use the NVT\n"
1575 +                  "\tensemble, you must set tauThermostat.\n");
1576 +          painCave.isFatal = 1;
1577 +          simError();
1578 +        }
1579 +
1580 +        info->the_integrator = myNVT;
1581 +        break;
1582 +
1583 +      case NPTi_ENS:
1584 +        if (globals->haveZconstraints()){
1585 +          setupZConstraint(info[k]);
1586 +          myNPTi = new ZConstraint<NPTi<NPT <RealIntegrator> > >(&(info[k]), the_ff);
1587 +        }
1588 +        else
1589 +          myNPTi = new NPTi<NPT<RealIntegrator> >(&(info[k]), the_ff);
1590 +
1591 +        myNPTi->setTargetTemp(globals->getTargetTemp());
1592 +
1593 +        if (globals->haveTargetPressure())
1594 +          myNPTi->setTargetPressure(globals->getTargetPressure());
1595 +        else{
1596 +          sprintf(painCave.errMsg,
1597 +                  "SimSetup error: If you use a constant pressure\n"
1598 +                  "\tensemble, you must set targetPressure in the BASS file.\n");
1599 +          painCave.isFatal = 1;
1600 +          simError();
1601 +        }
1602 +
1603 +        if (globals->haveTauThermostat())
1604 +          myNPTi->setTauThermostat(globals->getTauThermostat());
1605 +        else{
1606 +          sprintf(painCave.errMsg,
1607 +                  "SimSetup error: If you use an NPT\n"
1608 +                  "\tensemble, you must set tauThermostat.\n");
1609 +          painCave.isFatal = 1;
1610 +          simError();
1611 +        }
1612 +
1613 +        if (globals->haveTauBarostat())
1614 +          myNPTi->setTauBarostat(globals->getTauBarostat());
1615 +        else{
1616 +          sprintf(painCave.errMsg,
1617 +                  "SimSetup error: If you use an NPT\n"
1618 +                  "\tensemble, you must set tauBarostat.\n");
1619 +          painCave.isFatal = 1;
1620 +          simError();
1621 +        }
1622 +
1623 +        info->the_integrator = myNPTi;
1624 +        break;
1625 +
1626 +      case NPTf_ENS:
1627 +        if (globals->haveZconstraints()){
1628 +          setupZConstraint(info[k]);
1629 +          myNPTf = new ZConstraint<NPTf<NPT <RealIntegrator> > >(&(info[k]), the_ff);
1630 +        }
1631 +        else
1632 +          myNPTf = new NPTf<NPT <RealIntegrator> >(&(info[k]), the_ff);
1633 +
1634 +        myNPTf->setTargetTemp(globals->getTargetTemp());
1635 +
1636 +        if (globals->haveTargetPressure())
1637 +          myNPTf->setTargetPressure(globals->getTargetPressure());
1638 +        else{
1639 +          sprintf(painCave.errMsg,
1640 +                  "SimSetup error: If you use a constant pressure\n"
1641 +                  "\tensemble, you must set targetPressure in the BASS file.\n");
1642 +          painCave.isFatal = 1;
1643 +          simError();
1644 +        }    
1645 +
1646 +        if (globals->haveTauThermostat())
1647 +          myNPTf->setTauThermostat(globals->getTauThermostat());
1648 +
1649 +        else{
1650 +          sprintf(painCave.errMsg,
1651 +                  "SimSetup error: If you use an NPT\n"
1652 +                  "\tensemble, you must set tauThermostat.\n");
1653 +          painCave.isFatal = 1;
1654 +          simError();
1655 +        }
1656 +
1657 +        if (globals->haveTauBarostat())
1658 +          myNPTf->setTauBarostat(globals->getTauBarostat());
1659 +
1660 +        else{
1661 +          sprintf(painCave.errMsg,
1662 +                  "SimSetup error: If you use an NPT\n"
1663 +                  "\tensemble, you must set tauBarostat.\n");
1664 +          painCave.isFatal = 1;
1665 +          simError();
1666 +        }
1667 +
1668 +        info->the_integrator = myNPTf;
1669 +        break;
1670 +
1671 +      case NPTxyz_ENS:
1672 +        if (globals->haveZconstraints()){
1673 +          setupZConstraint(info[k]);
1674 +          myNPTxyz = new ZConstraint<NPTxyz<NPT <RealIntegrator> > >(&(info[k]), the_ff);
1675 +        }
1676 +        else
1677 +          myNPTxyz = new NPTxyz<NPT <RealIntegrator> >(&(info[k]), the_ff);
1678 +
1679 +        myNPTxyz->setTargetTemp(globals->getTargetTemp());
1680 +
1681 +        if (globals->haveTargetPressure())
1682 +          myNPTxyz->setTargetPressure(globals->getTargetPressure());
1683 +        else{
1684 +          sprintf(painCave.errMsg,
1685 +                  "SimSetup error: If you use a constant pressure\n"
1686 +                  "\tensemble, you must set targetPressure in the BASS file.\n");
1687 +          painCave.isFatal = 1;
1688 +          simError();
1689 +        }    
1690 +
1691 +        if (globals->haveTauThermostat())
1692 +          myNPTxyz->setTauThermostat(globals->getTauThermostat());
1693 +        else{
1694 +          sprintf(painCave.errMsg,
1695 +                  "SimSetup error: If you use an NPT\n"
1696 +                  "\tensemble, you must set tauThermostat.\n");
1697 +          painCave.isFatal = 1;
1698 +          simError();
1699 +        }
1700 +
1701 +        if (globals->haveTauBarostat())
1702 +          myNPTxyz->setTauBarostat(globals->getTauBarostat());
1703 +        else{
1704 +          sprintf(painCave.errMsg,
1705 +                  "SimSetup error: If you use an NPT\n"
1706 +                  "\tensemble, you must set tauBarostat.\n");
1707 +          painCave.isFatal = 1;
1708 +          simError();
1709 +        }
1710 +
1711 +        info->the_integrator = myNPTxyz;
1712 +        break;
1713 +
1714 +      default:
1715 +        sprintf(painCave.errMsg,
1716 +                "SimSetup Error. Unrecognized ensemble in case statement.\n");
1717 +        painCave.isFatal = 1;
1718 +        simError();
1719 +    }
1720 +  }
1721 + }
1722 +
1723 + void SimSetup::initFortran(void){
1724 +  info[0].refreshSim();
1725 +
1726 +  if (!strcmp(info[0].mixingRule, "standard")){
1727 +    the_ff->initForceField(LB_MIXING_RULE);
1728 +  }
1729 +  else if (!strcmp(info[0].mixingRule, "explicit")){
1730 +    the_ff->initForceField(EXPLICIT_MIXING_RULE);
1731 +  }
1732 +  else{
1733 +    sprintf(painCave.errMsg, "SimSetup Error: unknown mixing rule -> \"%s\"\n",
1734 +            info[0].mixingRule);
1735 +    painCave.isFatal = 1;
1736 +    simError();
1737 +  }
1738 +
1739 +
1740 + #ifdef IS_MPI
1741 +  strcpy(checkPointMsg, "Successfully intialized the mixingRule for Fortran.");
1742 +  MPIcheckPoint();
1743 + #endif // is_mpi
1744 + }
1745 +
1746 + void SimSetup::setupZConstraint(SimInfo& theInfo){
1747 +  int nZConstraints;
1748 +  ZconStamp** zconStamp;
1749 +
1750 +  if (globals->haveZconstraintTime()){
1751 +    //add sample time of z-constraint  into SimInfo's property list                    
1752 +    DoubleData* zconsTimeProp = new DoubleData();
1753 +    zconsTimeProp->setID(ZCONSTIME_ID);
1754 +    zconsTimeProp->setData(globals->getZconsTime());
1755 +    theInfo.addProperty(zconsTimeProp);
1756 +  }
1757 +  else{
1758 +    sprintf(painCave.errMsg,
1759 +            "ZConstraint error: If you use a ZConstraint,\n"
1760 +            "\tyou must set zconsTime.\n");
1761 +    painCave.isFatal = 1;
1762 +    simError();
1763 +  }
1764 +
1765 +  //push zconsTol into siminfo, if user does not specify
1766 +  //value for zconsTol, a default value will be used
1767 +  DoubleData* zconsTol = new DoubleData();
1768 +  zconsTol->setID(ZCONSTOL_ID);
1769 +  if (globals->haveZconsTol()){
1770 +    zconsTol->setData(globals->getZconsTol());
1771 +  }
1772 +  else{
1773 +    double defaultZConsTol = 0.01;
1774 +    sprintf(painCave.errMsg,
1775 +            "ZConstraint Warning: Tolerance for z-constraint method is not specified.\n"
1776 +            "\tOOPSE will use a default value of %f.\n"
1777 +            "\tTo set the tolerance, use the zconsTol variable.\n",
1778 +            defaultZConsTol);
1779 +    painCave.isFatal = 0;
1780 +    simError();      
1781 +
1782 +    zconsTol->setData(defaultZConsTol);
1783 +  }
1784 +  theInfo.addProperty(zconsTol);
1785 +
1786 +  //set Force Subtraction Policy
1787 +  StringData* zconsForcePolicy = new StringData();
1788 +  zconsForcePolicy->setID(ZCONSFORCEPOLICY_ID);
1789 +
1790 +  if (globals->haveZconsForcePolicy()){
1791 +    zconsForcePolicy->setData(globals->getZconsForcePolicy());
1792 +  }
1793 +  else{
1794 +    sprintf(painCave.errMsg,
1795 +            "ZConstraint Warning: No force subtraction policy was set.\n"
1796 +            "\tOOPSE will use PolicyByMass.\n"
1797 +            "\tTo set the policy, use the zconsForcePolicy variable.\n");
1798 +    painCave.isFatal = 0;
1799 +    simError();
1800 +    zconsForcePolicy->setData("BYMASS");
1801 +  }
1802 +
1803 +  theInfo.addProperty(zconsForcePolicy);
1804 +
1805 +  //set zcons gap
1806 +  DoubleData* zconsGap = new DoubleData();
1807 +  zconsGap->setID(ZCONSGAP_ID);
1808 +
1809 +  if (globals->haveZConsGap()){
1810 +    zconsGap->setData(globals->getZconsGap());
1811 +    theInfo.addProperty(zconsGap);  
1812 +  }
1813 +
1814 +  //set zcons fixtime
1815 +  DoubleData* zconsFixtime = new DoubleData();
1816 +  zconsFixtime->setID(ZCONSFIXTIME_ID);
1817 +
1818 +  if (globals->haveZConsFixTime()){
1819 +    zconsFixtime->setData(globals->getZconsFixtime());
1820 +    theInfo.addProperty(zconsFixtime);  
1821 +  }
1822 +
1823 +  //set zconsUsingSMD
1824 +  IntData* zconsUsingSMD = new IntData();
1825 +  zconsUsingSMD->setID(ZCONSUSINGSMD_ID);
1826 +
1827 +  if (globals->haveZConsUsingSMD()){
1828 +    zconsUsingSMD->setData(globals->getZconsUsingSMD());
1829 +    theInfo.addProperty(zconsUsingSMD);  
1830 +  }
1831 +
1832 +  //Determine the name of ouput file and add it into SimInfo's property list
1833 +  //Be careful, do not use inFileName, since it is a pointer which
1834 +  //point to a string at master node, and slave nodes do not contain that string
1835 +
1836 +  string zconsOutput(theInfo.finalName);
1837 +
1838 +  zconsOutput = zconsOutput.substr(0, zconsOutput.rfind(".")) + ".fz";
1839 +
1840 +  StringData* zconsFilename = new StringData();
1841 +  zconsFilename->setID(ZCONSFILENAME_ID);
1842 +  zconsFilename->setData(zconsOutput);
1843 +
1844 +  theInfo.addProperty(zconsFilename);
1845 +
1846 +  //setup index, pos and other parameters of z-constraint molecules
1847 +  nZConstraints = globals->getNzConstraints();
1848 +  theInfo.nZconstraints = nZConstraints;
1849 +
1850 +  zconStamp = globals->getZconStamp();
1851 +  ZConsParaItem tempParaItem;
1852 +
1853 +  ZConsParaData* zconsParaData = new ZConsParaData();
1854 +  zconsParaData->setID(ZCONSPARADATA_ID);
1855 +
1856 +  for (int i = 0; i < nZConstraints; i++){
1857 +    tempParaItem.havingZPos = zconStamp[i]->haveZpos();
1858 +    tempParaItem.zPos = zconStamp[i]->getZpos();
1859 +    tempParaItem.zconsIndex = zconStamp[i]->getMolIndex();
1860 +    tempParaItem.kRatio = zconStamp[i]->getKratio();
1861 +    tempParaItem.havingCantVel = zconStamp[i]->haveCantVel();
1862 +    tempParaItem.cantVel = zconStamp[i]->getCantVel();    
1863 +    zconsParaData->addItem(tempParaItem);
1864 +  }
1865 +
1866 +  //check the uniqueness of index  
1867 +  if(!zconsParaData->isIndexUnique()){
1868 +    sprintf(painCave.errMsg,
1869 +            "ZConstraint Error: molIndex is not unique!\n");
1870 +    painCave.isFatal = 1;
1871 +    simError();
1872 +  }
1873 +
1874 +  //sort the parameters by index of molecules
1875 +  zconsParaData->sortByIndex();
1876 +  
1877 +  //push data into siminfo, therefore, we can retrieve later
1878 +  theInfo.addProperty(zconsParaData);
1879 + }
1880 +
1881 + void SimSetup::makeMinimizer(){
1882 +
1883 +  OOPSEMinimizer* myOOPSEMinimizer;
1884 +  MinimizerParameterSet* param;
1885 +  char minimizerName[100];
1886 +  
1887 +  for (int i = 0; i < nInfo; i++){
1888 +    
1889 +    //prepare parameter set for minimizer
1890 +    param = new MinimizerParameterSet();
1891 +    param->setDefaultParameter();
1892 +
1893 +    if (globals->haveMinimizer()){
1894 +      param->setFTol(globals->getMinFTol());
1895 +    }
1896 +
1897 +    if (globals->haveMinGTol()){
1898 +      param->setGTol(globals->getMinGTol());
1899 +    }
1900 +
1901 +    if (globals->haveMinMaxIter()){
1902 +      param->setMaxIteration(globals->getMinMaxIter());
1903 +    }
1904 +
1905 +    if (globals->haveMinWriteFrq()){
1906 +      param->setMaxIteration(globals->getMinMaxIter());
1907 +    }
1908 +
1909 +    if (globals->haveMinWriteFrq()){
1910 +      param->setWriteFrq(globals->getMinWriteFrq());
1911 +    }
1912 +    
1913 +    if (globals->haveMinStepSize()){
1914 +      param->setStepSize(globals->getMinStepSize());
1915 +    }
1916 +
1917 +    if (globals->haveMinLSMaxIter()){
1918 +      param->setLineSearchMaxIteration(globals->getMinLSMaxIter());
1919 +    }    
1920 +
1921 +    if (globals->haveMinLSTol()){
1922 +      param->setLineSearchTol(globals->getMinLSTol());
1923 +    }    
1924 +
1925 +    strcpy(minimizerName, globals->getMinimizer());
1926 +
1927 +    if (!strcasecmp(minimizerName, "CG")){
1928 +      myOOPSEMinimizer = new PRCGMinimizer(&(info[i]), the_ff, param);
1929 +    }
1930 +    else if (!strcasecmp(minimizerName, "SD")){
1931 +    //myOOPSEMinimizer = MinimizerFactory.creatMinimizer("", &(info[i]), the_ff, param);
1932 +      myOOPSEMinimizer = new SDMinimizer(&(info[i]), the_ff, param);
1933 +    }
1934 +    else{
1935 +          sprintf(painCave.errMsg,
1936 +                  "SimSetup error: Unrecognized Minimizer, use Conjugate Gradient \n");
1937 +          painCave.isFatal = 0;
1938 +          simError();
1939 +
1940 +      myOOPSEMinimizer = new PRCGMinimizer(&(info[i]), the_ff, param);          
1941 +    }
1942 +     info[i].the_integrator = myOOPSEMinimizer;
1943 +
1944 +     //store the minimizer into simInfo
1945 +     info[i].the_minimizer = myOOPSEMinimizer;
1946 +     info[i].has_minimizer = true;
1947 +  }
1948 +
1949 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines