mailr23775 - in /branches/frame_order_cleanup: ./ test_suite/shared_data/dispersion/profiling/profiling_cr72.py


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

Header


Content

Posted by edward on June 10, 2014 - 09:45:
Author: bugman
Date: Tue Jun 10 09:45:03 2014
New Revision: 23775

URL: http://svn.gna.org/viewcvs/relax?rev=23775&view=rev
Log:
Merged revisions 23720 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r23720 | tlinnet | 2014-06-06 22:03:27 +0200 (Fri, 06 Jun 2014) | 5 lines
  
  Modified profiling script, to get closer to the implementation in relax.
  
  An additional test function is setup to figure out how to reshape the numpy 
arrays in the target function.
  
  bug #22146: (https://gna.org/bugs/?22146) Unpacking of R2A and R2B is 
performed wrong for clustered "full" dispersion models.
........

Modified:
    branches/frame_order_cleanup/   (props changed)
    
branches/frame_order_cleanup/test_suite/shared_data/dispersion/profiling/profiling_cr72.py

Propchange: branches/frame_order_cleanup/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Jun 10 09:45:03 2014
@@ -1 +1 @@
-/trunk:1-23715
+/trunk:1-23715,23720

Modified: 
branches/frame_order_cleanup/test_suite/shared_data/dispersion/profiling/profiling_cr72.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/test_suite/shared_data/dispersion/profiling/profiling_cr72.py?rev=23775&r1=23774&r2=23775&view=diff
==============================================================================
--- 
branches/frame_order_cleanup/test_suite/shared_data/dispersion/profiling/profiling_cr72.py
  (original)
+++ 
branches/frame_order_cleanup/test_suite/shared_data/dispersion/profiling/profiling_cr72.py
  Tue Jun 10 09:45:03 2014
@@ -44,18 +44,18 @@
 # relax module imports.
 from lib.physical_constants import g1H, g15N
 from target_functions.relax_disp import Dispersion
-from specific_analyses.relax_disp.variables import EXP_TYPE_CPMG_SQ, 
MODEL_CR72, MODEL_CR72_FULL
+from specific_analyses.relax_disp.variables import EXP_TYPE_CPMG_SQ, 
MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_NS_CPMG_2SITE_3D_FULL, 
MODEL_NS_CPMG_2SITE_STAR_FULL
 
 
 # Alter setup.
 def main():
     s_filename = 'single'
     # Profile for a single spin.
-    cProfile.run('single(iter=1000)', s_filename)
+    cProfile.run('single(iter=100)', s_filename)
 
     c_filename = 'cluster'
     # Profile for a cluster of 100 spins.
-    cProfile.run('cluster(iter=1000)', c_filename)
+    cProfile.run('cluster(iter=100)', c_filename)
 
     # Read all stats files into a single object
     s_stats = pstats.Stats(s_filename)
@@ -93,8 +93,9 @@
         # Define parameters
         self.model = model
         self.num_spins = num_spins
+        #self.fields = [800. * 1E6]
         self.fields = [600. * 1E6, 800. * 1E6]
-        #self.fields = [800. * 1E6]
+        #self.fields = [600. * 1E6, 800. * 1E6, 900. * 1E6]
         self.exp_type = [EXP_TYPE_CPMG_SQ]
         self.offset = [0]
 
@@ -103,7 +104,7 @@
         self.ncyc_list = range(2, 2*self.num_points + 1, 2)
         self.relax_time = 0.04
         self.points = array(self.ncyc_list) / self.relax_time
-        self.value = ones(len(self.ncyc_list), float64) * 1.00
+        self.value = array(range(1,len(self.ncyc_list)+1), float64) * 1.00
         self.error = ones(len(self.ncyc_list), float64) * 0.01
 
         # Make nested list arrays of data. And return them.
@@ -129,9 +130,7 @@
         frqs_H = []
         relax_times = []
         offsets = []
-        cpmg_frqs = []
         for ei in range(len(self.exp_type)):
-            exp_type = self.exp_type[ei]
             values.append([])
             errors.append([])
             missing.append([])
@@ -139,7 +138,6 @@
             frqs_H.append([])
             relax_times.append([])
             offsets.append([])
-            cpmg_frqs.append([])
             for si in range(self.num_spins):
                 values[ei].append([])
                 errors[ei].append([])
@@ -148,22 +146,29 @@
                 frqs_H[ei].append([])
                 offsets[ei].append([])
                 for mi in range(len(self.fields)):
