mailr18152 - in /branches/frame_order_testing: ./ generic_fns/ test_suite/unit_tests/_generic_fns/


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

Header


Content

Posted by edward on December 17, 2012 - 15:01:
Author: bugman
Date: Mon Dec 17 15:01:26 2012
New Revision: 18152

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

........
  r18149 | bugman | 2012-12-17 12:57:18 +0100 (Mon, 17 Dec 2012) | 3 lines
  
  Created 4 unit tests to demonstrate the failure of the selection object 
with spin IDs.
........
  r18150 | bugman | 2012-12-17 14:35:23 +0100 (Mon, 17 Dec 2012) | 3 lines
  
  The molecule, residue and spin selection object now works with spin IDs.
........
  r18151 | bugman | 2012-12-17 14:41:02 +0100 (Mon, 17 Dec 2012) | 3 lines
  
  Docstring consistency editing for all parts of the generic_fns.mol_res_spin 
module.
........

Modified:
    branches/frame_order_testing/   (props changed)
    branches/frame_order_testing/generic_fns/mol_res_spin.py
    
branches/frame_order_testing/test_suite/unit_tests/_generic_fns/test_mol_res_spin.py

Propchange: branches/frame_order_testing/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Dec 17 15:01:26 2012
@@ -1,1 +1,1 @@
-/trunk:1-18147
+/trunk:1-18151

Modified: branches/frame_order_testing/generic_fns/mol_res_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/generic_fns/mol_res_spin.py?rev=18152&r1=18151&r2=18152&view=diff
==============================================================================
--- branches/frame_order_testing/generic_fns/mol_res_spin.py (original)
+++ branches/frame_order_testing/generic_fns/mol_res_spin.py Mon Dec 17 
15:01:26 2012
@@ -27,10 +27,8 @@
     - Functions for parsing or generating spin identification strings.
     - The mol-res-spin selection object (derived from the Selection class).
     - Generator functions for looping over molecules, residues, or spins.
-    - Functions for returning MoleculeContainer, ResidueContainer, and 
SpinContainer objects or
-    information about these.
-    - Functions for copying, creating, deleting, displaying, naming, and 
numbering
-    MoleculeContainer, ResidueContainer, and SpinContainer objects in the 
relax data store.
+    - Functions for returning MoleculeContainer, ResidueContainer, and 
SpinContainer objects or information about these.
+    - Functions for copying, creating, deleting, displaying, naming, and 
numbering MoleculeContainer, ResidueContainer, and SpinContainer objects in 
the relax data store.
     - Functions for counting spins or testing their existence.
 """
 
@@ -69,8 +67,7 @@
 class Selection(object):
     """An object containing mol-res-spin selections.
 
-    A Selection object represents either a set of selected molecules, 
residues and spins, or the
-    union or intersection of two other Selection objects.
+    A Selection object represents either a set of selected molecules, 
residues and spins, or the union or intersection of two other Selection 
objects.
     """
 
     def __init__(self, select_string):
@@ -119,9 +116,7 @@
     def __contains__(self, obj):
         """Replacement function for determining if an object matches the 
selection.
 
-        @param obj:     The data object.  This can be a MoleculeContainer, 
ResidueContainer, or
-                        SpinContainer instance or a type of these instances. 
 If a tuple, only one
-                        type of object can be in the tuple.
+        @param obj:     The data object.  This can be a MoleculeContainer, 
ResidueContainer, or SpinContainer instance or a type of these instances.  If 
a tuple, only one type of object can be in the tuple.
         @type obj:      instance or type of instances.
         @return:        The answer of whether the object matches the 
selection.
         @rtype:         bool
@@ -147,9 +142,7 @@
     def __contains_mol_res_spin_containers(self, obj):
         """Are the MoleculeContainer, ResidueContainer, and/or SpinContainer 
in the selection.
 
-        @param obj:     The data object.  This can be a MoleculeContainer, 
ResidueContainer, or
-                        SpinContainer instance or a type of these instances. 
 If a tuple, only one
-                        type of object can be in the tuple.
+        @param obj:     The data object.  This can be a MoleculeContainer, 
ResidueContainer, or SpinContainer instance or a type of these instances.  If 
a tuple, only one type of object can be in the tuple.
         @type obj:      instance or type of instances.
         @return:        The answer of whether the objects are found within 
the selection object.
         @rtype:         bool
@@ -265,19 +258,20 @@
 
         @param spin_id: The spin identification string.
         @type spin_id:  str
-        @return:        The answer of whether the molecule, residue, and/or 
spin corresponding to
-                        the spin_id string found within the selection object.
+        @return:        The answer of whether the molecule, residue, and/or 
spin corresponding to the spin_id string found within the selection object.
         @rtype:         bool
         """
 
