FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 4026533a authored by Mark Driver's avatar Mark Driver
Browse files

add function for reading polynomial files.

parent c1769a1c
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ Script for running polynomial generation.
"""
import logging
import solventmapcreator.io.polynomialdatareader as polyread
import solventmapcreator.polynomialanalysis.polynomialplotting as polyplot
logging.basicConfig()
......@@ -34,6 +35,28 @@ POSITIVE_POINTS = ["{:.3f}solute".format((float(x)/10.0)) for x in range(101)]
NEGATIVE_POINTS = ["{:.3f}solute".format((float(x)/10.0) - 20.0) for x in range(201)]
def read_poly_data_to_dict(poly_filename_list, **kwargs):
"""Parse each file, and then returns the dictionary of information, by solvent ID.
Parameters
----------
poly_filename_list : list
list of polynomial file names.
suffix : str, optional
polynomial file suffix.
temperature_dir : bool, optional
if files are in temperature based directories, indicates to include
the preceding directory name in solvent ID to be able to distiguish
the same solvent composition at different temperatures.
Returns
-------
dict
dict of polynomial data by solvent ID.
"""
return polyread.parse_polynomial_data_file_list(poly_filename_list, **kwargs)
def generate_polynomial_data_free_energy_file_list(free_energy_filename_list):
"""Generate polynomial fits for free energy data in given files.
......
......@@ -44,6 +44,7 @@ class PolynomialIOTestCase(unittest.TestCase):
None.
"""
self.maxDiff = None
parent_directory = pathlib.Path(__file__).parents[1]
self.binding_file = (parent_directory / "resources"/ "expected_parsedbinding.xml").absolute().as_posix()
self.expected_binding_poly = (parent_directory / "resources"/ "expected_bindingpoly.csv").absolute().as_posix()
......@@ -63,8 +64,37 @@ class PolynomialIOTestCase(unittest.TestCase):
os.remove(self.actual_binding_poly_file)
if os.path.isfile(self.actual_free_poly_file):
os.remove(self.actual_free_poly_file)
def test_read_poly_data_to_dict(self):
"""Test expected_polynomial information read in.
Returns
-------
None.
"""
expected_dict = {'resourcesexpected,parsed':{8: {'negative': {'RMSE': 0.0137444779,
'coefficients': np.array([-2.60836624e-01, 4.65295250e-01, 2.57637417e-01, 2.19491128e-01,
4.20087475e-02, 4.02289353e-03, 2.12247938e-04, 5.89243946e-06,
6.73443996e-08]),
'covar': 0.0379710451935,
'order': 8},
'positive': {'RMSE': 0.008907316,
'coefficients': np.array([-2.52075337e-01, -7.07009850e-01, 9.86359325e-01, -1.40859321e+00,
5.04060101e-01, -9.17970326e-02, 9.28812463e-03, -4.97458825e-04,
1.10198937e-05]),
'covar': 0.008013368123414,
'order': 8}}}}
actual_dict = polyio.read_poly_data_to_dict([self.expected_free_poly], suffix="freepoly.csv",
temperature_dir=True)
self.assertListEqual(list(expected_dict.keys()), list(actual_dict.keys()))
for region, info_dict in actual_dict['resourcesexpected,parsed'][8].items():
for key, value in info_dict.items():
if key == "coefficients":
np.testing.assert_allclose(value, expected_dict['resourcesexpected,parsed'][8][region][key])
else:
self.assertEqual(value, expected_dict['resourcesexpected,parsed'][8][region][key])
def test_generate_polynomial_data_free_energy_file_list(self):
"""Test expected polynomial data ouputed.
"""Test expected polynomial data outputed.
Returns
-------
......
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