コード例 #1
0
void GridPrintingBase::update(){
  if( getStep()==0 || getStride()==0 ) return ;

  OFile ofile; ofile.link(*this);
  ofile.setBackupString("analysis");
  ofile.open( filename ); printGrid( ofile ); ofile.close();
}
コード例 #2
0
ファイル: FuncSumHills.cpp プロジェクト: apoma/plumed2
FuncSumHills::FuncSumHills(const ActionOptions&ao):
Action(ao),
Function(ao),
initstride(-1),
iscltool(false),
integratehills(false),
integratehisto(false),
parallelread(false),
negativebias(false),
nohistory(false),
beta(-1.),
fmt("%14.9f")
{

  // format
  parse("FMT",fmt);
  log<<"  Output format is "<<fmt<<"\n"; 
  // here read 
  // Grid Stuff
  vector<std::string> gmin;
  parseVector("GRID_MIN",gmin);
  if(gmin.size()!=getNumberOfArguments() && gmin.size()!=0) error("not enough values for GRID_MIN");
  plumed_massert(gmin.size()==getNumberOfArguments() || gmin.size()==0,"need GRID_MIN argument for this") ;
  vector<std::string> gmax;
  parseVector("GRID_MAX",gmax);
  if(gmax.size()!=getNumberOfArguments() && gmax.size()!=0) error("not enough values for GRID_MAX");
  plumed_massert(gmax.size()==getNumberOfArguments() || gmax.size()==0,"need GRID_MAX argument for this") ;
  vector<unsigned> gbin;
  parseVector("GRID_BIN",gbin);
  plumed_massert(gbin.size()==getNumberOfArguments() || gbin.size()==0,"need GRID_BIN argument for this"); 
  if(gbin.size()!=getNumberOfArguments() && gbin.size()!=0) error("not enough values for GRID_BIN");
  //plumed_assert(getNumberOfArguments()==gbin.size());

  // hills file: 
  parseVector("HILLSFILES",hillsFiles);
  if(hillsFiles.size()==0){
  	integratehills=false; // default behaviour 
  }else{
  	integratehills=true; 
        for(unsigned i=0;i<hillsFiles.size();i++) log<<"  hillsfile  : "<<hillsFiles[i]<<"\n";
  }
  // histo file: 
  parseVector("HISTOFILES",histoFiles);
  if(histoFiles.size()==0){
  	integratehisto=false;  
  }else{
  	integratehisto=true;  
        for(unsigned i=0;i<histoFiles.size();i++) log<<"  histofile  : "<<histoFiles[i]<<"\n";
  }
  vector<double> histoSigma;
  if(integratehisto){
  	parseVector("HISTOSIGMA",histoSigma);
	plumed_massert(histoSigma.size()==getNumberOfArguments()," The number of sigmas must be the same of the number of arguments ");
        for(unsigned i=0;i<histoSigma.size();i++) log<<"  histosigma  : "<<histoSigma[i]<<"\n";
  }

  // add some automatic hills width: not in case stride is defined  
  // since when you start from zero the automatic size will be zero!
  if(gmin.size()==0 || gmax.size()==0){
	log<<"   \n"; 
	log<<"  No boundaries defined: need to do a prescreening of hills \n"; 
        std::vector<Value*> tmpvalues; 
        for(unsigned i=0;i<getNumberOfArguments();i++)tmpvalues.push_back( getPntrToArgument(i) );
        if(integratehills) {
        	FilesHandler *hillsHandler;
        	hillsHandler=new FilesHandler(hillsFiles,parallelread,*this, log);
		vector<double> vmin,vmax;
        	vector<unsigned> vbin;  
        	hillsHandler->getMinMaxBin(tmpvalues,comm,vmin,vmax,vbin);
		log<<"  found boundaries from hillsfile: \n";
		gmin.resize(vmin.size());
		gmax.resize(vmax.size());
                if(gbin.size()==0){
			gbin=vbin;
                }else{
			log<<"  found nbins in input, this overrides the automatic choice \n"; 
		}
		for(unsigned i=0;i<getNumberOfArguments();i++){
		 	Tools::convert(vmin[i],gmin[i]);
		 	Tools::convert(vmax[i],gmax[i]);
			log<<"  variable "<< getPntrToArgument(i)->getName()<<" min: "<<gmin[i]<<" max: "<<gmax[i]<<" nbin: "<<gbin[i]<<"\n";
		}
        } 
	// if at this stage bins are not there then do it with histo
	if(gmin.size()==0){
    	   	FilesHandler *histoHandler;
	        histoHandler=new FilesHandler(histoFiles,parallelread,*this, log);
		vector<double> vmin,vmax;
        	vector<unsigned> vbin;  
        	histoHandler->getMinMaxBin(tmpvalues,comm,vmin,vmax,vbin,histoSigma);
		log<<"  found boundaries from histofile: \n";
		gmin.resize(vmin.size());
		gmax.resize(vmax.size());
                if(gbin.size()==0){
			gbin=vbin;
                }else{
			log<<"  found nbins in input, this overrides the automatic choice \n"; 
		}
		for(unsigned i=0;i<getNumberOfArguments();i++){
		 	Tools::convert(vmin[i],gmin[i]);
		 	Tools::convert(vmax[i],gmax[i]);
			log<<"  variable "<< getPntrToArgument(i)->getName()<<" min: "<<gmin[i]<<" max: "<<gmax[i]<<" nbin: "<<gbin[i]<<"\n";
		}
        }
	log<<"  done!\n"; 
	log<<"   \n"; 
  }

  // needs a projection? 
  proj.clear();
  parseVector("PROJ",proj);
  plumed_massert(proj.size()<getNumberOfArguments()," The number of projection must be less than the full list of arguments ");

  if( proj.size() != 0 || integratehisto==true  ) {
    parse("KT",beta);
    for(unsigned i=0;i<proj.size();i++) log<<"  projection "<<i<<" : "<<proj[i]<<"\n";
    plumed_massert(beta>0.,"if you make a projection or a histogram correction then you need KT flag!"); 
    beta=1./beta; 
    log<<"  beta is "<<beta<<"\n"; 
  }
  // is a cltool: then you start and then die
  parseFlag("ISCLTOOL",iscltool);
  // 
  parseFlag("NEGBIAS",negativebias); 
  //
  parseFlag("PARALLELREAD",parallelread);
  // stride
  parse("INITSTRIDE",initstride);
  // output suffix or names
  if(initstride<0){ log<<"  Doing only one integration: no stride \n";
  	 outhills="fes.dat";outhisto="correction.dat";}
  else{outhills="fes_";outhisto="correction_";
	log<<"  Doing integration slices every "<<initstride<<" kernels\n";
        parseFlag("NOHISTORY",nohistory); 
        if(nohistory)log<<"  nohistory: each stride block has no memory of the previous block\n";
  }

  //what might it be this? 
  // here start 
  // want something right now?? do it and return
  // your argument is a set of cvs 
  // then you need: a hills / a colvar-like file (to do a histogram) 
  // create a bias representation for this
  if(iscltool){

     std::vector<Value*> tmpvalues; 
    for(unsigned i=0;i<getNumberOfArguments();i++){
        // allocate a new value from the old one: no deriv here
	tmpvalues.push_back( getPntrToArgument(i) );
    }

    // check if the files exists 
    if(integratehills){
         checkFilesAreExisting(hillsFiles); 
         biasrep=new BiasRepresentation(tmpvalues,comm, gmin, gmax, gbin);
	 if(negativebias){
		biasrep->setRescaledToBias(true);
	        log<<"  required the -bias instead of the free energy \n";
		if(initstride<0){outhills="negativebias.dat";}
		else{outhills="negativebias_";}
	 }
    }

    parse("OUTHILLS",outhills);
    parse("OUTHISTO",outhisto);
    if(integratehills)log<<"  output file for fes/bias   is :  "<<outhills<<"\n";   
    if(integratehisto)log<<"  output file for correction is :  "<<outhisto<<"\n";   
    checkRead();

    log<<"\n";
    log<<"  Now calculating...\n";
    log<<"\n";

    if(integratehisto){
         checkFilesAreExisting(histoFiles); 
         historep=new BiasRepresentation(tmpvalues,comm,gmin,gmax,gbin,histoSigma);
    }

    // decide how to source hills ( serial/parallel )
    // here below the input control 
    // say how many hills and it will read them from the 
    // bunch of files provided, will update the representation 
    // of hills (i.e. a list of hills and the associated grid)

    // decide how to source colvars ( serial parallel )
    FilesHandler *hillsHandler;
    FilesHandler *histoHandler;

    if(integratehills)	hillsHandler=new FilesHandler(hillsFiles,parallelread,*this, log);
    if(integratehisto)	histoHandler=new FilesHandler(histoFiles,parallelread,*this, log);

    // read a number of hills and put in the bias representation
    int nfiles=0;
    bool ibias=integratehills; bool ihisto=integratehisto;
    while(true){
        if(  integratehills  && ibias  ){
		if(nohistory){biasrep->clear();log<<"  clearing history before reading a new block\n";}; 
		log<<"  reading hills: \n"; 
		ibias=hillsHandler->readBunch(biasrep,initstride) ; log<<"\n"; 
        }   

        if(  integratehisto  && ihisto ){
		if(nohistory){historep->clear();log<<"  clearing history before reading a new block\n";}; 
		log<<"  reading histogram: \n"; 
		ihisto=histoHandler->readBunch(historep,initstride) ;  log<<"\n";  
        }    

	// dump: need to project?	
        if(proj.size()!=0){

		if(integratehills){

    	      		log<<"  Bias: Projecting on subgrid... \n";
              		BiasWeight *Bw=new BiasWeight(beta); 
             		Grid biasGrid=*(biasrep->getGridPtr());
   	      		Grid smallGrid=biasGrid.project(proj,Bw);
              		OFile gridfile; gridfile.link(*this);
	      		std::ostringstream ostr;ostr<<nfiles;
              		string myout; 
                        if(initstride>0){ myout=outhills+ostr.str()+".dat" ;}else{myout=outhills;}
              		log<<"  Bias: Writing subgrid on file "<<myout<<" \n";
              		gridfile.open(myout);	
        		smallGrid.setOutputFmt(fmt); 
   	      		smallGrid.writeToFile(gridfile);
              		gridfile.close();
                        if(!ibias)integratehills=false;// once you get to the final bunch just give up 

		}
		if(integratehisto){

    	      		log<<"  Histo: Projecting on subgrid... \n";
                        ProbWeight *Pw=new ProbWeight(beta);
             		Grid histoGrid=*(historep->getGridPtr());
   	      		Grid smallGrid=histoGrid.project(proj,Pw);

              		OFile gridfile; gridfile.link(*this);
	      		std::ostringstream ostr;ostr<<nfiles;
              		string myout; 
                        if(initstride>0){ myout=outhisto+ostr.str()+".dat" ;}else{myout=outhisto;}
              		log<<"  Histo: Writing subgrid on file "<<myout<<" \n";
              		gridfile.open(myout);	
         
        		smallGrid.setOutputFmt(fmt); 
   	      		smallGrid.writeToFile(gridfile);
              		gridfile.close();

                        if(!ihisto)integratehisto=false;// once you get to the final bunch just give up 
                } 

	}else{

		if(integratehills){

	                Grid biasGrid=*(biasrep->getGridPtr());
			biasGrid.scaleAllValuesAndDerivatives(-1.);
	
	                OFile gridfile; gridfile.link(*this);
			std::ostringstream ostr;ostr<<nfiles;
			string myout;
			if(initstride>0){ myout=outhills+ostr.str()+".dat" ;}else{myout=outhills;}
	                log<<"  Writing full grid on file "<<myout<<" \n";
	                gridfile.open(myout);	
	
        		biasGrid.setOutputFmt(fmt); 
	                biasGrid.writeToFile(gridfile);
	                gridfile.close();
			// rescale back prior to accumulate
                        if(!ibias)integratehills=false;// once you get to the final bunch just give up 
		}
		if(integratehisto){

	                Grid histoGrid=*(historep->getGridPtr());
                        histoGrid.applyFunctionAllValuesAndDerivatives(&mylog,&mylogder);
                        histoGrid.scaleAllValuesAndDerivatives(-1./beta);	

			OFile gridfile; gridfile.link(*this);
			std::ostringstream ostr;ostr<<nfiles;
			string myout;
			if(initstride>0){ myout=outhisto+ostr.str()+".dat" ;}else{myout=outhisto;}
	                log<<"  Writing full grid on file "<<myout<<" \n";
	                gridfile.open(myout);	
	
        		histoGrid.setOutputFmt(fmt); 
	                histoGrid.writeToFile(gridfile);
	                gridfile.close();

                        if(!ihisto)integratehisto=false;// once you get to the final bunch just give up 
                } 
	} 	
        if ( !ibias && !ihisto) break; //when both are over then just quit 

	nfiles++;
    }

    return;
  } 
  // just an initialization but you need to do something on the fly?: need to connect with a metad run and its grid representation 
  // your argument is a metad run
  // if the grid does not exist crash and say that you need some data 
  // otherwise just link with it

}
コード例 #3
0
FuncSumHills::FuncSumHills(const ActionOptions&ao):
Action(ao),
Function(ao),
initstride(-1),
iscltool(false),
integratehills(false),
integratehisto(false),
parallelread(false),
negativebias(false),
nohistory(false),
minTOzero(false),
doInt(false),
lowI_(-1.),
uppI_(-1.),
beta(-1.),
fmt("%14.9f"),
biasrep(NULL),
historep(NULL)
{

  // format
  parse("FMT",fmt);
  log<<"  Output format is "<<fmt<<"\n"; 
  // here read 
  // Grid Stuff
  vector<std::string> gmin;
  parseVector("GRID_MIN",gmin);
  if(gmin.size()!=getNumberOfArguments() && gmin.size()!=0) error("not enough values for GRID_MIN");
  plumed_massert(gmin.size()==getNumberOfArguments() || gmin.size()==0,"need GRID_MIN argument for this") ;
  vector<std::string> gmax;
  parseVector("GRID_MAX",gmax);
  if(gmax.size()!=getNumberOfArguments() && gmax.size()!=0) error("not enough values for GRID_MAX");
  plumed_massert(gmax.size()==getNumberOfArguments() || gmax.size()==0,"need GRID_MAX argument for this") ;
  vector<unsigned> gbin;
  vector<double>   gspacing;
  parseVector("GRID_BIN",gbin);
  plumed_massert(gbin.size()==getNumberOfArguments() || gbin.size()==0,"need GRID_BIN argument for this") ;
  if(gbin.size()!=getNumberOfArguments() && gbin.size()!=0) error("not enough values for GRID_BIN");
  parseVector("GRID_SPACING",gspacing);
  plumed_massert(gspacing.size()==getNumberOfArguments() || gspacing.size()==0,"need GRID_SPACING argument for this") ;
  if(gspacing.size()!=getNumberOfArguments() && gspacing.size()!=0) error("not enough values for GRID_SPACING");
  if(gspacing.size()!=0 && gbin.size()==0){
    log<<"  The number of bins will be estimated from GRID_SPACING\n";
  } else if(gspacing.size()!=0 && gbin.size()!=0){
    log<<"  You specified both GRID_BIN and GRID_SPACING\n";
    log<<"  The more conservative (highest) number of bins will be used for each variable\n";
  }
  if(gspacing.size()!=0) for(unsigned i=0;i<getNumberOfArguments();i++){
    if(gbin.size()==0) gbin.assign(getNumberOfArguments(),1);
    double a,b;
    Tools::convert(gmin[i],a);
    Tools::convert(gmax[i],b);
    unsigned n=((b-a)/gspacing[i])+1;
    if(gbin[i]<n) gbin[i]=n;
  }

  // Inteval keyword
  vector<double> tmpI(2);
  parseVector("INTERVAL",tmpI);
  if(tmpI.size()!=2&&tmpI.size()!=0) error("both a lower and an upper limits must be provided with INTERVAL");
  else if(tmpI.size()==2) {
    lowI_=tmpI.at(0);
    uppI_=tmpI.at(1);
    if(getNumberOfArguments()!=1) error("INTERVAL limits correction works only for monodimensional metadynamics!");
    if(uppI_<lowI_) error("The Upper limit must be greater than the Lower limit!");
    doInt=true;
  }
  if(doInt) log << "  Upper and Lower limits boundaries for the bias are activated at " << lowI_ << " - " << uppI_<<"\n";
 

  // hills file: 
  parseVector("HILLSFILES",hillsFiles);
  if(hillsFiles.size()==0){
  	integratehills=false; // default behaviour 
  }else{
  	integratehills=true; 
        for(unsigned i=0;i<hillsFiles.size();i++) log<<"  hillsfile  : "<<hillsFiles[i]<<"\n";
  }
  // histo file: 
  parseVector("HISTOFILES",histoFiles);
  if(histoFiles.size()==0){
  	integratehisto=false;  
  }else{
  	integratehisto=true;  
        for(unsigned i=0;i<histoFiles.size();i++) log<<"  histofile  : "<<histoFiles[i]<<"\n";
  }
  vector<double> histoSigma;
  if(integratehisto){
  	parseVector("HISTOSIGMA",histoSigma);
        for(unsigned i=0;i<histoSigma.size();i++) log<<"  histosigma  : "<<histoSigma[i]<<"\n";
  }

  // needs a projection? 
  proj.clear();
  parseVector("PROJ",proj);
  if(integratehills) {
    plumed_massert(proj.size()<getNumberOfArguments()," The number of projection must be less than the full list of arguments ");
  }
  if(integratehisto) {
    plumed_massert(proj.size()<=getNumberOfArguments()," The number of projection must be less or equal to the full list of arguments ");
  }
  if(integratehisto&&proj.size()==0) {
    for(unsigned i=0;i<getNumberOfArguments();i++) proj.push_back(getPntrToArgument(i)->getName()); 
  }

  // add some automatic hills width: not in case stride is defined  
  // since when you start from zero the automatic size will be zero!
  if(gmin.size()==0 || gmax.size()==0){
	log<<"   \n"; 
	log<<"  No boundaries defined: need to do a prescreening of hills \n"; 
        std::vector<Value*> tmphillsvalues, tmphistovalues;
        if(integratehills) { 
          for(unsigned i=0;i<getNumberOfArguments();i++)tmphillsvalues.push_back( getPntrToArgument(i) );
        }
        if(integratehisto) {
          for(unsigned i=0;i<getNumberOfArguments();i++) {
            std::string ss = getPntrToArgument(i)->getName(); 
            for(unsigned j=0;j<proj.size();j++) {
              if(proj[j]==ss) tmphistovalues.push_back( getPntrToArgument(i) );
            }
          } 
        }

        if(integratehills) {
        	FilesHandler *hillsHandler;
        	hillsHandler=new FilesHandler(hillsFiles,parallelread,*this, log);
		vector<double> vmin,vmax;
        	vector<unsigned> vbin;  
        	hillsHandler->getMinMaxBin(tmphillsvalues,comm,vmin,vmax,vbin);
		log<<"  found boundaries from hillsfile: \n";
		gmin.resize(vmin.size());
		gmax.resize(vmax.size());
                if(gbin.size()==0){
			gbin=vbin;
                }else{
			log<<"  found nbins in input, this overrides the automatic choice \n"; 
		}
		for(unsigned i=0;i<getNumberOfArguments();i++){
		 	Tools::convert(vmin[i],gmin[i]);
		 	Tools::convert(vmax[i],gmax[i]);
			log<<"  variable "<< getPntrToArgument(i)->getName()<<" min: "<<gmin[i]<<" max: "<<gmax[i]<<" nbin: "<<gbin[i]<<"\n";
		}
                delete hillsHandler;
        } 
	// if at this stage bins are not there then do it with histo
	if(gmin.size()==0){
    	   	FilesHandler *histoHandler;
	        histoHandler=new FilesHandler(histoFiles,parallelread,*this, log);
		vector<double> vmin,vmax;
        	vector<unsigned> vbin;  
        	histoHandler->getMinMaxBin(tmphistovalues,comm,vmin,vmax,vbin,histoSigma);
		log<<"  found boundaries from histofile: \n";
		gmin.resize(vmin.size());
		gmax.resize(vmax.size());
                if(gbin.size()==0){
			gbin=vbin;
                }else{
			log<<"  found nbins in input, this overrides the automatic choice \n"; 
		}
		for(unsigned i=0;i<proj.size();i++){
		 	Tools::convert(vmin[i],gmin[i]);
		 	Tools::convert(vmax[i],gmax[i]);
			log<<"  variable "<< proj[i] <<" min: "<<gmin[i]<<" max: "<<gmax[i]<<" nbin: "<<gbin[i]<<"\n";
		}
                delete histoHandler;
        }
	log<<"  done!\n"; 
	log<<"   \n"; 
  }


  if( proj.size() != 0 || integratehisto==true  ) {
    parse("KT",beta);
    for(unsigned i=0;i<proj.size();i++) log<<"  projection "<<i<<" : "<<proj[i]<<"\n";
    // this should be only for projection or free energy from histograms
    plumed_massert(beta>0.,"if you make a projection or a histogram correction then you need KT flag!"); 
    beta=1./beta; 
    log<<"  beta is "<<beta<<"\n"; 
  }
  // is a cltool: then you start and then die
  parseFlag("ISCLTOOL",iscltool);
  // 
  parseFlag("NEGBIAS",negativebias); 
  //
  parseFlag("PARALLELREAD",parallelread);
  // stride
  parse("INITSTRIDE",initstride);
  // output suffix or names
  if(initstride<0){ log<<"  Doing only one integration: no stride \n";
  	 outhills="fes.dat";outhisto="histo.dat";}
  else{outhills="fes_";outhisto="histo_";
	log<<"  Doing integration slices every "<<initstride<<" kernels\n";
        parseFlag("NOHISTORY",nohistory); 
        if(nohistory)log<<"  nohistory: each stride block has no memory of the previous block\n";
  }
  parseFlag("MINTOZERO",minTOzero);
  if(minTOzero)log<<"  mintozero: bias/histogram will be translated to have the minimum value equal to zero\n";
  //what might it be this? 
  // here start 
  // want something right now?? do it and return
  // your argument is a set of cvs 
  // then you need: a hills / a colvar-like file (to do a histogram) 
  // create a bias representation for this
  if(iscltool){

    std::vector<Value*> tmphillsvalues, tmphistovalues; 
    if(integratehills) {
      for(unsigned i=0;i<getNumberOfArguments();i++){
        // allocate a new value from the old one: no deriv here
        // if we are summing hills then all the arguments are needed
	tmphillsvalues.push_back( getPntrToArgument(i) );
      }
    }
    if(integratehisto) {
      for(unsigned i=0;i<getNumberOfArguments();i++) {
        std::string ss = getPntrToArgument(i)->getName(); 
        for(unsigned j=0;j<proj.size();j++) {
          if(proj[j]==ss) tmphistovalues.push_back( getPntrToArgument(i) );
        }
      } 
    }

    // check if the files exists 
    if(integratehills){
         checkFilesAreExisting(hillsFiles); 
         biasrep=new BiasRepresentation(tmphillsvalues,comm, gmin, gmax, gbin, doInt, lowI_, uppI_);
	 if(negativebias){
		biasrep->setRescaledToBias(true);
	        log<<"  required the -bias instead of the free energy \n";
		if(initstride<0){outhills="negativebias.dat";}
		else{outhills="negativebias_";}
	 }
    }

    parse("OUTHILLS",outhills);
    parse("OUTHISTO",outhisto);
    if(integratehills)log<<"  output file for fes/bias  is :  "<<outhills<<"\n";   
    if(integratehisto)log<<"  output file for histogram is :  "<<outhisto<<"\n";   
    checkRead();

    log<<"\n";
    log<<"  Now calculating...\n";
    log<<"\n";

    // here it defines the column to be histogrammed, tmpvalues should be only
    // the list of the collective variable one want to consider
    if(integratehisto){
         checkFilesAreExisting(histoFiles); 
         historep=new BiasRepresentation(tmphistovalues,comm,gmin,gmax,gbin,histoSigma);
    }

    // decide how to source hills ( serial/parallel )
    // here below the input control 
    // say how many hills and it will read them from the 
    // bunch of files provided, will update the representation 
    // of hills (i.e. a list of hills and the associated grid)

    // decide how to source colvars ( serial parallel )
    FilesHandler *hillsHandler;
    FilesHandler *histoHandler;

    hillsHandler=NULL;
    histoHandler=NULL;

    if(integratehills)	hillsHandler=new FilesHandler(hillsFiles,parallelread,*this, log);
    if(integratehisto)	histoHandler=new FilesHandler(histoFiles,parallelread,*this, log);

    // read a number of hills and put in the bias representation
    int nfiles=0;
    bool ibias=integratehills; bool ihisto=integratehisto;
    while(true){
        if(  integratehills  && ibias  ){
		if(nohistory){biasrep->clear();log<<"  clearing history before reading a new block\n";}; 
		log<<"  reading hills: \n"; 
		ibias=hillsHandler->readBunch(biasrep,initstride) ; log<<"\n"; 
        }   

        if(  integratehisto  && ihisto ){
		if(nohistory){historep->clear();log<<"  clearing history before reading a new block\n";}; 
		log<<"  reading histogram: \n"; 
		ihisto=histoHandler->readBunch(historep,initstride) ;  log<<"\n";  
        }    

	// dump: need to project?	
        if(proj.size()!=0){

		if(integratehills){

    	      		log<<"  Bias: Projecting on subgrid... \n";
              		BiasWeight *Bw=new BiasWeight(beta); 
             		Grid biasGrid=*(biasrep->getGridPtr());
   	      		Grid smallGrid=biasGrid.project(proj,Bw);
              		OFile gridfile; gridfile.link(*this);
	      		std::ostringstream ostr;ostr<<nfiles;
              		string myout; 
                        if(initstride>0){ myout=outhills+ostr.str()+".dat" ;}else{myout=outhills;}
              		log<<"  Bias: Writing subgrid on file "<<myout<<" \n";
              		gridfile.open(myout);	
                        if(minTOzero) smallGrid.setMinToZero();	
        		smallGrid.setOutputFmt(fmt); 
   	      		smallGrid.writeToFile(gridfile);
              		gridfile.close();
                        if(!ibias)integratehills=false;// once you get to the final bunch just give up 
                        delete Bw;
		}
                // this should be removed
		if(integratehisto){

    	      		log<<"  Histo: Projecting on subgrid... \n";
             		Grid histoGrid=*(historep->getGridPtr());

              		OFile gridfile; gridfile.link(*this);
	      		std::ostringstream ostr;ostr<<nfiles;
              		string myout; 
                        if(initstride>0){ myout=outhisto+ostr.str()+".dat" ;}else{myout=outhisto;}
              		log<<"  Histo: Writing subgrid on file "<<myout<<" \n";
              		gridfile.open(myout);	
         
                        histoGrid.applyFunctionAllValuesAndDerivatives(&mylog,&mylogder);
                        histoGrid.scaleAllValuesAndDerivatives(-1./beta);	
                        if(minTOzero) histoGrid.setMinToZero();	
        		histoGrid.setOutputFmt(fmt); 
   	      		histoGrid.writeToFile(gridfile);
              		gridfile.close();

                        if(!ihisto)integratehisto=false;// once you get to the final bunch just give up 
                } 

	}else{

		if(integratehills){

	                Grid biasGrid=*(biasrep->getGridPtr());
			biasGrid.scaleAllValuesAndDerivatives(-1.);
	
	                OFile gridfile; gridfile.link(*this);
			std::ostringstream ostr;ostr<<nfiles;
			string myout;
			if(initstride>0){ myout=outhills+ostr.str()+".dat" ;}else{myout=outhills;}
	                log<<"  Writing full grid on file "<<myout<<" \n";
	                gridfile.open(myout);	

			if(minTOzero) biasGrid.setMinToZero();	
        		biasGrid.setOutputFmt(fmt); 
	                biasGrid.writeToFile(gridfile);
	                gridfile.close();
			// rescale back prior to accumulate
                        if(!ibias)integratehills=false;// once you get to the final bunch just give up 
		}
		if(integratehisto){

	                Grid histoGrid=*(historep->getGridPtr());
                        // do this if you want a free energy from a grid, otherwise do not
                        histoGrid.applyFunctionAllValuesAndDerivatives(&mylog,&mylogder);
                        histoGrid.scaleAllValuesAndDerivatives(-1./beta);	

			OFile gridfile; gridfile.link(*this);
			std::ostringstream ostr;ostr<<nfiles;
			string myout;
			if(initstride>0){ myout=outhisto+ostr.str()+".dat" ;}else{myout=outhisto;}
	                log<<"  Writing full grid on file "<<myout<<" \n";
	                gridfile.open(myout);	

                        // also this is usefull only for free energy
                        if(minTOzero) histoGrid.setMinToZero();	
        		histoGrid.setOutputFmt(fmt); 
	                histoGrid.writeToFile(gridfile);
	                gridfile.close();

                        if(!ihisto)integratehisto=false; // once you get to the final bunch just give up 
                } 
	} 	
        if ( !ibias && !ihisto) break; //when both are over then just quit 

	nfiles++;
    }
    if(hillsHandler) delete hillsHandler;
    if(histoHandler) delete histoHandler;

    return;
  } 
  // just an initialization but you need to do something on the fly?: need to connect with a metad run and its grid representation 
  // your argument is a metad run
  // if the grid does not exist crash and say that you need some data 
  // otherwise just link with it

}
コード例 #4
0
void GridPrintingBase::runFinalJobs(){
  if( getStride()>0 ) return;

  OFile ofile; ofile.link(*this);
  ofile.open( filename ); printGrid( ofile ); ofile.close();
}