first_col = <NUM_LIT:3><EOL>last_col = -<NUM_LIT:1><EOL>def print_usage():<EOL><INDENT>"""<STR_LIT>"""<EOL>sys.stdout.write(<EOL>'<STR_LIT>' + '<STR_LIT>'<EOL>)<EOL>sys.exit(<NUM_LIT:2>)<EOL><DEDENT>def binarize(num):<EOL><INDENT>"""<STR_LIT>"""<EOL>if num == '<STR_LIT:0>':  <EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif num == '<STR_LIT>':  <EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif num == '<STR_LIT:1>':  <EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif num == '<STR_LIT:2>':  <EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT>def init_termdicts():<EOL><INDENT>"""<STR_LIT>"""<EOL>ifile = codecs.open('<STR_LIT>', '<STR_LIT:r>', '<STR_LIT:utf-8>')<EOL>feature_mask = {}<EOL>keyline = ifile.readline().strip().split('<STR_LIT:U+002C>')[first_col:last_col]<EOL>mag = len(keyline)<EOL>for i in range(len(keyline)):<EOL><INDENT>features = '<STR_LIT>' + ('<STR_LIT>' * i) + '<STR_LIT>' + ('<STR_LIT>' * (mag - i - <NUM_LIT:1>))<EOL>feature_mask[keyline[i]] = int(features, <NUM_LIT:2>)<EOL><DEDENT>termdict = {}<EOL>for line in ifile:<EOL><INDENT>line = line.strip().rstrip('<STR_LIT:U+002C>')<EOL>if '<STR_LIT:#>' in line:<EOL><INDENT>line = line[: line.find('<STR_LIT:#>')].strip()<EOL><DEDENT>if line:<EOL><INDENT>line = line.split('<STR_LIT:U+002C>')<EOL>term = line[last_col]<EOL>features = '<STR_LIT>' + '<STR_LIT>'.join(<EOL>[binarize(val) for val in line[first_col:last_col]]<EOL>)<EOL>termdict[term] = int(features, <NUM_LIT:2>)<EOL><DEDENT><DEDENT>return termdict, feature_mask<EOL><DEDENT>def check_terms(sym, features, name, termdict):<EOL><INDENT>"""<STR_LIT>"""<EOL>if '<STR_LIT:#>' in name:<EOL><INDENT>name = name[: name.find('<STR_LIT:#>')].strip()<EOL><DEDENT>for term in name.split():<EOL><INDENT>if term in termdict:<EOL><INDENT>if termdict[term] & features != termdict[term]:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ term<EOL>+ '<STR_LIT>'<EOL>+ sym<EOL>+ '<STR_LIT:\n>'<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ term<EOL>+ '<STR_LIT>'<EOL>+ name<EOL>+ '<STR_LIT>'<EOL>+ sym<EOL>+ '<STR_LIT:\n>'<EOL>)<EOL><DEDENT><DEDENT><DEDENT>def check_entailments(sym, features, feature_mask):<EOL><INDENT>"""<STR_LIT>"""<EOL>entailments = {<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>',),<EOL>'<STR_LIT>': ('<STR_LIT>',),<EOL>}<EOL>for feature in entailments:<EOL><INDENT>fname = feature[<NUM_LIT:1>:]<EOL>if feature[<NUM_LIT:0>] == '<STR_LIT:+>':<EOL><INDENT>fm = (feature_mask[fname] >> <NUM_LIT:1>) & feature_mask[fname]<EOL><DEDENT>else:<EOL><INDENT>fm = (feature_mask[fname] << <NUM_LIT:1>) & feature_mask[fname]<EOL><DEDENT>if (features & fm) == fm:<EOL><INDENT>for ent in entailments[feature]:<EOL><INDENT>ename = ent[<NUM_LIT:1>:]<EOL>if ent[<NUM_LIT:0>] == '<STR_LIT:+>':<EOL><INDENT>efm = (feature_mask[ename] >> <NUM_LIT:1>) & feature_mask[ename]<EOL><DEDENT>elif ent[<NUM_LIT:0>] == '<STR_LIT:->':<EOL><INDENT>efm = (feature_mask[ename] << <NUM_LIT:1>) & feature_mask[ename]<EOL><DEDENT>elif ent[<NUM_LIT:0>] == '<STR_LIT:0>':<EOL><INDENT>efm = <NUM_LIT:0><EOL><DEDENT>elif ent[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>efm = feature_mask[ename]<EOL><DEDENT>if ent[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>if (features & efm) == <NUM_LIT:0>:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ sym<EOL>+ '<STR_LIT>'<EOL>+ fname<EOL>+ '<STR_LIT>'<EOL>+ ename<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if (features & efm) != efm:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ sym<EOL>+ '<STR_LIT>'<EOL>+ fname<EOL>+ '<STR_LIT>'<EOL>+ ename<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>checkdict = {}  <EOL>checkset_s = set()  <EOL>checkset_f = set()  <EOL>termdict, feature_mask = init_termdicts()<EOL>ifile = '<STR_LIT>'<EOL>ofile = '<STR_LIT>'<EOL>try:<EOL><INDENT>opts = getopt.getopt(argv, '<STR_LIT>', ['<STR_LIT>', '<STR_LIT>'])[<NUM_LIT:0>]<EOL><DEDENT>except getopt.GetoptError:<EOL><INDENT>print_usage()<EOL><DEDENT>for opt, arg in opts:<EOL><INDENT>if opt == '<STR_LIT>':<EOL><INDENT>print_usage()<EOL><DEDENT>elif opt in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>ifile = codecs.open(arg, '<STR_LIT:r>', '<STR_LIT:utf-8>')<EOL><DEDENT>elif opt in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>ofile = codecs.open(arg, '<STR_LIT:w>', '<STR_LIT:utf-8>')<EOL><DEDENT><DEDENT>if not ifile:<EOL><INDENT>print_usage()<EOL><DEDENT>oline = '<STR_LIT>'<EOL>if not ofile:<EOL><INDENT>ofile = sys.stdout<EOL><DEDENT>ofile.write(oline + '<STR_LIT:\n>')<EOL>keyline = ifile.readline().strip().split('<STR_LIT:U+002C>')[first_col:last_col]<EOL>for line in ifile:<EOL><INDENT>line = line.strip().rstrip('<STR_LIT:U+002C>')<EOL>if line.startswith('<STR_LIT>'):<EOL><INDENT>break<EOL><DEDENT>line = unicodedata.normalize('<STR_LIT>', line)<EOL>if not line or line.startswith('<STR_LIT:#>'):<EOL><INDENT>oline = '<STR_LIT:U+0020>' + line<EOL><DEDENT>else:<EOL><INDENT>line = line.strip().split('<STR_LIT:U+002C>')<EOL>if '<STR_LIT:#>' in line:<EOL><INDENT>line = line[: line.find('<STR_LIT:#>')]<EOL><DEDENT>symbol = line[<NUM_LIT:0>]<EOL>variant = int(line[<NUM_LIT:1>])<EOL>segmental = bool(line[<NUM_LIT:2>])<EOL>features = '<STR_LIT>' + '<STR_LIT>'.join(<EOL>[binarize(val) for val in line[first_col:last_col]]<EOL>)<EOL>name = line[-<NUM_LIT:1>].strip()<EOL>if not segmental:<EOL><INDENT>features = '<STR_LIT:->' + features<EOL><DEDENT>featint = int(features, <NUM_LIT:2>)<EOL>check_terms(symbol, featint, name, termdict)<EOL>check_entailments(symbol, featint, feature_mask)<EOL>if symbol in checkset_s:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>' + symbol + '<STR_LIT>'<EOL>)<EOL><DEDENT>else:<EOL><INDENT>checkset_s.add(symbol)<EOL><DEDENT>if variant < <NUM_LIT:2>:<EOL><INDENT>if featint in checkset_f:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ str(featint)<EOL>+ '<STR_LIT>'<EOL>+ '<STR_LIT>'<EOL>+ symbol<EOL>+ '<STR_LIT>'<EOL>+ checkdict[featint]<EOL>)<EOL><DEDENT>else:<EOL><INDENT>checkdict[featint] = symbol<EOL>checkset_f.add(featint)<EOL><DEDENT><DEDENT>if variant < <NUM_LIT:5>:<EOL><INDENT>oline = '<STR_LIT>'.format(<EOL>symbol, featint<EOL>)<EOL><DEDENT>else:<EOL><INDENT>oline = '<STR_LIT>'<EOL><DEDENT><DEDENT>if oline:<EOL><INDENT>ofile.write(oline + '<STR_LIT:\n>')<EOL><DEDENT><DEDENT>ofile.write('<STR_LIT>')<EOL>mag = len(keyline)<EOL>for i in range(len(keyline)):<EOL><INDENT>features = int('<STR_LIT>' + ('<STR_LIT>' * i) + '<STR_LIT>' + ('<STR_LIT>' * (mag - i - <NUM_LIT:1>)), <NUM_LIT:2>)<EOL>oline = '<STR_LIT>'.format(keyline[i], features)<EOL>ofile.write(oline + '<STR_LIT:\n>')<EOL><DEDENT>ofile.write('<STR_LIT>')<EOL>

Read input file and write to output.

    Parameters
    ----------
    argv : list
        Arguments to the script


return [_get_template(s) for s in utilities.asiterable(t)]<EOL>

Find template file(s) *t* and return their real paths.

    *t* can be a single string or a list of strings. A string should
    be one of

    1. a relative or absolute path,
    2. a file in one of the directories listed in :data:`gromacs.config.path`,
    3. a filename in the package template directory (defined in the template dictionary
       :data:`gromacs.config.templates`) or
    4. a key into :data:`~gromacs.config.templates`.

    The first match (in this order) is returned for each input argument.

    :Arguments: *t* : template file or key (string or list of strings)
    :Returns:   list of os.path.realpath(*t*)
    :Raises:    :exc:`ValueError` if no file can be located.


<EOL>envvars = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>']<EOL>cmdargs = ['<STR_LIT>', '<STR_LIT:-c>', "<STR_LIT>".format(gmxrc,<EOL>'<STR_LIT:U+0020>'.join(['<STR_LIT>'.format(v) for v in envvars]))]<EOL>if not gmxrc:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>return<EOL><DEDENT>try:<EOL><INDENT>out = subprocess.check_output(cmdargs)<EOL>out = out.strip().split()<EOL>for key, value in zip(envvars, out):<EOL><INDENT>value = str(value.decode('<STR_LIT:ascii>').replace('<STR_LIT>', '<STR_LIT>'))  <EOL>os.environ[key] = value<EOL>logger.debug("<STR_LIT>", key, value)<EOL><DEDENT><DEDENT>except (subprocess.CalledProcessError, OSError):<EOL><INDENT>logger.warning("<STR_LIT>"<EOL>"<STR_LIT>", gmxrc)<EOL><DEDENT>

Set the environment from ``GMXRC`` provided in *gmxrc*.

    Runs ``GMXRC`` in a subprocess and puts environment variables loaded by it
    into this Python environment.

    If *gmxrc* evaluates to ``False`` then nothing is done. If errors occur
    then only a warning will be logged. Thus, it should be safe to just call
    this function.


self.filename = kwargs.pop('<STR_LIT:filename>', CONFIGNAME)<EOL>super(GMXConfigParser, self).__init__(*args, **kwargs)<EOL>self.set('<STR_LIT>', '<STR_LIT>',<EOL>os.path.join("<STR_LIT>", os.path.basename(defaults['<STR_LIT>'])))<EOL>self.set('<STR_LIT>', '<STR_LIT>',<EOL>os.path.join("<STR_LIT>", os.path.basename(defaults['<STR_LIT>'])))<EOL>self.add_section('<STR_LIT>')<EOL>self.set("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>self.set("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>self.set("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>self.set("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>self.set("<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>self.set("<STR_LIT>", "<STR_LIT>", "<STR_LIT:yes>")<EOL>self.add_section('<STR_LIT>')<EOL>self.set('<STR_LIT>', '<STR_LIT>', defaults['<STR_LIT>'])<EOL>self.set('<STR_LIT>', '<STR_LIT>', defaults['<STR_LIT>'])<EOL>self.set('<STR_LIT>', '<STR_LIT>', defaults['<STR_LIT>'])<EOL>default_cfg = get_template(self.cfg_template)<EOL>self.read_file(open(default_cfg))<EOL>self.read([self.filename])<EOL>

Reads and parses the configuration file.

        Default values are loaded and then replaced with the values from
        ``~/.gromacswrapper.cfg`` if that file exists. The global
        configuration instance :data:`gromacswrapper.config.cfg` is updated
        as are a number of global variables such as :data:`configdir`,
        :data:`qscriptdir`, :data:`templatesdir`, :data:`logfilename`, ...

        Normally, the configuration is only loaded when the :mod:`gromacswrapper`
        package is imported but a re-reading of the configuration can be forced
        anytime by calling :func:`get_configuration`.


global cfg, configuration    <EOL>cfg = GMXConfigParser(filename=filename)   <EOL>globals().update(cfg.configuration)        <EOL>configuration = cfg.configuration          <EOL>return cfg<EOL>

Reads and parses the configuration file.

    Default values are loaded and then replaced with the values from
    ``~/.gromacswrapper.cfg`` if that file exists. The global
    configuration instance :data:`gromacswrapper.config.cfg` is updated
    as are a number of global variables such as :data:`configdir`,
    :data:`qscriptdir`, :data:`templatesdir`, :data:`logfilename`, ...

    Normally, the configuration is only loaded when the :mod:`gromacs`
    package is imported but a re-reading of the configuration can be forced
    anytime by calling :func:`get_configuration`.

    :Returns: a dict with all updated global configuration variables


templates = [_get_template(s) for s in utilities.asiterable(t)]<EOL>if len(templates) == <NUM_LIT:1>:<EOL><INDENT>return templates[<NUM_LIT:0>]<EOL><DEDENT>return templates<EOL>

Find template file *t* and return its real path.

    *t* can be a single string or a list of strings. A string
    should be one of

    1. a relative or absolute path,
    2. a file in one of the directories listed in :data:`gromacs.config.path`,
    3. a filename in the package template directory (defined in the template dictionary
       :data:`gromacs.config.templates`) or
    4. a key into :data:`~gromacs.config.templates`.

    The first match (in this order) is returned. If the argument is a
    single string then a single string is returned, otherwise a list
    of strings.

    :Arguments: *t* : template file or key (string or list of strings)
    :Returns:   os.path.realpath(*t*) (or a list thereof)
    :Raises:    :exc:`ValueError` if no file can be located.


def generate_submit_scripts(templates, prefix=None, deffnm='<STR_LIT>', jobname='<STR_LIT>', budget=None,<EOL>mdrun_opts=None, walltime=<NUM_LIT:1.0>, jobarray_string=None, startdir=None,<EOL>npme=None, **kwargs):

if not jobname[<NUM_LIT:0>].isalpha():<EOL><INDENT>jobname = '<STR_LIT>'+jobname<EOL>wmsg = "<STR_LIT>".format(jobname)<EOL>logger.warn(wmsg)<EOL>warnings.warn(wmsg, category=AutoCorrectionWarning)<EOL><DEDENT>if prefix is None:<EOL><INDENT>prefix = "<STR_LIT>"<EOL><DEDENT>if mdrun_opts is not None:<EOL><INDENT>mdrun_opts = '<STR_LIT:">'+str(mdrun_opts)+'<STR_LIT:">'  <EOL><DEDENT>dirname = kwargs.pop('<STR_LIT>', os.path.curdir)<EOL>wt = Timedelta(hours=walltime)<EOL>walltime = wt.strftime("<STR_LIT>")<EOL>wall_hours = wt.ashours<EOL>def write_script(template):<EOL><INDENT>submitscript = os.path.join(dirname, prefix + os.path.basename(template))<EOL>logger.info("<STR_LIT>".format(**vars()))<EOL>qsystem = detect_queuing_system(template)<EOL>if qsystem is not None and (qsystem.name == '<STR_LIT>'):<EOL><INDENT>cbook.edit_txt(template,<EOL>[('<STR_LIT>','<STR_LIT>', deffnm),<EOL>('<STR_LIT>', '<STR_LIT>', jobname),<EOL>('<STR_LIT>', '<STR_LIT>', budget),<EOL>('<STR_LIT>', '<STR_LIT>', walltime),<EOL>('<STR_LIT>', '<STR_LIT>', wall_hours),<EOL>('<STR_LIT>', '<STR_LIT>', startdir),<EOL>('<STR_LIT>', '<STR_LIT>', npme),<EOL>('<STR_LIT>', '<STR_LIT>', mdrun_opts),  <EOL>('<STR_LIT>', '<STR_LIT>', jobarray_string),<EOL>],<EOL>newname=submitscript)<EOL>ext = os.path.splitext(submitscript)[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>cbook.edit_txt(template,<EOL>[('<STR_LIT>','<STR_LIT>', deffnm),<EOL>('<STR_LIT>', '<STR_LIT>', jobname),<EOL>('<STR_LIT>', '<STR_LIT>', budget),<EOL>('<STR_LIT>', '<STR_LIT>', walltime),<EOL>('<STR_LIT>', '<STR_LIT>', wall_hours),<EOL>('<STR_LIT>', '<STR_LIT>', startdir),<EOL>('<STR_LIT>', '<STR_LIT>', npme),<EOL>('<STR_LIT>', '<STR_LIT>', mdrun_opts),  <EOL>('<STR_LIT>', '<STR_LIT>', jobarray_string),<EOL>],<EOL>newname=submitscript)<EOL>ext = os.path.splitext(submitscript)[<NUM_LIT:1>]<EOL><DEDENT>if ext in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>os.chmod(submitscript, <NUM_LIT>)<EOL><DEDENT>return submitscript<EOL><DEDENT>return [write_script(template) for template in config.get_templates(templates)]<EOL>

Write scripts for queuing systems.

    This sets up queuing system run scripts with a simple search and replace in
    templates. See :func:`gromacs.cbook.edit_txt` for details. Shell scripts
    are made executable.

    :Arguments:
      *templates*
          Template file or list of template files. The "files" can also be names
          or symbolic names for templates in the templates directory. See
          :mod:`gromacs.config` for details and rules for writing templates.
      *prefix*
          Prefix for the final run script filename; by default the filename will be
          the same as the template. [None]
      *dirname*
          Directory in which to place the submit scripts. [.]
      *deffnm*
          Default filename prefix for :program:`mdrun` ``-deffnm`` [md]
      *jobname*
          Name of the job in the queuing system. [MD]
      *budget*
          Which budget to book the runtime on [None]
      *startdir*
          Explicit path on the remote system (for run scripts that need to `cd`
          into this directory at the beginning of execution) [None]
      *mdrun_opts*
          String of additional options for :program:`mdrun`.
      *walltime*
          Maximum runtime of the job in hours. [1]
      *npme*
          number of PME nodes
      *jobarray_string*
          Multi-line string that is spliced in for job array functionality
          (see :func:`gromacs.qsub.generate_submit_array`; do not use manually)
      *kwargs*
          all other kwargs are ignored

    :Returns: list of generated run scripts


return self.array_variable is not None<EOL>


suffix = os.path.splitext(scriptname)[<NUM_LIT:1>].lower()<EOL>if suffix.startswith('<STR_LIT:.>'):<EOL><INDENT>suffix = suffix[<NUM_LIT:1>:]<EOL><DEDENT>return self.suffix == suffix<EOL>

Primitive queuing system detection; only looks at suffix at the moment.


if not self.has_arrays():<EOL><INDENT>raise NotImplementedError('<STR_LIT>'<EOL>'<STR_LIT>' % vars(self))<EOL><DEDENT>hrule = '<STR_LIT:#>'+<NUM_LIT>*'<STR_LIT:->'<EOL>lines = [<EOL>'<STR_LIT>',<EOL>hrule,<EOL>'<STR_LIT>',<EOL>self.array_flag(directories),<EOL>hrule,<EOL>'<STR_LIT>',<EOL>'<STR_LIT>']<EOL>for i,dirname in enumerate(asiterable(directories)):<EOL><INDENT>idx = i+<NUM_LIT:1>   <EOL>lines.append('<STR_LIT>'.format(**vars()))<EOL><DEDENT>lines.extend([<EOL>'<STR_LIT>',<EOL>'<STR_LIT>'.format(**vars(self)),<EOL>'<STR_LIT>',<EOL>hrule,<EOL>'<STR_LIT>'<EOL>])<EOL>return "<STR_LIT:\n>".join(lines)<EOL>

Return multiline string for simple array jobs over *directories*.

        .. Warning:: The string is in ``bash`` and hence the template must also
                     be ``bash`` (and *not* ``csh`` or ``sh``).


for qs in queuing_systems:<EOL><INDENT>if qs.isMine(scriptfile):<EOL><INDENT>return qs<EOL><DEDENT><DEDENT>return None<EOL>

Return the queuing system for which *scriptfile* was written.


return self.flag(self.array_option % (<NUM_LIT:1>,len(directories)))<EOL>

Return string to embed the array launching option in the script.


return self[:]<EOL>


path, ext = os.path.splitext(filename)<EOL>if not ext:<EOL><INDENT>ext = "<STR_LIT>"<EOL><DEDENT>return path + ext<EOL>

Use .collection as extension unless provided


def __getnewargs__(self, *args, **kwargs):

return (self.tolist(),)<EOL>

Provide proper initialization to make pickling with protocol 2 work


tmp = cPickle.load(open(self._canonicalize(filename), '<STR_LIT:rb>'))<EOL>if append:<EOL><INDENT>self.extend(tmp)<EOL><DEDENT>else:<EOL><INDENT>self[:] = tmp[:]<EOL><DEDENT>del tmp<EOL>

Load collection from pickled file *filename*.

        *append* determines if the saved collection is added to the current one
        or if it replaces the current content.

        If no extension is provided, ".collection" is appended.


for h in logger.handlers:<EOL><INDENT>logger.removeHandler(h)<EOL><DEDENT>

clean out handlers in the library top level logger

    (only important for reload/debug cycles...)


logger = logging.getLogger(logger_name)<EOL>logger.setLevel(logging.DEBUG)<EOL>logfile = logging.FileHandler(logfile)<EOL>logfile_formatter = logging.Formatter('<STR_LIT>')<EOL>logfile.setFormatter(logfile_formatter)<EOL>logger.addHandler(logfile)<EOL>console = logging.StreamHandler()<EOL>console.setLevel(logging.INFO)<EOL>formatter = logging.Formatter('<STR_LIT>')<EOL>console.setFormatter(formatter)<EOL>logger.addHandler(console)<EOL>return logger<EOL>

Create a top level logger.

    - The file logger logs everything (including DEBUG).
    - The console logger only logs INFO and above.

    Logging to a file and the console.

    See http://docs.python.org/library/logging.html?#logging-to-multiple-destinations

    The top level logger of the library is named 'gromacs'.  Note that
    we are configuring this logger with console output. If the root
    logger also does this then we will get two output lines to the
    console. We'll live with this because this is a simple
    convenience library...


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"] or pieces["<STR_LIT>"]:<EOL><INDENT>rendered += plus_or_dot(pieces)<EOL>rendered += "<STR_LIT>" % (pieces["<STR_LIT>"], pieces["<STR_LIT>"])<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % (pieces["<STR_LIT>"],<EOL>pieces["<STR_LIT>"])<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT>return rendered<EOL>

Build up version string, with post-release "local version identifier".

    Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
    get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty

    Exceptions:
    1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]


<EOL>cfg = VersioneerConfig()<EOL>cfg.VCS = "<STR_LIT>"<EOL>cfg.style = "<STR_LIT>"<EOL>cfg.tag_prefix = "<STR_LIT>"<EOL>cfg.parentdir_prefix = "<STR_LIT>"<EOL>cfg.versionfile_source = "<STR_LIT>"<EOL>cfg.verbose = False<EOL>return cfg<EOL>

Create, populate and return the VersioneerConfig() object.


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % (pieces["<STR_LIT>"], pieces["<STR_LIT>"])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL><DEDENT>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>return rendered<EOL>

TAG[-DISTANCE-gHEX][-dirty].

    Like 'git describe --tags --dirty --always'.

    Exceptions:
    1: no tags. HEX[-dirty]  (note: no 'g' prefix)


if pieces["<STR_LIT:error>"]:<EOL><INDENT>return {"<STR_LIT:version>": "<STR_LIT>",<EOL>"<STR_LIT>": pieces.get("<STR_LIT>"),<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT:error>": pieces["<STR_LIT:error>"],<EOL>"<STR_LIT:date>": None}<EOL><DEDENT>if not style or style == "<STR_LIT:default>":<EOL><INDENT>style = "<STR_LIT>"  <EOL><DEDENT>if style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440_pre(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440_post(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_pep440_old(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_git_describe(pieces)<EOL><DEDENT>elif style == "<STR_LIT>":<EOL><INDENT>rendered = render_git_describe_long(pieces)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % style)<EOL><DEDENT>return {"<STR_LIT:version>": rendered, "<STR_LIT>": pieces["<STR_LIT>"],<EOL>"<STR_LIT>": pieces["<STR_LIT>"], "<STR_LIT:error>": None,<EOL>"<STR_LIT:date>": pieces.get("<STR_LIT:date>")}<EOL>

Render the given version pieces into the requested style.


def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,<EOL>env=None):

assert isinstance(commands, list)<EOL>p = None<EOL>for c in commands:<EOL><INDENT>try:<EOL><INDENT>dispcmd = str([c] + args)<EOL>p = subprocess.Popen([c] + args, cwd=cwd, env=env,<EOL>stdout=subprocess.PIPE,<EOL>stderr=(subprocess.PIPE if hide_stderr<EOL>else None))<EOL>break<EOL><DEDENT>except EnvironmentError:<EOL><INDENT>e = sys.exc_info()[<NUM_LIT:1>]<EOL>if e.errno == errno.ENOENT:<EOL><INDENT>continue<EOL><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % dispcmd)<EOL>print(e)<EOL><DEDENT>return None, None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % (commands,))<EOL><DEDENT>return None, None<EOL><DEDENT>stdout = p.communicate()[<NUM_LIT:0>].strip()<EOL>if sys.version_info[<NUM_LIT:0>] >= <NUM_LIT:3>:<EOL><INDENT>stdout = stdout.decode()<EOL><DEDENT>if p.returncode != <NUM_LIT:0>:<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % dispcmd)<EOL>print("<STR_LIT>" % stdout)<EOL><DEDENT>return None, p.returncode<EOL><DEDENT>return stdout, p.returncode<EOL>


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"] or pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT><DEDENT>return rendered<EOL>

TAG[.postDISTANCE[.dev0]] .

    The ".dev0" means dirty.

    Eexceptions:
    1: no tags. 0.postDISTANCE[.dev0]


@register_vcs_handler("<STR_LIT>", "<STR_LIT>")<EOL>def git_versions_from_keywords(keywords, tag_prefix, verbose):

if not keywords:<EOL><INDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>date = keywords.get("<STR_LIT:date>")<EOL>if date is not None:<EOL><INDENT>date = date.strip().replace("<STR_LIT:U+0020>", "<STR_LIT:T>", <NUM_LIT:1>).replace("<STR_LIT:U+0020>", "<STR_LIT>", <NUM_LIT:1>)<EOL><DEDENT>refnames = keywords["<STR_LIT>"].strip()<EOL>if refnames.startswith("<STR_LIT>"):<EOL><INDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>raise NotThisMethod("<STR_LIT>")<EOL><DEDENT>refs = set([r.strip() for r in refnames.strip("<STR_LIT>").split("<STR_LIT:U+002C>")])<EOL>TAG = "<STR_LIT>"<EOL>tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])<EOL>if not tags:<EOL><INDENT>tags = set([r for r in refs if re.search(r'<STR_LIT>', r)])<EOL>if verbose:<EOL><INDENT>print("<STR_LIT>" % "<STR_LIT:U+002C>".join(refs - tags))<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>" % "<STR_LIT:U+002C>".join(sorted(tags)))<EOL><DEDENT>for ref in sorted(tags):<EOL><INDENT>if ref.startswith(tag_prefix):<EOL><INDENT>r = ref[len(tag_prefix):]<EOL>if verbose:<EOL><INDENT>print("<STR_LIT>" % r)<EOL><DEDENT>return {"<STR_LIT:version>": r,<EOL>"<STR_LIT>": keywords["<STR_LIT>"].strip(),<EOL>"<STR_LIT>": False, "<STR_LIT:error>": None,<EOL>"<STR_LIT:date>": date}<EOL><DEDENT><DEDENT>if verbose:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>return {"<STR_LIT:version>": "<STR_LIT>",<EOL>"<STR_LIT>": keywords["<STR_LIT>"].strip(),<EOL>"<STR_LIT>": False, "<STR_LIT:error>": "<STR_LIT>", "<STR_LIT:date>": None}<EOL>

