--- trunk/OOPSE/libmdtools/SimSetup.cpp 2004/05/12 14:30:12 1163 +++ trunk/OOPSE/libmdtools/SimSetup.cpp 2004/06/01 18:42:58 1214 @@ -10,8 +10,9 @@ #include "Integrator.hpp" #include "simError.h" #include "RigidBody.hpp" -//#include "ConjugateMinimizer.hpp" #include "OOPSEMinimizer.hpp" +//#include "ConstraintElement.hpp" +//#include "ConstraintPair.hpp" #ifdef IS_MPI #include "mpiBASS.h" @@ -170,8 +171,8 @@ void SimSetup::makeMolecules(void){ int i, j, k; int exI, exJ, exK, exL, slI, slJ; int tempI, tempJ, tempK, tempL; - int molI; - int stampID, atomOffset, rbOffset; + int molI, globalID; + int stampID, atomOffset, rbOffset, groupOffset; molInit molInfo; DirectionalAtom* dAtom; RigidBody* myRB; @@ -185,7 +186,9 @@ void SimSetup::makeMolecules(void){ RigidBodyStamp* currentRigidBody; CutoffGroupStamp* currentCutoffGroup; CutoffGroup* myCutoffGroup; - + int nCutoffGroups;// number of cutoff group of a molecule defined in mdl file + set cutoffAtomSet; //atoms belong to cutoffgroup defined at mdl file + bond_pair* theBonds; bend_set* theBends; torsion_set* theTorsions; @@ -196,6 +199,12 @@ void SimSetup::makeMolecules(void){ char* molName; char rbName[100]; + //ConstraintPair* consPair; //constraint pair + //ConstraintElement* consElement1; //first element of constraint pair + //ConstraintElement* consElement2; //second element of constraint pair + //int whichRigidBody; + //int consAtomIndex; //index of constraint atom in rigid body's atom array + //vector > jointAtoms; //init the forceField paramters the_ff->readParams(); @@ -206,8 +215,19 @@ void SimSetup::makeMolecules(void){ for (k = 0; k < nInfo; k++){ the_ff->setSimInfo(&(info[k])); + +#ifdef IS_MPI + info[k].globalGroupMembership = new int[mpiSim->getNAtomsGlobal()]; + for (i = 0; i < mpiSim->getNAtomsGlobal(); i++) + info[k].globalGroupMembership[i] = 0; +#else + info[k].globalGroupMembership = new int[info[k].n_atoms]; + for (i = 0; i < info[k].n_atoms; i++) + info[k].globalGroupMembership[i] = 0; +#endif atomOffset = 0; + groupOffset = 0; for (i = 0; i < info[k].n_mol; i++){ stampID = info[k].molecules[i].getStampID(); @@ -218,22 +238,23 @@ void SimSetup::makeMolecules(void){ molInfo.nBends = comp_stamps[stampID]->getNBends(); molInfo.nTorsions = comp_stamps[stampID]->getNTorsions(); molInfo.nRigidBodies = comp_stamps[stampID]->getNRigidBodies(); - molInfo.nCutoffGroups = comp_stamps[stampID]->getNCutoffGroups(); + + nCutoffGroups = comp_stamps[stampID]->getNCutoffGroups(); molInfo.myAtoms = &(info[k].atoms[atomOffset]); if (molInfo.nBonds > 0) - molInfo.myBonds = new (Bond *) [molInfo.nBonds]; + molInfo.myBonds = new Bond*[molInfo.nBonds]; else molInfo.myBonds = NULL; if (molInfo.nBends > 0) - molInfo.myBends = new (Bend *) [molInfo.nBends]; + molInfo.myBends = new Bend*[molInfo.nBends]; else molInfo.myBends = NULL; if (molInfo.nTorsions > 0) - molInfo.myTorsions = new (Torsion *) [molInfo.nTorsions]; + molInfo.myTorsions = new Torsion *[molInfo.nTorsions]; else molInfo.myTorsions = NULL; @@ -271,9 +292,7 @@ void SimSetup::makeMolecules(void){ molInfo.myAtoms[j]->setType(currentAtom->getType()); #ifdef IS_MPI - molInfo.myAtoms[j]->setGlobalIndex(globalAtomIndex[j + atomOffset]); - #endif // is_mpi } @@ -485,14 +504,23 @@ void SimSetup::makeMolecules(void){ //create cutoff group for molecule + + cutoffAtomSet.clear(); molInfo.myCutoffGroups.clear(); - for (j = 0; j < molInfo.nCutoffGroups; j++){ + + for (j = 0; j < nCutoffGroups; j++){ currentCutoffGroup = comp_stamps[stampID]->getCutoffGroup(j); nMembers = currentCutoffGroup->getNMembers(); myCutoffGroup = new CutoffGroup(); +#ifdef IS_MPI + myCutoffGroup->setGlobalIndex(globalGroupIndex[j + groupOffset]); +#else + myCutoffGroup->setGlobalIndex(j + groupOffset); +#endif + for (int cg = 0; cg < nMembers; cg++) { // molI is atom numbering inside this molecule @@ -501,13 +529,48 @@ void SimSetup::makeMolecules(void){ // tempI is atom numbering on local processor tempI = molI + atomOffset; +#ifdef IS_MPI + globalID = info[k].atoms[tempI]->getGlobalIndex(); + info[k].globalGroupMembership[globalID] = globalGroupIndex[j+groupOffset]; +#else + globalID = info[k].atoms[tempI]->getIndex(); + info[k].globalGroupMembership[globalID] = j + groupOffset; +#endif + + + myCutoffGroup->addAtom(info[k].atoms[tempI]); + + cutoffAtomSet.insert(tempI); } - + molInfo.myCutoffGroups.push_back(myCutoffGroup); + groupOffset++; + }//end for (j = 0; j < molInfo.nCutoffGroups; j++) + //creat a cutoff group for every atom in current molecule which does not belong to cutoffgroup defined at mdl file + + for(j = 0; j < molInfo.nAtoms; j++){ + + if(cutoffAtomSet.find(molInfo.myAtoms[j]->getIndex()) == cutoffAtomSet.end()){ + myCutoffGroup = new CutoffGroup(); + myCutoffGroup->addAtom(molInfo.myAtoms[j]); +#ifdef IS_MPI + myCutoffGroup->setGlobalIndex(globalGroupIndex[j + groupOffset]); + globalID = info[k].atoms[atomOffset + j]->getGlobalIndex(); + info[k].globalGroupMembership[globalID] = globalGroupIndex[j+groupOffset]; +#else + myCutoffGroup->setGlobalIndex(j + groupOffset); + globalID = info[k].atoms[atomOffset + j]->getIndex(); + info[k].globalGroupMembership[globalID] = j+groupOffset; +#endif + molInfo.myCutoffGroups.push_back(myCutoffGroup); + groupOffset++; + } + + } // After this is all set up, scan through the atoms to // see if they can be added to the integrableObjects: @@ -539,8 +602,54 @@ void SimSetup::makeMolecules(void){ info[k].integrableObjects.push_back(mySD); molInfo.myIntegrableObjects.push_back(mySD); } - + + + /* + + //creat ConstraintPair. + molInfo.myConstraintPair.clear(); + for (j = 0; j < molInfo.nBonds; j++){ + + //if both atoms are in the same rigid body, just skip it + currentBond = comp_stamps[stampID]->getBond(j); + if(!comp_stamps[stampID]->isBondInSameRigidBody(currentBond)){ + + tempI = currentBond->getA() + atomOffset; + if( comp_stamps[stampID]->isAtomInRigidBody(currentBond->getA(), whichRigidBody, consAtomIndex)) + consElement1 = new ConstraintRigidBody(molInfo.myRigidBodies[whichRigidBody], consAtomIndex); + else + consElement1 = new ConstraintAtom(info[k].atoms[tempI]); + + tempJ = currentBond->getB() + atomOffset; + if(comp_stamps[stampID]->isAtomInRigidBody(currentBond->getB(), whichRigidBody, consAtomIndex)) + consElement2 = new ConstraintRigidBody(molInfo.myRigidBodies[whichRigidBody], consAtomIndex); + else + consElement2 = new ConstraintAtom(info[k].atoms[tempJ]); + + consPair = new DistanceConstraintPair(consElement1, consElement2); + molInfo.myConstraintPairs.push_back(consPair); + } + } + + //loop over rigid bodies, if two rigid bodies share same joint, creat a HingeConstraintPair + for (int rb1 = 0; rb1 < molInfo.nRigidBodies -1 ; rb1++){ + for (int rb2 = rb1 + 1; rb2 < molInfo.nRigidBodies ; rb2++){ + + jointAtoms = comp_stamps[stampID]->getJointAtoms(rb1, rb2); + + for(size_t m = 0; m < jointAtoms.size(); m++){ + consElement1 = new ConstraintRigidBody(molInfo.myRigidBodies[rb1], jointAtoms[m].first); + consElement2 = new ConstraintRigidBody(molInfo.myRigidBodies[rb2], jointAtoms[m].second); + + consPair = new JointConstraintPair(consElement1, consElement2); + molInfo.myConstraintPairs.push_back(consPair); + } + + } + } + +*/ // send the arrays off to the forceField for init. the_ff->initializeAtoms(molInfo.nAtoms, molInfo.myAtoms); @@ -550,13 +659,39 @@ void SimSetup::makeMolecules(void){ theTorsions); info[k].molecules[i].initialize(molInfo); - - + + atomOffset += molInfo.nAtoms; delete[] theBonds; delete[] theBends; delete[] theTorsions; - } + } + + + +#ifdef IS_MPI + // Since the globalGroupMembership has been zero filled and we've only + // poked values into the atoms we know, we can do an Allreduce + // to get the full globalGroupMembership array (We think). + // This would be prettier if we could use MPI_IN_PLACE like the MPI-2 + // docs said we could. + + int* ggMjunk = new int[mpiSim->getNAtomsGlobal()]; + + MPI_Allreduce(info[k].globalGroupMembership, + ggMjunk, + mpiSim->getNAtomsGlobal(), + MPI_INT, MPI_SUM, MPI_COMM_WORLD); + + for (i = 0; i < mpiSim->getNAtomsGlobal(); i++) + info[k].globalGroupMembership[i] = ggMjunk[i]; + + delete[] ggMjunk; + +#endif + + + } #ifdef IS_MPI @@ -927,7 +1062,67 @@ void SimSetup::gatherInfo(void){ info[i].useInitXSstate = globals->getUseInitXSstate(); info[i].orthoTolerance = globals->getOrthoBoxTolerance(); - + + // check for thermodynamic integration + if (globals->getUseSolidThermInt() && !globals->getUseLiquidThermInt()) { + if (globals->haveThermIntLambda() && globals->haveThermIntK()) { + info[i].useSolidThermInt = globals->getUseSolidThermInt(); + info[i].thermIntLambda = globals->getThermIntLambda(); + info[i].thermIntK = globals->getThermIntK(); + + Restraints *myRestraint = new Restraints(tot_nmol, info[i].thermIntLambda, info[i].thermIntK); + info[i].restraint = myRestraint; + } + else { + sprintf(painCave.errMsg, + "SimSetup Error:\n" + "\tKeyword useSolidThermInt was set to 'true' but\n" + "\tthermodynamicIntegrationLambda (and/or\n" + "\tthermodynamicIntegrationK) was not specified.\n" + "\tPlease provide a lambda value and k value in your .bass file.\n"); + painCave.isFatal = 1; + simError(); + } + } + else if(globals->getUseLiquidThermInt()) { + if (globals->getUseSolidThermInt()) { + sprintf( painCave.errMsg, + "SimSetup Warning: It appears that you have both solid and\n" + "\tliquid thermodynamic integration activated in your .bass\n" + "\tfile. To avoid confusion, specify only one technique in\n" + "\tyour .bass file. Liquid-state thermodynamic integration\n" + "\twill be assumed for the current simulation. If this is not\n" + "\twhat you desire, set useSolidThermInt to 'true' and\n" + "\tuseLiquidThermInt to 'false' in your .bass file.\n"); + painCave.isFatal = 0; + simError(); + } + if (globals->haveThermIntLambda() && globals->haveThermIntK()) { + info[i].useLiquidThermInt = globals->getUseLiquidThermInt(); + info[i].thermIntLambda = globals->getThermIntLambda(); + info[i].thermIntK = globals->getThermIntK(); + } + else { + sprintf(painCave.errMsg, + "SimSetup Error:\n" + "\tKeyword useLiquidThermInt was set to 'true' but\n" + "\tthermodynamicIntegrationLambda (and/or\n" + "\tthermodynamicIntegrationK) was not specified.\n" + "\tPlease provide a lambda value and k value in your .bass file.\n"); + painCave.isFatal = 1; + simError(); + } + } + else if(globals->haveThermIntLambda() || globals->haveThermIntK()){ + sprintf(painCave.errMsg, + "SimSetup Warning: If you want to use Thermodynamic\n" + "\tIntegration, set useSolidThermInt or useLiquidThermInt to\n" + "\t'true' in your .bass file. These keywords are set to\n" + "\t'false' by default, so your lambda and/or k values are\n" + "\tbeing ignored.\n"); + painCave.isFatal = 0; + simError(); + } } //setup seed for random number generator @@ -1240,6 +1435,28 @@ void SimSetup::makeOutNames(void){ } } + strcpy(info[k].rawPotName, inFileName); + nameLength = strlen(info[k].rawPotName); + endTest = &(info[k].rawPotName[nameLength - 5]); + if (!strcmp(endTest, ".bass")){ + strcpy(endTest, ".raw"); + } + else if (!strcmp(endTest, ".BASS")){ + strcpy(endTest, ".raw"); + } + else{ + endTest = &(info[k].rawPotName[nameLength - 4]); + if (!strcmp(endTest, ".bss")){ + strcpy(endTest, ".raw"); + } + else if (!strcmp(endTest, ".mdl")){ + strcpy(endTest, ".raw"); + } + else{ + strcat(info[k].rawPotName, ".raw"); + } + } + #ifdef IS_MPI } @@ -1377,21 +1594,33 @@ void SimSetup::calcSysValues(void){ } void SimSetup::calcSysValues(void){ - int i; + int i, j; + int ncutgroups, atomsingroups, ngroupsinstamp; int* molMembershipArray; + CutoffGroupStamp* cg; tot_atoms = 0; tot_bonds = 0; tot_bends = 0; tot_torsions = 0; tot_rigid = 0; + tot_groups = 0; for (i = 0; i < n_components; i++){ tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms(); tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds(); tot_bends += components_nmol[i] * comp_stamps[i]->getNBends(); tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions(); tot_rigid += components_nmol[i] * comp_stamps[i]->getNRigidBodies(); + + ncutgroups = comp_stamps[i]->getNCutoffGroups(); + atomsingroups = 0; + for (j=0; j < ncutgroups; j++) { + cg = comp_stamps[i]->getCutoffGroup(j); + atomsingroups += cg->getNMembers(); + } + ngroupsinstamp = comp_stamps[i]->getNAtoms() - atomsingroups + ncutgroups; + tot_groups += components_nmol[i] * ngroupsinstamp; } tot_SRI = tot_bonds + tot_bends + tot_torsions; @@ -1404,7 +1633,7 @@ void SimSetup::calcSysValues(void){ info[i].n_torsions = tot_torsions; info[i].n_SRI = tot_SRI; info[i].n_mol = tot_nmol; - + info[i].ngroup = tot_groups; info[i].molMembershipArray = molMembershipArray; } } @@ -1415,13 +1644,16 @@ void SimSetup::mpiMolDivide(void){ int i, j, k; int localMol, allMol; int local_atoms, local_bonds, local_bends, local_torsions, local_SRI; - int local_rigid; + int local_rigid, local_groups; vector globalMolIndex; + int ncutgroups, atomsingroups, ngroupsinstamp; + CutoffGroupStamp* cg; mpiSim = new mpiSimulation(info); mpiSim->divideLabor(); globalAtomIndex = mpiSim->getGlobalAtomIndex(); + globalGroupIndex = mpiSim->getGlobalGroupIndex(); //globalMolIndex = mpiSim->getGlobalMolIndex(); // set up the local variables @@ -1436,6 +1668,7 @@ void SimSetup::mpiMolDivide(void){ local_bends = 0; local_torsions = 0; local_rigid = 0; + local_groups = 0; globalAtomCounter = 0; for (i = 0; i < n_components; i++){ @@ -1446,6 +1679,17 @@ void SimSetup::mpiMolDivide(void){ local_bends += comp_stamps[i]->getNBends(); local_torsions += comp_stamps[i]->getNTorsions(); local_rigid += comp_stamps[i]->getNRigidBodies(); + + ncutgroups = comp_stamps[i]->getNCutoffGroups(); + atomsingroups = 0; + for (k=0; k < ncutgroups; k++) { + cg = comp_stamps[i]->getCutoffGroup(k); + atomsingroups += cg->getNMembers(); + } + ngroupsinstamp = comp_stamps[i]->getNAtoms() - atomsingroups + + ncutgroups; + local_groups += ngroupsinstamp; + localMol++; } for (k = 0; k < comp_stamps[i]->getNAtoms(); k++){ @@ -1458,9 +1702,8 @@ void SimSetup::mpiMolDivide(void){ } local_SRI = local_bonds + local_bends + local_torsions; - info[0].n_atoms = mpiSim->getMyNlocal(); + info[0].n_atoms = mpiSim->getNAtomsLocal(); - if (local_atoms != info[0].n_atoms){ sprintf(painCave.errMsg, "SimSetup error: mpiSim's localAtom (%d) and SimSetup's\n" @@ -1470,6 +1713,16 @@ void SimSetup::mpiMolDivide(void){ simError(); } + info[0].ngroup = mpiSim->getNGroupsLocal(); + if (local_groups != info[0].ngroup){ + sprintf(painCave.errMsg, + "SimSetup error: mpiSim's localGroups (%d) and SimSetup's\n" + "\tlocalGroups (%d) are not equal.\n", + info[0].ngroup, local_groups); + painCave.isFatal = 1; + simError(); + } + info[0].n_bonds = local_bonds; info[0].n_bends = local_bends; info[0].n_torsions = local_torsions; @@ -1506,7 +1759,7 @@ void SimSetup::makeSysArrays(void){ molIndex = 0; - for (i = 0; i < mpiSim->getTotNmol(); i++){ + for (i = 0; i < mpiSim->getNMolGlobal(); i++){ if (mol2proc[i] == worldRank){ the_molecules[molIndex].setStampID(molCompType[i]); the_molecules[molIndex].setMyIndex(molIndex);