| 1 | gezelter | 246 | /* | 
| 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 | gezelter | 2 |  | 
| 49 | gezelter | 246 | #include <algorithm> | 
| 50 |  |  | #include <set> | 
| 51 | gezelter | 2 |  | 
| 52 | tim | 3 | #include "brains/SimInfo.hpp" | 
| 53 | gezelter | 246 | #include "math/Vector3.hpp" | 
| 54 |  |  | #include "primitives/Molecule.hpp" | 
| 55 |  |  | #include "UseTheForce/doForces_interface.h" | 
| 56 |  |  | #include "UseTheForce/notifyCutoffs_interface.h" | 
| 57 |  |  | #include "utils/MemoryUtils.hpp" | 
| 58 | tim | 3 | #include "utils/simError.h" | 
| 59 | tim | 316 | #include "selection/SelectionManager.hpp" | 
| 60 | gezelter | 2 |  | 
| 61 | gezelter | 246 | #ifdef IS_MPI | 
| 62 |  |  | #include "UseTheForce/mpiComponentPlan.h" | 
| 63 |  |  | #include "UseTheForce/DarkSide/simParallel_interface.h" | 
| 64 |  |  | #endif | 
| 65 | gezelter | 2 |  | 
| 66 | gezelter | 246 | namespace oopse { | 
| 67 | gezelter | 2 |  | 
| 68 | gezelter | 246 | SimInfo::SimInfo(std::vector<std::pair<MoleculeStamp*, int> >& molStampPairs, | 
| 69 |  |  | ForceField* ff, Globals* simParams) : | 
| 70 |  |  | forceField_(ff), simParams_(simParams), | 
| 71 |  |  | ndf_(0), ndfRaw_(0), ndfTrans_(0), nZconstraint_(0), | 
| 72 |  |  | nGlobalMols_(0), nGlobalAtoms_(0), nGlobalCutoffGroups_(0), | 
| 73 |  |  | nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), | 
| 74 |  |  | nAtoms_(0), nBonds_(0),  nBends_(0), nTorsions_(0), nRigidBodies_(0), | 
| 75 |  |  | nIntegrableObjects_(0),  nCutoffGroups_(0), nConstraints_(0), | 
| 76 | tim | 292 | sman_(NULL), fortranInitialized_(false), selectMan_(NULL) { | 
| 77 | gezelter | 2 |  | 
| 78 | gezelter | 246 |  | 
| 79 |  |  | std::vector<std::pair<MoleculeStamp*, int> >::iterator i; | 
| 80 |  |  | MoleculeStamp* molStamp; | 
| 81 |  |  | int nMolWithSameStamp; | 
| 82 |  |  | int nCutoffAtoms = 0; // number of atoms belong to cutoff groups | 
| 83 |  |  | int nGroups = 0;          //total cutoff groups defined in meta-data file | 
| 84 |  |  | CutoffGroupStamp* cgStamp; | 
| 85 |  |  | RigidBodyStamp* rbStamp; | 
| 86 |  |  | int nRigidAtoms = 0; | 
| 87 |  |  |  | 
| 88 |  |  | for (i = molStampPairs.begin(); i !=molStampPairs.end(); ++i) { | 
| 89 |  |  | molStamp = i->first; | 
| 90 |  |  | nMolWithSameStamp = i->second; | 
| 91 |  |  |  | 
| 92 |  |  | addMoleculeStamp(molStamp, nMolWithSameStamp); | 
| 93 | gezelter | 2 |  | 
| 94 | gezelter | 246 | //calculate atoms in molecules | 
| 95 |  |  | nGlobalAtoms_ += molStamp->getNAtoms() *nMolWithSameStamp; | 
| 96 | gezelter | 2 |  | 
| 97 |  |  |  | 
| 98 | gezelter | 246 | //calculate atoms in cutoff groups | 
| 99 |  |  | int nAtomsInGroups = 0; | 
| 100 |  |  | int nCutoffGroupsInStamp = molStamp->getNCutoffGroups(); | 
| 101 |  |  |  | 
| 102 |  |  | for (int j=0; j < nCutoffGroupsInStamp; j++) { | 
| 103 |  |  | cgStamp = molStamp->getCutoffGroup(j); | 
| 104 |  |  | nAtomsInGroups += cgStamp->getNMembers(); | 
| 105 |  |  | } | 
| 106 | gezelter | 2 |  | 
| 107 | gezelter | 246 | nGroups += nCutoffGroupsInStamp * nMolWithSameStamp; | 
| 108 |  |  | nCutoffAtoms += nAtomsInGroups * nMolWithSameStamp; | 
| 109 | gezelter | 2 |  | 
| 110 | gezelter | 246 | //calculate atoms in rigid bodies | 
| 111 |  |  | int nAtomsInRigidBodies = 0; | 
| 112 | tim | 274 | int nRigidBodiesInStamp = molStamp->getNRigidBodies(); | 
| 113 | gezelter | 246 |  | 
| 114 |  |  | for (int j=0; j < nRigidBodiesInStamp; j++) { | 
| 115 |  |  | rbStamp = molStamp->getRigidBody(j); | 
| 116 |  |  | nAtomsInRigidBodies += rbStamp->getNMembers(); | 
| 117 |  |  | } | 
| 118 | gezelter | 2 |  | 
| 119 | gezelter | 246 | nGlobalRigidBodies_ += nRigidBodiesInStamp * nMolWithSameStamp; | 
| 120 |  |  | nRigidAtoms += nAtomsInRigidBodies * nMolWithSameStamp; | 
| 121 |  |  |  | 
| 122 |  |  | } | 
| 123 | chrisfen | 143 |  | 
| 124 | gezelter | 246 | //every free atom (atom does not belong to cutoff groups) is a cutoff group | 
| 125 |  |  | //therefore the total number of cutoff groups in the system is equal to | 
| 126 |  |  | //the total number of atoms minus number of atoms belong to cutoff group defined in meta-data | 
| 127 |  |  | //file plus the number of cutoff groups defined in meta-data file | 
| 128 |  |  | nGlobalCutoffGroups_ = nGlobalAtoms_ - nCutoffAtoms + nGroups; | 
| 129 | gezelter | 2 |  | 
| 130 | gezelter | 246 | //every free atom (atom does not belong to rigid bodies) is an integrable object | 
| 131 |  |  | //therefore the total number of  integrable objects in the system is equal to | 
| 132 |  |  | //the total number of atoms minus number of atoms belong to  rigid body defined in meta-data | 
| 133 |  |  | //file plus the number of  rigid bodies defined in meta-data file | 
| 134 |  |  | nGlobalIntegrableObjects_ = nGlobalAtoms_ - nRigidAtoms + nGlobalRigidBodies_; | 
| 135 | gezelter | 2 |  | 
| 136 | gezelter | 246 | nGlobalMols_ = molStampIds_.size(); | 
| 137 | gezelter | 2 |  | 
| 138 | gezelter | 246 | #ifdef IS_MPI | 
| 139 |  |  | molToProcMap_.resize(nGlobalMols_); | 
| 140 |  |  | #endif | 
| 141 | tim | 292 |  | 
| 142 | tim | 316 | selectMan_ = new SelectionManager(this); | 
| 143 | tim | 292 | selectMan_->selectAll(); | 
| 144 | gezelter | 246 | } | 
| 145 | gezelter | 2 |  | 
| 146 | gezelter | 246 | SimInfo::~SimInfo() { | 
| 147 |  |  | //MemoryUtils::deleteVectorOfPointer(molecules_); | 
| 148 | gezelter | 2 |  | 
| 149 | gezelter | 246 | MemoryUtils::deleteVectorOfPointer(moleculeStamps_); | 
| 150 |  |  |  | 
| 151 |  |  | delete sman_; | 
| 152 |  |  | delete simParams_; | 
| 153 |  |  | delete forceField_; | 
| 154 | tim | 292 | delete selectMan_; | 
| 155 | gezelter | 2 | } | 
| 156 |  |  |  | 
| 157 | gezelter | 246 | int SimInfo::getNGlobalConstraints() { | 
| 158 |  |  | int nGlobalConstraints; | 
| 159 |  |  | #ifdef IS_MPI | 
| 160 |  |  | MPI_Allreduce(&nConstraints_, &nGlobalConstraints, 1, MPI_INT, MPI_SUM, | 
| 161 |  |  | MPI_COMM_WORLD); | 
| 162 |  |  | #else | 
| 163 |  |  | nGlobalConstraints =  nConstraints_; | 
| 164 |  |  | #endif | 
| 165 |  |  | return nGlobalConstraints; | 
| 166 |  |  | } | 
| 167 | gezelter | 2 |  | 
| 168 | gezelter | 246 | bool SimInfo::addMolecule(Molecule* mol) { | 
| 169 |  |  | MoleculeIterator i; | 
| 170 | gezelter | 2 |  | 
| 171 | gezelter | 246 | i = molecules_.find(mol->getGlobalIndex()); | 
| 172 |  |  | if (i == molecules_.end() ) { | 
| 173 | gezelter | 2 |  | 
| 174 | gezelter | 246 | molecules_.insert(std::make_pair(mol->getGlobalIndex(), mol)); | 
| 175 |  |  |  | 
| 176 |  |  | nAtoms_ += mol->getNAtoms(); | 
| 177 |  |  | nBonds_ += mol->getNBonds(); | 
| 178 |  |  | nBends_ += mol->getNBends(); | 
| 179 |  |  | nTorsions_ += mol->getNTorsions(); | 
| 180 |  |  | nRigidBodies_ += mol->getNRigidBodies(); | 
| 181 |  |  | nIntegrableObjects_ += mol->getNIntegrableObjects(); | 
| 182 |  |  | nCutoffGroups_ += mol->getNCutoffGroups(); | 
| 183 |  |  | nConstraints_ += mol->getNConstraintPairs(); | 
| 184 | gezelter | 2 |  | 
| 185 | gezelter | 246 | addExcludePairs(mol); | 
| 186 |  |  |  | 
| 187 |  |  | return true; | 
| 188 |  |  | } else { | 
| 189 |  |  | return false; | 
| 190 |  |  | } | 
| 191 | gezelter | 2 | } | 
| 192 |  |  |  | 
| 193 | gezelter | 246 | bool SimInfo::removeMolecule(Molecule* mol) { | 
| 194 |  |  | MoleculeIterator i; | 
| 195 |  |  | i = molecules_.find(mol->getGlobalIndex()); | 
| 196 | gezelter | 2 |  | 
| 197 | gezelter | 246 | if (i != molecules_.end() ) { | 
| 198 | gezelter | 2 |  | 
| 199 | gezelter | 246 | assert(mol == i->second); | 
| 200 |  |  |  | 
| 201 |  |  | nAtoms_ -= mol->getNAtoms(); | 
| 202 |  |  | nBonds_ -= mol->getNBonds(); | 
| 203 |  |  | nBends_ -= mol->getNBends(); | 
| 204 |  |  | nTorsions_ -= mol->getNTorsions(); | 
| 205 |  |  | nRigidBodies_ -= mol->getNRigidBodies(); | 
| 206 |  |  | nIntegrableObjects_ -= mol->getNIntegrableObjects(); | 
| 207 |  |  | nCutoffGroups_ -= mol->getNCutoffGroups(); | 
| 208 |  |  | nConstraints_ -= mol->getNConstraintPairs(); | 
| 209 | gezelter | 2 |  | 
| 210 | gezelter | 246 | removeExcludePairs(mol); | 
| 211 |  |  | molecules_.erase(mol->getGlobalIndex()); | 
| 212 | gezelter | 2 |  | 
| 213 | gezelter | 246 | delete mol; | 
| 214 |  |  |  | 
| 215 |  |  | return true; | 
| 216 |  |  | } else { | 
| 217 |  |  | return false; | 
| 218 |  |  | } | 
| 219 |  |  |  | 
| 220 |  |  |  | 
| 221 |  |  | } | 
| 222 |  |  |  | 
| 223 |  |  |  | 
| 224 |  |  | Molecule* SimInfo::beginMolecule(MoleculeIterator& i) { | 
| 225 |  |  | i = molecules_.begin(); | 
| 226 |  |  | return i == molecules_.end() ? NULL : i->second; | 
| 227 |  |  | } | 
| 228 |  |  |  | 
| 229 |  |  | Molecule* SimInfo::nextMolecule(MoleculeIterator& i) { | 
| 230 |  |  | ++i; | 
| 231 |  |  | return i == molecules_.end() ? NULL : i->second; | 
| 232 | gezelter | 2 | } | 
| 233 |  |  |  | 
| 234 |  |  |  | 
| 235 | gezelter | 246 | void SimInfo::calcNdf() { | 
| 236 |  |  | int ndf_local; | 
| 237 |  |  | MoleculeIterator i; | 
| 238 |  |  | std::vector<StuntDouble*>::iterator j; | 
| 239 |  |  | Molecule* mol; | 
| 240 |  |  | StuntDouble* integrableObject; | 
| 241 | gezelter | 2 |  | 
| 242 | gezelter | 246 | ndf_local = 0; | 
| 243 |  |  |  | 
| 244 |  |  | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 245 |  |  | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; | 
| 246 |  |  | integrableObject = mol->nextIntegrableObject(j)) { | 
| 247 | gezelter | 2 |  | 
| 248 | gezelter | 246 | ndf_local += 3; | 
| 249 | gezelter | 2 |  | 
| 250 | gezelter | 246 | if (integrableObject->isDirectional()) { | 
| 251 |  |  | if (integrableObject->isLinear()) { | 
| 252 |  |  | ndf_local += 2; | 
| 253 |  |  | } else { | 
| 254 |  |  | ndf_local += 3; | 
| 255 |  |  | } | 
| 256 |  |  | } | 
| 257 |  |  |  | 
| 258 |  |  | }//end for (integrableObject) | 
| 259 |  |  | }// end for (mol) | 
| 260 |  |  |  | 
| 261 |  |  | // n_constraints is local, so subtract them on each processor | 
| 262 |  |  | ndf_local -= nConstraints_; | 
| 263 |  |  |  | 
| 264 |  |  | #ifdef IS_MPI | 
| 265 |  |  | MPI_Allreduce(&ndf_local,&ndf_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 266 |  |  | #else | 
| 267 |  |  | ndf_ = ndf_local; | 
| 268 |  |  | #endif | 
| 269 |  |  |  | 
| 270 |  |  | // nZconstraints_ is global, as are the 3 COM translations for the | 
| 271 |  |  | // entire system: | 
| 272 |  |  | ndf_ = ndf_ - 3 - nZconstraint_; | 
| 273 |  |  |  | 
| 274 | gezelter | 2 | } | 
| 275 |  |  |  | 
| 276 | gezelter | 246 | void SimInfo::calcNdfRaw() { | 
| 277 |  |  | int ndfRaw_local; | 
| 278 | gezelter | 2 |  | 
| 279 | gezelter | 246 | MoleculeIterator i; | 
| 280 |  |  | std::vector<StuntDouble*>::iterator j; | 
| 281 |  |  | Molecule* mol; | 
| 282 |  |  | StuntDouble* integrableObject; | 
| 283 |  |  |  | 
| 284 |  |  | // Raw degrees of freedom that we have to set | 
| 285 |  |  | ndfRaw_local = 0; | 
| 286 |  |  |  | 
| 287 |  |  | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 288 |  |  | for (integrableObject = mol->beginIntegrableObject(j); integrableObject != NULL; | 
| 289 |  |  | integrableObject = mol->nextIntegrableObject(j)) { | 
| 290 |  |  |  | 
| 291 |  |  | ndfRaw_local += 3; | 
| 292 |  |  |  | 
| 293 |  |  | if (integrableObject->isDirectional()) { | 
| 294 |  |  | if (integrableObject->isLinear()) { | 
| 295 |  |  | ndfRaw_local += 2; | 
| 296 |  |  | } else { | 
| 297 |  |  | ndfRaw_local += 3; | 
| 298 |  |  | } | 
| 299 |  |  | } | 
| 300 |  |  |  | 
| 301 |  |  | } | 
| 302 |  |  | } | 
| 303 |  |  |  | 
| 304 |  |  | #ifdef IS_MPI | 
| 305 |  |  | MPI_Allreduce(&ndfRaw_local,&ndfRaw_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 306 |  |  | #else | 
| 307 |  |  | ndfRaw_ = ndfRaw_local; | 
| 308 |  |  | #endif | 
| 309 | gezelter | 2 | } | 
| 310 |  |  |  | 
| 311 | gezelter | 246 | void SimInfo::calcNdfTrans() { | 
| 312 |  |  | int ndfTrans_local; | 
| 313 | gezelter | 2 |  | 
| 314 | gezelter | 246 | ndfTrans_local = 3 * nIntegrableObjects_ - nConstraints_; | 
| 315 | gezelter | 2 |  | 
| 316 |  |  |  | 
| 317 | gezelter | 246 | #ifdef IS_MPI | 
| 318 |  |  | MPI_Allreduce(&ndfTrans_local,&ndfTrans_,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD); | 
| 319 |  |  | #else | 
| 320 |  |  | ndfTrans_ = ndfTrans_local; | 
| 321 |  |  | #endif | 
| 322 | gezelter | 2 |  | 
| 323 | gezelter | 246 | ndfTrans_ = ndfTrans_ - 3 - nZconstraint_; | 
| 324 |  |  |  | 
| 325 | gezelter | 2 | } | 
| 326 |  |  |  | 
| 327 | gezelter | 246 | void SimInfo::addExcludePairs(Molecule* mol) { | 
| 328 |  |  | std::vector<Bond*>::iterator bondIter; | 
| 329 |  |  | std::vector<Bend*>::iterator bendIter; | 
| 330 |  |  | std::vector<Torsion*>::iterator torsionIter; | 
| 331 |  |  | Bond* bond; | 
| 332 |  |  | Bend* bend; | 
| 333 |  |  | Torsion* torsion; | 
| 334 |  |  | int a; | 
| 335 |  |  | int b; | 
| 336 |  |  | int c; | 
| 337 |  |  | int d; | 
| 338 |  |  |  | 
| 339 |  |  | for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { | 
| 340 |  |  | a = bond->getAtomA()->getGlobalIndex(); | 
| 341 |  |  | b = bond->getAtomB()->getGlobalIndex(); | 
| 342 |  |  | exclude_.addPair(a, b); | 
| 343 |  |  | } | 
| 344 | gezelter | 2 |  | 
| 345 | gezelter | 246 | for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { | 
| 346 |  |  | a = bend->getAtomA()->getGlobalIndex(); | 
| 347 |  |  | b = bend->getAtomB()->getGlobalIndex(); | 
| 348 |  |  | c = bend->getAtomC()->getGlobalIndex(); | 
| 349 | gezelter | 2 |  | 
| 350 | gezelter | 246 | exclude_.addPair(a, b); | 
| 351 |  |  | exclude_.addPair(a, c); | 
| 352 |  |  | exclude_.addPair(b, c); | 
| 353 |  |  | } | 
| 354 | gezelter | 2 |  | 
| 355 | gezelter | 246 | for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { | 
| 356 |  |  | a = torsion->getAtomA()->getGlobalIndex(); | 
| 357 |  |  | b = torsion->getAtomB()->getGlobalIndex(); | 
| 358 |  |  | c = torsion->getAtomC()->getGlobalIndex(); | 
| 359 |  |  | d = torsion->getAtomD()->getGlobalIndex(); | 
| 360 | gezelter | 2 |  | 
| 361 | gezelter | 246 | exclude_.addPair(a, b); | 
| 362 |  |  | exclude_.addPair(a, c); | 
| 363 |  |  | exclude_.addPair(a, d); | 
| 364 |  |  | exclude_.addPair(b, c); | 
| 365 |  |  | exclude_.addPair(b, d); | 
| 366 |  |  | exclude_.addPair(c, d); | 
| 367 | gezelter | 2 | } | 
| 368 |  |  |  | 
| 369 |  |  |  | 
| 370 | gezelter | 246 | } | 
| 371 |  |  |  | 
| 372 |  |  | void SimInfo::removeExcludePairs(Molecule* mol) { | 
| 373 |  |  | std::vector<Bond*>::iterator bondIter; | 
| 374 |  |  | std::vector<Bend*>::iterator bendIter; | 
| 375 |  |  | std::vector<Torsion*>::iterator torsionIter; | 
| 376 |  |  | Bond* bond; | 
| 377 |  |  | Bend* bend; | 
| 378 |  |  | Torsion* torsion; | 
| 379 |  |  | int a; | 
| 380 |  |  | int b; | 
| 381 |  |  | int c; | 
| 382 |  |  | int d; | 
| 383 |  |  |  | 
| 384 |  |  | for (bond= mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { | 
| 385 |  |  | a = bond->getAtomA()->getGlobalIndex(); | 
| 386 |  |  | b = bond->getAtomB()->getGlobalIndex(); | 
| 387 |  |  | exclude_.removePair(a, b); | 
| 388 | gezelter | 2 | } | 
| 389 | gezelter | 246 |  | 
| 390 |  |  | for (bend= mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { | 
| 391 |  |  | a = bend->getAtomA()->getGlobalIndex(); | 
| 392 |  |  | b = bend->getAtomB()->getGlobalIndex(); | 
| 393 |  |  | c = bend->getAtomC()->getGlobalIndex(); | 
| 394 |  |  |  | 
| 395 |  |  | exclude_.removePair(a, b); | 
| 396 |  |  | exclude_.removePair(a, c); | 
| 397 |  |  | exclude_.removePair(b, c); | 
| 398 | gezelter | 2 | } | 
| 399 | gezelter | 246 |  | 
| 400 |  |  | for (torsion= mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { | 
| 401 |  |  | a = torsion->getAtomA()->getGlobalIndex(); | 
| 402 |  |  | b = torsion->getAtomB()->getGlobalIndex(); | 
| 403 |  |  | c = torsion->getAtomC()->getGlobalIndex(); | 
| 404 |  |  | d = torsion->getAtomD()->getGlobalIndex(); | 
| 405 |  |  |  | 
| 406 |  |  | exclude_.removePair(a, b); | 
| 407 |  |  | exclude_.removePair(a, c); | 
| 408 |  |  | exclude_.removePair(a, d); | 
| 409 |  |  | exclude_.removePair(b, c); | 
| 410 |  |  | exclude_.removePair(b, d); | 
| 411 |  |  | exclude_.removePair(c, d); | 
| 412 |  |  | } | 
| 413 |  |  |  | 
| 414 | gezelter | 2 | } | 
| 415 |  |  |  | 
| 416 |  |  |  | 
| 417 | gezelter | 246 | void SimInfo::addMoleculeStamp(MoleculeStamp* molStamp, int nmol) { | 
| 418 |  |  | int curStampId; | 
| 419 | gezelter | 2 |  | 
| 420 | gezelter | 246 | //index from 0 | 
| 421 |  |  | curStampId = moleculeStamps_.size(); | 
| 422 | gezelter | 2 |  | 
| 423 | gezelter | 246 | moleculeStamps_.push_back(molStamp); | 
| 424 |  |  | molStampIds_.insert(molStampIds_.end(), nmol, curStampId); | 
| 425 |  |  | } | 
| 426 | gezelter | 2 |  | 
| 427 | gezelter | 246 | void SimInfo::update() { | 
| 428 | gezelter | 2 |  | 
| 429 | gezelter | 246 | setupSimType(); | 
| 430 | gezelter | 2 |  | 
| 431 | gezelter | 246 | #ifdef IS_MPI | 
| 432 |  |  | setupFortranParallel(); | 
| 433 |  |  | #endif | 
| 434 | gezelter | 2 |  | 
| 435 | gezelter | 246 | setupFortranSim(); | 
| 436 | gezelter | 2 |  | 
| 437 | gezelter | 246 | //setup fortran force field | 
| 438 |  |  | /** @deprecate */ | 
| 439 |  |  | int isError = 0; | 
| 440 |  |  | initFortranFF( &fInfo_.SIM_uses_RF , &isError ); | 
| 441 |  |  | if(isError){ | 
| 442 |  |  | sprintf( painCave.errMsg, | 
| 443 |  |  | "ForceField error: There was an error initializing the forceField in fortran.\n" ); | 
| 444 |  |  | painCave.isFatal = 1; | 
| 445 |  |  | simError(); | 
| 446 |  |  | } | 
| 447 | gezelter | 2 |  | 
| 448 | gezelter | 246 |  | 
| 449 |  |  | setupCutoff(); | 
| 450 | gezelter | 2 |  | 
| 451 | gezelter | 246 | calcNdf(); | 
| 452 |  |  | calcNdfRaw(); | 
| 453 |  |  | calcNdfTrans(); | 
| 454 |  |  |  | 
| 455 |  |  | fortranInitialized_ = true; | 
| 456 | gezelter | 2 | } | 
| 457 |  |  |  | 
| 458 | gezelter | 246 | std::set<AtomType*> SimInfo::getUniqueAtomTypes() { | 
| 459 |  |  | SimInfo::MoleculeIterator mi; | 
| 460 |  |  | Molecule* mol; | 
| 461 |  |  | Molecule::AtomIterator ai; | 
| 462 |  |  | Atom* atom; | 
| 463 |  |  | std::set<AtomType*> atomTypes; | 
| 464 | gezelter | 2 |  | 
| 465 | gezelter | 246 | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | 
| 466 | gezelter | 2 |  | 
| 467 | gezelter | 246 | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 468 |  |  | atomTypes.insert(atom->getAtomType()); | 
| 469 |  |  | } | 
| 470 |  |  |  | 
| 471 |  |  | } | 
| 472 | gezelter | 2 |  | 
| 473 | gezelter | 246 | return atomTypes; | 
| 474 |  |  | } | 
| 475 | gezelter | 2 |  | 
| 476 | gezelter | 246 | void SimInfo::setupSimType() { | 
| 477 |  |  | std::set<AtomType*>::iterator i; | 
| 478 |  |  | std::set<AtomType*> atomTypes; | 
| 479 |  |  | atomTypes = getUniqueAtomTypes(); | 
| 480 | gezelter | 2 |  | 
| 481 | gezelter | 246 | int useLennardJones = 0; | 
| 482 |  |  | int useElectrostatic = 0; | 
| 483 |  |  | int useEAM = 0; | 
| 484 |  |  | int useCharge = 0; | 
| 485 |  |  | int useDirectional = 0; | 
| 486 |  |  | int useDipole = 0; | 
| 487 |  |  | int useGayBerne = 0; | 
| 488 |  |  | int useSticky = 0; | 
| 489 |  |  | int useShape = 0; | 
| 490 |  |  | int useFLARB = 0; //it is not in AtomType yet | 
| 491 |  |  | int useDirectionalAtom = 0; | 
| 492 |  |  | int useElectrostatics = 0; | 
| 493 |  |  | //usePBC and useRF are from simParams | 
| 494 |  |  | int usePBC = simParams_->getPBC(); | 
| 495 |  |  | int useRF = simParams_->getUseRF(); | 
| 496 | gezelter | 2 |  | 
| 497 | gezelter | 246 | //loop over all of the atom types | 
| 498 |  |  | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { | 
| 499 |  |  | useLennardJones |= (*i)->isLennardJones(); | 
| 500 |  |  | useElectrostatic |= (*i)->isElectrostatic(); | 
| 501 |  |  | useEAM |= (*i)->isEAM(); | 
| 502 |  |  | useCharge |= (*i)->isCharge(); | 
| 503 |  |  | useDirectional |= (*i)->isDirectional(); | 
| 504 |  |  | useDipole |= (*i)->isDipole(); | 
| 505 |  |  | useGayBerne |= (*i)->isGayBerne(); | 
| 506 |  |  | useSticky |= (*i)->isSticky(); | 
| 507 |  |  | useShape |= (*i)->isShape(); | 
| 508 |  |  | } | 
| 509 | gezelter | 2 |  | 
| 510 | gezelter | 246 | if (useSticky || useDipole || useGayBerne || useShape) { | 
| 511 |  |  | useDirectionalAtom = 1; | 
| 512 |  |  | } | 
| 513 | gezelter | 2 |  | 
| 514 | gezelter | 246 | if (useCharge || useDipole) { | 
| 515 |  |  | useElectrostatics = 1; | 
| 516 |  |  | } | 
| 517 | gezelter | 2 |  | 
| 518 | gezelter | 246 | #ifdef IS_MPI | 
| 519 |  |  | int temp; | 
| 520 | gezelter | 2 |  | 
| 521 | gezelter | 246 | temp = usePBC; | 
| 522 |  |  | MPI_Allreduce(&temp, &usePBC, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 523 | gezelter | 2 |  | 
| 524 | gezelter | 246 | temp = useDirectionalAtom; | 
| 525 |  |  | MPI_Allreduce(&temp, &useDirectionalAtom, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 526 | gezelter | 2 |  | 
| 527 | gezelter | 246 | temp = useLennardJones; | 
| 528 |  |  | MPI_Allreduce(&temp, &useLennardJones, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 529 | gezelter | 2 |  | 
| 530 | gezelter | 246 | temp = useElectrostatics; | 
| 531 |  |  | MPI_Allreduce(&temp, &useElectrostatics, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 532 | gezelter | 2 |  | 
| 533 | gezelter | 246 | temp = useCharge; | 
| 534 |  |  | MPI_Allreduce(&temp, &useCharge, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 535 | gezelter | 2 |  | 
| 536 | gezelter | 246 | temp = useDipole; | 
| 537 |  |  | MPI_Allreduce(&temp, &useDipole, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 538 | gezelter | 2 |  | 
| 539 | gezelter | 246 | temp = useSticky; | 
| 540 |  |  | MPI_Allreduce(&temp, &useSticky, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 541 | gezelter | 2 |  | 
| 542 | gezelter | 246 | temp = useGayBerne; | 
| 543 |  |  | MPI_Allreduce(&temp, &useGayBerne, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 544 | gezelter | 2 |  | 
| 545 | gezelter | 246 | temp = useEAM; | 
| 546 |  |  | MPI_Allreduce(&temp, &useEAM, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 547 | gezelter | 2 |  | 
| 548 | gezelter | 246 | temp = useShape; | 
| 549 |  |  | MPI_Allreduce(&temp, &useShape, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 550 |  |  |  | 
| 551 |  |  | temp = useFLARB; | 
| 552 |  |  | MPI_Allreduce(&temp, &useFLARB, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 553 |  |  |  | 
| 554 |  |  | temp = useRF; | 
| 555 |  |  | MPI_Allreduce(&temp, &useRF, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); | 
| 556 |  |  |  | 
| 557 | gezelter | 2 | #endif | 
| 558 |  |  |  | 
| 559 | gezelter | 246 | fInfo_.SIM_uses_PBC = usePBC; | 
| 560 |  |  | fInfo_.SIM_uses_DirectionalAtoms = useDirectionalAtom; | 
| 561 |  |  | fInfo_.SIM_uses_LennardJones = useLennardJones; | 
| 562 |  |  | fInfo_.SIM_uses_Electrostatics = useElectrostatics; | 
| 563 |  |  | fInfo_.SIM_uses_Charges = useCharge; | 
| 564 |  |  | fInfo_.SIM_uses_Dipoles = useDipole; | 
| 565 |  |  | fInfo_.SIM_uses_Sticky = useSticky; | 
| 566 |  |  | fInfo_.SIM_uses_GayBerne = useGayBerne; | 
| 567 |  |  | fInfo_.SIM_uses_EAM = useEAM; | 
| 568 |  |  | fInfo_.SIM_uses_Shapes = useShape; | 
| 569 |  |  | fInfo_.SIM_uses_FLARB = useFLARB; | 
| 570 |  |  | fInfo_.SIM_uses_RF = useRF; | 
| 571 | gezelter | 2 |  | 
| 572 | gezelter | 246 | if( fInfo_.SIM_uses_Dipoles && fInfo_.SIM_uses_RF) { | 
| 573 | gezelter | 2 |  | 
| 574 | gezelter | 246 | if (simParams_->haveDielectric()) { | 
| 575 |  |  | fInfo_.dielect = simParams_->getDielectric(); | 
| 576 |  |  | } else { | 
| 577 |  |  | sprintf(painCave.errMsg, | 
| 578 |  |  | "SimSetup Error: No Dielectric constant was set.\n" | 
| 579 |  |  | "\tYou are trying to use Reaction Field without" | 
| 580 |  |  | "\tsetting a dielectric constant!\n"); | 
| 581 |  |  | painCave.isFatal = 1; | 
| 582 |  |  | simError(); | 
| 583 |  |  | } | 
| 584 |  |  |  | 
| 585 |  |  | } else { | 
| 586 |  |  | fInfo_.dielect = 0.0; | 
| 587 |  |  | } | 
| 588 |  |  |  | 
| 589 | gezelter | 2 | } | 
| 590 |  |  |  | 
| 591 | gezelter | 246 | void SimInfo::setupFortranSim() { | 
| 592 |  |  | int isError; | 
| 593 |  |  | int nExclude; | 
| 594 |  |  | std::vector<int> fortranGlobalGroupMembership; | 
| 595 |  |  |  | 
| 596 |  |  | nExclude = exclude_.getSize(); | 
| 597 |  |  | isError = 0; | 
| 598 | gezelter | 2 |  | 
| 599 | gezelter | 246 | //globalGroupMembership_ is filled by SimCreator | 
| 600 |  |  | for (int i = 0; i < nGlobalAtoms_; i++) { | 
| 601 |  |  | fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1); | 
| 602 |  |  | } | 
| 603 | gezelter | 2 |  | 
| 604 | gezelter | 246 | //calculate mass ratio of cutoff group | 
| 605 |  |  | std::vector<double> mfact; | 
| 606 |  |  | SimInfo::MoleculeIterator mi; | 
| 607 |  |  | Molecule* mol; | 
| 608 |  |  | Molecule::CutoffGroupIterator ci; | 
| 609 |  |  | CutoffGroup* cg; | 
| 610 |  |  | Molecule::AtomIterator ai; | 
| 611 |  |  | Atom* atom; | 
| 612 |  |  | double totalMass; | 
| 613 |  |  |  | 
| 614 |  |  | //to avoid memory reallocation, reserve enough space for mfact | 
| 615 |  |  | mfact.reserve(getNCutoffGroups()); | 
| 616 | gezelter | 2 |  | 
| 617 | gezelter | 246 | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | 
| 618 |  |  | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { | 
| 619 | gezelter | 2 |  | 
| 620 | gezelter | 246 | totalMass = cg->getMass(); | 
| 621 |  |  | for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { | 
| 622 |  |  | mfact.push_back(atom->getMass()/totalMass); | 
| 623 |  |  | } | 
| 624 | gezelter | 2 |  | 
| 625 | gezelter | 246 | } | 
| 626 |  |  | } | 
| 627 | gezelter | 2 |  | 
| 628 | gezelter | 246 | //fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!) | 
| 629 |  |  | std::vector<int> identArray; | 
| 630 | gezelter | 2 |  | 
| 631 | gezelter | 246 | //to avoid memory reallocation, reserve enough space identArray | 
| 632 |  |  | identArray.reserve(getNAtoms()); | 
| 633 |  |  |  | 
| 634 |  |  | for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | 
| 635 |  |  | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 636 |  |  | identArray.push_back(atom->getIdent()); | 
| 637 |  |  | } | 
| 638 |  |  | } | 
| 639 | gezelter | 2 |  | 
| 640 | gezelter | 246 | //fill molMembershipArray | 
| 641 |  |  | //molMembershipArray is filled by SimCreator | 
| 642 |  |  | std::vector<int> molMembershipArray(nGlobalAtoms_); | 
| 643 |  |  | for (int i = 0; i < nGlobalAtoms_; i++) { | 
| 644 |  |  | molMembershipArray[i] = globalMolMembership_[i] + 1; | 
| 645 |  |  | } | 
| 646 |  |  |  | 
| 647 |  |  | //setup fortran simulation | 
| 648 |  |  | //gloalExcludes and molMembershipArray should go away (They are never used) | 
| 649 |  |  | //why the hell fortran need to know molecule? | 
| 650 |  |  | //OOPSE = Object-Obfuscated Parallel Simulation Engine | 
| 651 |  |  | int nGlobalExcludes = 0; | 
| 652 |  |  | int* globalExcludes = NULL; | 
| 653 |  |  | int* excludeList = exclude_.getExcludeList(); | 
| 654 |  |  | setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], &nExclude, excludeList , | 
| 655 |  |  | &nGlobalExcludes, globalExcludes, &molMembershipArray[0], | 
| 656 |  |  | &mfact[0], &nCutoffGroups_, &fortranGlobalGroupMembership[0], &isError); | 
| 657 | gezelter | 2 |  | 
| 658 | gezelter | 246 | if( isError ){ | 
| 659 | gezelter | 2 |  | 
| 660 | gezelter | 246 | sprintf( painCave.errMsg, | 
| 661 |  |  | "There was an error setting the simulation information in fortran.\n" ); | 
| 662 |  |  | painCave.isFatal = 1; | 
| 663 |  |  | painCave.severity = OOPSE_ERROR; | 
| 664 |  |  | simError(); | 
| 665 |  |  | } | 
| 666 |  |  |  | 
| 667 |  |  | #ifdef IS_MPI | 
| 668 |  |  | sprintf( checkPointMsg, | 
| 669 |  |  | "succesfully sent the simulation information to fortran.\n"); | 
| 670 |  |  | MPIcheckPoint(); | 
| 671 |  |  | #endif // is_mpi | 
| 672 | gezelter | 2 | } | 
| 673 |  |  |  | 
| 674 |  |  |  | 
| 675 | gezelter | 246 | #ifdef IS_MPI | 
| 676 |  |  | void SimInfo::setupFortranParallel() { | 
| 677 |  |  |  | 
| 678 |  |  | //SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex | 
| 679 |  |  | std::vector<int> localToGlobalAtomIndex(getNAtoms(), 0); | 
| 680 |  |  | std::vector<int> localToGlobalCutoffGroupIndex; | 
| 681 |  |  | SimInfo::MoleculeIterator mi; | 
| 682 |  |  | Molecule::AtomIterator ai; | 
| 683 |  |  | Molecule::CutoffGroupIterator ci; | 
| 684 |  |  | Molecule* mol; | 
| 685 |  |  | Atom* atom; | 
| 686 |  |  | CutoffGroup* cg; | 
| 687 |  |  | mpiSimData parallelData; | 
| 688 |  |  | int isError; | 
| 689 | gezelter | 2 |  | 
| 690 | gezelter | 246 | for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) { | 
| 691 | gezelter | 2 |  | 
| 692 | gezelter | 246 | //local index(index in DataStorge) of atom is important | 
| 693 |  |  | for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 694 |  |  | localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1; | 
| 695 |  |  | } | 
| 696 | gezelter | 2 |  | 
| 697 | gezelter | 246 | //local index of cutoff group is trivial, it only depends on the order of travesing | 
| 698 |  |  | for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { | 
| 699 |  |  | localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1); | 
| 700 |  |  | } | 
| 701 |  |  |  | 
| 702 |  |  | } | 
| 703 | gezelter | 2 |  | 
| 704 | gezelter | 246 | //fill up mpiSimData struct | 
| 705 |  |  | parallelData.nMolGlobal = getNGlobalMolecules(); | 
| 706 |  |  | parallelData.nMolLocal = getNMolecules(); | 
| 707 |  |  | parallelData.nAtomsGlobal = getNGlobalAtoms(); | 
| 708 |  |  | parallelData.nAtomsLocal = getNAtoms(); | 
| 709 |  |  | parallelData.nGroupsGlobal = getNGlobalCutoffGroups(); | 
| 710 |  |  | parallelData.nGroupsLocal = getNCutoffGroups(); | 
| 711 |  |  | parallelData.myNode = worldRank; | 
| 712 |  |  | MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors)); | 
| 713 | gezelter | 2 |  | 
| 714 | gezelter | 246 | //pass mpiSimData struct and index arrays to fortran | 
| 715 |  |  | setFsimParallel(¶llelData, &(parallelData.nAtomsLocal), | 
| 716 |  |  | &localToGlobalAtomIndex[0],  &(parallelData.nGroupsLocal), | 
| 717 |  |  | &localToGlobalCutoffGroupIndex[0], &isError); | 
| 718 | gezelter | 2 |  | 
| 719 | gezelter | 246 | if (isError) { | 
| 720 |  |  | sprintf(painCave.errMsg, | 
| 721 |  |  | "mpiRefresh errror: fortran didn't like something we gave it.\n"); | 
| 722 |  |  | painCave.isFatal = 1; | 
| 723 |  |  | simError(); | 
| 724 |  |  | } | 
| 725 | gezelter | 2 |  | 
| 726 | gezelter | 246 | sprintf(checkPointMsg, " mpiRefresh successful.\n"); | 
| 727 |  |  | MPIcheckPoint(); | 
| 728 | gezelter | 2 |  | 
| 729 |  |  |  | 
| 730 | gezelter | 246 | } | 
| 731 | chrisfen | 143 |  | 
| 732 | gezelter | 246 | #endif | 
| 733 | chrisfen | 143 |  | 
| 734 | gezelter | 246 | double SimInfo::calcMaxCutoffRadius() { | 
| 735 | chrisfen | 143 |  | 
| 736 |  |  |  | 
| 737 | gezelter | 246 | std::set<AtomType*> atomTypes; | 
| 738 |  |  | std::set<AtomType*>::iterator i; | 
| 739 |  |  | std::vector<double> cutoffRadius; | 
| 740 | gezelter | 2 |  | 
| 741 | gezelter | 246 | //get the unique atom types | 
| 742 |  |  | atomTypes = getUniqueAtomTypes(); | 
| 743 |  |  |  | 
| 744 |  |  | //query the max cutoff radius among these atom types | 
| 745 |  |  | for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { | 
| 746 |  |  | cutoffRadius.push_back(forceField_->getRcutFromAtomType(*i)); | 
| 747 |  |  | } | 
| 748 |  |  |  | 
| 749 |  |  | double maxCutoffRadius = *(std::max_element(cutoffRadius.begin(), cutoffRadius.end())); | 
| 750 | gezelter | 2 | #ifdef IS_MPI | 
| 751 | gezelter | 246 | //pick the max cutoff radius among the processors | 
| 752 | gezelter | 2 | #endif | 
| 753 |  |  |  | 
| 754 | gezelter | 246 | return maxCutoffRadius; | 
| 755 |  |  | } | 
| 756 |  |  |  | 
| 757 |  |  | void SimInfo::setupCutoff() { | 
| 758 |  |  | double rcut_;  //cutoff radius | 
| 759 |  |  | double rsw_; //switching radius | 
| 760 | gezelter | 2 |  | 
| 761 | gezelter | 246 | if (fInfo_.SIM_uses_Charges | fInfo_.SIM_uses_Dipoles | fInfo_.SIM_uses_RF) { | 
| 762 |  |  |  | 
| 763 |  |  | if (!simParams_->haveRcut()){ | 
| 764 |  |  | sprintf(painCave.errMsg, | 
| 765 |  |  | "SimCreator Warning: No value was set for the cutoffRadius.\n" | 
| 766 |  |  | "\tOOPSE will use a default value of 15.0 angstroms" | 
| 767 |  |  | "\tfor the cutoffRadius.\n"); | 
| 768 |  |  | painCave.isFatal = 0; | 
| 769 |  |  | simError(); | 
| 770 |  |  | rcut_ = 15.0; | 
| 771 |  |  | } else{ | 
| 772 |  |  | rcut_ = simParams_->getRcut(); | 
| 773 |  |  | } | 
| 774 |  |  |  | 
| 775 |  |  | if (!simParams_->haveRsw()){ | 
| 776 |  |  | sprintf(painCave.errMsg, | 
| 777 |  |  | "SimCreator Warning: No value was set for switchingRadius.\n" | 
| 778 |  |  | "\tOOPSE will use a default value of\n" | 
| 779 |  |  | "\t0.95 * cutoffRadius for the switchingRadius\n"); | 
| 780 |  |  | painCave.isFatal = 0; | 
| 781 |  |  | simError(); | 
| 782 |  |  | rsw_ = 0.95 * rcut_; | 
| 783 |  |  | } else{ | 
| 784 |  |  | rsw_ = simParams_->getRsw(); | 
| 785 |  |  | } | 
| 786 |  |  |  | 
| 787 |  |  | } else { | 
| 788 |  |  | // if charge, dipole or reaction field is not used and the cutofff radius is not specified in | 
| 789 |  |  | //meta-data file, the maximum cutoff radius calculated from forcefiled will be used | 
| 790 |  |  |  | 
| 791 |  |  | if (simParams_->haveRcut()) { | 
| 792 |  |  | rcut_ = simParams_->getRcut(); | 
| 793 |  |  | } else { | 
| 794 |  |  | //set cutoff radius to the maximum cutoff radius based on atom types in the whole system | 
| 795 |  |  | rcut_ = calcMaxCutoffRadius(); | 
| 796 |  |  | } | 
| 797 |  |  |  | 
| 798 |  |  | if (simParams_->haveRsw()) { | 
| 799 |  |  | rsw_  = simParams_->getRsw(); | 
| 800 |  |  | } else { | 
| 801 |  |  | rsw_ = rcut_; | 
| 802 |  |  | } | 
| 803 |  |  |  | 
| 804 |  |  | } | 
| 805 |  |  |  | 
| 806 |  |  | double rnblist = rcut_ + 1; // skin of neighbor list | 
| 807 |  |  |  | 
| 808 |  |  | //Pass these cutoff radius etc. to fortran. This function should be called once and only once | 
| 809 |  |  | notifyFortranCutoffs(&rcut_, &rsw_, &rnblist); | 
| 810 | gezelter | 2 | } | 
| 811 |  |  |  | 
| 812 | gezelter | 246 | void SimInfo::addProperty(GenericData* genData) { | 
| 813 |  |  | properties_.addProperty(genData); | 
| 814 | gezelter | 2 | } | 
| 815 |  |  |  | 
| 816 | gezelter | 246 | void SimInfo::removeProperty(const std::string& propName) { | 
| 817 |  |  | properties_.removeProperty(propName); | 
| 818 |  |  | } | 
| 819 | gezelter | 2 |  | 
| 820 | gezelter | 246 | void SimInfo::clearProperties() { | 
| 821 |  |  | properties_.clearProperties(); | 
| 822 | gezelter | 2 | } | 
| 823 |  |  |  | 
| 824 | gezelter | 246 | std::vector<std::string> SimInfo::getPropertyNames() { | 
| 825 |  |  | return properties_.getPropertyNames(); | 
| 826 |  |  | } | 
| 827 |  |  |  | 
| 828 |  |  | std::vector<GenericData*> SimInfo::getProperties() { | 
| 829 |  |  | return properties_.getProperties(); | 
| 830 |  |  | } | 
| 831 | gezelter | 2 |  | 
| 832 | gezelter | 246 | GenericData* SimInfo::getPropertyByName(const std::string& propName) { | 
| 833 |  |  | return properties_.getPropertyByName(propName); | 
| 834 | gezelter | 2 | } | 
| 835 |  |  |  | 
| 836 | gezelter | 246 | void SimInfo::setSnapshotManager(SnapshotManager* sman) { | 
| 837 |  |  | sman_ = sman; | 
| 838 | gezelter | 2 |  | 
| 839 | gezelter | 246 | Molecule* mol; | 
| 840 |  |  | RigidBody* rb; | 
| 841 |  |  | Atom* atom; | 
| 842 |  |  | SimInfo::MoleculeIterator mi; | 
| 843 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 844 |  |  | Molecule::AtomIterator atomIter;; | 
| 845 |  |  |  | 
| 846 |  |  | for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { | 
| 847 |  |  |  | 
| 848 |  |  | for (atom = mol->beginAtom(atomIter); atom != NULL; atom = mol->nextAtom(atomIter)) { | 
| 849 |  |  | atom->setSnapshotManager(sman_); | 
| 850 |  |  | } | 
| 851 |  |  |  | 
| 852 |  |  | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 853 |  |  | rb->setSnapshotManager(sman_); | 
| 854 |  |  | } | 
| 855 |  |  | } | 
| 856 | gezelter | 2 |  | 
| 857 | gezelter | 246 | } | 
| 858 | gezelter | 2 |  | 
| 859 | gezelter | 246 | Vector3d SimInfo::getComVel(){ | 
| 860 |  |  | SimInfo::MoleculeIterator i; | 
| 861 |  |  | Molecule* mol; | 
| 862 | gezelter | 2 |  | 
| 863 | gezelter | 246 | Vector3d comVel(0.0); | 
| 864 |  |  | double totalMass = 0.0; | 
| 865 | gezelter | 2 |  | 
| 866 | gezelter | 246 |  | 
| 867 |  |  | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 868 |  |  | double mass = mol->getMass(); | 
| 869 |  |  | totalMass += mass; | 
| 870 |  |  | comVel += mass * mol->getComVel(); | 
| 871 |  |  | } | 
| 872 | gezelter | 2 |  | 
| 873 | gezelter | 246 | #ifdef IS_MPI | 
| 874 |  |  | double tmpMass = totalMass; | 
| 875 |  |  | Vector3d tmpComVel(comVel); | 
| 876 |  |  | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 877 |  |  | MPI_Allreduce(tmpComVel.getArrayPointer(), comVel.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 878 |  |  | #endif | 
| 879 |  |  |  | 
| 880 |  |  | comVel /= totalMass; | 
| 881 |  |  |  | 
| 882 |  |  | return comVel; | 
| 883 | gezelter | 2 | } | 
| 884 |  |  |  | 
| 885 | gezelter | 246 | Vector3d SimInfo::getCom(){ | 
| 886 |  |  | SimInfo::MoleculeIterator i; | 
| 887 |  |  | Molecule* mol; | 
| 888 | gezelter | 2 |  | 
| 889 | gezelter | 246 | Vector3d com(0.0); | 
| 890 |  |  | double totalMass = 0.0; | 
| 891 |  |  |  | 
| 892 |  |  | for (mol = beginMolecule(i); mol != NULL; mol = nextMolecule(i)) { | 
| 893 |  |  | double mass = mol->getMass(); | 
| 894 |  |  | totalMass += mass; | 
| 895 |  |  | com += mass * mol->getCom(); | 
| 896 |  |  | } | 
| 897 | gezelter | 2 |  | 
| 898 |  |  | #ifdef IS_MPI | 
| 899 | gezelter | 246 | double tmpMass = totalMass; | 
| 900 |  |  | Vector3d tmpCom(com); | 
| 901 |  |  | MPI_Allreduce(&tmpMass,&totalMass,1,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 902 |  |  | MPI_Allreduce(tmpCom.getArrayPointer(), com.getArrayPointer(),3,MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); | 
| 903 | gezelter | 2 | #endif | 
| 904 |  |  |  | 
| 905 | gezelter | 246 | com /= totalMass; | 
| 906 | gezelter | 2 |  | 
| 907 | gezelter | 246 | return com; | 
| 908 | gezelter | 2 |  | 
| 909 | gezelter | 246 | } | 
| 910 |  |  |  | 
| 911 |  |  | std::ostream& operator <<(std::ostream& o, SimInfo& info) { | 
| 912 |  |  |  | 
| 913 |  |  | return o; | 
| 914 | gezelter | 2 | } | 
| 915 | gezelter | 246 |  | 
| 916 |  |  | }//end namespace oopse | 
| 917 |  |  |  |