Get version information from git keywords.


if pieces["<STR_LIT>"]:<EOL><INDENT>rendered = pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"] or pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>rendered += plus_or_dot(pieces)<EOL>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rendered = "<STR_LIT>" % pieces["<STR_LIT>"]<EOL>if pieces["<STR_LIT>"]:<EOL><INDENT>rendered += "<STR_LIT>"<EOL><DEDENT>rendered += "<STR_LIT>" % pieces["<STR_LIT>"]<EOL><DEDENT>return rendered<EOL>

TAG[.postDISTANCE[.dev0]+gHEX] .

    The ".dev0" means dirty. Note that .dev0 sorts backwards
    (a dirty tree will appear "older" than the corresponding clean one),
    but you shouldn't be releasing software with -dirty anyways.

    Exceptions:
    1: no tags. 0.postDISTANCE[.dev0]


super(Flags,self).__setitem__(flag.name,flag)<EOL>

Register a new :class:`Flag` instance with the Flags registry.


filter_gromacs_warnings('<STR_LIT>', categories=categories)<EOL>

Enable ("always") specified warnings from the gromacs package.

    *categories* must be a list of warning classes or strings.
    ``None`` selects the defaults, :data:`gromacs._less_important_warnings`.


from . import log<EOL>log.create("<STR_LIT>", logfile=logfile)<EOL>logging.getLogger("<STR_LIT>").info("<STR_LIT>",<EOL>__version__, logfile)<EOL>

