コード例 #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
ファイル: CoeffsBase.cpp プロジェクト: BingqingCheng/plumed2
void CoeffsBase::writeIterationCounterAndTimeToFile(OFile& ofile) const {
  if(time_md>=0.0) {
    ofile.fmtField("%f");
    ofile.addConstantField(field_time_).printField(field_time_,time_md);
    ofile.fmtField();
  }
  ofile.addConstantField(field_iteration_).printField(field_iteration_,(int) iteration_opt);
}
コード例 #3
0
ファイル: CoeffsBase.cpp プロジェクト: BingqingCheng/plumed2
void CoeffsBase::writeCoeffsInfoToFile(OFile& ofile) const {
  ofile.addConstantField(field_type_).printField(field_type_,getTypeStr());
  ofile.addConstantField(field_ndimensions_).printField(field_ndimensions_,(int) numberOfDimensions());
  ofile.addConstantField(field_ncoeffs_total_).printField(field_ncoeffs_total_,(int) numberOfCoeffs());
  for(unsigned int k=0; k<numberOfDimensions(); k++) {
    ofile.addConstantField(field_shape_prefix_+getDimensionLabel(k));
    ofile.printField(field_shape_prefix_+getDimensionLabel(k),(int) shapeOfIndices(k));
  }
}
コード例 #4
0
void GridPrintingBase::runFinalJobs() {
  if( !output_for_all_replicas ) {
    bool found=false; unsigned myrep=plumed.multi_sim_comm.Get_rank();
    for(unsigned i=0; i<preps.size(); ++i) {
      if( myrep==preps[i] ) { found=true; break; }
    }
    if( !found ) return;
  }
  if( getStride()>0 ) return;

  OFile ofile; ofile.link(*this);
  ofile.open( filename ); printGrid( ofile );
}
コード例 #5
0
ファイル: ReferenceAtoms.cpp プロジェクト: edoardob90/plumed2
void ReferenceAtoms::printAtoms( OFile& ofile, const double& lunits ) const {
  plumed_assert( indices.size()==reference_atoms.size() && align.size()==reference_atoms.size() && displace.size()==reference_atoms.size() );
  for(unsigned i=0;i<reference_atoms.size();++i){
      ofile.printf("ATOM  %4d  X    RES  %4u  %8.3f%8.3f%8.3f%6.2f%6.2f\n",
        indices[i].serial(), i, 
        lunits*reference_atoms[i][0], lunits*reference_atoms[i][1], lunits*reference_atoms[i][2],
        align[i], displace[i] );
  }
}
コード例 #6
0
ファイル: PointWiseMapping.cpp プロジェクト: whitead/plumed2
void PointWiseMapping::print( const std::string& method, const double & time, OFile& afile, const std::string& fmt ){
  std::string descr2, descr="DESCRIPTION: results from %s analysis performed at time " + fmt +"\n";
  afile.printf(descr.c_str(), method.c_str(), time );
  if(fmt.find("-")!=std::string::npos){
     descr="REMARK WEIGHT=" + fmt + " %s=" + fmt + " "; descr2="%s=" + fmt;
  } else {
     // This ensures numbers are left justified (i.e. next to the equals sign
     std::size_t psign=fmt.find("%");
     plumed_assert( psign!=std::string::npos );
     descr="REMARK WEIGHT=%-" + fmt.substr(psign+1) + " %s=%-" + fmt.substr(psign+1) + " "; 
     descr2="%s=%-" + fmt.substr(psign+1);
  }
  for(unsigned i=0;i<frames.size();++i){
      afile.printf(descr.c_str(), frames[i]->getWeight(), property[0].c_str(), low_dim[i][0] );
      for(unsigned j=1;j<property.size();++j) afile.printf(descr2.c_str(), property[j].c_str(), low_dim[i][j]);
      afile.printf("\n"); 
      frames[i]->print( afile, fmt );
  }
} 
コード例 #7
0
ファイル: MetaD.cpp プロジェクト: juvejones/plumed2
void MetaD::writeGaussian(const Gaussian& hill, OFile&file){
  unsigned ncv=getNumberOfArguments();
  file.printField("time",getTimeStep()*getStep());
  for(unsigned i=0;i<ncv;++i){
    file.printField(getPntrToArgument(i),hill.center[i]);
  }
  if(hill.multivariate){
    hillsOfile_.printField("multivariate","true");
         Matrix<double> mymatrix(ncv,ncv);
         unsigned k=0;
         for(unsigned i=0;i<ncv;i++){
                for(unsigned j=i;j<ncv;j++){
                        mymatrix(i,j)=mymatrix(j,i)=hill.sigma[k]; // recompose the full inverse matrix
                        k++;
                }
         }
         // invert it 
         Matrix<double> invmatrix(ncv,ncv);
         Invert(mymatrix,invmatrix);
         // enforce symmetry
         for(unsigned i=0;i<ncv;i++){
                for(unsigned j=i;j<ncv;j++){
                        invmatrix(i,j)=invmatrix(j,i);
                }
         }

         // do cholesky so to have a "sigma like" number
         Matrix<double> lower(ncv,ncv);
         cholesky(invmatrix,lower); // now this , in band form , is similar to the sigmas
         // loop in band form 
         for (unsigned i=0;i<ncv;i++){
              for (unsigned j=0;j<ncv-i;j++){
                      file.printField("sigma_"+getPntrToArgument(j+i)->getName()+"_"+getPntrToArgument(j)->getName(),lower(j+i,j));
              }
         }
  } else {
    hillsOfile_.printField("multivariate","false");
    for(unsigned i=0;i<ncv;++i)
      file.printField("sigma_"+getPntrToArgument(i)->getName(),hill.sigma[i]);
  }
  double height=hill.height;
  if(welltemp_){height*=biasf_/(biasf_-1.0);}
  file.printField("height",height).printField("biasf",biasf_);
  if(mw_n_>1) file.printField("clock",int(time(0)));
  file.printField();
}
コード例 #8
0
void MaxEnt::WriteLagrangians(vector<double> &lagmult,OFile &file) {
  if(printFirstStep) {
    unsigned ncv=getNumberOfArguments();
    file.printField("time",getTimeStep()*getStep());
    for(unsigned i=0; i<ncv; ++i)
      file.printField(getPntrToArgument(i)->getName()+"_coupling",lagmult[i]);
    file.printField();
  } else {
    if(!isFirstStep) {
      unsigned ncv=getNumberOfArguments();
      file.printField("time",getTimeStep()*getStep());
      for(unsigned i=0; i<ncv; ++i)
        file.printField(getPntrToArgument(i)->getName()+"_coupling",lagmult[i]);
      file.printField();
    }
  }
}
コード例 #9
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

}
コード例 #10
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

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

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