Author: bugman Date: Fri May 4 10:23:09 2012 New Revision: 15953 URL: http://svn.gna.org/viewcvs/relax?rev=15953&view=rev Log: The auto-generated prompt user function front end objects are now executable. The uf.backend variable is now the executable Python object. The pipe user function class has been updated for the uf.backend change. Modified: branches/uf_redesign/prompt/interpreter.py branches/uf_redesign/prompt/objects.py branches/uf_redesign/user_functions/objects.py branches/uf_redesign/user_functions/pipe.py Modified: branches/uf_redesign/prompt/interpreter.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/prompt/interpreter.py?rev=15953&r1=15952&r2=15953&view=diff ============================================================================== --- branches/uf_redesign/prompt/interpreter.py (original) +++ branches/uf_redesign/prompt/interpreter.py Fri May 4 10:23:09 2012 @@ -167,7 +167,7 @@ class_name, uf_name = split(name, '.') # Generate a new container. - obj = Uf_object(name, title=data.title, kargs=data.kargs, desc=data.desc, examples=data.prompt_examples) + obj = Uf_object(name, title=data.title, kargs=data.kargs, backend=data.backend, desc=data.desc, examples=data.prompt_examples) # Get the class object. class_obj = self._locals[class_name] Modified: branches/uf_redesign/prompt/objects.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/prompt/objects.py?rev=15953&r1=15952&r2=15953&view=diff ============================================================================== --- branches/uf_redesign/prompt/objects.py (original) +++ branches/uf_redesign/prompt/objects.py Fri May 4 10:23:09 2012 @@ -66,35 +66,36 @@ class Uf_object(object): """The object for auto-generating the user functions.""" - def __call__(self, *args, **kwds): + def __call__(self, *uf_args, **uf_kargs): """Make the user function executable.""" # Check the keyword args. - keys = kwds.keys() + keys = uf_kargs.keys() for name in keys: # Unknown keyword. if name not in self._karg_names: raise RelaxError("The keyword argument '%s' is unknown." % name) # Convert the args to keyword args if needed. - num_args = len(args) + num_args = len(uf_args) + new_args = [] if num_args: for i in range(num_args): # Check if the keyword is already assigned. if self._kargs[i]['name'] in keys: - raise RelaxError("The argument '%s' and the keyword argument '%s' cannot both be supplied." % (args[i], self._kargs[i]['name'])) + raise RelaxError("The argument '%s' and the keyword argument '%s' cannot both be supplied." % (uf_args[i], self._kargs[i]['name'])) # Add the arg as a keyword arg. - kwds[self._kargs[i]['name']] = args[i] + uf_kargs[self._kargs[i]['name']] = uf_args[i] # Set the argument defaults. values = [] - keys = kwds.keys() + keys = uf_kargs.keys() for i in range(self._karg_num): # The user supplied value. if self._kargs[i]['name'] in keys: # The value. - value = kwds[self._kargs[i]['name']] + value = uf_kargs[self._kargs[i]['name']] # Check if the correct Python object type has been supplied. if self._kargs[i]['py_type'] == 'str': @@ -131,18 +132,34 @@ # Print out. print(text) - - def __init__(self, name, title=None, kargs=None, desc=None, examples=None, additional=None): + # Execute the functional code. + self._backend(*new_args, **uf_kargs) + + + def __init__(self, name, title=None, kargs=None, backend=None, desc=None, examples=None, additional=None): """Set up the object. - @param name: The name of the user function. - @type name: str - """ + @param name: The name of the user function. + @type name: str + @keyword title: The long title of the user function. + @type title: str + @keyword kargs: The list of keyword argument details. + @type kargs: list of dict + @keyword backend: The user function back end. This should be a string version with full module path of the function which executes the back end. For example 'generic_fns.pipes.create'. Note, this should be importable as __import__(backend)! + @type backend: executable object + @keyword desc: The full, multi-paragraph description. + @type desc: str + @keyword examples: The examples of how to use the prompt front end. + @type examples: str or None + @keyword additional: The examples of how to use the prompt front end. + @type additional: list of str or None + """ # Store the args. self._name = name self._title = title self._kargs = kargs + self._backend = backend self._desc = desc self._examples = examples self._additional = additional Modified: branches/uf_redesign/user_functions/objects.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/user_functions/objects.py?rev=15953&r1=15952&r2=15953&view=diff ============================================================================== --- branches/uf_redesign/user_functions/objects.py (original) +++ branches/uf_redesign/user_functions/objects.py Fri May 4 10:23:09 2012 @@ -72,11 +72,17 @@ """This class is used to process and store all of the user function specific information. @ivar title: The long title of the user function. + @type title: str @ivar title_short: The optional short title. + @type title_short: str or None @ivar kargs: The list of keyword argument details. + @type kargs: list of dict @ivar backend: The user function back end. This should be a string version with full module path of the function which executes the back end. For example 'generic_fns.pipes.create'. Note, this should be importable as __import__(backend)! + @type backend: executable object @ivar desc: The full, multi-paragraph description. + @type desc: str @ivar prompt_examples: The examples of how to use the prompt front end. + @type prompt_examples: str or None """ # The list of modifiable objects (anything else will be rejected to prevent coding errors). Modified: branches/uf_redesign/user_functions/pipe.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/user_functions/pipe.py?rev=15953&r1=15952&r2=15953&view=diff ============================================================================== --- branches/uf_redesign/user_functions/pipe.py (original) +++ branches/uf_redesign/user_functions/pipe.py Fri May 4 10:23:09 2012 @@ -24,6 +24,8 @@ """Module containing the 'pipe' user function data.""" # relax module imports. +from generic_fns import pipes +from specific_fns.setup import hybrid_obj from user_functions.data import Uf_info; uf_info = Uf_info() @@ -37,7 +39,7 @@ uf.title_short = "Data pipe copying." uf.add_keyarg(name="pipe_from", default=None, py_type="str", desc_short="pipe from", desc="The name of the source data pipe to copy the data from.", can_be_none=True) uf.add_keyarg(name="pipe_to", default=None, py_type="str", desc_short="pipe to", desc="The name of the target data pipe to copy the data to.", can_be_none=True) -uf.backend = 'generic_fns.pipes.copy' +uf.backend = pipes.copy uf.desc = """ This allows the contents of a data pipe to be copied. If the source data pipe is not set, the current data pipe will be assumed. The target data pipe must not yet exist. """ @@ -58,7 +60,7 @@ uf.title_short = "Data pipe creation." uf.add_keyarg(name="pipe_name", default=None, py_type="str", desc_short="data pipe name", desc="The name of the data pipe.") uf.add_keyarg(name="pipe_type", default=None, py_type="str", desc_short="data pipe type", desc="The type of data pipe.") -uf.backend = 'generic_fns.pipes.create' +uf.backend = pipes.create uf.desc = """ The data pipe name can be any string however the data pipe type can only be one of the following: @@ -81,7 +83,7 @@ uf = uf_info.add_uf('pipe.current') uf.title = "Print the name of the current data pipe." uf.title_short = "Current data pipe printing." -uf.backend = 'generic_fns.pipes.current' +uf.backend = pipes.current uf.prompt_examples = """ To run the user function, type: @@ -93,7 +95,7 @@ uf.title = "Delete a data pipe from the relax data store." uf.title_short = "Data pipe deletion." uf.add_keyarg(name="pipe_name", default=None, py_type="str", desc_short="data pipe name", desc="The name of the data pipe to delete.", can_be_none=True) -uf.backend = 'generic_fns.pipes.delete' +uf.backend = pipes.delete uf.desc = """ This will permanently remove the data pipe and all of its contents from the relax data store. If the pipe name is not given, then all data pipes will be deleted. """ @@ -102,7 +104,7 @@ uf = uf_info.add_uf('pipe.display') uf.title = "Print a list of all the data pipes." uf.title_short = "Data pipe listing." -uf.backend = 'generic_fns.pipes.display' +uf.backend = pipes.display uf.prompt_examples = """ To run the user function, type: @@ -115,7 +117,7 @@ uf.title_short = "Hybrid data pipe creation." uf.add_keyarg(name="hybrid", default=None, py_type="str", desc_short="hybrid pipe name", desc="The name of the hybrid data pipe to create.") uf.add_keyarg(name="pipes", default=None, py_type="str_list", desc_short="data pipes", desc="An array containing the names of all data pipes to hybridise.") -uf.backend = 'specific_fns.setup.hybrid_obj._hybridise' +uf.backend = hybrid_obj._hybridise uf.desc = """ This user function can be used to construct hybrid models. An example of the use of a hybrid model could be if the protein consists of two independent domains. These two domains could be analysed separately, each having their own optimised diffusion tensors. The N-terminal domain data pipe could be called 'N_sphere' while the C-terminal domain could be called 'C_ellipsoid'. These two data pipes could then be hybridised into a single data pipe. This hybrid data pipe can then be compared via model selection to a data pipe whereby the entire protein is assumed to have a single diffusion tensor. @@ -134,7 +136,7 @@ uf.title = "Switch between the data pipes of the relax data store." uf.title_short = "Data pipe switching." uf.add_keyarg(name="pipe_name", default=None, py_type="str", desc_short="data pipe name", desc="The name of the data pipe.") -uf.backend = 'generic_fns.pipes.switch' +uf.backend = pipes.switch uf.desc = """ This will switch between the various data pipes within the relax data store. """