From c95b248eb6a82770589209a5f3e1eb70a3e13490 Mon Sep 17 00:00:00 2001 From: Carlo Camilloni <carlo.camilloni@gmail.com> Date: Wed, 10 Sep 2014 15:00:09 +0200 Subject: [PATCH] some cleaning in the code --- src/colvar/CH3Shifts.cpp | 34 +++++++++------------------------- src/colvar/CS2Backbone.cpp | 16 +++------------- src/colvar/NOE.cpp | 15 +++------------ src/colvar/RDC.cpp | 7 +------ 4 files changed, 16 insertions(+), 56 deletions(-) diff --git a/src/colvar/CH3Shifts.cpp b/src/colvar/CH3Shifts.cpp index e911980e8..4b2770025 100644 --- a/src/colvar/CH3Shifts.cpp +++ b/src/colvar/CH3Shifts.cpp @@ -183,7 +183,7 @@ PLUMED_COLVAR_INIT(ao) if(ensemble&&comm.Get_rank()==0) { if(multi_sim_comm.Get_size()<2) error("You CANNOT run Replica-Averaged simulations without running multiple replicas!\n"); else ens_dim=multi_sim_comm.Get_size(); - } else ens_dim=0; + } else ens_dim=1; if(ensemble) comm.Sum(&ens_dim, 1); stringadb = stringa_data + string("/CH3shifts.dat"); @@ -294,34 +294,19 @@ void CH3Shifts::calculate() coor.coor[ipos+2] = len_pl2alm*Pos[2]; } + bool printout=false; + string csfile; + if(pperiod>0&&comm.Get_rank()==0) printout = (!(getStep()%pperiod)); + if(printout) csfile = string("cs")+getLabel()+"-"+to_string(getStep())+string(".dat"); + double fact=1.0; if(!ensemble) { energy = meth_list[0]->calc_cs_force(coor, forces); - bool printout=false; - if(pperiod>0&&comm.Get_rank()==0) printout = (!(getStep()%pperiod)); - if(printout) { - string csfile; - char tmps1[21]; - // add to the name the label of the cv in such a way to have different files - // when there is more than one defined variable - sprintf(tmps1, "%li", getStep()); - csfile = string("cs")+tmps1+string(".dat"); - meth_list[0]->write_cs(csfile.c_str()); - } + if(printout) meth_list[0]->write_cs(csfile.c_str()); } else { meth_list[0]->calc_cs(coor); - bool printout=false; - if(pperiod>0&&comm.Get_rank()==0) printout = (!(getStep()%pperiod)); - if(printout) { - string csfile; - char tmps1[21], tmps2[21]; - // add to the name the label of the cv in such a way to have different files - // when there is more than one defined variable - sprintf(tmps1, "%li", getStep()); - sprintf(tmps2, "%i", multi_sim_comm.Get_rank()); - csfile = string("cs")+tmps2+"-"+tmps1+string(".dat"); - meth_list[0]->write_cs(csfile.c_str()); - } + if(printout) meth_list[0]->write_cs(csfile.c_str()); + unsigned size = meth_list[0]->ala_calc_hb.size(); for(unsigned j=0;j<size;j++) sh[0][j] = meth_list[0]->ala_calc_hb[j]; size = meth_list[0]->ile_calc_hd.size(); @@ -342,7 +327,6 @@ void CH3Shifts::calculate() if(comm.Get_rank()==0) { // I am the master of my replica // among replicas multi_sim_comm.Sum(&sh[0][0], numResidues*8); - multi_sim_comm.Barrier(); for(unsigned i=0;i<8;i++) for(int j=0;j<numResidues;j++) sh[j][i] *= fact; } else for(unsigned i=0;i<8;i++) for(int j=0;j<numResidues;j++) sh[j][i] = 0.; // inside each replica diff --git a/src/colvar/CS2Backbone.cpp b/src/colvar/CS2Backbone.cpp index fa79121fd..0b5219b10 100644 --- a/src/colvar/CS2Backbone.cpp +++ b/src/colvar/CS2Backbone.cpp @@ -195,7 +195,7 @@ PLUMED_COLVAR_INIT(ao) if(ensemble&&comm.Get_rank()==0) { if(multi_sim_comm.Get_size()<2) error("You CANNOT run Replica-Averaged simulations without running multiple replicas!\n"); else ens_dim=multi_sim_comm.Get_size(); - } else ens_dim=0; + } else ens_dim=1; if(ensemble) comm.Sum(&ens_dim, 1); stringadb = stringa_data + string("/camshift.db"); @@ -320,7 +320,6 @@ PLUMED_COLVAR_INIT(ao) <<plumed.cite("Kohlhoff K, Robustelli P, Cavalli A, Salvatella A, Vendruscolo M, J. Am. Chem. Soc. 131, 13894 (2009)") <<plumed.cite("Camilloni C, Robustelli P, De Simone A, Cavalli A, Vendruscolo M, J. Am. Chem. Soc. 134, 3968 (2012)") <<"\n"; - coor.resize(atoms.size()); csforces.resize(atoms.size()); @@ -355,15 +354,7 @@ void CS2Backbone::calculate() bool printout=false; if(pperiod>0&&comm.Get_rank()==0) printout = (!(getStep()%pperiod)); if(printout) { - string csfile; - char tmps1[21], tmps2[21]; - // add to the name the label of the cv in such a way to have different files - // when there is more than one defined variable - sprintf(tmps1, "%li", getStep()); - if(ensemble) { - sprintf(tmps2, "%i", multi_sim_comm.Get_rank()); - csfile = string("cs-")+getLabel()+"-"+tmps2+"-"+tmps1+string(".dat"); - } else csfile = string("cs-")+getLabel()+"-"+tmps1+string(".dat"); + string csfile = string("cs-")+getLabel()+"-"+to_string(getStep())+string(".dat");; cam_list[0].printout_chemical_shifts(csfile.c_str()); } @@ -380,8 +371,7 @@ void CS2Backbone::calculate() } csforces.clear(); - double energy; - energy = cam_list[0].ens_energy_force(coor, csforces, sh); + double energy = cam_list[0].ens_energy_force(coor, csforces, sh); if(!serial) comm.Sum(&csforces[0][0], N*4); Tensor virial; diff --git a/src/colvar/NOE.cpp b/src/colvar/NOE.cpp index 6bddb2911..1f08891a4 100644 --- a/src/colvar/NOE.cpp +++ b/src/colvar/NOE.cpp @@ -162,13 +162,13 @@ serial(false) if(ensemble&&comm.Get_rank()==0) { if(multi_sim_comm.Get_size()<2) error("You CANNOT run Replica-Averaged simulations without running multiple replicas!\n"); else ens_dim=multi_sim_comm.Get_size(); - } else ens_dim=0; + } else ens_dim=1; if(ensemble) comm.Sum(&ens_dim, 1); // Ouput details of all contacts unsigned index=0; for(unsigned i=0;i<nga.size();++i){ - log.printf(" The %uth NOE is calculated using %i equivalent couples of atoms and compared with a %f reference distance\n", i, nga[i], noedist[i]); + log.printf(" The %uth NOE is calculated using %u equivalent couples of atoms and compared with a %f reference distance\n", i, nga[i], noedist[i]); for(unsigned j=0;j<nga[i];j++) { log.printf(" couple %u is %d %d.\n", j, ga_lista[index].serial(), gb_lista[index].serial() ); index++; @@ -251,16 +251,7 @@ void NOE::calculate(){ bool printout=false; if(pperiod>0&&comm.Get_rank()==0) printout = (!(getStep()%pperiod)); if(printout) { - string csfile; - char tmps1[21], tmps2[21]; - // add to the name the label of the cv in such a way to have different files - // when there is more than one defined variable - sprintf(tmps1, "%li", getStep()); - if(ensemble) { - sprintf(tmps2, "%i", multi_sim_comm.Get_rank()); - csfile = string("noe")+tmps2+"-"+tmps1+string(".dat"); - } else csfile = string("noe")+tmps1+string(".dat"); - // now print it!! + string csfile = string("noe")+to_string(getStep())+string(".dat"); FILE *outfile = fopen(csfile.c_str(), "w"); fprintf(outfile, "#index calc exp\n"); for(unsigned i=0;i<nga.size();i++) { diff --git a/src/colvar/RDC.cpp b/src/colvar/RDC.cpp index a0a6f3940..ce0d3a841 100644 --- a/src/colvar/RDC.cpp +++ b/src/colvar/RDC.cpp @@ -442,12 +442,7 @@ void RDC::calculate() bool printout=false; if(pperiod>0&&comm.Get_rank()==0) printout = (!(getStep()%pperiod)); if(printout) { - string dcfile; - char tmps1[21]; - sprintf(tmps1, "%li", getStep()); - if(ensemble) { - dcfile = string("rdc-")+getLabel()+"-"+tmps1+string(".dat"); - } else dcfile = string("rdc-")+getLabel()+"-"+tmps1+string(".dat"); + string dcfile = string("rdc-")+getLabel()+"-"+to_string(getStep())+string(".dat"); FILE *outfile = fopen(dcfile.c_str(), "w"); fprintf(outfile, "#index calc exp\n"); double sum=0.; -- GitLab