--- trunk/OOPSE/libmdtools/Molecule.cpp 2004/04/12 20:32:20 1097 +++ trunk/OOPSE/libmdtools/Molecule.cpp 2004/05/11 21:14:26 1158 @@ -12,12 +12,8 @@ Molecule::Molecule( void ){ myBonds = NULL; myBends = NULL; myTorsions = NULL; - myRigidBodies = NULL; - } - - Molecule::~Molecule( void ){ int i; @@ -41,17 +37,17 @@ Molecule::~Molecule( void ){ delete[] myTorsions; } - if( myRigidBodies != NULL ){ - for(i=0; i::iterator iterCutoff; + Atom* cutoffAtom; + vector::iterator iterAtom; + int atomIndex; + nAtoms = theInit.nAtoms; nMembers = nAtoms; nBonds = theInit.nBonds; @@ -59,23 +55,56 @@ void Molecule::initialize( molInit &theInit ){ nTorsions = theInit.nTorsions; nRigidBodies = theInit.nRigidBodies; nOriented = theInit.nOriented; + nCutoffGroups = theInit.nCutoffGroups; myAtoms = theInit.myAtoms; myBonds = theInit.myBonds; myBends = theInit.myBends; myTorsions = theInit.myTorsions; myRigidBodies = theInit.myRigidBodies; - + + myIntegrableObjects = theInit.myIntegrableObjects; + + for (int i = 0; i < myRigidBodies.size(); i++) + myRigidBodies[i]->calcRefCoords(); + + myCutoffGroups = theInit.myCutoffGroups; + + //creat a global index set of atoms which belong to cutoff group. + //it will be use to speed up the query whether an atom belongs to cutoff group or not + cutoffAtomSet.clear(); + + for(curCutoffGroup = beginCutoffGroup(iterCutoff); curCutoffGroup != NULL; + curCutoffGroup = nextCutoffGroup(iterCutoff)){ + + for(cutoffAtom = curCutoffGroup->beginAtom(iterAtom); cutoffAtom != NULL; + cutoffAtom = curCutoffGroup->nextAtom(iterAtom)){ +#ifdef IS_MPI + atomIndex = cutoffAtom->getGlobalIndex(); +#else + atomIndex = cutoffAtom->getIndex(); +#endif + cutoffAtomSet.insert(atomIndex); + }// end for(cutoffAtom) + }//end for(curCutoffGroup) + } 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(); } @@ -97,6 +126,10 @@ double Molecule::getPotential( void ){ int i; double myPot = 0.0; + + for(i=0; iupdateAtoms(); + } for(i=0; iget_potential(); @@ -135,22 +168,20 @@ void Molecule::moveCOM(double delta[3]){ double aPos[3]; int i, j; - for(i=0; igetPos( aPos ); + myIntegrableObjects[i]->getPos( aPos ); for (j=0; j< 3; j++) aPos[j] += delta[j]; - myAtoms[i]->setPos( aPos ); + myIntegrableObjects[i]->setPos( aPos ); } } - for(i=0; igetPos( aPos ); for (j=0; j< 3; j++) @@ -158,15 +189,12 @@ void Molecule::moveCOM(double delta[3]){ myRigidBodies[i]->setPos( aPos ); } - } } void Molecule::atoms2rigidBodies( void ) { int i; - for (i = 0; i < nRigidBodies; i++) { - if (myRigidBodies[i] != NULL) { - myRigidBodies[i]->calcForcesAndTorques(); - } + for (i = 0; i < myRigidBodies.size(); i++) { + myRigidBodies[i]->calcForcesAndTorques(); } } @@ -181,13 +209,13 @@ void Molecule::getCOM( double COM[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]->getPos( aPos ); + myIntegrableObjects[i]->getPos( aPos ); for( j = 0; j < 3; j++) COM[j] += aPos[j] * mass; @@ -211,13 +239,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; @@ -234,15 +262,12 @@ double Molecule::getTotalMass() double Molecule::getTotalMass() { - int natoms; - Atom** atoms; + double totalMass; - natoms = getNAtoms(); - atoms = getMyAtoms(); totalMass = 0; - for(int i =0; i < natoms; i++){ - totalMass += atoms[i]->getMass(); + for(int i =0; i < myIntegrableObjects.size(); i++){ + totalMass += myIntegrableObjects[i]->getMass(); } return totalMass;