mailr19790 - in /branches/relax_disp: graphics/relax_icons/16x16/ specific_analyses/relax_disp/ user_functions/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on May 30, 2013 - 13:44:
Author: bugman
Date: Thu May 30 13:44:49 2013
New Revision: 19790

URL: http://svn.gna.org/viewcvs/relax?rev=19790&view=rev
Log:
Created the relax_disp.sherekhan_input user function.

This includes an icon for the GUI, and the full front and backends.


Added:
    branches/relax_disp/graphics/relax_icons/16x16/sherekhan.png   (with 
props)
    branches/relax_disp/specific_analyses/relax_disp/sherekhan.py
      - copied, changed from r19778, 
branches/relax_disp/specific_analyses/relax_disp/cpmgfit.py
Modified:
    branches/relax_disp/user_functions/relax_disp.py

Added: branches/relax_disp/graphics/relax_icons/16x16/sherekhan.png
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/graphics/relax_icons/16x16/sherekhan.png?rev=19790&view=auto
==============================================================================
Binary file - no diff available.

Propchange: branches/relax_disp/graphics/relax_icons/16x16/sherekhan.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Copied: branches/relax_disp/specific_analyses/relax_disp/sherekhan.py (from 
r19778, branches/relax_disp/specific_analyses/relax_disp/cpmgfit.py)
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/sherekhan.py?p2=branches/relax_disp/specific_analyses/relax_disp/sherekhan.py&p1=branches/relax_disp/specific_analyses/relax_disp/cpmgfit.py&r1=19778&r2=19790&rev=19790&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/cpmgfit.py (original)
+++ branches/relax_disp/specific_analyses/relax_disp/sherekhan.py Thu May 30 
13:44:49 2013
@@ -20,7 +20,7 @@
 
###############################################################################
 
 # Module docstring.
-"""Functions for interfacing with Art Palmer's CPMGFit program."""
+"""Functions for interfacing with Adam Mazur's ShereKhan program."""
 
 # Dependencies.
 import dep_check
@@ -36,96 +36,19 @@
 
 # relax module imports.
 from lib.errors import RelaxError, RelaxDirError, RelaxFileError, 
RelaxNoSequenceError
-from lib.io import mkdir_nofail, open_write_file, test_binary
-from lib.physical_constants import g1H
+from lib.io import mkdir_nofail, open_write_file
+from lib.physical_constants import g1H, g15N
 from pipe_control import pipes
 from pipe_control.spectrometer import get_frequencies
 from pipe_control.mol_res_spin import exists_mol_res_spin_data, spin_loop
