--- trunk/src/primitives/Molecule.hpp 2005/01/12 22:41:40 246 +++ trunk/src/primitives/Molecule.hpp 2013/07/19 21:25:45 1908 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -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,16 @@ * 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, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ /** @@ -58,258 +59,363 @@ #include "primitives/Bond.hpp" #include "primitives/Bend.hpp" #include "primitives/Torsion.hpp" +#include "primitives/Inversion.hpp" #include "primitives/CutoffGroup.hpp" +#include "utils/PropertyMap.hpp" -namespace oopse{ +namespace OpenMD{ -class Constraint; + class Constraint; -/** - * @class Molecule Molecule.hpp "primitives/Molecule.hpp" - * @brief - */ -class Molecule { - public: + /** + * @class Molecule Molecule.hpp "primitives/Molecule.hpp" + * @brief + */ + class Molecule { + public: - typedef std::vector::iterator AtomIterator; - typedef std::vector::iterator BondIterator; - typedef std::vector::iterator BendIterator; - typedef std::vector::iterator TorsionIterator; - typedef std::vector::iterator RigidBodyIterator; - typedef std::vector::iterator CutoffGroupIterator; - typedef std::vector::iterator IntegrableObjectIterator; - typedef std::vector::iterator ConstraintPairIterator; - typedef std::vector::iterator ConstraintElemIterator; - + typedef std::vector::iterator AtomIterator; + typedef std::vector::iterator BondIterator; + typedef std::vector::iterator BendIterator; + typedef std::vector::iterator TorsionIterator; + typedef std::vector::iterator InversionIterator; + typedef std::vector::iterator RigidBodyIterator; + typedef std::vector::iterator CutoffGroupIterator; + typedef std::vector::iterator IntegrableObjectIterator; + typedef std::vector::iterator ConstraintPairIterator; + typedef std::vector::iterator ConstraintElemIterator; + typedef std::vector::iterator FluctuatingChargeIterator; + + Molecule(int stampId, int globalIndex, const std::string& molName, int region); + virtual ~Molecule(); - Molecule(int stampId, int globalIndex, const std::string& molName); - virtual ~Molecule(); + /** + * Returns the global index of this molecule. + * @return the global index of this molecule + */ + int getGlobalIndex() { + return globalIndex_; + } + + /** + * Returns the stamp id of this molecule + * @note Ideally, every molecule should keep a pointer of its + * molecule stamp instead of its stamp id. However, the pointer + * will become invalid, if the molecule migrate to other + * processor. + */ + int getStampId() { + return stampId_; + } + int getRegion() { + return region_; + } + + /** Returns the name of the molecule */ + std::string getType() { + return moleculeName_; + } + + /** + * Sets the global index of this molecule. + * @param index new global index to be set + */ + void setGlobalIndex(int index) { + globalIndex_ = index; + } - /** - * Returns the global index of this molecule. - * @return the global index of this molecule - */ - int getGlobalIndex() { - return globalIndex_; - } + void setConstrainTotalCharge(bool ctc) { + constrainTotalCharge_ = ctc; + } + + bool constrainTotalCharge() { + return constrainTotalCharge_; + } - /** - * Returns the stamp id of this molecule - * @note Ideally, every molecule should keep a pointer of its molecule stamp instead of its - * stamp id. However, the pointer will become invalid, if the molecule migrate to other processor. - */ - int getStampId() { - return stampId_; - } + /** add an atom into this molecule */ + void addAtom(Atom* atom); + + /** add a bond into this molecule */ + void addBond(Bond* bond); + + /** add a bend into this molecule */ + void addBend(Bend* bend); + + /** add a torsion into this molecule*/ + void addTorsion(Torsion* torsion); - /** Returns the name of the molecule */ - std::string getType() { - return moleculeName_; - } - - /** - * Sets the global index of this molecule. - * @param new global index to be set - */ - int setGlobalIndex(int index) { - return globalIndex_; - } + /** add an improper torsion into this molecule*/ + void addInversion(Inversion* inversion); + + /** add a rigidbody into this molecule */ + void addRigidBody(RigidBody *rb); + + /** add a cutoff group into this molecule */ + void addCutoffGroup(CutoffGroup* cp); + + void addConstraintPair(ConstraintPair* consPair); + + void addConstraintElem(ConstraintElem* consElem); + + /** */ + void complete(); + + /** Returns the total number of atoms in this molecule */ + unsigned int getNAtoms() { + return atoms_.size(); + } + + /** Returns the total number of bonds in this molecule */ + unsigned int getNBonds(){ + return bonds_.size(); + } + + /** Returns the total number of bends in this molecule */ + unsigned int getNBends() { + return bends_.size(); + } + + /** Returns the total number of torsions in this molecule */ + unsigned int getNTorsions() { + return torsions_.size(); + } - - /** add an atom into this molecule */ - void addAtom(Atom* atom); + /** Returns the total number of improper torsions in this molecule */ + unsigned int getNInversions() { + return inversions_.size(); + } + + /** Returns the total number of rigid bodies in this molecule */ + unsigned int getNRigidBodies() { + return rigidBodies_.size(); + } + + /** Returns the total number of integrable objects in this molecule */ + unsigned int getNIntegrableObjects() { + return integrableObjects_.size(); + } + + /** Returns the total number of cutoff groups in this molecule */ + unsigned int getNCutoffGroups() { + return cutoffGroups_.size(); + } + + /** Returns the total number of constraints in this molecule */ + unsigned int getNConstraintPairs() { + return constraintPairs_.size(); + } - /** add a bond into this molecule */ - void addBond(Bond* bond); + /** Returns the total number of fluctuating charges in this molecule */ + unsigned int getNFluctuatingCharges() { + return fluctuatingCharges_.size(); + } - /** add a bend into this molecule */ - void addBend(Bend* bend); + Atom* getAtomAt(unsigned int i) { + assert(i < atoms_.size()); + return atoms_[i]; + } + + RigidBody* getRigidBodyAt(unsigned int i) { + assert(i < rigidBodies_.size()); + return rigidBodies_[i]; + } + + Atom* beginAtom(std::vector::iterator& i) { + i = atoms_.begin(); + return (i == atoms_.end()) ? NULL : *i; + } + + Atom* nextAtom(std::vector::iterator& i) { + ++i; + return (i == atoms_.end()) ? NULL : *i; + } + + Bond* beginBond(std::vector::iterator& i) { + i = bonds_.begin(); + return (i == bonds_.end()) ? NULL : *i; + } + + Bond* nextBond(std::vector::iterator& i) { + ++i; + return (i == bonds_.end()) ? NULL : *i; + + } + + Bend* beginBend(std::vector::iterator& i) { + i = bends_.begin(); + return (i == bends_.end()) ? NULL : *i; + } + + Bend* nextBend(std::vector::iterator& i) { + ++i; + return (i == bends_.end()) ? NULL : *i; + } + + Torsion* beginTorsion(std::vector::iterator& i) { + i = torsions_.begin(); + return (i == torsions_.end()) ? NULL : *i; + } + + Torsion* nextTorsion(std::vector::iterator& i) { + ++i; + return (i == torsions_.end()) ? NULL : *i; + } - /** add a torsion into this molecule*/ - void addTorsion(Torsion* torsion); - - /** add a rigidbody into this molecule */ - void addRigidBody(RigidBody *rb); - - /** add a cutoff group into this molecule */ - void addCutoffGroup(CutoffGroup* cp); - - void addConstraintPair(ConstraintPair* consPair); - - void addConstraintElem(ConstraintElem* consElem); - - /** */ - void complete(); - - /** Returns the total number of atoms in this molecule */ - unsigned int getNAtoms() { - return atoms_.size(); - } - - /** Returns the total number of bonds in this molecule */ - unsigned int getNBonds(){ - return bonds_.size(); - } - - /** Returns the total number of bends in this molecule */ - unsigned int getNBends() { - return bends_.size(); - } - - /** Returns the total number of torsions in this molecule */ - unsigned int getNTorsions() { - return torsions_.size(); - } + Inversion* beginInversion(std::vector::iterator& i) { + i = inversions_.begin(); + return (i == inversions_.end()) ? NULL : *i; + } + + Inversion* nextInversion(std::vector::iterator& i) { + ++i; + return (i == inversions_.end()) ? NULL : *i; + } + + RigidBody* beginRigidBody(std::vector::iterator& i) { + i = rigidBodies_.begin(); + return (i == rigidBodies_.end()) ? NULL : *i; + } + + RigidBody* nextRigidBody(std::vector::iterator& i) { + ++i; + return (i == rigidBodies_.end()) ? NULL : *i; + } + + StuntDouble* beginIntegrableObject(std::vector::iterator& i) { + i = integrableObjects_.begin(); + return (i == integrableObjects_.end()) ? NULL : *i; + } + + StuntDouble* nextIntegrableObject(std::vector::iterator& i) { + ++i; + return (i == integrableObjects_.end()) ? NULL : *i; + } + + CutoffGroup* beginCutoffGroup(std::vector::iterator& i) { + i = cutoffGroups_.begin(); + return (i == cutoffGroups_.end()) ? NULL : *i; + } - /** Returns the total number of rigid bodies in this molecule */ - unsigned int getNRigidBodies() { - return rigidBodies_.size(); - } + CutoffGroup* nextCutoffGroup(std::vector::iterator& i) { + ++i; + return (i == cutoffGroups_.end()) ? NULL : *i; + } + + ConstraintPair* beginConstraintPair(std::vector::iterator& i) { + i = constraintPairs_.begin(); + return (i == constraintPairs_.end()) ? NULL : *i; + } + + ConstraintPair* nextConstraintPair(std::vector::iterator& i) { + ++i; + return (i == constraintPairs_.end()) ? NULL : *i; + } + + ConstraintElem* beginConstraintElem(std::vector::iterator& i) { + i = constraintElems_.begin(); + return (i == constraintElems_.end()) ? NULL : *i; + } + + ConstraintElem* nextConstraintElem(std::vector::iterator& i) { + ++i; + return (i == constraintElems_.end()) ? NULL : *i; + } - /** Returns the total number of integrable objects in this molecule */ - unsigned int getNIntegrableObjects() { - return integrableObjects_.size(); - } + Atom* beginFluctuatingCharge(std::vector::iterator& i) { + i = fluctuatingCharges_.begin(); + return (i == fluctuatingCharges_.end()) ? NULL : *i; + } + + Atom* nextFluctuatingCharge(std::vector::iterator& i) { + ++i; + return (i == fluctuatingCharges_.end()) ? NULL : *i; + } - /** Returns the total number of cutoff groups in this molecule */ - unsigned int getNCutoffGroups() { - return cutoffGroups_.size(); - } + + /** + * Returns the total potential energy of short range interaction + * of this molecule + */ + RealType getPotential(); + + /** get total mass of this molecule */ + RealType getMass(); + + /** return the center of mass of this molecule */ + Vector3d getCom(); + + /** Moves the center of this molecule */ + void moveCom(const Vector3d& delta); + + /** Returns the velocity of center of mass of this molecule */ + Vector3d getComVel(); - /** Returns the total number of constraints in this molecule */ - unsigned int getNConstraintPairs() { - return constraintPairs_.size(); - } - - Atom* getAtomAt(unsigned int i) { - assert(i < atoms_.size()); - return atoms_[i]; - } - - Atom* beginAtom(std::vector::iterator& i) { - i = atoms_.begin(); - return (i == atoms_.end()) ? NULL : *i; - } - - Atom* nextAtom(std::vector::iterator& i) { - ++i; - return (i == atoms_.end()) ? NULL : *i; - } - - Bond* beginBond(std::vector::iterator& i) { - i = bonds_.begin(); - return (i == bonds_.end()) ? NULL : *i; - } - - Bond* nextBond(std::vector::iterator& i) { - ++i; - return (i == bonds_.end()) ? NULL : *i; - - } - - Bend* beginBend(std::vector::iterator& i) { - i = bends_.begin(); - return (i == bends_.end()) ? NULL : *i; - } - - Bend* nextBend(std::vector::iterator& i) { - ++i; - return (i == bends_.end()) ? NULL : *i; - } - - Torsion* beginTorsion(std::vector::iterator& i) { - i = torsions_.begin(); - return (i == torsions_.end()) ? NULL : *i; - } - - Torsion* nextTorsion(std::vector::iterator& i) { - ++i; - return (i == torsions_.end()) ? NULL : *i; - } - - RigidBody* beginRigidBody(std::vector::iterator& i) { - i = rigidBodies_.begin(); - return (i == rigidBodies_.end()) ? NULL : *i; - } - - RigidBody* nextRigidBody(std::vector::iterator& i) { - ++i; - return (i == rigidBodies_.end()) ? NULL : *i; - } - - StuntDouble* beginIntegrableObject(std::vector::iterator& i) { - i = integrableObjects_.begin(); - return (i == integrableObjects_.end()) ? NULL : *i; - } - - StuntDouble* nextIntegrableObject(std::vector::iterator& i) { - ++i; - return (i == integrableObjects_.end()) ? NULL : *i; - } - - CutoffGroup* beginCutoffGroup(std::vector::iterator& i) { - i = cutoffGroups_.begin(); - return (i == cutoffGroups_.end()) ? NULL : *i; - } - - CutoffGroup* nextCutoffGroup(std::vector::iterator& i) { - ++i; - return (i == cutoffGroups_.end()) ? NULL : *i; - } - - ConstraintPair* beginConstraintPair(std::vector::iterator& i) { - i = constraintPairs_.begin(); - return (i == constraintPairs_.end()) ? NULL : *i; - } - - ConstraintPair* nextConstraintPair(std::vector::iterator& i) { - ++i; - return (i == constraintPairs_.end()) ? NULL : *i; - } - - ConstraintElem* beginConstraintElem(std::vector::iterator& i) { - i = constraintElems_.begin(); - return (i == constraintElems_.end()) ? NULL : *i; - } - - ConstraintElem* nextConstraintElem(std::vector::iterator& i) { - ++i; - return (i == constraintElems_.end()) ? NULL : *i; - } + std::string getMoleculeName() { + return moleculeName_; + } - /** return the total potential energy of short range interaction of this molecule */ - double getPotential(); + friend std::ostream& operator <<(std::ostream& o, Molecule& mol); - /** get total mass of this molecule */ - double getMass(); + //below functions are just forward functions + /** + * Adds property into property map + * @param genData GenericData to be added into PropertyMap + */ + void addProperty(GenericData* genData); - /** return the center of mass of this molecule */ - Vector3d getCom(); + /** + * Removes property from PropertyMap by name + * @param propName the name of property to be removed + */ + void removeProperty(const std::string& propName); - /** Moves the center of this molecule */ - void moveCom(const Vector3d& delta); + /** + * clear all of the properties + */ + void clearProperties(); - /** Returns the velocity of center of mass of this molecule */ - Vector3d getComVel(); + /** + * Returns all names of properties + * @return all names of properties + */ + std::vector getPropertyNames(); - friend std::ostream& operator <<(std::ostream& o, Molecule& mol); - - private: - - int globalIndex_; + /** + * Returns all of the properties in PropertyMap + * @return all of the properties in PropertyMap + */ + std::vector getProperties(); - std::vector atoms_; - std::vector bonds_; - std::vector bends_; - std::vector torsions_; - std::vector rigidBodies_; - std::vector integrableObjects_; - std::vector cutoffGroups_; - std::vector constraintPairs_; - std::vector constraintElems_; - int stampId_; - std::string moleculeName_; -}; + /** + * Returns property + * @param propName name of property + * @return a pointer point to property with propName. If no property named propName + * exists, return NULL + */ + GenericData* getPropertyByName(const std::string& propName); + + private: + + int globalIndex_; + + std::vector atoms_; + std::vector bonds_; + std::vector bends_; + std::vector torsions_; + std::vector inversions_; + std::vector rigidBodies_; + std::vector integrableObjects_; + std::vector cutoffGroups_; + std::vector constraintPairs_; + std::vector constraintElems_; + std::vector fluctuatingCharges_; + int stampId_; + int region_; + std::string moleculeName_; + PropertyMap properties_; + bool constrainTotalCharge_; -} //namespace oopse + }; + +} //namespace OpenMD #endif //