From 7ea18e168336d4801b513c721c889a0cac36f069 Mon Sep 17 00:00:00 2001
From: Mark Driver <mdd31@cam.ac.uk>
Date: Mon, 14 Aug 2017 09:41:34 +0100
Subject: [PATCH] updated solvationmapgenerator to also write out solvation map
 values.

---
 .../solvationmapgenerator.py                  | 11 +++++++++-
 .../solvationmapgeneratortest.py              | 22 +++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/solventmapcreator/solvationcalculation/solvationmapgenerator.py b/solventmapcreator/solvationcalculation/solvationmapgenerator.py
index 560ad9f..37a39ba 100644
--- a/solventmapcreator/solvationcalculation/solvationmapgenerator.py
+++ b/solventmapcreator/solvationcalculation/solvationmapgenerator.py
@@ -11,6 +11,7 @@ two SSIPs forthe x and y axes need to be supplied.
 import logging
 import resultsanalysis.resultsoutput.plottinginput as plottinginput
 import solventmapcreator.io.polynomialdatareader as polynomialdatareader
+import solventmapcreator.io.solvationmapwriter as solvationmapwriter
 import solventmapcreator.solvationcalculation.fractionaloccupancycalculator as fractionaloccupancycalculator
 import solventmapcreator.solvationcalculation.solvationplotinformation as solvationplotinformation
 
@@ -30,13 +31,21 @@ def create_solvation_plot(epsilon_i_list, epsilon_j_list,
                                                    polynomial_order, **kwargs)
     LOGGER.debug("Input data:")
     LOGGER.debug(input_data)
-    return plot_and_write_contour_map(input_data, **kwargs)
+    matrix_write_out = write_matrix_to_file(input_data["figure_label"] + '.csv',
+                                            epsilon_i_list, epsilon_j_list,
+                                            input_data["z_data"])
+    return plot_and_write_contour_map(input_data, **kwargs), matrix_write_out
 
 def plot_and_write_contour_map(input_data, **kwargs):
     """This creates and plots a contour map wit the input given.
     """
     return plottinginput.create_and_write_contour_plot(input_data, kwargs.get("fileformat", "eps"))
 
+def write_matrix_to_file(filename, x_values, y_values, solvation_matrix):
+    """This writes the matrix to file.
+    """
+    return solvationmapwriter.write_matrix_to_file(filename, x_values, y_values, solvation_matrix)
+
 def create_plot_input_data_from_files(epsilon_i_list, epsilon_j_list,
                                       solvent_filename, solvent_id,
                                       polynomial_filename, polynomial_order, **kwargs):
diff --git a/solventmapcreator/test/solvationcalculationtest/solvationmapgeneratortest.py b/solventmapcreator/test/solvationcalculationtest/solvationmapgeneratortest.py
index e4795d7..0807e3a 100644
--- a/solventmapcreator/test/solvationcalculationtest/solvationmapgeneratortest.py
+++ b/solventmapcreator/test/solvationcalculationtest/solvationmapgeneratortest.py
@@ -9,6 +9,7 @@ that assemble the data. The functions that write plots are not tested.
 
 import logging
 import unittest
+import os
 import numpy as np
 import solventmapcreator.solvationcalculation.solvationmapgenerator as solvationmapgenerator
 
@@ -34,6 +35,27 @@ class SolvationMapGeneratorTestCase(unittest.TestCase):
         """clean up after tests.
         """
         del self.expected_data_by_solvent_id
+        del self.epsilon_i_list
+        del self.epsilon_j_list
+        if os.path.isfile("actualsimilmatrix.csv"):
+            os.remove("actualsimilmatrix.csv")
+    def test_write_matrix_to_file(self):
+        """
+        """
+        expected_file_name = "resources/similmatrix.csv"
+        actual_file_name = "actualsimilmatrix.csv"
+        simil_out_file = solvationmapgenerator.write_matrix_to_file(actual_file_name,
+                                                            self.epsilon_i_list,
+                                                            self.epsilon_j_list,
+                                                            np.array([[-4.332289, -5.403718],
+                                                                      [-5.403718, -5.757629],
+                                                                      [-6.475146, -6.167992]]))
+        self.assertEqual(0, simil_out_file)
+        with open(expected_file_name, 'r') as exp_file:
+            exp_file_lines = exp_file.readlines()
+            with open(actual_file_name, 'r') as act_file:
+                act_file_lines = act_file.readlines()
+                self.assertListEqual(act_file_lines, exp_file_lines)
     def test_create_plot_input_data_from_files(self):
         """Test to see if expected dictionary is produced.
         """
-- 
GitLab