Start logging of messages to file and console.

    The default logfile is named ``gromacs.log`` and messages are
    logged with the tag *gromacs*.


m = self.COLOUR.search(c)<EOL>if not m:<EOL><INDENT>self.logger.fatal("<STR_LIT>", c)<EOL>raise ParseError("<STR_LIT>".format(c))<EOL><DEDENT>value = m.group('<STR_LIT:value>')<EOL>color = m.group('<STR_LIT>')<EOL>self.logger.debug("<STR_LIT>", c.strip(), color, value)<EOL>return color, value<EOL>


self._init_filename(filename)<EOL>self.parse()<EOL>


if self.atoms:<EOL><INDENT>self._anumb_to_atom = {}<EOL>for i,atom in enumerate(self.atoms):<EOL><INDENT>atom.number = i+<NUM_LIT:1>   <EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.logger("<STR_LIT>")<EOL><DEDENT>

Reset the molecule's atoms :attr:`number` to be 1-indexed


assert isinstance(anumb, int), "<STR_LIT>"<EOL>if not self._anumb_to_atom:   <EOL><INDENT>if self.atoms:<EOL><INDENT>for atom in self.atoms:<EOL><INDENT>self._anumb_to_atom[atom.number] = atom<EOL><DEDENT>return self._anumb_to_atom[anumb]<EOL><DEDENT>else:<EOL><INDENT>self.logger("<STR_LIT>")<EOL>return False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if anumb in self._anumb_to_atom:<EOL><INDENT>return self._anumb_to_atom[anumb]<EOL><DEDENT>else:<EOL><INDENT>self.logger("<STR_LIT>".format(anumb))<EOL>return False<EOL><DEDENT><DEDENT>

Returns the atom object corresponding to an atom number


SystemToGroTop(self, filename)<EOL>


self.logger.debug("<STR_LIT>")<EOL>top = '<STR_LIT>'<EOL>self.logger.debug("<STR_LIT>")<EOL>top += self.toptemplate<EOL>top = top.replace('<STR_LIT>',       '<STR_LIT>'.join( self._make_defaults(self.system)) )<EOL>top = top.replace('<STR_LIT>',      '<STR_LIT>'.join( self._make_atomtypes(self.system)) )<EOL>top = top.replace('<STR_LIT>',  '<STR_LIT>'.join( self._make_nonbond_param(self.system)) )<EOL>top = top.replace('<STR_LIT>',      '<STR_LIT>'.join( self._make_pairtypes(self.system)) )<EOL>top = top.replace('<STR_LIT>',      '<STR_LIT>'.join( self._make_bondtypes(self.system)) )<EOL>top = top.replace('<STR_LIT>','<STR_LIT>'.join( self._make_constrainttypes(self.system)))<EOL>top = top.replace('<STR_LIT>',     '<STR_LIT>'.join( self._make_angletypes(self.system)))<EOL>top = top.replace('<STR_LIT>',  '<STR_LIT>'.join( self._make_dihedraltypes(self.system)) )<EOL>top = top.replace('<STR_LIT>',  '<STR_LIT>'.join( self._make_impropertypes(self.system)) )<EOL>top = top.replace('<STR_LIT>',      '<STR_LIT>'.join( self._make_cmaptypes(self.system)) )<EOL>for i,(molname,m) in enumerate(self.system.dict_molname_mol.items()):<EOL><INDENT>itp = self.itptemplate<EOL>itp = itp.replace('<STR_LIT>',  '<STR_LIT>'.join( self._make_moleculetype(m, molname, m.exclusion_numb))  )<EOL>itp = itp.replace('<STR_LIT>',         '<STR_LIT>'.join( self._make_atoms(m))  )<EOL>itp = itp.replace('<STR_LIT>',         '<STR_LIT>'.join( self._make_bonds(m))  )<EOL>itp = itp.replace('<STR_LIT>',         '<STR_LIT>'.join( self._make_pairs(m))  )<EOL>itp = itp.replace('<STR_LIT>',       '<STR_LIT>'.join( self._make_settles(m))  )<EOL>itp = itp.replace('<STR_LIT>','<STR_LIT>'.join( self._make_virtual_sites3(m))  )<EOL>itp = itp.replace('<STR_LIT>',    '<STR_LIT>'.join( self._make_exclusions(m))  )<EOL>itp = itp.replace('<STR_LIT>',        '<STR_LIT>'.join( self._make_angles(m)) )<EOL>itp = itp.replace('<STR_LIT>',     '<STR_LIT>'.join( self._make_dihedrals(m)) )<EOL>itp = itp.replace('<STR_LIT>',     '<STR_LIT>'.join( self._make_impropers(m)) )<EOL>itp = itp.replace('<STR_LIT>',         '<STR_LIT>'.join( self._make_cmaps(m)) )<EOL>if not self.multiple_output:<EOL><INDENT>top += itp<EOL><DEDENT>else:<EOL><INDENT>outfile = "<STR_LIT>".format(molname)<EOL>top += '<STR_LIT>'.format( molname )<EOL>with open(outfile, "<STR_LIT:w>") as f:<EOL><INDENT>f.writelines([itp])<EOL><DEDENT><DEDENT><DEDENT>top += '<STR_LIT>'<EOL>top += '<STR_LIT>'<EOL>molecules = [("<STR_LIT>", <NUM_LIT:0>)]<EOL>for m in self.system.molecules:<EOL><INDENT>if (molecules[-<NUM_LIT:1>][<NUM_LIT:0>] != m.name):<EOL><INDENT>molecules.append([m.name, <NUM_LIT:0>])<EOL><DEDENT>if molecules[-<NUM_LIT:1>][<NUM_LIT:0>] == m.name:<EOL><INDENT>molecules[-<NUM_LIT:1>][<NUM_LIT:1>] += <NUM_LIT:1><EOL><DEDENT><DEDENT>for molname, n in molecules[<NUM_LIT:1>:]:<EOL><INDENT>top += '<STR_LIT>'.format(molname, n)<EOL><DEDENT>top += '<STR_LIT:\n>'<EOL>with open(self.outfile, '<STR_LIT:w>') as f:<EOL><INDENT>f.writelines([top])<EOL><DEDENT>

Call the various member self._make_* functions to convert the topology object into a string


def __init__(self, system, outfile="<STR_LIT>", multiple_output=False):

self.logger = logging.getLogger('<STR_LIT>')<EOL>self.logger.debug("<STR_LIT>")<EOL>self.system   = system<EOL>self.outfile = outfile<EOL>self.multiple_output = multiple_output<EOL>self.assemble_topology()<EOL>self.logger.debug("<STR_LIT>")<EOL>

Initialize GROMACS topology writer.

        :Arguments:
          *system*
              :class:`blocks.System` object, containing the topology
          *outfile*
              name of the file to write to
          *multiple_output*
              if True, write moleculetypes to separate files, named mol_MOLNAME.itp (default: False)


if not isinstance(obj, six.string_types):<EOL><INDENT>return obj<EOL><DEDENT>try:<EOL><INDENT>obj = six.text_type(obj)<EOL><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT>return obj<EOL>

