#! /usr/local/bin/python2.7 # Load system modules. from argparse import ArgumentParser import os import signal import sys import warnings # Load custom modules from ParmedTools.logos import Logo from ParmedTools import parmed_cmd from ParmedTools.exceptions import (ParmError, SeriousParmWarning, InterpreterError) from ParmedTools.parmed_cmd import ParmedCmd from ParmedTools.ParmedActions import Action from ParmedTools.parmlist import ParmList from ParmedTools import __version__ # Set up new excepthook to clean up fatal exception printouts def interrupted(*args, **kwargs): """ Handle interruptions gracefully """ sys.stdout.write('Interrupted\n') sys.exit(1) signal.signal(signal.SIGINT, interrupted) # Define our own custom warning printer def _print_warnings(message, category, filename, lineno, file=None, line=None): """ Override the default showwarning method """ if file is None: file = sys.stderr try: file.write('%s: %s\n' % (category.__name__, message)) except IOError: pass warnings.showwarning = _print_warnings # Set up parser parser = ArgumentParser() parser.add_argument('-v', '--version', action='version', version='%%(prog)s: Version %s' % __version__) group = parser.add_argument_group('Input Files') group.add_argument('-i', '--input', dest='script', default=[], metavar='FILE', help='''Script with ParmEd commands to execute. Default reads from stdin. Can be specified multiple times to process multiple input files.''', action='append') group.add_argument('-p', '--parm', dest='prmtop', default=[], metavar='', action='append', help='''List of topology files to load into ParmEd. Can be specified multiple times to process multiple topologies.''') group = parser.add_argument_group('Output Files') group.add_argument('-O', '--overwrite', dest='overwrite', default=False, help='Allow ParmEd to overwrite existing files.', action='store_true') group.add_argument('-l', '--logfile', dest='logfile', metavar='FILE', default='parmed.log', help='''Log file with every command executed during an interactive ParmEd session. Default is parmed.log''') group = parser.add_argument_group('Interpreter Options', '''These options affect how the ParmEd interpreter behaves in certain cases.''') group.add_argument('--prompt', dest='prompt', default='>', metavar='PROMPT', help='String to use as a command prompt.') group.add_argument('-n', '--no-splash', dest='printlogo', action='store_false', help='Prevent printing the greeting logo.', default=True) group.add_argument('-e', '--enable-interpreter', dest='interpreter', action='store_true', default=False, help='''Allow arbitrary single Python commands or blocks of Python code to be run. By default Python commands will not be run as a safeguard for your system. Make sure you trust the source of the ParmEd command before turning this option on.''') group = parser.add_argument_group('Error Handling', '''These options control how ParmEd handles various errors and warnings that appear occur during the course of Action execution''') group.add_argument('-s', '--strict', dest='strict', action='store_true', default=True, help='''Prevent scripts from running past unrecognized input and actions that end with an error. In interactive mode, actions with unrecognized inputs and failed actions prevent any changes from being made to the topology, but does not quit the interpreter. This is the default behavior.''') group.add_argument('-r', '--relaxed', dest='strict', action='store_false', help='''Scripts ignore unrecognized input and simply skip over failed actions, executing the rest of the script. Unrecognized input in the interactive interpreter emits a non-fatal warning.''') parser.add_argument('prmtop_cl', nargs='?', metavar='', default=None, help='Topology file to analyze.') parser.add_argument('script_cl', nargs='?', metavar='