-                    frq = self.fields[mi]
                     values[ei][si].append([])
                     errors[ei][si].append([])
                     missing[ei][si].append([])
                     frqs[ei][si].append(0.0)
                     frqs_H[ei][si].append(0.0)
                     offsets[ei][si].append([])
-                    cpmg_frqs[ei].append([])
                     for oi in range(len(self.offset)):
                         values[ei][si][mi].append([])
                         errors[ei][si][mi].append([])
                         missing[ei][si][mi].append([])
                         offsets[ei][si][mi].append([])
-                        cpmg_frqs[ei][mi].append(self.points)
             for mi in range(len(self.fields)):
                 relax_times[ei].append(None)
+
+        cpmg_frqs = []
+        for ei in range(len(self.exp_type)):
+            cpmg_frqs.append([])
+            for mi in range(len(self.fields)):
+                cpmg_frqs[ei].append([])
+                for oi in range(len(self.offset)):
+                    #cpmg_frqs[ei][mi].append(self.points)
+                    cpmg_frqs[ei][mi].append([])
+
 
         # Pack the R2eff/R1rho data.
         si = 0
@@ -182,6 +187,8 @@
                         for di in range(len(self.points)):
                             # The Larmor frequency for this spin (and that 
of an attached proton for the MMQ models) and field strength (in MHz*2pi to 
speed up the ppm to rad/s conversion).
                             frqs[ei][si][mi] = 2.0 * pi * frq / g1H * g15N * 
1e-6
+
+                            cpmg_frqs[ei][mi][oi] = self.points
 
                             missing[ei][si][mi][oi].append(0)
 
@@ -208,7 +215,6 @@
                     for oi in range(len(self.offset)):
                         values[ei][si][mi][oi] = 
array(values[ei][si][mi][oi], float64)
                         errors[ei][si][mi][oi] = 
array(errors[ei][si][mi][oi], float64)
-                        cpmg_frqs[ei][mi][oi] = array(cpmg_frqs[ei][mi][oi], 
float64)
                         missing[ei][si][mi][oi] = 
array(missing[ei][si][mi][oi], int32)
 
         # Return the structures.
@@ -240,6 +246,40 @@
         param_vector = []
 
         # Loop over the parameters of the cluster.
+        for param_name, spin_index, mi in 
self.loop_parameters(spins_params=spins_params):
+            if param_name == 'r2':
+                value = r2
+                value = value + mi + spin_index*0.1
+            elif param_name == 'r2a':
+                value = r2a
+                value = value + mi+ spin_index*0.1
+            elif param_name == 'r2b':
+                value = r2b
+                value = value + mi + spin_index*0.1
+            elif param_name == 'dw':
+                value = dw + spin_index
+            elif param_name == 'pA':
+                value = pA
+            elif param_name == 'kex':
+                value = kex
+
+            # Add to the vector.
+            param_vector.append(value)
+
+        # Return a numpy array.
+        return array(param_vector, float64)
+
+
+    def loop_parameters(self, spins_params=None):
+        """Generator function for looping of the parameters of the cluster.
+
+        @keyword spins_params:  List of parameter strings used in dispersion 
model.
+        @type spins_params:     array of strings
+        @return:                The parameter name.
+        @rtype:                 str
+        """
+
+        # Loop over the parameters of the cluster.
         # First the R2 parameters (one per spin per field strength).
         for spin_index in range(self.num_spins):
 
@@ -247,36 +287,35 @@
             if 'r2' in spins_params:
                 for ei in range(len(self.exp_type)):
                     for mi in range(len(self.fields)):
-                        param_vector.append(r2)
+                        yield 'r2', spin_index, mi
 
             # The R2A parameter.
             if 'r2a' in spins_params:
                 for ei in range(len(self.exp_type)):
                     for mi in range(len(self.fields)):
-                        param_vector.append(r2a)
+                        yield 'r2a', spin_index, mi
+
 
             # The R2B parameter.
             if 'r2b' in spins_params:
                 for ei in range(len(self.exp_type)):
                     for mi in range(len(self.fields)):
-                        param_vector.append(r2b)
+                        yield 'r2b', spin_index, mi
+
 
         # Then the chemical shift difference parameters 'phi_ex', 
'phi_ex_B', 'phi_ex_C', 'padw2', 'dw', 'dw_AB', 'dw_BC', 'dw_AB' (one per 
spin).
         for spin_index in range(self.num_spins):
 
             if 'dw' in spins_params:
