Skip to content

Commit

Permalink
Moved code for ensuring single precision timestep is correctly conver…
Browse files Browse the repository at this point in the history
…ted from DataPassingObject to PlumedMain

This conversion was being done for all the single scalars that were being passed to PLUMED.  This is not necessary
and in fact breaks the passing of the energy from gromacs to PLUMED.  The passing of the energy from GROMACS to plumed should now work
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed Jun 12, 2024
1 parent 6707f5f commit 8cf7738
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/core/DataPassingObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ double DataPassingObjectTyped<T>::MD2double(const TypesafePtr & m) const {
template <class T>
void DataPassingObjectTyped<T>::saveValueAsDouble( const TypesafePtr & val ) {
hasbackup=true; bvalue=double(val.template get<T>());
// The following is to avoid extra digits in case the MD code uses floats
// e.g.: float f=0.002 when converted to double becomes 0.002000000094995
// To avoid this, we keep only up to 6 significant digits after first one
if( sizeof(T)<=4) {
double magnitude=std::pow(10,std::floor(std::log10(bvalue)));
bvalue=std::round(bvalue/magnitude*1e6)/1e6*magnitude;
}
}

template <class T>
Expand Down
8 changes: 8 additions & 0 deletions src/core/PlumedMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,14 @@ void PlumedMain::cmd(std::string_view word,const TypesafePtr & val) {
ts = actionSet.selectWithLabel<ActionToPutData*>("timestep");
}
if( !ts->setValuePointer("timestep", val ) ) plumed_error();
// The following is to avoid extra digits in case the MD code uses floats
// e.g.: float f=0.002 when converted to double becomes 0.002000000094995
// To avoid this, we keep only up to 6 significant digits after first one
if( getRealPrecision()<=4 ) {
Value* tstepv = ts->copyOutput(0);
double magnitude=std::pow(10,std::floor(std::log10(tstepv->get())));
tstepv->set( std::round(tstepv->get()/magnitude*1e6)/1e6*magnitude );
}
ts->updateUnits( passtools.get() );
}
break;
Expand Down

1 comment on commit 8cf7738

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANGLES.tmp
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/CAVITY.tmp
Found broken examples in automatic/CLASSICAL_MDS.tmp
Found broken examples in automatic/CLUSTER_DIAMETER.tmp
Found broken examples in automatic/CLUSTER_DISTRIBUTION.tmp
Found broken examples in automatic/CLUSTER_PROPERTIES.tmp
Found broken examples in automatic/CONSTANT.tmp
Found broken examples in automatic/CONTACT_MATRIX.tmp
Found broken examples in automatic/CONTACT_MATRIX_PROPER.tmp
Found broken examples in automatic/COORDINATIONNUMBER.tmp
Found broken examples in automatic/DFSCLUSTERING.tmp
Found broken examples in automatic/DISTANCE_FROM_CONTOUR.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FIND_CONTOUR.tmp
Found broken examples in automatic/FIND_CONTOUR_SURFACE.tmp
Found broken examples in automatic/FIND_SPHERICAL_CONTOUR.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/GPROPERTYMAP.tmp
Found broken examples in automatic/HBOND_MATRIX.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/INCYLINDER.tmp
Found broken examples in automatic/INENVELOPE.tmp
Found broken examples in automatic/INTERPOLATE_GRID.tmp
Found broken examples in automatic/LOCAL_AVERAGE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/MULTICOLVARDENS.tmp
Found broken examples in automatic/OUTPUT_CLUSTER.tmp
Found broken examples in automatic/PAMM.tmp
Found broken examples in automatic/PCA.tmp
Found broken examples in automatic/PCAVARS.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in automatic/PYCVINTERFACE.tmp
Found broken examples in automatic/PYTHONFUNCTION.tmp
Found broken examples in automatic/Q3.tmp
Found broken examples in automatic/Q4.tmp
Found broken examples in automatic/Q6.tmp
Found broken examples in automatic/QUATERNION.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_LINEAR_PROJ.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_MAHA_DIST.tmp
Found broken examples in automatic/SPRINT.tmp
Found broken examples in automatic/TETRAHEDRALPORE.tmp
Found broken examples in automatic/TORSIONS.tmp
Found broken examples in automatic/WHAM_WEIGHTS.tmp
Found broken examples in AnalysisPP.md
Found broken examples in CollectiveVariablesPP.md
Found broken examples in MiscelaneousPP.md

Please sign in to comment.