Package gromacs :: Module core :: Class GromacsCommand
[hide private]
[frames] | no frames]

Class GromacsCommand

source code

object --+    
         |    
   Command --+
             |
            GromacsCommand
Known Subclasses:

Base class for wrapping a g_* command.

Limitations: User must have sourced GMXRC so that the python script can inherit the environment and find the gromacs programs.

The class doc string is dynamically replaced by the documentation of the gromacs command when an instance is created.

Instance Methods [hide private]
 
__init__(self, *args, **kwargs)
Set up the command with gromacs flags as keyword arguments.
source code
 
_combine_arglist(self, args, kwargs)
Combine the default values and the supplied values.
source code
 
check_failure(self, result, msg='Gromacs tool failed', command_string=None) source code
 
_combineargs(self, *args, **kwargs)
Add switches as 'options' with value True to the options dict.
source code
 
_build_arg_list(self, **kwargs)
Build list of arguments from the dict; keys must be valid gromacs flags.
source code
 
_run_command(self, *args, **kwargs)
Execute the gromacs command; see the docs for __call__.
source code
 
transform_args(self, *args, **kwargs)
Combine arguments and turn them into gromacs tool arguments.
source code
 
_get_gmx_docs(self)
Extract standard gromacs doc by running the program and chopping the header.
source code

Inherited from Command: Popen, __call__, commandline, help, run

Inherited from Command (private): _commandline

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  command_name = None
Derive a class from command; typically one only has to set *command_name* to the name of the script or executable.
  doc_pattern = '.*?(?P<DOCS>DESCRIPTION.*)'
  gmxfatal_pattern = '----+\n # ---- decorator...
  failuremodes = ('raise', 'warn', None)
Available failure modes.
Properties [hide private]
  gmxdoc
Usage for the underlying Gromacs tool (cached).

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 
Set up the command with gromacs flags as keyword arguments.

The following  are generic instructions; refer  to the Gromacs
command  usage information  that should  have  appeared before
this generic documentation.

As an example, a generic Gromacs command could use the following flags::

  cmd = GromacsCommand('v', f=['md1.xtc','md2.xtc'], o='processed.xtc', t=200, ...)

which would correspond to running the command in the shell as ::

  GromacsCommand -v -f md1.xtc md2.xtc -o processed.xtc -t 200

**Gromacs command line arguments**

   Gromacs boolean switches (such as ``-v``) are given as python
   positional arguments (``'v'``) or as keyword argument (``v=True``);
   note the quotes in the first case. Negating a boolean switch can be
   done with ``'nov'``, ``nov=True`` or ``v=False`` (and even ``nov=False``
   works as expected: it is the same as ``v=True``).

   Any Gromacs options that take parameters are handled as keyword
   arguments. If an option takes multiple arguments (such as the
   multi-file input ``-f file1 file2 ...``) then the list of files must be
   supplied as a python list.

   If a keyword has the python value ``None`` then it will *not* be
   added to the Gromacs command line; this allows for flexible
   scripting if it is not known in advance if an input file is
   needed. In this case the default value of the gromacs tool
   is used.

   Keywords must be legal python keywords or the interpreter raises a
   :exc:`SyntaxError` but of course Gromacs commandline arguments are
   not required to be legal python. In this case "quote" the option
   with an underscore (``_``) and the underscore will be silently
   stripped. For instance, ``-or`` translates to the illegal keyword
   ``or`` so it must be underscore-quoted::
       
      cmd(...., _or='mindistres.xvg')

**Command execution**

   The command is executed with the :meth:`~GromacsCommand.run` method or by
   calling it as a function. The two next lines are equivalent::

     cmd(...)
     cmd.run(...)

   When the command is run one can override options that were given at
   initialization or one can add additional ones. The same rules for
   supplying Gromacs flags apply as described above.

**Non-Gromacs keyword arguments**

   The other keyword arguments (listed below) are not passed on to the
   Gromacs tool but determine how the command class behaves. They are
   only useful when instantiating a class. This is mostly of interest
   to developers.

:Keywords:
   *failure*
      determines how a failure of the gromacs command is treated; it
      can be one of the following:

      'raise'
           raises GromacsError if command fails
      'warn'
           issue a :exc:`GromacsFailureWarning`
      ``None``
           just continue silently

   *doc* : string
      additional documentation []

Overrides: object.__init__

_combine_arglist(self, args, kwargs)

source code 
Combine the default values and the supplied values.
Overrides: Command._combine_arglist

_run_command(self, *args, **kwargs)

source code 
Execute the gromacs command; see the docs for __call__.
Overrides: Command._run_command

transform_args(self, *args, **kwargs)

source code 
Combine arguments and turn them into gromacs tool arguments.
Overrides: Command.transform_args

Class Variable Details [hide private]

gmxfatal_pattern

Value:
'''----+
                   # ---- decorator line
            \\s*Program\\s+(?P<program_name>\\w+),     #  Program name\
,
              \\s+VERSION\\s+(?P<version>[\\w.]+)\\s*
 #    VERSION 4.0.5
            (?P<message>.*?)
                      # full message, multiple lines
...

Property Details [hide private]

gmxdoc

Usage for the underlying Gromacs tool (cached).
Get Method:
unreachable.fget(self)