mailr24818 - in /branches/frame_order_cleanup: ./ pipe_control/ test_suite/unit_tests/_pipe_control/


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

Header


Content

Posted by edward on July 29, 2014 - 18:35:
Author: bugman
Date: Tue Jul 29 18:35:25 2014
New Revision: 24818

URL: http://svn.gna.org/viewcvs/relax?rev=24818&view=rev
Log:
Merged revisions 24788,24796-24797 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r24788 | bugman | 2014-07-29 10:11:14 +0200 (Tue, 29 Jul 2014) | 9 lines
  
  Implemented the pipe_control.mol_res_spin.format_info_full() function.
  
  This follows from 
http://thread.gmane.org/gmane.science.nmr.relax.scm/22522/focus=6534.
  
  This is a verbose representation of the spin information which can be used 
for presenting to the
  user.  Functions for shorter string versions will also be of great use, for 
example as described by
  Troels at 
http://thread.gmane.org/gmane.science.nmr.relax.scm/22522/focus=6535.
........
  r24796 | bugman | 2014-07-29 10:25:37 +0200 (Tue, 29 Jul 2014) | 3 lines
  
  Fix for the pipe_control.mol_res_spin.format_info_full() function, it now 
actually returns the string.
........
  r24797 | bugman | 2014-07-29 10:51:20 +0200 (Tue, 29 Jul 2014) | 5 lines
  
  Created a unit test for the pipe_control.mol_res_spin.format_info_full() 
function.
  
  This comprehensive test covers all input argument combinations.
........

Modified:
    branches/frame_order_cleanup/   (props changed)
    branches/frame_order_cleanup/pipe_control/mol_res_spin.py
    
branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/test_mol_res_spin.py

Propchange: branches/frame_order_cleanup/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Jul 29 18:35:25 2014
@@ -1 +1 @@
-/trunk:1-24778
+/trunk:1-24806

Modified: branches/frame_order_cleanup/pipe_control/mol_res_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/pipe_control/mol_res_spin.py?rev=24818&r1=24817&r2=24818&view=diff
==============================================================================
--- branches/frame_order_cleanup/pipe_control/mol_res_spin.py   (original)
+++ branches/frame_order_cleanup/pipe_control/mol_res_spin.py   Tue Jul 29 
18:35:25 2014
@@ -1249,6 +1249,77 @@
 
     # The first residue number.
     return mol.res[0].num
+
+
+def format_info_full(mol_name=None, res_num=None, res_name=None, 
spin_num=None, spin_name=None):
+    """Format the molecule, residue, and spin information as a string, 
skipping missing information.
+
+    This will be a verbose representation.  If:
+
+        mol_name = 'Ubi'
+        res_name = 'Ala'
+        res_num = '10'
+        spin_num = None
+        spin_name = 'N'
+
+    Then the returned string will be "Molecule Ubi, residue Ala 10, spin N". 
 Any values of None will result in that part of the string being suppressed.
+
+
+    @keyword mol_name:  The molecule name.
+    @type mol_name:     str or None
+    @keyword res_num:   The residue number.
+    @type res_num:      int or None
+    @keyword res_name:  The residue name.
+    @type res_name:     str or None
+    @keyword spin_num:  The spin number.
+    @type spin_num:     int or None
+    @keyword spin_name: The spin name.
+    @type spin_name:    str or None
+    @return:            The formatted string containing all the molecule, 
residue and spin information.
+    @rtype:             str
+    """
+
+    # Init.
+    string = ''
+
+    # The molecule information.
+    if mol_name != None:
+        string += "Molecule %s" % mol_name
+
+    # The residue information.
+    if res_num != None or res_name != None:
+        # Starting string.
+        if not len(string):
+            string += "Residue"
+        else:
+            string += ", residue"
+
+        # The residue name.
+        if res_name != None:
+            string += " %s" % res_name
+
+        # The residue number.
+        if res_num != None:
+            string += " %s" % res_num
+
+    # The spin information.
+    if spin_num != None or spin_name != None:
+        # Starting string.
+        if not len(string):
+            string += "Spin"
+        else:
+            string += ", spin"
+
+        # The spin name.
+        if spin_name != None:
+            string += " %s" % spin_name
+
+        # The spin number.
+        if spin_num != None:
+            string += " %s" % spin_num
+
+    # Return the string.
+    return string
 
 
 def generate_spin_id(pipe_cont=None, pipe_name=None, mol_name=None, 
res_num=None, res_name=None, spin_num=None, spin_name=None):

Modified: 
branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/test_mol_res_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/test_mol_res_spin.py?rev=24818&r1=24817&r2=24818&view=diff
==============================================================================
--- 
branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/test_mol_res_spin.py
       (original)
+++ 
branches/frame_order_cleanup/test_suite/unit_tests/_pipe_control/test_mol_res_spin.py
       Tue Jul 29 18:35:25 2014
