######################################################
# The relax data model redesign -- planning document #
######################################################


# The proposal.
###############

The proposal was split into multiple posts to relax-devel.  The posts are:

* The parent message 'Redesign of the relax data model:  A HOWTO for breaking relax'.
Located at https://mail.gna.org/public/relax-devel/2006-10/msg00053.html (Message-id: <1160550133.9523.54.camel@pc172-31-2-63.biochem.unimelb.edu.au>).

* Section 1 'Redesign of the relax data model:  1.  Why change?'.
Located at https://mail.gna.org/public/relax-devel/2006-10/msg00054.html (Message-id: <1160551172.9523.60.camel@pc172-31-2-63.biochem.unimelb.edu.au>).

* Section 2 'Subject: Redesign of the relax data model:  2.  A new run concept'.
Located at https://mail.gna.org/public/relax-devel/2006-10/msg00056.html (Message-id: <1160555137.9523.70.camel@pc172-31-2-63.biochem.unimelb.edu.au>).

* Section 3 'Redesign of the relax data model:  3.  Molecules, residues, and spins'.
Located at https://mail.gna.org/public/relax-devel/2006-10/msg00057.html (Message-id: <1160557041.9523.74.camel@pc172-31-2-63.biochem.unimelb.edu.au>).

* Section 4 'Redesign of the relax data model:  4.  Conclusion'.
Located at https://mail.gna.org/public/relax-devel/2006-10/msg00058.html (Message-id: <1160557876.9523.79.camel@pc172-31-2-63.biochem.unimelb.edu.au>).



# Preparation.
##############

1 [Done].  Firstly release relax version 1.3.0 prior to any changes (to allow a functional version which handles RNA better, has the tensor PDB representation code, etc).

2 [Done].  Redesign 'self.relax.data'.

