def modify_input(input, parameters: dict, label: str = None, context=None): """Modify simulation input with data flow operations. Given simulation input *input*, override components of simulation input with additional arguments, such as *parameters*. """ handle_context = context if handle_context is not None: raise gmxapi.exceptions.NotImplementedError( 'context must be None. This factory is only for the Python UI right now.') target_context = _op.current_context() assert isinstance(target_context, _op.Context) # Get a director that will create a node in the standard context. node_director = _op._get_operation_director(RegisteredOperation, context=target_context) assert isinstance(node_director, StandardDirector) # TODO: refine this protocol assert handle_context is None # Examine the input. if isinstance(input, ModuleObject): # The input is from read_tpr or modify_input. source_context = input else: # Allow automatic dispatching source_context = None resource_factory = node_director.resource_factory(source=source_context, target=target_context) resources = resource_factory(input=input, parameters=parameters) handle = node_director(resources=resources, label=label) return handle
def read_tpr(filename, label: str = None, context=None): """ Arguments: filename: input file name label: optional human-readable label with which to tag the new node context: Context in which to return a handle to the new node. Use default (None) for Python scripting interface Returns: Reference (handle) to the new operation instance (node). """ handle_context = context if handle_context is not None: raise gmxapi.exceptions.NotImplementedError( 'context must be None. This factory is only for the Python UI right now.') # 1. Handle node creation in the scripting interface. # When *context* input is None, dispatch to the current Context. Confirm that # it is a standard context from the gmxapi.operation module, translate the # input into that context, and create the node. # 2. Dispatch to SimulationModuleContext. # Operation is not fully implemented in gmxapi.operation context. When creating # a node in a gmxapi.operation context, dispatch and subscribe to a SimulationModuleContext, # in which # 3. Handle consumption in SimulationModuleContext. # When a consuming operation is native to the SimulationModuleContext, # detect that a richer interface is available and use it. Possible implementation: # Chain of Responsibility: subscribe() is serviced by the Context "closest" # to the source. subscriber is the most native compatible Context for the consuming operation # but decays to the context in which the handle is being created. subscribe() # can accept a callback function and an indication of the form of the message # to send (a consuming Context or ResourceFactory). # TODO: Other types of input, such as File placeholders. target_context = _op.current_context() assert isinstance(target_context, _op.Context) # Get a director that will create a node in the standard context. node_director = _op._get_operation_director(RegisteredOperation, context=target_context) assert isinstance(node_director, StandardDirector) # TODO: refine this protocol assert handle_context is None resource_factory = node_director.resource_factory(source=handle_context, target=target_context) resources = resource_factory(filename=filename) handle = node_director(resources=resources, label=label) # Note: One effect of the assertions above is to help the type checker infer # the return type of the handle. It is hard to convince the type checker that # the return value of the node builder is up-cast. We might be able to resolve # this by making both get_operation_director and ReadTprImplementation # generics of the handle type, or using the handle type as the key for # get_operation_director. return handle
def mdrun(input, label: str = None, context=None): """MD simulation operation. Arguments: input : valid simulation input Returns: runnable operation to perform the specified simulation The *output* attribute of the returned operation handle contains dynamically determined outputs from the operation. `input` may be a TPR file name or a an object providing the SimulationInput interface. Note: New function names will be appearing to handle tasks that are separate "simulate" is plausibly a dispatcher or base class for various tasks dispatched by mdrun. Specific work factories are likely "minimize," "test_particle_insertion," "legacy_simulation" (do_md), or "simulation" composition (which may be leap-frog, vv, and other algorithms) """ handle_context = context if handle_context is not None: raise gmxapi.exceptions.NotImplementedError( 'context must be None. This factory is only for the Python UI right now.' ) target_context = _op.current_context() assert isinstance(target_context, _op.Context) # Get a director that will create a node in the standard context. node_director = _op._get_operation_director(RegisteredOperation, context=target_context) assert isinstance(node_director, StandardDirector) # TODO: refine this protocol assert handle_context is None # Examine the input. if isinstance(input, ModuleObject): # The input is from read_tpr or modify_input. source_context = input else: # Allow automatic dispatching source_context = None resource_factory = node_director.resource_factory(source=source_context, target=target_context) resources = resource_factory(input) handle = node_director(resources=resources, label=label) # Note: One effect of the assertions above is to help the type checker infer # the return type of the handle. It is hard to convince the type checker that # the return value of the node builder is up-cast. We might be able to resolve # this by making both get_operation_director and ReadTprImplementation # generics of the handle type, or using the handle type as the key for # get_operation_director. return handle