ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/SimInfo.hpp
Revision: 1764
Committed: Tue Jul 3 18:32:27 2012 UTC (12 years, 9 months ago) by gezelter
File size: 23141 byte(s)
Log Message:
Refactored Snapshot and Stats to use the Accumulator classes.  Collected
a number of methods into Thermo that belonged there.

File Contents

# Content
1 /*
2 * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
28 * arising out of the use of or inability to use software, even if the
29 * University of Notre Dame has been advised of the possibility of
30 * such damages.
31 *
32 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33 * research, please cite the appropriate papers when you publish your
34 * work. Good starting points are:
35 *
36 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 */
42
43 /**
44 * @file SimInfo.hpp
45 * @author tlin
46 * @date 11/02/2004
47 * @version 1.0
48 */
49
50 #ifndef BRAINS_SIMMODEL_HPP
51 #define BRAINS_SIMMODEL_HPP
52
53 #include <iostream>
54 #include <set>
55 #include <utility>
56 #include <vector>
57
58 #include "brains/PairList.hpp"
59 #include "io/Globals.hpp"
60 #include "math/Vector3.hpp"
61 #include "math/SquareMatrix3.hpp"
62 #include "types/MoleculeStamp.hpp"
63 #include "brains/ForceField.hpp"
64 #include "utils/PropertyMap.hpp"
65 #include "utils/LocalIndexManager.hpp"
66 #include "nonbonded/SwitchingFunction.hpp"
67
68 using namespace std;
69 namespace OpenMD{
70 //forward declaration
71 class SnapshotManager;
72 class Molecule;
73 class SelectionManager;
74 class StuntDouble;
75
76 /**
77 * @class SimInfo SimInfo.hpp "brains/SimInfo.hpp"
78 *
79 * @brief One of the heavy-weight classes of OpenMD, SimInfo
80 * maintains objects and variables relating to the current
81 * simulation. This includes the master list of Molecules. The
82 * Molecule class maintains all of the concrete objects (Atoms,
83 * Bond, Bend, Torsions, Inversions, RigidBodies, CutoffGroups,
84 * Constraints). In both the single and parallel versions, Atoms and
85 * RigidBodies have both global and local indices.
86 */
87 class SimInfo {
88 public:
89 typedef map<int, Molecule*>::iterator MoleculeIterator;
90
91 /**
92 * Constructor of SimInfo
93 *
94 * @param molStampPairs MoleculeStamp Array. The first element of
95 * the pair is molecule stamp, the second element is the total
96 * number of molecules with the same molecule stamp in the system
97 *
98 * @param ff pointer of a concrete ForceField instance
99 *
100 * @param simParams
101 */
102 SimInfo(ForceField* ff, Globals* simParams);
103 virtual ~SimInfo();
104
105 /**
106 * Adds a molecule
107 *
108 * @return return true if adding successfully, return false if the
109 * molecule is already in SimInfo
110 *
111 * @param mol molecule to be added
112 */
113 bool addMolecule(Molecule* mol);
114
115 /**
116 * Removes a molecule from SimInfo
117 *
118 * @return true if removing successfully, return false if molecule
119 * is not in this SimInfo
120 */
121 bool removeMolecule(Molecule* mol);
122
123 /** Returns the total number of molecules in the system. */
124 int getNGlobalMolecules() {
125 return nGlobalMols_;
126 }
127
128 /** Returns the total number of atoms in the system. */
129 int getNGlobalAtoms() {
130 return nGlobalAtoms_;
131 }
132
133 /** Returns the total number of cutoff groups in the system. */
134 int getNGlobalCutoffGroups() {
135 return nGlobalCutoffGroups_;
136 }
137
138 /**
139 * Returns the total number of integrable objects (total number of
140 * rigid bodies plus the total number of atoms which do not belong
141 * to the rigid bodies) in the system
142 */
143 int getNGlobalIntegrableObjects() {
144 return nGlobalIntegrableObjects_;
145 }
146
147 /**
148 * Returns the total number of integrable objects (total number of
149 * rigid bodies plus the total number of atoms which do not belong
150 * to the rigid bodies) in the system
151 */
152 int getNGlobalRigidBodies() {
153 return nGlobalRigidBodies_;
154 }
155
156 int getNGlobalConstraints();
157 /**
158 * Returns the number of local molecules.
159 * @return the number of local molecules
160 */
161 int getNMolecules() {
162 return molecules_.size();
163 }
164
165 /** Returns the number of local atoms */
166 unsigned int getNAtoms() {
167 return nAtoms_;
168 }
169
170 /** Returns the number of effective cutoff groups on local processor */
171 unsigned int getNLocalCutoffGroups();
172
173 /** Returns the number of local bonds */
174 unsigned int getNBonds(){
175 return nBonds_;
176 }
177
178 /** Returns the number of local bends */
179 unsigned int getNBends() {
180 return nBends_;
181 }
182
183 /** Returns the number of local torsions */
184 unsigned int getNTorsions() {
185 return nTorsions_;
186 }
187
188 /** Returns the number of local torsions */
189 unsigned int getNInversions() {
190 return nInversions_;
191 }
192 /** Returns the number of local rigid bodies */
193 unsigned int getNRigidBodies() {
194 return nRigidBodies_;
195 }
196
197 /** Returns the number of local integrable objects */
198 unsigned int getNIntegrableObjects() {
199 return nIntegrableObjects_;
200 }
201
202 /** Returns the number of local cutoff groups */
203 unsigned int getNCutoffGroups() {
204 return nCutoffGroups_;
205 }
206
207 /** Returns the total number of constraints in this SimInfo */
208 unsigned int getNConstraints() {
209 return nConstraints_;
210 }
211
212 /**
213 * Returns the first molecule in this SimInfo and intialize the iterator.
214 * @return the first molecule, return NULL if there is not molecule in this SimInfo
215 * @param i the iterator of molecule array (user shouldn't change it)
216 */
217 Molecule* beginMolecule(MoleculeIterator& i);
218
219 /**
220 * Returns the next avaliable Molecule based on the iterator.
221 * @return the next avaliable molecule, return NULL if reaching the end of the array
222 * @param i the iterator of molecule array
223 */
224 Molecule* nextMolecule(MoleculeIterator& i);
225
226 /** Returns the total number of fluctuating charges that are present */
227 int getNFluctuatingCharges() {
228 return nGlobalFluctuatingCharges_;
229 }
230
231 /** Returns the number of degrees of freedom */
232 int getNdf() {
233 return ndf_ - getFdf();
234 }
235
236 /** Returns the number of degrees of freedom (LOCAL) */
237 int getNdfLocal() {
238 return ndfLocal_;
239 }
240
241 /** Returns the number of raw degrees of freedom */
242 int getNdfRaw() {
243 return ndfRaw_;
244 }
245
246 /** Returns the number of translational degrees of freedom */
247 int getNdfTrans() {
248 return ndfTrans_;
249 }
250
251 /** sets the current number of frozen degrees of freedom */
252 void setFdf(int fdf) {
253 fdf_local = fdf;
254 }
255
256 int getFdf();
257
258 //getNZconstraint and setNZconstraint ruin the coherence of
259 //SimInfo class, need refactoring
260
261 /** Returns the total number of z-constraint molecules in the system */
262 int getNZconstraint() {
263 return nZconstraint_;
264 }
265
266 /**
267 * Sets the number of z-constraint molecules in the system.
268 */
269 void setNZconstraint(int nZconstraint) {
270 nZconstraint_ = nZconstraint;
271 }
272
273 /** Returns the snapshot manager. */
274 SnapshotManager* getSnapshotManager() {
275 return sman_;
276 }
277
278 /** Sets the snapshot manager. */
279 void setSnapshotManager(SnapshotManager* sman);
280
281 /** Returns the force field */
282 ForceField* getForceField() {
283 return forceField_;
284 }
285
286 Globals* getSimParams() {
287 return simParams_;
288 }
289
290 void update();
291 /**
292 * Do final bookkeeping before Force managers need their data.
293 */
294 void prepareTopology();
295
296
297 /** Returns the local index manager */
298 LocalIndexManager* getLocalIndexManager() {
299 return &localIndexMan_;
300 }
301
302 int getMoleculeStampId(int globalIndex) {
303 //assert(globalIndex < molStampIds_.size())
304 return molStampIds_[globalIndex];
305 }
306
307 /** Returns the molecule stamp */
308 MoleculeStamp* getMoleculeStamp(int id) {
309 return moleculeStamps_[id];
310 }
311
312 /** Return the total number of the molecule stamps */
313 int getNMoleculeStamp() {
314 return moleculeStamps_.size();
315 }
316 /**
317 * Finds a molecule with a specified global index
318 * @return a pointer point to found molecule
319 * @param index
320 */
321 Molecule* getMoleculeByGlobalIndex(int index) {
322 MoleculeIterator i;
323 i = molecules_.find(index);
324
325 return i != molecules_.end() ? i->second : NULL;
326 }
327
328 int getGlobalMolMembership(int id){
329 return globalMolMembership_[id];
330 }
331
332 /**
333 * returns a vector which maps the local atom index on this
334 * processor to the global atom index. With only one processor,
335 * these should be identical.
336 */
337 vector<int> getGlobalAtomIndices();
338
339 /**
340 * returns a vector which maps the local cutoff group index on
341 * this processor to the global cutoff group index. With only one
342 * processor, these should be identical.
343 */
344 vector<int> getGlobalGroupIndices();
345
346
347 string getFinalConfigFileName() {
348 return finalConfigFileName_;
349 }
350
351 void setFinalConfigFileName(const string& fileName) {
352 finalConfigFileName_ = fileName;
353 }
354
355 string getRawMetaData() {
356 return rawMetaData_;
357 }
358 void setRawMetaData(const string& rawMetaData) {
359 rawMetaData_ = rawMetaData;
360 }
361
362 string getDumpFileName() {
363 return dumpFileName_;
364 }
365
366 void setDumpFileName(const string& fileName) {
367 dumpFileName_ = fileName;
368 }
369
370 string getStatFileName() {
371 return statFileName_;
372 }
373
374 void setStatFileName(const string& fileName) {
375 statFileName_ = fileName;
376 }
377
378 string getRestFileName() {
379 return restFileName_;
380 }
381
382 void setRestFileName(const string& fileName) {
383 restFileName_ = fileName;
384 }
385
386 /**
387 * Sets GlobalGroupMembership
388 * @see #SimCreator::setGlobalIndex
389 */
390 void setGlobalGroupMembership(const vector<int>& globalGroupMembership) {
391 assert(globalGroupMembership.size() == static_cast<size_t>(nGlobalAtoms_));
392 globalGroupMembership_ = globalGroupMembership;
393 }
394
395 /**
396 * Sets GlobalMolMembership
397 * @see #SimCreator::setGlobalIndex
398 */
399 void setGlobalMolMembership(const vector<int>& globalMolMembership) {
400 assert(globalMolMembership.size() == static_cast<size_t>(nGlobalAtoms_));
401 globalMolMembership_ = globalMolMembership;
402 }
403
404
405 bool isTopologyDone() {
406 return topologyDone_;
407 }
408
409 bool getCalcBoxDipole() {
410 return calcBoxDipole_;
411 }
412
413 bool getUseAtomicVirial() {
414 return useAtomicVirial_;
415 }
416
417 /**
418 * Adds property into property map
419 * @param genData GenericData to be added into PropertyMap
420 */
421 void addProperty(GenericData* genData);
422
423 /**
424 * Removes property from PropertyMap by name
425 * @param propName the name of property to be removed
426 */
427 void removeProperty(const string& propName);
428
429 /**
430 * clear all of the properties
431 */
432 void clearProperties();
433
434 /**
435 * Returns all names of properties
436 * @return all names of properties
437 */
438 vector<string> getPropertyNames();
439
440 /**
441 * Returns all of the properties in PropertyMap
442 * @return all of the properties in PropertyMap
443 */
444 vector<GenericData*> getProperties();
445
446 /**
447 * Returns property
448 * @param propName name of property
449 * @return a pointer point to property with propName. If no property named propName
450 * exists, return NULL
451 */
452 GenericData* getPropertyByName(const string& propName);
453
454 /**
455 * add all special interaction pairs (including excluded
456 * interactions) in a molecule into the appropriate lists.
457 */
458 void addInteractionPairs(Molecule* mol);
459
460 /**
461 * remove all special interaction pairs which belong to a molecule
462 * from the appropriate lists.
463 */
464 void removeInteractionPairs(Molecule* mol);
465
466 /** Returns the set of atom types present in this simulation */
467 set<AtomType*> getSimulatedAtomTypes();
468
469 friend ostream& operator <<(ostream& o, SimInfo& info);
470
471 void getCutoff(RealType& rcut, RealType& rsw);
472
473 private:
474
475 /** fill up the simtype struct and other simulation-related variables */
476 void setupSimVariables();
477
478
479 /** Determine if we need to accumulate the simulation box dipole */
480 void setupAccumulateBoxDipole();
481
482 /** Calculates the number of degress of freedom in the whole system */
483 void calcNdf();
484 void calcNdfRaw();
485 void calcNdfTrans();
486
487 /**
488 * Adds molecule stamp and the total number of the molecule with
489 * same molecule stamp in the whole system.
490 */
491 void addMoleculeStamp(MoleculeStamp* molStamp, int nmol);
492
493 // Other classes holdingn important information
494 ForceField* forceField_; /**< provides access to defined atom types, bond types, etc. */
495 Globals* simParams_; /**< provides access to simulation parameters set by user */
496
497 /// Counts of local objects
498 int nAtoms_; /**< number of atoms in local processor */
499 int nBonds_; /**< number of bonds in local processor */
500 int nBends_; /**< number of bends in local processor */
501 int nTorsions_; /**< number of torsions in local processor */
502 int nInversions_; /**< number of inversions in local processor */
503 int nRigidBodies_; /**< number of rigid bodies in local processor */
504 int nIntegrableObjects_; /**< number of integrable objects in local processor */
505 int nCutoffGroups_; /**< number of cutoff groups in local processor */
506 int nConstraints_; /**< number of constraints in local processors */
507 int nFluctuatingCharges_; /**< number of fluctuating charges in local processor */
508
509 /// Counts of global objects
510 int nGlobalMols_; /**< number of molecules in the system (GLOBAL) */
511 int nGlobalAtoms_; /**< number of atoms in the system (GLOBAL) */
512 int nGlobalCutoffGroups_; /**< number of cutoff groups in this system (GLOBAL) */
513 int nGlobalIntegrableObjects_; /**< number of integrable objects in this system */
514 int nGlobalRigidBodies_; /**< number of rigid bodies in this system (GLOBAL) */
515 int nGlobalFluctuatingCharges_;/**< number of fluctuating charges in this system (GLOBAL) */
516
517
518 /// Degress of freedom
519 int ndf_; /**< number of degress of freedom (excludes constraints) (LOCAL) */
520 int ndfLocal_; /**< number of degrees of freedom (LOCAL, excludes constraints) */
521 int fdf_local; /**< number of frozen degrees of freedom (LOCAL) */
522 int fdf_; /**< number of frozen degrees of freedom (GLOBAL) */
523 int ndfRaw_; /**< number of degress of freedom (includes constraints), (LOCAL) */
524 int ndfTrans_; /**< number of translation degress of freedom, (LOCAL) */
525 int nZconstraint_; /**< number of z-constraint molecules (GLOBAL) */
526
527 /// logicals
528 bool usesPeriodicBoundaries_; /**< use periodic boundary conditions? */
529 bool usesDirectionalAtoms_; /**< are there atoms with position AND orientation? */
530 bool usesMetallicAtoms_; /**< are there transition metal atoms? */
531 bool usesElectrostaticAtoms_; /**< are there electrostatic atoms? */
532 bool usesFluctuatingCharges_; /**< are there fluctuating charges? */
533 bool usesAtomicVirial_; /**< are we computing atomic virials? */
534 bool requiresPrepair_; /**< does this simulation require a pre-pair loop? */
535 bool requiresSkipCorrection_; /**< does this simulation require a skip-correction? */
536 bool requiresSelfCorrection_; /**< does this simulation require a self-correction? */
537
538 public:
539 bool usesElectrostaticAtoms() { return usesElectrostaticAtoms_; }
540 bool usesDirectionalAtoms() { return usesDirectionalAtoms_; }
541 bool usesFluctuatingCharges() { return usesFluctuatingCharges_; }
542 bool usesAtomicVirial() { return usesAtomicVirial_; }
543 bool requiresPrepair() { return requiresPrepair_; }
544 bool requiresSkipCorrection() { return requiresSkipCorrection_;}
545 bool requiresSelfCorrection() { return requiresSelfCorrection_;}
546
547 private:
548 /// Data structures holding primary simulation objects
549 map<int, Molecule*> molecules_; /**< map holding pointers to LOCAL molecules */
550
551 /// Stamps are templates for objects that are then used to create
552 /// groups of objects. For example, a molecule stamp contains
553 /// information on how to build that molecule (i.e. the topology,
554 /// the atoms, the bonds, etc.) Once the system is built, the
555 /// stamps are no longer useful.
556 vector<int> molStampIds_; /**< stamp id for molecules in the system */
557 vector<MoleculeStamp*> moleculeStamps_; /**< molecule stamps array */
558
559 /**
560 * A vector that maps between the global index of an atom, and the
561 * global index of cutoff group the atom belong to. It is filled
562 * by SimCreator once and only once, since it never changed during
563 * the simulation. It should be nGlobalAtoms_ in size.
564 */
565 vector<int> globalGroupMembership_;
566 public:
567 vector<int> getGlobalGroupMembership() { return globalGroupMembership_; }
568 private:
569
570 /**
571 * A vector that maps between the global index of an atom and the
572 * global index of the molecule the atom belongs to. It is filled
573 * by SimCreator once and only once, since it is never changed
574 * during the simulation. It shoudl be nGlobalAtoms_ in size.
575 */
576 vector<int> globalMolMembership_;
577
578 /**
579 * A vector that maps between the local index of an atom and the
580 * index of the AtomType.
581 */
582 vector<int> identArray_;
583 public:
584 vector<int> getIdentArray() { return identArray_; }
585 private:
586
587 /**
588 * A vector which contains the fractional contribution of an
589 * atom's mass to the total mass of the cutoffGroup that atom
590 * belongs to. In the case of single atom cutoff groups, the mass
591 * factor for that atom is 1. For massless atoms, the factor is
592 * also 1.
593 */
594 vector<RealType> massFactors_;
595 public:
596 vector<RealType> getMassFactors() { return massFactors_; }
597
598 PairList* getExcludedInteractions() { return &excludedInteractions_; }
599 PairList* getOneTwoInteractions() { return &oneTwoInteractions_; }
600 PairList* getOneThreeInteractions() { return &oneThreeInteractions_; }
601 PairList* getOneFourInteractions() { return &oneFourInteractions_; }
602
603 private:
604
605 /// lists to handle atoms needing special treatment in the non-bonded interactions
606 PairList excludedInteractions_; /**< atoms excluded from interacting with each other */
607 PairList oneTwoInteractions_; /**< atoms that are directly Bonded */
608 PairList oneThreeInteractions_; /**< atoms sharing a Bend */
609 PairList oneFourInteractions_; /**< atoms sharing a Torsion */
610
611 PropertyMap properties_; /**< Generic Properties can be added */
612 SnapshotManager* sman_; /**< SnapshotManager (handles particle positions, etc.) */
613
614 /**
615 * The reason to have a local index manager is that when molecule
616 * is migrating to other processors, the atoms and the
617 * rigid-bodies will release their local indices to
618 * LocalIndexManager. Combining the information of molecule
619 * migrating to current processor, Migrator class can query the
620 * LocalIndexManager to make a efficient data moving plan.
621 */
622 LocalIndexManager localIndexMan_;
623
624 // unparsed MetaData block for storing in Dump and EOR files:
625 string rawMetaData_;
626
627 // file names
628 string finalConfigFileName_;
629 string dumpFileName_;
630 string statFileName_;
631 string restFileName_;
632
633
634 bool topologyDone_; /** flag to indicate whether the topology has
635 been scanned and all the relevant
636 bookkeeping has been done*/
637
638 bool calcBoxDipole_; /**< flag to indicate whether or not we calculate
639 the simulation box dipole moment */
640
641 bool useAtomicVirial_; /**< flag to indicate whether or not we use
642 Atomic Virials to calculate the pressure */
643
644 public:
645 /**
646 * return an integral objects by its global index. In MPI
647 * version, if the StuntDouble with specified global index does
648 * not belong to local processor, a NULL will be return.
649 */
650 StuntDouble* getIOIndexToIntegrableObject(int index);
651 void setIOIndexToIntegrableObject(const vector<StuntDouble*>& v);
652
653 private:
654 vector<StuntDouble*> IOIndexToIntegrableObject;
655
656 public:
657
658 /**
659 * Finds the processor where a molecule resides
660 * @return the id of the processor which contains the molecule
661 * @param globalIndex global Index of the molecule
662 */
663 int getMolToProc(int globalIndex) {
664 //assert(globalIndex < molToProcMap_.size());
665 return molToProcMap_[globalIndex];
666 }
667
668 /**
669 * Set MolToProcMap array
670 * @see #SimCreator::divideMolecules
671 */
672 void setMolToProcMap(const vector<int>& molToProcMap) {
673 molToProcMap_ = molToProcMap;
674 }
675
676 private:
677
678 /**
679 * The size of molToProcMap_ is equal to total number of molecules
680 * in the system. It maps a molecule to the processor on which it
681 * resides. it is filled by SimCreator once and only once.
682 */
683 vector<int> molToProcMap_;
684
685 };
686
687 } //namespace OpenMD
688 #endif //BRAINS_SIMMODEL_HPP
689

Properties

Name Value
svn:keywords Author Id Revision Date