--- trunk/OOPSE/libmdtools/Molecule.cpp 2003/04/03 21:12:51 450 +++ trunk/OOPSE/libmdtools/Molecule.cpp 2004/04/27 16:26:44 1136 @@ -1,4 +1,4 @@ -#include +#include #include "Molecule.hpp" @@ -15,8 +15,6 @@ Molecule::Molecule( void ){ } - - Molecule::~Molecule( void ){ int i; @@ -40,35 +38,54 @@ Molecule::~Molecule( void ){ delete[] myTorsions; } - if( myExcludes != NULL ){ - for(i=0; icalcRefCoords(); + + + //the mass ratio will never change during the simulation. Thus, we could + //just calculate it at the begining of the simulation + totMass = getTotalMass(); + for(int i = 0; i < nAtoms; i ++) + myAtoms[i]->setMassRatio(myAtoms[i]->getMass()/totMass); } 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 +97,9 @@ void Molecule::calcForces( void ){ for(i=0; icalc_forces(); } + + // Rigid Body forces and torques are done after the fortran force loop + } @@ -87,6 +107,10 @@ double Molecule::getPotential( void ){ int i; double myPot = 0.0; + + for(i=0; iupdateAtoms(); + } for(i=0; iget_potential(); @@ -118,50 +142,114 @@ 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] ) { + + double mass, mtot; + double aVel[3]; + int i, j; + + + for (j=0; j<3; j++) + COMvel[j] = 0.0; + + mtot = 0.0; + + for (i=0; i < myIntegrableObjects.size(); i++) { + if (myIntegrableObjects[i] != NULL) { + + mass = myIntegrableObjects[i]->getMass(); + mtot += mass; + + myIntegrableObjects[i]->getVel(aVel); + + for (j=0; j<3; j++) + COMvel[j] += aVel[j]*mass; + + } + } + + for (j=0; j<3; j++) + COMvel[j] /= mtot; + return mtot; + } + +double Molecule::getTotalMass() +{ + + double totalMass; + + totalMass = 0; + for(int i =0; i < myIntegrableObjects.size(); i++){ + totalMass += myIntegrableObjects[i]->getMass(); + } + + return totalMass; +}