File: pythonreference.rst

package info (click to toggle)
gromacs 2025.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 287,236 kB
  • sloc: xml: 3,718,478; cpp: 654,820; ansic: 75,282; python: 20,471; sh: 3,471; perl: 2,218; yacc: 644; fortran: 397; lisp: 265; makefile: 171; lex: 125; awk: 68; csh: 39
file content (277 lines) | stat: -rw-r--r-- 7,723 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
==============================
gmxapi Python module reference
==============================

Version |gmxapi-version|.

.. Concise reference documentation extracted directly from code.
.. For new and non-backwards-compatible features, API versions must be given.

The |Gromacs| Python package includes a high-level scripting interface implemented
in pure Python and a lower-level API implemented as a C++ extension module.
The pure Python implementation provides the basic ``gmxapi`` module and
classes with a very stable syntax that can be maintained with maximal compatibility
while mapping to lower level interfaces that may take a while to sort out. The
separation also serves as a reminder that different execution contexts may be
implemented quite diffently, though Python scripts using only the high-level
interface should execute on all.

Package documentation is extracted from the ``gmxapi`` Python module and is also available
directly, using either ``pydoc`` from the command line or :py:func:`help` from within Python, such
as during an interactive session.

Refer to the Python source code itself for additional clarification.

.. seealso:: :ref:`gmxapi_package_documentation`

.. Configuration for doctest: automated syntax checking in documentation code snippets
.. testsetup::

    import gmxapi as gmx
    from gmxapi.data import tpr_filename

Interface concepts
==================

.. py:currentmodule:: gmxapi.abc

*gmxapi* commands return *references* to operations.
Generally, the operations are collected into a graph of data flow dependencies,
and only executed when the results are requested.

.. autoclass:: OperationReference
    :members:

*gmxapi* uses a `Future` to reference an operation output or data that may not yet be available.

.. autoclass:: Future
    :members:

An `OperationReference` may provide several named Futures on its *output* attribute.

A `Future` may be provided directly as inputs to other *gmxapi* commands.
*gmxapi* will execute the required operation to get the data when it is needed.

To get an actual result in your Python script, you can call
:py:func:`~Future.result()` on any *gmxapi* data reference.
If the operation has not yet been executed, the operation (and any operation dependencies)
will be executed immediately.

You can also force an operation to run by calling its :py:func:`~OperationReference.run()` method.
But this is not generally necessary unless your only goal is to produce output files on disk
that are not consumed in the same script.

In some cases, a `Future` can be subscripted to get a new Future representing
a slice of the original.
For instance, `commandline_operation` objects have a *file* output that produces
a mapping of command line flags to output files (per the *output_files* parameter).
This *file* output can be subscripted with a single command line option to get
a `Future` for just one output file type.
See :ref:`gmxapi simulation preparation` for an illustrative example.

Ensemble data flow
------------------

*gmxapi* automatically generates arrays of operations and parallel data flow,
when parallel inputs are provided to *gmxapi* command parameters.

When a `Future` represents the output of an ensemble operation,
:py:func:`~Future.result()` returns a list with elements corresponding
to the ensemble members.

It is not currently possible to get a `Future` for a specific ensemble member.

See :ref:`gmxapi ensemble` for more information.

gmxapi basic package
=====================

::

    import gmxapi as gmx

.. automodule:: gmxapi

.. autodecorator:: function_wrapper

.. autofunction:: commandline_operation

.. autofunction:: subgraph

.. autofunction:: while_loop

Simulation module
=================

.. automodule:: gmxapi.simulation

.. py:currentmodule:: gmxapi

Preparing simulations
---------------------

.. autofunction:: read_tpr

.. For the OutputDataProxy classes, the creation signatures are distracting.
   As of Sphinx 6.0, however, the autodoc_class_signature configuration option
   cannot be overridden for individual 'autoclass' directives, and in general
   the default "mixed" value seems appropriate for this documentation.

.. autoclass:: gmxapi.simulation.read_tpr.OutputDataProxy

.. autofunction:: modify_input

.. autoclass:: gmxapi.simulation.modify_input.OutputDataProxy

Running simulations
-------------------

.. autofunction:: mdrun

.. autoclass:: gmxapi.simulation.mdrun.OutputDataProxy

Utilities
=========

.. automodule:: gmxapi.utility

.. autofunction:: config

.. autofunction:: join_path

.. py:currentmodule:: gmxapi

.. autofunction:: concatenate_lists

.. autofunction:: join_arrays

.. autofunction:: logical_not

.. autofunction:: make_constant

Run time details
----------------

.. note:: The *gmxapi.runtime* Python module is evolving. Some details are not yet well specified.

.. automodule:: gmxapi.runtime

.. autofunction:: filtered_mpi_environ

.. autodata:: filtered_prefixes

Status messages and Logging
===========================

.. automodule:: gmxapi._logging
   :members:

Exceptions module
=================
..  automodule:: gmxapi.exceptions
    :members:

gmx.version module
==================
..  automodule:: gmxapi.version
    :members:

Core API
========

.. automodule:: gmxapi._gmxapi

Exceptions
----------

Module Exceptions
~~~~~~~~~~~~~~~~~

.. autoexception:: gmxapi._gmxapi.Exception

    Root exception for the C++ extension module. Derives from `gmxapi.exceptions.Error`.

.. autoexception:: FeatureNotAvailable


Wrapped C++ exceptions emitted through the supporting |Gromacs| library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autoexception:: gmxapi._gmxapi.MissingImplementationError

.. autoexception:: gmxapi._gmxapi.ProtocolError

.. autoexception:: gmxapi._gmxapi.UsageError

Other
~~~~~

No other C++ exceptions are expected, but will be wrapped in a
:py:class:`Exception` to help tracing and reporting bugs.

.. autoexception:: gmxapi._gmxapi.UnknownException

Functions
---------

This documentation is provided for completeness and as an aid to developers.
Users of the :py:mod:`gmxapi` package, generally, should not need to use the
following tools directly.

Tools for launching simulations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: gmxapi._gmxapi.from_tpr

.. autofunction:: gmxapi._gmxapi.create_context

Tools to manipulate TPR input files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: gmxapi._gmxapi.copy_tprfile

.. autofunction:: gmxapi._gmxapi.read_tprfile

.. autofunction:: gmxapi._gmxapi.write_tprfile

.. autofunction:: gmxapi._gmxapi.rewrite_tprfile

Utilities
~~~~~~~~~

.. autofunction:: gmxapi._gmxapi.has_feature

    Available features may depend on the package version, the details of the
    supporting |Gromacs| installation, the software environment detected
    when the package was built, or possibly on detected runtime details.
    These feature checks are largely for internal use. The :py:mod:`gmxapi`
    commands may adjust their behavior slightly depending on feature checks,
    and (at worst) should produce meaningful error messages or exceptions.

    Named features:

    * *create_context*: `create_context` can be used to initialize a `Context`
      with assigned resources.
    * *mpi_bindings*: C++ extension module was built with :py:mod:`mpi4py` compatibility.


Classes
-------

.. autoclass:: gmxapi._gmxapi.Context
    :members:

.. autoclass:: gmxapi._gmxapi.MDArgs
    :members:

.. autoclass:: gmxapi._gmxapi.MDSession
    :members:

.. autoclass:: gmxapi._gmxapi.MDSystem
    :members:

.. autoclass:: gmxapi._gmxapi.SimulationParameters
    :members:

.. autoclass:: gmxapi._gmxapi.TprFile
    :members: