mailr20997 - in /branches/relax_disp: specific_analyses/relax_disp/catia.py user_functions/relax_disp.py


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

Header


Content

Posted by edward on September 13, 2013 - 11:53:
Author: bugman
Date: Fri Sep 13 11:53:38 2013
New Revision: 20997

URL: http://svn.gna.org/viewcvs/relax?rev=20997&view=rev
Log:
Implemented the relax_disp.catia_execute user function.

This is modelled on the palmer.execute user function.


Modified:
    branches/relax_disp/specific_analyses/relax_disp/catia.py
    branches/relax_disp/user_functions/relax_disp.py

Modified: branches/relax_disp/specific_analyses/relax_disp/catia.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_disp/catia.py?rev=20997&r1=20996&r2=20997&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_disp/catia.py (original)
+++ branches/relax_disp/specific_analyses/relax_disp/catia.py Fri Sep 13 
11:53:38 2013
@@ -22,16 +22,88 @@
 # Module docstring.
 """Functions for interfacing with Flemming Hansen's CATIA program."""
 
+# Dependencies.
+import dep_check
+
 # Python module imports.
-from os import sep
+from os import F_OK, access, chdir, getcwd, sep
+PIPE, Popen = None, None
+if dep_check.subprocess_module:
+    from subprocess import PIPE, Popen
+import sys
 
 # relax module imports.
-from lib.errors import RelaxError
-from lib.io import mkdir_nofail, open_write_file
+from lib.errors import RelaxError, RelaxDirError
+from lib.io import mkdir_nofail, open_write_file, test_binary
 from pipe_control import pipes
 from pipe_control.mol_res_spin import check_mol_res_spin_data, spin_loop
 from specific_analyses.relax_disp.checks import check_model_type, 
check_spectra_id_setup
 from specific_analyses.relax_disp.disp_data import loop_frq, loop_point, 
return_param_key_from_data
+
+
+def catia_execute(file='Fit.catia', dir=None, binary=None):
+    """Create the CATIA input files.
+
+    @keyword file:          The main CATIA execution file.
+    @type file:             str
+    @keyword dir:           The optional directory to place the files into.  
If None, then the files will be placed into the current directory.
+    @type dir:              str or None
+    @keyword binary:        The name of the CATIA binary file.  This can 
include the path to the binary.
+    @type binary:           str
+    """
+
+    # The current directory.
+    orig_dir = getcwd()
+
+    # Test the binary file string corresponds to a valid executable.
+    test_binary(binary)
+
+    # The directory.
+    if dir == None:
+        dir = orig_dir
+    if not access(dir, F_OK):
+        raise RelaxDirError('CATIA', dir)
+
+    # Change to the directory with the CATIA input files.
+    chdir(dir)
+
+    # Catch failures and return to the correct directory.
+    try:
+        # Execute CATIA.
+        cmd = binary + ' < Fit.catia'
+        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)
+
+    # Failure.
+    except:
+        # Change back to the original directory.
+        chdir(orig_dir)
+
+        # Reraise the error.
+        raise
+
+    # Change back to the original directory.
+    chdir(orig_dir)
 
 
 def catia_input(file='Fit.catia', dir=None, output_dir='output', 
force=False):

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=20997&r1=20996&r2=20997&view=diff
==============================================================================
--- branches/relax_disp/user_functions/relax_disp.py (original)
+++ branches/relax_disp/user_functions/relax_disp.py Fri Sep 13 11:53:38 2013
@@ -36,7 +36,7 @@
 from graphics import ANALYSIS_IMAGE_PATH, WIZARD_IMAGE_PATH
 from pipe_control import pipes, spectrum
 from pipe_control.mol_res_spin import get_spin_ids
-from specific_analyses.relax_disp.catia import catia_input
+from specific_analyses.relax_disp.catia import catia_execute, catia_input
 from specific_analyses.relax_disp.cpmgfit import cpmgfit_execute, 
cpmgfit_input
 from specific_analyses.relax_disp.disp_data import cpmg_frq, exp_type, 
plot_disp_curves, plot_exp_curves, relax_time, spin_lock_field, 
spin_lock_offset
 from specific_analyses.relax_disp.nessy import nessy_input
@@ -53,6 +53,41 @@
 uf_class.title = "Class for relaxation curve fitting."
 uf_class.menu_text = "&relax_disp"
 uf_class.gui_icon = "relax.relax_disp"
+
+
+# The relax_disp.catia_execute user function.
+uf = uf_info.add_uf('relax_disp.catia_execute')
+uf.title = "Perform a relaxation dispersion optimisation using Flemming 
Hansen's CATIA."
+uf.title_short = "CATIA execution."
+uf.add_keyarg(
+    name = "dir",
+    py_type = "str",
+    arg_type = "dir sel",
+    desc_short = "directory name",
+    desc = "The directory containing all of the CATIA input files.",
+    can_be_none = True
+)
+uf.add_keyarg(
+    name = "binary",
+    default = "catia",
+    py_type = "str",
+    arg_type = "file sel",
+    desc_short = "CATIA executable file",
+    desc = "The name of the executable CATIA program file.",
+    wiz_filesel_style = FD_OPEN,
+    wiz_filesel_preview = False
+)
+# Description.
+uf.desc.append(Desc_container())
+uf.desc[-1].add_paragraph("CATIA will be executed as")
+uf.desc[-1].add_prompt("$ catia < Fit.catia")
+uf.desc[-1].add_paragraph("If you would like to use a different CATIA 
executable file, change the binary name to the appropriate file name.  If the 
file is not located within the environment's path, include the full path in 
front of the binary file name.")
+uf.backend = catia_execute
+uf.gui_icon = "oxygen.categories.applications-education"
+uf.menu_text = "catia_e&xecute"
+uf.wizard_size = (800, 600)
+uf.wizard_apply_button = False
+uf.wizard_image = ANALYSIS_IMAGE_PATH + 'relax_disp_200x200.png'
 
 
 # The relax_disp.catia_input user function.




Related Messages


Powered by MHonArc, Updated Fri Sep 13 12:00:01 2013