Skip to content

Commit

Permalink
Merge pull request #16 from molssi-seamm/option-handling
Browse files Browse the repository at this point in the history
Updated for the new command-line argument handling
  • Loading branch information
paulsaxe authored Nov 2, 2020
2 parents cbd3ffe + d261fb5 commit b7c914d
Showing 1 changed file with 29 additions and 59 deletions.
88 changes: 29 additions & 59 deletions packmol_step/packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

"""A step for building fluids with Packmol in a SEAMM flowchart"""

import argparse
import configargparse
import logging
import mendeleev
import os.path
Expand All @@ -20,14 +18,6 @@
printer = printing.getPrinter('packmol')


def upcase(string):
"""Return an uppercase version of the string.
Used for the type argument in argparse/
"""
return string.upper()


class Packmol(seamm.Node):

def __init__(self, flowchart=None, extension=None):
Expand All @@ -38,50 +28,6 @@ def __init__(self, flowchart=None, extension=None):

logger.debug('Handling arguments in Packmol {}'.format(self))

# Argument/config parsing
self.parser = configargparse.ArgParser(
auto_env_var_prefix='',
default_config_files=[
'/etc/seamm/packmol.ini',
'/etc/seamm/packmol_step.ini',
'/etc/seamm/seamm.ini',
'~/.seamm/packmol.ini',
'~/.seamm/packmol_step.ini',
'~/.seamm/seamm.ini',
]
)

self.parser.add_argument(
'--seamm-configfile',
is_config_file=True,
default=None,
help='a configuration file to override others'
)

# Options for this plugin
self.parser.add_argument(
"--packmol-log-level",
default=argparse.SUPPRESS,
choices=[
'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'
],
type=upcase,
help="the logging level for the Packmol step"
)

# Options for Packmol
self.parser.add_argument(
'--packmol-path',
default='',
help='the path to the Packmol executables'
)

self.options, self.unknown = self.parser.parse_known_args()

# Set the logging level for this module if requested
if 'packmol_log_level' in self.options:
logger.setLevel(self.options.packmol_log_level)

super().__init__(
flowchart=flowchart,
title='Packmol',
Expand All @@ -104,6 +50,32 @@ def git_revision(self):
"""
return packmol_step.__git_revision__

def create_parser(self):
"""Setup the command-line / config file parser
"""
parser_name = self.step_type
parser = seamm.getParser()

# Remember if the parser exists ... this type of step may have been
# found before
parser_exists = parser.exists(parser_name)

# Create the standard options, e.g. log-level
result = super().create_parser(name=parser_name)

if parser_exists:
return result

# Options for Packmol
parser.add_argument(
self.step_type,
'--packmol-path',
default='',
help='the path to the Packmol executables'
)

return result

def description_text(self, P=None):
"""Return a short description of this step.
Expand Down Expand Up @@ -167,13 +139,11 @@ def run(self):
system = self.get_variable('_system')

# The options from command line, config file ...
o = self.options
path = self.options['packmol_path']

packmol_exe = os.path.join(o.packmol_path, 'packmol')
packmol_exe = os.path.join(path, 'packmol')

seamm_util.check_executable(
packmol_exe, key='--packmol-path', parser=self.parser
)
seamm_util.check_executable(packmol_exe)

P = self.parameters.current_values_to_dict(
context=seamm.flowchart_variables._data
Expand Down

0 comments on commit b7c914d

Please sign in to comment.