Convert obj to unicode (if it can be be converted).

    Conversion is only attempted if `obj` is a string type (as
    determined by :data:`six.string_types`).

    .. versionchanged:: 0.7.0
       removed `encoding keyword argument


if self.sep is False:<EOL><INDENT>x = self._convert_singlet(field)<EOL><DEDENT>else:<EOL><INDENT>x = tuple([self._convert_singlet(s) for s in field.split(self.sep)])<EOL>if len(x) == <NUM_LIT:0>:<EOL><INDENT>x = '<STR_LIT>'<EOL><DEDENT>elif len(x) == <NUM_LIT:1>:<EOL><INDENT>x = x[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>return x<EOL>

Convert to a list (sep != None) and convert list elements.


<EOL>def promote_i4(typestr):<EOL><INDENT>if typestr[<NUM_LIT:1>:] == '<STR_LIT>':<EOL><INDENT>typestr = typestr[<NUM_LIT:0>]+'<STR_LIT>'<EOL><DEDENT>return typestr<EOL><DEDENT>dtype = [(name, promote_i4(typestr)) for name,typestr in a.dtype.descr]<EOL>return a.astype(dtype)<EOL>

Return view of the recarray with all int32 cast to int64.


self._init_filename(filename)<EOL>with utilities.openany(self.real_filename, '<STR_LIT:w>') as xvg:<EOL><INDENT>xvg.write("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>xvg.write("<STR_LIT>".format(self.names))<EOL>for xyy in self.array.T:<EOL><INDENT>xyy.tofile(xvg, sep="<STR_LIT:U+0020>", format="<STR_LIT>")  <EOL>xvg.write('<STR_LIT:\n>')<EOL><DEDENT><DEDENT>

Write array to xvg file *filename* in NXY format.

        .. Note:: Only plain files working at the moment, not compressed.


return self.array[<NUM_LIT:1>:].max(axis=<NUM_LIT:1>)<EOL>


def decimate_rms(self, a, maxpoints, **kwargs):

return self._decimate(numkit.timeseries.rms_histogrammed_function, a, maxpoints, **kwargs)<EOL>

Return data *a* rms-decimated on *maxpoints*.

        Histograms each column into *maxpoints* bins and calculates
        the root mean square sum in each bin as the decimated data,
        using :func:`numkit.timeseries.rms_histogrammed_function`. The coarse
        grained time in the first column contains the centers of the
        histogram time.

        If *a* contains <= *maxpoints* then *a* is simply returned;
        otherwise a new array of the same dimensions but with a
        reduced number of  *maxpoints* points is returned.

        .. Note::

           Assumes that the first column is time.


self.__array = numpy.asarray(a)<EOL>

Set the *array* data from *a* (i.e. completely replace).

        No sanity checks at the moment...


def decimate_max(self, a, maxpoints, **kwargs):

return self._decimate(numkit.timeseries.max_histogrammed_function, a, maxpoints, **kwargs)<EOL>

Return data *a* max-decimated on *maxpoints*.

        Histograms each column into *maxpoints* bins and calculates
        the maximum in each bin as the decimated data, using
        :func:`numkit.timeseries.max_histogrammed_function`. The coarse grained
        time in the first column contains the centers of the histogram
        time.

        If *a* contains <= *maxpoints* then *a* is simply returned;
        otherwise a new array of the same dimensions but with a
        reduced number of  *maxpoints* points is returned.

        .. Note::

           Assumes that the first column is time.


return self.array[<NUM_LIT:1>:].min(axis=<NUM_LIT:1>)<EOL>


if self.__array is None:<EOL><INDENT>self.parse()<EOL><DEDENT>return self.__array<EOL>

Represent xvg data as a (cached) numpy array.

        The array is returned with column-first indexing, i.e. for a data file with
        columns X Y1 Y2 Y3 ... the array a will be a[0] = X, a[1] = Y1, ... .


ax = kwargs.pop('<STR_LIT>', None)<EOL>columns = kwargs.pop('<STR_LIT>', Ellipsis)         <EOL>if columns is Ellipsis or columns is None:<EOL><INDENT>columns = numpy.arange(self.array.shape[<NUM_LIT:0>])<EOL><DEDENT>if len(columns) < <NUM_LIT:2>:<EOL><INDENT>raise MissingDataError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>color = kwargs.pop('<STR_LIT>', self.default_color_cycle)<EOL>try:<EOL><INDENT>cmap = matplotlib.cm.get_cmap(color)<EOL>colors = cmap(matplotlib.colors.Normalize()(numpy.arange(len(columns[<NUM_LIT:1>:]), dtype=float)))<EOL><DEDENT>except TypeError:<EOL><INDENT>colors = cycle(utilities.asiterable(color))<EOL><DEDENT>if ax is None:<EOL><INDENT>ax = plt.gca()<EOL><DEDENT>t = columns[<NUM_LIT:0>]<EOL>kwargs['<STR_LIT>'] = True<EOL>kwargs['<STR_LIT>'] = ax<EOL>for column, color in zip(columns[<NUM_LIT:1>:], colors):<EOL><INDENT>kwargs['<STR_LIT>'] = color<EOL>self.errorbar(columns=[t, column, column], **kwargs)<EOL><DEDENT>return ax<EOL>

Plot data like :meth:`XVG.plot` with the range of **all** data shown.

        Data are reduced to *maxpoints* (good results are obtained
        with low values such as 100) and the actual range of observed
        data is plotted as a translucent error band around the mean.

        Each column in *columns* (except the abscissa, i.e. the first
        column) is decimated (with :meth:`XVG.decimate`) and the range
        of data is plotted alongside the mean using
        :meth:`XVG.errorbar` (see for arguments). Additional
        arguments:

        :Kewords:
           *maxpoints*
                number of points (bins) to coarsen over
           *color*
                single color (used for all plots); sequence of colors
                (will be repeated as necessary); or a matplotlib
                colormap (e.g. "jet", see :mod:`matplotlib.cm`). The
                default is to use the :attr:`XVG.default_color_cycle`.
           *method*
                Method to coarsen the data. See :meth:`XVG.decimate`

        The *demean* keyword has no effect as it is required to be ``True``.

        .. SeeAlso:: :meth:`XVG.plot`, :meth:`XVG.errorbar` and :meth:`XVG.decimate`


def __init__(self, filename=None, names=None, array=None, permissive=False, **kwargs):

self.__array = None           <EOL>self.__cache = {}             <EOL>self.savedata = kwargs.pop('<STR_LIT>', False)<EOL>if filename is not None:<EOL><INDENT>self._init_filename(filename)  <EOL><DEDENT>if names is None:<EOL><INDENT>self.names = []<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>self.names = names.split('<STR_LIT:U+002C>')<EOL><DEDENT>except AttributeError:<EOL><INDENT>self.names = names<EOL><DEDENT><DEDENT>self.metadata = kwargs.pop('<STR_LIT>', {})  <EOL>self.permissive = permissive<EOL>self.stride = kwargs.pop('<STR_LIT>', <NUM_LIT:1>)<EOL>self.corrupted_lineno = None      <EOL>self.ncorrel = kwargs.pop('<STR_LIT>', <NUM_LIT>)<EOL>self.__correlkwargs = {}          <EOL>if array is not None:<EOL><INDENT>self.set(array)<EOL><DEDENT>

Initialize the class from a xvg file.

        :Arguments:
              *filename*
                    is the xvg file; it can only be of type XY or
                    NXY. If it is supplied then it is read and parsed
                    when :attr:`XVG.array` is accessed.
              *names*
                    optional labels for the columns (currently only
                    written as comments to file); string with columns
                    separated by commas or a list of strings
              *array*
                    read data from *array* (see :meth:`XVG.set`)
              *permissive*
                    ``False`` raises a :exc:`ValueError` and logs and errior
                    when encountering data lines that it cannot parse.
                    ``True`` ignores those lines and logs a warning---this is
                    a risk because it might read a corrupted input file [``False``]
              *stride*
                    Only read every *stride* line of data [1].
              *savedata*
                    ``True`` includes the data (:attr:`XVG.array`` and
                    associated caches) when the instance is pickled (see
                    :mod:`pickle`); this is oftens not desirable because the
                    data are already on disk (the xvg file *filename*) and the
                    resulting pickle file can become very big. ``False`` omits
                    those data from a pickle. [``False``]
              *metadata*
                    dictionary of metadata, which is not touched by the class


def _tcorrel(self, nstep=<NUM_LIT:100>, **kwargs):

t = self.array[<NUM_LIT:0>,::nstep]<EOL>r = gromacs.collections.Collection([numkit.timeseries.tcorrel(t, Y, nstep=<NUM_LIT:1>, **kwargs) for Y in self.array[<NUM_LIT:1>:,::nstep]])<EOL>return r<EOL>

Correlation "time" of data.

        The 0-th column of the data is interpreted as a time and the
        decay of the data is computed from the autocorrelation
        function (using FFT).

        .. SeeAlso:: :func:`numkit.timeseries.tcorrel`


