--- trunk/OOPSE/libmdtools/Molecule.cpp 2003/07/15 14:28:54 607 +++ trunk/OOPSE/libmdtools/Molecule.cpp 2004/04/28 22:34:02 1140 @@ -1,4 +1,4 @@ -#include +#include #include "Molecule.hpp" @@ -12,11 +12,9 @@ Molecule::Molecule( void ){ myBonds = NULL; myBends = NULL; myTorsions = NULL; - + hasMassRatio = false; } - - Molecule::~Molecule( void ){ int i; @@ -40,10 +38,6 @@ Molecule::~Molecule( void ){ delete[] myTorsions; } - if( myExcludes != NULL ){ - for(i=0; icalcRefCoords(); + } void Molecule::calcForces( void ){ int i; + double com[3]; + for(i=0; iupdateAtoms(); + } + + //the mass ratio will never change during the simulation. Thus, we could + //just calculate it at the begining of the simulation + if (!hasMassRatio){ + double totMass = getTotalMass(); + for(int i = 0; i < nAtoms; i ++) + myAtoms[i]->setMassRatio(myAtoms[i]->getMass()/totMass); + hasMassRatio = true; + } + + //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 +99,9 @@ void Molecule::calcForces( void ){ for(i=0; icalc_forces(); } + + // Rigid Body forces and torques are done after the fortran force loop + } @@ -87,6 +109,10 @@ double Molecule::getPotential( void ){ int i; double myPot = 0.0; + + for(i=0; iupdateAtoms(); + } for(i=0; iget_potential(); @@ -118,52 +144,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 +222,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 +242,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; +}