-                param_vector.append(dw)
+                yield 'dw', spin_index, 0
 
         # All other parameters (one per spin cluster).
         for param in spins_params:
             if not param in ['r2', 'r2a', 'r2b', 'phi_ex', 'phi_ex_B', 
'phi_ex_C', 'padw2', 'dw', 'dw_AB', 'dw_BC', 'dw_AB', 'dwH', 'dwH_AB', 
'dwH_BC', 'dwH_AB']:
                 if param == 'pA':
-                    param_vector.append(pA)
+                    yield 'pA', 0, 0
                 elif param == 'kex':
-                    param_vector.append(kex)
-
-        # Return a numpy array.
-        return array(param_vector, float64)
+                    yield 'kex', 0, 0
 
 
     def calc(self, params):
@@ -312,7 +351,7 @@
     C1 = Profile(num_spins=num_spins, num_points=num_points, model=model)
 
     # Assemble the parameter list.
-    params = C1.assemble_param_vector(r2a=2.0, r2b=4.0, dw=3.0, pA=0.95, 
kex=1000.0, spins_params=['r2a', 'r2b', 'dw', 'pA', 'kex'])
+    params = C1.assemble_param_vector(r2a=5.0, r2b=10.0, dw=3.0, pA=0.9, 
kex=1000.0, spins_params=['r2a', 'r2b', 'dw', 'pA', 'kex'])
 
     # Repeat the function call, to simulate minimisation.
     for i in xrange(iter):
@@ -338,7 +377,7 @@
     C1 = Profile(num_spins=num_spins, num_points=num_points, model=model)
 
     # Assemble the parameter list.
-    params = C1.assemble_param_vector(r2a=2.0, r2b=4.0, dw=3.0, pA=0.95, 
kex=1000.0, spins_params=['r2a', 'r2b', 'dw', 'pA', 'kex'])
+    params = C1.assemble_param_vector(r2a=5.0, r2b=10.0, dw=3.0, pA=0.9, 
kex=1000.0, spins_params=['r2a', 'r2b', 'dw', 'pA', 'kex'])
 
     # Repeat the function call, to simulate minimisation.
     for i in xrange(iter):
@@ -348,3 +387,53 @@
 # Execute main function.
 if __name__ == "__main__":
     main()
+
+def test_reshape():
+    C1 = Profile(num_spins=4, num_points=20, model=MODEL_CR72_FULL)
+    end_index = C1.model.end_index
+    print("end_index:", end_index)
+    num_spins = C1.model.num_spins
+    print("num_spins:", num_spins)
+    num_frq = C1.model.num_frq
+    print("num_frq:", num_frq)
+    params = C1.assemble_param_vector(r2a=5.0, r2b=10.0, dw=3.0, pA=0.9, 
kex=1000.0, spins_params=['r2a', 'r2b', 'dw', 'pA', 'kex'])
+    print("params", params)
+
+    R20 = params[:end_index[1]].reshape(num_spins*2, num_frq)
+    R20A = R20[::2].flatten()
+    R20B = R20[1::2].flatten()
+    dw = params[end_index[1]:end_index[2]]
+    pA = params[end_index[2]]
+    kex = params[end_index[2]+1]
+    print("R20A", R20A, len(R20A))
+    print("R20B", R20B, len(R20B))
+    print("dw", dw, len(dw))
+    print("dw", pA)
+    print("kex", kex)
+
+    for si in range(num_spins):
+        for mi in range(num_frq):
+            r20_index = mi + si*num_frq
+            r20a=R20A[r20_index]
+            r20b=R20B[r20_index]
+            print "r20a", r20a, "r20b", r20b
+
+    for mi in range(num_frq):
+        mi_s = mi*num_spins
+        mi_e = mi_s + num_spins
+        r20a=R20A[mi_s:mi_e]
+        r20b=R20B[mi_s:mi_e]
+        print "r20a", r20a, "r20b", r20b
+
+    values = array(C1.model.values)
+    values = array(values)
+    ex = values
+    # (1, 4, 3, 1, 20): ex, spin, frq, off, disp
+    #print type(ex), len(ex), ex.shape, ex
+    ex2 = ex.reshape(num_frq*20*num_spins)
+    #print type(ex2), len(ex2), ex2.shape, ex2
+    #print "here"
+    model = C1.calc(params)
+    print model
+
+#test_par()




Related Messages


Powered by MHonArc, Updated Tue Jun 10 10:00:02 2014