@@ -255,6 +255,66 @@
         self.assertRaises(RelaxNoPipeError, 
mol_res_spin.exists_mol_res_spin_data)
 
 
+    def test_format_info_full1(self):
+        """Test the format_info_full() function for all combinations of 
input."""
+
+        # The spin info and expected string - covering all possible 
combinations.
+        info = [
+            # 5 bits of info.
+            {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10,   
'spin_name': 'N',  'spin_num': 200,  'string': "Molecule Ubi, residue Ala 10, 
spin N 200"},
+
+            # 4 bits of info.
+            {'mol_name': None,  'res_name': 'Ala', 'res_num': 10,   
'spin_name': 'N',  'spin_num': 200,  'string': "Residue Ala 10, spin N 200"},
+            {'mol_name': 'Ubi', 'res_name': None,  'res_num': 10,   
'spin_name': 'N',  'spin_num': 200,  'string': "Molecule Ubi, residue 10, 
spin N 200"},
+            {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 
'spin_name': 'N',  'spin_num': 200,  'string': "Molecule Ubi, residue Ala, 
spin N 200"},
+            {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10,   
'spin_name': None, 'spin_num': 200,  'string': "Molecule Ubi, residue Ala 10, 
spin 200"},
+            {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10,   
'spin_name': 'N',  'spin_num': None, 'string': "Molecule Ubi, residue Ala 10, 
spin N"},
+
+            # 3 bits of info.
+            {'mol_name': None,  'res_name': None,  'res_num': 10,   
'spin_name': 'N',  'spin_num': 200,  'string': "Residue 10, spin N 200"},
+            {'mol_name': None,  'res_name': 'Ala', 'res_num': None, 
'spin_name': 'N',  'spin_num': 200,  'string': "Residue Ala, spin N 200"},
+            {'mol_name': None,  'res_name': 'Ala', 'res_num': 10,   
'spin_name': None, 'spin_num': 200,  'string': "Residue Ala 10, spin 200"},
+            {'mol_name': None,  'res_name': 'Ala', 'res_num': 10,   
'spin_name': 'N',  'spin_num': None, 'string': "Residue Ala 10, spin N"},
+            {'mol_name': 'Ubi', 'res_name': None,  'res_num': None, 
'spin_name': 'N',  'spin_num': 200,  'string': "Molecule Ubi, spin N 200"},
+            {'mol_name': 'Ubi', 'res_name': None,  'res_num': 10,   
'spin_name': None, 'spin_num': 200,  'string': "Molecule Ubi, residue 10, 
spin 200"},
+            {'mol_name': 'Ubi', 'res_name': None,  'res_num': 10,   
'spin_name': 'N',  'spin_num': None, 'string': "Molecule Ubi, residue 10, 
spin N"},
+            {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 
'spin_name': None, 'spin_num': 200,  'string': "Molecule Ubi, residue Ala, 
spin 200"},
+            {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 
'spin_name': 'N',  'spin_num': None, 'string': "Molecule Ubi, residue Ala, 
spin N"},
+            {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10,   
'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi, residue Ala 
10"},
+
+            # 2 bits of info.
+            {'mol_name': None,  'res_name': None,  'res_num': None, 
'spin_name': 'N',  'spin_num': 200,  'string': "Spin N 200"},
+            {'mol_name': None,  'res_name': None,  'res_num': 10,   
'spin_name': None, 'spin_num': 200,  'string': "Residue 10, spin 200"},
+            {'mol_name': None,  'res_name': None,  'res_num': 10,   
'spin_name': 'N',  'spin_num': None, 'string': "Residue 10, spin N"},
+            {'mol_name': None,  'res_name': 'Ala', 'res_num': None, 
'spin_name': None, 'spin_num': 200,  'string': "Residue Ala, spin 200"},
+            {'mol_name': None,  'res_name': 'Ala', 'res_num': None, 
'spin_name': 'N',  'spin_num': None, 'string': "Residue Ala, spin N"},
+            {'mol_name': None,  'res_name': 'Ala', 'res_num': 10,   
'spin_name': None, 'spin_num': None, 'string': "Residue Ala 10"},
+            {'mol_name': 'Ubi', 'res_name': None,  'res_num': None, 
'spin_name': None, 'spin_num': 200,  'string': "Molecule Ubi, spin 200"},
+            {'mol_name': 'Ubi', 'res_name': None,  'res_num': None, 
'spin_name': 'N',  'spin_num': None, 'string': "Molecule Ubi, spin N"},
+            {'mol_name': 'Ubi', 'res_name': None,  'res_num': 10,   
'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi, residue 10"},
+            {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 
'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi, residue Ala"},
+
+            # 1 bit of info.
+            {'mol_name': None,  'res_name': None,  'res_num': None, 
'spin_name': None, 'spin_num': 200,  'string': "Spin 200"},
+            {'mol_name': None,  'res_name': None,  'res_num': None, 
'spin_name': 'N',  'spin_num': None, 'string': "Spin N"},
+            {'mol_name': None,  'res_name': None,  'res_num': 10,   
'spin_name': None, 'spin_num': None, 'string': "Residue 10"},
+            {'mol_name': None,  'res_name': 'Ala', 'res_num': None, 
'spin_name': None, 'spin_num': None, 'string': "Residue Ala"},
+            {'mol_name': 'Ubi', 'res_name': None,  'res_num': None, 
'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi"},
+
+            # 0 bits of info.
+            {'mol_name': None,  'res_name': None,  'res_num': None, 
'spin_name': None, 'spin_num': None, 'string': ""},
+        ]
+
+        # Printout.
+        print("Checking %s combinations." % len(info))
+
+        # Create and check each string.
+        for i in range(len(info)):
+            print("    Checking %s" % info[i])
+            string = 
mol_res_spin.format_info_full(mol_name=info[i]['mol_name'], 
res_name=info[i]['res_name'], res_num=info[i]['res_num'], 
spin_name=info[i]['spin_name'], spin_num=info[i]['spin_num'])
+            self.assertEqual(string, info[i]['string'])
+
+
     def test_generate_spin_id_data_array1(self):
         """First test of the spin ID generation function.
 




Related Messages


Powered by MHonArc, Updated Tue Jul 29 19:00:02 2014