--- trunk/OOPSE-4/src/primitives/Molecule.hpp 2004/09/24 16:27:58 1492 +++ trunk/OOPSE-4/src/primitives/Molecule.hpp 2005/01/12 22:41:40 1930 @@ -1,117 +1,315 @@ -#ifndef _MOLECULE_H_ -#define _MOLECULE_H_ + /* + * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. + * + * The University of Notre Dame grants you ("Licensee") a + * non-exclusive, royalty free, license to use, modify and + * 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 + * notice, this list of conditions and the following disclaimer. + * + * 3. 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. + * + * This software is provided "AS IS," without a warranty of any + * kind. All express or implied conditions, representations and + * warranties, including any implied warranty of merchantability, + * fitness for a particular purpose or non-infringement, are hereby + * excluded. The University of Notre Dame and its licensors shall not + * be liable for any damages suffered by licensee as a result of + * using, modifying or distributing the software or its + * derivatives. In no event will the University of Notre Dame or its + * licensors be liable for any lost revenue, profit or data, or for + * direct, indirect, special, consequential, incidental or punitive + * damages, however caused and regardless of the theory of liability, + * 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. + */ + +/** + * @file Molecule.hpp + * @author tlin + * @date 10/25/2004 + * @version 1.0 + */ -#include +#ifndef PRIMITIVES_MOLECULE_HPP +#define PRIMITIVES_MOLECULE_HPP #include +#include +#include "constraints/ConstraintPair.hpp" +#include "math/Vector3.hpp" #include "primitives/Atom.hpp" -#include "primitives/SRI.hpp" -#include "types/MoleculeStamp.hpp" #include "primitives/RigidBody.hpp" +#include "primitives/Bond.hpp" +#include "primitives/Bend.hpp" +#include "primitives/Torsion.hpp" #include "primitives/CutoffGroup.hpp" -using namespace std; +namespace oopse{ -typedef struct{ - - int stampID; // the ID in the BASS component stamp array - int nAtoms; // the number of atoms in the molecule - int nBonds; // ... .. .. . .bonds .. .. . . . . - int nBends; // . . . . .. . .bends . . . . .. . - int nTorsions; // .. . . .. . . torsions . . .. . . - int nRigidBodies; // .. .. .. . rigid bodies ... .. - int nOriented; // .. . . . .. . oriented atoms . . . - - Atom** myAtoms; // the array of atoms - Bond** myBonds; // arrays of all the short range interactions - Bend** myBends; - Torsion** myTorsions; - vector myRigidBodies; - vector myIntegrableObjects; - vector myCutoffGroups; -} molInit; +class Constraint; -class Molecule{ +/** + * @class Molecule Molecule.hpp "primitives/Molecule.hpp" + * @brief + */ +class Molecule { + public: -public: - - Molecule( void ); - ~Molecule( void ); + 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; + - void initialize( molInit &theInit ); + Molecule(int stampId, int globalIndex, const std::string& molName); + virtual ~Molecule(); - void setMyIndex( int theIndex ){ myIndex = theIndex;} - int getMyIndex( void ) { return myIndex; } + /** + * Returns the global index of this molecule. + * @return the global index of this molecule + */ + int getGlobalIndex() { + return globalIndex_; + } - int getGlobalIndex( void ) { return globalIndex; } - void setGlobalIndex( int theIndex ) { globalIndex = theIndex; } + /** + * 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 getNAtoms ( void ) {return nAtoms;} - int getNBonds ( void ) {return nBonds;} - int getNBends ( void ) {return nBends;} - int getNTorsions( void ) {return nTorsions;} - int getNRigidBodies( void ) {return myRigidBodies.size();} - int getNOriented( void ) {return nOriented;} - int getNMembers ( void ) {return nMembers;} - int getStampID ( void ) {return stampID;} + /** 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_; + } - Atom** getMyAtoms ( void ) {return myAtoms;} - Bond** getMyBonds ( void ) {return myBonds;} - Bend** getMyBends ( void ) {return myBends;} - Torsion** getMyTorsions( void ) {return myTorsions;} - vector getMyRigidBodies( void ) {return myRigidBodies;} - vector& getIntegrableObjects(void) {return myIntegrableObjects;} + + /** add an atom into this molecule */ + void addAtom(Atom* atom); - //beginCutoffGroup return the first group and initialize the iterator - CutoffGroup* beginCutoffGroup(vector::iterator& i){ - i = myCutoffGroups.begin(); - return i != myCutoffGroups.end()? *i : NULL; - } + /** add a bond into this molecule */ + void addBond(Bond* bond); - //nextCutoffGroup return next cutoff group based on the iterator - CutoffGroup* nextCutoffGroup(vector::iterator& i){ - i++; - return i != myCutoffGroups.end()? *i : NULL; - } + /** add a bend into this molecule */ + void addBend(Bend* bend); - int getNCutoffGroups() {return nCutoffGroups;} + /** add a torsion into this molecule*/ + void addTorsion(Torsion* torsion); - void setStampID( int info ) {stampID = info;} + /** add a rigidbody into this molecule */ + void addRigidBody(RigidBody *rb); - void calcForces( void ); - void atoms2rigidBodies( void ); - double getPotential( void ); - - void printMe( void ); + /** add a cutoff group into this molecule */ + void addCutoffGroup(CutoffGroup* cp); - void getCOM( double COM[3] ); - void moveCOM( double delta[3] ); - double getCOMvel( double COMvel[3] ); - - double getTotalMass(); + void addConstraintPair(ConstraintPair* consPair); + + void addConstraintElem(ConstraintElem* consElem); -private: + /** */ + void complete(); - int stampID; // the ID in the BASS component stamp array - int nAtoms; // the number of atoms in the molecule - int nBonds; // ... .. .. . .bonds .. .. . . . . - int nBends; // . . . . .. . .bends . . . . .. . - int nTorsions; // .. . . .. . . torsions . . .. . . - int nRigidBodies; // .. . . .. .rigid bodies . . .. . . - int nOriented; // .. . . . .. . oriented atoms . . . - int nMembers; // .. . . . . . .atoms (legacy code) . . . - int nCutoffGroups; - - int myIndex; // mostly just for debug (and for making pressure calcs work) - int globalIndex; + /** Returns the total number of atoms in this molecule */ + unsigned int getNAtoms() { + return atoms_.size(); + } - Atom** myAtoms; // the array of atoms - Bond** myBonds; // arrays of all the short range interactions - Bend** myBends; - Torsion** myTorsions; - vector myRigidBodies; - vector myIntegrableObjects; - vector myCutoffGroups; + /** 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(); + } + + /** 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(); + } + + 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; + } + + /** return the total potential energy of short range interaction of this molecule */ + double getPotential(); + + /** get total mass of this molecule */ + double 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(); + + friend std::ostream& operator <<(std::ostream& o, Molecule& mol); + + private: + + int globalIndex_; + + 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_; }; -#endif +} //namespace oopse +#endif //