-from specific_analyses.relax_disp.disp_data import loop_frq_point, 
return_param_key_from_data
+from specific_analyses.relax_disp.disp_data import loop_frq, loop_point, 
return_param_key_from_data
 
 
-def cpmgfit_execute(dir=None, binary='cpmgfit', force=False):
-    """Execute CPMGFit for each spin input file.
-
-    @keyword dir:       The directory where the input files are located.  If 
None, this defaults to the dispersion model name in lowercase.
-    @type dir:          str or None
-    @keyword binary:    The name of the CPMGFit binary file.  This can 
include the path to the binary.
-    @type binary:       str
-    @keyword force:     A flag which if True will cause any pre-existing 
files to be overwritten by CPMGFit.
-    @type force:        bool
-    """
-
-    # Test if the current pipe exists.
-    pipes.test()
-
-    # Test if sequence data is loaded.
-    if not exists_mol_res_spin_data():
-        raise RelaxNoSequenceError
-
-    # Test if the experiment type has been set.
-    if not hasattr(cdp, 'exp_type'):
-        raise RelaxError("The relaxation dispersion experiment type has not 
been specified.")
-
-    # Test if the model has been set.
-    if not hasattr(cdp, 'model'):
-        raise RelaxError("The relaxation dispersion model has not been 
specified.")
-
-    # Translate the model.
-    function = translate_model()
-
-    # The directory.
-    if dir == None:
-        dir = lower(cdp.model)
-    if not access(dir, F_OK):
-        raise RelaxDirError('CPMGFit', dir)
-
-    # Loop over each spin.
-    for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
-        # The spin input file name.
-        file_in = dir + sep + spin_file_name(spin_id=spin_id)
-        if not access(file_in, F_OK):
-            raise RelaxFileError("spin input", file_in)
-
-        # The spin output file name.
-        file_out = dir + sep + spin_file_name(spin_id=spin_id, output=True)
-
-        # Test the binary file string corresponds to a valid executable.
-        test_binary(binary)
-
-        # Execute CPMGFit.
-        cmd = "%s -grid -xmgr -f %s | tee %s\n" % (binary, file_in, file_out)
-        print("\n\n%s" % cmd)
-        pipe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, 
close_fds=False)
-
-        # Close the pipe.
-        pipe.stdin.close()
-
-        # Write to stdout.
-        for line in pipe.stdout.readlines():
-            # Decode Python 3 byte arrays.
-            if hasattr(line, 'decode'):
-                line = line.decode()
-
-            # Write.
-            sys.stdout.write(line)
-
-        # Write to stderr.
-        for line in pipe.stderr.readlines():
-            # Decode Python 3 byte arrays.
-            if hasattr(line, 'decode'):
-                line = line.decode()
-
-            # Write.
-            sys.stderr.write(line)
-
-
-def cpmgfit_input(dir=None, binary='cpmgfit', spin_id=None, force=False):
-    """Create the CPMGFit input files.
+def sherekhan_input(dir=None, spin_id=None, force=False):
+    """Create the ShereKhan input files.
 
     @keyword dir:               The optional directory to place the files 
into.  If None, then the files will be placed into a directory named after 
the dispersion model.
     @type dir:                  str or None
-    @keyword binary:            The name of the CPMGFit binary file.  This 
can include the path to the binary.
-    @type binary:               str
     @keyword spin_id:           The spin ID string to restrict the file 
creation to.
     @type spin_id:              str
     @keyword force:             A flag which if True will cause all 
pre-existing files to be overwritten.
@@ -147,141 +70,53 @@
     if not hasattr(cdp, 'model'):
         raise RelaxError("The relaxation dispersion model has not been 
specified.")
 
-    # Translate the model.
-    function = translate_model()
+    # Test that this is a fixed time period experiment.
+    if len(cdp.relax_time_list) != 1:
+            raise RelaxError("ShereKhan only supports the fixed time 
relaxation dispersion experiments.")
 
     # Directory creation.
     if dir == None:
         dir = lower(cdp.model)
     mkdir_nofail(dir, verbosity=0)
 
-    # The 'run.sh' script.
-    batch = open_write_file('batch_run.sh', dir, force)
-    batch.write("#! /bin/sh\n\n")
+    # Loop over the magnetic fields.
+    frq_index = 0
+    for frq in loop_frq():
+        # The ShereKhan input file.
+        file = open_write_file('sherekhan_%s.py' % (frq_index+1), dir, force)
 
-    # Generate the input files for each spin.
-    for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
-        file_name = create_spin_input(function=function, spin=spin, 
spin_id=spin_id, dir=dir)
+        # The B0 field for the nuclei of interest in MHz.
+        file.write("%s\n" % (frq / g1H * g15N / 1e6))
 
-        # Add the file to the batch script.
-        batch.write("%s -xmgr -f %s\n" % (binary, file_name))
+        # The constant relaxation time for the CPMG experiment in seconds.
+        file.write("%s\n" % (cdp.relax_time_list[0]))
 
-    # Close the batch script, then make it executable.
-    batch.close()
-    chmod(dir + sep + 'batch_run.sh', 0755)
+        # The comment line.#nu_cpmg(Hz) R2(1/s) Esd(R2))
+        file.write("# %-18s %-20s %-20s\n" % ("nu_cpmg (Hz)", "R2eff 
(rad/s)", "Error"))
 
+        # Generate the input files for each spin.
+        for spin, mol_name, res_num, res_name, id in 
spin_loop(full_info=True, selection=spin_id, return_id=True, skip_desel=True):
+            # Name the residue if needed.
+            if res_name == None:
+                res_name = 'X'
 
-def create_spin_input(function=None, spin=None, spin_id=None, dir=None):
-    """Generate the CPMGFit file for the given spin.
+            # The residue ID line.
+            file.write("# %s%s\n" % (res_name, res_num))
 
-    @keyword function:  The CPMGFit model or function name.
-    @type function:     str
-    @keyword spin:      The spin container to generate the input file for.
-    @type spin:         SpinContainer instance
-    @keyword spin_id:   The spin ID string corresponding to the spin 
container.
-    @type spin_id:      str
-    @keyword dir:       The directory to place the file into.
-    @type dir:          str or None
-    @return:            The name of the file created.
-    @rtype:             str
-    """
+            # Loop over the dispersion points.
+            for point in loop_point(skip_ref=True):
+                # The parameter key.
+                param_key = return_param_key_from_data(frq=frq, point=point)
 
-    # The output file.
-    file_name = spin_file_name(spin_id=spin_id)
-    file = open_write_file(file_name=file_name, dir=dir, force=True)
+                # No data.
+                if param_key not in spin.r2eff:
+                    continue
 
-    # The title.
-    file.write("title %s\n" % spin_id)
+                # Write out the data.
+                file.write("%20.15g %20.15g %20.15g\n" % (point, 
spin.r2eff[param_key], spin.r2eff_err[param_key]))
 
-    # The proton frequencies.
-    frq = get_frequencies(units='T')
+        # Close the file.
+        file.close()
 
-    # The frequency info.
-    file.write("fields %s" % len(frq))
-    for i in range(len(frq)):
-        file.write(" %s" % frq[i])
-    file.write("\n")
-
-    # The function and parameters.
-    if function == 'CPMG':
-        # Function.
-        file.write("function CPMG\n")
-
-        # Parameters.
-        file.write("R2 1 10 20\n")
-        file.write("Rex 0 100.0 100\n")
-        file.write("tex 0 10.0 100\n")
-
-    # The Grace setup.
-    file.write("xmgr\n")
-    file.write("@ xaxis label \"1/tcp (1/ms)\"\n")
-    file.write("@ yaxis label \"R2(tcp) (rad/s)\"\n")
-    file.write("@ xaxis ticklabel format decimal\n")
-    file.write("@ yaxis ticklabel format decimal\n")
-    file.write("@ xaxis ticklabel char size 0.8\n")
-    file.write("@ yaxis ticklabel char size 0.8\n")
-    file.write("@ world xmin 0.0\n")
-
-    # The data.
-    file.write("data\n")
-    for frq, point in loop_frq_point():
-        # The parameter key.
-        param_key = return_param_key_from_data(frq=frq, point=point)
-
-        # No data.
-        if param_key not in spin.r2eff:
-            continue
-
-        # Tesla units.
-        B0 = frq * 2.0 * pi / g1H
-
-        # Write out the data and error.
-        file.write("%-20f %-20f %-20f %-20f\n" % (point/1000.0, 
spin.r2eff[param_key], spin.r2eff_err[param_key], B0))
-
-    # Close the file and return its name.
-    file.close()
-    return file_name
-
-
-def spin_file_name(spin_id=None, output=False):
-    """Generate the unique file name for the given spin ID.
-
-    @keyword spin_id:   The spin ID string.
-    @type spin_id:      str
-    @keyword output:    A flag which if True will cause the CPMGFit output 
rather than input name to be returned.
-    @return:            The file name.
-    @rtype:             str
-    """
-
-    # Construct the name.
-    name = "spin_%s." % spin_id
-    if output:
-        name += "out"
-    else:
-        name += "in"
-
-    # Return the file name.
-    return name
-
-
-def translate_model():
-    """Translate the dispersion model from relax notation to CPMGFit 
notation.
-
-    @return:    The CPMGFit model name.
-    @rtype:     str
-    """
-
-    # A translation table (relax to CPMGFit models).
-    translation = {
-        'LM63': 'CPMG'
-    }
-
-    # No translation, so fail.
-    if cdp.model not in translation:
-        raise RelaxError("The conversion of the relax model '%s' to a 
CPMGFit model is not supported." % cdp.model)
-
-    # Printout.
-    print("Translating the relax '%s' model to the CPMGFit '%s' model." % 
(cdp.model, translation[cdp.model]))
-
-    # Return the translated name.
-    return translation[cdp.model]
+        # Increment the field index.
+        frq_index += 1

Modified: branches/relax_disp/user_functions/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/user_functions/relax_disp.py?rev=19790&r1=19789&r2=19790&view=diff
==============================================================================
--- branches/relax_disp/user_functions/relax_disp.py (original)
+++ branches/relax_disp/user_functions/relax_disp.py Thu May 30 13:44:49 2013
@@ -36,8 +36,9 @@
 from pipe_control.mol_res_spin import get_spin_ids
 from graphics import ANALYSIS_IMAGE_PATH, WIZARD_IMAGE_PATH
 from specific_analyses.relax_disp.cpmgfit import cpmgfit_execute, 
cpmgfit_input
+from specific_analyses.relax_disp.disp_data import cpmg_frq, relax_time, 
spin_lock_field
 from specific_analyses.relax_disp.nessy import nessy_input
-from specific_analyses.relax_disp.disp_data import cpmg_frq, relax_time, 
spin_lock_field
+from specific_analyses.relax_disp.sherekhan import sherekhan_input
 from specific_analyses.relax_disp.variables import MODEL_CR72, MODEL_LM63, 
MODEL_R2EFF
 from specific_analyses.setup import relax_disp_obj
 from user_functions.data import Uf_info; uf_info = Uf_info()
@@ -556,6 +557,43 @@
 uf.wizard_image = ANALYSIS_IMAGE_PATH + 'relax_disp_200x200.png'
 
 
+# The relax_disp.sherekhan_input user function.
+uf = uf_info.add_uf('relax_disp.sherekhan_input')
+uf.title = "Create the input files for Adam Mazur's ShereKhan program."
+uf.title_short = "ShereKhan input file creation."
+uf.add_keyarg(
+    name = "dir",
+    py_type = "str",
+    arg_type = "dir sel",
+    desc_short = "directory name",
+    desc = "The directory to place the files.  If not given, this defaults 
to the model name in lower case.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "force",
+    default = False,
+    py_type = "bool",
+    desc_short = "force flag",
+    desc = "A flag which if set to True will cause the files to be 
overwritten if they already exist."
+)
+uf.add_keyarg(
+    name = "spin_id",
+    py_type = "str",
+    desc_short = "spin ID string",
+    desc = "The spin identification string.",
+    can_be_none = True
+)
+# Description.
+uf.desc.append(Desc_container())
+uf.desc[-1].add_paragraph("This creates the files required for the ShereKhan 
server located at http://sherekhan.bionmr.org/.  One file per field strength 
will be created.  These will be named 'dir/sherekhan_x.in', where x is a 
number starting from 1 and dir is the specified directory which if not given 
defaults to the model name in lower case.")
+uf.backend = sherekhan_input
+uf.menu_text = "&sherekhan_input"
+uf.gui_icon = "relax.sherekhan"
+uf.wizard_size = (800, 500)
+uf.wizard_apply_button = False
+uf.wizard_image = ANALYSIS_IMAGE_PATH + 'relax_disp_200x200.png'
+
+
 # The relax_disp.spin_lock_field user function.
 uf = uf_info.add_uf('relax_disp.spin_lock_field')
 uf.title = "Set the relaxation dispersion spin-lock field strength (nu1)."




Related Messages


Powered by MHonArc, Updated Thu May 30 14:20:02 2013