[gmx-users] exclusions

Steven Neumann s.neumann08 at gmail.com
Thu Dec 5 16:32:27 CET 2013


I found sth like this:

#!/usr/bin/python
# -*- coding: ISO-8859-1 -*-
#---------------------------------------------------------------------------#
# Function: Echo an exclusions list for Gromacs.
#
# Usage: exclusions.py [options] #-of-beads
#
# Help: run exclusions.py --help
#
# Author: Martti Louhivuori (m.j.louhivuori at rug.nl)
#
# Version: 1.0 (19.10.2007)
#
#---------------------------------------------------------------------------#
from optparse import OptionParser
import logging, sys

if __name__ == '__main__':
    usage = 'usage: %prog [options] #-of-beads'
    desc = 'Echo an exclusions list for Gromacs.'
    parser = OptionParser(usage=usage, description=desc)
    parser.add_option('-o', '--output', metavar='FILE', default=None,
            help='write output to FILE (default: STDOUT)')
    parser.add_option('--verbose', action='store_true', default=False,
            help='display additional information while running')
    parser.add_option('--debug', action='store_true', default=False,
            help='run in debug mode, i.e. maximum information')

    options, args = parser.parse_args()

    # set logger format etc.
    logging.basicConfig(level=logging.WARNING, format='%(levelname)s ' + \
            '%(message)s @ %(asctime)s %(module)s line %(lineno)s',
            datefmt='%H:%M:%S')
    # set logging thresholds
    if options.debug:
        logging.getLogger('').setLevel(logging.DEBUG)
    elif options.verbose:
        logging.getLogger('').setLevel(logging.WARNING)
    else:
        logging.getLogger('').setLevel(logging.CRITICAL)
    logging.debug('options: %s' % repr(options))
    logging.debug('args: %s' % repr(args))

    # redirect STDOUT?
    if options.output:
        try:
            sys.stdout = open(options.output, 'w')
        except IOError, errmsg:
            print '#', errmsg
            print '# Directing output to STDOUT instead.'

    # too few arguments?
    if len(args) < 1:
        parser.error('too few arguments')
    else:
        beads = int(args[0])
        logging.debug('beads: ' + repr(beads))

    print '[ exclusions ]'
    all = range(1, beads + 1)
    for i in all:
        print ' '.join([str(x) for x in [i] + all[:i-1] + all[i:]])

    # the end.
    if options.output:
        sys.stdout.close()

But I get an error: ValueError: invalid literal for int()

Any help appreciated.

Steven


More information about the gromacs.org_gmx-users mailing list