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

Comparing:
trunk/OOPSE-2.0/src/brains/SimInfo.cpp (file contents), Revision 1492 by tim, Fri Sep 24 16:27:58 2004 UTC vs.
branches/new_design/OOPSE-2.0/src/brains/SimInfo.cpp (file contents), Revision 1804 by tim, Tue Nov 30 19:58:25 2004 UTC

# Line 1 | Line 1
1 < #include <stdlib.h>
2 < #include <string.h>
3 < #include <math.h>
1 > /*
2 > * Copyright (C) 2000-2004  Object Oriented Parallel Simulation Engine (OOPSE) project
3 > *
4 > * Contact: oopse@oopse.org
5 > *
6 > * This program is free software; you can redistribute it and/or
7 > * modify it under the terms of the GNU Lesser General Public License
8 > * as published by the Free Software Foundation; either version 2.1
9 > * of the License, or (at your option) any later version.
10 > * All we ask is that proper credit is given for our work, which includes
11 > * - but is not limited to - adding the above copyright notice to the beginning
12 > * of your source code files, and to any copyright notice that you may distribute
13 > * with programs based on this work.
14 > *
15 > * This program is distributed in the hope that it will be useful,
16 > * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 > * GNU Lesser General Public License for more details.
19 > *
20 > * You should have received a copy of the GNU Lesser General Public License
21 > * along with this program; if not, write to the Free Software
22 > * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 > *
24 > */
25  
26 < #include <iostream>
27 < using namespace std;
26 > /**
27 > * @file SimInfo.cpp
28 > * @author    tlin
29 > * @date  11/02/2004
30 > * @version 1.0
31 > */
32  
33 + #include <algorithm>
34 +
35   #include "brains/SimInfo.hpp"
36 < #define __C
37 < #include "brains/fSimulation.h"
36 > #include "primitives/Molecule.hpp"
37 > #include "UseTheForce/notifyCutoffs_interface.h"
38 > #include "utils/MemoryUtils.hpp"
39   #include "utils/simError.h"
40  
41 < #include "UseTheForce/fortranWrappers.hpp"
41 > namespace oopse {
42  
43 < #include "math/MatVec3.h"
43 > SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs,
44 >                                ForceField* ff, Globals* globals) :
45 >                                forceField_(ff), globals_(globals), nAtoms_(0), nBonds_(0),
46 >                                nBends_(0), nTorsions_(0), nRigidBodies_(0), nIntegrableObjects_(0),
47 >                                nCutoffGroups_(0), nConstraints_(0), nZconstraint_(0), sman_(NULL),
48 >                                fortranInitialized_(false) {
49  
50 < #ifdef IS_MPI
51 < #include "brains/mpiSimulation.hpp"
52 < #endif
50 >    std::vector<std::pair<MoleculeStamp*, int> >::iterator i;
51 >    MoleculeStamp* molStamp;
52 >    int nMolWithSameStamp;
53 >    int nCutoffAtoms; // number of atoms belong to cutoff groups
54 >    int nGroups;          //total cutoff groups defined in meta-data file
55 >    CutoffGroupStamp* cgStamp;
56 >    int nAtomsInGroups;
57 >    int nCutoffGroupsInStamp;
58 >    
59 >    RigidBodyStamp* rbStamp;
60 >    int nAtomsInRigidBodies;
61 >    int nRigidBodiesInStamp;
62 >    int nRigidAtoms;
63 >    int nRigidBodies;
64 >        
65 >    nGlobalAtoms_ =  0;
66 >    
67 >    nGroups = 0;
68 >    nCutoffAtoms = 0;
69 >    nRigidBodies = 0;
70 >    
71 >    for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) {
72 >        molStamp = i->first;
73 >        nMolWithSameStamp = i->second;
74 >        
75 >        addMoleculeStamp(molStamp, nMolWithSameStamp);
76  
77 < inline double roundMe( double x ){
78 <  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 < }
77 >        //calculate atoms in molecules
78 >        nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp;  
79  
29 SimInfo* currentInfo;
80  
81 < SimInfo::SimInfo(){
81 >        //calculate atoms in cutoff groups
82 >        nAtomsInGroups = 0;
83 >        nCutoffGroupsInStamp = molStamp->getNCutoffGroups();
84 >        
85 >        for (int j=0; j < nCutoffGroupsInStamp; j++) {
86 >            cgStamp = molStamp->getCutoffGroup(j);
87 >            nAtomsInGroups += cgStamp->getNMembers();
88 >        }
89  
90 <  n_constraints = 0;
91 <  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;
90 >        nGroups += nCutoffGroupsInStamp * nMolWithSameStamp;
91 >        nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp;            
92  
93 <  haveRcut = 0;
94 <  haveRsw = 0;
95 <  boxIsInit = 0;
96 <  
97 <  resetTime = 1e99;
93 >        //calculate atoms in rigid bodies
94 >        nAtomsInRigidBodies = 0;
95 >        nRigidBodiesInStamp = molStamp->getNCutoffGroups();
96 >        
97 >        for (int j=0; j < nRigidBodiesInStamp; j++) {
98 >            rbStamp = molStamp->getRigidBody(j);
99 >            nRigidBodiesInStamp += rbStamp->getNMembers();
100 >        }
101  
102 <  orthoRhombic = 0;
103 <  orthoTolerance = 1E-6;
104 <  useInitXSstate = true;
102 >        nRigidBodies += nRigidBodiesInStamp * nMolWithSameStamp;
103 >        nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp;            
104 >        
105 >    }
106  
107 <  usePBC = 0;
108 <  useLJ = 0;
109 <  useSticky = 0;
110 <  useCharges = 0;
111 <  useDipoles = 0;
62 <  useReactionField = 0;
63 <  useGB = 0;
64 <  useEAM = 0;
65 <  useSolidThermInt = 0;
66 <  useLiquidThermInt = 0;
107 >    //every free atom (atom does not belong to cutoff groups) is a cutoff group
108 >    //therefore the total number of cutoff groups in the system is equal to
109 >    //the total number of atoms minus number of atoms belong to cutoff group defined in meta-data
110 >    //file plus the number of cutoff groups defined in meta-data file
111 >    nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups;
112  
113 <  haveCutoffGroups = false;
113 >    //every free atom (atom does not belong to rigid bodies) is a rigid body
114 >    //therefore the total number of cutoff groups in the system is equal to
115 >    //the total number of atoms minus number of atoms belong to  rigid body defined in meta-data
116 >    //file plus the number of  rigid bodies defined in meta-data file
117 >    nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + nRigidBodies;
118  
119 <  excludes = Exclude::Instance();
119 >    //initialize globalGroupMembership_, every element of this array will be 0
120 >    globalGroupMembership_.insert(globalGroupMembership_.end(), nGlobalAtoms_, 0);
121  
122 <  myConfiguration = new SimState();
122 >    nGlobalMols_ = molStampIds_.size();
123  
124 <  has_minimizer = false;
125 <  the_minimizer =NULL;
124 > #ifdef IS_MPI    
125 >    molToProcMap_.resize(nGlobalMols_);
126 > #endif
127 >    
128 > }
129  
130 <  ngroup = 0;
130 > SimInfo::~SimInfo() {
131 >    //MemoryUtils::deleteVectorOfPointer(molecules_);
132  
133 <  wrapMeSimInfo( this );
133 >    MemoryUtils::deleteVectorOfPointer(moleculeStamps_);
134 >    
135 >    delete sman_;
136 >    delete globals_;
137 >    delete forceField_;
138 >
139   }
140  
141  
142 < SimInfo::~SimInfo(){
142 > bool SimInfo::addMolecule(Molecule* mol) {
143 >    MoleculeIterator i;
144  
145 <  delete myConfiguration;
145 >    i = molecules_.find(mol->getGlobalIndex());
146 >    if (i != molecules_.end() ) {
147  
148 <  map<string, GenericData*>::iterator i;
149 <  
150 <  for(i = properties.begin(); i != properties.end(); i++)
151 <    delete (*i).second;
148 >        molecules_.insert(make_pair(mol->getGlobalIndex(), mol));
149 >        
150 >        nAtoms_ += mol->getNAtoms();
151 >        nBonds_ += mol->getNBonds();
152 >        nBends_ += mol->getNBends();
153 >        nTorsions_ += mol->getNTorsions();
154 >        nRigidBodies_ += mol->getNRigidBodies();
155 >        nIntegrableObjects_ += mol->getNIntegrableObjects();
156 >        nCutoffGroups_ += mol->getNCutoffGroups();
157 >        nConstraints_ += mol->getNConstraints();
158  
159 +        return true;
160 +    } else {
161 +        return false;
162 +    }
163   }
164  
165 < void SimInfo::setBox(double newBox[3]) {
166 <  
167 <  int i, j;
97 <  double tempMat[3][3];
165 > bool SimInfo::removeMolecule(Molecule* mol) {
166 >    MoleculeIterator i;
167 >    i = molecules_.find(mol->getGlobalIndex());
168  
169 <  for(i=0; i<3; i++)
100 <    for (j=0; j<3; j++) tempMat[i][j] = 0.0;;
169 >    if (i != molecules_.end() ) {
170  
171 <  tempMat[0][0] = newBox[0];
172 <  tempMat[1][1] = newBox[1];
173 <  tempMat[2][2] = newBox[2];
171 >        assert(mol == i->second);
172 >        
173 >        nAtoms_ -= mol->getNAtoms();
174 >        nBonds_ -= mol->getNBonds();
175 >        nBends_ -= mol->getNBends();
176 >        nTorsions_ -= mol->getNTorsions();
177 >        nRigidBodies_ -= mol->getNRigidBodies();
178 >        nIntegrableObjects_ -= mol->getNIntegrableObjects();
179 >        nCutoffGroups_ -= mol->getNCutoffGroups();
180 >        nConstraints_ -= mol->getNConstraints();
181  
182 <  setBoxM( tempMat );
182 >        molecules_.erase(mol->getGlobalIndex());
183  
184 < }
184 >        delete mol;
185 >        
186 >        return true;
187 >    } else {
188 >        return false;
189 >    }
190  
110 void SimInfo::setBoxM( double theBox[3][3] ){
111  
112  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);
191  
192 <  if( !boxIsInit ) boxIsInit = 1;
192 > }    
193  
194 <  for(i=0; i < 3; i++)
195 <    for (j=0; j < 3; j++) Hmat[i][j] = theBox[i][j];
196 <  
197 <  calcBoxL();
198 <  calcHmatInv();
194 >        
195 > Molecule* SimInfo::beginMolecule(MoleculeIterator& i) {
196 >    i = molecules_.begin();
197 >    return i == molecules_.end() ? NULL : i->second;
198 > }    
199  
200 <  for(i=0; i < 3; i++) {
201 <    for (j=0; j < 3; j++) {
202 <      FortranHmat[3*j + i] = Hmat[i][j];
131 <      FortranHmatInv[3*j + i] = HmatInv[i][j];
132 <    }
133 <  }
134 <
135 <  setFortranBoxSize(FortranHmat, FortranHmatInv, &orthoRhombic);
136 <
200 > Molecule* SimInfo::nextMolecule(MoleculeIterator& i) {
201 >    ++i;
202 >    return i == molecules_.end() ? NULL : i->second;    
203   }
138
204  
140 void SimInfo::getBoxM (double theBox[3][3]) {
205  
206 <  int i, j;
207 <  for(i=0; i<3; i++)
208 <    for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j];
209 < }
206 > void SimInfo::calcNdf() {
207 >    int ndf_local;
208 >    MoleculeIterator i;
209 >    std::vector<StuntDouble*>::iterator j;
210 >    Molecule* mol;
211 >    StuntDouble* integrableObject;
212  
213 +    ndf_local = 0;
214 +    
215 +    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
216 +        for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
217 +               integrableObject = mol->nextIntegrableObject(j)) {
218  
219 < void SimInfo::scaleBox(double scale) {
149 <  double theBox[3][3];
150 <  int i, j;
219 >            ndf_local += 3;
220  
221 <  // cerr << "Scaling box by " << scale << "\n";
221 >            if (integrableObject->isDirectional()) {
222 >                if (integrableObject->isLinear()) {
223 >                    ndf_local += 2;
224 >                } else {
225 >                    ndf_local += 3;
226 >                }
227 >            }
228 >            
229 >        }//end for (integrableObject)
230 >    }// end for (mol)
231 >    
232 >    // n_constraints is local, so subtract them on each processor
233 >    ndf_local -= nConstraints_;
234  
235 <  for(i=0; i<3; i++)
236 <    for (j=0; j<3; j++) theBox[i][j] = Hmat[i][j]*scale;
235 > #ifdef IS_MPI
236 >    MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
237 > #else
238 >    ndf_ = ndf_local;
239 > #endif
240  
241 <  setBoxM(theBox);
241 >    // nZconstraints_ is global, as are the 3 COM translations for the
242 >    // entire system:
243 >    ndf_ = ndf_ - 3 - nZconstraint_;
244  
245   }
246  
247 < void SimInfo::calcHmatInv( void ) {
248 <  
163 <  int oldOrtho;
164 <  int i,j;
165 <  double smallDiag;
166 <  double tol;
167 <  double sanity[3][3];
247 > void SimInfo::calcNdfRaw() {
248 >    int ndfRaw_local;
249  
250 <  invertMat3( Hmat, HmatInv );
250 >    MoleculeIterator i;
251 >    std::vector<StuntDouble*>::iterator j;
252 >    Molecule* mol;
253 >    StuntDouble* integrableObject;
254  
255 <  // check to see if Hmat is orthorhombic
256 <  
257 <  oldOrtho = orthoRhombic;
258 <
259 <  smallDiag = fabs(Hmat[0][0]);
260 <  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;
255 >    // Raw degrees of freedom that we have to set
256 >    ndfRaw_local = 0;
257 >    
258 >    for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) {
259 >        for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL;
260 >               integrableObject = mol->nextIntegrableObject(j)) {
261  
262 <  orthoRhombic = 1;
181 <  
182 <  for (i = 0; i < 3; i++ ) {
183 <    for (j = 0 ; j < 3; j++) {
184 <      if (i != j) {
185 <        if (orthoRhombic) {
186 <          if ( fabs(Hmat[i][j]) >= tol) orthoRhombic = 0;
187 <        }        
188 <      }
189 <    }
190 <  }
262 >            ndfRaw_local += 3;
263  
264 <  if( oldOrtho != orthoRhombic ){
265 <    
266 <    if( orthoRhombic ) {
267 <      sprintf( painCave.errMsg,
268 <               "OOPSE is switching from the default Non-Orthorhombic\n"
269 <               "\tto the faster Orthorhombic periodic boundary computations.\n"
270 <               "\tThis is usually a good thing, but if you wan't the\n"
271 <               "\tNon-Orthorhombic computations, make the orthoBoxTolerance\n"
272 <               "\tvariable ( currently set to %G ) smaller.\n",
201 <               orthoTolerance);
202 <      painCave.severity = OOPSE_INFO;
203 <      simError();
264 >            if (integrableObject->isDirectional()) {
265 >                if (integrableObject->isLinear()) {
266 >                    ndfRaw_local += 2;
267 >                } else {
268 >                    ndfRaw_local += 3;
269 >                }
270 >            }
271 >            
272 >        }
273      }
274 <    else {
275 <      sprintf( painCave.errMsg,
276 <               "OOPSE is switching from the faster Orthorhombic to the more\n"
277 <               "\tflexible Non-Orthorhombic periodic boundary computations.\n"
278 <               "\tThis is usually because the box has deformed under\n"
279 <               "\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 <  }
274 >    
275 > #ifdef IS_MPI
276 >    MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
277 > #else
278 >    ndfRaw_ = ndfRaw_local;
279 > #endif
280   }
281  
282 < void SimInfo::calcBoxL( void ){
282 > void SimInfo::calcNdfTrans() {
283 >    int ndfTrans_local;
284  
285 <  double dx, dy, dz, dsq;
285 >    ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_;
286  
224  // boxVol = Determinant of Hmat
287  
288 <  boxVol = matDet3( Hmat );
288 > #ifdef IS_MPI
289 >    MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
290 > #else
291 >    ndfTrans_ = ndfTrans_local;
292 > #endif
293  
294 <  // boxLx
295 <  
296 <  dx = Hmat[0][0]; dy = Hmat[1][0]; dz = Hmat[2][0];
231 <  dsq = dx*dx + dy*dy + dz*dz;
232 <  boxL[0] = sqrt( dsq );
233 <  //maxCutoff = 0.5 * boxL[0];
294 >    ndfTrans_ = ndfTrans_ - 3 - nZconstraint_;
295 >
296 > }
297  
298 <  // boxLy
299 <  
300 <  dx = Hmat[0][1]; dy = Hmat[1][1]; dz = Hmat[2][1];
301 <  dsq = dx*dx + dy*dy + dz*dz;
302 <  boxL[1] = sqrt( dsq );
303 <  //if( (0.5 * boxL[1]) < maxCutoff ) maxCutoff = 0.5 * boxL[1];
298 > void SimInfo::addExcludePairs(Molecule* mol) {
299 >    std::vector<Bond*>::iterator bondIter;
300 >    std::vector<Bend*>::iterator bendIter;
301 >    std::vector<Torsion*>::iterator torsionIter;
302 >    Bond* bond;
303 >    Bend* bend;
304 >    Torsion* torsion;
305 >    int a;
306 >    int b;
307 >    int c;
308 >    int d;
309 >    
310 >    for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
311 >        a = bond->getAtomA()->getGlobalIndex();
312 >        b = bond->getAtomB()->getGlobalIndex();        
313 >        exclude_.addPair(a, b);
314 >    }
315  
316 +    for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
317 +        a = bend->getAtomA()->getGlobalIndex();
318 +        b = bend->getAtomB()->getGlobalIndex();        
319 +        c = bend->getAtomC()->getGlobalIndex();
320  
321 <  // boxLz
322 <  
323 <  dx = Hmat[0][2]; dy = Hmat[1][2]; dz = Hmat[2][2];
324 <  dsq = dx*dx + dy*dy + dz*dz;
247 <  boxL[2] = sqrt( dsq );
248 <  //if( (0.5 * boxL[2]) < maxCutoff ) maxCutoff = 0.5 * boxL[2];
321 >        exclude_.addPair(a, b);
322 >        exclude_.addPair(a, c);
323 >        exclude_.addPair(b, c);        
324 >    }
325  
326 <  //calculate the max cutoff
327 <  maxCutoff =  calcMaxCutOff();
328 <  
329 <  checkCutOffs();
326 >    for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
327 >        a = torsion->getAtomA()->getGlobalIndex();
328 >        b = torsion->getAtomB()->getGlobalIndex();        
329 >        c = torsion->getAtomC()->getGlobalIndex();        
330 >        d = torsion->getAtomD()->getGlobalIndex();        
331  
332 +        exclude_.addPair(a, b);
333 +        exclude_.addPair(a, c);
334 +        exclude_.addPair(a, d);
335 +        exclude_.addPair(b, c);
336 +        exclude_.addPair(b, d);
337 +        exclude_.addPair(c, d);        
338 +    }
339 +
340 +    
341   }
342  
343 + void SimInfo::removeExcludePairs(Molecule* mol) {
344 +    std::vector<Bond*>::iterator bondIter;
345 +    std::vector<Bend*>::iterator bendIter;
346 +    std::vector<Torsion*>::iterator torsionIter;
347 +    Bond* bond;
348 +    Bend* bend;
349 +    Torsion* torsion;
350 +    int a;
351 +    int b;
352 +    int c;
353 +    int d;
354 +    
355 +    for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) {
356 +        a = bond->getAtomA()->getGlobalIndex();
357 +        b = bond->getAtomB()->getGlobalIndex();        
358 +        exclude_.removePair(a, b);
359 +    }
360  
361 < double SimInfo::calcMaxCutOff(){
361 >    for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) {
362 >        a = bend->getAtomA()->getGlobalIndex();
363 >        b = bend->getAtomB()->getGlobalIndex();        
364 >        c = bend->getAtomC()->getGlobalIndex();
365  
366 <  double ri[3], rj[3], rk[3];
367 <  double rij[3], rjk[3], rki[3];
368 <  double minDist;
366 >        exclude_.removePair(a, b);
367 >        exclude_.removePair(a, c);
368 >        exclude_.removePair(b, c);        
369 >    }
370  
371 <  ri[0] = Hmat[0][0];
372 <  ri[1] = Hmat[1][0];
373 <  ri[2] = Hmat[2][0];
371 >    for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) {
372 >        a = torsion->getAtomA()->getGlobalIndex();
373 >        b = torsion->getAtomB()->getGlobalIndex();        
374 >        c = torsion->getAtomC()->getGlobalIndex();        
375 >        d = torsion->getAtomD()->getGlobalIndex();        
376  
377 <  rj[0] = Hmat[0][1];
378 <  rj[1] = Hmat[1][1];
379 <  rj[2] = Hmat[2][1];
377 >        exclude_.removePair(a, b);
378 >        exclude_.removePair(a, c);
379 >        exclude_.removePair(a, d);
380 >        exclude_.removePair(b, c);
381 >        exclude_.removePair(b, d);
382 >        exclude_.removePair(c, d);        
383 >    }
384  
385 <  rk[0] = Hmat[0][2];
273 <  rk[1] = Hmat[1][2];
274 <  rk[2] = Hmat[2][2];
275 <    
276 <  crossProduct3(ri, rj, rij);
277 <  distXY = dotProduct3(rk,rij) / norm3(rij);
385 > }
386  
279  crossProduct3(rj,rk, rjk);
280  distYZ = dotProduct3(ri,rjk) / norm3(rjk);
387  
388 <  crossProduct3(rk,ri, rki);
389 <  distZX = dotProduct3(rj,rki) / norm3(rki);
388 > void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) {
389 >    int curStampId;
390  
391 <  minDist = min(min(distXY, distYZ), distZX);
392 <  return minDist/2;
393 <  
391 >    //index from 0
392 >    curStampId = molStampIds_.size();
393 >
394 >    moleculeStamps_.push_back(molStamp);
395 >    molStampIds_.insert(molStampIds_.end(), nmol, curStampId);
396   }
397  
398 < void SimInfo::wrapVector( double thePos[3] ){
398 > void SimInfo::update() {
399  
400 <  int i;
293 <  double scaled[3];
400 >    setupSimType();
401  
402 <  if( !orthoRhombic ){
403 <    // calc the scaled coordinates.
404 <  
402 > #ifdef IS_MPI
403 >    setupFortranParallel();
404 > #endif
405  
406 <    matVecMul3(HmatInv, thePos, scaled);
300 <    
301 <    for(i=0; i<3; i++)
302 <      scaled[i] -= roundMe(scaled[i]);
303 <    
304 <    // calc the wrapped real coordinates from the wrapped scaled coordinates
305 <    
306 <    matVecMul3(Hmat, scaled, thePos);
406 >    setupFortranSim();
407  
408 <  }
309 <  else{
310 <    // calc the scaled coordinates.
311 <    
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 < }
408 >    setupCutoff();
409  
410 +    //notify fortran whether reaction field is used or not. It is deprecated now
411 +    //int isError = 0;
412 +    //initFortranFF( &useReactionField, &isError );
413  
414 < int SimInfo::getNDF(){
415 <  int ndf_local;
414 >    //if(isError){
415 >    //    sprintf( painCave.errMsg,
416 >    //    "SimCreator::initFortran() error: There was an error initializing the forceField in fortran.\n" );
417 >    //    painCave.isFatal = 1;
418 >    //    simError();
419 >    //}
420 >    
421 >    calcNdf();
422 >    calcNdfRaw();
423 >    calcNdfTrans();
424  
425 <  ndf_local = 0;
426 <  
334 <  for(int i = 0; i < integrableObjects.size(); i++){
335 <    ndf_local += 3;
336 <    if (integrableObjects[i]->isDirectional()) {
337 <      if (integrableObjects[i]->isLinear())
338 <        ndf_local += 2;
339 <      else
340 <        ndf_local += 3;
341 <    }
342 <  }
425 >    fortranInitialized_ = true;
426 > }
427  
428 <  // n_constraints is local, so subtract them on each processor:
428 > std::set<AtomType*> SimInfo::getUniqueAtomTypes() {
429 >    SimInfo::MoleculeIterator mi;
430 >    Molecule* mol;
431 >    Molecule::AtomIterator ai;
432 >    Atom* atom;
433 >    std::set<AtomType*> atomTypes;
434  
435 <  ndf_local -= n_constraints;
435 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
436  
437 < #ifdef IS_MPI
438 <  MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
439 < #else
440 <  ndf = ndf_local;
441 < #endif
437 >        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
438 >            atomTypes.insert(atom->getAtomType());
439 >        }
440 >        
441 >    }
442  
443 <  // nZconstraints is global, as are the 3 COM translations for the
355 <  // entire system:
356 <
357 <  ndf = ndf - 3 - nZconstraints;
358 <
359 <  return ndf;
443 >    return atomTypes;        
444   }
445  
446 < int SimInfo::getNDFraw() {
447 <  int ndfRaw_local;
446 > void SimInfo::setupSimType() {
447 >    std::set<AtomType*>::iterator i;
448 >    std::set<AtomType*> atomTypes;
449 >    atomTypes = getUniqueAtomTypes();
450 >    
451 >    int useLennardJones = 0;
452 >    int useElectrostatic = 0;
453 >    int useEAM = 0;
454 >    int useCharge = 0;
455 >    int useDirectional = 0;
456 >    int useDipole = 0;
457 >    int useGayBerne = 0;
458 >    int useSticky = 0;
459 >    int useShape = 0;
460 >    int useFLARB = 0; //it is not in AtomType yet
461 >    int useDirectionalAtom = 0;    
462 >    int useElectrostatics = 0;
463 >    //usePBC and useRF are from globals
464 >    bool usePBC = globals_->getPBC();
465 >    bool useRF = globals_->getUseRF();
466  
467 <  // Raw degrees of freedom that we have to set
468 <  ndfRaw_local = 0;
467 >    //loop over all of the atom types
468 >    for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
469 >        useLennardJones |= (*i)->isLennardJones();
470 >        useElectrostatic |= (*i)->isElectrostatic();
471 >        useEAM |= (*i)->isEAM();
472 >        useCharge |= (*i)->isCharge();
473 >        useDirectional |= (*i)->isDirectional();
474 >        useDipole |= (*i)->isDipole();
475 >        useGayBerne |= (*i)->isGayBerne();
476 >        useSticky |= (*i)->isSticky();
477 >        useShape |= (*i)->isShape();
478 >    }
479  
480 <  for(int i = 0; i < integrableObjects.size(); i++){
481 <    ndfRaw_local += 3;
370 <    if (integrableObjects[i]->isDirectional()) {
371 <       if (integrableObjects[i]->isLinear())
372 <        ndfRaw_local += 2;
373 <      else
374 <        ndfRaw_local += 3;
480 >    if (useSticky || useDipole || useGayBerne || useShape) {
481 >        useDirectionalAtom = 1;
482      }
376  }
377    
378 #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
483  
484 <  return ndfRaw;
485 < }
484 >    if (useCharge || useDipole) {
485 >        useElectrostatics = 1;
486 >    }
487  
488 < int SimInfo::getNDFtranslational() {
489 <  int ndfTrans_local;
488 > #ifdef IS_MPI    
489 >    int temp;
490  
491 <  ndfTrans_local = 3 * integrableObjects.size() - n_constraints;
491 >    temp = usePBC;
492 >    MPI_Allreduce(&temp, &usePBC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
493  
494 +    temp = useDirectionalAtom;
495 +    MPI_Allreduce(&temp, &useDirectionalAtom, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
496  
497 < #ifdef IS_MPI
498 <  MPI_Allreduce(&ndfTrans_local,&ndfTrans,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
395 < #else
396 <  ndfTrans = ndfTrans_local;
397 < #endif
497 >    temp = useLennardJones;
498 >    MPI_Allreduce(&temp, &useLennardJones, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
499  
500 <  ndfTrans = ndfTrans - 3 - nZconstraints;
500 >    temp = useElectrostatics;
501 >    MPI_Allreduce(&temp, &useElectrostatics, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
502  
503 <  return ndfTrans;
504 < }
503 >    temp = useCharge;
504 >    MPI_Allreduce(&temp, &useCharge, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
505  
506 < int SimInfo::getTotIntegrableObjects() {
507 <  int nObjs_local;
406 <  int nObjs;
506 >    temp = useDipole;
507 >    MPI_Allreduce(&temp, &useDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
508  
509 <  nObjs_local =  integrableObjects.size();
509 >    temp = useSticky;
510 >    MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
511  
512 +    temp = useGayBerne;
513 +    MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
514  
515 < #ifdef IS_MPI
516 <  MPI_Allreduce(&nObjs_local,&nObjs,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
517 < #else
518 <  nObjs = nObjs_local;
515 >    temp = useEAM;
516 >    MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
517 >
518 >    temp = useShape;
519 >    MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);  
520 >
521 >    temp = useFLARB;
522 >    MPI_Allreduce(&temp, &useFLARB, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
523 >
524 >    temp = useRF;
525 >    MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD);    
526 >    
527   #endif
528  
529 +    fInfo_.SIM_uses_PBC = usePBC;    
530 +    fInfo_.SIM_uses_DirectionalAtoms = useDirectionalAtom;
531 +    fInfo_.SIM_uses_LennardJones = useLennardJones;
532 +    fInfo_.SIM_uses_Electrostatics = useElectrostatics;    
533 +    fInfo_.SIM_uses_Charges = useCharge;
534 +    fInfo_.SIM_uses_Dipoles = useDipole;
535 +    fInfo_.SIM_uses_Sticky = useSticky;
536 +    fInfo_.SIM_uses_GayBerne = useGayBerne;
537 +    fInfo_.SIM_uses_EAM = useEAM;
538 +    fInfo_.SIM_uses_Shapes = useShape;
539 +    fInfo_.SIM_uses_FLARB = useFLARB;
540 +    fInfo_.SIM_uses_RF = useRF;
541  
542 <  return nObjs;
542 >    if( fInfo_.SIM_uses_Dipoles && fInfo_.SIM_uses_RF) {
543 >
544 >        if (globals_->haveDielectric()) {
545 >            fInfo_.dielect = globals_->getDielectric();
546 >        } else {
547 >            sprintf(painCave.errMsg,
548 >                    "SimSetup Error: No Dielectric constant was set.\n"
549 >                    "\tYou are trying to use Reaction Field without"
550 >                    "\tsetting a dielectric constant!\n");
551 >            painCave.isFatal = 1;
552 >            simError();
553 >        }
554 >        
555 >    } else {
556 >        fInfo_.dielect = 0.0;
557 >    }
558 >
559   }
560  
561 < void SimInfo::refreshSim(){
561 > void SimInfo::setupFortranSim() {
562 >    int isError;
563 >    int nExclude;
564 >    std::vector<int> fortranGlobalGroupMembership;
565 >    
566 >    nExclude = exclude_.getSize();
567 >    isError = 0;
568  
569 <  simtype fInfo;
570 <  int isError;
571 <  int n_global;
572 <  int* excl;
569 >    //globalGroupMembership_ is filled by SimCreator    
570 >    for (int i = 0; i < nGlobalAtoms_; i++) {
571 >        fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1);
572 >    }
573  
574 <  fInfo.dielect = 0.0;
574 >    //calculate mass ratio of cutoff group
575 >    std::vector<double> mfact;
576 >    SimInfo::MoleculeIterator mi;
577 >    Molecule* mol;
578 >    Molecule::CutoffGroupIterator ci;
579 >    CutoffGroup* cg;
580 >    Molecule::AtomIterator ai;
581 >    Atom* atom;
582 >    double totalMass;
583  
584 <  if( useDipoles ){
585 <    if( useReactionField )fInfo.dielect = dielectric;
586 <  }
584 >    //to avoid memory reallocation, reserve enough space for mfact
585 >    mfact.reserve(getNCutoffGroups());
586 >    
587 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
588 >        for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
589  
590 <  fInfo.SIM_uses_PBC = usePBC;
591 <  //fInfo.SIM_uses_LJ = 0;
592 <  fInfo.SIM_uses_LJ = useLJ;
593 <  fInfo.SIM_uses_sticky = useSticky;
438 <  //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;
590 >            totalMass = cg->getMass();
591 >            for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) {
592 >                        mfact.push_back(atom->getMass()/totalMass);
593 >            }
594  
595 <  n_exclude = excludes->getSize();
596 <  excl = excludes->getFortranArray();
449 <  
450 < #ifdef IS_MPI
451 <  n_global = mpiSim->getNAtomsGlobal();
452 < #else
453 <  n_global = n_atoms;
454 < #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);
595 >        }      
596 >    }
597  
598 <  if( isError ){
598 >    //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!)
599 >    std::vector<int> identArray;
600 >
601 >    //to avoid memory reallocation, reserve enough space identArray
602 >    identArray.reserve(getNAtoms());
603      
604 <    sprintf( painCave.errMsg,
605 <             "There was an error setting the simulation information in fortran.\n" );
606 <    painCave.isFatal = 1;
607 <    painCave.severity = OOPSE_ERROR;
608 <    simError();
609 <  }
610 <  
604 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {        
605 >        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
606 >            identArray.push_back(atom->getIdent());
607 >        }
608 >    }    
609 >
610 >    //fill molMembershipArray
611 >    //molMembershipArray is filled by SimCreator    
612 >    std::vector<int> molMembershipArray(nGlobalAtoms_);
613 >    for (int i = 0; i < nGlobalAtoms_; i++) {
614 >        molMembershipArray.push_back(globalMolMembership_[i] + 1);
615 >    }
616 >    
617 >    //setup fortran simulation
618 >    //gloalExcludes and molMembershipArray should go away (They are never used)
619 >    //why the hell fortran need to know molecule?
620 >    //OOPSE = Object-Obfuscated Parallel Simulation Engine
621 >    int nGlobalExcludes = 0;
622 >    int* globalExcludes = NULL;
623 >    int* excludeList = exclude_.getExcludeList();
624 >    setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], &nExclude, excludeList ,
625 >                  &nGlobalExcludes, globalExcludes, &molMembershipArray[0],
626 >                  &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError);
627 >
628 >    if( isError ){
629 >
630 >        sprintf( painCave.errMsg,
631 >                 "There was an error setting the simulation information in fortran.\n" );
632 >        painCave.isFatal = 1;
633 >        painCave.severity = OOPSE_ERROR;
634 >        simError();
635 >    }
636 >
637   #ifdef IS_MPI
638 <  sprintf( checkPointMsg,
639 <           "succesfully sent the simulation information to fortran.\n");
640 <  MPIcheckPoint();
638 >    sprintf( checkPointMsg,
639 >       "succesfully sent the simulation information to fortran.\n");
640 >    MPIcheckPoint();
641   #endif // is_mpi
480  
481  this->ndf = this->getNDF();
482  this->ndfRaw = this->getNDFraw();
483  this->ndfTrans = this->getNDFtranslational();
642   }
643  
486 void SimInfo::setDefaultRcut( double theRcut ){
487  
488  haveRcut = 1;
489  rCut = theRcut;
490  rList = rCut + 1.0;
491  
492  notifyFortranCutOffs( &rCut, &rSw, &rList );
493 }
644  
645 < void SimInfo::setDefaultRcut( double theRcut, double theRsw ){
645 > #ifdef IS_MPI
646 > void SimInfo::setupFortranParallel() {
647 >    
648 >    //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex
649 >    std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0);
650 >    std::vector<int> localToGlobalCutoffGroupIndex;
651 >    SimInfo::MoleculeIterator mi;
652 >    Molecule::AtomIterator ai;
653 >    Molecule::CutoffGroupIterator ci;
654 >    Molecule* mol;
655 >    Atom* atom;
656 >    CutoffGroup* cg;
657 >    mpiSimData parallelData;
658 >    int isError;
659  
660 <  rSw = theRsw;
498 <  setDefaultRcut( theRcut );
499 < }
660 >    for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
661  
662 +        //local index(index in DataStorge) of atom is important
663 +        for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
664 +            localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1;
665 +        }
666  
667 < void SimInfo::checkCutOffs( void ){
668 <  
669 <  if( boxIsInit ){
670 <    
671 <    //we need to check cutOffs against the box
672 <    
673 <    if( rCut > maxCutoff ){
674 <      sprintf( painCave.errMsg,
675 <               "cutoffRadius is too large for the current periodic box.\n"
676 <               "\tCurrent Value of cutoffRadius = %G at time %G\n "
677 <               "\tThis is larger than half of at least one of the\n"
678 <               "\tperiodic box vectors.  Right now, the Box matrix is:\n"
679 <               "\n"
680 <               "\t[ %G %G %G ]\n"
681 <               "\t[ %G %G %G ]\n"
682 <               "\t[ %G %G %G ]\n",
683 <               rCut, currentTime,
684 <               Hmat[0][0], Hmat[0][1], Hmat[0][2],
685 <               Hmat[1][0], Hmat[1][1], Hmat[1][2],
686 <               Hmat[2][0], Hmat[2][1], Hmat[2][2]);
687 <      painCave.severity = OOPSE_ERROR;
688 <      painCave.isFatal = 1;
689 <      simError();
690 <    }    
691 <  } else {
692 <    // initialize this stuff before using it, OK?
693 <    sprintf( painCave.errMsg,
694 <             "Trying to check cutoffs without a box.\n"
695 <             "\tOOPSE should have better programmers than that.\n" );
696 <    painCave.severity = OOPSE_ERROR;
697 <    painCave.isFatal = 1;
698 <    simError();      
699 <  }
535 <  
667 >        //local index of cutoff group is trivial, it only depends on the order of travesing
668 >        for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) {
669 >            localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1);
670 >        }        
671 >        
672 >    }
673 >
674 >    //fill up mpiSimData struct
675 >    parallelData.nMolGlobal = getNGlobalMolecules();
676 >    parallelData.nMolLocal = getNMolecules();
677 >    parallelData.nAtomsGlobal = getNGlobalAtoms();
678 >    parallelData.nAtomsLocal = getNAtoms();
679 >    parallelData.nGroupsGlobal = getNGlobalCutoffGroups();
680 >    parallelData.nGroupsLocal = getNCutoffGroups();
681 >    parallelData.myNode = worldRank;
682 >    MPI_Comm_size(MPI_COMM_WORLD, &(parallelData->nProcessors));
683 >
684 >    //pass mpiSimData struct and index arrays to fortran
685 >    setFsimParallel(parallelData, &(parallelData->nAtomsLocal),
686 >                    &localToGlobalAtomIndex[0],  &(parallelData->nGroupsLocal),
687 >                    &localToGlobalCutoffGroupIndex[0], &isError);
688 >
689 >    if (isError) {
690 >        sprintf(painCave.errMsg,
691 >                "mpiRefresh errror: fortran didn't like something we gave it.\n");
692 >        painCave.isFatal = 1;
693 >        simError();
694 >    }
695 >
696 >    sprintf(checkPointMsg, " mpiRefresh successful.\n");
697 >    MPIcheckPoint();
698 >
699 >
700   }
701  
702 < void SimInfo::addProperty(GenericData* prop){
702 > #endif
703  
704 <  map<string, GenericData*>::iterator result;
705 <  result = properties.find(prop->getID());
706 <  
707 <  //we can't simply use  properties[prop->getID()] = prop,
708 <  //it will cause memory leak if we already contain a propery which has the same name of prop
709 <  
710 <  if(result != properties.end()){
704 > double SimInfo::calcMaxCutoffRadius() {
705 >
706 >
707 >    std::set<AtomType*> atomTypes;
708 >    std::set<AtomType*>::iterator i;
709 >    std::vector<double> cutoffRadius;
710 >
711 >    //get the unique atom types
712 >    atomTypes = getUniqueAtomTypes();
713 >
714 >    //query the max cutoff radius among these atom types
715 >    for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
716 >        cutoffRadius.push_back(forceField_->getRcutFromAtomType(*i));
717 >    }
718 >
719 >    double maxCutoffRadius = *(std::max_element(cutoffRadius.begin(), cutoffRadius.end()));
720 > #ifdef IS_MPI
721 >    //pick the max cutoff radius among the processors
722 > #endif
723 >
724 >    return maxCutoffRadius;
725 > }
726 >
727 > void SimInfo::setupCutoff() {
728 >    double rcut_;  //cutoff radius
729 >    double rsw_; //switching radius
730      
731 <    delete (*result).second;
732 <    (*result).second = prop;
733 <      
734 <  }
735 <  else{
731 >    if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) {
732 >        
733 >        if (!globals_->haveRcut()){
734 >            sprintf(painCave.errMsg,
735 >                "SimCreator Warning: No value was set for the cutoffRadius.\n"
736 >                "\tOOPSE will use a default value of 15.0 angstroms"
737 >                "\tfor the cutoffRadius.\n");
738 >            painCave.isFatal = 0;
739 >            simError();
740 >            rcut_ = 15.0;
741 >        } else{
742 >            rcut_ = globals_->getRcut();
743 >        }
744  
745 <    properties[prop->getID()] = prop;
745 >        if (!globals_->haveRsw()){
746 >            sprintf(painCave.errMsg,
747 >                "SimCreator Warning: No value was set for switchingRadius.\n"
748 >                "\tOOPSE will use a default value of\n"
749 >                "\t0.95 * cutoffRadius for the switchingRadius\n");
750 >            painCave.isFatal = 0;
751 >            simError();
752 >            rsw_ = 0.95 * rcut_;
753 >        } else{
754 >            rsw_ = globals_->getRsw();
755 >        }
756  
757 <  }
757 >    } else {
758 >        // if charge, dipole or reaction field is not used and the cutofff radius is not specified in
759 >        //meta-data file, the maximum cutoff radius calculated from forcefiled will be used
760 >        
761 >        if (globals_->haveRcut()) {
762 >            rcut_ = globals_->getRcut();
763 >        } else {
764 >            //set cutoff radius to the maximum cutoff radius based on atom types in the whole system
765 >            rcut_ = calcMaxCutoffRadius();
766 >        }
767 >
768 >        if (globals_->haveRsw()) {
769 >            rsw_  = globals_->getRsw();
770 >        } else {
771 >            rsw_ = rcut_;
772 >        }
773      
774 +    }
775 +        
776 +    double rnblist = rcut_ + 1; // skin of neighbor list
777 +
778 +    //Pass these cutoff radius etc. to fortran. This function should be called once and only once
779 +    notifyFortranCutoffs(&rcut_, &rsw_, &rnblist);
780   }
781  
782 < GenericData* SimInfo::getProperty(const string& propName){
783 <
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;  
782 > void SimInfo::addProperty(GenericData* genData) {
783 >    properties_.addProperty(genData);  
784   }
785  
786 + void SimInfo::removeProperty(const std::string& propName) {
787 +    properties_.removeProperty(propName);  
788 + }
789  
790 < void SimInfo::getFortranGroupArrays(SimInfo* info,
791 <                                    vector<int>& FglobalGroupMembership,
792 <                                    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 <  
790 > void SimInfo::clearProperties() {
791 >    properties_.clearProperties();
792 > }
793  
794 <  // Fix the silly fortran indexing problem
795 < #ifdef IS_MPI
796 <  numAtom = mpiSim->getNAtomsGlobal();
797 < #else
798 <  numAtom = n_atoms;
799 < #endif
800 <  for (int i = 0; i < numAtom; i++)
603 <    FglobalGroupMembership.push_back(globalGroupMembership[i] + 1);
604 <  
794 > std::vector<std::string> SimInfo::getPropertyNames() {
795 >    return properties_.getPropertyNames();  
796 > }
797 >      
798 > std::vector<GenericData*> SimInfo::getProperties() {
799 >    return properties_.getProperties();
800 > }
801  
802 <  myMols = info->molecules;
803 <  numMol = info->n_mol;
804 <  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)){
802 > GenericData* SimInfo::getPropertyByName(const std::string& propName) {
803 >    return properties_.getPropertyByName(propName);
804 > }
805  
614      totalMass = myCutoffGroup->getMass();
615      
616      for(cutoffAtom = myCutoffGroup->beginAtom(iterAtom);
617          cutoffAtom != NULL;
618          cutoffAtom = myCutoffGroup->nextAtom(iterAtom)){
619        mfact.push_back(cutoffAtom->getMass()/totalMass);
620      }  
621    }
622  }
806  
807 + std::ostream& operator <<(ostream& o, SimInfo& info) {
808 +
809 +    return o;
810   }
811 +
812 + }//end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines