[AMBER] [PATCH 8/8] amber_outputs.py: Format floats in csv output

From: Reinis Danne <gam4rei.gmail.com>
Date: Tue, 23 Oct 2012 01:15:01 +0300

From: Reinis Danne <rei4dan.gmail.com>

It might be or might not be the right fix for the test failure I was
seeing. Basically it looked like ndiff used lexical comparison between
energies and it failed since floating point representation in binary is
not exact and it gets extra numbers in output value although the value
itself is correct to the required precision.

I couldn't track down what exactly was causing this, so I changed the
output writing to format energies to the required precision and added
extra 0's for energy values in energies.csv.save where required.

If such formatting is desired, then it might be a usable change (just
have to make sure all writers are formatting energies like that).

Most likely the real issue is somewhere in number comparison scripts
and someone who is more familiar with them should take a look.
---
 AmberTools/src/mmpbsa_py/MMPBSA_mods/amber_outputs.py           | 4 ++--
 AmberTools/test/mmpbsa_py/01_Generalized_Born/energies.csv.save | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/AmberTools/src/mmpbsa_py/MMPBSA_mods/amber_outputs.py b/AmberTools/src/mmpbsa_py/MMPBSA_mods/amber_outputs.py
index 0349ba9..c700beb 100644
--- a/AmberTools/src/mmpbsa_py/MMPBSA_mods/amber_outputs.py
+++ b/AmberTools/src/mmpbsa_py/MMPBSA_mods/amber_outputs.py
.. -210,7 +210,7 .. class AmberOutput(object):
 
       # write out each frame
       for i in range(len(self.data[print_keys[0]])):
-         csvwriter.writerow([i] + [self.data[key][i] for key in print_keys])
+         csvwriter.writerow([i] + ["%.4f" % self.data[key][i] for key in print_keys])
 
    #==================================================
 
.. -1003,7 +1003,7 .. class BindingStatistics(object):
 
          # write out each frame
          for i in range(len(self.data[print_keys[0]])):
-            csvwriter.writerow([i]+[self.data[key][i] for key in print_keys])
+            csvwriter.writerow([i]+["%.4f" % self.data[key][i] for key in print_keys])
          csvwriter.writerow([])
 
    #==================================================
diff --git a/AmberTools/test/mmpbsa_py/01_Generalized_Born/energies.csv.save b/AmberTools/test/mmpbsa_py/01_Generalized_Born/energies.csv.save
index 3595375..1a0be46 100644
--- a/AmberTools/test/mmpbsa_py/01_Generalized_Born/energies.csv.save
+++ b/AmberTools/test/mmpbsa_py/01_Generalized_Born/energies.csv.save
.. -7,16 +7,16 .. Frame #,VDWAALS,EEL,EGB,ESURF,G gas,G solv,TOTAL
 Receptor Energy Terms
 Frame #,VDWAALS,EEL,EGB,ESURF,G gas,G solv,TOTAL
 0,-1969.4265,-17103.7958,-3027.0953,101.7772,-19073.2223,-2925.3181,-21998.5404
-1,-1956.6674,-17020.9923,-3062.954,102.3918,-18977.6597,-2960.5622,-21938.2219
+1,-1956.6674,-17020.9923,-3062.9540,102.3918,-18977.6597,-2960.5622,-21938.2219
 
 Ligand Energy Terms
 Frame #,VDWAALS,EEL,EGB,ESURF,G gas,G solv,TOTAL
-0,-1.2566,-5.6263,-28.5797,4.4486,-6.8829,-24.1311,-31.014
+0,-1.2566,-5.6263,-28.5797,4.4486,-6.8829,-24.1311,-31.0140
 1,-3.1118,-6.1548,-29.3738,4.4016,-9.2666,-24.9722,-34.2388
 
 DELTA Energy Terms
 Frame #,VDWAALS,EEL,EGB,ESURF,DELTA G gas,DELTA G solv,DELTA TOTAL
-0,-63.4582,-32.3518,35.2679,-8.3751,-95.81,26.8928,-68.9172
-1,-60.9966,-35.1045,41.6205,-8.465,-96.1011,33.1555,-62.9456
+0,-63.4582,-32.3518,35.2679,-8.3751,-95.8100,26.8928,-68.9172
+1,-60.9966,-35.1045,41.6205,-8.4650,-96.1011,33.1555,-62.9456
 
 
-- 
1.7.12.4
_______________________________________________
AMBER mailing list
AMBER.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber
Received on Mon Oct 22 2012 - 15:30:10 PDT
Custom Search