--- trunk/OOPSE-1.0/libmdtools/SimSetup.cpp 2004/07/26 17:50:57 1415 +++ trunk/OOPSE-1.0/libmdtools/SimSetup.cpp 2004/08/09 14:50:35 1451 @@ -57,6 +57,28 @@ bool isDivisible(double dividend, double divisor){ return false; } +string getPrefix(const string& str ){ + string prefix; + string suffix; + int pos; + + pos = str.rfind("."); + + if (pos >= 0) { + prefix = str.substr(0, pos); + suffix = str.substr(pos, str.size()); + + // leave .bass there in case we've reverted to old habits + if (LowerCase(suffix) == ".md" || LowerCase(suffix) == ".bass") + return prefix; + else + return str; + + } else + return str; +}; + + SimSetup::SimSetup(){ initSuspend = false; @@ -74,6 +96,9 @@ SimSetup::~SimSetup(){ } SimSetup::~SimSetup(){ + // clean up the forcefield + the_ff->cleanMe(); + delete stamps; delete globals; } @@ -92,6 +117,8 @@ void SimSetup::parseFile(char* fileName){ #endif // is_mpi inFileName = fileName; + + globals->initalize(); set_interface_stamps(stamps, globals); #ifdef IS_MPI @@ -122,7 +149,7 @@ void SimSetup::createSim(void){ void SimSetup::createSim(void){ - // gather all of the information from the Bass file + // gather all of the information from the meta-data file gatherInfo(); @@ -643,178 +670,9 @@ void SimSetup::makeMolecules(void){ sprintf(checkPointMsg, "all molecules initialized succesfully"); MPIcheckPoint(); #endif // is_mpi - -} - -void SimSetup::initFromBass(void){ - int i, j, k; - int n_cells; - double cellx, celly, cellz; - double temp1, temp2, temp3; - int n_per_extra; - int n_extra; - int have_extra, done; - - double vel[3]; - vel[0] = 0.0; - vel[1] = 0.0; - vel[2] = 0.0; - - temp1 = (double) tot_nmol / 4.0; - temp2 = pow(temp1, (1.0 / 3.0)); - temp3 = ceil(temp2); - - have_extra = 0; - if (temp2 < temp3){ - // we have a non-complete lattice - have_extra = 1; - - n_cells = (int) temp3 - 1; - cellx = info[0].boxL[0] / temp3; - celly = info[0].boxL[1] / temp3; - cellz = info[0].boxL[2] / temp3; - n_extra = tot_nmol - (4 * n_cells * n_cells * n_cells); - temp1 = ((double) n_extra) / (pow(temp3, 3.0) - pow(n_cells, 3.0)); - n_per_extra = (int) ceil(temp1); - - if (n_per_extra > 4){ - sprintf(painCave.errMsg, - "SimSetup error. There has been an error in constructing" - " the non-complete lattice.\n"); - painCave.isFatal = 1; - simError(); - } - } - else{ - n_cells = (int) temp3; - cellx = info[0].boxL[0] / temp3; - celly = info[0].boxL[1] / temp3; - cellz = info[0].boxL[2] / temp3; - } - - current_mol = 0; - current_comp_mol = 0; - current_comp = 0; - current_atom_ndx = 0; - - for (i = 0; i < n_cells ; i++){ - for (j = 0; j < n_cells; j++){ - for (k = 0; k < n_cells; k++){ - makeElement(i * cellx, j * celly, k * cellz); - makeElement(i * cellx + 0.5 * cellx, j * celly + 0.5 * celly, k * cellz); - - makeElement(i * cellx, j * celly + 0.5 * celly, k * cellz + 0.5 * cellz); - - makeElement(i * cellx + 0.5 * cellx, j * celly, k * cellz + 0.5 * cellz); - } - } - } - - if (have_extra){ - done = 0; - - int start_ndx; - for (i = 0; i < (n_cells + 1) && !done; i++){ - for (j = 0; j < (n_cells + 1) && !done; j++){ - if (i < n_cells){ - if (j < n_cells){ - start_ndx = n_cells; - } - else - start_ndx = 0; - } - else - start_ndx = 0; - - for (k = start_ndx; k < (n_cells + 1) && !done; k++){ - makeElement(i * cellx, j * celly, k * cellz); - done = (current_mol >= tot_nmol); - - if (!done && n_per_extra > 1){ - makeElement(i * cellx + 0.5 * cellx, j * celly + 0.5 * celly, - k * cellz); - done = (current_mol >= tot_nmol); - } - - if (!done && n_per_extra > 2){ - makeElement(i * cellx, j * celly + 0.5 * celly, - k * cellz + 0.5 * cellz); - done = (current_mol >= tot_nmol); - } - - if (!done && n_per_extra > 3){ - makeElement(i * cellx + 0.5 * cellx, j * celly, - k * cellz + 0.5 * cellz); - done = (current_mol >= tot_nmol); - } - } - } - } - } - - for (i = 0; i < info[0].n_atoms; i++){ - info[0].atoms[i]->setVel(vel); - } } -void SimSetup::makeElement(double x, double y, double z){ - int k; - AtomStamp* current_atom; - DirectionalAtom* dAtom; - double rotMat[3][3]; - double pos[3]; - - for (k = 0; k < comp_stamps[current_comp]->getNAtoms(); k++){ - current_atom = comp_stamps[current_comp]->getAtom(k); - if (!current_atom->havePosition()){ - sprintf(painCave.errMsg, - "SimSetup:initFromBass error.\n" - "\tComponent %s, atom %s does not have a position specified.\n" - "\tThe initialization routine is unable to give a start" - " position.\n", - comp_stamps[current_comp]->getID(), current_atom->getType()); - painCave.isFatal = 1; - simError(); - } - - pos[0] = x + current_atom->getPosX(); - pos[1] = y + current_atom->getPosY(); - pos[2] = z + current_atom->getPosZ(); - - info[0].atoms[current_atom_ndx]->setPos(pos); - - if (info[0].atoms[current_atom_ndx]->isDirectional()){ - dAtom = (DirectionalAtom *) info[0].atoms[current_atom_ndx]; - - rotMat[0][0] = 1.0; - rotMat[0][1] = 0.0; - rotMat[0][2] = 0.0; - - rotMat[1][0] = 0.0; - rotMat[1][1] = 1.0; - rotMat[1][2] = 0.0; - - rotMat[2][0] = 0.0; - rotMat[2][1] = 0.0; - rotMat[2][2] = 1.0; - - dAtom->setA(rotMat); - } - - current_atom_ndx++; - } - - current_mol++; - current_comp_mol++; - - if (current_comp_mol >= components_nmol[current_comp]){ - current_comp_mol = 0; - current_comp++; - } -} - - void SimSetup::gatherInfo(void){ int i; @@ -974,7 +832,6 @@ void SimSetup::gatherInfo(void){ } } - for (i=0; i < nInfo; i++) { // check for the temperature set flag @@ -994,7 +851,7 @@ void SimSetup::gatherInfo(void){ info[i].thermIntLambda = globals->getThermIntLambda(); info[i].thermIntK = globals->getThermIntK(); - Restraints *myRestraint = new Restraints(tot_nmol, info[i].thermIntLambda, info[i].thermIntK); + Restraints *myRestraint = new Restraints(info[i].thermIntLambda, info[i].thermIntK); info[i].restraint = myRestraint; } else { @@ -1003,7 +860,7 @@ void SimSetup::gatherInfo(void){ "\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"); + "\tPlease provide a lambda value and k value in your meta-data file.\n"); painCave.isFatal = 1; simError(); } @@ -1012,12 +869,12 @@ void SimSetup::gatherInfo(void){ 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" + "\tliquid thermodynamic integration activated in your meta-data\n" "\tfile. To avoid confusion, specify only one technique in\n" - "\tyour .bass file. Liquid-state thermodynamic integration\n" + "\tyour meta-data 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"); + "\tuseLiquidThermInt to 'false' in your meta-data file.\n"); painCave.isFatal = 0; simError(); } @@ -1032,7 +889,7 @@ void SimSetup::gatherInfo(void){ "\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"); + "\tPlease provide a lambda value and k value in your meta-data file.\n"); painCave.isFatal = 1; simError(); } @@ -1041,7 +898,7 @@ void SimSetup::gatherInfo(void){ 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'true' in your meta-data 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; @@ -1136,7 +993,7 @@ void SimSetup::gatherInfo(void){ } #ifdef IS_MPI - strcpy(checkPointMsg, "Successfully gathered all information from Bass\n"); + strcpy(checkPointMsg, "Successfully gathered all information from meta-data file\n"); MPIcheckPoint(); #endif // is_mpi } @@ -1273,8 +1130,6 @@ void SimSetup::finalInfoCheck(void){ MPIcheckPoint(); #endif // is_mpi - // clean up the forcefield - the_ff->cleanMe(); } void SimSetup::initSystemCoords(void){ @@ -1305,7 +1160,7 @@ void SimSetup::initSystemCoords(void){ } else{ - // no init from bass + // no init from md file sprintf(painCave.errMsg, "Cannot intialize a simulation without an initial configuration file.\n"); @@ -1323,109 +1178,21 @@ void SimSetup::makeOutNames(void){ void SimSetup::makeOutNames(void){ int k; + string prefix; - for (k = 0; k < nInfo; k++){ #ifdef IS_MPI if (worldRank == 0){ #endif // is_mpi - - if (globals->haveFinalConfig()){ - strcpy(info[k].finalName, globals->getFinalConfig()); - } - else{ - strcpy(info[k].finalName, inFileName); - char* endTest; - int nameLength = strlen(info[k].finalName); - endTest = &(info[k].finalName[nameLength - 5]); - if (!strcmp(endTest, ".bass")){ - strcpy(endTest, ".eor"); - } - else if (!strcmp(endTest, ".BASS")){ - strcpy(endTest, ".eor"); - } - else{ - endTest = &(info[k].finalName[nameLength - 4]); - if (!strcmp(endTest, ".bss")){ - strcpy(endTest, ".eor"); - } - else if (!strcmp(endTest, ".mdl")){ - strcpy(endTest, ".eor"); - } - else{ - strcat(info[k].finalName, ".eor"); - } - } - } + + if(globals->haveFinalConfig()) + prefix = getPrefix(globals->getFinalConfig()); + else + prefix = getPrefix(inFileName); - // make the sample and status out names - - strcpy(info[k].sampleName, inFileName); - char* endTest; - int nameLength = strlen(info[k].sampleName); - endTest = &(info[k].sampleName[nameLength - 5]); - if (!strcmp(endTest, ".bass")){ - strcpy(endTest, ".dump"); - } - else if (!strcmp(endTest, ".BASS")){ - strcpy(endTest, ".dump"); - } - else{ - endTest = &(info[k].sampleName[nameLength - 4]); - if (!strcmp(endTest, ".bss")){ - strcpy(endTest, ".dump"); - } - else if (!strcmp(endTest, ".mdl")){ - strcpy(endTest, ".dump"); - } - else{ - strcat(info[k].sampleName, ".dump"); - } - } - - strcpy(info[k].statusName, inFileName); - nameLength = strlen(info[k].statusName); - endTest = &(info[k].statusName[nameLength - 5]); - if (!strcmp(endTest, ".bass")){ - strcpy(endTest, ".stat"); - } - else if (!strcmp(endTest, ".BASS")){ - strcpy(endTest, ".stat"); - } - else{ - endTest = &(info[k].statusName[nameLength - 4]); - if (!strcmp(endTest, ".bss")){ - strcpy(endTest, ".stat"); - } - else if (!strcmp(endTest, ".mdl")){ - strcpy(endTest, ".stat"); - } - else{ - strcat(info[k].statusName, ".stat"); - } - } - - 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"); - } - } + info[k].finalName = prefix + ".eor"; + info[k].sampleName = prefix + ".dump"; + info[k].statusName = prefix + ".stat"; #ifdef IS_MPI @@ -1853,7 +1620,7 @@ void SimSetup::makeIntegrator(void){ else{ sprintf(painCave.errMsg, "SimSetup error: If you use a constant pressure\n" - "\tensemble, you must set targetPressure in the BASS file.\n"); + "\tensemble, you must set targetPressure in the meta-data file.\n"); painCave.isFatal = 1; simError(); } @@ -1904,7 +1671,7 @@ void SimSetup::makeIntegrator(void){ else{ sprintf(painCave.errMsg, "SimSetup error: If you use a constant pressure\n" - "\tensemble, you must set targetPressure in the BASS file.\n"); + "\tensemble, you must set targetPressure in the meta-data file.\n"); painCave.isFatal = 1; simError(); } @@ -1957,7 +1724,7 @@ void SimSetup::makeIntegrator(void){ else{ sprintf(painCave.errMsg, "SimSetup error: If you use a constant pressure\n" - "\tensemble, you must set targetPressure in the BASS file.\n"); + "\tensemble, you must set targetPressure in the meta-data file.\n"); painCave.isFatal = 1; simError(); }