--- trunk/OOPSE-1.0/utils/sysbuilder/simpleBuilder.cpp 2004/07/29 18:01:05 1434 +++ trunk/OOPSE-1.0/utils/sysbuilder/simpleBuilder.cpp 2004/07/29 18:16:16 1435 @@ -29,11 +29,8 @@ int main( int argc, char* argv[]){ string inputFileName; string outPrefix; string outMdFileName; - string outInitFileName; SimInfo* oldInfo; - SimInfo* newInfo; SimSetup* oldSimSetup; - SimSetup* newSimSetup; BaseLattice* simpleLat; int numMol; double latticeConstant; @@ -116,7 +113,6 @@ int main( int argc, char* argv[]){ outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType; outMdFileName = outPrefix + ".md"; - outInitFileName = outPrefix + ".in"; //parse md file and set up the system oldInfo = new SimInfo; @@ -130,15 +126,16 @@ int main( int argc, char* argv[]){ cerr << "error in creating SimSetup" << endl; exit(1); } - + + oldSimSetup->suspendInit(); oldSimSetup->setSimInfo(oldInfo ); oldSimSetup->parseFile(&inputFileName[0] ); oldSimSetup->createSim(); + if(oldInfo->nComponents >=2){ cerr << "can not build the system with more than two components" << endl; exit(1); } - //get mass of molecule. //Due to the design of OOPSE, given atom type, we have to query forcefiled to get the mass @@ -161,51 +158,39 @@ int main( int argc, char* argv[]){ simpleLat->setLatticeConstant(lc); //calculate the total number of molecules - numMol = args_info.nx_arg * args_info.ny_arg * args_info.nz_arg * numMolPerCell; - - //creat new .md file on fly - createMdFile(inputFileName, outMdFileName, numMol); + numMol = nx * ny * nz * numMolPerCell; - //parse new .md file and set up the system - newInfo = new SimInfo; - if(newInfo == NULL){ - cerr << "error in creating SimInfo" << endl; - exit(1); + if (oldInfo->n_mol != numMol){ + //creat new .md file on fly which corrects the number of molecule + createMdFile(inputFileName, outMdFileName, numMol); + cerr << "SimpleBuilder Error: the number of molecule and the density are not matched" <setSimInfo(newInfo ); - newSimSetup->parseFile(&outMdFileName[0] ); - newSimSetup->createSim(); //allocat memory for storing pos, vel and etc - newInfo->getConfiguration()->createArrays(newInfo->n_atoms); - for (int i = 0; i < newInfo->n_atoms; i++) - newInfo->atoms[i]->setCoords(); + oldInfo->getConfiguration()->createArrays(oldInfo->n_atoms); + for (int i = 0; i < oldInfo->n_atoms; i++) + oldInfo->atoms[i]->setCoords(); //creat Molocator - locator = new MoLocator(newInfo->compStamps[0], newSimSetup->getForceField()); + locator = new MoLocator(oldInfo->compStamps[0], oldSimSetup->getForceField()); //fill Hmat Hmat[0][0] = nx * latticeConstant; Hmat[0][1] = 0.0; Hmat[0][2] = 0.0; - Hmat[1][0] = ny * latticeConstant; - Hmat[1][1] = 0.0; + Hmat[1][0] = 0.0; + Hmat[1][1] = ny * latticeConstant; Hmat[1][2] = 0.0; - Hmat[2][0] = nz * latticeConstant; + Hmat[2][0] = 0.0; Hmat[2][1] = 0.0; - Hmat[2][2] = 0.0; + Hmat[2][2] = nz * latticeConstant ; //set Hmat - newInfo->setBoxM(Hmat); + oldInfo->setBoxM(Hmat); //place the molecules @@ -223,13 +208,13 @@ int main( int argc, char* argv[]){ simpleLat->getLatticePointsPos(latticePos, i, j, k); for(int l = 0; l < numMolPerCell; l++) - locator->placeMol(latticePos[l], latticeOrt[l], &(newInfo->molecules[curMolIndex++])); + locator->placeMol(latticePos[l], latticeOrt[l], &(oldInfo->molecules[curMolIndex++])); } } } //create dumpwriter and write out the coordinates - writer = new DumpWriter( newInfo ); + writer = new DumpWriter( oldInfo ); if(writer == NULL){ cerr << "error in creating DumpWriter" << endl; exit(1); @@ -237,18 +222,14 @@ int main( int argc, char* argv[]){ writer->writeFinal(0); //delete objects - if(!oldInfo) + + //delete oldInfo and oldSimSetup + if(oldInfo != NULL) delete oldInfo; - if(!oldSimSetup) - delete oldSimSetup; - - if(!newInfo) - delete newInfo; + if(oldSimSetup != NULL) + delete oldSimSetup; - if(!newSimSetup) - delete newSimSetup; - if (writer != NULL) delete writer; return 0; @@ -259,7 +240,6 @@ void createMdFile(const string& oldMdFileName, const s ofstream newMdFile; const int MAXLEN = 65535; char buffer[MAXLEN]; - string line; //create new .md file based on old .md file oldMdFile.open(oldMdFileName.c_str()); @@ -268,8 +248,8 @@ void createMdFile(const string& oldMdFileName, const s oldMdFile.getline(buffer, MAXLEN); while(!oldMdFile.eof()){ - if(line.find("nMol") < line.size()){ - + //correct molecule number + if(strstr(buffer, "nMol") !=NULL){ sprintf(buffer, "\t\tnMol = %d;", numMol); newMdFile << buffer << endl; }