FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit fcbee42b authored by M.D. Driver's avatar M.D. Driver
Browse files

added writer for solvation matrix.

parent f9f209e9
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script for writing out the solvation values generated for a solvent map.
Format is
Y1 Y2 ...
X1 S(X1,Y1) S(X1,Y2) ...
X2 S(X2,Y1) S(X2,Y2) ...
. .
. .
. .
XN S(XN,Y1) S(XN,Y2) ...
@author: mark
"""
import logging
import csv
logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.WARN)
def write_matrix_to_file(filename, x_values, y_values, solvation_matrix):
"""This writes the matrix to file.
"""
with open(filename, 'w') as outfile:
csv_writer = csv.writer(outfile, delimiter='\t',
quoting=csv.QUOTE_NONE)
csv_writer.writerow(["", *y_values])
for i in range(len(x_values)):
csv_writer.writerow(write_matrix_line(x_values[i], solvation_matrix[i]))
return 0
def write_matrix_line(x_value, solvation_matrix_row):
"""This creates the list of entries ready for writing.
"""
return ["{:.3f}".format(x_value), *["{:.7f}".format(val) for val in solvation_matrix_row]]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 13 22:42:58 2017
@author: mark
"""
import logging
import numpy as np
import os
import unittest
import solventmapcreator.io.solvationmapwriter as solvmapwriter
logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.WARN)
class SolvationMapWriterTestCase(unittest.TestCase):
"""Test case for the solvation
"""
def setUp(self):
"""Set up for tests.
"""
self.x_list = np.array([float(x) for x in range(3)])
self.y_list = np.array([float(x) for x in range(2)])
self.similarity_matrix = np.array([[-4.332289, -5.403718],
[-5.403718, -5.757629],
[-6.475146, -6.167992]])
def tearDown(self):
"""Clean up after tests
"""
del self.x_list
del self.y_list
del self.similarity_matrix
if os.path.isfile("actualsimilmatrix.csv"):
os.remove("actualsimilmatrix.csv")
def test_write_similarity_matrix_file(self):
"""Test to see if expected file is written out.
"""
expected_file_name = "resources/similmatrix.csv"
actual_file_name = "actualsimilmatrix.csv"
simil_out_file = solvmapwriter.write_matrix_to_file(actual_file_name,
self.x_list,
self.y_list,
self.similarity_matrix)
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_file_line(self):
"""Test to see if expected list is returned.
"""
expected_list = ['0.000', '-4.3322890', '-5.4037180']
actual_list = solvmapwriter.write_matrix_line(self.x_list[0], self.similarity_matrix[0])
self.assertListEqual(expected_list, actual_list)
\ No newline at end of file
0.0 1.0
0.000 -4.3322890 -5.4037180
1.000 -5.4037180 -5.7576290
2.000 -6.4751460 -6.1679920
......@@ -15,6 +15,7 @@ from solventmapcreator.test.iotest.polynomialdatareadertest import PolynomialDat
from solventmapcreator.test.iotest.similaritymatrixwritertest import SimilarityMatrixWriterTestCase
from solventmapcreator.test.iotest.similaritymatrixreadertest import SimilarityMatrixReaderTestCase
from solventmapcreator.test.iotest.linkagewritertest import LinkageWriterTestCase
from solventmapcreator.test.iotest.solvationmapwritertest import SolvationMapWriterTestCase
from solventmapcreator.test.solvationcalculationtest.solvationcalculatortest import SolvationCalculatorTestCase
from solventmapcreator.test.solvationcalculationtest.solvationmapgeneratortest import SolvationMapGeneratorTestCase
from solventmapcreator.test.solvationcalculationtest.solvationplotinformationtest import SolvationPlotInformationTestCase
......@@ -34,7 +35,7 @@ LOGGER.setLevel(logging.WARN)
IO_TEST_CASES = [SolvationEnergyReaderTestCase, SolventXMLReaderTestCase,
PolynomialDataWriterTestCase, PolynomialDataReaderTestCase,
SimilarityMatrixReaderTestCase, SimilarityMatrixWriterTestCase,
LinkageWriterTestCase]
LinkageWriterTestCase, SolvationMapWriterTestCase]
SOLVATION_CALCULATION_TEST_CASES = [SolvationCalculatorTestCase,
SolvationMapGeneratorTestCase,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment