From ada8220f874aaf5df63e441ee3d021deae2cb1a3 Mon Sep 17 00:00:00 2001 From: Mark Driver <mdd31@cam.ac.uk> Date: Mon, 19 Mar 2018 19:10:05 +0000 Subject: [PATCH] update to make use of validation of XML, and also rename of methods to make clear the existing functions operate on binding energies. --- solventmapcreator/io/solvationenergyreader.py | 21 ++- solventmapcreator/io/solventxmlreader.py | 29 ++--- .../polynomialanalysis/polynomialplotting.py | 34 ++--- .../test/iotest/solvationenergyreadertest.py | 22 ++-- .../test/iotest/solventxmlreadertest.py | 123 +++++++++++------- .../polynomialplottingtest.py | 22 ++-- .../test/resources/energyvaluestest.xml | 6 +- solventmapcreator/test/resources/water.xml | 44 +++---- .../test/resources/watersolvent.xml | 48 ++++--- 9 files changed, 194 insertions(+), 155 deletions(-) diff --git a/solventmapcreator/io/solvationenergyreader.py b/solventmapcreator/io/solvationenergyreader.py index 437f231..2e116fc 100644 --- a/solventmapcreator/io/solvationenergyreader.py +++ b/solventmapcreator/io/solvationenergyreader.py @@ -13,26 +13,25 @@ logging.basicConfig() LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.WARN) -def parse_free_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 creates the data arrays. """ - datapoints = parse_free_energy_from_file(filename) + datapoints = parse_binding_energy_from_file(filename) datapoints.createDataArrays() return datapoints -def parse_free_energy_from_file(filename): +def parse_binding_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_datapoints_with_values(solvation_energy_dict) - -def create_datapoints_with_values(solvation_energy_dict): - """ + solvation_energy_dict = parse_binding_energy_info(filename) + return create_binding_datapoints_with_values(solvation_energy_dict) +def create_binding_datapoints_with_values(solvation_energy_dict): + """This creates binding datapoints """ - return solvationreader.create_datapoints_with_values(solvation_energy_dict) + return solvationreader.create_binding_datapoints_with_values(solvation_energy_dict) -def parse_free_energy_info(filename): +def parse_binding_energy_info(filename): """This extracts the solvation information to a dictionary. """ - return solvationreader.parse_free_energy_info(filename) + return solvationreader.parse_binding_energy_info(filename) diff --git a/solventmapcreator/io/solventxmlreader.py b/solventmapcreator/io/solventxmlreader.py index b9395ba..414062a 100644 --- a/solventmapcreator/io/solventxmlreader.py +++ b/solventmapcreator/io/solventxmlreader.py @@ -12,6 +12,7 @@ This allows the calculation of the fractional occupancy of the phase. import logging from lxml import etree +import resultsanalysis.fileparsing.xmlparsing.xmlvalidation as xmlvalidation logging.basicConfig() LOGGER = logging.getLogger(__name__) @@ -40,7 +41,7 @@ def get_fractional_occupancy_for_solvent(solvent_list_element, solvent_id): def calculate_fractional_occupancy_for_solvent(solvent_element): """This calculates the contribution to the fractional occupancy from the solvent. """ - xpath_expression = "phase:Molecule" + xpath_expression = "phase:Molecules/phase:Molecule" molecule_element_list = solvent_element.xpath(xpath_expression, namespaces=PHASE_NAMESPACE_DICT) solvent_fractional_occupancy = 0.0 for molecule_element in molecule_element_list: @@ -51,27 +52,23 @@ def calculate_fractional_occupancy_for_solvent(solvent_element): def calculate_fractional_occupancy_contribution(molecule_element): """This calculates the contribution to the fractional occupancy for this species. """ - concentration_value = get_concentration_value(molecule_element) - number_of_ssips = get_number_of_ssips_in_molecule(molecule_element) - return (concentration_value * number_of_ssips)/IDEAL_MAX_SSIP_CONCENTRATION_MOLAR + concentration_sum_value = get_concentration_value_sum(molecule_element) + return (concentration_sum_value)/IDEAL_MAX_SSIP_CONCENTRATION_MOLAR -def get_concentration_value(molecule_element): +def get_concentration_value_sum(molecule_element): """This extracts the concentration. """ - xpath_expression = "phase:Concentration" + xpath_expression = "phase:SSIPs/phase:SSIP/phase:TotalConcentration" concentration_element_list = molecule_element.xpath(xpath_expression, namespaces=PHASE_NAMESPACE_DICT) - if len(concentration_element_list) == 1: - return float(concentration_element_list[0].text) - else: - LOGGER.debug("len:") - LOGGER.debug(len(concentration_element_list)) - LOGGER.debug(concentration_element_list) - raise ValueError("Wrong number of Concentration Elements.") + total_concentration = 0.0 + for i in range(len(concentration_element_list)): + total_concentration += float(concentration_element_list[0].text) + return total_concentration def get_number_of_ssips_in_molecule(molecule_element): """This extracts the SSIP elements and return the number. """ - xpath_expression = "ssip:SSIPList/ssip:SSIP" + xpath_expression = "phase:SSIPs/phase:SSIP" ssip_element_list = molecule_element.xpath(xpath_expression, namespaces=PHASE_NAMESPACE_DICT) return len(ssip_element_list) @@ -92,9 +89,9 @@ def create_solvent_xpath_expression(solvent_id): """This creates the xpath expression to extract the solvent Element based on solventID. """ - return 'phase:Solvent[@phase:solventID="{:s}"]'.format(solvent_id) + return 'phase:Solvents/phase:Solvent[@phase:solventID="{:s}"]'.format(solvent_id) def read_element_tree(filename): """This reads in an xml file to an element tree. """ - return etree.parse(filename) + return xmlvalidation.validate_and_read_xml_file(filename, xmlvalidation.PHASE_SCHEMA) diff --git a/solventmapcreator/polynomialanalysis/polynomialplotting.py b/solventmapcreator/polynomialanalysis/polynomialplotting.py index 9272bdd..964efbf 100644 --- a/solventmapcreator/polynomialanalysis/polynomialplotting.py +++ b/solventmapcreator/polynomialanalysis/polynomialplotting.py @@ -18,13 +18,15 @@ logging.basicConfig() LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.WARN) -def plot_energies_from_file(free_energy_filename, polynomial_order, **kwargs): +def plot_binding_energies_from_file(free_energy_filename, polynomial_order, **kwargs): """This creates in the plotting information, and outputs a plot to file. """ - plot_data = parse_energies_create_plot_input_data(free_energy_filename, - polynomial_order, - kwargs.get("pos_subset_list", None), - kwargs.get("neg_subset_list", None)) + plot_data = parse_binding_energies_create_plot_input_data(free_energy_filename, + polynomial_order, + kwargs.get("pos_subset_list", + None), + kwargs.get("neg_subset_list", + None)) if type(plot_data['polynomial coefficients']) is dict: return create_scatter_with_split_poly(plot_data, **kwargs) else: @@ -49,12 +51,12 @@ def create_scatter_with_split_poly(input_data, **kwargs): plottinginput.plt.close(scatter_plot) return 0 -def parse_energies_create_plot_input_data(free_energy_filename, polynomial_order, - pos_subset_list=None, neg_subset_list=None): +def parse_binding_energies_create_plot_input_data(free_energy_filename, polynomial_order, + pos_subset_list=None, neg_subset_list=None): """This creates the input data for a plot. This overrides the default figure label, so that the figures can be distinguished based on the solvent. """ - datapoints = parse_free_energy_from_file_with_data_arrays(free_energy_filename) + datapoints = parse_binding_energy_from_file_with_data_arrays(free_energy_filename) plot_data = datapoints.generateScatterPlotParameters(label_type='', polynomial_order=polynomial_order) if pos_subset_list != None and neg_subset_list != None: poly_coeff_dict = generate_poly_pos_neg_separate_fit(datapoints, polynomial_order, @@ -74,12 +76,12 @@ def generate_poly_pos_neg_separate_fit(datapoints, order, pos_subset_list, neg_s return {"positive":poly_dict["positive"]["coefficients"], "negative":poly_dict["negative"]["coefficients"]} -def parse_poly_data_to_file_split_fit(free_energy_filename, order_list, poly_filename, +def parse_poly_data_to_file_split_fit(binding_energy_filename, order_list, poly_filename, pos_subset_list, neg_subset_list): """This reads in the energy information, and then performs the fits on the two separate subsets, and outputs to file. """ - datapoints = parse_free_energy_from_file_with_data_arrays(free_energy_filename) + datapoints = parse_binding_energy_from_file_with_data_arrays(binding_energy_filename) return write_poly_data_to_file_split_fit(datapoints, order_list, poly_filename, pos_subset_list, neg_subset_list) @@ -94,21 +96,21 @@ def write_poly_data_to_file_split_fit(datapoints, order_list, filename, pos_subset_list, neg_subset_list) -def parse_energies_and_output_poly_data_subset(free_energy_filename, order_list, poly_filename, subset_list): +def parse_binding_energies_and_output_poly_data_subset(free_energy_filename, order_list, poly_filename, subset_list): """This reads in the energy information, and then selects teh subset of points to carry out the analysis on, outputs the polynomial information to file. """ - datapoints = parse_free_energy_from_file_with_data_arrays(free_energy_filename) + datapoints = parse_binding_energy_from_file_with_data_arrays(free_energy_filename) datapoints_subset = datapoints.createDatapointsSubGroup(subset_list) datapoints_subset.createDataArrays() return write_poly_data_to_file(datapoints_subset, order_list, poly_filename) -def parse_energies_and_output_poly_data(free_energy_filename, order_list, poly_filename): +def parse_binding_energies_and_output_poly_data(free_energy_filename, order_list, poly_filename): """This reads in the energy information, and then outputs the polynomial information to file. """ - datapoints = parse_free_energy_from_file_with_data_arrays(free_energy_filename) + datapoints = parse_binding_energy_from_file_with_data_arrays(free_energy_filename) return write_poly_data_to_file(datapoints, order_list, poly_filename) def write_poly_data_to_file(datapoints, order_list, filename): @@ -117,8 +119,8 @@ def write_poly_data_to_file(datapoints, order_list, filename): """ return polynomialdatawriter.write_poly_data_to_file(datapoints, order_list, filename) -def parse_free_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 creates the data arrays. """ - return solvationenergyreader.parse_free_energy_from_file_with_data_arrays(filename) + return solvationenergyreader.parse_binding_energy_from_file_with_data_arrays(filename) diff --git a/solventmapcreator/test/iotest/solvationenergyreadertest.py b/solventmapcreator/test/iotest/solvationenergyreadertest.py index 3bc05ee..f908f87 100644 --- a/solventmapcreator/test/iotest/solvationenergyreadertest.py +++ b/solventmapcreator/test/iotest/solvationenergyreadertest.py @@ -25,45 +25,45 @@ class SolvationEnergyReaderTestCase(unittest.TestCase): def setUp(self): """Set up for tests """ - self.solvation_info_dict = solvationenergyreader.parse_free_energy_info("resources/energyvaluestest.xml") - self.expected_datapoints = Datapoints(("SSIP Value","Solvation Energy"), (Units.dimensionless, Units.kj_per_mol)) + self.solvation_info_dict = solvationenergyreader.parse_binding_energy_info("resources/energyvaluestest.xml") + 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", Units.dimensionless), Value(-34.8195308084233, - "Solvation Energy", Units.kj_per_mol), + "Solvation Binding Energy", Units.kj_per_mol), "-14.100solute")) def tearDown(self): """Tear down after tests. """ del self.solvation_info_dict del self.expected_datapoints - def test_parse_free_energy_from_file_with_data_arrays(self): + def test_parse_binding_energy_from_file_with_data_arrays(self): """Test to see if """ - actual_datapoints = solvationenergyreader.parse_free_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) 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_free_energy_from_file(self): + def test_parse_binding_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/energyvaluestest.xml") + actual_datapoints = solvationenergyreader.parse_binding_energy_from_file("resources/energyvaluestest.xml") self.assertEqual(self.expected_datapoints, actual_datapoints) - def test_create_datapoints_with_values(self): + def test_create_binding_datapoints_with_values(self): """Test to see if expected Datapoints object is created. """ - actual_datapoints = solvationenergyreader.create_datapoints_with_values(self.solvation_info_dict) + actual_datapoints = solvationenergyreader.create_binding_datapoints_with_values(self.solvation_info_dict) self.assertEqual(self.expected_datapoints, actual_datapoints) - def test_parse_free_energy_info(self): + def test_parse_binding_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 = solvationenergyreader.parse_free_energy_info("resources/energyvaluestest.xml") + actual_dict_dict = solvationenergyreader.parse_binding_energy_info("resources/energyvaluestest.xml") 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())) diff --git a/solventmapcreator/test/iotest/solventxmlreadertest.py b/solventmapcreator/test/iotest/solventxmlreadertest.py index bb685f4..aacf439 100644 --- a/solventmapcreator/test/iotest/solventxmlreadertest.py +++ b/solventmapcreator/test/iotest/solventxmlreadertest.py @@ -22,8 +22,8 @@ class SolventXMLReaderTestCase(unittest.TestCase): """Set up for tests. """ self.solvent_list_xml = solventxmlreader.read_element_tree("resources/watersolvent.xml") - self.water_solvent_element = self.solvent_list_xml.xpath("phase:Solvent", namespaces=solventxmlreader.PHASE_NAMESPACE_DICT)[0] - self.water_molecule_element = self.water_solvent_element.xpath("phase:Molecule", namespaces=solventxmlreader.PHASE_NAMESPACE_DICT)[0] + self.water_solvent_element = self.solvent_list_xml.xpath("phase:Solvents/phase:Solvent", namespaces=solventxmlreader.PHASE_NAMESPACE_DICT)[0] + self.water_molecule_element = self.water_solvent_element.xpath("phase:Molecules/phase:Molecule", namespaces=solventxmlreader.PHASE_NAMESPACE_DICT)[0] self.maxDiff=None def tearDown(self): """Tear down after tests. @@ -56,11 +56,11 @@ class SolventXMLReaderTestCase(unittest.TestCase): expected_value = 55.35* 4.0 / 300.0 actual_value = solventxmlreader.calculate_fractional_occupancy_contribution(self.water_molecule_element) self.assertAlmostEqual(expected_value, actual_value) - def test_get_concentration_value(self): + def test_get_concentration_value_sum(self): """Test to see if expected concentration is returned """ - expected_value = 55.3500 - actual_value = solventxmlreader.get_concentration_value(self.water_molecule_element) + expected_value = 55.3500 * 4 + actual_value = solventxmlreader.get_concentration_value_sum(self.water_molecule_element) self.assertAlmostEqual(expected_value, actual_value) def test_get_number_of_ssips_in_molecule(self): """Test to see if expected number of SSIPs is returned. @@ -71,56 +71,81 @@ class SolventXMLReaderTestCase(unittest.TestCase): def test_get_solvent_element_by_id(self): """Test to see if expected solvent element is returned. """ - expected_xml = ('<phase:Solvent xmlns:phase="http://www-hunter.ch.cam.ac.uk/PhaseSchema" xmlns:cml="http://www.xml-cml.org/schema" xmlns:ssip="http://www-hunter.ch.cam.ac.uk/SSIP" phase:solventID="water" phase:solven' + - 'tName="water" phase:numberOfMolecules="1">\n' + - ' <phase:Molecule phase:stdInChIKey="XLYOFNOQVPJJNP-UHFFFAOYSA-N">\n' + - ' <ssip:SSIPList>\n' + - '\t\t\t<ssip:SurfaceInformation numberOfPoints="1000">\n' + - '\t\t\t\t<ssip:IsosurfaceDensity>0.002</ssip:IsosurfaceDensity>\n' + - '\t\t\t\t<ssip:TotalSurfaceArea>10.0</ssip:TotalSurfaceArea>\n' + - '\t\t\t\t<ssip:NegativeSurfaceArea>5.0</ssip:NegativeSurfaceArea>\n' + - '\t\t\t\t<ssip:PositiveSurfaceArea>5.0</ssip:PositiveSurfaceArea>\n' + - '\t\t\t</ssip:SurfaceInformation>\n' + - '\t\t\t<ssip:SSIP x3="1.0" y3="0.0" z3="0.0" nearestAtomID="a1">2.8</ssip:SSIP>\n' + - '\t\t\t<ssip:SSIP x3="1.0" y3="1.0" z3="1.0" nearestAtomID="a1">2.8</ssip:SSIP>\n' + - '\t\t\t<ssip:SSIP x3="0.0" y3="1.0" z3="1.0" nearestAtomID="a1">-4.5</ssip:SSIP>\n' + - '\t\t\t<ssip:SSIP x3="0.0" y3="1.0" z3="0.0" nearestAtomID="a1">-4.5</ssip:SSIP>\n' + - '\t\t</ssip:SSIPList>\n' + - ' <phase:Concentration phase:units="MOLAR">55.350000</phase:Concentration>\n' + - ' </phase:Molecule>\n' + - ' </phase:Solvent>\n') + expected_xml = '''<phase:Solvent xmlns:phase="http://www-hunter.ch.cam.ac.uk/PhaseSchema" xmlns:cml="http://www.xml-cml.org/schema" xmlns:ssip="http://www-hunter.ch.cam.ac.uk/SSIP" phase:solventID="water" phase:solventName="water"> + <phase:Molecules> + <phase:Molecule phase:stdInChIKey="XLYOFNOQVPJJNP-UHFFFAOYSA-N"><cml:molecule ssip:stdInChIKey="XLYOFNOQVPJJNP-UHFFFAOYSA-N" cml:id="XLYOFNOQVPJJNP-UHFFFAOYSA-N"> + <cml:atomArray> + <cml:atom cml:elementType="O" cml:id="a1" cml:x3="0.0569236794019" cml:y3="0.53497425302" cml:z3="-9.99862395488E-5"/> + <cml:atom cml:elementType="H" cml:id="a2" cml:x3="-0.735721920018" cml:y3="-0.0219270863225" cml:z3="-1.029173866E-4"/> + <cml:atom cml:elementType="H" cml:id="a3" cml:x3="0.785198240616" cml:y3="-0.103847166698" cml:z3="-1.97096373822E-4"/> + </cml:atomArray> + <cml:bondArray> + <cml:bond cml:atomRefs2="a1 a2" cml:order="1"/> + <cml:bond cml:atomRefs2="a1 a3" cml:order="1"/> + </cml:bondArray> + </cml:molecule> + <ssip:SurfaceInformation> + <ssip:TotalSurfaceArea>37.48483410829331</ssip:TotalSurfaceArea> + <ssip:NegativeSurfaceArea>18.664358683092974</ssip:NegativeSurfaceArea> + <ssip:PositiveSurfaceArea>18.82047542519977</ssip:PositiveSurfaceArea> + <ssip:ElectronDensityIsosurface>0.002</ssip:ElectronDensityIsosurface> + <ssip:NumberOFMEPSPoints>2286</ssip:NumberOFMEPSPoints> + </ssip:SurfaceInformation> + <phase:SSIPs phase:units="MOLAR"> + <phase:SSIP ssip:value="2.9387503903833574" ssip:nearestAtomID="a3" cml:x3="1.509794550767402" cml:y3="-0.8784982637871289" cml:z3="-1.6986589692899999E-4" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + <phase:SSIP ssip:value="2.9275582734233065" ssip:nearestAtomID="a2" cml:x3="-1.4603207114038939" cml:y3="-0.790973405157027" cml:z3="0.12362427220238399" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + <phase:SSIP ssip:value="-6.263074063139137" ssip:nearestAtomID="a1" cml:x3="0.156188781751346" cml:y3="1.6969169177862917" cml:z3="1.172598045109361" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + <phase:SSIP ssip:value="-6.607684490829715" ssip:nearestAtomID="a1" cml:x3="0.06855491260794999" cml:y3="1.9788577934582507" cml:z3="-0.77762067563301" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + </phase:SSIPs> +</phase:Molecule> + </phase:Molecules> + </phase:Solvent> + +''' actual_xml = solventxmlreader.get_solvent_element_by_id(self.solvent_list_xml, "water") - self.assertEqual(expected_xml, etree.tounicode(actual_xml)) + self.assertMultiLineEqual(expected_xml, etree.tounicode(actual_xml, pretty_print=True)) def test_create_solvent_xpath_expression(self): - """Test to seeif expected xpath expression is created. + """Test to see if expected xpath expression is created. """ - expected_expression = 'phase:Solvent[@phase:solventID="water"]' + expected_expression = 'phase:Solvents/phase:Solvent[@phase:solventID="water"]' actual_expression = solventxmlreader.create_solvent_xpath_expression("water") self.assertEqual(expected_expression, actual_expression) def test_read_element_tree(self): """Test to see if expected file is read in. """ - expected_xml = ('<phase:SolventList xmlns:cml="http://www.xml-cml.org/sch' + - 'ema" xmlns:phase="http://www-hunter.ch.cam.ac.uk/PhaseSc' + - 'hema" xmlns:ssip="http://www-hunter.ch.cam.ac.uk/SSIP">' + - '\n <phase:Solvent phase:solventID="water" phase:solven' + - 'tName="water" phase:numberOfMolecules="1">\n' + - ' <phase:Molecule phase:stdInChIKey="XLYOFNOQVPJJNP-UHFFFAOYSA-N">\n' + - ' <ssip:SSIPList>\n' + - '\t\t\t<ssip:SurfaceInformation numberOfPoints="1000">\n' + - '\t\t\t\t<ssip:IsosurfaceDensity>0.002</ssip:IsosurfaceDensity>\n' + - '\t\t\t\t<ssip:TotalSurfaceArea>10.0</ssip:TotalSurfaceArea>\n' + - '\t\t\t\t<ssip:NegativeSurfaceArea>5.0</ssip:NegativeSurfaceArea>\n' + - '\t\t\t\t<ssip:PositiveSurfaceArea>5.0</ssip:PositiveSurfaceArea>\n' + - '\t\t\t</ssip:SurfaceInformation>\n' + - '\t\t\t<ssip:SSIP x3="1.0" y3="0.0" z3="0.0" nearestAtomID="a1">2.8</ssip:SSIP>\n' + - '\t\t\t<ssip:SSIP x3="1.0" y3="1.0" z3="1.0" nearestAtomID="a1">2.8</ssip:SSIP>\n' + - '\t\t\t<ssip:SSIP x3="0.0" y3="1.0" z3="1.0" nearestAtomID="a1">-4.5</ssip:SSIP>\n' + - '\t\t\t<ssip:SSIP x3="0.0" y3="1.0" z3="0.0" nearestAtomID="a1">-4.5</ssip:SSIP>\n' + - '\t\t</ssip:SSIPList>\n' + - ' <phase:Concentration phase:units="MOLAR">55.350000</phase:Concentration>\n' + - ' </phase:Molecule>\n' + - ' </phase:Solvent>\n' + - '</phase:SolventList>') + expected_xml = '''<phase:SolventList xmlns:cml="http://www.xml-cml.org/schema" xmlns:phase="http://www-hunter.ch.cam.ac.uk/PhaseSchema" xmlns:ssip="http://www-hunter.ch.cam.ac.uk/SSIP"> + <phase:Solvents> + <phase:Solvent phase:solventID="water" phase:solventName="water"> + <phase:Molecules> + <phase:Molecule phase:stdInChIKey="XLYOFNOQVPJJNP-UHFFFAOYSA-N"><cml:molecule ssip:stdInChIKey="XLYOFNOQVPJJNP-UHFFFAOYSA-N" cml:id="XLYOFNOQVPJJNP-UHFFFAOYSA-N"> + <cml:atomArray> + <cml:atom cml:elementType="O" cml:id="a1" cml:x3="0.0569236794019" cml:y3="0.53497425302" cml:z3="-9.99862395488E-5"/> + <cml:atom cml:elementType="H" cml:id="a2" cml:x3="-0.735721920018" cml:y3="-0.0219270863225" cml:z3="-1.029173866E-4"/> + <cml:atom cml:elementType="H" cml:id="a3" cml:x3="0.785198240616" cml:y3="-0.103847166698" cml:z3="-1.97096373822E-4"/> + </cml:atomArray> + <cml:bondArray> + <cml:bond cml:atomRefs2="a1 a2" cml:order="1"/> + <cml:bond cml:atomRefs2="a1 a3" cml:order="1"/> + </cml:bondArray> + </cml:molecule> + <ssip:SurfaceInformation> + <ssip:TotalSurfaceArea>37.48483410829331</ssip:TotalSurfaceArea> + <ssip:NegativeSurfaceArea>18.664358683092974</ssip:NegativeSurfaceArea> + <ssip:PositiveSurfaceArea>18.82047542519977</ssip:PositiveSurfaceArea> + <ssip:ElectronDensityIsosurface>0.002</ssip:ElectronDensityIsosurface> + <ssip:NumberOFMEPSPoints>2286</ssip:NumberOFMEPSPoints> + </ssip:SurfaceInformation> + <phase:SSIPs phase:units="MOLAR"> + <phase:SSIP ssip:value="2.9387503903833574" ssip:nearestAtomID="a3" cml:x3="1.509794550767402" cml:y3="-0.8784982637871289" cml:z3="-1.6986589692899999E-4" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + <phase:SSIP ssip:value="2.9275582734233065" ssip:nearestAtomID="a2" cml:x3="-1.4603207114038939" cml:y3="-0.790973405157027" cml:z3="0.12362427220238399" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + <phase:SSIP ssip:value="-6.263074063139137" ssip:nearestAtomID="a1" cml:x3="0.156188781751346" cml:y3="1.6969169177862917" cml:z3="1.172598045109361" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + <phase:SSIP ssip:value="-6.607684490829715" ssip:nearestAtomID="a1" cml:x3="0.06855491260794999" cml:y3="1.9788577934582507" cml:z3="-0.77762067563301" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + </phase:SSIPs> +</phase:Molecule> + </phase:Molecules> + </phase:Solvent> + </phase:Solvents> +</phase:SolventList> +''' actual_xml = solventxmlreader.read_element_tree("resources/watersolvent.xml") - self.assertEqual(expected_xml, etree.tounicode(actual_xml)) + self.assertMultiLineEqual(expected_xml, etree.tounicode(actual_xml, pretty_print=True)) diff --git a/solventmapcreator/test/polynomialanalysistest/polynomialplottingtest.py b/solventmapcreator/test/polynomialanalysistest/polynomialplottingtest.py index 70c65a4..0dea4c9 100644 --- a/solventmapcreator/test/polynomialanalysistest/polynomialplottingtest.py +++ b/solventmapcreator/test/polynomialanalysistest/polynomialplottingtest.py @@ -23,7 +23,7 @@ class PolynomialPlottingTestCase(unittest.TestCase): def setUp(self): """Set up for tests """ - self.expected_datapoints = solvationenergyreader.parse_free_energy_from_file_with_data_arrays("resources/water.xml") + self.expected_datapoints = solvationenergyreader.parse_binding_energy_from_file_with_data_arrays("resources/water.xml") def tearDown(self): """Clean up after tests. """ @@ -34,7 +34,7 @@ class PolynomialPlottingTestCase(unittest.TestCase): os.remove("actual_water_poly_fit_subset.csv") if os.path.isfile("actual_water_poly_fit_split.csv"): os.remove("actual_water_poly_fit_split.csv") - def test_parse_energies_create_plot_input_data(self): + def test_parse_binding_energies_create_plot_input_data(self): """Test to see expected plot data is returned. """ expected_dict = {'figure_label': "resources/water", @@ -56,8 +56,8 @@ class PolynomialPlottingTestCase(unittest.TestCase): -9.315464914185585, -20.143787975013183, 0.6588682955012527, -0.4429837300591526, -25.844114335864262]]), - 'y_label': "Solvation Energy/$kJmol^{-1}$"} - actual_dict = polynomialplotting.parse_energies_create_plot_input_data("resources/water.xml", 4) + 'y_label': "Solvation Binding Energy/$kJmol^{-1}$"} + actual_dict = polynomialplotting.parse_binding_energies_create_plot_input_data("resources/water.xml", 4) LOGGER.debug(actual_dict["x_data"].tolist()) LOGGER.debug(actual_dict["y_data"].tolist()) self.assertListEqual(sorted(actual_dict.keys()), sorted(expected_dict.keys())) @@ -76,7 +76,7 @@ class PolynomialPlottingTestCase(unittest.TestCase): #test to see if new functionality is supported neg_set_list = ["-5.400solute", "-4.300solute", "-9.100solute", "-11.100solute", "-15.400solute"] pos_set_list = ["0.500solute", "1.200solute", "7.200solute"] - actual_dict2 = polynomialplotting.parse_energies_create_plot_input_data("resources/water.xml", 4, + actual_dict2 = polynomialplotting.parse_binding_energies_create_plot_input_data("resources/water.xml", 4, pos_set_list, neg_set_list) self.assertListEqual(sorted(actual_dict2.keys()), sorted(expected_dict.keys())) for key in actual_dict.keys(): @@ -155,25 +155,25 @@ class PolynomialPlottingTestCase(unittest.TestCase): 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_parse_energies_and_output_poly_data_subset(self): + def test_parse_binding_energies_and_output_poly_data_subset(self): """Test to see if expected_fit is done on a smaller subset of points. """ expected_file_name = "resources/water_poly_fit_subset.csv" actual_file_name = "actual_water_poly_fit_subset.csv" subset_list = ["-5.400solute", "-4.300solute", "-9.100solute", "-11.100solute", "-15.400solute"] - poly_file_out = polynomialplotting.parse_energies_and_output_poly_data_subset("resources/water.xml", [2, 4], actual_file_name, subset_list) + poly_file_out = polynomialplotting.parse_binding_energies_and_output_poly_data_subset("resources/water.xml", [2, 4], actual_file_name, subset_list) self.assertEqual(0, poly_file_out) 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_parse_energies_and_output_poly_data(self): + def test_parse_binding_energies_and_output_poly_data(self): """Test to see if expected polynomial fit information is outputted to file. """ expected_file_name = "resources/water_poly_fit.csv" actual_file_name = "actual_water_poly_fit.csv" - poly_file_out = polynomialplotting.parse_energies_and_output_poly_data("resources/water.xml", [2, 4], actual_file_name) + poly_file_out = polynomialplotting.parse_binding_energies_and_output_poly_data("resources/water.xml", [2, 4], actual_file_name) self.assertEqual(0, poly_file_out) with open(expected_file_name, 'r') as exp_file: exp_file_lines = exp_file.readlines() @@ -193,9 +193,9 @@ class PolynomialPlottingTestCase(unittest.TestCase): 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_parse_free_energy_from_file_with_data_arrays(self): + def test_parse_binding_energy_from_file_with_data_arrays(self): """Test to see if expected datapoints are read in. """ - actual_datapoints = polynomialplotting.parse_free_energy_from_file_with_data_arrays("resources/water.xml") + actual_datapoints = polynomialplotting.parse_binding_energy_from_file_with_data_arrays("resources/water.xml") self.assertEqual(self.expected_datapoints, actual_datapoints) diff --git a/solventmapcreator/test/resources/energyvaluestest.xml b/solventmapcreator/test/resources/energyvaluestest.xml index af814c6..08a2759 100644 --- a/solventmapcreator/test/resources/energyvaluestest.xml +++ b/solventmapcreator/test/resources/energyvaluestest.xml @@ -1,8 +1,10 @@ <?xml version='1.0' encoding='UTF-8'?> <phase:EnergyValues xmlns:phase="http://www-hunter.ch.cam.ac.uk/PhaseSchema"> - <phase:BindingEnergyCollection><phase:BindingEnergy phase:stdInChIKey="-14.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergyCollection><phase:BindingEnergy phase:moleculeID="-14.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-34.8195308084233</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-34.8195308084233</phase:EnergyContribution> + <phase:EnergyContributions> + <phase:EnergyContribution phase:ssipID="1">-34.8195308084233</phase:EnergyContribution> + </phase:EnergyContributions> </phase:BindingEnergy> </phase:BindingEnergyCollection> </phase:EnergyValues> diff --git a/solventmapcreator/test/resources/water.xml b/solventmapcreator/test/resources/water.xml index 249e029..db2736f 100644 --- a/solventmapcreator/test/resources/water.xml +++ b/solventmapcreator/test/resources/water.xml @@ -1,48 +1,48 @@ <?xml version='1.0' encoding='UTF-8'?> <phase:EnergyValues xmlns:phase="http://www-hunter.ch.cam.ac.uk/PhaseSchema"> - <phase:BindingEnergyCollection><phase:BindingEnergy phase:stdInChIKey="-14.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergyCollection><phase:BindingEnergy phase:moleculeID="-14.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-34.8195308084233</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-34.8195308084233</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">-34.8195308084233</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="-5.400solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="-5.400solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-9.315464914185585</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-9.315464914185585</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">-9.315464914185585</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="-4.300solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="-4.300solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-6.170784422419204</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-6.170784422419204</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">-6.170784422419204</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="7.200solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="7.200solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-25.844114335864262</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-25.844114335864262</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">-25.844114335864262</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="0.500solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="0.500solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>0.6588682955012527</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">0.6588682955012527</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">0.6588682955012527</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="-0.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="-0.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>0.9185830776018105</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">0.9185830776018105</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">0.9185830776018105</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="-2.400solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="-2.400solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-1.4082598726557432</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-1.4082598726557432</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">-1.4082598726557432</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="1.200solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="1.200solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-0.4429837300591526</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-0.4429837300591526</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">-0.4429837300591526</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="-9.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="-9.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-20.143787975013183</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-20.143787975013183</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">-20.143787975013183</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="-11.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="-11.100solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-26.013780093398356</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-26.013780093398356</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">-26.013780093398356</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> - <phase:BindingEnergy phase:stdInChIKey="-15.400solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> + <phase:BindingEnergy phase:moleculeID="-15.400solute" phase:fromSolventID="" phase:toSolventID="water" phase:valueType="MOLEFRACTION"> <phase:TotalEnergy>-38.635444108544405</phase:TotalEnergy> - <phase:EnergyContribution phase:ssipID1="1">-38.635444108544405</phase:EnergyContribution> + <phase:EnergyContributions><phase:EnergyContribution phase:ssipID="1">-38.635444108544405</phase:EnergyContribution></phase:EnergyContributions> </phase:BindingEnergy> </phase:BindingEnergyCollection> </phase:EnergyValues> diff --git a/solventmapcreator/test/resources/watersolvent.xml b/solventmapcreator/test/resources/watersolvent.xml index 4fb26bd..68fbabf 100644 --- a/solventmapcreator/test/resources/watersolvent.xml +++ b/solventmapcreator/test/resources/watersolvent.xml @@ -1,20 +1,34 @@ <?xml version='1.0' encoding='UTF-8'?> <phase:SolventList xmlns:cml="http://www.xml-cml.org/schema" xmlns:phase="http://www-hunter.ch.cam.ac.uk/PhaseSchema" xmlns:ssip="http://www-hunter.ch.cam.ac.uk/SSIP"> - <phase:Solvent phase:solventID="water" phase:solventName="water" phase:numberOfMolecules="1"> - <phase:Molecule phase:stdInChIKey="XLYOFNOQVPJJNP-UHFFFAOYSA-N"> - <ssip:SSIPList> - <ssip:SurfaceInformation numberOfPoints="1000"> - <ssip:IsosurfaceDensity>0.002</ssip:IsosurfaceDensity> - <ssip:TotalSurfaceArea>10.0</ssip:TotalSurfaceArea> - <ssip:NegativeSurfaceArea>5.0</ssip:NegativeSurfaceArea> - <ssip:PositiveSurfaceArea>5.0</ssip:PositiveSurfaceArea> - </ssip:SurfaceInformation> - <ssip:SSIP x3="1.0" y3="0.0" z3="0.0" nearestAtomID="a1">2.8</ssip:SSIP> - <ssip:SSIP x3="1.0" y3="1.0" z3="1.0" nearestAtomID="a1">2.8</ssip:SSIP> - <ssip:SSIP x3="0.0" y3="1.0" z3="1.0" nearestAtomID="a1">-4.5</ssip:SSIP> - <ssip:SSIP x3="0.0" y3="1.0" z3="0.0" nearestAtomID="a1">-4.5</ssip:SSIP> - </ssip:SSIPList> - <phase:Concentration phase:units="MOLAR">55.350000</phase:Concentration> - </phase:Molecule> - </phase:Solvent> + <phase:Solvents> + <phase:Solvent phase:solventID="water" phase:solventName="water"> + <phase:Molecules> + <phase:Molecule phase:stdInChIKey="XLYOFNOQVPJJNP-UHFFFAOYSA-N"><cml:molecule ssip:stdInChIKey="XLYOFNOQVPJJNP-UHFFFAOYSA-N" cml:id="XLYOFNOQVPJJNP-UHFFFAOYSA-N"> + <cml:atomArray> + <cml:atom cml:elementType="O" cml:id="a1" cml:x3="0.0569236794019" cml:y3="0.53497425302" cml:z3="-9.99862395488E-5"/> + <cml:atom cml:elementType="H" cml:id="a2" cml:x3="-0.735721920018" cml:y3="-0.0219270863225" cml:z3="-1.029173866E-4"/> + <cml:atom cml:elementType="H" cml:id="a3" cml:x3="0.785198240616" cml:y3="-0.103847166698" cml:z3="-1.97096373822E-4"/> + </cml:atomArray> + <cml:bondArray> + <cml:bond cml:atomRefs2="a1 a2" cml:order="1"/> + <cml:bond cml:atomRefs2="a1 a3" cml:order="1"/> + </cml:bondArray> + </cml:molecule> + <ssip:SurfaceInformation> + <ssip:TotalSurfaceArea>37.48483410829331</ssip:TotalSurfaceArea> + <ssip:NegativeSurfaceArea>18.664358683092974</ssip:NegativeSurfaceArea> + <ssip:PositiveSurfaceArea>18.82047542519977</ssip:PositiveSurfaceArea> + <ssip:ElectronDensityIsosurface>0.002</ssip:ElectronDensityIsosurface> + <ssip:NumberOFMEPSPoints>2286</ssip:NumberOFMEPSPoints> + </ssip:SurfaceInformation> + <phase:SSIPs phase:units="MOLAR"> + <phase:SSIP ssip:value="2.9387503903833574" ssip:nearestAtomID="a3" cml:x3="1.509794550767402" cml:y3="-0.8784982637871289" cml:z3="-1.6986589692899999E-4" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + <phase:SSIP ssip:value="2.9275582734233065" ssip:nearestAtomID="a2" cml:x3="-1.4603207114038939" cml:y3="-0.790973405157027" cml:z3="0.12362427220238399" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + <phase:SSIP ssip:value="-6.263074063139137" ssip:nearestAtomID="a1" cml:x3="0.156188781751346" cml:y3="1.6969169177862917" cml:z3="1.172598045109361" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + <phase:SSIP ssip:value="-6.607684490829715" ssip:nearestAtomID="a1" cml:x3="0.06855491260794999" cml:y3="1.9788577934582507" cml:z3="-0.77762067563301" phase:units="MOLAR"><phase:TotalConcentration phase:units="MOLAR">55.350000</phase:TotalConcentration></phase:SSIP> + </phase:SSIPs> +</phase:Molecule> + </phase:Molecules> + </phase:Solvent> + </phase:Solvents> </phase:SolventList> -- GitLab