+        # No ID string.
+        if spin_id == '':
+            warn(RelaxWarning("The spin ID string '' is empty."))
+            return False
+
         # Parse the spin_id string.
-        try:
-            mol_token, res_token, spin_token = tokenise(spin_id)
-            molecules = parse_token(mol_token)
-            residues = parse_token(res_token)
-            spins = parse_token(spin_token)
-        except RelaxError:
-            warn(RelaxWarning("The spin identification string " + 
repr(spin_id) + " is too complex for the selection object."))
+        mol_name, res_num, res_name, spin_num, spin_name = 
spin_id_to_data_list(spin_id)
+
+        # Check if the spin is in the selection object.
+        return self.contains_spin(spin_num=spin_num, spin_name=spin_name, 
res_num=res_num, res_name=res_name, mol=mol_name)
 
 
     def contains_mol(self, mol=None):
@@ -285,8 +279,7 @@
 
         @keyword mol:   The name of the molecule.
         @type mol:      str or None
-        @return:        The answer of whether the molecule is contained 
withing the selection
-                        object.
+        @return:        The answer of whether the molecule is contained 
withing the selection object.
         @rtype:         bool
         """
 
@@ -319,8 +312,7 @@
         @type res_name:     str or None
         @keyword mol:       The molecule name.
         @type mol:          str or None
-        @return:            The answer of whether the molecule is contained 
withing the selection
-                            object.
+        @return:            The answer of whether the molecule is contained 
withing the selection object.
         @rtype:             bool
         """
 
@@ -363,8 +355,7 @@
         @type res_name:     str or None
         @keyword mol:       The molecule name.
         @type mol:          str or None
-        @return:            The answer of whether the spin is contained 
withing the selection
-                            object.
+        @return:            The answer of whether the spin is contained 
withing the selection object.
         @rtype:             bool
         """
 
@@ -618,13 +609,12 @@
 
     For copying to be successful, the mol_from identification string must 
match an existent molecule.
 
-    @param pipe_from:   The data pipe to copy the molecule data from.  This 
defaults to the current
-                        data pipe.
+
+    @param pipe_from:   The data pipe to copy the molecule data from.  This 
defaults to the current data pipe.
     @type pipe_from:    str
     @param mol_from:    The molecule identification string for the structure 
to copy the data from.
     @type mol_from:     str
-    @param pipe_to:     The data pipe to copy the molecule data to.  This 
defaults to the current
-                        data pipe.
+    @param pipe_to:     The data pipe to copy the molecule data to.  This 
defaults to the current data pipe.
     @type pipe_to:      str
     @param mol_to:      The molecule identification string for the structure 
to copy the data to.
     @type mol_to:       str
@@ -693,16 +683,13 @@
 def copy_residue(pipe_from=None, res_from=None, pipe_to=None, res_to=None):
     """Copy the contents of the residue structure from one residue to a new 
residue.
 
-    For copying to be successful, the res_from identification string must 
match an existent residue.
-    The new residue number must be unique.
-
-    @param pipe_from:   The data pipe to copy the residue from.  This 
defaults to the current data
-                        pipe.
+    For copying to be successful, the res_from identification string must 
match an existent residue. The new residue number must be unique.
+
+    @param pipe_from:   The data pipe to copy the residue from.  This 
defaults to the current data pipe.
     @type pipe_from:    str
     @param res_from:    The residue identification string for the structure 
to copy the data from.
     @type res_from:     str
-    @param pipe_to:     The data pipe to copy the residue to.  This defaults 
to the current data
-                        pipe.
+    @param pipe_to:     The data pipe to copy the residue to.  This defaults 
to the current data pipe.
     @type pipe_to:      str
     @param res_to:      The residue identification string for the structure 
to copy the data to.
     @type res_to:       str
