--- trunk/OOPSE/libmdtools/Molecule.cpp 2004/04/27 16:26:44 1136 +++ trunk/OOPSE/libmdtools/Molecule.cpp 2004/04/28 22:34:02 1140 @@ -12,7 +12,7 @@ Molecule::Molecule( void ){ myBonds = NULL; myBends = NULL; myTorsions = NULL; - + hasMassRatio = false; } Molecule::~Molecule( void ){ @@ -42,8 +42,7 @@ void Molecule::initialize( molInit &theInit ){ void Molecule::initialize( molInit &theInit ){ - double totMass; - + nAtoms = theInit.nAtoms; nMembers = nAtoms; nBonds = theInit.nBonds; @@ -63,12 +62,6 @@ void Molecule::initialize( molInit &theInit ){ for (int i = 0; i < myRigidBodies.size(); i++) myRigidBodies[i]->calcRefCoords(); - - //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 ){ @@ -80,6 +73,15 @@ void Molecule::calcForces( void ){ myRigidBodies[i]->updateAtoms(); } + //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 ++)