From 3979d1741d69a93a62f00b69c357296e9c1904eb Mon Sep 17 00:00:00 2001
From: Mark Driver <mdd31@cam.ac.uk>
Date: Wed, 4 Apr 2018 12:34:45 +0100
Subject: [PATCH] initial attempt at map merging to form FGIPs.

---
 setup.py                                      |  3 +-
 .../solvationcalculation/fgipmaker.py         | 64 +++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 solventmapcreator/solvationcalculation/fgipmaker.py

diff --git a/setup.py b/setup.py
index c497676..80c9bc4 100644
--- a/setup.py
+++ b/setup.py
@@ -8,5 +8,6 @@ setup(name='solventmapcreator',
       author_email='mdd31@cam.ac.uk',
       license='TBD',
       packages=setuptools.find_packages(),
-      package_data={'test/resources':['test/resources']},
+      package_data={'test/resources':['test/resources'],
+                    'solvationcalculation/resources':['solvationcalculation/resources']},
       zip_safe=False)
diff --git a/solventmapcreator/solvationcalculation/fgipmaker.py b/solventmapcreator/solvationcalculation/fgipmaker.py
new file mode 100644
index 0000000..a2404d9
--- /dev/null
+++ b/solventmapcreator/solvationcalculation/fgipmaker.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+Script for merging the molecules to the solvent map to create the functional
+group interaction profile.
+
+@author: mark
+"""
+
+import logging
+import os
+import svgutils.transform as svgt
+
+logging.basicConfig()
+LOGGER = logging.getLogger(__name__)
+LOGGER.setLevel(logging.WARN)
+
+FGIP_MOLECULES_FILENAME = os.path.join(os.path.dirname(__file__),
+                                       "resources/FGIPmolecules.svg")
+
+def create_fgip_from_map(map_filename):
+    """This creates a FGIP from the given solvent map.
+    """
+    svg_figure = create_svgfigure()
+    map_plot = get_svg_plot(map_filename)
+    map_plot.moveto(0.0,150.0, scale=1.1)
+    molecules_plot = get_molecules()
+    
+    append_svg_plots(svg_figure, map_plot)
+    append_svg_plots(svg_figure, molecules_plot)
+    output_filename = create_output_filename(map_filename)
+    save_svg_figure(svg_figure, output_filename)
+
+def save_svg_figure(svg_figure, filename):
+    """This saves the figue to file.
+    """
+    svg_figure.save(filename)
+
+def create_output_filename(filename, suffix="_solv_map.svg"):
+    """This returns the output filename to be used.
+    """
+    return filename.replace(suffix, "_FGIP.svg")
+
+def append_svg_plots(svg_figure, svg_plot):
+    """This appends the plot to the figure.
+    """
+    svg_figure.append(svg_plot)
+
+def get_molecules():
+    """This gets the molecules.
+    """
+    return get_svg_plot(FGIP_MOLECULES_FILENAME)
+
+def get_svg_plot(svg_filename):
+    """This gets the plot elements.
+    """
+    figure = svgt.fromfile(svg_filename)
+    return figure.getroot()
+
+def create_svgfigure():
+    """This creates SVG figure with default size.
+    """
+    return svgt.SVGFigure(width="725.05334pt", height="676.02484pt")
+
-- 
GitLab