Open main menu

Relax source design

Revision as of 07:52, 20 September 2014 by Bugman (talk | contribs) (→‎Package: specific_analyses: Added a package layout description.)

The following is a set of notes which will be used to design the layout of functions, modules, and packages in relax.


Packages

Package: data_store

Package: lib

Package: pipe_control

Package: specific_analyses

The package layout of modules is as follows:

  • api - the specific analysis API. This module provides a class that inherits from specific_analyses.api_base.API_base (and optionally specific_analysis.api_common.API_common). This class is initialised as a singleton object and returned by the specific_analyses.api.return_api() function.
  • checks - all functions for performing analysis specific Relax_source_design#The_check_.2A.28.29_functions checks.
  • data - a module of all functions for handling the base data for the analysis.
  • model - a module of all functions for handling the models of the analysis.
  • optimisation - all functions related to optimisation which are not part of the specific analysis API.
  • parameter_object - the parameter list singleton object for the specific analysis. This provides a class that inherits from specific_analysis.parameter_object.Param_list. This class is initialised and returned by the specific_analyses.api.return_parameter_list() function.
  • parameters - all functions relating to the model parameters.
  • uf - the user function backends. Any analysis specific user functions in user_functions should call functions in this module.
  • variables - a module containing all fixed variables for the analysis.

General

The check_*() functions

These functions are for performing checks for certain data being present. They can return True or False, throw RelaxWarnings, or raise RelaxErrors.

Packages

These functions are found in the pipe_control and specific_analyses packages:

  • pipe_control: The check_*() functions are located in the individual modules of this package.
  • specific_analyses: For these packages, a special 'checks' module should be created for these functions.

Design

The check_*() functions should have the 'escalate' keyword argument which can have the following values:

  • 0 - This will simply cause the function to return True or False.
  • 1 - In addition to returning True or False, the function will throw a RelaxWarning for better user feedback.
  • 2 - This will cause a RelaxError to be raised if the data is missing, not set up, etc. Otherwise the function returns True.

Implementation

Here is a prototype function:

# Python module imports.
from warnings import warn

# relax module imports.
from lib.errors import RelaxError
from lib.warnings import RelaxWarning


def check_xxx(escalate=0):
    """Check if xxx.

    @keyword escalate:      The feedback to give if the check fails.  This can be 0 for no printouts, 1 to throw a RelaxWarning, or 2 to raise a RelaxError.
    @type escalate:         int
    @raises RelaxError:     If escalate is set to 2 and the check fails.
    @return:                True if the check passes, False otherwise.
    @rtype:                 bool
    """

    # Init.
    flag = True
    msg = ''

    # Check that...
    if not something():
        flag = False
        msg = "Something is missing."

    # Warnings and errors.
    if not flag and escalate == 1:
        warn(RelaxWarning(msg))
    elif not flag and escalate == 2:
        raise RelaxError(msg)

    # Return the answer.
    return flag