ax = kwargs.pop('<STR_LIT>', None)<EOL>color = kwargs.pop('<STR_LIT>', '<STR_LIT>')<EOL>filled = kwargs.pop('<STR_LIT>', True)<EOL>fill_alpha = kwargs.pop('<STR_LIT>', <NUM_LIT>)<EOL>kwargs.setdefault('<STR_LIT>', <NUM_LIT:0>)<EOL>kwargs.setdefault('<STR_LIT>', <NUM_LIT:1>)<EOL>kwargs.setdefault('<STR_LIT>', color)<EOL>kwargs.setdefault('<STR_LIT>', <NUM_LIT>)<EOL>kwargs.setdefault('<STR_LIT>', None)<EOL>columns = kwargs.pop('<STR_LIT>', Ellipsis)         <EOL>maxpoints = kwargs.pop('<STR_LIT>', self.maxpoints_default)<EOL>transform = kwargs.pop('<STR_LIT>', lambda x: x)  <EOL>method = kwargs.pop('<STR_LIT>', "<STR_LIT>")<EOL>if method != "<STR_LIT>":<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT>error_method = kwargs.pop('<STR_LIT>', "<STR_LIT>")  <EOL>percentile = numpy.abs(kwargs.pop('<STR_LIT>', <NUM_LIT>))<EOL>demean = kwargs.pop('<STR_LIT>', False)<EOL>try:<EOL><INDENT>data = numpy.asarray(transform(self.array))[columns]<EOL><DEDENT>except IndexError:<EOL><INDENT>raise MissingDataError("<STR_LIT>".format(columns))<EOL><DEDENT>if data.shape[-<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>raise MissingDataError("<STR_LIT>")<EOL><DEDENT>a = numpy.zeros((data.shape[<NUM_LIT:0>], maxpoints), dtype=numpy.float64)<EOL>a[<NUM_LIT:0>:<NUM_LIT:2>] = self.decimate("<STR_LIT>", data[<NUM_LIT:0>:<NUM_LIT:2>], maxpoints=maxpoints)<EOL>error_data = numpy.vstack((data[<NUM_LIT:0>], data[<NUM_LIT:2>:]))<EOL>if error_method == "<STR_LIT>":<EOL><INDENT>if percentile > <NUM_LIT:50>:<EOL><INDENT>upper_per = percentile<EOL>lower_per = <NUM_LIT:100> - percentile<EOL><DEDENT>else:<EOL><INDENT>upper_per = <NUM_LIT:100> - percentile<EOL>lower_per = percentile<EOL><DEDENT>upper = a[<NUM_LIT:2>:] = self.decimate("<STR_LIT>", error_data, maxpoints=maxpoints,<EOL>per=upper_per, demean=False)[<NUM_LIT:1>:]<EOL>lower = self.decimate("<STR_LIT>", error_data, maxpoints=maxpoints,<EOL>per=lower_per, demean=False)[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>a[<NUM_LIT:2>:] = self.decimate(error_method, error_data, maxpoints=maxpoints, demean=demean)[<NUM_LIT:1>:]<EOL>lower = None<EOL><DEDENT>ma = numpy.ma.MaskedArray(a, mask=numpy.logical_not(numpy.isfinite(a)))<EOL>if lower is not None:<EOL><INDENT>mlower = numpy.ma.MaskedArray(lower, mask=numpy.logical_not(numpy.isfinite(lower)))<EOL><DEDENT>X = ma[<NUM_LIT:0>]          <EOL>Y = ma[<NUM_LIT:1>]<EOL>try:<EOL><INDENT>kwargs['<STR_LIT>'] = ma[<NUM_LIT:3>]<EOL>kwargs['<STR_LIT>'] = ma[<NUM_LIT:2>]<EOL><DEDENT>except IndexError:<EOL><INDENT>try:<EOL><INDENT>kwargs['<STR_LIT>'] = ma[<NUM_LIT:2>]<EOL><DEDENT>except IndexError:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT><DEDENT>if ax is None:<EOL><INDENT>ax = plt.gca()<EOL><DEDENT>if filled:<EOL><INDENT>if error_method == "<STR_LIT>":<EOL><INDENT>if demean:<EOL><INDENT>y1 = mlower[-<NUM_LIT:1>]<EOL>y2 = kwargs['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>y1 = Y - mlower[-<NUM_LIT:1>]<EOL>y2 = Y + kwargs['<STR_LIT>']<EOL><DEDENT><DEDENT>else:<EOL><INDENT>y1 = Y - kwargs['<STR_LIT>']<EOL>y2 = Y + kwargs['<STR_LIT>']<EOL><DEDENT>ax.fill_between(X, y1, y2, color=color, alpha=fill_alpha)<EOL><DEDENT>else:<EOL><INDENT>if error_method == "<STR_LIT>":<EOL><INDENT>if demean:<EOL><INDENT>kwargs['<STR_LIT>'] = numpy.vstack((mlower[-<NUM_LIT:1>], kwargs['<STR_LIT>']))<EOL><DEDENT>else:<EOL><INDENT>kwargs['<STR_LIT>'] = numpy.vstack((Y - mlower[-<NUM_LIT:1>], Y + kwargs['<STR_LIT>']))<EOL><DEDENT>try:<EOL><INDENT>kwargs['<STR_LIT>'] = numpy.vstack((X - mlower[<NUM_LIT:0>], X + kwargs['<STR_LIT>']))<EOL><DEDENT>except (KeyError, IndexError):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>ax.errorbar(X, Y, **kwargs)<EOL><DEDENT>for kw in "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>":<EOL><INDENT>kwargs.pop(kw, None)<EOL><DEDENT>kwargs['<STR_LIT>'] = <NUM_LIT:1.0><EOL>ax.plot(X, Y, color=color, **kwargs)<EOL>return ax<EOL>

errorbar plot for a single time series with errors.

        Set *columns* keyword to select [x, y, dy] or [x, y, dx, dy],
        e.g. ``columns=[0,1,2]``. See :meth:`XVG.plot` for
        details. Only a single timeseries can be plotted and the user
        needs to select the appropriate columns with the *columns*
        keyword.

        By default, the data are decimated (see :meth:`XVG.plot`) for
        the default of *maxpoints* = 10000 by averaging data in
        *maxpoints* bins.

        x,y,dx,dy data can plotted with error bars in the x- and
        y-dimension (use *filled* = ``False``).

        For x,y,dy use *filled* = ``True`` to fill the region between
        y±dy. *fill_alpha* determines the transparency of the fill
        color. *filled* = ``False`` will draw lines for the error
        bars. Additional keywords are passed to
        :func:`pylab.errorbar`.

        By default, the errors are decimated by plotting the 5% and
        95% percentile of the data in each bin. The percentile can be
        changed with the *percentile* keyword; e.g. *percentile* = 1
        will plot the 1% and 99% perentile (as will *percentile* =
        99).

        The *error_method* keyword can be used to compute errors as
        the root mean square sum (*error_method* = "rms") across each
        bin instead of percentiles ("percentile"). The value of the
        keyword *demean* is applied to the decimation of error data
        alone.

        .. SeeAlso::

           :meth:`XVG.plot` lists keywords common to both methods.


def __init__(self, filename=None, autoconvert=True, **kwargs):

super(MDP, self).__init__(**kwargs)  <EOL>self.autoconvert = autoconvert<EOL>if filename is not None:<EOL><INDENT>self._init_filename(filename)<EOL>self.read(filename)<EOL><DEDENT>

Initialize mdp structure.

        :Arguments:
          *filename*
              read from mdp file
          *autoconvert* : boolean
              ``True`` converts numerical values to python numerical types;
              ``False`` keeps everything as strings [``True``]
          *kwargs*
              Populate the MDP with key=value pairs. (NO SANITY CHECKS; and also
              does not work for keys that are not legal python variable names such
              as anything that includes a minus '-' sign or starts with a number).


return len(self[name])<EOL>

Return number of entries for group *name*.


return self[name]<EOL>

Return index array for index group *name*.


return numpy.ravel(v).astype(int)<EOL>

Transform input to the stored representation.

        Override eg with ``return set(v)`` for index lists as sets.


return self._sum([self[k] for k in groupnames if k in self])<EOL>

Return an index group that contains atoms from all  *groupnames*.

        The method will silently ignore any groups that are not in the
        index.

        **Example**

        Always make a solvent group from water and ions, even if not
        all ions are present in all simulations::

           I['SOLVENT'] = I.join('SOL', 'NA+', 'K+', 'CL-')


return [{'<STR_LIT:name>': name, '<STR_LIT>': len(atomnumbers), '<STR_LIT>': nr+<NUM_LIT:1>} for<EOL>nr,(name,atomnumbers) in enumerate(self.items())]<EOL>

Return a list of groups in the same format as  :func:`gromacs.cbook.get_ndx_groups`.

        Format:
           [ {'name': group_name, 'natoms': number_atoms, 'nr':  # group_number}, ....]


def write(self, filename=None, ncol=ncol, format=format):

with open(self.filename(filename, ext='<STR_LIT>'), '<STR_LIT:w>') as ndx:<EOL><INDENT>for name in self:<EOL><INDENT>atomnumbers = self._getarray(name)  <EOL>ndx.write('<STR_LIT>'.format(name))<EOL>for k in range(<NUM_LIT:0>, len(atomnumbers), ncol):<EOL><INDENT>line = atomnumbers[k:k+ncol].astype(int)   <EOL>n = len(line)<EOL>ndx.write(("<STR_LIT:U+0020>".join(n*[format])+'<STR_LIT:\n>') % tuple(line))<EOL><DEDENT>ndx.write('<STR_LIT:\n>')<EOL><DEDENT><DEDENT>

Write index file to *filename* (or overwrite the file that the index was read from)


self._init_filename(filename)<EOL>data = odict()<EOL>with open(self.real_filename) as ndx:<EOL><INDENT>current_section = None<EOL>for line in ndx:<EOL><INDENT>line = line.strip()<EOL>if len(line) == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>m = self.SECTION.match(line)<EOL>if m:<EOL><INDENT>current_section = m.group('<STR_LIT:name>')<EOL>data[current_section] = []  <EOL>continue<EOL><DEDENT>if current_section is not None:<EOL><INDENT>data[current_section].extend(map(int, line.split()))<EOL><DEDENT><DEDENT><DEDENT>super(NDX,self).update(odict([(name, self._transform(atomnumbers))<EOL>for name, atomnumbers in data.items()]))<EOL>


cmd = self.MDRUN.commandline()<EOL>if self.mpiexec:<EOL><INDENT>cmd = self.mpicommand(**mpiargs) + cmd<EOL><DEDENT>return cmd<EOL>

Returns simple command line to invoke mdrun.

        If :attr:`mpiexec` is set then :meth:`mpicommand` provides the mpi
        launcher command that prefixes the actual ``mdrun`` invocation:

           :attr:`mpiexec` [*mpiargs*]  :attr:`mdrun` [*mdrun-args*]

        The *mdrun-args* are set on initializing the class. Override
        :meth:`mpicommand` to fit your system if the simple default
        OpenMP launcher is not appropriate.


try:<EOL><INDENT>gromacs.mdrun_d(h=True, stdout=False, stderr=False)<EOL>logger.debug("<STR_LIT>")<EOL>return gromacs.mdrun_d<EOL><DEDENT>except (AttributeError, GromacsError, OSError):<EOL><INDENT>wmsg = "<STR_LIT>""<STR_LIT>"<EOL>logger.warn(wmsg)<EOL>warnings.warn(wmsg, category=AutoCorrectionWarning)<EOL>return gromacs.mdrun<EOL><DEDENT>

Return double precision ``mdrun`` or fall back to single precision.

    This convenience function tries :func:`gromacs.mdrun_d` first and
    if it cannot run it, falls back to :func:`gromacs.mdrun` (without
    further checking).

    .. versionadded:: 0.5.1


cmd = ['<STR_LIT>', '<STR_LIT>']<EOL>logger.info("<STR_LIT>"+"<STR_LIT:U+0020>".join(cmd))<EOL>rc = subprocess.call(cmd)<EOL>return rc<EOL>


if not os.path.exists(logfile):<EOL><INDENT>return None<EOL><DEDENT>with open(logfile, '<STR_LIT:rb>') as log:<EOL><INDENT>log.seek(-<NUM_LIT>, <NUM_LIT:2>)<EOL>for line in log:<EOL><INDENT>line = line.decode('<STR_LIT>')<EOL>if line.startswith("<STR_LIT>"):<EOL><INDENT>return True<EOL><DEDENT><DEDENT><DEDENT>return False<EOL>

Check if ``mdrun`` finished successfully.

    Analyses the output from ``mdrun`` in *logfile*. Right now we are
    simply looking for the line "Finished mdrun on node" in the last 1kb of
    the file. (The file must be seeakable.)

    :Arguments:
      *logfile* : filename
         Logfile produced by ``mdrun``.

    :Returns: ``True`` if all ok, ``False`` if not finished, and
              ``None`` if the *logfile* cannot be opened


return<EOL>

Called directly before launching the process.


if self.mpiexec is None:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT>ncores = kwargs.pop('<STR_LIT>', <NUM_LIT:8>)<EOL>return [self.mpiexec, '<STR_LIT>', str(ncores)]<EOL>

Return a list of the mpi command portion of the commandline.

        Only allows primitive mpi at the moment:
           *mpiexec* -n *ncores* *mdrun* *mdrun-args*

        (This is a primitive example for OpenMP. Override it for more
        complicated cases.)


frames = self.all_frames<EOL>if len(frames) == <NUM_LIT:0>:<EOL><INDENT>self.extract()<EOL>frames = self.all_frames<EOL><DEDENT>for i in xrange(len(frames)):<EOL><INDENT>self.framenumber = i<EOL>yield self.current_framename<EOL><DEDENT>self.totalframes += len(frames)<EOL>


shutil.rmtree(self.framedir)<EOL>self.framedir = None<EOL>

Clean up all temporary frames (which can be HUGE).


kwargs.setdefault('<STR_LIT>', '<STR_LIT>')<EOL>kw_fit = {}<EOL>for k in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:input>'):<EOL><INDENT>if k in kwargs:<EOL><INDENT>kw_fit[k] = kwargs.pop(k)<EOL><DEDENT><DEDENT>kwargs['<STR_LIT:input>'] = kwargs.pop('<STR_LIT>', ['<STR_LIT>'])<EOL>kwargs['<STR_LIT>'] = kw_fit['<STR_LIT>'] = kwargs.pop('<STR_LIT>', self.force)<EOL>paths = self.strip_water(**kwargs)    <EOL>transformer_nowater = self.nowater[paths['<STR_LIT>']]  <EOL>return transformer_nowater.fit(**kw_fit)          <EOL>

Strip water and fit to the remaining system.

        First runs :meth:`strip_water` and then :meth:`fit`; see there
        for arguments.

        - *strip_input* is used for :meth:`strip_water` (but is only useful in
          special cases, e.g. when there is no Protein group defined. Then set
          *strip_input* = ``['Other']``.

        - *input* is passed on to :meth:`fit` and can contain the
          ``[center_group, fit_group, output_group]``

        - *fitgroup* is only passed to :meth:`fit` and just contains
          the group to fit to ("backbone" by default)

          .. warning:: *fitgroup* can only be a Gromacs default group and not
                       a custom group (because the indices change after stripping)

        - By default *fit* = "rot+trans" (and *fit* is passed to :meth:`fit`,
          together with the *xy* = ``False`` keyword)

        .. Note:: The call signature of :meth:`strip_water` is somewhat different from this one.


def _process_residue(self, selection, name=None):

if name is None:<EOL><INDENT>name = selection.replace('<STR_LIT::>', '<STR_LIT:_>')<EOL><DEDENT>m = self.RESIDUE.match(selection)<EOL>if not m:<EOL><INDENT>raise ValueError("<STR_LIT>".format(**vars()))<EOL><DEDENT>gmx_resid = self.gmx_resid(int(m.group('<STR_LIT>')))<EOL>residue = m.group('<STR_LIT>')<EOL>if len(residue) == <NUM_LIT:1>:<EOL><INDENT>gmx_resname = utilities.convert_aa_code(residue) <EOL><DEDENT>else:<EOL><INDENT>gmx_resname = residue                            <EOL><DEDENT>gmx_atomname = m.group('<STR_LIT>')<EOL>if gmx_atomname is None:<EOL><INDENT>gmx_atomname = '<STR_LIT>'<EOL><DEDENT>_selection = '<STR_LIT>'.format(**vars())<EOL>cmd = ['<STR_LIT>', '<STR_LIT>',<EOL>_selection,<EOL>'<STR_LIT>'.format(**vars()),<EOL>'<STR_LIT:q>']<EOL>fd, ndx = tempfile.mkstemp(suffix='<STR_LIT>', prefix=name+'<STR_LIT>')<EOL>rc,out,err = self.make_ndx(n=self.ndx, o=ndx, input=cmd)<EOL>self.check_output(out, "<STR_LIT>"<EOL>"<STR_LIT>" % vars())<EOL>return name, ndx<EOL>

Process residue/atom selection and return name and temp index file.


def keep_protein_only(self, os=None, o=None, on=None, compact=False,<EOL>groupname="<STR_LIT>", **kwargs):

force = kwargs.pop('<STR_LIT>', self.force)<EOL>suffix = '<STR_LIT>'<EOL>newtpr = self.outfile(self.infix_filename(os, self.tpr, '<STR_LIT:_>'+suffix))<EOL>newxtc = self.outfile(self.infix_filename(o, self.xtc, '<STR_LIT:_>'+suffix))<EOL>newndx = self.outfile(self.infix_filename(on, self.tpr, '<STR_LIT:_>'+suffix, '<STR_LIT>'))<EOL>selection_ndx = suffix+"<STR_LIT>"    <EOL>if compact:<EOL><INDENT>TRJCONV = trj_compact<EOL>_input = kwargs.get('<STR_LIT:input>', ['<STR_LIT>'])<EOL>kwargs['<STR_LIT:input>'] = [_input[<NUM_LIT:0>], groupname]  <EOL>del _input<EOL><DEDENT>else:<EOL><INDENT>TRJCONV = gromacs.trjconv<EOL>kwargs['<STR_LIT:input>'] = [groupname]<EOL><DEDENT>selections = ['<STR_LIT:@>'+sel for sel in ['<STR_LIT>'] + kwargs.pop('<STR_LIT>',[])]<EOL>with utilities.in_dir(self.dirname):<EOL><INDENT>if not self.check_file_exists(newxtc, resolve="<STR_LIT>", force=force):<EOL><INDENT>B = IndexBuilder(struct=self.tpr, selections=selections,<EOL>ndx=self.ndx, out_ndx=selection_ndx)<EOL>B.combine(name_all=groupname, operation="<STR_LIT:|>", defaultgroups=True)<EOL>logger.info("<STR_LIT>".format(**vars()))<EOL>gromacs.tpbconv(s=self.tpr, o=newtpr, n=selection_ndx, input=[groupname])<EOL>logger.info("<STR_LIT>".format(**vars()))<EOL>gromacs.make_ndx(f=newtpr, o=newndx, input=['<STR_LIT:q>'], stderr=False, stdout=False)<EOL>logger.info("<STR_LIT>".format(**vars()))<EOL>kwargs['<STR_LIT:s>'] = self.tpr<EOL>kwargs['<STR_LIT:f>'] = self.xtc<EOL>kwargs['<STR_LIT:n>'] = selection_ndx<EOL>kwargs['<STR_LIT:o>'] = newxtc<EOL>TRJCONV(**kwargs)<EOL>logger.info("<STR_LIT>")<EOL>for ext in '<STR_LIT>', '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>kwargs['<STR_LIT:o>'] = self.filename(newtpr, ext=ext)<EOL>TRJCONV(dump=<NUM_LIT:0>, stdout=False, stderr=False, **kwargs)  <EOL><DEDENT>except:<EOL><INDENT>logger.exception("<STR_LIT>"<EOL>"<STR_LIT>" % vars())<EOL><DEDENT><DEDENT><DEDENT>logger.info("<STR_LIT>")<EOL><DEDENT>self.proteinonly[self.rp(newxtc)] = Transformer(dirname=self.dirname, s=newtpr,<EOL>f=newxtc, n=newndx, force=force)<EOL>return {'<STR_LIT>':self.rp(newtpr), '<STR_LIT>':self.rp(newxtc), '<STR_LIT>':self.rp(newndx)}<EOL>

Write xtc and tpr only containing the protein.

        :Keywords:
           *os*
              Name of the output tpr file; by default use the original but
              insert "proteinonly" before suffix.
           *o*
              Name of the output trajectory; by default use the original name but
              insert "proteinonly" before suffix.
           *on*
              Name of a new index file.
           *compact*
              ``True``: write a compact and centered trajectory
              ``False``: use trajectory as it is [``False``]
           *groupname*
              Name of the protein-only group.
           *keepalso*
              List of literal make_ndx selections of additional groups that should
              be kept, e.g. ['resname DRUG', 'atom 6789'].
           *force* : Boolean
             - ``True``: overwrite existing trajectories
             - ``False``: throw a IOError exception
             - ``None``: skip existing and log a warning [default]
           *kwargs*
              are passed on to :func:`gromacs.cbook.trj_compact` (unless the
              values have to be set to certain values such as s, f, n, o
              keywords). The *input* keyword is always mangled: Only the first
              entry (the group to centre the trajectory on) is kept, and as a
              second group (the output group) *groupname* is used.

        :Returns:
              dictionary with keys *tpr*, *xtc*, *ndx* which are the names of the
              the new files

        .. warning:: The input tpr file should *not* have *any position restraints*;
                     otherwise Gromacs will throw a hissy-fit and say

                     *Software inconsistency error: Position restraint coordinates are
                     missing*

                     (This appears to be a bug in Gromacs 4.x.)


if out_ndx is None:<EOL><INDENT>out_ndx = self.output<EOL><DEDENT>self.make_ndx(o=out_ndx, input=['<STR_LIT:q>'])<EOL>return out_ndx<EOL>

Concatenate input index files.

        Generate a new index file that contains the default Gromacs index
        groups (if a structure file was defined) and all index groups from the
        input index files.

        :Arguments:
           out_ndx : filename
              Name of the output index file; if ``None`` then use the default
              provided to the constructore. [``None``].


grompp_options = ('<STR_LIT:f>','<STR_LIT>','<STR_LIT:c>','<STR_LIT:r>','<STR_LIT:rb>','<STR_LIT:n>','<STR_LIT:p>','<STR_LIT>','<STR_LIT:o>','<STR_LIT:t>','<STR_LIT:e>',  <EOL>'<STR_LIT:h>', '<STR_LIT>', '<STR_LIT:version>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:v>', '<STR_LIT>',<EOL>'<STR_LIT:time>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>')<EOL>grompp = dict((k,v) for k,v in kwargs.items() if k in grompp_options)<EOL>other =  dict((k,v) for k,v in kwargs.items() if k not in grompp_options)<EOL>return grompp, other<EOL>

Returns one dictionary only containing valid :program:`grompp` options and everything else.

    Option list is hard coded and nased on :class:`~gromacs.tools.grompp` 4.5.3.

    :Returns: ``(grompp_dict, other_dict)``

    .. versionadded:: 0.2.4


def edit_mdp(mdp, new_mdp=None, extend_parameters=None, **substitutions):

if new_mdp is None:<EOL><INDENT>new_mdp = mdp<EOL><DEDENT>if extend_parameters is None:<EOL><INDENT>extend_parameters = ['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>extend_parameters = list(asiterable(extend_parameters))<EOL><DEDENT>substitutions = {k: v for k,v in substitutions.items() if v is not None}<EOL>params = list(substitutions.keys())   <EOL>def demangled(p):<EOL><INDENT>"""<STR_LIT>"""<EOL>return p.replace('<STR_LIT:_>', '<STR_LIT>')  <EOL><DEDENT>patterns = {parameter:<EOL>re.compile("""<STR_LIT>""".format(demangled(parameter)), re.VERBOSE)<EOL>for parameter in substitutions}<EOL>with tempfile.TemporaryFile() as target:<EOL><INDENT>with open(mdp, '<STR_LIT:rb>') as src:<EOL><INDENT>logger.info("<STR_LIT>".format(mdp, substitutions.keys()))<EOL>for line in src:<EOL><INDENT>line = line.decode('<STR_LIT:utf-8>')<EOL>new_line = line.strip()  <EOL>for p in params[:]:<EOL><INDENT>m = patterns[p].match(new_line)<EOL>if m:<EOL><INDENT>if m.group('<STR_LIT>') is None:<EOL><INDENT>comment = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>comment = "<STR_LIT:U+0020>"+m.group('<STR_LIT>')<EOL><DEDENT>assignment = m.group('<STR_LIT>')<EOL>if not assignment.endswith('<STR_LIT:U+0020>'):<EOL><INDENT>assignment += '<STR_LIT:U+0020>'<EOL><DEDENT>new_line = assignment<EOL>if p in extend_parameters:<EOL><INDENT>new_line += str(m.group('<STR_LIT:value>')) + '<STR_LIT:U+0020>'<EOL><DEDENT>value = "<STR_LIT:U+0020>".join(map(str, asiterable(substitutions[p])))<EOL>new_line += value + comment<EOL>params.remove(p)<EOL>break<EOL><DEDENT><DEDENT>target.write((new_line+'<STR_LIT:\n>').encode('<STR_LIT:utf-8>'))<EOL><DEDENT><DEDENT>target.seek(<NUM_LIT:0>)<EOL>with open(new_mdp, '<STR_LIT:wb>') as final:<EOL><INDENT>shutil.copyfileobj(target, final)<EOL><DEDENT><DEDENT>if len(params) > <NUM_LIT:0>:<EOL><INDENT>logger.warn("<STR_LIT>".format(**vars()))<EOL><DEDENT>return {p: substitutions[p] for p in params}<EOL>

Change values in a Gromacs mdp file.

    Parameters and values are supplied as substitutions, eg ``nsteps=1000``.

    By default the template mdp file is **overwritten in place**.

    If a parameter does not exist in the template then it cannot be substituted
    and the parameter/value pair is returned. The user has to check the
    returned list in order to make sure that everything worked as expected. At
    the moment it is not possible to automatically append the new values to the
    mdp file because of ambiguities when having to replace dashes in parameter
    names with underscores (see the notes below on dashes/underscores).

    If a parameter is set to the value ``None`` then it will be ignored.

    :Arguments:
        *mdp* : filename
            filename of input (and output filename of ``new_mdp=None``)
        *new_mdp* : filename
            filename of alternative output mdp file [None]
        *extend_parameters* : string or list of strings
            single parameter or list of parameters for which the new values
            should be appended to the existing value in the mdp file. This
            makes mostly sense for a single parameter, namely 'include', which
            is set as the default. Set to ``[]`` to disable. ['include']
        *substitutions*
            parameter=value pairs, where parameter is defined by the Gromacs
            mdp file; dashes in parameter names have to be replaced by
            underscores. If a value is a list-like object then the items are
            written as a sequence, joined with spaces, e.g. ::

               ref_t=[310,310,310] --->  ref_t = 310 310 310

    :Returns:
        Dict of parameters that have *not* been substituted.

    **Example** ::

       edit_mdp('md.mdp', new_mdp='long_md.mdp', nsteps=100000, nstxtcout=1000, lincs_iter=2)

    .. Note::

       * Dashes in Gromacs mdp parameters have to be replaced by an underscore
         when supplied as python keyword arguments (a limitation of python). For example
         the MDP syntax is  ``lincs-iter = 4`` but the corresponding  keyword would be
         ``lincs_iter = 4``.
       * If the keyword is set as a dict key, eg ``mdp_params['lincs-iter']=4`` then one
         does not have to substitute.
       * Parameters *aa_bb* and *aa-bb* are considered the same (although this should
         not be a problem in practice because there are no mdp parameters that only
         differ by a underscore).
       * This code is more compact in ``Perl`` as one can use ``s///`` operators:
         ``s/^(\s*${key}\s*=\s*).*/$1${val}/``

    .. SeeAlso:: One can also load the mdp file with
                :class:`gromacs.formats.MDP`, edit the object (a dict), and save it again.


def combine(self, name_all=None, out_ndx=None, operation='<STR_LIT:|>', defaultgroups=False):

if not operation in ('<STR_LIT:|>', '<STR_LIT:&>', False):<EOL><INDENT>raise ValueError("<STR_LIT>".format(<EOL>operation))<EOL><DEDENT>if name_all is None and operation:<EOL><INDENT>name_all = self.name_all or operation.join(self.indexfiles)<EOL><DEDENT>if out_ndx is None:<EOL><INDENT>out_ndx = self.output<EOL><DEDENT>if defaultgroups:<EOL><INDENT>fd, default_ndx = tempfile.mkstemp(suffix='<STR_LIT>', prefix='<STR_LIT>')<EOL>try:<EOL><INDENT>self.make_ndx(o=default_ndx, input=['<STR_LIT:q>'])<EOL><DEDENT>except:<EOL><INDENT>utilities.unlink_gmx(default_ndx)<EOL>raise<EOL><DEDENT>ndxfiles = [default_ndx]<EOL><DEDENT>else:<EOL><INDENT>ndxfiles = []<EOL><DEDENT>ndxfiles.extend(self.indexfiles.values())<EOL>if operation:<EOL><INDENT>try:<EOL><INDENT>fd, tmp_ndx = tempfile.mkstemp(suffix='<STR_LIT>', prefix='<STR_LIT>')<EOL>operation = '<STR_LIT:U+0020>'+operation.strip()+'<STR_LIT:U+0020>'<EOL>cmd = [operation.join(['<STR_LIT>'.format(gname) for gname in self.indexfiles]),<EOL>'<STR_LIT>', '<STR_LIT:q>']<EOL>rc,out,err = self.make_ndx(n=ndxfiles, o=tmp_ndx, input=cmd)<EOL>if self._is_empty_group(out):<EOL><INDENT>warnings.warn("<STR_LIT>".format(**vars()),<EOL>category=BadParameterWarning)<EOL><DEDENT>groups = parse_ndxlist(out)<EOL>last = groups[-<NUM_LIT:1>]<EOL>name_cmd = ["<STR_LIT>".format(last['<STR_LIT>'], name_all), '<STR_LIT:q>']<EOL>rc,out,err = self.make_ndx(n=tmp_ndx, o=out_ndx, input=name_cmd)<EOL><DEDENT>finally:<EOL><INDENT>utilities.unlink_gmx(tmp_ndx)<EOL>if defaultgroups:<EOL><INDENT>utilities.unlink_gmx(default_ndx)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>rc,out,err = self.make_ndx(n=ndxfiles, o=out_ndx, input=['<STR_LIT>','<STR_LIT:q>'])<EOL><DEDENT>return name_all, out_ndx<EOL>

Combine individual groups into a single one and write output.

        :Keywords:
           name_all : string
              Name of the combined group, ``None`` generates a name.  [``None``]
           out_ndx : filename
              Name of the output file that will contain the individual groups
              and the combined group. If ``None`` then default from the class
              constructor is used. [``None``]
           operation : character
              Logical operation that is used to generate the combined group from
              the individual groups: "|" (OR) or "&" (AND); if set to ``False``
              then no combined group is created and only the individual groups
              are written. ["|"]
           defaultgroups : bool
              ``True``: append everything to the default groups produced by
              :program:`make_ndx` (or rather, the groups provided in the ndx file on
              initialization --- if this was ``None`` then these are truly default groups);
              ``False``: only use the generated groups

        :Returns:
           ``(combinedgroup_name, output_ndx)``, a tuple showing the
           actual group name and the name of the file; useful when all names are autogenerated.

        .. Warning:: The order of the atom numbers in the combined group is
                     *not* guaranteed to be the same as the selections on input because
                     ``make_ndx`` sorts them ascending. Thus you should be careful when
                     using these index files for calculations of angles and dihedrals.
                     Use :class:`gromacs.formats.NDX` in these cases.

        .. SeeAlso:: :meth:`IndexBuilder.write`.


m = NDXLIST.search(output)    <EOL>grouplist = m.group('<STR_LIT>')<EOL>return parse_groups(grouplist)<EOL>

Parse output from make_ndx to build list of index groups::

      groups = parse_ndxlist(output)

    output should be the standard output from ``make_ndx``, e.g.::

       rc,output,junk = gromacs.make_ndx(..., input=('', 'q'), stdout=False, stderr=True)

    (or simply use

       rc,output,junk = cbook.make_ndx_captured(...)

    which presets input, stdout and stderr; of course input can be overriden.)

    :Returns:
       The function returns a list of dicts (``groups``) with fields

       name
           name of the groups
       nr
           number of the group (starts at 0)
       natoms
           number of atoms in the group


fd, tmp_ndx = tempfile.mkstemp(suffix='<STR_LIT>')<EOL>kwargs['<STR_LIT:o>'] = tmp_ndx<EOL>try:<EOL><INDENT>g = parse_ndxlist(make_ndx_captured(n=ndx, **kwargs)[<NUM_LIT:1>])<EOL><DEDENT>finally:<EOL><INDENT>utilities.unlink_gmx(tmp_ndx)<EOL><DEDENT>return g<EOL>

Return a list of index groups in the index file *ndx*.

    :Arguments:
        - *ndx*  is a Gromacs index file.
        - kwargs are passed to :func:`make_ndx_captured`.

    :Returns:
        list of groups as supplied by :func:`parse_ndxlist`

    Alternatively, load the index file with
    :class:`gromacs.formats.NDX` for full control.


<EOL>return os.path.join(os.path.dirname(args[<NUM_LIT:0>]), *args[<NUM_LIT:1>:])<EOL>


kwargs['<STR_LIT>']=False   <EOL>user_input = kwargs.pop('<STR_LIT:input>',[])<EOL>user_input = [cmd for cmd in user_input if cmd != '<STR_LIT:q>']  <EOL>kwargs['<STR_LIT:input>'] = user_input + ['<STR_LIT>', '<STR_LIT:q>']                <EOL>return gromacs.make_ndx(**kwargs)<EOL>

make_ndx that captures all output

    Standard :func:`~gromacs.make_ndx` command with the input and
    output pre-set in such a way that it can be conveniently used for
    :func:`parse_ndxlist`.

    Example::
      ndx_groups = parse_ndxlist(make_ndx_captured(n=ndx)[0])

    Note that the convenient :func:`get_ndx_groups` function does exactly
    that and can probably used in most cases.

    :Arguments:
        keywords are passed on to :func:`~gromacs.make_ndx`
    :Returns:
        (*returncode*, *output*, ``None``)


def __init__(self, struct=None, selections=None, names=None, name_all=None,<EOL>ndx=None, out_ndx="<STR_LIT>", offset=<NUM_LIT:0>):

self.structure = struct<EOL>self.ndx = ndx<EOL>self.output = out_ndx<EOL>self.name_all = name_all<EOL>self.offset = offset<EOL>self._command_counter = <NUM_LIT:0><EOL>if selections is None:<EOL><INDENT>selections = []<EOL><DEDENT>if not utilities.iterable(selections):<EOL><INDENT>selections = [selections]<EOL><DEDENT>self.selections = selections<EOL>if names is None:<EOL><INDENT>names = [None] * len(selections)<EOL><DEDENT>self.make_ndx = tools.Make_ndx(f=self.structure, n=self.ndx,<EOL>stdout=False, stderr=False)<EOL>self.indexfiles = dict([self.parse_selection(selection, name)<EOL>for selection, name in zip(selections, names)])<EOL>

Build a index group from the selection arguments.

        If selections and a structure file are supplied then the individual
        selections are constructed with separate calls to
        :func:`gromacs.make_ndx`. Use :meth:`IndexBuilder.combine` to combine
        them into a joint selection or :meth:`IndexBuilder.write` to simply write
        out the individual named selections (useful with *names*).

        :Arguments:

           *struct* : filename
              Structure file (tpr, pdb, ...)

           *selections* : list
              The list must contain strings or tuples, which must be be one of
              the following constructs:

                 "<1-letter aa code><resid>[:<atom name]"

                     Selects the CA of the residue or the specified atom
                     name.

                     example: ``"S312:OA"`` or ``"A22"`` (equivalent to ``"A22:CA"``)

                 ("<1-letter aa code><resid>", "<1-letter aa code><resid>, ["<atom name>"])

                    Selects a *range* of residues. If only two residue
                    identifiers are provided then all atoms are
                    selected. With an optional third atom identifier,
                    only this atom anme is selected for each residue
                    in the range. [EXPERIMENTAL]

                 "@<make_ndx selection>"

                     The ``@`` letter introduces a verbatim ``make_ndx``
                     command. It will apply the given selection without any
                     further processing or checks.

                     example: ``"@a 6234 - 6238"`` or ``'@"SOL"'`` (note the quoting)
                     or ``"@r SER & r 312 & t OA"``.

           *names* : list
              Strings to name the selections; if not supplied or if individuals
              are ``None`` then a default name is created. When simply using
              :meth:`IndexBuilder.write` then these should be supplied.

           *name_all* : string
              Name of the group that is generated by :meth:`IndexBuilder.combine`.

           *offset* : int, dict
              This number is added to the resids in the first selection scheme; this
              allows names to be the same as in a crystal structure. If offset is a
              dict then it is used to directly look up the resids.

           *ndx* : filename or list of filenames
              Optional input index file(s).

           *out_ndx* : filename
              Output index file.


def _translate_residue(self, selection, default_atomname='<STR_LIT>'):

m = self.RESIDUE.match(selection)<EOL>if not m:<EOL><INDENT>errmsg = "<STR_LIT>".format(**vars())<EOL>logger.error(errmsg)<EOL>raise ValueError(errmsg)<EOL><DEDENT>gmx_resid = self.gmx_resid(int(m.group('<STR_LIT>')))    <EOL>residue = m.group('<STR_LIT>')<EOL>if len(residue) == <NUM_LIT:1>:<EOL><INDENT>gmx_resname = utilities.convert_aa_code(residue) <EOL><DEDENT>else:<EOL><INDENT>gmx_resname = residue                            <EOL><DEDENT>gmx_atomname = m.group('<STR_LIT>')<EOL>if gmx_atomname is None:<EOL><INDENT>gmx_atomname = default_atomname<EOL><DEDENT>return {'<STR_LIT>':gmx_resname, '<STR_LIT>':gmx_resid, '<STR_LIT>':gmx_atomname}<EOL>

Translate selection for a single res to make_ndx syntax.


def create_portable_topology(topol, struct, **kwargs):

_topoldir, _topol = os.path.split(topol)<EOL>processed = kwargs.pop('<STR_LIT>', os.path.join(_topoldir, '<STR_LIT>'+_topol))<EOL>grompp_kwargs, mdp_kwargs = filter_grompp_options(**kwargs)<EOL>mdp_kwargs = add_mdp_includes(topol, mdp_kwargs)<EOL>with tempfile.NamedTemporaryFile(suffix='<STR_LIT>') as mdp:<EOL><INDENT>mdp.write('<STR_LIT>'.format(**mdp_kwargs))<EOL>mdp.flush()<EOL>grompp_kwargs['<STR_LIT:p>'] = topol<EOL>grompp_kwargs['<STR_LIT>'] = processed<EOL>grompp_kwargs['<STR_LIT:f>'] =  mdp.name<EOL>grompp_kwargs['<STR_LIT:c>'] = struct<EOL>grompp_kwargs['<STR_LIT:v>'] = False<EOL>try:<EOL><INDENT>gromacs.grompp(**grompp_kwargs)<EOL><DEDENT>finally:<EOL><INDENT>utilities.unlink_gmx('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT><DEDENT>return utilities.realpath(processed)<EOL>

Create a processed topology.

    The processed (or portable) topology file does not contain any
    ``#include`` statements and hence can be easily copied around. It
    also makes it possible to re-grompp without having any special itp
    files available.

    :Arguments:
      *topol*
          topology file
      *struct*
          coordinat (structure) file

    :Keywords:
      *processed*
          name of the new topology file; if not set then it is named like
          *topol* but with ``pp_`` prepended
      *includes*
          path or list of paths of directories in which itp files are
          searched for
      *grompp_kwargs**
          other options for :program:`grompp` such as ``maxwarn=2`` can
          also be supplied

    :Returns: full path to the processed topology


def parse_selection(self, selection, name=None):

if type(selection) is tuple:<EOL><INDENT>process = self._process_range<EOL><DEDENT>elif selection.startswith('<STR_LIT:@>'):<EOL><INDENT>process = self._process_command<EOL>selection = selection[<NUM_LIT:1>:]<EOL><DEDENT>else:<EOL><INDENT>process = self._process_residue<EOL><DEDENT>return process(selection, name)<EOL>

Retuns (groupname, filename) with index group.


<EOL>self.extractor.run()<EOL>

Extract frames from the trajectory to the temporary directory.


return glob.glob(self.frameglob)<EOL>

Unordered list of all frames currently held on disk.


try:<EOL><INDENT>p = os.path.join(*args)<EOL>if os.path.isabs(p):<EOL><INDENT>return p<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT>return utilities.realpath(self.dirname, *args)<EOL>

Return canonical path to file under *dirname* with components *args*

         If *args* form an absolute path then just return it as the absolute path.


def __init__(self, s="<STR_LIT>", f="<STR_LIT>", n=None, force=None,<EOL>dirname=os.path.curdir, outdir=None):

self.tpr = self.filename(s, ext="<STR_LIT>", use_my_ext=True)<EOL>self.xtc = self.filename(f, ext="<STR_LIT>", use_my_ext=True)<EOL>self.ndx = n<EOL>self.dirname = dirname<EOL>self.outdir = utilities.realpath(outdir) if outdir is not None else None<EOL>self.force = force<EOL>self.nowater = {}     <EOL>self.proteinonly = {} <EOL>with utilities.in_dir(self.dirname, create=False):<EOL><INDENT>for f in (self.tpr, self.xtc, self.ndx):<EOL><INDENT>if f is None:<EOL><INDENT>continue<EOL><DEDENT>if not os.path.exists(f):<EOL><INDENT>msg = "<STR_LIT>".format(**vars())<EOL>warnings.warn(msg, category=MissingDataWarning)<EOL>logger.warn(msg)<EOL><DEDENT><DEDENT><DEDENT>logger.info("<STR_LIT>", self)<EOL>

Set up Transformer with structure and trajectory.

        Supply *n* = tpr, *f* = xtc (and *n* = ndx) relative to dirname.

        :Keywords:
           *s*
              tpr file (or similar); note that this should not contain
              position restraints if it is to be used with a reduced
              system (see :meth:`~Transformer.strip_water`)
           *f*
              trajectory (xtc, trr, ...)
           *n*
              index file (it is typically safe to leave this as ``None``; in
              cases where a trajectory needs to be centered on non-standard
              groups this should contain those groups)
           *force*
              Set the default behaviour for handling existing files:
                - ``True``: overwrite existing trajectories
                - ``False``: throw a IOError exception
                - ``None``: skip existing and log a warning [default]
           *dirname*
              directory in which all operations are performed, relative paths
              are interpreted relative to *dirname* [.]
           *outdir*
              directory under which output files are placed; by default
              the same directory where the input files live


newargs = self._combineargs(*args, **kwargs)<EOL>return self._build_arg_list(**newargs)<EOL>

Combine arguments and turn them into gromacs tool arguments.


def _commandline(self, *args, **kwargs):

<EOL>return [self.command_name] + self.transform_args(*args, **kwargs)<EOL>

Returns the command line (without pipes) as a list.


def _run_command(self, *args, **kwargs):

<EOL>use_input = kwargs.pop('<STR_LIT>', True)<EOL>capturefile = None<EOL>if environment.flags['<STR_LIT>'] is True:<EOL><INDENT>kwargs.setdefault('<STR_LIT>', PIPE)<EOL>kwargs.setdefault('<STR_LIT>', PIPE)<EOL><DEDENT>elif environment.flags['<STR_LIT>'] == "<STR_LIT:file>":<EOL><INDENT>if '<STR_LIT>' in kwargs and '<STR_LIT>' in kwargs:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>fn = environment.flags['<STR_LIT>']<EOL>capturefile = file(fn, "<STR_LIT:w>")   <EOL>if '<STR_LIT>' in kwargs and '<STR_LIT>' not in kwargs:<EOL><INDENT>kwargs.setdefault('<STR_LIT>', capturefile)<EOL><DEDENT>else:<EOL><INDENT>kwargs.setdefault('<STR_LIT>', STDOUT)<EOL>kwargs.setdefault('<STR_LIT>', capturefile)<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>p = self.Popen(*args, **kwargs)<EOL>out, err = p.communicate(use_input=use_input) <EOL><DEDENT>except:<EOL><INDENT>if capturefile is not None:<EOL><INDENT>logger.error("<STR_LIT>", capturefile)<EOL><DEDENT>raise<EOL><DEDENT>finally:<EOL><INDENT>if capturefile is not None:<EOL><INDENT>capturefile.close()<EOL><DEDENT><DEDENT>rc = p.returncode<EOL>return (rc, out, err), p<EOL>

Execute the command; see the docs for __call__.

        :Returns: a tuple of the *results* tuple ``(rc, stdout, stderr)`` and
                  the :class:`Popen` instance.


if use_input:<EOL><INDENT>return super(PopenWithInput, self).communicate(self.input)<EOL><DEDENT>else:<EOL><INDENT>return super(PopenWithInput, self).communicate()<EOL><DEDENT>

Run the command, using the input that was set up on __init__ (for *use_input* = ``True``)


self.args = args<EOL>self.kwargs = kwargs<EOL>

Set up the command class.

        The arguments can always be provided as standard positional
        arguments such as

          ``"-c", "config.conf", "-o", "output.dat", "--repeats=3", "-v", "input.dat"``

        In addition one can also use keyword arguments such as

          ``c="config.conf", o="output.dat", repeats=3, v=True``

        These are automatically transformed appropriately according to
        simple rules:

        * Any single-character keywords are assumed to be POSIX-style
          options and will be prefixed with a single dash and the value
          separated by a space.

        * Any other keyword is assumed to be a GNU-style long option
          and thus will be prefixed with two dashes and the value will
          be joined directly with an equals sign and no space.

        If this does not work (as for instance for the options of the
        UNIX ``find`` command) then provide options and values in the
        sequence of positional arguments.

        *Example*

        Create a ``Ls`` class whose instances execute the ``ls`` command::

          LS = type("LS", (gromacs.core.Command,), {'command_name': 'ls'})
          ls = LS()
          ls()        # lists directory like ls
          ls(l=True)  # lists directory like ls -l

        Now create an instance that performs a long directory listing by
        default::

          lslong = LS(l=True)
          lslong()    # like ls -l


ndxs = []<EOL>struct = None<EOL>for fname in args:<EOL><INDENT>if fname.endswith('<STR_LIT>'):<EOL><INDENT>ndxs.append(fname)<EOL><DEDENT>else:<EOL><INDENT>if struct is not None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>struct = fname<EOL><DEDENT><DEDENT>fd, multi_ndx = tempfile.mkstemp(suffix='<STR_LIT>', prefix='<STR_LIT>')<EOL>os.close(fd)<EOL>atexit.register(os.unlink, multi_ndx)<EOL>if struct:<EOL><INDENT>make_ndx = registry['<STR_LIT>'](f=struct, n=ndxs, o=multi_ndx)<EOL><DEDENT>else:<EOL><INDENT>make_ndx = registry['<STR_LIT>'](n=ndxs, o=multi_ndx)<EOL><DEDENT>_, _, _ = make_ndx(input=['<STR_LIT:q>'], stdout=False, stderr=False)<EOL>return multi_ndx<EOL>

Takes one or more index files and optionally one structure file and
    returns a path for a new merged index file.

    :param args: index files and zero or one structure file
    :return: path for the new merged index file


return name.replace('<STR_LIT:->', '<STR_LIT:_>').capitalize()<EOL>

Turns tool names into valid identifiers.

    :param name: tool name
    :return: valid identifier


for path in args:<EOL><INDENT>dirname, filename = os.path.split(path)<EOL>fbaks = glob.glob(os.path.join(dirname, '<STR_LIT:#>'+filename+'<STR_LIT>'))<EOL>for bak in fbaks:<EOL><INDENT>unlink_f(bak)<EOL><DEDENT><DEDENT>

Unlink (rm) all backup files corresponding to the listed files.


signature_methods = ("<STR_LIT>",)<EOL>alternative_methods = (<EOL>("<STR_LIT>", "<STR_LIT>", "<STR_LIT>"),<EOL>("<STR_LIT>", "<STR_LIT>", "<STR_LIT>"))<EOL>for m in signature_methods:<EOL><INDENT>if not hasmethod(obj, m):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>alternative_results = [<EOL>numpy.all([hasmethod(obj, m) for m in alternatives])<EOL>for alternatives in alternative_methods]<EOL>return numpy.any(alternative_results)<EOL>

Detect if `obj` is a stream.

    We consider anything a stream that has the methods

    - ``close()``

    and either set of the following

    - ``read()``, ``readline()``, ``readlines()``
    - ``write()``, ``writeline()``, ``writelines()``

    :Arguments:
      *obj*
          stream or str

    :Returns:
      *bool*, ``True`` if `obj` is a stream, ``False`` otherwise

    .. SeeAlso::
       :mod:`io`

    .. versionadded:: 0.7.1


def _init_filename(self, filename=None, ext=None):

extension = ext or self.default_extension<EOL>filename = self.filename(filename, ext=extension, use_my_ext=True, set_default=True)<EOL>self.real_filename = os.path.realpath(filename)<EOL>

Initialize the current filename :attr:`FileUtils.real_filename` of the object.

        Bit of a hack.

        - The first invocation must have ``filename != None``; this will set a
          default filename with suffix :attr:`FileUtils.default_extension`
          unless another one was supplied.

        - Subsequent invocations either change the filename accordingly or
          ensure that the default filename is set with the proper suffix.


<EOL>from pylab import gcf, axes<EOL>numPlot -= <NUM_LIT:1>  <EOL>return axes(gcf().get_axes()[numPlot])<EOL>

Make subplot *numPlot* active on the canvas.

    Use this if a simple ``subplot(numRows, numCols, numPlot)``
    overwrites the subplot instead of activating it.


if None in args:<EOL><INDENT>return None<EOL><DEDENT>return os.path.realpath(<EOL>os.path.expandvars(os.path.expanduser(os.path.join(*args))))<EOL>

Join all args and return the real path, rooted at /.

    Expands ``~`` and environment variables such as :envvar:`$HOME`.

    Returns ``None`` if any of the args is none.


for path in args:<EOL><INDENT>unlink_f(path)<EOL><DEDENT>unlink_gmx_backups(*args)<EOL>

Unlink (remove) Gromacs file(s) and all corresponding backups.


if len(x) == <NUM_LIT:1>:<EOL><INDENT>return amino_acid_codes[x.upper()]<EOL><DEDENT>elif len(x) == <NUM_LIT:3>:<EOL><INDENT>return inverse_aa_codes[x.upper()]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % x)<EOL><DEDENT>

Converts between 3-letter and 1-letter amino acid codes.


try:<EOL><INDENT>os.makedirs(path)<EOL><DEDENT>except OSError as err:<EOL><INDENT>if err.errno != errno.EEXIST:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>

Create a directory *path* with subdirs but do not complain if it exists.

    This is like GNU ``mkdir -p path``.


from pylab import gca, draw<EOL>if ax is None:<EOL><INDENT>ax = gca()<EOL><DEDENT>ax.legend_ = None<EOL>draw()<EOL>

Remove legend for axes or gca.

    See http://osdir.com/ml/python.matplotlib.general/2005-07/msg00285.html


for root, dirs, files in os.walk(directory):<EOL><INDENT>for basename in files:<EOL><INDENT>if fnmatch.fnmatch(basename, pattern):<EOL><INDENT>filename = os.path.join(root, basename)<EOL>yield filename<EOL><DEDENT><DEDENT><DEDENT>

Find files recursively under *directory*, matching *pattern* (generator).

    *pattern* is a UNIX-style glob pattern as used ny :func:`fnmatch.fnmatch`.

    Recipe by Bruno Oliveira from
    http://stackoverflow.com/questions/2186525/use-a-glob-to-find-files-recursively-in-python


def check_file_exists(self, filename, resolve='<STR_LIT>', force=None):

def _warn(x):<EOL><INDENT>msg = "<STR_LIT>".format(x)<EOL>logger.warn(msg)<EOL>warnings.warn(msg)<EOL>return True<EOL><DEDENT>def _raise(x):<EOL><INDENT>msg = "<STR_LIT>".format(x)<EOL>logger.error(msg)<EOL>raise IOError(errno.EEXIST, x, msg)<EOL><DEDENT>solutions = {'<STR_LIT:ignore>': lambda x: False,      <EOL>'<STR_LIT>': lambda x: True,     <EOL>'<STR_LIT>': _warn,<EOL>'<STR_LIT>': _warn,<EOL>'<STR_LIT>': _raise,<EOL>'<STR_LIT>': _raise,<EOL>}<EOL>if force is True:<EOL><INDENT>resolve = '<STR_LIT:ignore>'<EOL><DEDENT>elif force is False:<EOL><INDENT>resolve = '<STR_LIT>'<EOL><DEDENT>if not os.path.isfile(filename):<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>return solutions[resolve](filename)<EOL><DEDENT>

If a file exists then continue with the action specified in ``resolve``.

        ``resolve`` must be one of

        "ignore"
              always return ``False``
        "indicate"
              return ``True`` if it exists
        "warn"
              indicate and issue a :exc:`UserWarning`
        "exception"
              raise :exc:`IOError` if it exists

        Alternatively, set *force* for the following behaviour (which
        ignores *resolve*):

        ``True``
              same as *resolve* = "ignore" (will allow overwriting of files)
        ``False``
              same as *resolve* = "exception" (will prevent overwriting of files)
        ``None``
              ignored, do whatever *resolve* says


@contextmanager<EOL>def openany(datasource, mode='<STR_LIT>', reset=True):

stream = anyopen(datasource, mode=mode, reset=reset)<EOL>try:<EOL><INDENT>yield stream<EOL><DEDENT>finally:<EOL><INDENT>stream.close()<EOL><DEDENT>

Context manager for :func:`anyopen`.

    Open the `datasource` and close it when the context of the :keyword:`with`
    statement exits.

    `datasource` can be a filename or a stream (see :func:`isstream`). A stream
    is reset to its start if possible (via :meth:`~io.IOBase.seek` or
    :meth:`~cString.StringIO.reset`).

    The advantage of this function is that very different input sources
    ("streams") can be used for a "file", ranging from files on disk (including
    compressed files) to open file objects to sockets and strings---as long as
    they have a file-like interface.

    :Arguments:
      *datasource*
           a file or a stream
      *mode*
           {'r', 'w'} (optional), open in r(ead) or w(rite) mode
      *reset*
           bool (optional) try to read (`mode` 'r') the stream from the
           start [``True``]

    **Example**

    Open a gzipped file and process it line by line::

        with openany("input.pdb.gz") as pdb:
            for line in pdb:
                if line.startswith('ATOM'):
                    print(line)

    Open a URL and read it::

       import urllib2
       with openany(urllib2.urlopen("https://www.mdanalysis.org/")) as html:
           print(html.read())

    .. SeeAlso::
       :func:`anyopen`


if filename is None:<EOL><INDENT>if not hasattr(self,'<STR_LIT>'):<EOL><INDENT>self._filename = None        <EOL><DEDENT>if self._filename:<EOL><INDENT>filename = self._filename<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>my_ext = None<EOL><DEDENT>else:<EOL><INDENT>filename, my_ext = os.path.splitext(filename)<EOL>if set_default:                  <EOL><INDENT>self._filename = filename<EOL><DEDENT><DEDENT>if my_ext and use_my_ext:<EOL><INDENT>ext = my_ext<EOL><DEDENT>if ext is not None:<EOL><INDENT>if ext.startswith(os.extsep):<EOL><INDENT>ext = ext[<NUM_LIT:1>:]  <EOL><DEDENT>if ext != "<STR_LIT>":<EOL><INDENT>filename = filename + os.extsep + ext<EOL><DEDENT><DEDENT>return filename<EOL>

Supply a file name for the class object.

        Typical uses::

           fn = filename()             ---> <default_filename>
           fn = filename('name.ext')   ---> 'name'
           fn = filename(ext='pickle') ---> <default_filename>'.pickle'
           fn = filename('name.inp','pdf') --> 'name.pdf'
           fn = filename('foo.pdf',ext='png',use_my_ext=True) --> 'foo.pdf'

        The returned filename is stripped of the extension
        (``use_my_ext=False``) and if provided, another extension is
        appended. Chooses a default if no filename is given.

        Raises a ``ValueError`` exception if no default file name is known.

        If ``set_default=True`` then the default filename is also set.

        ``use_my_ext=True`` lets the suffix of a provided filename take
        priority over a default ``ext`` tension.

        .. versionchanged:: 0.3.1
           An empty string as *ext* = "" will suppress appending an extension.


if len(d) > <NUM_LIT:0>:<EOL><INDENT>wmsg = "<STR_LIT>"+str(d)<EOL>logger.warn(wmsg)<EOL>warnings.warn(wmsg, category=UsageWarning)<EOL><DEDENT>return len(d) == <NUM_LIT:0><EOL>

Check if any arguments remain in dict *d*.


vdwradii_dat = os.path.join(outdir, "<STR_LIT>")<EOL>if libdir is not None:<EOL><INDENT>filename = os.path.join(libdir, '<STR_LIT>')  <EOL>if not os.path.exists(filename):<EOL><INDENT>msg = '<STR_LIT>'.format(**vars())<EOL>logger.exception(msg)<EOL>raise OSError(msg, errno.ENOENT)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>filename = os.path.join(os.environ['<STR_LIT>'], '<STR_LIT>')<EOL><DEDENT>except KeyError:<EOL><INDENT>try:<EOL><INDENT>filename = os.path.join(os.environ['<STR_LIT>'], '<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>except KeyError:<EOL><INDENT>msg = "<STR_LIT>"<EOL>logger.exception(msg)<EOL>raise OSError(msg, errno.ENOENT)<EOL><DEDENT><DEDENT><DEDENT>if not os.path.exists(filename):<EOL><INDENT>msg = "<STR_LIT>".format(**vars())<EOL>logger.exception(msg, errno.ENOENT)<EOL>raise OSError(msg)<EOL><DEDENT>patterns = vdw_lipid_resnames + list({x[:<NUM_LIT:3>] for x in vdw_lipid_resnames})<EOL>with open(vdwradii_dat, '<STR_LIT:w>') as outfile:<EOL><INDENT>outfile.write('<STR_LIT>')<EOL>for resname in patterns:<EOL><INDENT>for atom,radius in vdw_lipid_atom_radii.items():<EOL><INDENT>outfile.write('<STR_LIT>'.format(**vars()))<EOL><DEDENT><DEDENT>with open(filename, '<STR_LIT:r>') as infile:<EOL><INDENT>for line in infile:<EOL><INDENT>outfile.write(line)<EOL><DEDENT><DEDENT><DEDENT>logger.debug('<STR_LIT>'.format(**vars()))<EOL>return realpath(vdwradii_dat)<EOL>

Find vdwradii.dat and add special entries for lipids.

    See :data:`gromacs.setup.vdw_lipid_resnames` for lipid
    resnames. Add more if necessary.


self.tx.send = False<EOL>self.__save()<EOL>

save a transaction, but don't let it be picked up by the broadcaster


self.tx.send = True<EOL>self.__save()<EOL>

queue a transaction to be picked up by the background transaction broadcaster


if model._meta.app_label == '<STR_LIT>':<EOL><INDENT>return ark_db['<STR_LIT>']<EOL><DEDENT>return None<EOL>

Attempts to write ark_app models go to ARK_DB_NAME.


def allow_relation(self, obj1, obj2, **hints):

if obj1._meta.app_label == '<STR_LIT>' orobj2._meta.app_label == '<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>return None<EOL>

Allow relations if a model in the ark is involved.


if config is None:<EOL><INDENT>config = get_config_index(config_url)<EOL><DEDENT>if build_file is None:<EOL><INDENT>build_files = get_ci_build_files(config, rosdistro_name)<EOL>build_file = build_files[ci_build_name]<EOL><DEDENT>if build_targets is not None:<EOL><INDENT>build_file.targets = build_targets<EOL><DEDENT>if index is None:<EOL><INDENT>index = get_index(config.rosdistro_index_url)<EOL><DEDENT>if dist_file is None:<EOL><INDENT>dist_file = get_distribution_file(index, rosdistro_name, build_file)<EOL>if not dist_file:<EOL><INDENT>raise JobValidationError(<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if os_name not in build_file.targets.keys():<EOL><INDENT>raise JobValidationError(<EOL>"<STR_LIT>" % os_name +<EOL>'<STR_LIT>' +<EOL>'<STR_LIT:U+002CU+0020>'.join(sorted(build_file.targets.keys())))<EOL><DEDENT>if os_code_name not in build_file.targets[os_name].keys():<EOL><INDENT>raise JobValidationError(<EOL>"<STR_LIT>" % os_code_name +<EOL>'<STR_LIT>' +<EOL>'<STR_LIT:U+002CU+0020>'.join(sorted(build_file.targets[os_name].keys())))<EOL><DEDENT>if arch not in build_file.targets[os_name][os_code_name]:<EOL><INDENT>raise JobValidationError(<EOL>"<STR_LIT>" % arch +<EOL>'<STR_LIT>' % '<STR_LIT:U+002CU+0020>'.join(sorted(<EOL>build_file.targets[os_name][os_code_name])))<EOL><DEDENT>if len(build_file.underlay_from_ci_jobs) > <NUM_LIT:1>:<EOL><INDENT>raise JobValidationError(<EOL>'<STR_LIT>' +<EOL>'<STR_LIT>' % len(build_file.underlay_from_ci_jobs))<EOL><DEDENT>underlay_source_job = None<EOL>if build_file.underlay_from_ci_jobs:<EOL><INDENT>underlay_source_job = get_ci_job_name(<EOL>rosdistro_name, os_name, os_code_name, arch,<EOL>build_file.underlay_from_ci_jobs[<NUM_LIT:0>])<EOL>underlay_source_paths = (underlay_source_paths or []) +['<STR_LIT>']<EOL><DEDENT>if jenkins is None:<EOL><INDENT>from ros_buildfarm.jenkins import connect<EOL>jenkins = connect(config.jenkins_url)<EOL><DEDENT>if views is None:<EOL><INDENT>view_name = get_ci_view_name(rosdistro_name)<EOL>configure_ci_view(jenkins, view_name, dry_run=dry_run)<EOL><DEDENT>job_name = get_ci_job_name(<EOL>rosdistro_name, os_name, os_code_name, arch, ci_build_name)<EOL>job_config = _get_ci_job_config(<EOL>index, rosdistro_name, build_file, os_name,<EOL>os_code_name, arch,<EOL>build_file.repos_files,<EOL>underlay_source_job,<EOL>underlay_source_paths,<EOL>trigger_timer,<EOL>is_disabled=is_disabled)<EOL>if isinstance(jenkins, object) and jenkins is not False:<EOL><INDENT>from ros_buildfarm.jenkins import configure_job<EOL>configure_job(jenkins, job_name, job_config, dry_run=dry_run)<EOL><DEDENT>return job_name, job_config<EOL>

Configure a single Jenkins CI job.

This includes the following steps:
- clone the ros_buildfarm repository
- write the distribution repository keys into files
- invoke the ci/run_ci_job.py script