--- trunk/OOPSE/libmdtools/SimSetup.cpp 2003/08/07 21:47:18 670 +++ trunk/OOPSE/libmdtools/SimSetup.cpp 2003/08/12 17:51:33 682 @@ -22,12 +22,6 @@ #define NPTf_ENS 3 #define NPTim_ENS 4 #define NPTfm_ENS 5 -#define NVEZCONS_ENS 6 -#define NVTZCONS_ENS 7 -#define NPTiZCONS_ENS 8 -#define NPTfZCONS_ENS 9 -#define NPTimZCONS_ENS 10 -#define NPTfmZCONS_ENS 11 #define FF_DUFF 0 #define FF_LJ 1 @@ -639,15 +633,6 @@ void SimSetup::gatherInfo( void ){ else if( !strcasecmp( ensemble, "NPTf" )) ensembleCase = NPTf_ENS; else if( !strcasecmp( ensemble, "NPTim" )) ensembleCase = NPTim_ENS; else if( !strcasecmp( ensemble, "NPTfm" )) ensembleCase = NPTfm_ENS; - - else if( !strcasecmp( ensemble, "NVEZCONS")) ensembleCase = NVEZCONS_ENS; - else if( !strcasecmp( ensemble, "NVTZCONS")) ensembleCase = NVTZCONS_ENS; - else if( !strcasecmp( ensemble, "NPTiZCONS") || !strcasecmp( ensemble, "NPTZCONS")) - ensembleCase = NPTiZCONS_ENS; - else if( !strcasecmp( ensemble, "NPTfZCONS")) ensembleCase = NPTfZCONS_ENS; - else if( !strcasecmp( ensemble, "NPTimZCONS")) ensembleCase = NPTimZCONS_ENS; - else if( !strcasecmp( ensemble, "NPTfmZCONS")) ensembleCase = NPTfmZCONS_ENS; - else{ sprintf( painCave.errMsg, "SimSetup Warning. Unrecognized Ensemble -> %s, " @@ -1367,23 +1352,29 @@ void SimSetup::makeIntegrator( void ){ NPTf* myNPTf = NULL; NPTim* myNPTim = NULL; NPTfm* myNPTfm = NULL; - ZConstraint >* myNVEZCons = NULL; - ZConstraint >* myNVTZCons = NULL; - ZConstraint >* myNPTiZCons = NULL; - ZConstraint >* myNPTfZCons = NULL; - ZConstraint >* myNPTimZCons = NULL; - ZConstraint >* myNPTfmZCons = NULL; for(k=0; k( &(info[k]), the_ff ); + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + new ZConstraint >( &(info[k]), the_ff ); + } + + else + new NVE( &(info[k]), the_ff ); break; case NVT_ENS: - myNVT = new NVT( &(info[k]), the_ff ); + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNVT = new ZConstraint >( &(info[k]), the_ff ); + } + else + myNVT = new NVT( &(info[k]), the_ff ); + myNVT->setTargetTemp(globals->getTargetTemp()); if (globals->haveTauThermostat()) @@ -1399,8 +1390,14 @@ void SimSetup::makeIntegrator( void ){ break; case NPTi_ENS: - myNPTi = new NPTi( &(info[k]), the_ff ); - myNPTi->setTargetTemp( globals->getTargetTemp() ); + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNPTi = new ZConstraint >( &(info[k]), the_ff ); + } + else + myNPTi = new NPTi( &(info[k]), the_ff ); + + myNPTi->setTargetTemp( globals->getTargetTemp() ); if (globals->haveTargetPressure()) myNPTi->setTargetPressure(globals->getTargetPressure()); @@ -1434,7 +1431,13 @@ void SimSetup::makeIntegrator( void ){ break; case NPTf_ENS: - myNPTf = new NPTf( &(info[k]), the_ff ); + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNPTf = new ZConstraint >( &(info[k]), the_ff ); + } + else + myNPTf = new NPTf( &(info[k]), the_ff ); + myNPTf->setTargetTemp( globals->getTargetTemp()); if (globals->haveTargetPressure()) @@ -1469,8 +1472,14 @@ void SimSetup::makeIntegrator( void ){ break; case NPTim_ENS: - myNPTim = new NPTim( &(info[k]), the_ff ); - myNPTim->setTargetTemp( globals->getTargetTemp()); + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNPTim = new ZConstraint >( &(info[k]), the_ff ); + } + else + myNPTim = new NPTim( &(info[k]), the_ff ); + + myNPTim->setTargetTemp( globals->getTargetTemp()); if (globals->haveTargetPressure()) myNPTim->setTargetPressure(globals->getTargetPressure()); @@ -1504,8 +1513,14 @@ void SimSetup::makeIntegrator( void ){ break; case NPTfm_ENS: - myNPTfm = new NPTfm( &(info[k]), the_ff ); - myNPTfm->setTargetTemp( globals->getTargetTemp()); + if (globals->haveZconstraints()){ + setupZConstraint(info[k]); + myNPTfm = new ZConstraint >( &(info[k]), the_ff ); + } + else + myNPTfm = new NPTfm( &(info[k]), the_ff ); + + myNPTfm->setTargetTemp( globals->getTargetTemp()); if (globals->haveTargetPressure()) myNPTfm->setTargetPressure(globals->getTargetPressure()); @@ -1529,204 +1544,15 @@ void SimSetup::makeIntegrator( void ){ if( globals->haveTauBarostat() ) myNPTfm->setTauBarostat( globals->getTauBarostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauBarostat.\n"); - painCave.isFatal = 1; - simError(); - } - break; - - case NVEZCONS_ENS: - - - //setup index of z-constraint molecules, z-constraint sampel time - //and z-constraint force output name. These parameter should be known - //before constructing the z-constraint integrator - setupZConstraint(); - - myNVEZCons = new ZConstraint >( &(info[k]), the_ff ); - - break; - - - case NVTZCONS_ENS: - - setupZConstraint(); - - myNVTZCons = new ZConstraint >( &(info[k]), the_ff ); - myNVTZCons->setTargetTemp(globals->getTargetTemp()); - - if (globals->haveTauThermostat()) - myNVTZCons->setTauThermostat(globals->getTauThermostat()); - - else { - sprintf( painCave.errMsg, - "SimSetup error: If you use the NVT\n" - " ensemble, you must set tauThermostat.\n"); - painCave.isFatal = 1; - simError(); - } - break; - - case NPTiZCONS_ENS: - - setupZConstraint(); - - myNPTiZCons = new ZConstraint >( &(info[k]), the_ff ); - myNPTiZCons->setTargetTemp( globals->getTargetTemp() ); - - if (globals->haveTargetPressure()) - myNPTiZCons->setTargetPressure(globals->getTargetPressure()); - else { - sprintf( painCave.errMsg, - "SimSetup error: If you use a constant pressure\n" - " ensemble, you must set targetPressure in the BASS file.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauThermostat() ) - myNPTiZCons->setTauThermostat( globals->getTauThermostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauThermostat.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauBarostat() ) - myNPTiZCons->setTauBarostat( globals->getTauBarostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauBarostat.\n"); - painCave.isFatal = 1; - simError(); - } - - break; - - case NPTfZCONS_ENS: - - setupZConstraint(); - - myNPTfZCons = new ZConstraint >( &(info[k]), the_ff ); - myNPTfZCons->setTargetTemp( globals->getTargetTemp()); - - if (globals->haveTargetPressure()) - myNPTfZCons->setTargetPressure(globals->getTargetPressure()); - else { - sprintf( painCave.errMsg, - "SimSetup error: If you use a constant pressure\n" - " ensemble, you must set targetPressure in the BASS file.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauThermostat() ) - myNPTfZCons->setTauThermostat( globals->getTauThermostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauThermostat.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauBarostat() ) - myNPTfZCons->setTauBarostat( globals->getTauBarostat() ); else{ sprintf( painCave.errMsg, "SimSetup error: If you use an NPT\n" " ensemble, you must set tauBarostat.\n"); painCave.isFatal = 1; simError(); - } - - break; - - case NPTimZCONS_ENS: - - setupZConstraint(); - - myNPTimZCons = new ZConstraint >( &(info[k]), the_ff ); - myNPTimZCons->setTargetTemp( globals->getTargetTemp()); - - if (globals->haveTargetPressure()) - myNPTimZCons->setTargetPressure(globals->getTargetPressure()); - else { - sprintf( painCave.errMsg, - "SimSetup error: If you use a constant pressure\n" - " ensemble, you must set targetPressure in the BASS file.\n"); - painCave.isFatal = 1; - simError(); } - - if( globals->haveTauThermostat() ) - myNPTimZCons->setTauThermostat( globals->getTauThermostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauThermostat.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauBarostat() ) - myNPTimZCons->setTauBarostat( globals->getTauBarostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauBarostat.\n"); - painCave.isFatal = 1; - simError(); - } - break; - case NPTfmZCONS_ENS: - - setupZConstraint(); - - myNPTfmZCons = new ZConstraint >( &(info[k]), the_ff ); - myNPTfmZCons->setTargetTemp( globals->getTargetTemp()); - - if (globals->haveTargetPressure()) - myNPTfmZCons->setTargetPressure(globals->getTargetPressure()); - else { - sprintf( painCave.errMsg, - "SimSetup error: If you use a constant pressure\n" - " ensemble, you must set targetPressure in the BASS file.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauThermostat() ) - myNPTfmZCons->setTauThermostat( globals->getTauThermostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauThermostat.\n"); - painCave.isFatal = 1; - simError(); - } - - if( globals->haveTauBarostat() ) - myNPTfmZCons->setTauBarostat( globals->getTauBarostat() ); - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an NPT\n" - " ensemble, you must set tauBarostat.\n"); - painCave.isFatal = 1; - simError(); - } - break; - - - default: sprintf( painCave.errMsg, "SimSetup Error. Unrecognized ensemble in case statement.\n"); @@ -1763,19 +1589,18 @@ void SimSetup::initFortran( void ){ } -void SimSetup::setupZConstraint() +void SimSetup::setupZConstraint(SimInfo& theInfo) { - int k; - - for(k=0; khaveZConsTime()){ + int nZConstraints; + ZconStamp** zconStamp; + + if(globals->haveZconstraintTime()){ //add sample time of z-constraint into SimInfo's property list DoubleData* zconsTimeProp = new DoubleData(); - zconsTimeProp->setID("zconstime"); - zconsTimeProp->setData(globals->getZConsTime()); - info[k].addProperty(zconsTimeProp); + zconsTimeProp->setID(ZCONSTIME_ID); + zconsTimeProp->setData(globals->getZconsTime()); + theInfo.addProperty(zconsTimeProp); } else{ sprintf( painCave.errMsg, @@ -1784,41 +1609,60 @@ void SimSetup::setupZConstraint() painCave.isFatal = 1; simError(); } - - if(globals->haveIndexOfAllZConsMols()){ - - //add index of z-constraint molecules into SimInfo's property list - vector tempIndex = globals->getIndexOfAllZConsMols(); - - //sort the index - sort(tempIndex.begin(), tempIndex.end()); - - IndexData* zconsIndex = new IndexData(); - zconsIndex->setID("zconsindex"); - zconsIndex->setIndexData(tempIndex); - info[k].addProperty(zconsIndex); + + // + nZConstraints = globals->getNzConstraints(); + zconStamp = globals->getZconStamp(); + ZConsParaItem tempParaItem; + + ZConsParaData* zconsParaData = new ZConsParaData(); + zconsParaData->setID(ZCONSPARADATA_ID); + + for(int i = 0; i < nZConstraints; i++){ + tempParaItem.havingZPos = zconStamp[i]->haveZpos(); + tempParaItem.zPos = zconStamp[i]->getZpos(); + tempParaItem.zconsIndex = zconStamp[i]->getMolIndex(); + tempParaItem.kRatio = zconStamp[i]->getKratio(); + + zconsParaData->addItem(tempParaItem); } - else{ - sprintf( painCave.errMsg, - "SimSetup error: If you use an ZConstraint\n" - " , you must set index of z-constraint molecules.\n"); - painCave.isFatal = 1; - simError(); - + + //sort the parameters by index of molecules + zconsParaData->sortByIndex(); + + //push data into siminfo, therefore, we can retrieve later + theInfo.addProperty(zconsParaData); + + //push zconsTol into siminfo, if user does not specify + //value for zconsTol, a default value will be used + DoubleData* zconsTol = new DoubleData(); + zconsTol->setID(ZCONSTOL_ID); + if(globals->haveZconsTol()){ + zconsTol->setData(globals->getZconsTol()); } - + else{ + double defaultZConsTol = 1E-6; + sprintf( painCave.errMsg, + "ZConstraint Waring: Tolerance for z-constraint methodl is not specified\n" + " , default value %f is used.\n", defaultZConsTol); + painCave.isFatal = 0; + simError(); + + zconsTol->setData(defaultZConsTol); + } + theInfo.addProperty(zconsTol); + //Determine the name of ouput file and add it into SimInfo's property list //Be careful, do not use inFileName, since it is a pointer which //point to a string at master node, and slave nodes do not contain that string - string zconsOutput(info[k].finalName); + string zconsOutput(theInfo.finalName); zconsOutput = zconsOutput.substr(0, zconsOutput.rfind(".")) + ".fz"; StringData* zconsFilename = new StringData(); - zconsFilename->setID("zconsfilename"); + zconsFilename->setID(ZCONSFILENAME_ID); zconsFilename->setData(zconsOutput); - info[k].addProperty(zconsFilename); - } + theInfo.addProperty(zconsFilename); }