--- trunk/OOPSE-2.0/src/primitives/Molecule.hpp 2004/09/24 16:27:58 1492 +++ branches/new_design/OOPSE-2.0/src/primitives/Molecule.hpp 2004/11/12 06:19:04 1733 @@ -1,117 +1,278 @@ -#ifndef _MOLECULE_H_ -#define _MOLECULE_H_ +/* + * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project + * + * Contact: oopse@oopse.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * All we ask is that proper credit is given for our work, which includes + * - but is not limited to - adding the above copyright notice to the beginning + * of your source code files, and to any copyright notice that you may distribute + * with programs based on this work. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ -#include +/** + * @file Molecule.hpp + * @author tlin + * @date 10/25/2004 + * @version 1.0 + */ + +#ifndef PRIMITIVES_MOLECULE_HPP +#define PRIMITIVES_MOLECULE_HPP #include +#include +#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/SRI.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; - 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 complete(); -private: + /** Returns the total number of atoms in this molecule */ + unsigned int getNAtoms() { + return atoms_.size(); + } - 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 bonds in this molecule */ + unsigned int getNBonds(){ + return bonds_.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 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 getNConstraints() { + return constraints_.size(); + } + + Atom* getAtomAt(unsigned int i) { + assert(i < atoms_.size()); + return atoms_[i]; + } + /** + * Returns the first atom in this molecule and initialize the iterator. + * @return the first atom, return NULL if there is not cut off group in this molecule + * @param i iteraotr + */ + Atom* beginAtom(std::vector::iterator& i); + + Atom* nextAtom(std::vector::iterator& i); + + /** + * Returns the first bond in this molecule and initialize the iterator. + * @return the first bond, return NULL if there is not cut off group in this molecule + * @param i iteraotr + */ + Bond* beginBond(std::vector::iterator& i); + + Bond* nextBond(std::vector::iterator& i); + + /** + * Returns the first bend in this molecule and initialize the iterator. + * @return the first bend, return NULL if there is not cut off group in this molecule + * @param i iteraotr + */ + Bend* beginBend(std::vector::iterator& i); + + Bend* nextBend(std::vector::iterator& i); + + /** + * Returns the first torsion in this molecule and initialize the iterator. + * @return the first torsion, return NULL if there is not cut off group in this molecule + * @param i iteraotr + */ + Torsion* beginTorsion(std::vector::iterator& i); + Torsion* nextTorsion(std::vector::iterator& i); + + /** + * Returns the first rigid body in this molecule and initialize the iterator. + * @return the first rigid body, return NULL if there is not cut off group in this molecule + * @param i iteraotr + */ + RigidBody* beginRigidBody(std::vector::iterator& i); + + RigidBody* nextRigidBody(std::vector::iterator& i); + + /** + * Returns the first integrable object in this molecule and initialize the iterator. + * @return the first integrable object, return NULL if there is not cut off group in this molecule + * @param i iteraotr + */ + StuntDouble* beginIntegrableObject(std::vector::iterator& i); + + StuntDouble* nextIntegrableObject(std::vector::iterator& i); + + /** + * Returns the first cutoff group in this molecule and initialize the iterator. + * @return the first cutoff group, return NULL if there is not cut off group in this molecule + * @param i iteraotr + */ + CutoffGroup* beginCutoffGroup(std::vector::iterator& i); + + /** + * Returns next cutoff group based on the iterator + * @return next cutoff group + * @param i + */ + CutoffGroup* nextCutoffGroup(std::vector::iterator& i); + + Constraint* beginConstraint(std::vector::iterator& i); + + Constraint* nextConstraint(std::vector::iterator& i); + + //void setStampID( int info ) {stampID = info;} + + void calcForces( void ); + + void atoms2rigidBodies( void ); + + /** return the total potential energy of short range interaction of this molecule */ + double getPotential(); + + + /** 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 mass of this molecule */ + double getTotalMass(); + + 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 constraints_; + + int stampId_; + std::string moleculeName_; }; -#endif +} //namespace oopse +#endif //