FAQ | This is a LIVE service | Changelog

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

add methods to deal with reading free energy information.

parent ada8220f
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,14 @@ logging.basicConfig() ...@@ -13,6 +13,14 @@ logging.basicConfig()
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.WARN) LOGGER.setLevel(logging.WARN)
def parse_free_energy_from_file_with_data_arrays(filename):
"""This reads in the information form file to a Datapoints object, and
creates the data arrays.
"""
datapoints = parse_free_energy_from_file(filename)
datapoints.createDataArrays()
return datapoints
def parse_binding_energy_from_file_with_data_arrays(filename): def parse_binding_energy_from_file_with_data_arrays(filename):
"""This reads in the information form file to a Datapoints object, and """This reads in the information form file to a Datapoints object, and
creates the data arrays. creates the data arrays.
...@@ -21,16 +29,33 @@ def parse_binding_energy_from_file_with_data_arrays(filename): ...@@ -21,16 +29,33 @@ def parse_binding_energy_from_file_with_data_arrays(filename):
datapoints.createDataArrays() datapoints.createDataArrays()
return datapoints return datapoints
def parse_free_energy_from_file(filename):
"""This parses the file and returns a datapoints representation of it.
"""
solvation_energy_dict = parse_free_energy_info(filename)
return create_free_energy_datapoints_with_values(solvation_energy_dict)
def parse_binding_energy_from_file(filename): def parse_binding_energy_from_file(filename):
"""This parses the file and returns a datapoints representation of it. """This parses the file and returns a datapoints representation of it.
""" """
solvation_energy_dict = parse_binding_energy_info(filename) solvation_energy_dict = parse_binding_energy_info(filename)
return create_binding_datapoints_with_values(solvation_energy_dict) return create_binding_datapoints_with_values(solvation_energy_dict)
def create_free_energy_datapoints_with_values(solvation_energy_dict):
"""This creates free energy datapoints.
"""
return solvationreader.create_free_energy_datapoints_with_values(solvation_energy_dict)
def create_binding_datapoints_with_values(solvation_energy_dict): def create_binding_datapoints_with_values(solvation_energy_dict):
"""This creates binding datapoints """This creates binding datapoints
""" """
return solvationreader.create_binding_datapoints_with_values(solvation_energy_dict) return solvationreader.create_binding_datapoints_with_values(solvation_energy_dict)
def parse_free_energy_info(filename):
"""This extracts the solvation information to a dictionary.
"""
return solvationreader.parse_free_energy_info(filename)
def parse_binding_energy_info(filename): def parse_binding_energy_info(filename):
"""This extracts the solvation information to a dictionary. """This extracts the solvation information to a dictionary.
""" """
......
...@@ -25,20 +25,39 @@ class SolvationEnergyReaderTestCase(unittest.TestCase): ...@@ -25,20 +25,39 @@ class SolvationEnergyReaderTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
"""Set up for tests """Set up for tests
""" """
self.solvation_info_dict = solvationenergyreader.parse_binding_energy_info("resources/energyvaluestest.xml") self.solvation_binding_info_dict = solvationenergyreader.parse_binding_energy_info("resources/energyvaluestest.xml")
self.solvation_free_info_dict = solvationenergyreader.parse_free_energy_info("resources/energyvaluestest2.xml")
self.expected_datapoints = Datapoints(("SSIP Value","Solvation Binding Energy"), (Units.dimensionless, Units.kj_per_mol)) self.expected_datapoints = Datapoints(("SSIP Value","Solvation Binding Energy"), (Units.dimensionless, Units.kj_per_mol))
self.expected_datapoints.addDatapoint(Datapoint(Value(-14.100, "SSIP Value", self.expected_datapoints.addDatapoint(Datapoint(Value(-14.100, "SSIP Value",
Units.dimensionless), Units.dimensionless),
Value(-34.8195308084233, Value(-34.8195308084233,
"Solvation Binding Energy", Units.kj_per_mol), "Solvation Binding Energy", Units.kj_per_mol),
"-14.100solute")) "-14.100solute"))
self.expected_free_energy_datapoints = Datapoints(("SSIP Value","Solvation Free Energy"),
(Units.dimensionless, Units.kj_per_mol))
self.expected_free_energy_datapoints.addDatapoint(Datapoint(Value(-14.100, "SSIP Value",
Units.dimensionless),
Value(-34.8195308084233,
"Solvation Free Energy", Units.kj_per_mol),
"-14.100solute"))
def tearDown(self): def tearDown(self):
"""Tear down after tests. """Tear down after tests.
""" """
del self.solvation_info_dict del self.solvation_binding_info_dict
del self.solvation_free_info_dict
del self.expected_datapoints del self.expected_datapoints
del self.expected_free_energy_datapoints
def test_parse_free_energy_from_file_with_data_arrays(self):
"""Test to see if expected datapoints and arrays are produced.
"""
actual_datapoints = solvationenergyreader.parse_free_energy_from_file_with_data_arrays("resources/energyvaluestest2.xml")
self.assertEqual(self.expected_free_energy_datapoints, actual_datapoints)
np.testing.assert_array_almost_equal(np.array([[-14.100]]),
actual_datapoints.x_values)
np.testing.assert_array_almost_equal(np.array([[-34.8195308084233]]),
actual_datapoints.y_values)
def test_parse_binding_energy_from_file_with_data_arrays(self): def test_parse_binding_energy_from_file_with_data_arrays(self):
"""Test to see if """Test to see if expected datapoints and arrays are produced.
""" """
actual_datapoints = solvationenergyreader.parse_binding_energy_from_file_with_data_arrays("resources/energyvaluestest.xml") actual_datapoints = solvationenergyreader.parse_binding_energy_from_file_with_data_arrays("resources/energyvaluestest.xml")
self.assertEqual(self.expected_datapoints, actual_datapoints) self.assertEqual(self.expected_datapoints, actual_datapoints)
...@@ -46,24 +65,50 @@ class SolvationEnergyReaderTestCase(unittest.TestCase): ...@@ -46,24 +65,50 @@ class SolvationEnergyReaderTestCase(unittest.TestCase):
actual_datapoints.x_values) actual_datapoints.x_values)
np.testing.assert_array_almost_equal(np.array([[-34.8195308084233]]), np.testing.assert_array_almost_equal(np.array([[-34.8195308084233]]),
actual_datapoints.y_values) actual_datapoints.y_values)
def test_parse_free_energy_from_file(self):
"""Test to see if expected Datapoints object is created from reading of
a file.
"""
actual_datapoints = solvationenergyreader.parse_free_energy_from_file("resources/energyvaluestest2.xml")
self.assertEqual(self.expected_free_energy_datapoints, actual_datapoints)
def test_parse_binding_energy_from_file(self): def test_parse_binding_energy_from_file(self):
"""Test to see if expected Datapoints object is created from reading of """Test to see if expected Datapoints object is created from reading of
a file. a file.
""" """
actual_datapoints = solvationenergyreader.parse_binding_energy_from_file("resources/energyvaluestest.xml") actual_datapoints = solvationenergyreader.parse_binding_energy_from_file("resources/energyvaluestest.xml")
self.assertEqual(self.expected_datapoints, actual_datapoints) self.assertEqual(self.expected_datapoints, actual_datapoints)
def test_create_free_energy_datapoints_with_values(self):
"""Test to see if expected Datapoints object is created.
"""
actual_datapoints = solvationenergyreader.create_free_energy_datapoints_with_values(self.solvation_free_info_dict)
self.assertEqual(self.expected_free_energy_datapoints, actual_datapoints)
def test_create_binding_datapoints_with_values(self): def test_create_binding_datapoints_with_values(self):
"""Test to see if expected Datapoints object is created. """Test to see if expected Datapoints object is created.
""" """
actual_datapoints = solvationenergyreader.create_binding_datapoints_with_values(self.solvation_info_dict) actual_datapoints = solvationenergyreader.create_binding_datapoints_with_values(self.solvation_binding_info_dict)
self.assertEqual(self.expected_datapoints, actual_datapoints) self.assertEqual(self.expected_datapoints, actual_datapoints)
def test_parse_free_energy_info(self):
"""Test to see if expected free energy values are extracted from file.
"""
expected_dict = {"total_energy": -34.8195308084233, "value_type":"MOLEFRACTION",
"to_solvent_id":"water", "from_solvent_id":"",
"stdinchikey":"-14.100solute"}
actual_dict_dict = self.solvation_free_info_dict
self.assertListEqual(["-14.100solute"], sorted(actual_dict_dict.keys()))
actual_dict = actual_dict_dict["-14.100solute"]
self.assertListEqual(sorted(expected_dict.keys()), sorted(actual_dict.keys()))
for key, value in expected_dict.items():
if key == "total_energy":
self.assertAlmostEqual(value, actual_dict[key])
else:
self.assertEqual(value, actual_dict[key])
def test_parse_binding_energy_info(self): def test_parse_binding_energy_info(self):
"""Test to see if expected free energy values are extracted from file. """Test to see if expected free energy values are extracted from file.
""" """
expected_dict = {"total_energy": -34.8195308084233, "value_type":"MOLEFRACTION", expected_dict = {"total_energy": -34.8195308084233, "value_type":"MOLEFRACTION",
"to_solvent_id":"water", "from_solvent_id":"", "to_solvent_id":"water", "from_solvent_id":"",
"stdinchikey":"-14.100solute"} "stdinchikey":"-14.100solute"}
actual_dict_dict = solvationenergyreader.parse_binding_energy_info("resources/energyvaluestest.xml") actual_dict_dict = self.solvation_binding_info_dict
self.assertListEqual(["-14.100solute"], sorted(actual_dict_dict.keys())) self.assertListEqual(["-14.100solute"], sorted(actual_dict_dict.keys()))
actual_dict = actual_dict_dict["-14.100solute"] actual_dict = actual_dict_dict["-14.100solute"]
self.assertListEqual(sorted(expected_dict.keys()), sorted(actual_dict.keys())) self.assertListEqual(sorted(expected_dict.keys()), sorted(actual_dict.keys()))
......
<?xml version='1.0' encoding='UTF-8'?>
<phase:EnergyValues xmlns:phase="http://www-hunter.ch.cam.ac.uk/PhaseSchema">
<phase:FreeEnergyCollection><phase:FreeEnergy phase:moleculeID="-14.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION">
<phase:TotalEnergy>-34.8195308084233</phase:TotalEnergy>
<phase:EnergyContributions>
<phase:EnergyContribution phase:ssipID="1">-34.8195308084233</phase:EnergyContribution>
</phase:EnergyContributions>
</phase:FreeEnergy>
</phase:FreeEnergyCollection>
</phase:EnergyValues>
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