--- trunk/OOPSE/libmdtools/Molecule.cpp 2003/07/15 14:28:54 607 +++ trunk/OOPSE/libmdtools/Molecule.cpp 2004/08/23 15:11:36 1452 @@ -1,4 +1,4 @@ -#include +#include #include "Molecule.hpp" @@ -12,13 +12,12 @@ Molecule::Molecule( void ){ myBonds = NULL; myBends = NULL; myTorsions = NULL; - } - - Molecule::~Molecule( void ){ int i; + CutoffGroup* cg; + vector::iterator iter; if( myAtoms != NULL ){ for(i=0; i::iterator iterCutoff; + Atom* cutoffAtom; + vector::iterator iterAtom; + int atomIndex; + GenericData* gdata; + ConsRbData* rbData; + RigidBody* oldRb; + nAtoms = theInit.nAtoms; nMembers = nAtoms; nBonds = theInit.nBonds; nBends = theInit.nBends; nTorsions = theInit.nTorsions; - nExcludes = theInit.nExcludes; + nRigidBodies = theInit.nRigidBodies; nOriented = theInit.nOriented; myAtoms = theInit.myAtoms; myBonds = theInit.myBonds; myBends = theInit.myBends; myTorsions = theInit.myTorsions; - myExcludes = theInit.myExcludes; + myRigidBodies = theInit.myRigidBodies; + + myIntegrableObjects = theInit.myIntegrableObjects; + + for (int i = 0; i < myRigidBodies.size(); i++){ + myRigidBodies[i]->calcRefCoords(); + //just a quick hack + gdata = myRigidBodies[i]->getProperty("OldState"); + if(gdata != NULL){ + rbData = dynamic_cast(gdata); + if(rbData ==NULL) + cerr << "dynamic_cast to ConsRbData Error in Molecule::initialize()" << endl; + else{ + oldRb = rbData->getData(); + oldRb->calcRefCoords(); + } + }//end if(gata != NULL) + + }//end for(int i = 0; i < myRigidBodies.size(); i++) + + myCutoffGroups = theInit.myCutoffGroups; + nCutoffGroups = myCutoffGroups.size(); + + myConstraintPairs = theInit.myConstraintPairs; + } void Molecule::calcForces( void ){ int i; + double com[3]; + for(i=0; iupdateAtoms(); + } + + //calculate the center of mass of the molecule + //getCOM(com); + //for(int i = 0; i < nAtoms; i ++) + // myAtoms[i]->setRc(com); + + for(i=0; icalc_forces(); } @@ -80,6 +123,9 @@ void Molecule::calcForces( void ){ for(i=0; icalc_forces(); } + + // Rigid Body forces and torques are done after the fortran force loop + } @@ -87,6 +133,10 @@ double Molecule::getPotential( void ){ int i; double myPot = 0.0; + + for(i=0; iupdateAtoms(); + } for(i=0; iget_potential(); @@ -118,52 +168,70 @@ void Molecule::printMe( void ){ for(i=0; iprintMe(); } + } void Molecule::moveCOM(double delta[3]){ - double x, y, z; - int i; + double aPos[3]; + int i, j; - for(i=0; igetPos( aPos ); + + for (j=0; j< 3; j++) + aPos[j] += delta[j]; - x = myAtoms[i]->getX() + delta[0]; - y = myAtoms[i]->getY() + delta[1]; - z = myAtoms[i]->getZ() + delta[2]; + myIntegrableObjects[i]->setPos( aPos ); + } + } - myAtoms[i]->setX(x); - myAtoms[i]->setY(y); - myAtoms[i]->setZ(z); + for(i=0; igetPos( aPos ); + + for (j=0; j< 3; j++) + aPos[j] += delta[j]; + + myRigidBodies[i]->setPos( aPos ); } +} + +void Molecule::atoms2rigidBodies( void ) { + int i; + for (i = 0; i < myRigidBodies.size(); i++) { + myRigidBodies[i]->calcForcesAndTorques(); } } void Molecule::getCOM( double COM[3] ) { double mass, mtot; - int i; + double aPos[3]; + int i, j; - COM[0] = 0.0; - COM[1] = 0.0; - COM[2] = 0.0; + for (j=0; j<3; j++) + COM[j] = 0.0; + mtot = 0.0; - for (i=0; i < nAtoms; i++) { - if (myAtoms[i] != NULL) { + for (i=0; i < myIntegrableObjects.size(); i++) { + if (myIntegrableObjects[i] != NULL) { - mass = myAtoms[i]->getMass(); + mass = myIntegrableObjects[i]->getMass(); mtot += mass; - COM[0] += myAtoms[i]->getX() * mass; - COM[1] += myAtoms[i]->getY() * mass; - COM[2] += myAtoms[i]->getZ() * mass; + + myIntegrableObjects[i]->getPos( aPos ); + for( j = 0; j < 3; j++) + COM[j] += aPos[j] * mass; + } } - COM[0] /= mtot; - COM[1] /= mtot; - COM[2] /= mtot; - + for (j = 0; j < 3; j++) + COM[j] /= mtot; } double Molecule::getCOMvel( double COMvel[3] ) { @@ -178,13 +246,13 @@ double Molecule::getCOMvel( double COMvel[3] ) { mtot = 0.0; - for (i=0; i < nAtoms; i++) { - if (myAtoms[i] != NULL) { + for (i=0; i < myIntegrableObjects.size(); i++) { + if (myIntegrableObjects[i] != NULL) { - mass = myAtoms[i]->getMass(); + mass = myIntegrableObjects[i]->getMass(); mtot += mass; - myAtoms[i]->getVel(aVel); + myIntegrableObjects[i]->getVel(aVel); for (j=0; j<3; j++) COMvel[j] += aVel[j]*mass; @@ -198,3 +266,16 @@ double Molecule::getCOMvel( double COMvel[3] ) { return mtot; } + +double Molecule::getTotalMass() +{ + + double totalMass; + + totalMass = 0; + for(int i =0; i < myIntegrableObjects.size(); i++){ + totalMass += myIntegrableObjects[i]->getMass(); + } + + return totalMass; +}