ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/brains/SimInfo.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/brains/SimInfo.cpp (file contents):
Revision 1490 by gezelter, Fri Sep 24 04:16:43 2004 UTC vs.
Revision 2328 by chuckv, Mon Sep 26 15:58:17 2005 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. Acknowledgement of the program authors must be made in any
10 > *    publication of scientific results based in part on use of the
11 > *    program.  An acceptable form of acknowledgement is citation of
12 > *    the article in which the program was described (Matthew
13 > *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 > *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 > *    Parallel Simulation Engine for Molecular Dynamics,"
16 > *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 > *
18 > * 2. Redistributions of source code must retain the above copyright
19 > *    notice, this list of conditions and the following disclaimer.
20 > *
21 > * 3. Redistributions in binary form must reproduce the above copyright
22 > *    notice, this list of conditions and the following disclaimer in the
23 > *    documentation and/or other materials provided with the
24 > *    distribution.
25 > *
26 > * This software is provided "AS IS," without a warranty of any
27 > * kind. All express or implied conditions, representations and
28 > * warranties, including any implied warranty of merchantability,
29 > * fitness for a particular purpose or non-infringement, are hereby
30 > * excluded.  The University of Notre Dame and its licensors shall not
31 > * be liable for any damages suffered by licensee as a result of
32 > * using, modifying or distributing the software or its
33 > * derivatives. In no event will the University of Notre Dame or its
34 > * licensors be liable for any lost revenue, profit or data, or for
35 > * direct, indirect, special, consequential, incidental or punitive
36 > * damages, however caused and regardless of the theory of liability,
37 > * arising out of the use of or inability to use software, even if the
38 > * University of Notre Dame has been advised of the possibility of
39 > * such damages.
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  
52 < #include "SimInfo.hpp"
53 < #define __C
54 < #include "fSimulation.h"
55 < #include "simError.h"
52 > #include "brains/SimInfo.hpp"
53 > #include "math/Vector3.hpp"
54 > #include "primitives/Molecule.hpp"
55 > #include "UseTheForce/fCutoffPolicy.h"
56 > #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
57 > #include "UseTheForce/doForces_interface.h"
58 > #include "UseTheForce/DarkSide/electrostatic_interface.h"
59 > #include "UseTheForce/notifyCutoffs_interface.h"
60 > #include "utils/MemoryUtils.hpp"
61 > #include "utils/simError.h"
62 > #include "selection/SelectionManager.hpp"
63  
13 #include "fortranWrappers.hpp"
14
15 #include "MatVec3.h"
16
64   #ifdef IS_MPI
65 < #include "mpiSimulation.hpp"
66 < #endif
65 > #include "UseTheForce/mpiComponentPlan.h"
66 > #include "UseTheForce/DarkSide/simParallel_interface.h"
67 > #endif
68  
69 < inline double roundMe( double x ){
22 <  return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 );
23 < }
24 <          
25 < inline double min( double a, double b ){
26 <  return (a < b ) ? a : b;
27 < }
69 > namespace oopse {
70  
71 < SimInfo* currentInfo;
71 >  SimInfo::SimInfo(MakeStamps* stamps, std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs,
72 >                   ForceField* ff, Globals* simParams) :
73 >    stamps_(stamps), forceField_(ff), simParams_(simParams),
74 >    ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0),
75 >    nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0),
76 >    nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0),
77 >    nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nRigidBodies_(0),
78 >    nIntegrableObjects_(0),  nCutoffGroups_(0), nConstraints_(0),
79 >    sman_(NULL), fortranInitialized_(false) {
80  
81 < SimInfo::SimInfo(){
81 >            
82 >      std::vector<std::pair<MoleculeStamp*, int> >::iterator i;
83 >      MoleculeStamp* molStamp;
84 >      int nMolWithSameStamp;
85 >      int nCutoffAtoms = 0; // number of atoms belong to cutoff groups
86 >      int nGroups = 0;          //total cutoff groups defined in meta-data file
87 >      CutoffGroupStamp* cgStamp;    
88 >      RigidBodyStamp* rbStamp;
89 >      int nRigidAtoms = 0;
90 >    
91 >      for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) {
92 >        molStamp = i->first;
93 >        nMolWithSameStamp = i->second;
94 >        
95 >        addMoleculeStamp(molStamp, nMolWithSameStamp);
96  
97 <  n_constraints = 0;
98 <  nZconstraints = 0;
35 <  n_oriented = 0;
36 <  n_dipoles = 0;
37 <  ndf = 0;
38 <  ndfRaw = 0;
39 <  nZconstraints = 0;
40 <  the_integrator = NULL;
41 <  setTemp = 0;
42 <  thermalTime = 0.0;
43 <  currentTime = 0.0;
44 <  rCut = 0.0;
45 <  rSw = 0.0;
97 >        //calculate atoms in molecules
98 >        nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp;  
99  
47  haveRcut = 0;
48  haveRsw = 0;
49  boxIsInit = 0;
50  
51  resetTime = 1e99;
100  
101 <  orthoRhombic = 0;
102 <  orthoTolerance = 1E-6;
103 <  useInitXSstate = true;
101 >        //calculate atoms in cutoff groups
102 >        int nAtomsInGroups = 0;
103 >        int nCutoffGroupsInStamp = molStamp->getNCutoffGroups();
104 >        
105 >        for (int j=0; j < nCutoffGroupsInStamp; j++) {
106 >          cgStamp = molStamp->getCutoffGroup(j);
107 >          nAtomsInGroups += cgStamp->getNMembers();
108 >        }
109  
110 <  usePBC = 0;
111 <  useLJ = 0;
59 <  useSticky = 0;
60 <  useCharges = 0;
61 <  useDipoles = 0;
62 <  useReactionField = 0;
63 <  useGB = 0;
64 <  useEAM = 0;
65 <  useSolidThermInt = 0;
66 <  useLiquidThermInt = 0;
110 >        nGroups += nCutoffGroupsInStamp * nMolWithSameStamp;
111 >        nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp;            
112  
113 <  haveCutoffGroups = false;
113 >        //calculate atoms in rigid bodies
114 >        int nAtomsInRigidBodies = 0;
115 >        int nRigidBodiesInStamp = molStamp->getNRigidBodies();
116 >        
117 >        for (int j=0; j < nRigidBodiesInStamp; j++) {
118 >          rbStamp = molStamp->getRigidBody(j);
119 >          nAtomsInRigidBodies += rbStamp->getNMembers();
120 >        }
121  
122 <  excludes = Exclude::Instance();
122 >        nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp;
123 >        nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp;            
124 >        
125 >      }
126  
127 <  myConfiguration = new SimState();
127 >      //every free atom (atom does not belong to cutoff groups) is a cutoff group
128 >      //therefore the total number of cutoff groups in the system is equal to
129 >      //the total number of atoms minus number of atoms belong to cutoff group defined in meta-data
130 >      //file plus the number of cutoff groups defined in meta-data file
131 >      nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups;
132  
133 <  has_minimizer = false;
134 <  the_minimizer =NULL;
133 >      //every free atom (atom does not belong to rigid bodies) is an integrable object
134 >      //therefore the total number of  integrable objects in the system is equal to
135 >      //the total number of atoms minus number of atoms belong to  rigid body defined in meta-data
136 >      //file plus the number of  rigid bodies defined in meta-data file
137 >      nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + nGlobalRigidBodies_;
138  
139 <  ngroup = 0;
139 >      nGlobalMols_ = molStampIds_.size();
140  
141 <  wrapMeSimInfo( this );
142 < }
141 > #ifdef IS_MPI    
142 >      molToProcMap_.resize(nGlobalMols_);
143 > #endif
144  
145 +    }
146  
147 < SimInfo::~SimInfo(){
147 >  SimInfo::~SimInfo() {
148 >    std::map<int, Molecule*>::iterator i;
149 >    for (i = molecules_.begin(); i != molecules_.end(); ++i) {
150 >      delete i->second;
151 >    }
152 >    molecules_.clear();
153 >      
154 >    delete stamps_;
155 >    delete sman_;
156 >    delete simParams_;
157 >    delete forceField_;
158 >  }
159  
160 <  delete myConfiguration;
160 >  int SimInfo::getNGlobalConstraints() {
161 >    int nGlobalConstraints;
162 > #ifdef IS_MPI
163 >    MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM,
164 >                  MPI_COMM_WORLD);    
165 > #else
166 >    nGlobalConstraints =  nConstraints_;
167 > #endif
168 >    return nGlobalConstraints;
169 >  }
170  
171 <  map<string, GenericData*>::iterator i;
172 <  
89 <  for(i = properties.begin(); i != properties.end(); i++)
90 <    delete (*i).second;
171 >  bool SimInfo::addMolecule(Molecule* mol) {
172 >    MoleculeIterator i;
173  
174 < }
174 >    i = molecules_.find(mol->getGlobalIndex());
175 >    if (i == molecules_.end() ) {
176  
177 < void SimInfo::setBox(double newBox[3]) {
178 <  
179 <  int i, j;
180 <  double tempMat[3][3];
181 <
182 <  for(i=0; i<3; i++)
183 <    for (j=0; j<3; j++) tempMat[i][j] = 0.0;;
184 <
185 <  tempMat[0][0] = newBox[0];
186 <  tempMat[1][1] = newBox[1];
104 <  tempMat[2][2] = newBox[2];
105 <
106 <  setBoxM( tempMat );
177 >      molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol));
178 >        
179 >      nAtoms_ += mol->getNAtoms();
180 >      nBonds_ += mol->getNBonds();
181 >      nBends_ += mol->getNBends();
182 >      nTorsions_ += mol->getNTorsions();
183 >      nRigidBodies_ += mol->getNRigidBodies();
184 >      nIntegrableObjects_ += mol->getNIntegrableObjects();
185 >      nCutoffGroups_ += mol->getNCutoffGroups();
186 >      nConstraints_ += mol->getNConstraintPairs();
187  
188 < }
189 <
190 < void SimInfo::setBoxM( double theBox[3][3] ){
191 <  
192 <  int i, j;
113 <  double FortranHmat[9]; // to preserve compatibility with Fortran the
114 <                         // ordering in the array is as follows:
115 <                         // [ 0 3 6 ]
116 <                         // [ 1 4 7 ]
117 <                         // [ 2 5 8 ]
118 <  double FortranHmatInv[9]; // the inverted Hmat (for Fortran);
119 <
120 <  if( !boxIsInit ) boxIsInit = 1;
121 <
122 <  for(i=0; i < 3; i++)
123 <    for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j];
124 <  
125 <  calcBoxL();
126 <  calcHmatInv();
127 <
128 <  for(i=0; i < 3; i++) {
129 <    for (j=0; j < 3; j++) {
130 <      FortranHmat[3*j + i] = Hmat[i][j];
131 <      FortranHmatInv[3*j + i] = HmatInv[i][j];
188 >      addExcludePairs(mol);
189 >        
190 >      return true;
191 >    } else {
192 >      return false;
193      }
194    }
195  
196 <  setFortranBoxSize(FortranHmat, FortranHmatInv, &orthoRhombic);
197 <
198 < }
138 <
196 >  bool SimInfo::removeMolecule(Molecule* mol) {
197 >    MoleculeIterator i;
198 >    i = molecules_.find(mol->getGlobalIndex());
199  
200 < void SimInfo::getBoxM (double theBox[3][3]) {
200 >    if (i != molecules_.end() ) {
201  
202 <  int i, j;
203 <  for(i=0; i<3; i++)
204 <    for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j];
205 < }
202 >      assert(mol == i->second);
203 >        
204 >      nAtoms_ -= mol->getNAtoms();
205 >      nBonds_ -= mol->getNBonds();
206 >      nBends_ -= mol->getNBends();
207 >      nTorsions_ -= mol->getNTorsions();
208 >      nRigidBodies_ -= mol->getNRigidBodies();
209 >      nIntegrableObjects_ -= mol->getNIntegrableObjects();
210 >      nCutoffGroups_ -= mol->getNCutoffGroups();
211 >      nConstraints_ -= mol->getNConstraintPairs();
212  
213 +      removeExcludePairs(mol);
214 +      molecules_.erase(mol->getGlobalIndex());
215  
216 < void SimInfo::scaleBox(double scale) {
217 <  double theBox[3][3];
218 <  int i, j;
216 >      delete mol;
217 >        
218 >      return true;
219 >    } else {
220 >      return false;
221 >    }
222  
152  // cerr << "Scaling box by " << scale << "\n";
223  
224 <  for(i=0; i<3; i++)
155 <    for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]*scale;
224 >  }    
225  
226 <  setBoxM(theBox);
226 >        
227 >  Molecule* SimInfo::beginMolecule(MoleculeIterator& i) {
228 >    i = molecules_.begin();
229 >    return i == molecules_.end() ? NULL : i->second;
230 >  }    
231  
232 < }
232 >  Molecule* SimInfo::nextMolecule(MoleculeIterator& i) {
233 >    ++i;
234 >    return i == molecules_.end() ? NULL : i->second;    
235 >  }
236  
161 void SimInfo::calcHmatInv( void ) {
162  
163  int oldOrtho;
164  int i,j;
165  double smallDiag;
166  double tol;
167  double sanity[3][3];
237  
238 <  invertMat3( Hmat, HmatInv );
238 >  void SimInfo::calcNdf() {
239 >    int ndf_local;
240 >    MoleculeIterator i;
241 >    std::vector<StuntDouble*>::iterator j;
242 >    Molecule* mol;
243 >    StuntDouble* integrableObject;
244  
245 <  // check to see if Hmat is orthorhombic
246 <  
247 <  oldOrtho = orthoRhombic;
245 >    ndf_local = 0;
246 >    
247 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
248 >      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
249 >           integrableObject = mol->nextIntegrableObject(j)) {
250  
251 <  smallDiag = fabs(Hmat[0][0]);
176 <  if(smallDiag > fabs(Hmat[1][1])) smallDiag = fabs(Hmat[1][1]);
177 <  if(smallDiag > fabs(Hmat[2][2])) smallDiag = fabs(Hmat[2][2]);
178 <  tol = smallDiag * orthoTolerance;
251 >        ndf_local += 3;
252  
253 <  orthoRhombic = 1;
254 <  
255 <  for (i = 0; i < 3; i++ ) {
256 <    for (j = 0 ; j < 3; j++) {
257 <      if (i != j) {
258 <        if (orthoRhombic) {
259 <          if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0;
260 <        }        
261 <      }
262 <    }
190 <  }
191 <
192 <  if( oldOrtho != orthoRhombic ){
253 >        if (integrableObject->isDirectional()) {
254 >          if (integrableObject->isLinear()) {
255 >            ndf_local += 2;
256 >          } else {
257 >            ndf_local += 3;
258 >          }
259 >        }
260 >            
261 >      }//end for (integrableObject)
262 >    }// end for (mol)
263      
264 <    if( orthoRhombic ) {
265 <      sprintf( painCave.errMsg,
196 <               "OOPSE is switching from the default Non-Orthorhombic\n"
197 <               "\tto the faster Orthorhombic periodic boundary computations.\n"
198 <               "\tThis is usually a good thing, but if you wan't the\n"
199 <               "\tNon-Orthorhombic computations, make the orthoBoxTolerance\n"
200 <               "\tvariable ( currently set to %G ) smaller.\n",
201 <               orthoTolerance);
202 <      painCave.severity = OOPSE_INFO;
203 <      simError();
204 <    }
205 <    else {
206 <      sprintf( painCave.errMsg,
207 <               "OOPSE is switching from the faster Orthorhombic to the more\n"
208 <               "\tflexible Non-Orthorhombic periodic boundary computations.\n"
209 <               "\tThis is usually because the box has deformed under\n"
210 <               "\tNPTf integration. If you wan't to live on the edge with\n"
211 <               "\tthe Orthorhombic computations, make the orthoBoxTolerance\n"
212 <               "\tvariable ( currently set to %G ) larger.\n",
213 <               orthoTolerance);
214 <      painCave.severity = OOPSE_WARNING;
215 <      simError();
216 <    }
217 <  }
218 < }
264 >    // n_constraints is local, so subtract them on each processor
265 >    ndf_local -= nConstraints_;
266  
267 < void SimInfo::calcBoxL( void ){
267 > #ifdef IS_MPI
268 >    MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
269 > #else
270 >    ndf_ = ndf_local;
271 > #endif
272  
273 <  double dx, dy, dz, dsq;
273 >    // nZconstraints_ is global, as are the 3 COM translations for the
274 >    // entire system:
275 >    ndf_ = ndf_ - 3 - nZconstraint_;
276  
277 <  // boxVol = Determinant of Hmat
277 >  }
278  
279 <  boxVol = matDet3( Hmat );
279 >  void SimInfo::calcNdfRaw() {
280 >    int ndfRaw_local;
281  
282 <  // boxLx
283 <  
284 <  dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0];
285 <  dsq = dx*dx + dy*dy + dz*dz;
232 <  boxL[0] = sqrt( dsq );
233 <  //maxCutoff = 0.5 * boxL[0];
282 >    MoleculeIterator i;
283 >    std::vector<StuntDouble*>::iterator j;
284 >    Molecule* mol;
285 >    StuntDouble* integrableObject;
286  
287 <  // boxLy
288 <  
289 <  dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1];
290 <  dsq = dx*dx + dy*dy + dz*dz;
291 <  boxL[1] = sqrt( dsq );
292 <  //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1];
287 >    // Raw degrees of freedom that we have to set
288 >    ndfRaw_local = 0;
289 >    
290 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
291 >      for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
292 >           integrableObject = mol->nextIntegrableObject(j)) {
293  
294 +        ndfRaw_local += 3;
295  
296 <  // boxLz
297 <  
298 <  dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2];
299 <  dsq = dx*dx + dy*dy + dz*dz;
300 <  boxL[2] = sqrt( dsq );
301 <  //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2];
296 >        if (integrableObject->isDirectional()) {
297 >          if (integrableObject->isLinear()) {
298 >            ndfRaw_local += 2;
299 >          } else {
300 >            ndfRaw_local += 3;
301 >          }
302 >        }
303 >            
304 >      }
305 >    }
306 >    
307 > #ifdef IS_MPI
308 >    MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
309 > #else
310 >    ndfRaw_ = ndfRaw_local;
311 > #endif
312 >  }
313  
314 <  //calculate the max cutoff
315 <  maxCutoff =  calcMaxCutOff();
252 <  
253 <  checkCutOffs();
314 >  void SimInfo::calcNdfTrans() {
315 >    int ndfTrans_local;
316  
317 < }
317 >    ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
318  
319  
320 < double SimInfo::calcMaxCutOff(){
320 > #ifdef IS_MPI
321 >    MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
322 > #else
323 >    ndfTrans_ = ndfTrans_local;
324 > #endif
325  
326 <  double ri[3], rj[3], rk[3];
327 <  double rij[3], rjk[3], rki[3];
328 <  double minDist;
326 >    ndfTrans_ = ndfTrans_ - 3 - nZconstraint_;
327 >
328 >  }
329  
330 <  ri[0] = Hmat[0][0];
331 <  ri[1] = Hmat[1][0];
332 <  ri[2] = Hmat[2][0];
333 <
334 <  rj[0] = Hmat[0][1];
335 <  rj[1] = Hmat[1][1];
336 <  rj[2] = Hmat[2][1];
337 <
338 <  rk[0] = Hmat[0][2];
339 <  rk[1] = Hmat[1][2];
340 <  rk[2] = Hmat[2][2];
330 >  void SimInfo::addExcludePairs(Molecule* mol) {
331 >    std::vector<Bond*>::iterator bondIter;
332 >    std::vector<Bend*>::iterator bendIter;
333 >    std::vector<Torsion*>::iterator torsionIter;
334 >    Bond* bond;
335 >    Bend* bend;
336 >    Torsion* torsion;
337 >    int a;
338 >    int b;
339 >    int c;
340 >    int d;
341      
342 <  crossProduct3(ri, rj, rij);
343 <  distXY = dotProduct3(rk,rij) / norm3(rij);
342 >    for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
343 >      a = bond->getAtomA()->getGlobalIndex();
344 >      b = bond->getAtomB()->getGlobalIndex();        
345 >      exclude_.addPair(a, b);
346 >    }
347  
348 <  crossProduct3(rj,rk, rjk);
349 <  distYZ = dotProduct3(ri,rjk) / norm3(rjk);
348 >    for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
349 >      a = bend->getAtomA()->getGlobalIndex();
350 >      b = bend->getAtomB()->getGlobalIndex();        
351 >      c = bend->getAtomC()->getGlobalIndex();
352  
353 <  crossProduct3(rk,ri, rki);
354 <  distZX = dotProduct3(rj,rki) / norm3(rki);
353 >      exclude_.addPair(a, b);
354 >      exclude_.addPair(a, c);
355 >      exclude_.addPair(b, c);        
356 >    }
357  
358 <  minDist = min(min(distXY, distYZ), distZX);
359 <  return minDist/2;
360 <  
361 < }
358 >    for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
359 >      a = torsion->getAtomA()->getGlobalIndex();
360 >      b = torsion->getAtomB()->getGlobalIndex();        
361 >      c = torsion->getAtomC()->getGlobalIndex();        
362 >      d = torsion->getAtomD()->getGlobalIndex();        
363  
364 < void SimInfo::wrapVector( double thePos[3] ){
364 >      exclude_.addPair(a, b);
365 >      exclude_.addPair(a, c);
366 >      exclude_.addPair(a, d);
367 >      exclude_.addPair(b, c);
368 >      exclude_.addPair(b, d);
369 >      exclude_.addPair(c, d);        
370 >    }
371  
372 <  int i;
373 <  double scaled[3];
372 >    Molecule::RigidBodyIterator rbIter;
373 >    RigidBody* rb;
374 >    for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
375 >      std::vector<Atom*> atoms = rb->getAtoms();
376 >      for (int i = 0; i < atoms.size() -1 ; ++i) {
377 >        for (int j = i + 1; j < atoms.size(); ++j) {
378 >          a = atoms[i]->getGlobalIndex();
379 >          b = atoms[j]->getGlobalIndex();
380 >          exclude_.addPair(a, b);
381 >        }
382 >      }
383 >    }        
384  
385 <  if( !orthoRhombic ){
296 <    // calc the scaled coordinates.
297 <  
385 >  }
386  
387 <    matVecMul3(HmatInv, thePos, scaled);
387 >  void SimInfo::removeExcludePairs(Molecule* mol) {
388 >    std::vector<Bond*>::iterator bondIter;
389 >    std::vector<Bend*>::iterator bendIter;
390 >    std::vector<Torsion*>::iterator torsionIter;
391 >    Bond* bond;
392 >    Bend* bend;
393 >    Torsion* torsion;
394 >    int a;
395 >    int b;
396 >    int c;
397 >    int d;
398      
399 <    for(i=0; i<3; i++)
400 <      scaled[i] -= roundMe(scaled[i]);
401 <    
402 <    // calc the wrapped real coordinates from the wrapped scaled coordinates
403 <    
306 <    matVecMul3(Hmat, scaled, thePos);
399 >    for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
400 >      a = bond->getAtomA()->getGlobalIndex();
401 >      b = bond->getAtomB()->getGlobalIndex();        
402 >      exclude_.removePair(a, b);
403 >    }
404  
405 <  }
406 <  else{
407 <    // calc the scaled coordinates.
408 <    
312 <    for(i=0; i<3; i++)
313 <      scaled[i] = thePos[i]*HmatInv[i][i];
314 <    
315 <    // wrap the scaled coordinates
316 <    
317 <    for(i=0; i<3; i++)
318 <      scaled[i] -= roundMe(scaled[i]);
319 <    
320 <    // calc the wrapped real coordinates from the wrapped scaled coordinates
321 <    
322 <    for(i=0; i<3; i++)
323 <      thePos[i] = scaled[i]*Hmat[i][i];
324 <  }
325 <    
326 < }
405 >    for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
406 >      a = bend->getAtomA()->getGlobalIndex();
407 >      b = bend->getAtomB()->getGlobalIndex();        
408 >      c = bend->getAtomC()->getGlobalIndex();
409  
410 +      exclude_.removePair(a, b);
411 +      exclude_.removePair(a, c);
412 +      exclude_.removePair(b, c);        
413 +    }
414  
415 < int SimInfo::getNDF(){
416 <  int ndf_local;
415 >    for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
416 >      a = torsion->getAtomA()->getGlobalIndex();
417 >      b = torsion->getAtomB()->getGlobalIndex();        
418 >      c = torsion->getAtomC()->getGlobalIndex();        
419 >      d = torsion->getAtomD()->getGlobalIndex();        
420  
421 <  ndf_local = 0;
422 <  
423 <  for(int i = 0; i < integrableObjects.size(); i++){
424 <    ndf_local += 3;
425 <    if (integrableObjects[i]->isDirectional()) {
426 <      if (integrableObjects[i]->isLinear())
338 <        ndf_local += 2;
339 <      else
340 <        ndf_local += 3;
421 >      exclude_.removePair(a, b);
422 >      exclude_.removePair(a, c);
423 >      exclude_.removePair(a, d);
424 >      exclude_.removePair(b, c);
425 >      exclude_.removePair(b, d);
426 >      exclude_.removePair(c, d);        
427      }
428 +
429 +    Molecule::RigidBodyIterator rbIter;
430 +    RigidBody* rb;
431 +    for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
432 +      std::vector<Atom*> atoms = rb->getAtoms();
433 +      for (int i = 0; i < atoms.size() -1 ; ++i) {
434 +        for (int j = i + 1; j < atoms.size(); ++j) {
435 +          a = atoms[i]->getGlobalIndex();
436 +          b = atoms[j]->getGlobalIndex();
437 +          exclude_.removePair(a, b);
438 +        }
439 +      }
440 +    }        
441 +
442    }
443  
344  // n_constraints is local, so subtract them on each processor:
444  
445 <  ndf_local -= n_constraints;
445 >  void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) {
446 >    int curStampId;
447  
448 < #ifdef IS_MPI
449 <  MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
350 < #else
351 <  ndf = ndf_local;
352 < #endif
448 >    //index from 0
449 >    curStampId = moleculeStamps_.size();
450  
451 <  // nZconstraints is global, as are the 3 COM translations for the
452 <  // entire system:
451 >    moleculeStamps_.push_back(molStamp);
452 >    molStampIds_.insert(molStampIds_.end(), nmol, curStampId);
453 >  }
454  
455 <  ndf = ndf - 3 - nZconstraints;
455 >  void SimInfo::update() {
456  
457 <  return ndf;
360 < }
457 >    setupSimType();
458  
459 < int SimInfo::getNDFraw() {
460 <  int ndfRaw_local;
459 > #ifdef IS_MPI
460 >    setupFortranParallel();
461 > #endif
462  
463 <  // Raw degrees of freedom that we have to set
366 <  ndfRaw_local = 0;
463 >    setupFortranSim();
464  
465 <  for(int i = 0; i < integrableObjects.size(); i++){
466 <    ndfRaw_local += 3;
467 <    if (integrableObjects[i]->isDirectional()) {
468 <       if (integrableObjects[i]->isLinear())
469 <        ndfRaw_local += 2;
470 <      else
471 <        ndfRaw_local += 3;
465 >    //setup fortran force field
466 >    /** @deprecate */    
467 >    int isError = 0;
468 >    
469 >    setupElectrostaticSummationMethod( isError );
470 >
471 >    if(isError){
472 >      sprintf( painCave.errMsg,
473 >               "ForceField error: There was an error initializing the forceField in fortran.\n" );
474 >      painCave.isFatal = 1;
475 >      simError();
476      }
477 <  }
477 >  
478      
479 < #ifdef IS_MPI
379 <  MPI_Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
380 < #else
381 <  ndfRaw = ndfRaw_local;
382 < #endif
479 >    setupCutoff();
480  
481 <  return ndfRaw;
482 < }
481 >    calcNdf();
482 >    calcNdfRaw();
483 >    calcNdfTrans();
484  
485 < int SimInfo::getNDFtranslational() {
486 <  int ndfTrans_local;
485 >    fortranInitialized_ = true;
486 >  }
487  
488 <  ndfTrans_local = 3 * integrableObjects.size() - n_constraints;
488 >  std::set<AtomType*> SimInfo::getUniqueAtomTypes() {
489 >    SimInfo::MoleculeIterator mi;
490 >    Molecule* mol;
491 >    Molecule::AtomIterator ai;
492 >    Atom* atom;
493 >    std::set<AtomType*> atomTypes;
494  
495 +    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
496  
497 < #ifdef IS_MPI
498 <  MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
499 < #else
500 <  ndfTrans = ndfTrans_local;
501 < #endif
497 >      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
498 >        atomTypes.insert(atom->getAtomType());
499 >      }
500 >        
501 >    }
502  
503 <  ndfTrans = ndfTrans - 3 - nZconstraints;
503 >    return atomTypes;        
504 >  }
505  
506 <  return ndfTrans;
507 < }
506 >  void SimInfo::setupSimType() {
507 >    std::set<AtomType*>::iterator i;
508 >    std::set<AtomType*> atomTypes;
509 >    atomTypes = getUniqueAtomTypes();
510 >    
511 >    int useLennardJones = 0;
512 >    int useElectrostatic = 0;
513 >    int useEAM = 0;
514 >    int useCharge = 0;
515 >    int useDirectional = 0;
516 >    int useDipole = 0;
517 >    int useGayBerne = 0;
518 >    int useSticky = 0;
519 >    int useStickyPower = 0;
520 >    int useShape = 0;
521 >    int useFLARB = 0; //it is not in AtomType yet
522 >    int useDirectionalAtom = 0;    
523 >    int useElectrostatics = 0;
524 >    //usePBC and useRF are from simParams
525 >    int usePBC = simParams_->getPBC();
526 >    int useRF;
527  
528 < int SimInfo::getTotIntegrableObjects() {
529 <  int nObjs_local;
530 <  int nObjs;
528 >    // set the useRF logical
529 >    std::string myMethod = simParams_->getElectrostaticSummationMethod();
530 >    if (myMethod == "REACTION_FIELD")
531 >      useRF = 1;
532 >    else
533 >      useRF = 0;
534  
535 <  nObjs_local =  integrableObjects.size();
535 >    //loop over all of the atom types
536 >    for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
537 >      useLennardJones |= (*i)->isLennardJones();
538 >      useElectrostatic |= (*i)->isElectrostatic();
539 >      useEAM |= (*i)->isEAM();
540 >      useCharge |= (*i)->isCharge();
541 >      useDirectional |= (*i)->isDirectional();
542 >      useDipole |= (*i)->isDipole();
543 >      useGayBerne |= (*i)->isGayBerne();
544 >      useSticky |= (*i)->isSticky();
545 >      useStickyPower |= (*i)->isStickyPower();
546 >      useShape |= (*i)->isShape();
547 >    }
548  
549 +    if (useSticky || useStickyPower || useDipole || useGayBerne || useShape) {
550 +      useDirectionalAtom = 1;
551 +    }
552  
553 < #ifdef IS_MPI
554 <  MPI_Allreduce(&nObjs_local,&nObjs,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
555 < #else
414 <  nObjs = nObjs_local;
415 < #endif
553 >    if (useCharge || useDipole) {
554 >      useElectrostatics = 1;
555 >    }
556  
557 + #ifdef IS_MPI    
558 +    int temp;
559  
560 <  return nObjs;
561 < }
560 >    temp = usePBC;
561 >    MPI_Allreduce(&temp, &usePBC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
562  
563 < void SimInfo::refreshSim(){
563 >    temp = useDirectionalAtom;
564 >    MPI_Allreduce(&temp, &useDirectionalAtom, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
565  
566 <  simtype fInfo;
567 <  int isError;
425 <  int n_global;
426 <  int* excl;
566 >    temp = useLennardJones;
567 >    MPI_Allreduce(&temp, &useLennardJones, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
568  
569 <  fInfo.dielect = 0.0;
569 >    temp = useElectrostatics;
570 >    MPI_Allreduce(&temp, &useElectrostatics, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
571 >
572 >    temp = useCharge;
573 >    MPI_Allreduce(&temp, &useCharge, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
574 >
575 >    temp = useDipole;
576 >    MPI_Allreduce(&temp, &useDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
577  
578 <  if( useDipoles ){
579 <    if( useReactionField )fInfo.dielect = dielectric;
432 <  }
578 >    temp = useSticky;
579 >    MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
580  
581 <  fInfo.SIM_uses_PBC = usePBC;
582 <  //fInfo.SIM_uses_LJ = 0;
583 <  fInfo.SIM_uses_LJ = useLJ;
584 <  fInfo.SIM_uses_sticky = useSticky;
585 <  //fInfo.SIM_uses_sticky = 0;
439 <  fInfo.SIM_uses_charges = useCharges;
440 <  fInfo.SIM_uses_dipoles = useDipoles;
441 <  //fInfo.SIM_uses_dipoles = 0;
442 <  fInfo.SIM_uses_RF = useReactionField;
443 <  //fInfo.SIM_uses_RF = 0;
444 <  fInfo.SIM_uses_GB = useGB;
445 <  fInfo.SIM_uses_EAM = useEAM;
581 >    temp = useStickyPower;
582 >    MPI_Allreduce(&temp, &useStickyPower, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
583 >    
584 >    temp = useGayBerne;
585 >    MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
586  
587 <  n_exclude = excludes->getSize();
588 <  excl = excludes->getFortranArray();
589 <  
590 < #ifdef IS_MPI
591 <  n_global = mpiSim->getNAtomsGlobal();
592 < #else
593 <  n_global = n_atoms;
587 >    temp = useEAM;
588 >    MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
589 >
590 >    temp = useShape;
591 >    MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);  
592 >
593 >    temp = useFLARB;
594 >    MPI_Allreduce(&temp, &useFLARB, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
595 >
596 >    temp = useRF;
597 >    MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
598 >
599   #endif
455  
456  isError = 0;
457  
458  getFortranGroupArrays(this, FglobalGroupMembership, mfact);
459  //it may not be a good idea to pass the address of first element in vector
460  //since c++ standard does not require vector to be stored continuously in meomory
461  //Most of the compilers will organize the memory of vector continuously
462  setFsimulation( &fInfo, &n_global, &n_atoms, identArray, &n_exclude, excl,
463                  &nGlobalExcludes, globalExcludes, molMembershipArray,
464                  &mfact[0], &ngroup, &FglobalGroupMembership[0], &isError);
600  
601 <  if( isError ){
602 <    
603 <    sprintf( painCave.errMsg,
604 <             "There was an error setting the simulation information in fortran.\n" );
605 <    painCave.isFatal = 1;
606 <    painCave.severity = OOPSE_ERROR;
607 <    simError();
601 >    fInfo_.SIM_uses_PBC = usePBC;    
602 >    fInfo_.SIM_uses_DirectionalAtoms = useDirectionalAtom;
603 >    fInfo_.SIM_uses_LennardJones = useLennardJones;
604 >    fInfo_.SIM_uses_Electrostatics = useElectrostatics;    
605 >    fInfo_.SIM_uses_Charges = useCharge;
606 >    fInfo_.SIM_uses_Dipoles = useDipole;
607 >    fInfo_.SIM_uses_Sticky = useSticky;
608 >    fInfo_.SIM_uses_StickyPower = useStickyPower;
609 >    fInfo_.SIM_uses_GayBerne = useGayBerne;
610 >    fInfo_.SIM_uses_EAM = useEAM;
611 >    fInfo_.SIM_uses_Shapes = useShape;
612 >    fInfo_.SIM_uses_FLARB = useFLARB;
613 >    fInfo_.SIM_uses_RF = useRF;
614 >
615 >    if( fInfo_.SIM_uses_Dipoles && myMethod == "REACTION_FIELD") {
616 >
617 >      if (simParams_->haveDielectric()) {
618 >        fInfo_.dielect = simParams_->getDielectric();
619 >      } else {
620 >        sprintf(painCave.errMsg,
621 >                "SimSetup Error: No Dielectric constant was set.\n"
622 >                "\tYou are trying to use Reaction Field without"
623 >                "\tsetting a dielectric constant!\n");
624 >        painCave.isFatal = 1;
625 >        simError();
626 >      }
627 >        
628 >    } else {
629 >      fInfo_.dielect = 0.0;
630 >    }
631 >
632    }
474  
475 #ifdef IS_MPI
476  sprintf( checkPointMsg,
477           "succesfully sent the simulation information to fortran.\n");
478  MPIcheckPoint();
479 #endif // is_mpi
480  
481  this->ndf = this->getNDF();
482  this->ndfRaw = this->getNDFraw();
483  this->ndfTrans = this->getNDFtranslational();
484 }
633  
634 < void SimInfo::setDefaultRcut( double theRcut ){
635 <  
636 <  haveRcut = 1;
637 <  rCut = theRcut;
638 <  rList = rCut + 1.0;
639 <  
640 <  notifyFortranCutOffs( &rCut, &rSw, &rList );
493 < }
634 >  void SimInfo::setupFortranSim() {
635 >    int isError;
636 >    int nExclude;
637 >    std::vector<int> fortranGlobalGroupMembership;
638 >    
639 >    nExclude = exclude_.getSize();
640 >    isError = 0;
641  
642 < void SimInfo::setDefaultRcut( double theRcut, double theRsw ){
642 >    //globalGroupMembership_ is filled by SimCreator    
643 >    for (int i = 0; i < nGlobalAtoms_; i++) {
644 >      fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1);
645 >    }
646  
647 <  rSw = theRsw;
648 <  setDefaultRcut( theRcut );
649 < }
647 >    //calculate mass ratio of cutoff group
648 >    std::vector<double> mfact;
649 >    SimInfo::MoleculeIterator mi;
650 >    Molecule* mol;
651 >    Molecule::CutoffGroupIterator ci;
652 >    CutoffGroup* cg;
653 >    Molecule::AtomIterator ai;
654 >    Atom* atom;
655 >    double totalMass;
656  
657 +    //to avoid memory reallocation, reserve enough space for mfact
658 +    mfact.reserve(getNCutoffGroups());
659 +    
660 +    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
661 +      for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
662  
663 < void SimInfo::checkCutOffs( void ){
664 <  
665 <  if( boxIsInit ){
663 >        totalMass = cg->getMass();
664 >        for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
665 >          mfact.push_back(atom->getMass()/totalMass);
666 >        }
667 >
668 >      }      
669 >    }
670 >
671 >    //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!)
672 >    std::vector<int> identArray;
673 >
674 >    //to avoid memory reallocation, reserve enough space identArray
675 >    identArray.reserve(getNAtoms());
676      
677 <    //we need to check cutOffs against the box
677 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
678 >      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
679 >        identArray.push_back(atom->getIdent());
680 >      }
681 >    }    
682 >
683 >    //fill molMembershipArray
684 >    //molMembershipArray is filled by SimCreator    
685 >    std::vector<int> molMembershipArray(nGlobalAtoms_);
686 >    for (int i = 0; i < nGlobalAtoms_; i++) {
687 >      molMembershipArray[i] = globalMolMembership_[i] + 1;
688 >    }
689      
690 <    if( rCut > maxCutoff ){
690 >    //setup fortran simulation
691 >    int nGlobalExcludes = 0;
692 >    int* globalExcludes = NULL;
693 >    int* excludeList = exclude_.getExcludeList();
694 >    setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], &nExclude, excludeList ,
695 >                   &nGlobalExcludes, globalExcludes, &molMembershipArray[0],
696 >                   &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError);
697 >
698 >    if( isError ){
699 >
700        sprintf( painCave.errMsg,
701 <               "cutoffRadius is too large for the current periodic box.\n"
511 <               "\tCurrent Value of cutoffRadius = %G at time %G\n "
512 <               "\tThis is larger than half of at least one of the\n"
513 <               "\tperiodic box vectors.  Right now, the Box matrix is:\n"
514 <               "\n"
515 <               "\t[ %G %G %G ]\n"
516 <               "\t[ %G %G %G ]\n"
517 <               "\t[ %G %G %G ]\n",
518 <               rCut, currentTime,
519 <               Hmat[0][0], Hmat[0][1], Hmat[0][2],
520 <               Hmat[1][0], Hmat[1][1], Hmat[1][2],
521 <               Hmat[2][0], Hmat[2][1], Hmat[2][2]);
522 <      painCave.severity = OOPSE_ERROR;
701 >               "There was an error setting the simulation information in fortran.\n" );
702        painCave.isFatal = 1;
703 +      painCave.severity = OOPSE_ERROR;
704        simError();
705 <    }    
706 <  } else {
707 <    // initialize this stuff before using it, OK?
708 <    sprintf( painCave.errMsg,
709 <             "Trying to check cutoffs without a box.\n"
710 <             "\tOOPSE should have better programmers than that.\n" );
711 <    painCave.severity = OOPSE_ERROR;
532 <    painCave.isFatal = 1;
533 <    simError();      
705 >    }
706 >
707 > #ifdef IS_MPI
708 >    sprintf( checkPointMsg,
709 >             "succesfully sent the simulation information to fortran.\n");
710 >    MPIcheckPoint();
711 > #endif // is_mpi
712    }
535  
536 }
713  
538 void SimInfo::addProperty(GenericData* prop){
714  
715 <  map<string, GenericData*>::iterator result;
716 <  result = properties.find(prop->getID());
542 <  
543 <  //we can't simply use  properties[prop->getID()] = prop,
544 <  //it will cause memory leak if we already contain a propery which has the same name of prop
545 <  
546 <  if(result != properties.end()){
715 > #ifdef IS_MPI
716 >  void SimInfo::setupFortranParallel() {
717      
718 <    delete (*result).second;
719 <    (*result).second = prop;
720 <      
721 <  }
722 <  else{
718 >    //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex
719 >    std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0);
720 >    std::vector<int> localToGlobalCutoffGroupIndex;
721 >    SimInfo::MoleculeIterator mi;
722 >    Molecule::AtomIterator ai;
723 >    Molecule::CutoffGroupIterator ci;
724 >    Molecule* mol;
725 >    Atom* atom;
726 >    CutoffGroup* cg;
727 >    mpiSimData parallelData;
728 >    int isError;
729  
730 <    properties[prop->getID()] = prop;
730 >    for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
731  
732 +      //local index(index in DataStorge) of atom is important
733 +      for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
734 +        localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1;
735 +      }
736 +
737 +      //local index of cutoff group is trivial, it only depends on the order of travesing
738 +      for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
739 +        localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1);
740 +      }        
741 +        
742 +    }
743 +
744 +    //fill up mpiSimData struct
745 +    parallelData.nMolGlobal = getNGlobalMolecules();
746 +    parallelData.nMolLocal = getNMolecules();
747 +    parallelData.nAtomsGlobal = getNGlobalAtoms();
748 +    parallelData.nAtomsLocal = getNAtoms();
749 +    parallelData.nGroupsGlobal = getNGlobalCutoffGroups();
750 +    parallelData.nGroupsLocal = getNCutoffGroups();
751 +    parallelData.myNode = worldRank;
752 +    MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors));
753 +
754 +    //pass mpiSimData struct and index arrays to fortran
755 +    setFsimParallel(&parallelData, &(parallelData.nAtomsLocal),
756 +                    &localToGlobalAtomIndex[0],  &(parallelData.nGroupsLocal),
757 +                    &localToGlobalCutoffGroupIndex[0], &isError);
758 +
759 +    if (isError) {
760 +      sprintf(painCave.errMsg,
761 +              "mpiRefresh errror: fortran didn't like something we gave it.\n");
762 +      painCave.isFatal = 1;
763 +      simError();
764 +    }
765 +
766 +    sprintf(checkPointMsg, " mpiRefresh successful.\n");
767 +    MPIcheckPoint();
768 +
769 +
770    }
557    
558 }
771  
772 < GenericData* SimInfo::getProperty(const string& propName){
561 <
562 <  map<string, GenericData*>::iterator result;
563 <  
564 <  //string lowerCaseName = ();
565 <  
566 <  result = properties.find(propName);
567 <  
568 <  if(result != properties.end())
569 <    return (*result).second;  
570 <  else  
571 <    return NULL;  
572 < }
772 > #endif
773  
774 +  double SimInfo::calcMaxCutoffRadius() {
775  
575 void SimInfo::getFortranGroupArrays(SimInfo* info,
576                                    vector<int>& FglobalGroupMembership,
577                                    vector<double>& mfact){
578  
579  Molecule* myMols;
580  Atom** myAtoms;
581  int numAtom;
582  double mtot;
583  int numMol;
584  int numCutoffGroups;
585  CutoffGroup* myCutoffGroup;
586  vector<CutoffGroup*>::iterator iterCutoff;
587  Atom* cutoffAtom;
588  vector<Atom*>::iterator iterAtom;
589  int atomIndex;
590  double totalMass;
591  
592  mfact.clear();
593  FglobalGroupMembership.clear();
594  
776  
777 <  // Fix the silly fortran indexing problem
777 >    std::set<AtomType*> atomTypes;
778 >    std::set<AtomType*>::iterator i;
779 >    std::vector<double> cutoffRadius;
780 >
781 >    //get the unique atom types
782 >    atomTypes = getUniqueAtomTypes();
783 >
784 >    //query the max cutoff radius among these atom types
785 >    for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
786 >      cutoffRadius.push_back(forceField_->getRcutFromAtomType(*i));
787 >    }
788 >
789 >    double maxCutoffRadius = *(std::max_element(cutoffRadius.begin(), cutoffRadius.end()));
790   #ifdef IS_MPI
791 <  numAtom = mpiSim->getNAtomsGlobal();
599 < #else
600 <  numAtom = n_atoms;
791 >    //pick the max cutoff radius among the processors
792   #endif
602  for (int i = 0; i < numAtom; i++)
603    FglobalGroupMembership.push_back(globalGroupMembership[i] + 1);
604  
793  
794 <  myMols = info->molecules;
795 <  numMol = info->n_mol;
608 <  for(int i  = 0; i < numMol; i++){
609 <    numCutoffGroups = myMols[i].getNCutoffGroups();
610 <    for(myCutoffGroup =myMols[i].beginCutoffGroup(iterCutoff);
611 <        myCutoffGroup != NULL;
612 <        myCutoffGroup =myMols[i].nextCutoffGroup(iterCutoff)){
794 >    return maxCutoffRadius;
795 >  }
796  
797 <      totalMass = myCutoffGroup->getMass();
798 <      
799 <      for(cutoffAtom = myCutoffGroup->beginAtom(iterAtom);
800 <          cutoffAtom != NULL;
801 <          cutoffAtom = myCutoffGroup->nextAtom(iterAtom)){
802 <        mfact.push_back(cutoffAtom->getMass()/totalMass);
803 <      }  
797 >  void SimInfo::getCutoff(double& rcut, double& rsw) {
798 >    
799 >    if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) {
800 >        
801 >      if (!simParams_->haveRcut()){
802 >        sprintf(painCave.errMsg,
803 >                "SimCreator Warning: No value was set for the cutoffRadius.\n"
804 >                "\tOOPSE will use a default value of 15.0 angstroms"
805 >                "\tfor the cutoffRadius.\n");
806 >        painCave.isFatal = 0;
807 >        simError();
808 >        rcut = 15.0;
809 >      } else{
810 >        rcut = simParams_->getRcut();
811 >      }
812 >
813 >      if (!simParams_->haveRsw()){
814 >        sprintf(painCave.errMsg,
815 >                "SimCreator Warning: No value was set for switchingRadius.\n"
816 >                "\tOOPSE will use a default value of\n"
817 >                "\t0.95 * cutoffRadius for the switchingRadius\n");
818 >        painCave.isFatal = 0;
819 >        simError();
820 >        rsw = 0.95 * rcut;
821 >      } else{
822 >        rsw = simParams_->getRsw();
823 >      }
824 >
825 >    } else {
826 >      // if charge, dipole or reaction field is not used and the cutofff radius is not specified in
827 >      //meta-data file, the maximum cutoff radius calculated from forcefiled will be used
828 >        
829 >      if (simParams_->haveRcut()) {
830 >        rcut = simParams_->getRcut();
831 >      } else {
832 >        //set cutoff radius to the maximum cutoff radius based on atom types in the whole system
833 >        rcut = calcMaxCutoffRadius();
834 >      }
835 >
836 >      if (simParams_->haveRsw()) {
837 >        rsw  = simParams_->getRsw();
838 >      } else {
839 >        rsw = rcut;
840 >      }
841 >    
842      }
843    }
844  
845 < }
845 >  void SimInfo::setupCutoff() {    
846 >    getCutoff(rcut_, rsw_);    
847 >    double rnblist = rcut_ + 1; // skin of neighbor list
848 >
849 >    //Pass these cutoff radius etc. to fortran. This function should be called once and only once
850 >    
851 >    int cp =  TRADITIONAL_CUTOFF_POLICY;
852 >    if (simParams_->haveCutoffPolicy()) {
853 >      std::string myPolicy = simParams_->getCutoffPolicy();
854 >      if (myPolicy == "MIX") {
855 >        cp = MIX_CUTOFF_POLICY;
856 >      } else {
857 >        if (myPolicy == "MAX") {
858 >          cp = MAX_CUTOFF_POLICY;
859 >        } else {
860 >          if (myPolicy == "TRADITIONAL") {            
861 >            cp = TRADITIONAL_CUTOFF_POLICY;
862 >          } else {
863 >            // throw error        
864 >            sprintf( painCave.errMsg,
865 >                     "SimInfo error: Unknown cutoffPolicy. (Input file specified %s .)\n\tcutoffPolicy must be one of: \"Mix\", \"Max\", or \"Traditional\".", myPolicy.c_str() );
866 >            painCave.isFatal = 1;
867 >            simError();
868 >          }    
869 >        }          
870 >      }
871 >    }
872 >
873 >
874 >    if (simParams_->haveSkinThickness()) {
875 >      double skinThickness = simParams_->getSkinThickness();
876 >    }
877 >
878 >    notifyFortranCutoffs(&rcut_, &rsw_, &rnblist, &cp);
879 >    // also send cutoff notification to electrostatics
880 >    setElectrostaticCutoffRadius(&rcut_);
881 >  }
882 >
883 >  void SimInfo::setupElectrostaticSummationMethod( int isError ) {    
884 >    
885 >    int errorOut;
886 >    int esm =  NONE;
887 >    double alphaVal;
888 >    double dielectric;
889 >
890 >    errorOut = isError;
891 >    alphaVal = simParams_->getDampingAlpha();
892 >    dielectric = simParams_->getDielectric();
893 >
894 >    if (simParams_->haveElectrostaticSummationMethod()) {
895 >      std::string myMethod = simParams_->getElectrostaticSummationMethod();
896 >      if (myMethod == "NONE") {
897 >        esm = NONE;
898 >      } else {
899 >        if (myMethod == "UNDAMPED_WOLF") {
900 >          esm = UNDAMPED_WOLF;
901 >        } else {
902 >          if (myMethod == "DAMPED_WOLF") {            
903 >            esm = DAMPED_WOLF;
904 >            if (!simParams_->haveDampingAlpha()) {
905 >              //throw error
906 >              sprintf( painCave.errMsg,
907 >                       "SimInfo warning: dampingAlpha was not specified in the input file. A default value of %f (1/ang) will be used for the Damped Wolf Method.", alphaVal);
908 >              painCave.isFatal = 0;
909 >              simError();
910 >            }
911 >          } else {
912 >            if (myMethod == "REACTION_FIELD") {
913 >              esm = REACTION_FIELD;
914 >            } else {
915 >              // throw error        
916 >              sprintf( painCave.errMsg,
917 >                       "SimInfo error: Unknown electrostaticSummationMethod. (Input file specified %s .)\n\telectrostaticSummationMethod must be one of: \"none\", \"undamped_wolf\", \"damped_wolf\", or \"reaction_field\".", myMethod.c_str() );
918 >              painCave.isFatal = 1;
919 >              simError();
920 >            }    
921 >          }          
922 >        }
923 >      }
924 >    }
925 >    // let's pass some summation method variables to fortran
926 >    setElectrostaticSummationMethod( &esm );
927 >    setDampedWolfAlpha( &alphaVal );
928 >    setReactionFieldDielectric( &dielectric );
929 >    initFortranFF( &esm, &errorOut );
930 >  }
931 >
932 >  void SimInfo::addProperty(GenericData* genData) {
933 >    properties_.addProperty(genData);  
934 >  }
935 >
936 >  void SimInfo::removeProperty(const std::string& propName) {
937 >    properties_.removeProperty(propName);  
938 >  }
939 >
940 >  void SimInfo::clearProperties() {
941 >    properties_.clearProperties();
942 >  }
943 >
944 >  std::vector<std::string> SimInfo::getPropertyNames() {
945 >    return properties_.getPropertyNames();  
946 >  }
947 >      
948 >  std::vector<GenericData*> SimInfo::getProperties() {
949 >    return properties_.getProperties();
950 >  }
951 >
952 >  GenericData* SimInfo::getPropertyByName(const std::string& propName) {
953 >    return properties_.getPropertyByName(propName);
954 >  }
955 >
956 >  void SimInfo::setSnapshotManager(SnapshotManager* sman) {
957 >    if (sman_ == sman) {
958 >      return;
959 >    }    
960 >    delete sman_;
961 >    sman_ = sman;
962 >
963 >    Molecule* mol;
964 >    RigidBody* rb;
965 >    Atom* atom;
966 >    SimInfo::MoleculeIterator mi;
967 >    Molecule::RigidBodyIterator rbIter;
968 >    Molecule::AtomIterator atomIter;;
969 >
970 >    for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
971 >        
972 >      for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) {
973 >        atom->setSnapshotManager(sman_);
974 >      }
975 >        
976 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
977 >        rb->setSnapshotManager(sman_);
978 >      }
979 >    }    
980 >    
981 >  }
982 >
983 >  Vector3d SimInfo::getComVel(){
984 >    SimInfo::MoleculeIterator i;
985 >    Molecule* mol;
986 >
987 >    Vector3d comVel(0.0);
988 >    double totalMass = 0.0;
989 >    
990 >
991 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
992 >      double mass = mol->getMass();
993 >      totalMass += mass;
994 >      comVel += mass * mol->getComVel();
995 >    }  
996 >
997 > #ifdef IS_MPI
998 >    double tmpMass = totalMass;
999 >    Vector3d tmpComVel(comVel);    
1000 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1001 >    MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1002 > #endif
1003 >
1004 >    comVel /= totalMass;
1005 >
1006 >    return comVel;
1007 >  }
1008 >
1009 >  Vector3d SimInfo::getCom(){
1010 >    SimInfo::MoleculeIterator i;
1011 >    Molecule* mol;
1012 >
1013 >    Vector3d com(0.0);
1014 >    double totalMass = 0.0;
1015 >    
1016 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1017 >      double mass = mol->getMass();
1018 >      totalMass += mass;
1019 >      com += mass * mol->getCom();
1020 >    }  
1021 >
1022 > #ifdef IS_MPI
1023 >    double tmpMass = totalMass;
1024 >    Vector3d tmpCom(com);    
1025 >    MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1026 >    MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1027 > #endif
1028 >
1029 >    com /= totalMass;
1030 >
1031 >    return com;
1032 >
1033 >  }        
1034 >
1035 >  std::ostream& operator <<(std::ostream& o, SimInfo& info) {
1036 >
1037 >    return o;
1038 >  }
1039 >  
1040 >  
1041 >   /*
1042 >   Returns center of mass and center of mass velocity in one function call.
1043 >   */
1044 >  
1045 >   void SimInfo::getComAll(Vector3d &com, Vector3d &comVel){
1046 >      SimInfo::MoleculeIterator i;
1047 >      Molecule* mol;
1048 >      
1049 >    
1050 >      double totalMass = 0.0;
1051 >    
1052 >
1053 >      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1054 >         double mass = mol->getMass();
1055 >         totalMass += mass;
1056 >         com += mass * mol->getCom();
1057 >         comVel += mass * mol->getComVel();          
1058 >      }  
1059 >      
1060 > #ifdef IS_MPI
1061 >      double tmpMass = totalMass;
1062 >      Vector3d tmpCom(com);  
1063 >      Vector3d tmpComVel(comVel);
1064 >      MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1065 >      MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1066 >      MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1067 > #endif
1068 >      
1069 >      com /= totalMass;
1070 >      comVel /= totalMass;
1071 >   }        
1072 >  
1073 >   /*
1074 >   Return intertia tensor for entire system and angular momentum Vector.
1075 >
1076 >
1077 >       [  Ixx -Ixy  -Ixz ]
1078 >  J =| -Iyx  Iyy  -Iyz |
1079 >       [ -Izx -Iyz   Izz ]
1080 >    */
1081 >
1082 >   void SimInfo::getInertiaTensor(Mat3x3d &inertiaTensor, Vector3d &angularMomentum){
1083 >      
1084 >
1085 >      double xx = 0.0;
1086 >      double yy = 0.0;
1087 >      double zz = 0.0;
1088 >      double xy = 0.0;
1089 >      double xz = 0.0;
1090 >      double yz = 0.0;
1091 >      Vector3d com(0.0);
1092 >      Vector3d comVel(0.0);
1093 >      
1094 >      getComAll(com, comVel);
1095 >      
1096 >      SimInfo::MoleculeIterator i;
1097 >      Molecule* mol;
1098 >      
1099 >      Vector3d thisq(0.0);
1100 >      Vector3d thisv(0.0);
1101 >
1102 >      double thisMass = 0.0;
1103 >    
1104 >      
1105 >      
1106 >  
1107 >      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
1108 >        
1109 >         thisq = mol->getCom()-com;
1110 >         thisv = mol->getComVel()-comVel;
1111 >         thisMass = mol->getMass();
1112 >         // Compute moment of intertia coefficients.
1113 >         xx += thisq[0]*thisq[0]*thisMass;
1114 >         yy += thisq[1]*thisq[1]*thisMass;
1115 >         zz += thisq[2]*thisq[2]*thisMass;
1116 >        
1117 >         // compute products of intertia
1118 >         xy += thisq[0]*thisq[1]*thisMass;
1119 >         xz += thisq[0]*thisq[2]*thisMass;
1120 >         yz += thisq[1]*thisq[2]*thisMass;
1121 >            
1122 >         angularMomentum += cross( thisq, thisv ) * thisMass;
1123 >            
1124 >      }  
1125 >      
1126 >      
1127 >      inertiaTensor(0,0) = yy + zz;
1128 >      inertiaTensor(0,1) = -xy;
1129 >      inertiaTensor(0,2) = -xz;
1130 >      inertiaTensor(1,0) = -xy;
1131 >      inertiaTensor(1,1) = xx + zz;
1132 >      inertiaTensor(1,2) = -yz;
1133 >      inertiaTensor(2,0) = -xz;
1134 >      inertiaTensor(2,1) = -yz;
1135 >      inertiaTensor(2,2) = xx + yy;
1136 >      
1137 > #ifdef IS_MPI
1138 >      Mat3x3d tmpI(inertiaTensor);
1139 >      Vector3d tmpAngMom;
1140 >      MPI_Allreduce(tmpI.getArrayPointer(), inertiaTensor.getArrayPointer(),9,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1141 >      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1142 > #endif
1143 >              
1144 >      return;
1145 >   }
1146 >
1147 >   //Returns the angular momentum of the system
1148 >   Vector3d SimInfo::getAngularMomentum(){
1149 >      
1150 >      Vector3d com(0.0);
1151 >      Vector3d comVel(0.0);
1152 >      Vector3d angularMomentum(0.0);
1153 >      
1154 >      getComAll(com,comVel);
1155 >      
1156 >      SimInfo::MoleculeIterator i;
1157 >      Molecule* mol;
1158 >      
1159 >      Vector3d thisr(0.0);
1160 >      Vector3d thisp(0.0);
1161 >      
1162 >      double thisMass;
1163 >      
1164 >      for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {        
1165 >        thisMass = mol->getMass();
1166 >        thisr = mol->getCom()-com;
1167 >        thisp = (mol->getComVel()-comVel)*thisMass;
1168 >        
1169 >        angularMomentum += cross( thisr, thisp );
1170 >        
1171 >      }  
1172 >      
1173 > #ifdef IS_MPI
1174 >      Vector3d tmpAngMom;
1175 >      MPI_Allreduce(tmpAngMom.getArrayPointer(), angularMomentum.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD);
1176 > #endif
1177 >      
1178 >      return angularMomentum;
1179 >   }
1180 >  
1181 >  
1182 > }//end namespace oopse
1183 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines