From a0c87679e615878731bbec9221399f6ef2854fce Mon Sep 17 00:00:00 2001 From: Mark Driver <mdd31@cam.ac.uk> Date: Tue, 18 Jul 2017 17:06:27 +0100 Subject: [PATCH] added function and corresponding test for getting fractional occupancy from file. --- solventmapcreator/io/solventxmlreader.py | 7 +++++++ solventmapcreator/test/iotest/solventxmlreadertest.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/solventmapcreator/io/solventxmlreader.py b/solventmapcreator/io/solventxmlreader.py index c4adb70..1ef1bec 100644 --- a/solventmapcreator/io/solventxmlreader.py +++ b/solventmapcreator/io/solventxmlreader.py @@ -23,6 +23,13 @@ PHASE_NAMESPACE_DICT = {"phase":"http://www-hunter.ch.cam.ac.uk/PhaseSchema", IDEAL_MAX_SSIP_CONCENTRATION_MOLAR = 300.0 +def get_fractional_occupancy_for_solvent_from_file(solvent_filename, solvent_id): + """This reads inthe file and extracts the solvent information, and returns + the fractional occupancy contribution from the solvent. + """ + solvent_list_element = read_element_tree(solvent_filename) + return get_fractional_occupancy_for_solvent(solvent_list_element, solvent_id) + def get_fractional_occupancy_for_solvent(solvent_list_element, solvent_id): """This extracts the solvent XML, and calculates the fractional occupancy contribution for the solvent. diff --git a/solventmapcreator/test/iotest/solventxmlreadertest.py b/solventmapcreator/test/iotest/solventxmlreadertest.py index 2b900a7..bb685f4 100644 --- a/solventmapcreator/test/iotest/solventxmlreadertest.py +++ b/solventmapcreator/test/iotest/solventxmlreadertest.py @@ -31,6 +31,12 @@ class SolventXMLReaderTestCase(unittest.TestCase): del self.solvent_list_xml del self.water_solvent_element del self.water_molecule_element + def test_get_fractional_occupancy_for_solvent_from_file(self): + """Test to see if expected value is returned. + """ + expected_value = 55.35 * 4.0 /300.0 + actual_value = solventxmlreader.get_fractional_occupancy_for_solvent_from_file("resources/watersolvent.xml", "water") + self.assertAlmostEqual(expected_value, actual_value) def test_get_fractional_occupancy_for_solvent(self): """Test to see if expected fractional occupancy is returned. """ -- GitLab