@@ -774,16 +761,14 @@
 def copy_spin(pipe_from=None, spin_from=None, pipe_to=None, spin_to=None):
     """Copy the contents of the spin structure from one spin to a new spin.
 
-    For copying to be successful, the spin_from identification string must 
match an existent spin.
-    The new spin number must be unique.
-
-    @param pipe_from:   The data pipe to copy the spin from.  This defaults 
to the current data
-                        pipe.
+    For copying to be successful, the spin_from identification string must 
match an existent spin. The new spin number must be unique.
+
+
+    @param pipe_from:   The data pipe to copy the spin from.  This defaults 
to the current data pipe.
     @type pipe_from:    str
     @param spin_from:   The spin identification string for the structure to 
copy the data from.
     @type spin_from:    str
-    @param pipe_to:     The data pipe to copy the spin to.  This defaults to 
the current data
-                        pipe.
+    @param pipe_to:     The data pipe to copy the spin to.  This defaults to 
the current data pipe.
     @type pipe_to:      str
     @param spin_to:     The spin identification string for the structure to 
copy the data to.
     @type spin_to:      str
@@ -926,8 +911,7 @@
     @type selection:        str
     @keyword pipe:          The data pipe containing the spin.  Defaults to 
the current data pipe.
     @type pipe:             str
-    @keyword skip_desel:    A flag which if true will cause deselected spins 
to be skipped in the
-                            count.
+    @keyword skip_desel:    A flag which if true will cause deselected spins 
to be skipped in the count.
     @type skip_desel:       bool
     @return:                The number of non-empty spins.
     @rtype:                 int
@@ -1265,8 +1249,7 @@
 
     @param global_index:        The global spin index, spanning the molecule 
and residue containers.
     @type global_index:         int
-    @param pipe:                The data pipe containing the spin.  Defaults 
to the current data
-                                pipe.
+    @param pipe:                The data pipe containing the spin.  Defaults 
to the current data pipe.
     @type pipe:                 str
     @return:                    The corresponding molecule, residue, and 
spin indices.
     @rtype:                     tuple of int
@@ -1545,8 +1528,7 @@
     @type selection:        str
     @keyword pipe:          The data pipe containing the spin.  Defaults to 
the current data pipe.
     @type pipe:             str
-    @keyword global_index:  A flag which if True will cause the global index 
to be returned.  If
-                            False, then the molecule, residue, and spin 
indices will be returned.
+    @keyword global_index:  A flag which if True will cause the global index 
to be returned.  If False, then the molecule, residue, and spin indices will 
be returned.
     @type global_index:     bool
     @return:                The global spin index or the molecule, residue, 
and spin indices.
     @rtype:                 int or tuple of 3 int
@@ -2367,13 +2349,10 @@
 def parse_token(token, verbosity=False):
     """Parse the token string and return a list of identifying numbers and 
names.
 
-    Firstly the token is split by the ',' character into its individual 
elements and all whitespace
-    stripped from the elements.  Numbers are converted to integers, names 
are left as strings, and
-    ranges are converted into the full list of integers.
-
-    @param token:       The identification string, the elements of which are 
separated by commas.
-                        Each element can be either a single number, a range 
of numbers (two numbers
-                        separated by '-'), or a name.
+    Firstly the token is split by the ',' character into its individual 
elements and all whitespace stripped from the elements.  Numbers are 
converted to integers, names are left as strings, and ranges are converted 
into the full list of integers.
+
+
+    @param token:       The identification string, the elements of which are 
separated by commas. Each element can be either a single number, a range of 
numbers (two numbers separated by '-'), or a name.
     @type token:        str
     @keyword verbosity: A flag which if True will cause a number of 
printouts to be activated.
     @type verbosity:    bool
