2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2019, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 """mdrun operation module
37 The mdrun operation (in its first draft) conforms to the user-level API, but does
38 not use the Python Context resource manager. It uses either the legacy 0.0.7
39 Context or its own Context, also implemented in this module.
44 from gmxapi import exceptions
45 from gmxapi.operation import AbstractOperation
46 from gmxapi.operation import function_wrapper
47 # The following imports are not marked as public API.
48 # TODO: Resolve public API and exposure.
49 from . import workflow
52 def mdrun_dispatcher(context, *, input, label: str = None, **kwargs) -> typing.Type['AbstractOperation']:
53 """Dispatch to an appropriate director based on the context and input.
55 Runs appropriate director code to set up an operation, returning a handle to
56 a simulation operation node.
59 context: Execution context in which to attempt to instantiate an operation from input
60 input: operation input. Argument type is context dependent.
61 label: human readable tag for the work node to be created.
63 Additional key word arguments are passed on to the dispatched factory.
66 # TODO: This is a legacy import that should be updated.
67 from .context import get_context
69 raise exceptions.NotImplementedError('sorry... no labels yet')
71 legacy_context = get_context(work=input)
76 with legacy_context as session:
80 if context is not None and context is legacy_context:
81 helper = function_wrapper(output={'data': bool})(run_session)
82 return helper(**kwargs)
84 raise exceptions.ValueError('Could not dispatch MD input {} with context {}'.format(input, legacy_context))
87 def mdrun(input=None) -> typing.Type['AbstractOperation']:
88 """MD simulation operation.
91 input : valid simulation input
94 runnable operation to perform the specified simulation
96 The returned object has a `run()` method to launch the simulation.
97 Otherwise, this operation does not yet support the gmxapi data flow model.
99 `input` may be a TPR file name.
102 New function names will be appearing to handle tasks that are separate
104 "simulate" is plausibly a dispatcher or base class for various tasks
105 dispatched by mdrun. Specific work factories are likely "minimize,"
106 "test_particle_insertion," "legacy_simulation" (do_md), or "simulation"
107 composition (which may be leap-frog, vv, and other algorithms)
109 # If input looks like classic filename input, use the gmxapi 0.0.7
111 from .context import get_context
113 work = workflow.from_tpr(input)
114 assert work is not None
115 work_context = get_context(work)
116 assert work_context is not None
117 except exceptions.UsageError:
118 # Input was not gmxapi 0.0.7 input.
122 # TODO: Inspect input to determine context.
124 handle = mdrun_dispatcher(context=work_context, input=work, label=None, **kwargs)