3.  Create the data pipe looping function for the 'pipes' argument (Chris MacRaild, https://mail.gna.org/public/relax-devel/2006-10/msg00060.html, Message-id: <1160562239.14487.98.camel@mrspell>).  The user functions could be implemented as functors (Chris MacRaild, https://mail.gna.org/public/relax-devel/2007-01/msg00020.html, Message-ID: <1168432131.7569.338.camel@mrspell>).  The design will need to take into account the user function docstrings, relax help system, and the relax manual docstring fetching code.

4 [Done].  Create the spin_loop function (Edward d'Auvergne, https://mail.gna.org/public/relax-devel/2006-10/msg00057.html, Message-id: <1160557041.9523.74.camel@pc172-31-2-63.biochem.unimelb.edu.au>).  Use a generator function, using the yield statement, to return the spin data containers which are essentially pointers to the data (Gary Thompson, https://mail.gna.org/public/relax-devel/2007-01/msg00014.html, Message-id: <f001463a0701071417w6bd7927cp8fdd052e698575ec@mail.gmail.com>).  The implementation was essentially given by Chris MacRaild at https://mail.gna.org/public/relax-devel/2007-01/msg00036.html (Message-ID: <1168883717.7569.511.camel@mrspell>).

5 [Done].  Implement a parser for the following molecule/residue/spin selection syntax (Gary Thompson, https://mail.gna.org/public/relax-devel/2007-01/msg00014.html, Message-id: <f001463a0701071417w6bd7927cp8fdd052e698575ec@mail.gmail.com>):
    #<molecule number> | <molecule_name>:<residue_selection>[,<residue_selection>...]@<atom_selection> [,<atom_selection>]
    residue_selection=<residue_number> | <residue_range> | <residue_type>
    residue_selection=<residue_number>-<residue_number>
    atom_selection=<string_and_wildcards>
This syntax will need to be properly referenced (in addition to being fully described) in the user function docstrings.  I.e. the reference for Molmol syntax, the reference for UCSF syntax, etc.  We need to find the source and name of the syntax.

6 [Done].  Convert the methods of the class 'Selection' from the file 'generic_fns/selection.py' into methods and then add the following functions (Chris MacRaild at https://mail.gna.org/public/relax-devel/2007-01/msg00036.html Message-ID: <1168883717.7569.511.camel@mrspell>; Edward d'Auvergne, https://mail.gna.org/public/relax-devel/2007-01/msg00041.html, Message-ID: <7f080ed10701190408i8a5dee3y8ccbe1aba11bcba@mail.gmail.com>):
    parse_token()
    tokenise()

7.  Create the spin_command function (Chris MacRaild, https://mail.gna.org/public/relax-devel/2007-01/msg00036.html, Message-ID: <1168883717.7569.511.camel@mrspell>).

8 [Done].  Rename 'prompt/run.py' to 'prompt/pipe.py'.  Rename 'generic_fns/runs.py' to 'generic_fns/pipes.py'.

9 [Done].  Create the new pipe user functions (from the old run user functions):
    pipe.copy()         # Create a new pipe with the current contents of another pipe.
    pipe.create()       # Create a new pipe.  Switch to this pipe by default.
    pipe.current()      # Print the current pipe name.
    pipe.delete()       # Delete the pipe.
    [this is almost the same as reset() so it will not be implemented] pipe.delete_all()   # Delete all pipes.  Essentially deleting 'self.relax.data'.
    pipe.hybridise()    # Fuse two pipes into the current pipe.  Overlapping data in the two pipes must be identical!
    pipe.list()         # Print the details of all pipes.
    pipe.switch()       # Switch to a different pipe.

10 [Done].  Create the 'molecule' user function class:
    molecule.create()
    molecule.copy()     # Copy the molecule information (name and num) from another pipe.
    molecule.delete()
    molecule.display()     # Print the molecule info.
    molecule.rename()
The molecule.add() user function should be used to create all the residue and spin structures for that molecule from a loaded structure.  This can be done through an API to allow users to code their own PDB readers (which could in future be incorporated into relax).  For more information see Gary Thompson's post at https://mail.gna.org/public/relax-devel/2007-01/msg00014.html (Message-ID: <f001463a0701071417w6bd7927cp8fdd052e698575ec@mail.gmail.com>).  The user function should also allow for the creation of an empty molecule data container to allow for analyses whereby no structure is needed (relaxation curve-fitting, NOE calculation, model-free analysis with isotropic diffusion, etc.).  The sequence user function class can then be used to load the sequence (or spin.read()).

11 [Done].  Create the 'residue' user function class:
    residue.copy()
    residue.create()    # This is currently named 'sequence.add()'.
    residue.delete()
    residue.display()
    residue.rename()
    residue.renumber()

12 [Done].  Create the 'spin' user function class:
    spin.copy()         # Copy the spin info (name and num) from another pipe.
    spin.create()
    spin.delete()
    spin.display()
    spin.rename()
    spin.renumber()

13 [Done].  Create a single user function class which handles molecules, residues, and spins together with selections:
    sequence.display()
    sequence.read()
    sequence.write()


# The incremental changes.
##########################

The following are the steps to be taken for the function to function, file to file incremental conversion of the old system to the new system.  For each function:

1.  Rewrite the function docstring expanding to better describe what the function is doing.  Convert to the epytext format for describing what data is input, what data is returned, etc.

2.  User function docstrings should not be converted to epytext format.  The variable __doctype__ should be set to 'plaintext' just after each docstring so that the API documentation can properly interpret the docstring.

3.  Write unit tests for the function to check all its expected behaviour.  This must be done prior to modifying the code.

4.  Remove all the 'run' arguments and the code accessing it.

5.  Add the 'pipes' argument to each user function in the 'prompt' directory to allow looping over a number of data pipes (Chris MacRaild, https://mail.gna.org/public/relax-devel/2006-10/msg00060.html, Message-id: <1160562239.14487.98.camel@mrspell>).

6.  Use the following code at the start if 'self.relax.data' is accessed by the function:
-----
# Alias the data for the current data pipe.
data = self.relax.data[self.relax.pipe]
-----
Then access the object 'data' throughout the function.



# Bugs and improvements.
########################

If bugs are found in the code the a bug report should be added to the relax bug tracker (https://gna.org/bugs/?group=relax).  The bug should be fixed and, if the 1.2 line is affected as well, then the revision can be requested to be back ported.

As large amounts of old code will be read, ideas for improvements will be inevitable.  If small, these improvements can be implemented on the spot.  Otherwise if the idea is large and disruptive, it can be lodged as a task (https://gna.org/task/?group=relax).
