[https://mail.gna.org/public/relax-devel/2013-06/msg00016.html See mail archive]
The following is a tutorial for adding new relaxation dispersionmodels for either CPMG-type or R1rho-type experiments to relax. Thisincludes both the models based on the analytical, closed-formexpressions as well as the models involving numerical integration solutions ofthe Bloch-McConnell equations.
The tutorial will follow the example of the addition of the 'M61'model already present within relax, pointing to the relevant commitsfor reference. To see the commit message and the code changes incolour, click on the links found within these commit messages. Thisspecific case is the Meiboom 1961 analytic model for 2-site fastexchange equation for R1rho-type experiments.
Reference commit: http://article.gmane.org/gmane.science.nmr.relax.scm/17611
Firstly the model should be added to the lists of thespecific_analyses.relax_disp.variables module. The model name isstored in a special variable which will be used throughout relax.
Reference commit: http://article.gmane.org/gmane.science.nmr.relax.scm/17612
The next step is to add the model, its description, the equations forthe analytic models, and all references to the relax_disp.select_modeluser function front end. When the relaxation dispersion chapter ofthe relax [[manual]] is created (this will be thedocs/latex/relax_disp.tex file), then the same description should beadded there as well.
=== The relax library ===
Reference commit: http://article.gmane.org/gmane.science.nmr.relax.scm/17615
Now the dispersion function needs to be added to the relax library (inthe lib.relax_disp package). This should be designed as a simplePython function which takes the dispersion parameters and experimentalvariables, and calculates the R2eff/R1rho values. The module cancontain auxiliary functions for the calculation. Some auxiliaryfunctions, if not specific to relaxation dispersion, may be betterplaced in other locations within the relax library.
The relaxation dispersion functions in the library currently take asan argument a data structure for the back-calculated R2eff/R1rhovalues and populate this structure. This design is not essential ifthe target function, described in the next point, handles the libraryfunction appropriately. Just look at the files in lib/dispersion toget an idea of the design used.
The dispersion code in the relax library must be robust. Thisinvolves identifying parameter values or combinations which wouldcause failures in the mathematical operations (numerical issues notpresent in the mathematics must be considered). Note that parametervalues of 0 are common within a grid search. It should be decided ifthe R2eff/R1rho value should be set to zero, to another value, or tosomething large (e.g. 1e100). For example:
Divisions - always catch zeros in the denominator with if statements,even if you believe that this will never be encountered. Square roots - make sure that the value inside is always > 0. Trigonometric functions - these should be tested for where they arenot defined or where the software implementation can no longer handlecertain values. For example try cosh(1000) in Python.
In the reference example, the M61 model code was copied from the LM63module and modified appropriately.