mailRe: r26152 - /trunk/specific_analyses/relax_disp/api.py


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

Header


Content

Posted by Edward d'Auvergne on October 06, 2014 - 15:30:
Hi Troels,

The correct and really only way to do this would be to use the
dispersion API model_loop() generator method, which yields a list of
spin IDs.  You can then check if the spin_id argument is in this list
within the methods that require it, and if not then just use the
Python 'continue' statement.  The intent of the model_loop() method is
exactly what you want here!  The loop_cluster_ids() method you
introduce later is not the correct way to handle this - you'll see
this method appear as a unit test failure for specifically this
reason:

======================================================================
FAIL: test_relax_disp_objects
(test_suite.unit_tests._specific_analyses.test_api.Test_api)
The relaxation dispersion curve fitting object public objects check.
----------------------------------------------------------------------
Traceback (most recent call last):
  File 
"/data/relax/relax-trunk/test_suite/unit_tests/_specific_analyses/test_api.py",
line 278, in test_relax_disp_objects
    self.__check_objects(Relax_disp())
  File 
"/data/relax/relax-trunk/test_suite/unit_tests/_specific_analyses/test_api.py",
line 152, in __check_objects
    self.fail('The object ' + repr(name) + ' ' + repr(type(obj)) + '
cannot be found in the API base class.')
AssertionError: The object 'loop_cluster_ids' <type 'instancemethod'>
cannot be found in the API base class.

----------------------------------------------------------------------

The model_loop() method will be much more consistent.  It is also
extremely important that the spin containers are obtained within the
methods which call model_loop() and is not returned by model_loop() or
by loop_cluster_ids().  The reason is because of the multiprocessor
and parallelisations.  This can lead to fatal racing conditions, or at
least cause corruption of the data in the spin container, and for the
multiprocessor it can cause the data to be completely lost.  That is
why I removed the returning of spin containers from model_loop()
originally.  Please try to make this change from the
loop_cluster_ids() method to model_loop().

Cheers,

Edward



On 6 October 2014 02:39,  <tlinnet@xxxxxxxxxxxxx> wrote:
Author: tlinnet
Date: Mon Oct  6 02:39:46 2014
New Revision: 26152

URL: http://svn.gna.org/viewcvs/relax?rev=26152&view=rev
Log:
Made initial preparation to loop over clustered spins and ids for 
minimise.calculate() call.

Bug #22754 (https://gna.org/bugs/index.php?22754): The minimise.calculate() 
does not calculate chi2 value for clustered residues.

Modified:
    trunk/specific_analyses/relax_disp/api.py

Modified: trunk/specific_analyses/relax_disp/api.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/relax_disp/api.py?rev=26152&r1=26151&r2=26152&view=diff
==============================================================================
--- trunk/specific_analyses/relax_disp/api.py   (original)
+++ trunk/specific_analyses/relax_disp/api.py   Mon Oct  6 02:39:46 2014
@@ -37,6 +37,7 @@
 from lib.arg_check import is_list, is_str_list
 from lib.dispersion.variables import EXP_TYPE_CPMG_PROTON_MQ, 
EXP_TYPE_CPMG_PROTON_SQ, MODEL_LIST_MMQ, MODEL_R2EFF, PARAMS_R20
 from lib.errors import RelaxError, RelaxImplementError
+from lib.selection import Selection, tokenise
 from lib.text.sectioning import subsection
 from multi import Processor_box
 from pipe_control import pipes, relax_data, sequence
@@ -260,6 +261,71 @@
         check_mol_res_spin_data()
         check_model_type()

+        # Initialise cluster ids.
+        cluster_ids = ['free spins']
+
+        # Add the defined cluster IDs.
+        if hasattr(cdp, 'clustering'):
+            for key in list(cdp.clustering.keys()):
+                if key not in cluster_ids:
+                    cluster_ids.append(key)
+
+        # Now collect spins and spin_id per cluster ids.
+        cluster_spin_list = []
+        cluster_spin_id_list = []
+        clust_contain_spin_id_list = []
+
+        # Loop over the cluster ids
+        if hasattr(cdp, 'clustering'):
+            # Now loop over the cluster_ids in the list, and collect per 
id.
+            for cluster_id in cluster_ids:
+                cluster_id_spin_list = []
+                cluster_id_spin_id_list = []
+                # Now loop through spins in the clustered id, and collect
+                col_sel_str = ''
+                mol_token = None
+                for clust_spin_id in cdp.clustering[cluster_id]:
+                    clust_spin = return_spin(clust_spin_id)
+
+                    # Add to list.
+                    cluster_id_spin_list.append(clust_spin)
+                    cluster_id_spin_id_list.append(clust_spin_id)
+
+                    # Add id to string
+                    mol_token, res_token, spin_token = 
tokenise(clust_spin_id)
+                    col_sel_str += '%s,' % (res_token)
+
+                # Make selection for molecule.
+                if mol_token == None:
+                    col_sel_str = ':' + col_sel_str
+                else:
+                    col_sel_str = '#%s:' % mol_token + col_sel_str
+
+                # Make a selection object, based on the cluster id.
+                select_obj = Selection(col_sel_str)
+                # Does the current cluster id contain the spin of interest.
+                clust_contain_spin_id = 
select_obj.contains_spin_id(spin_id)
+                # If the spin_id is set to None, then we calculate for all:
+                if spin_id == None:
+                    clust_contain_spin_id = True
+
+                cluster_spin_list.append(cluster_id_spin_list)
+                cluster_spin_id_list.append(cluster_id_spin_id_list)
+                clust_contain_spin_id_list.append(clust_contain_spin_id)
+
+        # If clustering has not been specified, then collect for free 
spins, according to selection.
+        else:
+            # Now loop over selected spins.
+            free_spin_list = []
+            free_spin_id_list = []
+            for cur_spin, cur_spin_id in spin_loop(selection=spin_id, 
return_id=True, skip_desel=True):
+                free_spin_list.append(cur_spin)
+                free_spin_id_list.append(cur_spin_id)
+
+            cluster_spin_list.append(free_spin_list)
+            cluster_spin_id_list.append(free_spin_id_list)
+            clust_contain_spin_id_list.append(True)
+
         # Special exponential curve-fitting for the R2eff model.
         if cdp.model_type == MODEL_R2EFF:
             calculate_r2eff()
@@ -270,7 +336,7 @@
             proton_mmq_flag = has_proton_mmq_cpmg()

             # Loop over all spins.
-            for spin, spin_id in spin_loop(return_id=True, 
skip_desel=True):
+            for spin, cur_spin_id in spin_loop(selection=spin_id, 
return_id=True, skip_desel=True):
                 # Skip protons for MMQ data.
                 if spin.model in MODEL_LIST_MMQ and spin.isotope == '1H':
                     continue
@@ -278,13 +344,13 @@
                 # Get the attached proton.
                 proton = None
                 if proton_mmq_flag:
-                    proton = return_attached_protons(spin_id)[0]
+                    proton = return_attached_protons(cur_spin_id)[0]

                 # The back calculated values.
-                back_calc = back_calc_r2eff(spin=spin, spin_id=spin_id, 
store_chi2=True)
+                back_calc = back_calc_r2eff(spin=spin, 
spin_id=cur_spin_id, store_chi2=True)

                 # Pack the data.
-                pack_back_calc_r2eff(spin=spin, spin_id=spin_id, si=0, 
back_calc=back_calc, proton_mmq_flag=proton_mmq_flag)
+                pack_back_calc_r2eff(spin=spin, spin_id=cur_spin_id, si=0, 
back_calc=back_calc, proton_mmq_flag=proton_mmq_flag)


     def constraint_algorithm(self):


_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-commits mailing list
relax-commits@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits



Related Messages


Powered by MHonArc, Updated Mon Oct 06 15:40:09 2014