ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/SimInfo.cpp
(Generate patch)

Comparing:
trunk/src/brains/SimInfo.cpp (file contents), Revision 124 by chuckv, Wed Oct 20 20:46:20 2004 UTC vs.
branches/development/src/brains/SimInfo.cpp (file contents), Revision 1503 by gezelter, Sat Oct 2 19:54:41 2010 UTC

# Line 1 | Line 1
1 < #include <stdlib.h>
2 < #include <string.h>
3 < #include <math.h>
1 > /*
2 > * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 > *
4 > * The University of Notre Dame grants you ("Licensee") a
5 > * non-exclusive, royalty free, license to use, modify and
6 > * redistribute this software in source and binary code form, provided
7 > * that the following conditions are met:
8 > *
9 > * 1. Redistributions of source code must retain the above copyright
10 > *    notice, this list of conditions and the following disclaimer.
11 > *
12 > * 2. Redistributions in binary form must reproduce the above copyright
13 > *    notice, this list of conditions and the following disclaimer in the
14 > *    documentation and/or other materials provided with the
15 > *    distribution.
16 > *
17 > * This software is provided "AS IS," without a warranty of any
18 > * kind. All express or implied conditions, representations and
19 > * warranties, including any implied warranty of merchantability,
20 > * fitness for a particular purpose or non-infringement, are hereby
21 > * excluded.  The University of Notre Dame and its licensors shall not
22 > * be liable for any damages suffered by licensee as a result of
23 > * using, modifying or distributing the software or its
24 > * derivatives. In no event will the University of Notre Dame or its
25 > * licensors be liable for any lost revenue, profit or data, or for
26 > * direct, indirect, special, consequential, incidental or punitive
27 > * damages, however caused and regardless of the theory of liability,
28 > * arising out of the use of or inability to use software, even if the
29 > * University of Notre Dame has been advised of the possibility of
30 > * such damages.
31 > *
32 > * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 > * research, please cite the appropriate papers when you publish your
34 > * work.  Good starting points are:
35 > *                                                                      
36 > * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 > * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 > * [4]  Vardeman & Gezelter, in progress (2009).                        
40 > */
41 >
42 > /**
43 > * @file SimInfo.cpp
44 > * @author    tlin
45 > * @date  11/02/2004
46 > * @version 1.0
47 > */
48  
49 < #include <iostream>
50 < using namespace std;
49 > #include <algorithm>
50 > #include <set>
51 > #include <map>
52  
53   #include "brains/SimInfo.hpp"
54 < #define __C
55 < #include "brains/fSimulation.h"
54 > #include "math/Vector3.hpp"
55 > #include "primitives/Molecule.hpp"
56 > #include "primitives/StuntDouble.hpp"
57 > #include "UseTheForce/fCutoffPolicy.h"
58 > #include "UseTheForce/DarkSide/fSwitchingFunctionType.h"
59 > #include "UseTheForce/doForces_interface.h"
60 > #include "UseTheForce/DarkSide/neighborLists_interface.h"
61 > #include "UseTheForce/DarkSide/switcheroo_interface.h"
62 > #include "utils/MemoryUtils.hpp"
63   #include "utils/simError.h"
64 < #include "UseTheForce/DarkSide/simulation_interface.h"
65 < #include "UseTheForce/notifyCutoffs_interface.h"
64 > #include "selection/SelectionManager.hpp"
65 > #include "io/ForceFieldOptions.hpp"
66 > #include "UseTheForce/ForceField.hpp"
67  
15 //#include "UseTheForce/fortranWrappers.hpp"
68  
17 #include "math/MatVec3.h"
18
69   #ifdef IS_MPI
70 < #include "brains/mpiSimulation.hpp"
71 < #endif
70 > #include "UseTheForce/mpiComponentPlan.h"
71 > #include "UseTheForce/DarkSide/simParallel_interface.h"
72 > #endif
73  
74 < inline double roundMe( double x ){
75 <  return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 );
76 < }
77 <          
78 < inline double min( double a, double b ){
79 <  return (a < b ) ? a : b;
80 < }
74 > namespace OpenMD {
75 >  std::set<int> getRigidSet(int index, std::map<int, std::set<int> >& container) {
76 >    std::map<int, std::set<int> >::iterator i = container.find(index);
77 >    std::set<int> result;
78 >    if (i != container.end()) {
79 >        result = i->second;
80 >    }
81  
82 < SimInfo* currentInfo;
83 <
33 < SimInfo::SimInfo(){
34 <
35 <  n_constraints = 0;
36 <  nZconstraints = 0;
37 <  n_oriented = 0;
38 <  n_dipoles = 0;
39 <  ndf = 0;
40 <  ndfRaw = 0;
41 <  nZconstraints = 0;
42 <  the_integrator = NULL;
43 <  setTemp = 0;
44 <  thermalTime = 0.0;
45 <  currentTime = 0.0;
46 <  rCut = 0.0;
47 <  rSw = 0.0;
48 <
49 <  haveRcut = 0;
50 <  haveRsw = 0;
51 <  boxIsInit = 0;
82 >    return result;
83 >  }
84    
85 <  resetTime = 1e99;
85 >  SimInfo::SimInfo(ForceField* ff, Globals* simParams) :
86 >    forceField_(ff), simParams_(simParams),
87 >    ndf_(0), fdf_local(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
88 >    nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0),
89 >    nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
90 >    nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nInversions_(0),
91 >    nRigidBodies_(0), nIntegrableObjects_(0), nCutoffGroups_(0),
92 >    nConstraints_(0), sman_(NULL), fortranInitialized_(false),
93 >    calcBoxDipole_(false), useAtomicVirial_(true) {
94  
55  orthoRhombic = 0;
56  orthoTolerance = 1E-6;
57  useInitXSstate = true;
95  
96 <  usePBC = 0;
97 <  useLJ = 0;
98 <  useSticky = 0;
99 <  useCharges = 0;
100 <  useDipoles = 0;
101 <  useReactionField = 0;
102 <  useGB = 0;
66 <  useEAM = 0;
67 <  useSolidThermInt = 0;
68 <  useLiquidThermInt = 0;
96 >      MoleculeStamp* molStamp;
97 >      int nMolWithSameStamp;
98 >      int nCutoffAtoms = 0; // number of atoms belong to cutoff groups
99 >      int nGroups = 0;      //total cutoff groups defined in meta-data file
100 >      CutoffGroupStamp* cgStamp;    
101 >      RigidBodyStamp* rbStamp;
102 >      int nRigidAtoms = 0;
103  
104 <  haveCutoffGroups = false;
104 >      std::vector<Component*> components = simParams->getComponents();
105 >      
106 >      for (std::vector<Component*>::iterator i = components.begin(); i !=components.end(); ++i) {
107 >        molStamp = (*i)->getMoleculeStamp();
108 >        nMolWithSameStamp = (*i)->getNMol();
109 >        
110 >        addMoleculeStamp(molStamp, nMolWithSameStamp);
111  
112 <  excludes = Exclude::Instance();
112 >        //calculate atoms in molecules
113 >        nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp;  
114  
115 <  myConfiguration = new SimState();
115 >        //calculate atoms in cutoff groups
116 >        int nAtomsInGroups = 0;
117 >        int nCutoffGroupsInStamp = molStamp->getNCutoffGroups();
118 >        
119 >        for (int j=0; j < nCutoffGroupsInStamp; j++) {
120 >          cgStamp = molStamp->getCutoffGroupStamp(j);
121 >          nAtomsInGroups += cgStamp->getNMembers();
122 >        }
123  
124 <  has_minimizer = false;
77 <  the_minimizer =NULL;
124 >        nGroups += nCutoffGroupsInStamp * nMolWithSameStamp;
125  
126 <  ngroup = 0;
126 >        nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp;            
127  
128 < }
128 >        //calculate atoms in rigid bodies
129 >        int nAtomsInRigidBodies = 0;
130 >        int nRigidBodiesInStamp = molStamp->getNRigidBodies();
131 >        
132 >        for (int j=0; j < nRigidBodiesInStamp; j++) {
133 >          rbStamp = molStamp->getRigidBodyStamp(j);
134 >          nAtomsInRigidBodies += rbStamp->getNMembers();
135 >        }
136  
137 +        nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp;
138 +        nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp;            
139 +        
140 +      }
141  
142 < SimInfo::~SimInfo(){
142 >      //every free atom (atom does not belong to cutoff groups) is a cutoff
143 >      //group therefore the total number of cutoff groups in the system is
144 >      //equal to the total number of atoms minus number of atoms belong to
145 >      //cutoff group defined in meta-data file plus the number of cutoff
146 >      //groups defined in meta-data file
147 >      nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups;
148  
149 <  delete myConfiguration;
150 <
151 <  map<string, GenericData*>::iterator i;
149 >      //every free atom (atom does not belong to rigid bodies) is an
150 >      //integrable object therefore the total number of integrable objects
151 >      //in the system is equal to the total number of atoms minus number of
152 >      //atoms belong to rigid body defined in meta-data file plus the number
153 >      //of rigid bodies defined in meta-data file
154 >      nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms
155 >                                                + nGlobalRigidBodies_;
156    
157 <  for(i = properties.begin(); i != properties.end(); i++)
158 <    delete (*i).second;
157 >      nGlobalMols_ = molStampIds_.size();
158 >      molToProcMap_.resize(nGlobalMols_);
159 >    }
160  
161 < }
161 >  SimInfo::~SimInfo() {
162 >    std::map<int, Molecule*>::iterator i;
163 >    for (i = molecules_.begin(); i != molecules_.end(); ++i) {
164 >      delete i->second;
165 >    }
166 >    molecules_.clear();
167 >      
168 >    delete sman_;
169 >    delete simParams_;
170 >    delete forceField_;
171 >  }
172  
173 < void SimInfo::setBox(double newBox[3]) {
174 <  
175 <  int i, j;
176 <  double tempMat[3][3];
173 >  int SimInfo::getNGlobalConstraints() {
174 >    int nGlobalConstraints;
175 > #ifdef IS_MPI
176 >    MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM,
177 >                  MPI_COMM_WORLD);    
178 > #else
179 >    nGlobalConstraints =  nConstraints_;
180 > #endif
181 >    return nGlobalConstraints;
182 >  }
183  
184 <  for(i=0; i<3; i++)
185 <    for (j=0; j<3; j++) tempMat[i][j] = 0.0;;
184 >  bool SimInfo::addMolecule(Molecule* mol) {
185 >    MoleculeIterator i;
186  
187 <  tempMat[0][0] = newBox[0];
188 <  tempMat[1][1] = newBox[1];
105 <  tempMat[2][2] = newBox[2];
187 >    i = molecules_.find(mol->getGlobalIndex());
188 >    if (i == molecules_.end() ) {
189  
190 <  setBoxM( tempMat );
190 >      molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol));
191 >        
192 >      nAtoms_ += mol->getNAtoms();
193 >      nBonds_ += mol->getNBonds();
194 >      nBends_ += mol->getNBends();
195 >      nTorsions_ += mol->getNTorsions();
196 >      nInversions_ += mol->getNInversions();
197 >      nRigidBodies_ += mol->getNRigidBodies();
198 >      nIntegrableObjects_ += mol->getNIntegrableObjects();
199 >      nCutoffGroups_ += mol->getNCutoffGroups();
200 >      nConstraints_ += mol->getNConstraintPairs();
201  
202 < }
110 <
111 < void SimInfo::setBoxM( double theBox[3][3] ){
202 >      addInteractionPairs(mol);
203    
204 <  int i, j;
205 <  double FortranHmat[9]; // to preserve compatibility with Fortran the
206 <                         // ordering in the array is as follows:
207 <                         // [ 0 3 6 ]
208 <                         // [ 1 4 7 ]
118 <                         // [ 2 5 8 ]
119 <  double FortranHmatInv[9]; // the inverted Hmat (for Fortran);
204 >      return true;
205 >    } else {
206 >      return false;
207 >    }
208 >  }
209  
210 <  if( !boxIsInit ) boxIsInit = 1;
210 >  bool SimInfo::removeMolecule(Molecule* mol) {
211 >    MoleculeIterator i;
212 >    i = molecules_.find(mol->getGlobalIndex());
213  
214 <  for(i=0; i < 3; i++)
124 <    for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j];
125 <  
126 <  calcBoxL();
127 <  calcHmatInv();
214 >    if (i != molecules_.end() ) {
215  
216 <  for(i=0; i < 3; i++) {
217 <    for (j=0; j < 3; j++) {
218 <      FortranHmat[3*j + i] = Hmat[i][j];
219 <      FortranHmatInv[3*j + i] = HmatInv[i][j];
220 <    }
221 <  }
216 >      assert(mol == i->second);
217 >        
218 >      nAtoms_ -= mol->getNAtoms();
219 >      nBonds_ -= mol->getNBonds();
220 >      nBends_ -= mol->getNBends();
221 >      nTorsions_ -= mol->getNTorsions();
222 >      nInversions_ -= mol->getNInversions();
223 >      nRigidBodies_ -= mol->getNRigidBodies();
224 >      nIntegrableObjects_ -= mol->getNIntegrableObjects();
225 >      nCutoffGroups_ -= mol->getNCutoffGroups();
226 >      nConstraints_ -= mol->getNConstraintPairs();
227  
228 <  setFortranBox(FortranHmat, FortranHmatInv, &orthoRhombic);
229 <
138 < }
139 <
228 >      removeInteractionPairs(mol);
229 >      molecules_.erase(mol->getGlobalIndex());
230  
231 < void SimInfo::getBoxM (double theBox[3][3]) {
231 >      delete mol;
232 >        
233 >      return true;
234 >    } else {
235 >      return false;
236 >    }
237  
143  int i, j;
144  for(i=0; i<3; i++)
145    for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j];
146 }
238  
239 +  }    
240  
241 < void SimInfo::scaleBox(double scale) {
242 <  double theBox[3][3];
243 <  int i, j;
241 >        
242 >  Molecule* SimInfo::beginMolecule(MoleculeIterator& i) {
243 >    i = molecules_.begin();
244 >    return i == molecules_.end() ? NULL : i->second;
245 >  }    
246  
247 <  // cerr << "Scaling box by " << scale << "\n";
247 >  Molecule* SimInfo::nextMolecule(MoleculeIterator& i) {
248 >    ++i;
249 >    return i == molecules_.end() ? NULL : i->second;    
250 >  }
251  
155  for(i=0; i<3; i++)
156    for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]*scale;
252  
253 <  setBoxM(theBox);
253 >  void SimInfo::calcNdf() {
254 >    int ndf_local;
255 >    MoleculeIterator i;
256 >    std::vector<StuntDouble*>::iterator j;
257 >    Molecule* mol;
258 >    StuntDouble* integrableObject;
259  
260 < }
260 >    ndf_local = 0;
261 >    
262 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
263 >      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
264 >           integrableObject = mol->nextIntegrableObject(j)) {
265  
266 < void SimInfo::calcHmatInv( void ) {
163 <  
164 <  int oldOrtho;
165 <  int i,j;
166 <  double smallDiag;
167 <  double tol;
168 <  double sanity[3][3];
266 >        ndf_local += 3;
267  
268 <  invertMat3( Hmat, HmatInv );
269 <
270 <  // check to see if Hmat is orthorhombic
271 <  
272 <  oldOrtho = orthoRhombic;
273 <
274 <  smallDiag = fabs(Hmat[0][0]);
275 <  if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]);
178 <  if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]);
179 <  tol = smallDiag * orthoTolerance;
180 <
181 <  orthoRhombic = 1;
182 <  
183 <  for (i = 0; i < 3; i++ ) {
184 <    for (j = 0 ; j < 3; j++) {
185 <      if (i != j) {
186 <        if (orthoRhombic) {
187 <          if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0;
188 <        }        
268 >        if (integrableObject->isDirectional()) {
269 >          if (integrableObject->isLinear()) {
270 >            ndf_local += 2;
271 >          } else {
272 >            ndf_local += 3;
273 >          }
274 >        }
275 >            
276        }
277      }
191  }
192
193  if( oldOrtho != orthoRhombic ){
278      
279 <    if( orthoRhombic ) {
280 <      sprintf( painCave.errMsg,
197 <               "OOPSE is switching from the default Non-Orthorhombic\n"
198 <               "\tto the faster Orthorhombic periodic boundary computations.\n"
199 <               "\tThis is usually a good thing, but if you wan't the\n"
200 <               "\tNon-Orthorhombic computations, make the orthoBoxTolerance\n"
201 <               "\tvariable ( currently set to %G ) smaller.\n",
202 <               orthoTolerance);
203 <      painCave.severity = OOPSE_INFO;
204 <      simError();
205 <    }
206 <    else {
207 <      sprintf( painCave.errMsg,
208 <               "OOPSE is switching from the faster Orthorhombic to the more\n"
209 <               "\tflexible Non-Orthorhombic periodic boundary computations.\n"
210 <               "\tThis is usually because the box has deformed under\n"
211 <               "\tNPTf integration. If you wan't to live on the edge with\n"
212 <               "\tthe Orthorhombic computations, make the orthoBoxTolerance\n"
213 <               "\tvariable ( currently set to %G ) larger.\n",
214 <               orthoTolerance);
215 <      painCave.severity = OOPSE_WARNING;
216 <      simError();
217 <    }
218 <  }
219 < }
279 >    // n_constraints is local, so subtract them on each processor
280 >    ndf_local -= nConstraints_;
281  
282 < void SimInfo::calcBoxL( void ){
282 > #ifdef IS_MPI
283 >    MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
284 > #else
285 >    ndf_ = ndf_local;
286 > #endif
287  
288 <  double dx, dy, dz, dsq;
288 >    // nZconstraints_ is global, as are the 3 COM translations for the
289 >    // entire system:
290 >    ndf_ = ndf_ - 3 - nZconstraint_;
291  
225  // boxVol = Determinant of Hmat
226
227  boxVol = matDet3( Hmat );
228
229  // boxLx
230  
231  dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0];
232  dsq = dx*dx + dy*dy + dz*dz;
233  boxL[0] = sqrt( dsq );
234  //maxCutoff = 0.5 * boxL[0];
235
236  // boxLy
237  
238  dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1];
239  dsq = dx*dx + dy*dy + dz*dz;
240  boxL[1] = sqrt( dsq );
241  //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1];
242
243
244  // boxLz
245  
246  dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2];
247  dsq = dx*dx + dy*dy + dz*dz;
248  boxL[2] = sqrt( dsq );
249  //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2];
250
251  //calculate the max cutoff
252  maxCutoff =  calcMaxCutOff();
253  
254  checkCutOffs();
255
256 }
257
258
259 double SimInfo::calcMaxCutOff(){
260
261  double ri[3], rj[3], rk[3];
262  double rij[3], rjk[3], rki[3];
263  double minDist;
264
265  ri[0] = Hmat[0][0];
266  ri[1] = Hmat[1][0];
267  ri[2] = Hmat[2][0];
268
269  rj[0] = Hmat[0][1];
270  rj[1] = Hmat[1][1];
271  rj[2] = Hmat[2][1];
272
273  rk[0] = Hmat[0][2];
274  rk[1] = Hmat[1][2];
275  rk[2] = Hmat[2][2];
276    
277  crossProduct3(ri, rj, rij);
278  distXY = dotProduct3(rk,rij) / norm3(rij);
279
280  crossProduct3(rj,rk, rjk);
281  distYZ = dotProduct3(ri,rjk) / norm3(rjk);
282
283  crossProduct3(rk,ri, rki);
284  distZX = dotProduct3(rj,rki) / norm3(rki);
285
286  minDist = min(min(distXY, distYZ), distZX);
287  return minDist/2;
288  
289 }
290
291 void SimInfo::wrapVector( double thePos[3] ){
292
293  int i;
294  double scaled[3];
295
296  if( !orthoRhombic ){
297    // calc the scaled coordinates.
298  
299
300    matVecMul3(HmatInv, thePos, scaled);
301    
302    for(i=0; i<3; i++)
303      scaled[i] -= roundMe(scaled[i]);
304    
305    // calc the wrapped real coordinates from the wrapped scaled coordinates
306    
307    matVecMul3(Hmat, scaled, thePos);
308
292    }
310  else{
311    // calc the scaled coordinates.
312    
313    for(i=0; i<3; i++)
314      scaled[i] = thePos[i]*HmatInv[i][i];
315    
316    // wrap the scaled coordinates
317    
318    for(i=0; i<3; i++)
319      scaled[i] -= roundMe(scaled[i]);
320    
321    // calc the wrapped real coordinates from the wrapped scaled coordinates
322    
323    for(i=0; i<3; i++)
324      thePos[i] = scaled[i]*Hmat[i][i];
325  }
326    
327 }
293  
294 <
330 < int SimInfo::getNDF(){
331 <  int ndf_local;
332 <
333 <  ndf_local = 0;
334 <  
335 <  for(int i = 0; i < integrableObjects.size(); i++){
336 <    ndf_local += 3;
337 <    if (integrableObjects[i]->isDirectional()) {
338 <      if (integrableObjects[i]->isLinear())
339 <        ndf_local += 2;
340 <      else
341 <        ndf_local += 3;
342 <    }
343 <  }
344 <
345 <  // n_constraints is local, so subtract them on each processor:
346 <
347 <  ndf_local -= n_constraints;
348 <
294 >  int SimInfo::getFdf() {
295   #ifdef IS_MPI
296 <  MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
296 >    MPI_Allreduce(&fdf_local,&fdf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
297   #else
298 <  ndf = ndf_local;
298 >    fdf_ = fdf_local;
299   #endif
300 <
301 <  // nZconstraints is global, as are the 3 COM translations for the
302 <  // entire system:
303 <
304 <  ndf = ndf - 3 - nZconstraints;
300 >    return fdf_;
301 >  }
302 >    
303 >  void SimInfo::calcNdfRaw() {
304 >    int ndfRaw_local;
305  
306 <  return ndf;
307 < }
306 >    MoleculeIterator i;
307 >    std::vector<StuntDouble*>::iterator j;
308 >    Molecule* mol;
309 >    StuntDouble* integrableObject;
310  
311 < int SimInfo::getNDFraw() {
312 <  int ndfRaw_local;
311 >    // Raw degrees of freedom that we have to set
312 >    ndfRaw_local = 0;
313 >    
314 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
315 >      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
316 >           integrableObject = mol->nextIntegrableObject(j)) {
317  
318 <  // Raw degrees of freedom that we have to set
367 <  ndfRaw_local = 0;
318 >        ndfRaw_local += 3;
319  
320 <  for(int i = 0; i < integrableObjects.size(); i++){
321 <    ndfRaw_local += 3;
322 <    if (integrableObjects[i]->isDirectional()) {
323 <       if (integrableObjects[i]->isLinear())
324 <        ndfRaw_local += 2;
325 <      else
326 <        ndfRaw_local += 3;
320 >        if (integrableObject->isDirectional()) {
321 >          if (integrableObject->isLinear()) {
322 >            ndfRaw_local += 2;
323 >          } else {
324 >            ndfRaw_local += 3;
325 >          }
326 >        }
327 >            
328 >      }
329      }
377  }
330      
331   #ifdef IS_MPI
332 <  MPI_Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
332 >    MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
333   #else
334 <  ndfRaw = ndfRaw_local;
334 >    ndfRaw_ = ndfRaw_local;
335   #endif
336 +  }
337  
338 <  return ndfRaw;
339 < }
338 >  void SimInfo::calcNdfTrans() {
339 >    int ndfTrans_local;
340  
341 < int SimInfo::getNDFtranslational() {
389 <  int ndfTrans_local;
341 >    ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
342  
391  ndfTrans_local = 3 * integrableObjects.size() - n_constraints;
343  
393
344   #ifdef IS_MPI
345 <  MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
345 >    MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
346   #else
347 <  ndfTrans = ndfTrans_local;
347 >    ndfTrans_ = ndfTrans_local;
348   #endif
349  
350 <  ndfTrans = ndfTrans - 3 - nZconstraints;
350 >    ndfTrans_ = ndfTrans_ - 3 - nZconstraint_;
351 >
352 >  }
353  
354 <  return ndfTrans;
355 < }
354 >  void SimInfo::addInteractionPairs(Molecule* mol) {
355 >    ForceFieldOptions& options_ = forceField_->getForceFieldOptions();
356 >    std::vector<Bond*>::iterator bondIter;
357 >    std::vector<Bend*>::iterator bendIter;
358 >    std::vector<Torsion*>::iterator torsionIter;
359 >    std::vector<Inversion*>::iterator inversionIter;
360 >    Bond* bond;
361 >    Bend* bend;
362 >    Torsion* torsion;
363 >    Inversion* inversion;
364 >    int a;
365 >    int b;
366 >    int c;
367 >    int d;
368  
369 < int SimInfo::getTotIntegrableObjects() {
370 <  int nObjs_local;
371 <  int nObjs;
369 >    // atomGroups can be used to add special interaction maps between
370 >    // groups of atoms that are in two separate rigid bodies.
371 >    // However, most site-site interactions between two rigid bodies
372 >    // are probably not special, just the ones between the physically
373 >    // bonded atoms.  Interactions *within* a single rigid body should
374 >    // always be excluded.  These are done at the bottom of this
375 >    // function.
376  
377 <  nObjs_local =  integrableObjects.size();
377 >    std::map<int, std::set<int> > atomGroups;
378 >    Molecule::RigidBodyIterator rbIter;
379 >    RigidBody* rb;
380 >    Molecule::IntegrableObjectIterator ii;
381 >    StuntDouble* integrableObject;
382 >    
383 >    for (integrableObject = mol->beginIntegrableObject(ii);
384 >         integrableObject != NULL;
385 >         integrableObject = mol->nextIntegrableObject(ii)) {
386 >      
387 >      if (integrableObject->isRigidBody()) {
388 >        rb = static_cast<RigidBody*>(integrableObject);
389 >        std::vector<Atom*> atoms = rb->getAtoms();
390 >        std::set<int> rigidAtoms;
391 >        for (int i = 0; i < static_cast<int>(atoms.size()); ++i) {
392 >          rigidAtoms.insert(atoms[i]->getGlobalIndex());
393 >        }
394 >        for (int i = 0; i < static_cast<int>(atoms.size()); ++i) {
395 >          atomGroups.insert(std::map<int, std::set<int> >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms));
396 >        }      
397 >      } else {
398 >        std::set<int> oneAtomSet;
399 >        oneAtomSet.insert(integrableObject->getGlobalIndex());
400 >        atomGroups.insert(std::map<int, std::set<int> >::value_type(integrableObject->getGlobalIndex(), oneAtomSet));        
401 >      }
402 >    }  
403 >          
404 >    for (bond= mol->beginBond(bondIter); bond != NULL;
405 >         bond = mol->nextBond(bondIter)) {
406  
407 +      a = bond->getAtomA()->getGlobalIndex();
408 +      b = bond->getAtomB()->getGlobalIndex();  
409 +    
410 +      if (options_.havevdw12scale() || options_.haveelectrostatic12scale()) {
411 +        oneTwoInteractions_.addPair(a, b);
412 +      } else {
413 +        excludedInteractions_.addPair(a, b);
414 +      }
415 +    }
416  
417 < #ifdef IS_MPI
418 <  MPI_Allreduce(&nObjs_local,&nObjs,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
414 < #else
415 <  nObjs = nObjs_local;
416 < #endif
417 >    for (bend= mol->beginBend(bendIter); bend != NULL;
418 >         bend = mol->nextBend(bendIter)) {
419  
420 +      a = bend->getAtomA()->getGlobalIndex();
421 +      b = bend->getAtomB()->getGlobalIndex();        
422 +      c = bend->getAtomC()->getGlobalIndex();
423 +      
424 +      if (options_.havevdw12scale() || options_.haveelectrostatic12scale()) {
425 +        oneTwoInteractions_.addPair(a, b);      
426 +        oneTwoInteractions_.addPair(b, c);
427 +      } else {
428 +        excludedInteractions_.addPair(a, b);
429 +        excludedInteractions_.addPair(b, c);
430 +      }
431  
432 <  return nObjs;
433 < }
432 >      if (options_.havevdw13scale() || options_.haveelectrostatic13scale()) {
433 >        oneThreeInteractions_.addPair(a, c);      
434 >      } else {
435 >        excludedInteractions_.addPair(a, c);
436 >      }
437 >    }
438  
439 < void SimInfo::refreshSim(){
439 >    for (torsion= mol->beginTorsion(torsionIter); torsion != NULL;
440 >         torsion = mol->nextTorsion(torsionIter)) {
441  
442 <  simtype fInfo;
443 <  int isError;
444 <  int n_global;
445 <  int* excl;
442 >      a = torsion->getAtomA()->getGlobalIndex();
443 >      b = torsion->getAtomB()->getGlobalIndex();        
444 >      c = torsion->getAtomC()->getGlobalIndex();        
445 >      d = torsion->getAtomD()->getGlobalIndex();      
446  
447 <  fInfo.dielect = 0.0;
447 >      if (options_.havevdw12scale() || options_.haveelectrostatic12scale()) {
448 >        oneTwoInteractions_.addPair(a, b);      
449 >        oneTwoInteractions_.addPair(b, c);
450 >        oneTwoInteractions_.addPair(c, d);
451 >      } else {
452 >        excludedInteractions_.addPair(a, b);
453 >        excludedInteractions_.addPair(b, c);
454 >        excludedInteractions_.addPair(c, d);
455 >      }
456  
457 <  if( useDipoles ){
458 <    if( useReactionField )fInfo.dielect = dielectric;
459 <  }
457 >      if (options_.havevdw13scale() || options_.haveelectrostatic13scale()) {
458 >        oneThreeInteractions_.addPair(a, c);      
459 >        oneThreeInteractions_.addPair(b, d);      
460 >      } else {
461 >        excludedInteractions_.addPair(a, c);
462 >        excludedInteractions_.addPair(b, d);
463 >      }
464  
465 <  fInfo.SIM_uses_PBC = usePBC;
466 <  //fInfo.SIM_uses_LJ = 0;
467 <  fInfo.SIM_uses_LJ = useLJ;
468 <  fInfo.SIM_uses_sticky = useSticky;
469 <  //fInfo.SIM_uses_sticky = 0;
470 <  fInfo.SIM_uses_charges = useCharges;
441 <  fInfo.SIM_uses_dipoles = useDipoles;
442 <  //fInfo.SIM_uses_dipoles = 0;
443 <  fInfo.SIM_uses_RF = useReactionField;
444 <  //fInfo.SIM_uses_RF = 0;
445 <  fInfo.SIM_uses_GB = useGB;
446 <  fInfo.SIM_uses_EAM = useEAM;
465 >      if (options_.havevdw14scale() || options_.haveelectrostatic14scale()) {
466 >        oneFourInteractions_.addPair(a, d);      
467 >      } else {
468 >        excludedInteractions_.addPair(a, d);
469 >      }
470 >    }
471  
472 <  n_exclude = excludes->getSize();
473 <  excl = excludes->getFortranArray();
450 <  
451 < #ifdef IS_MPI
452 <  n_global = mpiSim->getNAtomsGlobal();
453 < #else
454 <  n_global = n_atoms;
455 < #endif
456 <  
457 <  isError = 0;
458 <  
459 <  getFortranGroupArrays(this, FglobalGroupMembership, mfact);
460 <  //it may not be a good idea to pass the address of first element in vector
461 <  //since c++ standard does not require vector to be stored continuously in meomory
462 <  //Most of the compilers will organize the memory of vector continuously
463 <  setFortranSim( &fInfo, &n_global, &n_atoms, identArray, &n_exclude, excl,
464 <                  &nGlobalExcludes, globalExcludes, molMembershipArray,
465 <                  &mfact[0], &ngroup, &FglobalGroupMembership[0], &isError);
472 >    for (inversion= mol->beginInversion(inversionIter); inversion != NULL;
473 >         inversion = mol->nextInversion(inversionIter)) {
474  
475 <  if( isError ){
476 <    
477 <    sprintf( painCave.errMsg,
478 <             "There was an error setting the simulation information in fortran.\n" );
479 <    painCave.isFatal = 1;
480 <    painCave.severity = OOPSE_ERROR;
481 <    simError();
475 >      a = inversion->getAtomA()->getGlobalIndex();
476 >      b = inversion->getAtomB()->getGlobalIndex();        
477 >      c = inversion->getAtomC()->getGlobalIndex();        
478 >      d = inversion->getAtomD()->getGlobalIndex();        
479 >
480 >      if (options_.havevdw12scale() || options_.haveelectrostatic12scale()) {
481 >        oneTwoInteractions_.addPair(a, b);      
482 >        oneTwoInteractions_.addPair(a, c);
483 >        oneTwoInteractions_.addPair(a, d);
484 >      } else {
485 >        excludedInteractions_.addPair(a, b);
486 >        excludedInteractions_.addPair(a, c);
487 >        excludedInteractions_.addPair(a, d);
488 >      }
489 >
490 >      if (options_.havevdw13scale() || options_.haveelectrostatic13scale()) {
491 >        oneThreeInteractions_.addPair(b, c);    
492 >        oneThreeInteractions_.addPair(b, d);    
493 >        oneThreeInteractions_.addPair(c, d);      
494 >      } else {
495 >        excludedInteractions_.addPair(b, c);
496 >        excludedInteractions_.addPair(b, d);
497 >        excludedInteractions_.addPair(c, d);
498 >      }
499 >    }
500 >
501 >    for (rb = mol->beginRigidBody(rbIter); rb != NULL;
502 >         rb = mol->nextRigidBody(rbIter)) {
503 >      std::vector<Atom*> atoms = rb->getAtoms();
504 >      for (int i = 0; i < static_cast<int>(atoms.size()) -1 ; ++i) {
505 >        for (int j = i + 1; j < static_cast<int>(atoms.size()); ++j) {
506 >          a = atoms[i]->getGlobalIndex();
507 >          b = atoms[j]->getGlobalIndex();
508 >          excludedInteractions_.addPair(a, b);
509 >        }
510 >      }
511 >    }        
512 >
513    }
514 +
515 +  void SimInfo::removeInteractionPairs(Molecule* mol) {
516 +    ForceFieldOptions& options_ = forceField_->getForceFieldOptions();
517 +    std::vector<Bond*>::iterator bondIter;
518 +    std::vector<Bend*>::iterator bendIter;
519 +    std::vector<Torsion*>::iterator torsionIter;
520 +    std::vector<Inversion*>::iterator inversionIter;
521 +    Bond* bond;
522 +    Bend* bend;
523 +    Torsion* torsion;
524 +    Inversion* inversion;
525 +    int a;
526 +    int b;
527 +    int c;
528 +    int d;
529 +
530 +    std::map<int, std::set<int> > atomGroups;
531 +    Molecule::RigidBodyIterator rbIter;
532 +    RigidBody* rb;
533 +    Molecule::IntegrableObjectIterator ii;
534 +    StuntDouble* integrableObject;
535 +    
536 +    for (integrableObject = mol->beginIntegrableObject(ii);
537 +         integrableObject != NULL;
538 +         integrableObject = mol->nextIntegrableObject(ii)) {
539 +      
540 +      if (integrableObject->isRigidBody()) {
541 +        rb = static_cast<RigidBody*>(integrableObject);
542 +        std::vector<Atom*> atoms = rb->getAtoms();
543 +        std::set<int> rigidAtoms;
544 +        for (int i = 0; i < static_cast<int>(atoms.size()); ++i) {
545 +          rigidAtoms.insert(atoms[i]->getGlobalIndex());
546 +        }
547 +        for (int i = 0; i < static_cast<int>(atoms.size()); ++i) {
548 +          atomGroups.insert(std::map<int, std::set<int> >::value_type(atoms[i]->getGlobalIndex(), rigidAtoms));
549 +        }      
550 +      } else {
551 +        std::set<int> oneAtomSet;
552 +        oneAtomSet.insert(integrableObject->getGlobalIndex());
553 +        atomGroups.insert(std::map<int, std::set<int> >::value_type(integrableObject->getGlobalIndex(), oneAtomSet));        
554 +      }
555 +    }  
556 +
557 +    for (bond= mol->beginBond(bondIter); bond != NULL;
558 +         bond = mol->nextBond(bondIter)) {
559 +      
560 +      a = bond->getAtomA()->getGlobalIndex();
561 +      b = bond->getAtomB()->getGlobalIndex();  
562 +    
563 +      if (options_.havevdw12scale() || options_.haveelectrostatic12scale()) {
564 +        oneTwoInteractions_.removePair(a, b);
565 +      } else {
566 +        excludedInteractions_.removePair(a, b);
567 +      }
568 +    }
569 +
570 +    for (bend= mol->beginBend(bendIter); bend != NULL;
571 +         bend = mol->nextBend(bendIter)) {
572 +
573 +      a = bend->getAtomA()->getGlobalIndex();
574 +      b = bend->getAtomB()->getGlobalIndex();        
575 +      c = bend->getAtomC()->getGlobalIndex();
576 +      
577 +      if (options_.havevdw12scale() || options_.haveelectrostatic12scale()) {
578 +        oneTwoInteractions_.removePair(a, b);      
579 +        oneTwoInteractions_.removePair(b, c);
580 +      } else {
581 +        excludedInteractions_.removePair(a, b);
582 +        excludedInteractions_.removePair(b, c);
583 +      }
584 +
585 +      if (options_.havevdw13scale() || options_.haveelectrostatic13scale()) {
586 +        oneThreeInteractions_.removePair(a, c);      
587 +      } else {
588 +        excludedInteractions_.removePair(a, c);
589 +      }
590 +    }
591 +
592 +    for (torsion= mol->beginTorsion(torsionIter); torsion != NULL;
593 +         torsion = mol->nextTorsion(torsionIter)) {
594 +
595 +      a = torsion->getAtomA()->getGlobalIndex();
596 +      b = torsion->getAtomB()->getGlobalIndex();        
597 +      c = torsion->getAtomC()->getGlobalIndex();        
598 +      d = torsion->getAtomD()->getGlobalIndex();      
599    
600 < #ifdef IS_MPI
601 <  sprintf( checkPointMsg,
602 <           "succesfully sent the simulation information to fortran.\n");
603 <  MPIcheckPoint();
604 < #endif // is_mpi
605 <  
606 <  this->ndf = this->getNDF();
607 <  this->ndfRaw = this->getNDFraw();
608 <  this->ndfTrans = this->getNDFtranslational();
485 < }
600 >      if (options_.havevdw12scale() || options_.haveelectrostatic12scale()) {
601 >        oneTwoInteractions_.removePair(a, b);      
602 >        oneTwoInteractions_.removePair(b, c);
603 >        oneTwoInteractions_.removePair(c, d);
604 >      } else {
605 >        excludedInteractions_.removePair(a, b);
606 >        excludedInteractions_.removePair(b, c);
607 >        excludedInteractions_.removePair(c, d);
608 >      }
609  
610 < void SimInfo::setDefaultRcut( double theRcut ){
610 >      if (options_.havevdw13scale() || options_.haveelectrostatic13scale()) {
611 >        oneThreeInteractions_.removePair(a, c);      
612 >        oneThreeInteractions_.removePair(b, d);      
613 >      } else {
614 >        excludedInteractions_.removePair(a, c);
615 >        excludedInteractions_.removePair(b, d);
616 >      }
617 >
618 >      if (options_.havevdw14scale() || options_.haveelectrostatic14scale()) {
619 >        oneFourInteractions_.removePair(a, d);      
620 >      } else {
621 >        excludedInteractions_.removePair(a, d);
622 >      }
623 >    }
624 >
625 >    for (inversion= mol->beginInversion(inversionIter); inversion != NULL;
626 >         inversion = mol->nextInversion(inversionIter)) {
627 >
628 >      a = inversion->getAtomA()->getGlobalIndex();
629 >      b = inversion->getAtomB()->getGlobalIndex();        
630 >      c = inversion->getAtomC()->getGlobalIndex();        
631 >      d = inversion->getAtomD()->getGlobalIndex();        
632 >
633 >      if (options_.havevdw12scale() || options_.haveelectrostatic12scale()) {
634 >        oneTwoInteractions_.removePair(a, b);      
635 >        oneTwoInteractions_.removePair(a, c);
636 >        oneTwoInteractions_.removePair(a, d);
637 >      } else {
638 >        excludedInteractions_.removePair(a, b);
639 >        excludedInteractions_.removePair(a, c);
640 >        excludedInteractions_.removePair(a, d);
641 >      }
642 >
643 >      if (options_.havevdw13scale() || options_.haveelectrostatic13scale()) {
644 >        oneThreeInteractions_.removePair(b, c);    
645 >        oneThreeInteractions_.removePair(b, d);    
646 >        oneThreeInteractions_.removePair(c, d);      
647 >      } else {
648 >        excludedInteractions_.removePair(b, c);
649 >        excludedInteractions_.removePair(b, d);
650 >        excludedInteractions_.removePair(c, d);
651 >      }
652 >    }
653 >
654 >    for (rb = mol->beginRigidBody(rbIter); rb != NULL;
655 >         rb = mol->nextRigidBody(rbIter)) {
656 >      std::vector<Atom*> atoms = rb->getAtoms();
657 >      for (int i = 0; i < static_cast<int>(atoms.size()) -1 ; ++i) {
658 >        for (int j = i + 1; j < static_cast<int>(atoms.size()); ++j) {
659 >          a = atoms[i]->getGlobalIndex();
660 >          b = atoms[j]->getGlobalIndex();
661 >          excludedInteractions_.removePair(a, b);
662 >        }
663 >      }
664 >    }        
665 >    
666 >  }
667    
489  haveRcut = 1;
490  rCut = theRcut;
491  rList = rCut + 1.0;
668    
669 <  notifyFortranCutoffs( &rCut, &rSw, &rList );
670 < }
669 >  void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) {
670 >    int curStampId;
671 >    
672 >    //index from 0
673 >    curStampId = moleculeStamps_.size();
674  
675 < void SimInfo::setDefaultRcut( double theRcut, double theRsw ){
675 >    moleculeStamps_.push_back(molStamp);
676 >    molStampIds_.insert(molStampIds_.end(), nmol, curStampId);
677 >  }
678  
679 <  rSw = theRsw;
680 <  setDefaultRcut( theRcut );
681 < }
679 >  void SimInfo::update() {
680 >
681 >    setupSimType();
682 >
683 > #ifdef IS_MPI
684 >    setupFortranParallel();
685 > #endif
686 >
687 >    setupFortranSim();
688 >
689 >    //setup fortran force field
690 >    /** @deprecate */    
691 >    int isError = 0;
692 >    
693 >    setupCutoff();
694 >    
695 >    setupElectrostaticSummationMethod( isError );
696 >    setupSwitchingFunction();
697 >    setupAccumulateBoxDipole();
698 >
699 >    if(isError){
700 >      sprintf( painCave.errMsg,
701 >               "ForceField error: There was an error initializing the forceField in fortran.\n" );
702 >      painCave.isFatal = 1;
703 >      simError();
704 >    }
705 >
706 >    calcNdf();
707 >    calcNdfRaw();
708 >    calcNdfTrans();
709 >
710 >    fortranInitialized_ = true;
711 >  }
712 >
713 >  std::set<AtomType*> SimInfo::getUniqueAtomTypes() {
714 >    SimInfo::MoleculeIterator mi;
715 >    Molecule* mol;
716 >    Molecule::AtomIterator ai;
717 >    Atom* atom;
718 >    std::set<AtomType*> atomTypes;
719 >
720 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
721 >
722 >      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
723 >        atomTypes.insert(atom->getAtomType());
724 >      }
725 >        
726 >    }
727 >
728 >    return atomTypes;        
729 >  }
730 >
731 >  void SimInfo::setupSimType() {
732 >    std::set<AtomType*>::iterator i;
733 >    std::set<AtomType*> atomTypes;
734 >    atomTypes = getUniqueAtomTypes();
735 >    
736 >    int useLennardJones = 0;
737 >    int useElectrostatic = 0;
738 >    int useEAM = 0;
739 >    int useSC = 0;
740 >    int useCharge = 0;
741 >    int useDirectional = 0;
742 >    int useDipole = 0;
743 >    int useGayBerne = 0;
744 >    int useSticky = 0;
745 >    int useStickyPower = 0;
746 >    int useShape = 0;
747 >    int useFLARB = 0; //it is not in AtomType yet
748 >    int useDirectionalAtom = 0;    
749 >    int useElectrostatics = 0;
750 >    //usePBC and useRF are from simParams
751 >    int usePBC = simParams_->getUsePeriodicBoundaryConditions();
752 >    int useRF;
753 >    int useSF;
754 >    int useSP;
755 >    int useBoxDipole;
756  
757 +    std::string myMethod;
758  
759 < void SimInfo::checkCutOffs( void ){
760 <  
761 <  if( boxIsInit ){
759 >    // set the useRF logical
760 >    useRF = 0;
761 >    useSF = 0;
762 >    useSP = 0;
763 >    useBoxDipole = 0;
764 >
765 >
766 >    if (simParams_->haveElectrostaticSummationMethod()) {
767 >      std::string myMethod = simParams_->getElectrostaticSummationMethod();
768 >      toUpper(myMethod);
769 >      if (myMethod == "REACTION_FIELD"){
770 >        useRF = 1;
771 >      } else if (myMethod == "SHIFTED_FORCE"){
772 >        useSF = 1;
773 >      } else if (myMethod == "SHIFTED_POTENTIAL"){
774 >        useSP = 1;
775 >      }
776 >    }
777      
778 <    //we need to check cutOffs against the box
779 <    
780 <    if( rCut > maxCutoff ){
510 <      sprintf( painCave.errMsg,
511 <               "cutoffRadius is too large for the current periodic box.\n"
512 <               "\tCurrent Value of cutoffRadius = %G at time %G\n "
513 <               "\tThis is larger than half of at least one of the\n"
514 <               "\tperiodic box vectors.  Right now, the Box matrix is:\n"
515 <               "\n"
516 <               "\t[ %G %G %G ]\n"
517 <               "\t[ %G %G %G ]\n"
518 <               "\t[ %G %G %G ]\n",
519 <               rCut, currentTime,
520 <               Hmat[0][0], Hmat[0][1], Hmat[0][2],
521 <               Hmat[1][0], Hmat[1][1], Hmat[1][2],
522 <               Hmat[2][0], Hmat[2][1], Hmat[2][2]);
523 <      painCave.severity = OOPSE_ERROR;
524 <      painCave.isFatal = 1;
525 <      simError();
526 <    }    
527 <  } else {
528 <    // initialize this stuff before using it, OK?
529 <    sprintf( painCave.errMsg,
530 <             "Trying to check cutoffs without a box.\n"
531 <             "\tOOPSE should have better programmers than that.\n" );
532 <    painCave.severity = OOPSE_ERROR;
533 <    painCave.isFatal = 1;
534 <    simError();      
535 <  }
536 <  
537 < }
778 >    if (simParams_->haveAccumulateBoxDipole())
779 >      if (simParams_->getAccumulateBoxDipole())
780 >        useBoxDipole = 1;
781  
782 < void SimInfo::addProperty(GenericData* prop){
782 >    useAtomicVirial_ = simParams_->getUseAtomicVirial();
783  
784 <  map<string, GenericData*>::iterator result;
785 <  result = properties.find(prop->getID());
786 <  
787 <  //we can't simply use  properties[prop->getID()] = prop,
788 <  //it will cause memory leak if we already contain a propery which has the same name of prop
789 <  
790 <  if(result != properties.end()){
784 >    //loop over all of the atom types
785 >    for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
786 >      useLennardJones |= (*i)->isLennardJones();
787 >      useElectrostatic |= (*i)->isElectrostatic();
788 >      useEAM |= (*i)->isEAM();
789 >      useSC |= (*i)->isSC();
790 >      useCharge |= (*i)->isCharge();
791 >      useDirectional |= (*i)->isDirectional();
792 >      useDipole |= (*i)->isDipole();
793 >      useGayBerne |= (*i)->isGayBerne();
794 >      useSticky |= (*i)->isSticky();
795 >      useStickyPower |= (*i)->isStickyPower();
796 >      useShape |= (*i)->isShape();
797 >    }
798 >
799 >    if (useSticky || useStickyPower || useDipole || useGayBerne || useShape) {
800 >      useDirectionalAtom = 1;
801 >    }
802 >
803 >    if (useCharge || useDipole) {
804 >      useElectrostatics = 1;
805 >    }
806 >
807 > #ifdef IS_MPI    
808 >    int temp;
809 >
810 >    temp = usePBC;
811 >    MPI_Allreduce(&temp, &usePBC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
812 >
813 >    temp = useDirectionalAtom;
814 >    MPI_Allreduce(&temp, &useDirectionalAtom, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
815 >
816 >    temp = useLennardJones;
817 >    MPI_Allreduce(&temp, &useLennardJones, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
818 >
819 >    temp = useElectrostatics;
820 >    MPI_Allreduce(&temp, &useElectrostatics, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
821 >
822 >    temp = useCharge;
823 >    MPI_Allreduce(&temp, &useCharge, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
824 >
825 >    temp = useDipole;
826 >    MPI_Allreduce(&temp, &useDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
827 >
828 >    temp = useSticky;
829 >    MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
830 >
831 >    temp = useStickyPower;
832 >    MPI_Allreduce(&temp, &useStickyPower, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
833      
834 <    delete (*result).second;
835 <    (*result).second = prop;
551 <      
552 <  }
553 <  else{
834 >    temp = useGayBerne;
835 >    MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
836  
837 <    properties[prop->getID()] = prop;
837 >    temp = useEAM;
838 >    MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
839  
840 <  }
840 >    temp = useSC;
841 >    MPI_Allreduce(&temp, &useSC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
842      
843 < }
843 >    temp = useShape;
844 >    MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);  
845  
846 < GenericData* SimInfo::getProperty(const string& propName){
847 <
563 <  map<string, GenericData*>::iterator result;
564 <  
565 <  //string lowerCaseName = ();
566 <  
567 <  result = properties.find(propName);
568 <  
569 <  if(result != properties.end())
570 <    return (*result).second;  
571 <  else  
572 <    return NULL;  
573 < }
846 >    temp = useFLARB;
847 >    MPI_Allreduce(&temp, &useFLARB, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
848  
849 +    temp = useRF;
850 +    MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
851  
852 < void SimInfo::getFortranGroupArrays(SimInfo* info,
853 <                                    vector<int>& FglobalGroupMembership,
578 <                                    vector<double>& mfact){
579 <  
580 <  Molecule* myMols;
581 <  Atom** myAtoms;
582 <  int numAtom;
583 <  double mtot;
584 <  int numMol;
585 <  int numCutoffGroups;
586 <  CutoffGroup* myCutoffGroup;
587 <  vector<CutoffGroup*>::iterator iterCutoff;
588 <  Atom* cutoffAtom;
589 <  vector<Atom*>::iterator iterAtom;
590 <  int atomIndex;
591 <  double totalMass;
592 <  
593 <  mfact.clear();
594 <  FglobalGroupMembership.clear();
595 <  
852 >    temp = useSF;
853 >    MPI_Allreduce(&temp, &useSF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);  
854  
855 <  // Fix the silly fortran indexing problem
856 < #ifdef IS_MPI
857 <  numAtom = mpiSim->getNAtomsGlobal();
858 < #else
859 <  numAtom = n_atoms;
855 >    temp = useSP;
856 >    MPI_Allreduce(&temp, &useSP, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
857 >
858 >    temp = useBoxDipole;
859 >    MPI_Allreduce(&temp, &useBoxDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
860 >
861 >    temp = useAtomicVirial_;
862 >    MPI_Allreduce(&temp, &useAtomicVirial_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);
863 >
864   #endif
603  for (int i = 0; i < numAtom; i++)
604    FglobalGroupMembership.push_back(globalGroupMembership[i] + 1);
605  
865  
866 <  myMols = info->molecules;
867 <  numMol = info->n_mol;
868 <  for(int i  = 0; i < numMol; i++){
869 <    numCutoffGroups = myMols[i].getNCutoffGroups();
870 <    for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff);
871 <        myCutoffGroup != NULL;
872 <        myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){
866 >    fInfo_.SIM_uses_PBC = usePBC;    
867 >    fInfo_.SIM_uses_DirectionalAtoms = useDirectionalAtom;
868 >    fInfo_.SIM_uses_LennardJones = useLennardJones;
869 >    fInfo_.SIM_uses_Electrostatics = useElectrostatics;    
870 >    fInfo_.SIM_uses_Charges = useCharge;
871 >    fInfo_.SIM_uses_Dipoles = useDipole;
872 >    fInfo_.SIM_uses_Sticky = useSticky;
873 >    fInfo_.SIM_uses_StickyPower = useStickyPower;
874 >    fInfo_.SIM_uses_GayBerne = useGayBerne;
875 >    fInfo_.SIM_uses_EAM = useEAM;
876 >    fInfo_.SIM_uses_SC = useSC;
877 >    fInfo_.SIM_uses_Shapes = useShape;
878 >    fInfo_.SIM_uses_FLARB = useFLARB;
879 >    fInfo_.SIM_uses_RF = useRF;
880 >    fInfo_.SIM_uses_SF = useSF;
881 >    fInfo_.SIM_uses_SP = useSP;
882 >    fInfo_.SIM_uses_BoxDipole = useBoxDipole;
883 >    fInfo_.SIM_uses_AtomicVirial = useAtomicVirial_;
884 >  }
885  
886 <      totalMass = myCutoffGroup->getMass();
886 >  void SimInfo::setupFortranSim() {
887 >    int isError;
888 >    int nExclude, nOneTwo, nOneThree, nOneFour;
889 >    std::vector<int> fortranGlobalGroupMembership;
890 >    
891 >    isError = 0;
892 >
893 >    //globalGroupMembership_ is filled by SimCreator    
894 >    for (int i = 0; i < nGlobalAtoms_; i++) {
895 >      fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1);
896 >    }
897 >
898 >    //calculate mass ratio of cutoff group
899 >    std::vector<RealType> mfact;
900 >    SimInfo::MoleculeIterator mi;
901 >    Molecule* mol;
902 >    Molecule::CutoffGroupIterator ci;
903 >    CutoffGroup* cg;
904 >    Molecule::AtomIterator ai;
905 >    Atom* atom;
906 >    RealType totalMass;
907 >
908 >    //to avoid memory reallocation, reserve enough space for mfact
909 >    mfact.reserve(getNCutoffGroups());
910 >    
911 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
912 >      for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
913 >
914 >        totalMass = cg->getMass();
915 >        for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
916 >          // Check for massless groups - set mfact to 1 if true
917 >          if (totalMass != 0)
918 >            mfact.push_back(atom->getMass()/totalMass);
919 >          else
920 >            mfact.push_back( 1.0 );
921 >        }
922 >      }      
923 >    }
924 >
925 >    //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!)
926 >    std::vector<int> identArray;
927 >
928 >    //to avoid memory reallocation, reserve enough space identArray
929 >    identArray.reserve(getNAtoms());
930 >    
931 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
932 >      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
933 >        identArray.push_back(atom->getIdent());
934 >      }
935 >    }    
936 >
937 >    //fill molMembershipArray
938 >    //molMembershipArray is filled by SimCreator    
939 >    std::vector<int> molMembershipArray(nGlobalAtoms_);
940 >    for (int i = 0; i < nGlobalAtoms_; i++) {
941 >      molMembershipArray[i] = globalMolMembership_[i] + 1;
942 >    }
943 >    
944 >    //setup fortran simulation
945 >
946 >    nExclude = excludedInteractions_.getSize();
947 >    nOneTwo = oneTwoInteractions_.getSize();
948 >    nOneThree = oneThreeInteractions_.getSize();
949 >    nOneFour = oneFourInteractions_.getSize();
950 >
951 >    int* excludeList = excludedInteractions_.getPairList();
952 >    int* oneTwoList = oneTwoInteractions_.getPairList();
953 >    int* oneThreeList = oneThreeInteractions_.getPairList();
954 >    int* oneFourList = oneFourInteractions_.getPairList();
955 >
956 >    setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0],
957 >                   &nExclude, excludeList,
958 >                   &nOneTwo, oneTwoList,
959 >                   &nOneThree, oneThreeList,
960 >                   &nOneFour, oneFourList,
961 >                   &molMembershipArray[0], &mfact[0], &nCutoffGroups_,
962 >                   &fortranGlobalGroupMembership[0], &isError);
963 >    
964 >    if( isError ){
965        
966 <      for(cutoffAtom = myCutoffGroup->beginAtom(iterAtom);
967 <          cutoffAtom != NULL;
968 <          cutoffAtom = myCutoffGroup->nextAtom(iterAtom)){
969 <        mfact.push_back(cutoffAtom->getMass()/totalMass);
970 <      }  
966 >      sprintf( painCave.errMsg,
967 >               "There was an error setting the simulation information in fortran.\n" );
968 >      painCave.isFatal = 1;
969 >      painCave.severity = OPENMD_ERROR;
970 >      simError();
971 >    }
972 >    
973 >    
974 >    sprintf( checkPointMsg,
975 >             "succesfully sent the simulation information to fortran.\n");
976 >    
977 >    errorCheckPoint();
978 >    
979 >    // Setup number of neighbors in neighbor list if present
980 >    if (simParams_->haveNeighborListNeighbors()) {
981 >      int nlistNeighbors = simParams_->getNeighborListNeighbors();
982 >      setNeighbors(&nlistNeighbors);
983 >    }
984 >  
985 >
986 >  }
987 >
988 >
989 >  void SimInfo::setupFortranParallel() {
990 > #ifdef IS_MPI    
991 >    //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex
992 >    std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0);
993 >    std::vector<int> localToGlobalCutoffGroupIndex;
994 >    SimInfo::MoleculeIterator mi;
995 >    Molecule::AtomIterator ai;
996 >    Molecule::CutoffGroupIterator ci;
997 >    Molecule* mol;
998 >    Atom* atom;
999 >    CutoffGroup* cg;
1000 >    mpiSimData parallelData;
1001 >    int isError;
1002 >
1003 >    for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
1004 >
1005 >      //local index(index in DataStorge) of atom is important
1006 >      for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
1007 >        localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1;
1008 >      }
1009 >
1010 >      //local index of cutoff group is trivial, it only depends on the order of travesing
1011 >      for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
1012 >        localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1);
1013 >      }        
1014 >        
1015 >    }
1016 >
1017 >    //fill up mpiSimData struct
1018 >    parallelData.nMolGlobal = getNGlobalMolecules();
1019 >    parallelData.nMolLocal = getNMolecules();
1020 >    parallelData.nAtomsGlobal = getNGlobalAtoms();
1021 >    parallelData.nAtomsLocal = getNAtoms();
1022 >    parallelData.nGroupsGlobal = getNGlobalCutoffGroups();
1023 >    parallelData.nGroupsLocal = getNCutoffGroups();
1024 >    parallelData.myNode = worldRank;
1025 >    MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors));
1026 >
1027 >    //pass mpiSimData struct and index arrays to fortran
1028 >    setFsimParallel(&parallelData, &(parallelData.nAtomsLocal),
1029 >                    &localToGlobalAtomIndex[0],  &(parallelData.nGroupsLocal),
1030 >                    &localToGlobalCutoffGroupIndex[0], &isError);
1031 >
1032 >    if (isError) {
1033 >      sprintf(painCave.errMsg,
1034 >              "mpiRefresh errror: fortran didn't like something we gave it.\n");
1035 >      painCave.isFatal = 1;
1036 >      simError();
1037 >    }
1038 >
1039 >    sprintf(checkPointMsg, " mpiRefresh successful.\n");
1040 >    errorCheckPoint();
1041 >
1042 > #endif
1043 >  }
1044 >
1045 >  void SimInfo::setupCutoff() {          
1046 >    
1047 >    ForceFieldOptions& forceFieldOptions_ = forceField_->getForceFieldOptions();
1048 >
1049 >    // Check the cutoff policy
1050 >    int cp =  TRADITIONAL_CUTOFF_POLICY; // Set to traditional by default
1051 >
1052 >    // Set LJ shifting bools to false
1053 >    ljsp_ = 0;
1054 >    ljsf_ = 0;
1055 >
1056 >    std::string myPolicy;
1057 >    if (forceFieldOptions_.haveCutoffPolicy()){
1058 >      myPolicy = forceFieldOptions_.getCutoffPolicy();
1059 >    }else if (simParams_->haveCutoffPolicy()) {
1060 >      myPolicy = simParams_->getCutoffPolicy();
1061 >    }
1062 >
1063 >    if (!myPolicy.empty()){
1064 >      toUpper(myPolicy);
1065 >      if (myPolicy == "MIX") {
1066 >        cp = MIX_CUTOFF_POLICY;
1067 >      } else {
1068 >        if (myPolicy == "MAX") {
1069 >          cp = MAX_CUTOFF_POLICY;
1070 >        } else {
1071 >          if (myPolicy == "TRADITIONAL") {            
1072 >            cp = TRADITIONAL_CUTOFF_POLICY;
1073 >          } else {
1074 >            // throw error        
1075 >            sprintf( painCave.errMsg,
1076 >                     "SimInfo error: Unknown cutoffPolicy. (Input file specified %s .)\n\tcutoffPolicy must be one of: \"Mix\", \"Max\", or \"Traditional\".", myPolicy.c_str() );
1077 >            painCave.isFatal = 1;
1078 >            simError();
1079 >          }    
1080 >        }          
1081 >      }
1082 >    }          
1083 >    notifyFortranCutoffPolicy(&cp);
1084 >
1085 >    // Check the Skin Thickness for neighborlists
1086 >    RealType skin;
1087 >    if (simParams_->haveSkinThickness()) {
1088 >      skin = simParams_->getSkinThickness();
1089 >      notifyFortranSkinThickness(&skin);
1090 >    }            
1091 >        
1092 >    // Check if the cutoff was set explicitly:
1093 >    if (simParams_->haveCutoffRadius()) {
1094 >      rcut_ = simParams_->getCutoffRadius();
1095 >      if (simParams_->haveSwitchingRadius()) {
1096 >        rsw_  = simParams_->getSwitchingRadius();
1097 >      } else {
1098 >        if (fInfo_.SIM_uses_Charges |
1099 >            fInfo_.SIM_uses_Dipoles |
1100 >            fInfo_.SIM_uses_RF) {
1101 >          
1102 >          rsw_ = 0.85 * rcut_;
1103 >          sprintf(painCave.errMsg,
1104 >                  "SimCreator Warning: No value was set for the switchingRadius.\n"
1105 >                  "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
1106 >                  "\tswitchingRadius = %f. for this simulation\n", rsw_);
1107 >        painCave.isFatal = 0;
1108 >        simError();
1109 >        } else {
1110 >          rsw_ = rcut_;
1111 >          sprintf(painCave.errMsg,
1112 >                  "SimCreator Warning: No value was set for the switchingRadius.\n"
1113 >                  "\tOpenMD will use the same value as the cutoffRadius.\n"
1114 >                  "\tswitchingRadius = %f. for this simulation\n", rsw_);
1115 >          painCave.isFatal = 0;
1116 >          simError();
1117 >        }
1118 >      }
1119 >
1120 >      if (simParams_->haveElectrostaticSummationMethod()) {
1121 >        std::string myMethod = simParams_->getElectrostaticSummationMethod();
1122 >        toUpper(myMethod);
1123 >        
1124 >        if (myMethod == "SHIFTED_POTENTIAL") {
1125 >          ljsp_ = 1;
1126 >        } else if (myMethod == "SHIFTED_FORCE") {
1127 >          ljsf_ = 1;
1128 >        }
1129 >      }
1130 >
1131 >      notifyFortranCutoffs(&rcut_, &rsw_, &ljsp_, &ljsf_);
1132 >      
1133 >    } else {
1134 >      
1135 >      // For electrostatic atoms, we'll assume a large safe value:
1136 >      if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) {
1137 >        sprintf(painCave.errMsg,
1138 >                "SimCreator Warning: No value was set for the cutoffRadius.\n"
1139 >                "\tOpenMD will use a default value of 15.0 angstroms"
1140 >                "\tfor the cutoffRadius.\n");
1141 >        painCave.isFatal = 0;
1142 >        simError();
1143 >        rcut_ = 15.0;
1144 >      
1145 >        if (simParams_->haveElectrostaticSummationMethod()) {
1146 >          std::string myMethod = simParams_->getElectrostaticSummationMethod();
1147 >          toUpper(myMethod);
1148 >          
1149 >          // For the time being, we're tethering the LJ shifted behavior to the
1150 >          // electrostaticSummationMethod keyword options
1151 >          if (myMethod == "SHIFTED_POTENTIAL") {
1152 >            ljsp_ = 1;
1153 >          } else if (myMethod == "SHIFTED_FORCE") {
1154 >            ljsf_ = 1;
1155 >          }
1156 >          if (myMethod == "SHIFTED_POTENTIAL" || myMethod == "SHIFTED_FORCE") {
1157 >            if (simParams_->haveSwitchingRadius()){
1158 >              sprintf(painCave.errMsg,
1159 >                      "SimInfo Warning: A value was set for the switchingRadius\n"
1160 >                      "\teven though the electrostaticSummationMethod was\n"
1161 >                      "\tset to %s\n", myMethod.c_str());
1162 >              painCave.isFatal = 1;
1163 >              simError();            
1164 >            }
1165 >          }
1166 >        }
1167 >      
1168 >        if (simParams_->haveSwitchingRadius()){
1169 >          rsw_ = simParams_->getSwitchingRadius();
1170 >        } else {        
1171 >          sprintf(painCave.errMsg,
1172 >                  "SimCreator Warning: No value was set for switchingRadius.\n"
1173 >                  "\tOpenMD will use a default value of\n"
1174 >                  "\t0.85 * cutoffRadius for the switchingRadius\n");
1175 >          painCave.isFatal = 0;
1176 >          simError();
1177 >          rsw_ = 0.85 * rcut_;
1178 >        }
1179 >
1180 >        Electrostatic::setElectrostaticCutoffRadius(rcut_, rsw_);
1181 >        notifyFortranCutoffs(&rcut_, &rsw_, &ljsp_, &ljsf_);
1182 >
1183 >      } else {
1184 >        // We didn't set rcut explicitly, and we don't have electrostatic atoms, so
1185 >        // We'll punt and let fortran figure out the cutoffs later.
1186 >        
1187 >        notifyFortranYouAreOnYourOwn();
1188 >
1189 >      }
1190      }
1191    }
1192  
1193 < }
1193 >  void SimInfo::setupElectrostaticSummationMethod( int isError ) {    
1194 >    
1195 >    int errorOut;
1196 >    ElectrostaticSummationMethod esm = NONE;
1197 >    ElectrostaticScreeningMethod sm = UNDAMPED;
1198 >    RealType alphaVal;
1199 >    RealType dielectric;
1200 >    
1201 >    errorOut = isError;
1202 >
1203 >    if (simParams_->haveElectrostaticSummationMethod()) {
1204 >      std::string myMethod = simParams_->getElectrostaticSummationMethod();
1205 >      toUpper(myMethod);
1206 >      if (myMethod == "NONE") {
1207 >        esm = NONE;
1208 >      } else {
1209 >        if (myMethod == "SWITCHING_FUNCTION") {
1210 >          esm = SWITCHING_FUNCTION;
1211 >        } else {
1212 >          if (myMethod == "SHIFTED_POTENTIAL") {
1213 >            esm = SHIFTED_POTENTIAL;
1214 >          } else {
1215 >            if (myMethod == "SHIFTED_FORCE") {            
1216 >              esm = SHIFTED_FORCE;
1217 >            } else {
1218 >              if (myMethod == "REACTION_FIELD") {
1219 >                esm = REACTION_FIELD;
1220 >                dielectric = simParams_->getDielectric();
1221 >                if (!simParams_->haveDielectric()) {
1222 >                  // throw warning
1223 >                  sprintf( painCave.errMsg,
1224 >                           "SimInfo warning: dielectric was not specified in the input file\n\tfor the reaction field correction method.\n"
1225 >                           "\tA default value of %f will be used for the dielectric.\n", dielectric);
1226 >                  painCave.isFatal = 0;
1227 >                  simError();
1228 >                }
1229 >              } else {
1230 >                // throw error        
1231 >                sprintf( painCave.errMsg,
1232 >                         "SimInfo error: Unknown electrostaticSummationMethod.\n"
1233 >                         "\t(Input file specified %s .)\n"
1234 >                         "\telectrostaticSummationMethod must be one of: \"none\",\n"
1235 >                         "\t\"shifted_potential\", \"shifted_force\", or \n"
1236 >                         "\t\"reaction_field\".\n", myMethod.c_str() );
1237 >                painCave.isFatal = 1;
1238 >                simError();
1239 >              }    
1240 >            }          
1241 >          }
1242 >        }
1243 >      }
1244 >    }
1245 >    
1246 >    if (simParams_->haveElectrostaticScreeningMethod()) {
1247 >      std::string myScreen = simParams_->getElectrostaticScreeningMethod();
1248 >      toUpper(myScreen);
1249 >      if (myScreen == "UNDAMPED") {
1250 >        sm = UNDAMPED;
1251 >      } else {
1252 >        if (myScreen == "DAMPED") {
1253 >          sm = DAMPED;
1254 >          if (!simParams_->haveDampingAlpha()) {
1255 >            // first set a cutoff dependent alpha value
1256 >            // we assume alpha depends linearly with rcut from 0 to 20.5 ang
1257 >            alphaVal = 0.5125 - rcut_* 0.025;
1258 >            // for values rcut > 20.5, alpha is zero
1259 >            if (alphaVal < 0) alphaVal = 0;
1260 >
1261 >            // throw warning
1262 >            sprintf( painCave.errMsg,
1263 >                     "SimInfo warning: dampingAlpha was not specified in the input file.\n"
1264 >                     "\tA default value of %f (1/ang) will be used for the cutoff of\n\t%f (ang).\n", alphaVal, rcut_);
1265 >            painCave.isFatal = 0;
1266 >            simError();
1267 >          } else {
1268 >            alphaVal = simParams_->getDampingAlpha();
1269 >          }
1270 >          
1271 >        } else {
1272 >          // throw error        
1273 >          sprintf( painCave.errMsg,
1274 >                   "SimInfo error: Unknown electrostaticScreeningMethod.\n"
1275 >                   "\t(Input file specified %s .)\n"
1276 >                   "\telectrostaticScreeningMethod must be one of: \"undamped\"\n"
1277 >                   "or \"damped\".\n", myScreen.c_str() );
1278 >          painCave.isFatal = 1;
1279 >          simError();
1280 >        }
1281 >      }
1282 >    }
1283 >    
1284 >
1285 >    Electrostatic::setElectrostaticSummationMethod( esm );
1286 >    Electrostatic::setElectrostaticScreeningMethod( sm );
1287 >    Electrostatic::setDampingAlpha( alphaVal );
1288 >    Electrostatic::setReactionFieldDielectric( dielectric );
1289 >    initFortranFF( &errorOut );
1290 >  }
1291 >
1292 >  void SimInfo::setupSwitchingFunction() {    
1293 >    int ft = CUBIC;
1294 >
1295 >    if (simParams_->haveSwitchingFunctionType()) {
1296 >      std::string funcType = simParams_->getSwitchingFunctionType();
1297 >      toUpper(funcType);
1298 >      if (funcType == "CUBIC") {
1299 >        ft = CUBIC;
1300 >      } else {
1301 >        if (funcType == "FIFTH_ORDER_POLYNOMIAL") {
1302 >          ft = FIFTH_ORDER_POLY;
1303 >        } else {
1304 >          // throw error        
1305 >          sprintf( painCave.errMsg,
1306 >                   "SimInfo error: Unknown switchingFunctionType. (Input file specified %s .)\n\tswitchingFunctionType must be one of: \"cubic\" or \"fifth_order_polynomial\".", funcType.c_str() );
1307 >          painCave.isFatal = 1;
1308 >          simError();
1309 >        }          
1310 >      }
1311 >    }
1312 >
1313 >    // send switching function notification to switcheroo
1314 >    setFunctionType(&ft);
1315 >
1316 >  }
1317 >
1318 >  void SimInfo::setupAccumulateBoxDipole() {    
1319 >
1320 >    // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true
1321 >    if ( simParams_->haveAccumulateBoxDipole() )
1322 >      if ( simParams_->getAccumulateBoxDipole() ) {
1323 >        setAccumulateBoxDipole();
1324 >        calcBoxDipole_ = true;
1325 >      }
1326 >
1327 >  }
1328 >
1329 >  void SimInfo::addProperty(GenericData* genData) {
1330 >    properties_.addProperty(genData);  
1331 >  }
1332 >
1333 >  void SimInfo::removeProperty(const std::string& propName) {
1334 >    properties_.removeProperty(propName);  
1335 >  }
1336 >
1337 >  void SimInfo::clearProperties() {
1338 >    properties_.clearProperties();
1339 >  }
1340 >
1341 >  std::vector<std::string> SimInfo::getPropertyNames() {
1342 >    return properties_.getPropertyNames();  
1343 >  }
1344 >      
1345 >  std::vector<GenericData*> SimInfo::getProperties() {
1346 >    return properties_.getProperties();
1347 >  }
1348 >
1349 >  GenericData* SimInfo::getPropertyByName(const std::string& propName) {
1350 >    return properties_.getPropertyByName(propName);
1351 >  }
1352 >
1353 >  void SimInfo::setSnapshotManager(SnapshotManager* sman) {
1354 >    if (sman_ == sman) {
1355 >      return;
1356 >    }    
1357 >    delete sman_;
1358 >    sman_ = sman;
1359 >
1360 >    Molecule* mol;
1361 >    RigidBody* rb;
1362 >    Atom* atom;
1363 >    SimInfo::MoleculeIterator mi;
1364 >    Molecule::RigidBodyIterator rbIter;
1365 >    Molecule::AtomIterator atomIter;;
1366 >
1367 >    for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
1368 >        
1369 >      for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) {
1370 >        atom->setSnapshotManager(sman_);
1371 >      }
1372 >        
1373 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
1374 >        rb->setSnapshotManager(sman_);
1375 >      }
1376 >    }    
1377 >    
1378 >  }
1379 >
1380 >  Vector3d SimInfo::getComVel(){
1381 >    SimInfo::MoleculeIterator i;
1382 >    Molecule* mol;
1383 >
1384 >    Vector3d comVel(0.0);
1385 >    RealType totalMass = 0.0;
1386 >    
1387 >
1388 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1389 >      RealType mass = mol->getMass();
1390 >      totalMass += mass;
1391 >      comVel += mass * mol->getComVel();
1392 >    }  
1393 >
1394 > #ifdef IS_MPI
1395 >    RealType tmpMass = totalMass;
1396 >    Vector3d tmpComVel(comVel);    
1397 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1398 >    MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1399 > #endif
1400 >
1401 >    comVel /= totalMass;
1402 >
1403 >    return comVel;
1404 >  }
1405 >
1406 >  Vector3d SimInfo::getCom(){
1407 >    SimInfo::MoleculeIterator i;
1408 >    Molecule* mol;
1409 >
1410 >    Vector3d com(0.0);
1411 >    RealType totalMass = 0.0;
1412 >    
1413 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1414 >      RealType mass = mol->getMass();
1415 >      totalMass += mass;
1416 >      com += mass * mol->getCom();
1417 >    }  
1418 >
1419 > #ifdef IS_MPI
1420 >    RealType tmpMass = totalMass;
1421 >    Vector3d tmpCom(com);    
1422 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1423 >    MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1424 > #endif
1425 >
1426 >    com /= totalMass;
1427 >
1428 >    return com;
1429 >
1430 >  }        
1431 >
1432 >  std::ostream& operator <<(std::ostream& o, SimInfo& info) {
1433 >
1434 >    return o;
1435 >  }
1436 >  
1437 >  
1438 >   /*
1439 >   Returns center of mass and center of mass velocity in one function call.
1440 >   */
1441 >  
1442 >   void SimInfo::getComAll(Vector3d &com, Vector3d &comVel){
1443 >      SimInfo::MoleculeIterator i;
1444 >      Molecule* mol;
1445 >      
1446 >    
1447 >      RealType totalMass = 0.0;
1448 >    
1449 >
1450 >      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1451 >         RealType mass = mol->getMass();
1452 >         totalMass += mass;
1453 >         com += mass * mol->getCom();
1454 >         comVel += mass * mol->getComVel();          
1455 >      }  
1456 >      
1457 > #ifdef IS_MPI
1458 >      RealType tmpMass = totalMass;
1459 >      Vector3d tmpCom(com);  
1460 >      Vector3d tmpComVel(comVel);
1461 >      MPI_Allreduce(&tmpMass,&totalMass,1,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1462 >      MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1463 >      MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1464 > #endif
1465 >      
1466 >      com /= totalMass;
1467 >      comVel /= totalMass;
1468 >   }        
1469 >  
1470 >   /*
1471 >   Return intertia tensor for entire system and angular momentum Vector.
1472 >
1473 >
1474 >       [  Ixx -Ixy  -Ixz ]
1475 >  J =| -Iyx  Iyy  -Iyz |
1476 >       [ -Izx -Iyz   Izz ]
1477 >    */
1478 >
1479 >   void SimInfo::getInertiaTensor(Mat3x3d &inertiaTensor, Vector3d &angularMomentum){
1480 >      
1481 >
1482 >      RealType xx = 0.0;
1483 >      RealType yy = 0.0;
1484 >      RealType zz = 0.0;
1485 >      RealType xy = 0.0;
1486 >      RealType xz = 0.0;
1487 >      RealType yz = 0.0;
1488 >      Vector3d com(0.0);
1489 >      Vector3d comVel(0.0);
1490 >      
1491 >      getComAll(com, comVel);
1492 >      
1493 >      SimInfo::MoleculeIterator i;
1494 >      Molecule* mol;
1495 >      
1496 >      Vector3d thisq(0.0);
1497 >      Vector3d thisv(0.0);
1498 >
1499 >      RealType thisMass = 0.0;
1500 >    
1501 >      
1502 >      
1503 >  
1504 >      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1505 >        
1506 >         thisq = mol->getCom()-com;
1507 >         thisv = mol->getComVel()-comVel;
1508 >         thisMass = mol->getMass();
1509 >         // Compute moment of intertia coefficients.
1510 >         xx += thisq[0]*thisq[0]*thisMass;
1511 >         yy += thisq[1]*thisq[1]*thisMass;
1512 >         zz += thisq[2]*thisq[2]*thisMass;
1513 >        
1514 >         // compute products of intertia
1515 >         xy += thisq[0]*thisq[1]*thisMass;
1516 >         xz += thisq[0]*thisq[2]*thisMass;
1517 >         yz += thisq[1]*thisq[2]*thisMass;
1518 >            
1519 >         angularMomentum += cross( thisq, thisv ) * thisMass;
1520 >            
1521 >      }  
1522 >      
1523 >      
1524 >      inertiaTensor(0,0) = yy + zz;
1525 >      inertiaTensor(0,1) = -xy;
1526 >      inertiaTensor(0,2) = -xz;
1527 >      inertiaTensor(1,0) = -xy;
1528 >      inertiaTensor(1,1) = xx + zz;
1529 >      inertiaTensor(1,2) = -yz;
1530 >      inertiaTensor(2,0) = -xz;
1531 >      inertiaTensor(2,1) = -yz;
1532 >      inertiaTensor(2,2) = xx + yy;
1533 >      
1534 > #ifdef IS_MPI
1535 >      Mat3x3d tmpI(inertiaTensor);
1536 >      Vector3d tmpAngMom;
1537 >      MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1538 >      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1539 > #endif
1540 >              
1541 >      return;
1542 >   }
1543 >
1544 >   //Returns the angular momentum of the system
1545 >   Vector3d SimInfo::getAngularMomentum(){
1546 >      
1547 >      Vector3d com(0.0);
1548 >      Vector3d comVel(0.0);
1549 >      Vector3d angularMomentum(0.0);
1550 >      
1551 >      getComAll(com,comVel);
1552 >      
1553 >      SimInfo::MoleculeIterator i;
1554 >      Molecule* mol;
1555 >      
1556 >      Vector3d thisr(0.0);
1557 >      Vector3d thisp(0.0);
1558 >      
1559 >      RealType thisMass;
1560 >      
1561 >      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {        
1562 >        thisMass = mol->getMass();
1563 >        thisr = mol->getCom()-com;
1564 >        thisp = (mol->getComVel()-comVel)*thisMass;
1565 >        
1566 >        angularMomentum += cross( thisr, thisp );
1567 >        
1568 >      }  
1569 >      
1570 > #ifdef IS_MPI
1571 >      Vector3d tmpAngMom;
1572 >      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD);
1573 > #endif
1574 >      
1575 >      return angularMomentum;
1576 >   }
1577 >  
1578 >  StuntDouble* SimInfo::getIOIndexToIntegrableObject(int index) {
1579 >    return IOIndexToIntegrableObject.at(index);
1580 >  }
1581 >  
1582 >  void SimInfo::setIOIndexToIntegrableObject(const std::vector<StuntDouble*>& v) {
1583 >    IOIndexToIntegrableObject= v;
1584 >  }
1585 >
1586 >  /* Returns the Volume of the simulation based on a ellipsoid with semi-axes
1587 >     based on the radius of gyration V=4/3*Pi*R_1*R_2*R_3
1588 >     where R_i are related to the principle inertia moments R_i = sqrt(C*I_i/N), this reduces to
1589 >     V = 4/3*Pi*(C/N)^3/2*sqrt(det(I)). See S.E. Baltazar et. al. Comp. Mat. Sci. 37 (2006) 526-536.
1590 >  */
1591 >  void SimInfo::getGyrationalVolume(RealType &volume){
1592 >    Mat3x3d intTensor;
1593 >    RealType det;
1594 >    Vector3d dummyAngMom;
1595 >    RealType sysconstants;
1596 >    RealType geomCnst;
1597 >
1598 >    geomCnst = 3.0/2.0;
1599 >    /* Get the inertial tensor and angular momentum for free*/
1600 >    getInertiaTensor(intTensor,dummyAngMom);
1601 >    
1602 >    det = intTensor.determinant();
1603 >    sysconstants = geomCnst/(RealType)nGlobalIntegrableObjects_;
1604 >    volume = 4.0/3.0*NumericConstant::PI*pow(sysconstants,3.0/2.0)*sqrt(det);
1605 >    return;
1606 >  }
1607 >
1608 >  void SimInfo::getGyrationalVolume(RealType &volume, RealType &detI){
1609 >    Mat3x3d intTensor;
1610 >    Vector3d dummyAngMom;
1611 >    RealType sysconstants;
1612 >    RealType geomCnst;
1613 >
1614 >    geomCnst = 3.0/2.0;
1615 >    /* Get the inertial tensor and angular momentum for free*/
1616 >    getInertiaTensor(intTensor,dummyAngMom);
1617 >    
1618 >    detI = intTensor.determinant();
1619 >    sysconstants = geomCnst/(RealType)nGlobalIntegrableObjects_;
1620 >    volume = 4.0/3.0*NumericConstant::PI*pow(sysconstants,3.0/2.0)*sqrt(detI);
1621 >    return;
1622 >  }
1623 > /*
1624 >   void SimInfo::setStuntDoubleFromGlobalIndex(std::vector<StuntDouble*> v) {
1625 >      assert( v.size() == nAtoms_ + nRigidBodies_);
1626 >      sdByGlobalIndex_ = v;
1627 >    }
1628 >
1629 >    StuntDouble* SimInfo::getStuntDoubleFromGlobalIndex(int index) {
1630 >      //assert(index < nAtoms_ + nRigidBodies_);
1631 >      return sdByGlobalIndex_.at(index);
1632 >    }  
1633 > */  
1634 > }//end namespace OpenMD
1635 >

Comparing:
trunk/src/brains/SimInfo.cpp (property svn:keywords), Revision 124 by chuckv, Wed Oct 20 20:46:20 2004 UTC vs.
branches/development/src/brains/SimInfo.cpp (property svn:keywords), Revision 1503 by gezelter, Sat Oct 2 19:54:41 2010 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines