mailr7458 - /branches/pipe_refs/sample_scripts/relax_curve_diff.py


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

Header


Content

Posted by edward on September 30, 2008 - 17:16:
Author: bugman
Date: Tue Sep 30 17:16:15 2008
New Revision: 7458

URL: http://svn.gna.org/viewcvs/relax?rev=7458&view=rev
Log:
Converted the relax_curve_diff.py sample script to the new design.

This was identified by the unnecessary import of the relax data storage 
object.


Modified:
    branches/pipe_refs/sample_scripts/relax_curve_diff.py

Modified: branches/pipe_refs/sample_scripts/relax_curve_diff.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/pipe_refs/sample_scripts/relax_curve_diff.py?rev=7458&r1=7457&r2=7458&view=diff
==============================================================================
--- branches/pipe_refs/sample_scripts/relax_curve_diff.py (original)
+++ branches/pipe_refs/sample_scripts/relax_curve_diff.py Tue Sep 30 17:16:15 
2008
@@ -1,7 +1,25 @@
-# Script:   relax_curve_diff.py
-# Author:   Edward d'Auvergne
-# Email:    edward at nmr-relax dot com
-#
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2007-2008 Edward d'Auvergne                                  
 #
+#                                                                            
 #
+# This file is part of the program relax.                                    
 #
+#                                                                            
 #
+# relax is free software; you can redistribute it and/or modify              
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation; either version 2 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# relax is distributed in the hope that it will be useful,                   
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with relax; if not, write to the Free Software                       
 #
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  
 #
+#                                                                            
 #
+###############################################################################
+
 # This script creates a Grace plot of Ix - Ix(theta), the difference between 
the measured peak
 # intensity and the back calculated peak intensity for each spin system x.  
Ix(theta) is back
 # calculated using the parameter vector theta = [Rx, I0], where Rx is either 
the R1 or R2 relaxation
@@ -18,7 +36,7 @@
 # extensions).  The file name of the saved state can be changed at the 
bottom of this script.  It is
 # important to note that the same version of relax should be used for 
creating the saved state as
 # reading the program state, these files are neither backwards nor forwards 
compatible.  The name of
-# the run using in the curve fitting is expected to be 'rx' but this can 
also be changed at the
+# the data pipe using in the curve fitting is expected to be 'rx' but this 
can also be changed at
 # bottom of the script.  Only the two parameter exponential fit is currently 
supported.
 
 
@@ -26,21 +44,26 @@
 from numpy import float64, array, identity, sqrt, zeros
 
 # relax module imports.
-from data import Relax_data_store; ds = Relax_data_store()
+from generic_fns.mol_res_spin import spin_loop
+from generic_fns import pipes
 from maths_fns.relax_fit import back_calc_I, func, setup
 
 
-# The relax data storage object.
-
-
-def back_calc(name):
+# The name of the save file generated by 'relax_fit.py'.
+SAVE_FILE = 'rx.save'
+
+
+def back_calc():
     """Back calculate the peak intensities.
 
     The simple two parameter exponential curve (Rx, I0) is assumed.
     """
 
+    # Get the current data pipe.
+    cdp = pipes.get_pipe()
+
     # Loop over the spins.
-    for spin in ds.res[name]:
+    for spin in spin_loop()
         # Skip deselected spins.
         if not spin.select:
             continue
@@ -49,7 +72,7 @@
         param_vector = array([spin.rx, spin.i0], float64)
 
         # Initialise the relaxation fit functions.
-        setup(num_params=len(spin.params), 
num_times=len(ds.relax_times[name]), values=spin.ave_intensities, 
sd=ds.sd[name], relax_times=ds.relax_times[name], scaling_matrix=identity(2, 
float64))
+        setup(num_params=len(spin.params), num_times=len(cdp.relax_times), 
values=spin.ave_intensities, sd=cdp.sd, relax_times=cdp.relax_times, 
scaling_matrix=identity(2, float64))
 
         # Make a single function call.  This will cause back calculation and 
the data will be stored in the C module.
         func(param_vector)
