From c03f9c509c90e7b142f907c7c536c35046ad0bd8 Mon Sep 17 00:00:00 2001
From: Mark Driver <mdd31@alumni.cam.ac.uk>
Date: Thu, 26 Mar 2020 22:48:16 +0000
Subject: [PATCH] update to CLI adding extra subparser and updating help
 information.

---
 phasecalculator/phasecalculatorcli.py | 54 +++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 4 deletions(-)

diff --git a/phasecalculator/phasecalculatorcli.py b/phasecalculator/phasecalculatorcli.py
index 183dd17..d9d479a 100755
--- a/phasecalculator/phasecalculatorcli.py
+++ b/phasecalculator/phasecalculatorcli.py
@@ -22,17 +22,21 @@ Script with CLI for phasecalculator.
 
 import logging
 import argparse
+import textwrap
 import phasecalculator.runners.phasecalculatorrunner as phasecrun
 import phasecalculator.io.systemcollectionprocessor as sysproc
 import phasecalculator.io.phasecsvconverter as csvconv
 from phasecalculator.classes.runtimeinformation import RuntimeInformation
 from phasecalculator.classes.outputinformation import OutputInformation
 from phasecalculator.classes.system import System, SystemCollection
+import puresolventinformation.information as pureinf
 
 logging.basicConfig()
 LOGGER = logging.getLogger(__name__)
 LOGGER.setLevel(logging.WARN)
 
+INFO_LOGGER = logging.getLogger(__name__)
+INFO_LOGGER.setLevel(logging.INFO)
 
 def main():
     """Main function run when program called.
@@ -236,6 +240,27 @@ def run_system_collection(system_collection, **kwargs):
     for system_info in system_collection.system_list:
         phasecrun.run_all_analysis(system_info, **kwargs)
 
+def get_acceptable_solvent_names():
+    """Get Acceptable solvent names.
+
+    Returns
+    -------
+    Str
+        Solvent names, formatted 1 per line.
+
+    """
+    solvent_names = pureinf.get_name_inchikey_mapping().keys()
+    return "\n".join(solvent_names)
+    
+def solvent_names(args):
+    """Output solvent names by using a logger.
+
+    Returns
+    -------
+    None.
+
+    """
+    INFO_LOGGER.info("Solvent names:\n%s", get_acceptable_solvent_names())
 
 def create_phasecalculator_argparser():
     """Create Argument parser for Phasecalculator module.
@@ -247,7 +272,7 @@ def create_phasecalculator_argparser():
     """
     description = """Phase Calculator provides methods to perform FGIP,
 similarity and VLE analysis for solvents."""
-    epilog = """Example usage"""
+    epilog = """For example usage see submodule help"""
     phase_argparser = argparse.ArgumentParser(
         description=description,
         epilog=epilog,
@@ -257,7 +282,11 @@ similarity and VLE analysis for solvents."""
     subparsers = phase_argparser.add_subparsers(title="commands", dest="command")
 
     calc_description = """Calculation runner based on input System XML."""
-    calc_epilog = """"""
+    calc_epilog = textwrap.dedent("""Example Usage:
+
+python -m phasecalculator calculate -f systemcollection.xml
+
+Where systemcollection.xml was generated with inpgen. For large phase sets you need to set memreq to match your current hardware limit.""")
 
     calc_argparser = subparsers.add_parser(
         "calculate",
@@ -283,7 +312,13 @@ similarity and VLE analysis for solvents."""
     calc_argparser.set_defaults(func=process_phasecalculator)
 
     inpgen_description = """Input SystemCollection XML generation."""
-    inpgen_epilog = """"""
+    inpgen_epilog = textwrap.dedent("""\
+  Example usage:
+    
+    python -m phasecalculator inpgen -p $CONDA_PREFIX/lib/python3.7/site-packages/phasecalculator/test/resources/examplephasecomp.csv -f -j PATH_TO_JAR
+
+  Where PATH_TO_JAR is replaced with the SSIP phasetransfer jar file location.
+""")
 
     inpgen_argparser = subparsers.add_parser(
         "inpgen",
@@ -323,7 +358,18 @@ similarity and VLE analysis for solvents."""
         "-v", "--vle", action="store_true", help="Calculate VLE for input solvents"
     )
     inpgen_argparser.add_argument(
-        "--filename", type=str, default="systemcollection.xml"
+        "--filename", type=str, default="systemcollection.xml",
+        help="filename for XML file.",
     )
     inpgen_argparser.set_defaults(func=process_inputgen)
+    solvname_description = """Display acceptable solvent molecule names for inclusion in a phases csv file."""
+    solvnames_epilog = "Solvent molecule names:\n" + get_acceptable_solvent_names() + "\n"
+    solvent_nameparser = subparsers.add_parser(
+        "solventnames",
+        description=solvname_description,
+        epilog=solvnames_epilog,
+        help="Get list of aceptable pure solvent names.",
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
+    )
+    solvent_nameparser.set_defaults(func=solvent_names)
     return phase_argparser
-- 
GitLab