--- trunk/src/brains/SimInfo.hpp 2006/05/17 21:51:42 963 +++ branches/development/src/brains/SimInfo.hpp 2011/05/26 13:55:04 1569 @@ -6,19 +6,10 @@ * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,6 +28,15 @@ * arising out of the use of or inability to use software, even if the * University of Notre Dame has been advised of the possibility of * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). + * [4] Vardeman & Gezelter, in progress (2009). */ /** @@ -54,7 +54,7 @@ #include #include -#include "brains/Exclude.hpp" +#include "brains/PairList.hpp" #include "io/Globals.hpp" #include "math/Vector3.hpp" #include "math/SquareMatrix3.hpp" @@ -62,51 +62,60 @@ #include "UseTheForce/ForceField.hpp" #include "utils/PropertyMap.hpp" #include "utils/LocalIndexManager.hpp" +#include "nonbonded/SwitchingFunction.hpp" -//another nonsense macro declaration -#define __C -#include "brains/fSimulation.h" - -namespace oopse{ - - //forward decalration +using namespace std; +namespace OpenMD{ + //forward declaration class SnapshotManager; class Molecule; class SelectionManager; + class StuntDouble; + /** - * @class SimInfo SimInfo.hpp "brains/SimInfo.hpp" - * @brief One of the heavy weight classes of OOPSE, SimInfo maintains a list of molecules. - * The Molecule class maintains all of the concrete objects - * (atoms, bond, bend, torsions, rigid bodies, cutoff groups, constrains). - * In both the single and parallel versions, atoms and - * rigid bodies have both global and local indices. The local index is - * not relevant to molecules or cutoff groups. + * @class SimInfo SimInfo.hpp "brains/SimInfo.hpp" + * + * @brief One of the heavy-weight classes of OpenMD, SimInfo + * maintains objects and variables relating to the current + * simulation. This includes the master list of Molecules. The + * Molecule class maintains all of the concrete objects (Atoms, + * Bond, Bend, Torsions, Inversions, RigidBodies, CutoffGroups, + * Constraints). In both the single and parallel versions, Atoms and + * RigidBodies have both global and local indices. */ class SimInfo { public: - typedef std::map::iterator MoleculeIterator; - + typedef map::iterator MoleculeIterator; + /** * Constructor of SimInfo - * @param molStampPairs MoleculeStamp Array. The first element of the pair is molecule stamp, the - * second element is the total number of molecules with the same molecule stamp in the system + * + * @param molStampPairs MoleculeStamp Array. The first element of + * the pair is molecule stamp, the second element is the total + * number of molecules with the same molecule stamp in the system + * * @param ff pointer of a concrete ForceField instance + * * @param simParams - * @note */ SimInfo(ForceField* ff, Globals* simParams); virtual ~SimInfo(); /** * Adds a molecule - * @return return true if adding successfully, return false if the molecule is already in SimInfo + * + * @return return true if adding successfully, return false if the + * molecule is already in SimInfo + * * @param mol molecule to be added */ bool addMolecule(Molecule* mol); /** * Removes a molecule from SimInfo - * @return true if removing successfully, return false if molecule is not in this SimInfo + * + * @return true if removing successfully, return false if molecule + * is not in this SimInfo */ bool removeMolecule(Molecule* mol); @@ -126,16 +135,18 @@ namespace oopse{ } /** - * Returns the total number of integrable objects (total number of rigid bodies plus the total number - * of atoms which do not belong to the rigid bodies) in the system + * Returns the total number of integrable objects (total number of + * rigid bodies plus the total number of atoms which do not belong + * to the rigid bodies) in the system */ int getNGlobalIntegrableObjects() { return nGlobalIntegrableObjects_; } /** - * Returns the total number of integrable objects (total number of rigid bodies plus the total number - * of atoms which do not belong to the rigid bodies) in the system + * Returns the total number of integrable objects (total number of + * rigid bodies plus the total number of atoms which do not belong + * to the rigid bodies) in the system */ int getNGlobalRigidBodies() { return nGlobalRigidBodies_; @@ -170,6 +181,10 @@ namespace oopse{ return nTorsions_; } + /** Returns the number of local torsions */ + unsigned int getNInversions() { + return nInversions_; + } /** Returns the number of local rigid bodies */ unsigned int getNRigidBodies() { return nRigidBodies_; @@ -226,7 +241,8 @@ namespace oopse{ int getFdf(); - //getNZconstraint and setNZconstraint ruin the coherent of SimInfo class, need refactorying + //getNZconstraint and setNZconstraint ruin the coherence of + //SimInfo class, need refactoring /** Returns the total number of z-constraint molecules in the system */ int getNZconstraint() { @@ -262,18 +278,31 @@ namespace oopse{ /** Returns the center of the mass of the whole system.*/ Vector3d getCom(); - /** Returns the center of the mass and Center of Mass velocity of the whole system.*/ + /** Returns the center of the mass and Center of Mass velocity of + the whole system.*/ void getComAll(Vector3d& com,Vector3d& comVel); - /** Returns intertia tensor for the entire system and system Angular Momentum.*/ + /** Returns intertia tensor for the entire system and system + Angular Momentum.*/ void getInertiaTensor(Mat3x3d &intertiaTensor,Vector3d &angularMomentum); /** Returns system angular momentum */ Vector3d getAngularMomentum(); - /** main driver function to interact with fortran during the initialization and molecule migration */ + /** Returns volume of system as estimated by an ellipsoid defined + by the radii of gyration*/ + void getGyrationalVolume(RealType &vol); + /** Overloaded version of gyrational volume that also returns + det(I) so dV/dr can be calculated*/ + void getGyrationalVolume(RealType &vol, RealType &detI); + void update(); + /** + * Do final bookkeeping before Force managers need their data. + */ + void prepareTopology(); + /** Returns the local index manager */ LocalIndexManager* getLocalIndexManager() { return &localIndexMan_; @@ -305,47 +334,61 @@ namespace oopse{ return i != molecules_.end() ? i->second : NULL; } - RealType getRcut() { - return rcut_; + int getGlobalMolMembership(int id){ + return globalMolMembership_[id]; } - RealType getRsw() { - return rsw_; - } - - RealType getList() { - return rlist_; - } + /** + * returns a vector which maps the local atom index on this + * processor to the global atom index. With only one processor, + * these should be identical. + */ + vector getGlobalAtomIndices(); + + /** + * returns a vector which maps the local cutoff group index on + * this processor to the global cutoff group index. With only one + * processor, these should be identical. + */ + vector getGlobalGroupIndices(); + - std::string getFinalConfigFileName() { + string getFinalConfigFileName() { return finalConfigFileName_; } - - void setFinalConfigFileName(const std::string& fileName) { + + void setFinalConfigFileName(const string& fileName) { finalConfigFileName_ = fileName; } - std::string getDumpFileName() { + string getRawMetaData() { + return rawMetaData_; + } + void setRawMetaData(const string& rawMetaData) { + rawMetaData_ = rawMetaData; + } + + string getDumpFileName() { return dumpFileName_; } - void setDumpFileName(const std::string& fileName) { + void setDumpFileName(const string& fileName) { dumpFileName_ = fileName; } - std::string getStatFileName() { + string getStatFileName() { return statFileName_; } - void setStatFileName(const std::string& fileName) { + void setStatFileName(const string& fileName) { statFileName_ = fileName; } - std::string getRestFileName() { + string getRestFileName() { return restFileName_; } - void setRestFileName(const std::string& fileName) { + void setRestFileName(const string& fileName) { restFileName_ = fileName; } @@ -353,8 +396,8 @@ namespace oopse{ * Sets GlobalGroupMembership * @see #SimCreator::setGlobalIndex */ - void setGlobalGroupMembership(const std::vector& globalGroupMembership) { - assert(globalGroupMembership.size() == nGlobalAtoms_); + void setGlobalGroupMembership(const vector& globalGroupMembership) { + assert(globalGroupMembership.size() == static_cast(nGlobalAtoms_)); globalGroupMembership_ = globalGroupMembership; } @@ -362,19 +405,24 @@ namespace oopse{ * Sets GlobalMolMembership * @see #SimCreator::setGlobalIndex */ - void setGlobalMolMembership(const std::vector& globalMolMembership) { - assert(globalMolMembership.size() == nGlobalAtoms_); + void setGlobalMolMembership(const vector& globalMolMembership) { + assert(globalMolMembership.size() == static_cast(nGlobalAtoms_)); globalMolMembership_ = globalMolMembership; } - bool isFortranInitialized() { - return fortranInitialized_; + bool isTopologyDone() { + return topologyDone_; } - //below functions are just forward functions - //To compose or to inherit is always a hot debate. In general, is-a relation need subclassing, in the - //the other hand, has-a relation need composing. + bool getCalcBoxDipole() { + return calcBoxDipole_; + } + + bool getUseAtomicVirial() { + return useAtomicVirial_; + } + /** * Adds property into property map * @param genData GenericData to be added into PropertyMap @@ -385,7 +433,7 @@ namespace oopse{ * Removes property from PropertyMap by name * @param propName the name of property to be removed */ - void removeProperty(const std::string& propName); + void removeProperty(const string& propName); /** * clear all of the properties @@ -396,13 +444,13 @@ namespace oopse{ * Returns all names of properties * @return all names of properties */ - std::vector getPropertyNames(); + vector getPropertyNames(); /** * Returns all of the properties in PropertyMap * @return all of the properties in PropertyMap */ - std::vector getProperties(); + vector getProperties(); /** * Returns property @@ -410,133 +458,201 @@ namespace oopse{ * @return a pointer point to property with propName. If no property named propName * exists, return NULL */ - GenericData* getPropertyByName(const std::string& propName); + GenericData* getPropertyByName(const string& propName); /** - * add all exclude pairs of a molecule into exclude list. + * add all special interaction pairs (including excluded + * interactions) in a molecule into the appropriate lists. */ - void addExcludePairs(Molecule* mol); + void addInteractionPairs(Molecule* mol); /** - * remove all exclude pairs which belong to a molecule from exclude list + * remove all special interaction pairs which belong to a molecule + * from the appropriate lists. */ + void removeInteractionPairs(Molecule* mol); - void removeExcludePairs(Molecule* mol); - - - /** Returns the unique atom types of local processor in an array */ - std::set getUniqueAtomTypes(); + /** Returns the set of atom types present in this simulation */ + set getSimulatedAtomTypes(); - friend std::ostream& operator <<(std::ostream& o, SimInfo& info); + friend ostream& operator <<(ostream& o, SimInfo& info); void getCutoff(RealType& rcut, RealType& rsw); private: - /** fill up the simtype struct*/ - void setupSimType(); + /** fill up the simtype struct and other simulation-related variables */ + void setupSimVariables(); - /** - * Setup Fortran Simulation - * @see #setupFortranParallel - */ - void setupFortranSim(); - /** Figure out the radius of cutoff, radius of switching function and pass them to fortran */ - void setupCutoff(); + /** Determine if we need to accumulate the simulation box dipole */ + void setupAccumulateBoxDipole(); - /** Figure out which coulombic correction method to use and pass to fortran */ - void setupElectrostaticSummationMethod( int isError ); - - /** Figure out which polynomial type to use for the switching function */ - void setupSwitchingFunction(); - /** Calculates the number of degress of freedom in the whole system */ void calcNdf(); void calcNdfRaw(); void calcNdfTrans(); - ForceField* forceField_; - Globals* simParams_; - - std::map molecules_; /**< Molecule array */ - /** - * Adds molecule stamp and the total number of the molecule with same molecule stamp in the whole - * system. + * Adds molecule stamp and the total number of the molecule with + * same molecule stamp in the whole system. */ void addMoleculeStamp(MoleculeStamp* molStamp, int nmol); + + // Other classes holdingn important information + ForceField* forceField_; /**< provides access to defined atom types, bond types, etc. */ + Globals* simParams_; /**< provides access to simulation parameters set by user */ + + /// Counts of local objects + int nAtoms_; /**< number of atoms in local processor */ + int nBonds_; /**< number of bonds in local processor */ + int nBends_; /**< number of bends in local processor */ + int nTorsions_; /**< number of torsions in local processor */ + int nInversions_; /**< number of inversions in local processor */ + int nRigidBodies_; /**< number of rigid bodies in local processor */ + int nIntegrableObjects_; /**< number of integrable objects in local processor */ + int nCutoffGroups_; /**< number of cutoff groups in local processor */ + int nConstraints_; /**< number of constraints in local processors */ - //degress of freedom - int ndf_; /**< number of degress of freedom (excludes constraints), ndf_ is local */ - int fdf_local; /**< number of frozen degrees of freedom */ - int fdf_; /**< number of frozen degrees of freedom */ - int ndfRaw_; /**< number of degress of freedom (includes constraints), ndfRaw_ is local */ - int ndfTrans_; /**< number of translation degress of freedom, ndfTrans_ is local */ - int nZconstraint_; /** number of z-constraint molecules, nZconstraint_ is global */ - - //number of global objects - int nGlobalMols_; /**< number of molecules in the system */ - int nGlobalAtoms_; /**< number of atoms in the system */ - int nGlobalCutoffGroups_; /**< number of cutoff groups in this system */ + /// Counts of global objects + int nGlobalMols_; /**< number of molecules in the system (GLOBAL) */ + int nGlobalAtoms_; /**< number of atoms in the system (GLOBAL) */ + int nGlobalCutoffGroups_; /**< number of cutoff groups in this system (GLOBAL) */ int nGlobalIntegrableObjects_; /**< number of integrable objects in this system */ - int nGlobalRigidBodies_; /**< number of rigid bodies in this system */ + int nGlobalRigidBodies_; /**< number of rigid bodies in this system (GLOBAL) */ + + /// Degress of freedom + int ndf_; /**< number of degress of freedom (excludes constraints) (LOCAL) */ + int fdf_local; /**< number of frozen degrees of freedom (LOCAL) */ + int fdf_; /**< number of frozen degrees of freedom (GLOBAL) */ + int ndfRaw_; /**< number of degress of freedom (includes constraints), (LOCAL) */ + int ndfTrans_; /**< number of translation degress of freedom, (LOCAL) */ + int nZconstraint_; /**< number of z-constraint molecules (GLOBAL) */ + + /// logicals + bool usesPeriodicBoundaries_; /**< use periodic boundary conditions? */ + bool usesDirectionalAtoms_; /**< are there atoms with position AND orientation? */ + bool usesMetallicAtoms_; /**< are there transition metal atoms? */ + bool usesElectrostaticAtoms_; /**< are there electrostatic atoms? */ + bool usesAtomicVirial_; /**< are we computing atomic virials? */ + bool requiresPrepair_; /**< does this simulation require a pre-pair loop? */ + bool requiresSkipCorrection_; /**< does this simulation require a skip-correction? */ + bool requiresSelfCorrection_; /**< does this simulation require a self-correction? */ + + public: + bool usesElectrostaticAtoms() { return usesElectrostaticAtoms_; } + bool usesDirectionalAtoms() { return usesDirectionalAtoms_; } + bool usesMetallicAtoms() { return usesMetallicAtoms_; } + bool usesAtomicVirial() { return usesAtomicVirial_; } + bool requiresPrepair() { return requiresPrepair_; } + bool requiresSkipCorrection() { return requiresSkipCorrection_;} + bool requiresSelfCorrection() { return requiresSelfCorrection_;} + + private: + /// Data structures holding primary simulation objects + map molecules_; /**< map holding pointers to LOCAL molecules */ + + /// Stamps are templates for objects that are then used to create + /// groups of objects. For example, a molecule stamp contains + /// information on how to build that molecule (i.e. the topology, + /// the atoms, the bonds, etc.) Once the system is built, the + /// stamps are no longer useful. + vector molStampIds_; /**< stamp id for molecules in the system */ + vector moleculeStamps_; /**< molecule stamps array */ + /** - * the size of globalGroupMembership_ is nGlobalAtoms. Its index is global index of an atom, and the - * corresponding content is the global index of cutoff group this atom belong to. - * It is filled by SimCreator once and only once, since it never changed during the simulation. + * A vector that maps between the global index of an atom, and the + * global index of cutoff group the atom belong to. It is filled + * by SimCreator once and only once, since it never changed during + * the simulation. It should be nGlobalAtoms_ in size. */ - std::vector globalGroupMembership_; + vector globalGroupMembership_; + public: + vector getGlobalGroupMembership() { return globalGroupMembership_; } + private: /** - * the size of globalGroupMembership_ is nGlobalAtoms. Its index is global index of an atom, and the - * corresponding content is the global index of molecule this atom belong to. - * It is filled by SimCreator once and only once, since it is never changed during the simulation. + * A vector that maps between the global index of an atom and the + * global index of the molecule the atom belongs to. It is filled + * by SimCreator once and only once, since it is never changed + * during the simulation. It shoudl be nGlobalAtoms_ in size. */ - std::vector globalMolMembership_; + vector globalMolMembership_; - - std::vector molStampIds_; /**< stamp id array of all molecules in the system */ - std::vector moleculeStamps_; /**< molecule stamps array */ - - //number of local objects - int nAtoms_; /**< number of atoms in local processor */ - int nBonds_; /**< number of bonds in local processor */ - int nBends_; /**< number of bends in local processor */ - int nTorsions_; /**< number of torsions in local processor */ - int nRigidBodies_; /**< number of rigid bodies in local processor */ - int nIntegrableObjects_; /**< number of integrable objects in local processor */ - int nCutoffGroups_; /**< number of cutoff groups in local processor */ - int nConstraints_; /**< number of constraints in local processors */ + /** + * A vector that maps between the local index of an atom and the + * index of the AtomType. + */ + vector identArray_; + public: + vector getIdentArray() { return identArray_; } + private: + + /** + * A vector which contains the fractional contribution of an + * atom's mass to the total mass of the cutoffGroup that atom + * belongs to. In the case of single atom cutoff groups, the mass + * factor for that atom is 1. For massless atoms, the factor is + * also 1. + */ + vector massFactors_; + public: + vector getMassFactors() { return massFactors_; } + private: - simtype fInfo_; /**< A dual struct shared by c++/fortran which indicates the atom types in simulation*/ - Exclude exclude_; - PropertyMap properties_; /**< Generic Property */ - SnapshotManager* sman_; /**< SnapshotManager */ + + /// lists to handle atoms needing special treatment in the non-bonded interactions + PairList excludedInteractions_; /**< atoms excluded from interacting with each other */ + PairList oneTwoInteractions_; /**< atoms that are directly Bonded */ + PairList oneThreeInteractions_; /**< atoms sharing a Bend */ + PairList oneFourInteractions_; /**< atoms sharing a Torsion */ + PropertyMap properties_; /**< Generic Properties can be added */ + SnapshotManager* sman_; /**< SnapshotManager (handles particle positions, etc.) */ + /** - * The reason to have a local index manager is that when molecule is migrating to other processors, - * the atoms and the rigid-bodies will release their local indices to LocalIndexManager. Combining the - * information of molecule migrating to current processor, Migrator class can query the LocalIndexManager - * to make a efficient data moving plan. + * The reason to have a local index manager is that when molecule + * is migrating to other processors, the atoms and the + * rigid-bodies will release their local indices to + * LocalIndexManager. Combining the information of molecule + * migrating to current processor, Migrator class can query the + * LocalIndexManager to make a efficient data moving plan. */ LocalIndexManager localIndexMan_; - //file names - std::string finalConfigFileName_; - std::string dumpFileName_; - std::string statFileName_; - std::string restFileName_; + // unparsed MetaData block for storing in Dump and EOR files: + string rawMetaData_; + + // file names + string finalConfigFileName_; + string dumpFileName_; + string statFileName_; + string restFileName_; - RealType rcut_; /**< cutoff radius*/ - RealType rsw_; /**< radius of switching function*/ - RealType rlist_; /**< neighbor list radius */ - bool fortranInitialized_; /**< flag indicate whether fortran side is initialized */ - -#ifdef IS_MPI - //in Parallel version, we need MolToProc + bool topologyDone_; /** flag to indicate whether the topology has + been scanned and all the relevant + bookkeeping has been done*/ + + bool calcBoxDipole_; /**< flag to indicate whether or not we calculate + the simulation box dipole moment */ + + bool useAtomicVirial_; /**< flag to indicate whether or not we use + Atomic Virials to calculate the pressure */ + public: + /** + * return an integral objects by its global index. In MPI + * version, if the StuntDouble with specified global index does + * not belong to local processor, a NULL will be return. + */ + StuntDouble* getIOIndexToIntegrableObject(int index); + void setIOIndexToIntegrableObject(const vector& v); + + private: + vector IOIndexToIntegrableObject; + + public: /** * Finds the processor where a molecule resides @@ -547,30 +663,26 @@ namespace oopse{ //assert(globalIndex < molToProcMap_.size()); return molToProcMap_[globalIndex]; } - + /** * Set MolToProcMap array * @see #SimCreator::divideMolecules */ - void setMolToProcMap(const std::vector& molToProcMap) { + void setMolToProcMap(const vector& molToProcMap) { molToProcMap_ = molToProcMap; } private: - - void setupFortranParallel(); /** - * The size of molToProcMap_ is equal to total number of molecules in the system. - * It maps a molecule to the processor on which it resides. it is filled by SimCreator once and only - * once. + * The size of molToProcMap_ is equal to total number of molecules + * in the system. It maps a molecule to the processor on which it + * resides. it is filled by SimCreator once and only once. */ - std::vector molToProcMap_; + vector molToProcMap_; -#endif - }; -} //namespace oopse +} //namespace OpenMD #endif //BRAINS_SIMMODEL_HPP