Package gromacs :: Module utilities
[hide private]
[frames] | no frames]

Module utilities

source code


:mod:`gromacs.utilities` -- Helper functions and classes
========================================================

The module defines some convenience functions and classes that are
used in other modules; they do *not* make use of :mod:`gromacs.tools`
or :mod:`gromacs.cbook` and can be safely imported at any time.


Classes
-------

:class:`FileUtils` provides functions related to filename handling. It
can be used as a base or mixin class. The :class:`gromacs.analysis.Simulation`
class is derived from it.

.. autoclass:: FileUtils
   :members:
.. autoclass:: AttributeDict
.. autoclass:: Timedelta

Functions
---------

Some additional convenience functions that deal with files and
directories:

.. function:: openany(directory[,mode='r'])

   Context manager to open a compressed (bzip2, gzip) or plain file
   (uses :func:`anyopen`).

.. autofunction:: anyopen
.. autofunction:: realpath
.. function:: in_dir(directory[,create=True])

   Context manager to execute a code block in a directory.

   * The *directory* is created if it does not exist (unless
     *create* = ``False`` is set)   
   * At the end or after an exception code always returns to
     the directory that was the current directory before entering
     the block.

.. autofunction:: find_first
.. autofunction:: withextsep

Functions that improve list processing and which do *not* treat
strings as lists:

.. autofunction:: iterable
.. autofunction:: asiterable


Functions that help handling Gromacs files:

.. autofunction:: unlink_f
.. autofunction:: unlink_gmx
.. autofunction:: unlink_gmx_backups
.. autofunction:: number_pdbs

Functions that make working with matplotlib_ easier:

.. _matplotlib: http://matplotlib.sourceforge.net/

.. autofunction:: activate_subplot
.. autofunction:: remove_legend


Miscellaneous functions:

.. autofunction:: convert_aa_code


Data
----

.. autodata:: amino_acid_codes

Classes [hide private]
  AttributeDict
A dictionary with pythonic access to keys as attributes --- useful for interactive work.
  FileUtils
Mixin class to provide additional file-related capabilities.
  Timedelta
Extension of :class:`datetime.timedelta`.
Functions [hide private]
 
Property(func)
Simple decorator wrapper to make full fledged properties.
source code
 
anyopen(datasource, mode='r')
Open datasource (gzipped, bzipped, uncompressed) and return a stream.
source code
 
_get_stream(filename, openfunction=<type 'file'>, mode='r') source code
 
convert_aa_code(x)
Converts between 3-letter and 1-letter amino acid codes.
source code
 
realpath(*args)
Join all args and return the real path, rooted at /.
source code
 
find_first(filename, suffices=None)
Find first *filename* with a suffix from *suffices*.
source code
 
withextsep(extensions)
Return list in which each element is guaranteed to start with :data:`os.path.extsep`.
source code
 
iterable(obj)
Returns True if obj can be iterated over and is not a string.
source code
 
asiterable(obj)
Returns obj so that it can be iterated over; a string is not treated as iterable
source code
 
unlink_f(path)
Unlink path but do not complain if file does not exist.
source code
 
unlink_gmx(*args)
Unlink (remove) Gromacs file(s) and all corresponding backups.
source code
 
unlink_gmx_backups(*args)
Unlink (rm) all backup files corresponding to the listed files.
source code
 
mkdir_p(path)
Create a directory path with subdirs but do not complain if it exists.
source code
 
cat(f=None, o=None)
Concatenate files f*=[...] and write to *o
source code
 
activate_subplot(numPlot)
Make subplot numPlot active on the canvas.
source code
 
remove_legend(ax=None)
Remove legend for axes or gca.
source code
 
number_pdbs(*args, **kwargs)
Rename pdbs x1.pdb ...
source code
Variables [hide private]
  logger = logging.getLogger('gromacs.utilities')
  amino_acid_codes = {'A': 'ALA', 'C': 'CYS', 'D': 'ASP', 'E': '...
translation table for 1-letter codes --> 3-letter codes ..
  inverse_aa_codes = {'ALA': 'A', 'ARG': 'R', 'ASN': 'N', 'ASP':...
  NUMBERED_PDB = re.compile(r'(?P<PREFIX>.*\D)(?P<NUMBER>\d+)\.(...
  one = 'Y'
  three = 'TYR'
Function Details [hide private]

Property(func)

source code 
Simple decorator wrapper to make full fledged properties. See eg http://adam.gomaa.us/blog/2008/aug/11/the-python-property-builtin/

anyopen(datasource, mode='r')

source code 

Open datasource (gzipped, bzipped, uncompressed) and return a stream.

  • datasource: a file or a stream
  • mode: 'r' or 'w'

Arguments:  

realpath(*args)

source code 

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

Returns None if any of the args is none.

find_first(filename, suffices=None)

source code 
Find first *filename* with a suffix from *suffices*.

:Arguments:
  *filename*
     base filename; this file name is checked first
  *suffices*
     list of suffices that are tried in turn on the root of *filename*; can contain the 
     ext separator (:data:`os.path.extsep`) or not

:Returns: The first match or ``None``.

mkdir_p(path)

source code 

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

This is like GNU mkdir -p path.

activate_subplot(numPlot)

source code 

Make subplot numPlot active on the canvas.

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

remove_legend(ax=None)

source code 

Remove legend for axes or gca.

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

number_pdbs(*args, **kwargs)

source code 
Rename pdbs x1.pdb ... x345.pdb --> x0001.pdb ... x0345.pdb

Arguments:

  • args: filenames or glob patterns (such as "pdb/md*.pdb")
  • format: format string including keyword num ["%(num)04d"]


Variables Details [hide private]

amino_acid_codes

translation table for 1-letter codes --> 3-letter codes .. Note: This does not work for HISB and non-default charge state aa!
Value:
{'A': 'ALA',
 'C': 'CYS',
 'D': 'ASP',
 'E': 'GLU',
 'F': 'PHE',
 'G': 'GLY',
 'H': 'HIS',
 'I': 'ILE',
...

inverse_aa_codes

Value:
{'ALA': 'A',
 'ARG': 'R',
 'ASN': 'N',
 'ASP': 'D',
 'CYS': 'C',
 'GLN': 'Q',
 'GLU': 'E',
 'GLY': 'G',
...

NUMBERED_PDB

Value:
re.compile(r'(?P<PREFIX>.*\D)(?P<NUMBER>\d+)\.(?P<SUFFIX>pdb)')