@@ -2666,6 +2645,7 @@
     """Function for returning the spin data container of the given selection.
 
     If more than one selection is given, then the boolean AND operation will 
be used to pull out the spin.
+
 
     @keyword selection: The spin selection identifier.
     @type selection:    str
@@ -2751,16 +2731,12 @@
 
     @param global_index:        The global spin index, spanning the molecule 
and residue containers.
     @type global_index:         int
-    @param pipe:                The data pipe containing the spin.  Defaults 
to the current data
-                                pipe.
+    @param pipe:                The data pipe containing the spin.  Defaults 
to the current data pipe.
     @type pipe:                 str
-    @keyword return_spin_id:    A flag which if True will cause both the 
spin container and spin
-                                identification string to be returned.
+    @keyword return_spin_id:    A flag which if True will cause both the 
spin container and spin identification string to be returned.
     @type return_spin_id:       bool
-    @return:                    The spin specific data container 
(additionally the spin
-                                identification string if return_spin_id is 
set).
-    @rtype:                     instance of the SpinContainer class (or 
tuple of SpinContainer and
-                                str)
+    @return:                    The spin specific data container 
(additionally the spin identification string if return_spin_id is set).
+    @rtype:                     instance of the SpinContainer class (or 
tuple of SpinContainer and str)
     """
 
     # The data pipe.
@@ -3275,8 +3251,7 @@
 def spin_in_list(spin_list, mol_name_col=None, res_num_col=None, 
res_name_col=None, spin_num_col=None, spin_name_col=None, mol_name=None, 
res_num=None, res_name=None, spin_num=None, spin_name=None):
     """Function for determining if the spin is located within the list of 
spins.
 
-    @param spin_list:       The list of spins.  The first dimension 
corresponds to different spins,
-                            the second corresponds to the spin information 
columns.
+    @param spin_list:       The list of spins.  The first dimension 
corresponds to different spins, the second corresponds to the spin 
information columns.
     @type spin_list:        list of lists of str
     @keyword mol_name_col:  The column containing the molecule name 
information.
     @type mol_name_col:     int or None
@@ -3429,13 +3404,12 @@
 def tokenise(selection):
     """Split the input selection string returning the mol_token, res_token, 
and spin_token strings.
 
-    The mol_token is identified as the text from the '#' to either the ':' 
or '@' characters or the
-    end of the string.
-
-    The res_token is identified as the text from the ':' to either the '@' 
character or the end of
-    the string.
+    The mol_token is identified as the text from the '#' to either the ':' 
or '@' characters or the end of the string.
+
+    The res_token is identified as the text from the ':' to either the '@' 
character or the end of the string.
 
     The spin_token is identified as the text from the '@' to the end of the 
string.
+
 
     @param selection:   The selection identifier.
     @type selection:    str

Modified: 
branches/frame_order_testing/test_suite/unit_tests/_generic_fns/test_mol_res_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/test_suite/unit_tests/_generic_fns/test_mol_res_spin.py?rev=18152&r1=18151&r2=18152&view=diff
==============================================================================
--- 
branches/frame_order_testing/test_suite/unit_tests/_generic_fns/test_mol_res_spin.py
 (original)
+++ 
branches/frame_order_testing/test_suite/unit_tests/_generic_fns/test_mol_res_spin.py
 Mon Dec 17 15:01:26 2012
@@ -455,6 +455,46 @@
         self.assertEqual(obj.spins, [])
 
 
+    def test_Selection_range_contains_resid(self):
+        """The Selection object ":1-70" contains the res ':1'."""
+
+        # The Selection object.
+        obj = mol_res_spin.Selection(":1-70")
+
+        # Check that the residue ID is in the selection.
+        self.assert_(':1' in obj)
+
+
+    def test_Selection_range_contains_resid2(self):
+        """The Selection object ":1-70" does not contain the res ':71'."""
+
+        # The Selection object.
+        obj = mol_res_spin.Selection(":1-70")
+
+        # Check that the residue ID is in the selection.
+        self.assert_(':71' not in obj)
+
+
+    def test_Selection_range_contains_spinid(self):
+        """The Selection object ":1-70" contains the spin ':1@N'."""
+
+        # The Selection object.
+        obj = mol_res_spin.Selection(":1-70")
+
+        # Check that the residue ID is in the selection.
+        self.assert_(':1@N' in obj)
+
+
+    def test_Selection_range_contains_spinid2(self):
+        """The Selection object ":1-70" does not contain the spin ':71@C'."""
+
+        # The Selection object.
+        obj = mol_res_spin.Selection(":1-70")
+
+        # Check that the residue ID is in the selection.
+        self.assert_(':71@C' not in obj)
+
+
     def test_count_spins(self):
         """Test that the number of spins can be properly counted.
 




Related Messages


Powered by MHonArc, Updated Mon Dec 17 19:00:02 2012