@@ -71,9 +94,12 @@
     and Xav is the peak intensity difference averaged across all spins.
     """
 
+    # Get the current data pipe.
+    cdp = pipes.get_pipe()
+
     # Diff array, std deviation array, and number of spins.
-    diff_array = zeros(sum(ds.num_spectra[name]), float64)
-    sd_array = zeros(sum(ds.num_spectra[name]), float64)
+    diff_array = zeros(sum(cdp.num_spectra), float64)
+    sd_array = zeros(sum(cdp.num_spectra), float64)
     num_spins = 0
 
 
@@ -81,7 +107,7 @@
     ###################################
 
     # Loop over the spins.
-    for spin in ds.res[name]:
+    for spin in spin_loop()
         # Skip deselected spins.
         if not spin.select:
             continue
@@ -107,7 +133,7 @@
     ####################################
 
     # Loop over the spins.
-    for spin in ds.res[name]:
+    for spin in spin_loop()
         # Skip deselected spins.
         if not spin.select:
             continue
@@ -185,8 +211,11 @@
     file.write("@    s2 line linestyle 3\n")
 
 
-def grace_plot(ave, sd, name):
+def grace_plot(ave, sd):
     """Grace plot of the intensity differences."""
+
+    # Get the current data pipe.
+    cdp = pipes.get_pipe()
 
     # Open the file.
     file = open('differences.agr', 'w')
@@ -196,7 +225,7 @@
     ymax = 2.5*max(ave + sd)
 
     # Grace header.
-    grace_header(file, xmin=0, xmax=ds.relax_times[name][-1], ymin=ymin, 
ymax=ymax)
+    grace_header(file, xmin=0, xmax=cdp.relax_times[-1], ymin=ymin, 
ymax=ymax)
 
 
     # First time point difference distributions.
@@ -207,15 +236,15 @@
     file.write("@type xy\n")
 
     # Loop over the individual time points.
-    for i in xrange(len(ds.num_spectra[name])):
+    for i in xrange(len(cdp.num_spectra)):
         # Loop over the spins.
-        for spin in ds.res[name]:
+        for spin in spin_loop():
             # Skip deselected spins.
             if not spin.select:
                 continue
 
             # Grace data point.
-            file.write("%-30s%-30s\n" % (`ds.relax_times[name][i]`, 
`spin.intensities[i][0] - spin.fit_int[i]`))
+            file.write("%-30s%-30s\n" % (`cdp.relax_times[i]`, 
`spin.intensities[i][0] - spin.fit_int[i]`))
 
     # End the graph.
     file.write("&\n")
@@ -229,16 +258,16 @@
     file.write("@type xy\n")
 
     # Loop over the individual time points.
-    for i in xrange(len(ds.num_spectra[name])):
+    for i in xrange(len(cdp.num_spectra)):
         # Loop over the spins.
-        for spin in ds.res[name]:
+        for spin in spin_loop():
             # Skip deselected spins.
             if not spin.select:
                 continue
 
             # Grace data point.
             if len(spin.intensities[i]) == 2:
-                file.write("%-30s%-30s\n" % (`ds.relax_times[name][i]`, 
`spin.intensities[i][1] - spin.fit_int[i]`))
+                file.write("%-30s%-30s\n" % (`cdp.relax_times[i]`, 
`spin.intensities[i][1] - spin.fit_int[i]`))
 
     # End the graph.
     file.write("&\n")
@@ -253,10 +282,10 @@
 
     # Loop over the data.
     index = 0
-    for i in xrange(len(ds.num_spectra[name])):
-        for j in xrange(ds.num_spectra[name][i]):
+    for i in xrange(len(cdp.num_spectra)):
+        for j in xrange(cdp.num_spectra[i]):
             # Grace data point.
-            file.write("%-30s%-30s%-30s\n" % (`ds.relax_times[name][i]`, 
`ave[index]`, `sd[index]`))
+            file.write("%-30s%-30s%-30s\n" % (`cdp.relax_times[i]`, 
`ave[index]`, `sd[index]`))
 
             # Increment the index.
             index = index + 1
@@ -269,19 +298,16 @@
 
 
 # Load the program state containing saved by the 'relax_fit.py' sample 
script.
-state.load('rx.save')
-
-# The name of the run from the 'relax_fit.py' sample script.
-name = 'rx'
+state.load(SAVE_FILE)
 
 # Back calculate the peak intensities from the fitted parameters.
-back_calc(name)
+back_calc()
 
 # Calculate the average difference and standard deviations for each time 
point.
 ave, sd = calc_ave_sd()
 
 # Create a Grace plot of the differences.
-grace_plot(ave, sd, name)
+grace_plot(ave, sd)
 
 # View the graph.
 grace.view(file='differences.agr', dir=None)




Related Messages


Powered by MHonArc, Updated Tue Sep 30 17:20:03 2008