FAQ | This is a LIVE service | Changelog

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

add solvent extractor and test.

parent 65c68cc9
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# phasecalculator calculates FGIPs, solvent similarity and VLE with SSIMPLE.
# Copyright (C) 2019 Mark D. Driver
#
# phasecalculator is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
Script for spliting input fed into different energy XML files based on solvent ID.
@author: mark
"""
import logging
import solventmapcreator.io.solvationenergyextraction as solvextract
logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.WARN)
def extract_and_write_energy_values_from_files(solvent_filename, energy_xml_filename, energy_type, directory):
"""Extracts energies and splits to different file for each solvent.
Parameters
----------
solvent_filename : str
Solvent XML filename.
energy_xml_filename : str
Energy XML filename.
energy_type : str
type of energy to extract. Either "binding" or "free".
directory : str
directory name.
Returns
-------
None
Result in file output to disk.
"""
solvextract.extract_and_write_energy_values_from_files(solvent_filename, energy_xml_filename, energy_type, directory)
# -*- coding: utf-8 -*-
# phasecalculator calculates FGIPs, solvent similarity and VLE with SSIMPLE.
# Copyright (C) 2019 Mark D. Driver
#
# phasecalculator is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
Test case for solvent extractor method.
@author: Mark
"""
import logging
import unittest
import pathlib
import os
import phasecalculator.io.solventextractor as solvextract
logging.basicConfig()
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.WARN)
class SolventExtractorTestCase(unittest.TestCase):
"""Test case for solvent extractor methods."""
def setUp(self):
"""Set up for tests.
Returns
-------
None.
"""
self.maxDiff = None
parent_directory = pathlib.Path(__file__).parents[1]
self.binding_energy_filename = (
(parent_directory / "resources/expected_bindingenergy.xml").absolute().as_posix()
)
self.expected_output_filename = (
(parent_directory / "resources/expected_bindingparsed.xml").absolute().as_posix()
)
self.output_filename = "1-butanol0.165water0.835binding.xml"
self.solvent_filename = (
(parent_directory / "resources/expected_solvent.xml").absolute().as_posix()
)
def tearDown(self):
"""Clean up after tests.
Returns
-------
None.
"""
if os.path.isfile(self.output_filename):
os.remove(self.output_filename)
del self.output_filename
def test_extract_and_write_energy_values_from_file(self):
"""
Returns
-------
None.
"""
solvextract.extract_and_write_energy_values_from_files(self.solvent_filename, self.binding_energy_filename, "binding", "")
with open(self.output_filename, "r") as actual_file:
actual_xml = actual_file.read()
with open(self.expected_output_filename) as expected_file:
expected_xml = expected_file.read()
self.assertMultiLineEqual(expected_xml, actual_xml)
\ No newline at end of file
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
Created on Tue Jan 7 16:34:17 2020 Test runner using unittest framework.
This can also be used to run tests on the installed instance of the library.
@author: Mark @author: Mark
""" """
...@@ -24,14 +26,17 @@ import logging ...@@ -24,14 +26,17 @@ import logging
import unittest import unittest
import sys import sys
from phasecalculator.test.iotest.phasetransferxmlcreatortest import PhasetransferXMLCreatorTestCase from phasecalculator.test.iotest.phasetransferxmlcreatortest import PhasetransferXMLCreatorTestCase
from phasecalculator.test.iotest.solventextractortest import SolventExtractorTestCase
from phasecalculator.test.runnerstest.phasetransferrunnertest import PhasetransferRunnerTestCase
logging.basicConfig() logging.basicConfig()
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.WARN) LOGGER.setLevel(logging.WARN)
IO_TEST_CASES = [PhasetransferXMLCreatorTestCase,] IO_TEST_CASES = [PhasetransferXMLCreatorTestCase,
SolventExtractorTestCase,]
RUNNERS_TEST_CASES = [] RUNNERS_TEST_CASES = [PhasetransferRunnerTestCase,]
ANALYSIS_TEST_CASES = [] ANALYSIS_TEST_CASES = []
......
This diff is collapsed.
This diff is collapsed.
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