mailr8932 - in /1.3: generic_fns/ prompt/ test_suite/unit_tests/ test_suite/unit_tests/_prompt/


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

Header


Content

Posted by edward on March 08, 2009 - 23:35:
Author: bugman
Date: Sun Mar  8 23:35:24 2009
New Revision: 8932

URL: http://svn.gna.org/viewcvs/relax?rev=8932&view=rev
Log:
Redesigned the spin.create() and residue.create() user functions.

The res_id and mol_id args are no longer supplied.  Instead the residue name 
and number and molecule
name is used.  If the molecule or residue does not exist when these user 
functions are called, then
they will be automatically created.


Modified:
    1.3/generic_fns/mol_res_spin.py
    1.3/generic_fns/relax_data.py
    1.3/prompt/residue.py
    1.3/prompt/spin.py
    1.3/test_suite/unit_tests/_prompt/test_residue.py
    1.3/test_suite/unit_tests/_prompt/test_spin.py
    1.3/test_suite/unit_tests/spin_testing_base.py

Modified: 1.3/generic_fns/mol_res_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/mol_res_spin.py?rev=8932&r1=8931&r2=8932&view=diff
==============================================================================
--- 1.3/generic_fns/mol_res_spin.py (original)
+++ 1.3/generic_fns/mol_res_spin.py Sun Mar  8 23:35:24 2009
@@ -777,7 +777,11 @@
 
 
 def create_molecule(mol_name=None):
-    """Function for adding a molecule into the relax data store."""
+    """Add a molecule into the relax data store.
+
+    @keyword mol_name:  The name of the molecule.
+    @type mol_name:     str
+    """
 
     # Test if the current data pipe exists.
     pipes.test()
@@ -794,78 +798,70 @@
     cdp.mol.add_item(mol_name=mol_name)
 
 
-def create_residue(res_num=None, res_name=None, mol_id=None):
-    """Function for adding a residue into the relax data store.
-
-    @param res_num:     The identification number of the new residue.
+def create_residue(res_num=None, res_name=None, mol_name=None):
+    """Add a residue into the relax data store (and molecule if necessary).
+
+    @keyword res_num:   The number of the new residue.
     @type res_num:      int
-    @param res_name:    The name of the new residue.
+    @keyword res_name:  The name of the new residue.
     @type res_name:     str
-    @param mol_id:      The molecule identification string.
-    @type mol_id:       str
-    """
+    @keyword mol_name:  The name of the molecule to add the residue to.
+    @type mol_name:     str
+    """
+
+    # Test if the current data pipe exists.
+    pipes.test()
 
     # Get the current data pipe.
     cdp = pipes.get_pipe()
 
-    # Split up the selection string.
-    mol_token, res_token, spin_token = tokenise(mol_id)
-
-    # Disallowed selections.
-    if res_token != None:
-        raise RelaxResSelectDisallowError
-    if spin_token != None:
-        raise RelaxSpinSelectDisallowError
+    # Create the molecule if it does not exist.
+    if not return_molecule(generate_spin_id(mol_name=mol_name)):
+        create_molecule(mol_name=mol_name)
+
+    # Get the molecule container to add the residue to.
+    mol_cont = return_molecule(generate_spin_id(mol_name=mol_name))
+    if not mol_cont:
+        mol_cont = cdp.mol[0]
+
+    # Add the residue.
+    mol_cont.res.add_item(res_num=res_num, res_name=res_name)
+
+
+def create_spin(spin_num=None, spin_name=None, res_num=None, res_name=None, 
mol_name=None):
+    """Add a spin into the relax data store (and molecule and residue if 
necessary).
+    
+    @keyword spin_num:  The number of the new spin.
+    @type spin_num:     int
+    @keyword spin_name: The name of the new spin.
+    @type spin_name:    str
+    @keyword res_num:   The number of the residue to add the spin to.
+    @type res_num:      int
+    @keyword res_name:  The name of the residue to add the spin to.
+    @type res_name:     str
+    @keyword mol_name:  The name of the molecule to add the spin to.
+    @type mol_name:     str
+    """
 
     # Test if the current data pipe exists.
     pipes.test()
 
-    # Get the molecule container to add the residue to.
-    if mol_id:
-        mol_to_cont = return_molecule(mol_id)
-        if mol_to_cont == None:
-            raise RelaxError, "The molecule in " + `mol_id` + " does not 
exist in the current data pipe."
-    else:
-        mol_to_cont = cdp.mol[0]
-
-    # Add the residue.
-    mol_to_cont.res.add_item(res_num=res_num, res_name=res_name)
-
-
-def create_spin(spin_num=None, spin_name=None, res_id=None):
-    """Function for adding a spin into the relax data store.
-    
-    @param spin_num:    The identification number of the new spin.
-    @type spin_num:     int
-    @param spin_name:   The name of the new spin.
-    @type spin_name:    str
-    @param res_id:      The molecule and residue identification string.
-    @type res_id:       str
-    """
-
     # Get the current data pipe.
     cdp = pipes.get_pipe()
 
-    # Split up the selection string.
-    mol_token, res_token, spin_token = tokenise(res_id)
-
-    # Disallow spin selections.
-    if spin_token != None:
-        raise RelaxSpinSelectDisallowError
-
-    # Test if the current data pipe exists.
-    pipes.test()
+    # Create the molecule and residue if they do not exist.
+    if not return_molecule(generate_spin_id(mol_name=mol_name)):
+        create_molecule(mol_name=mol_name)
+    if not return_residue(generate_spin_id(mol_name=mol_name, 
res_num=res_num, res_name=res_name)):
+        create_residue(mol_name=mol_name, res_num=res_num, res_name=res_name)
 
     # Get the residue container to add the spin to.
-    if res_id:
-        res_to_cont = return_residue(res_id)
-        if res_to_cont == None:
-            raise RelaxError, "The residue in " + `res_id` + " does not 
exist in the current data pipe."
-    else:
-        res_to_cont = cdp.mol[0].res[0]
+    res_cont = return_residue(generate_spin_id(mol_name=mol_name, 
res_num=res_num, res_name=res_name))
+    if not res_cont:
+        res_cont = cdp.mol[0].res[0]
 
     # Add the spin.
-    res_to_cont.spin.add_item(spin_num=spin_num, spin_name=spin_name)
+    res_cont.spin.add_item(spin_num=spin_num, spin_name=spin_name)
 
 
 def convert_from_global_index(global_index=None, pipe=None):

Modified: 1.3/generic_fns/relax_data.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/relax_data.py?rev=8932&r1=8931&r2=8932&view=diff
==============================================================================
--- 1.3/generic_fns/relax_data.py (original)
+++ 1.3/generic_fns/relax_data.py Sun Mar  8 23:35:24 2009
@@ -29,7 +29,7 @@
 
 # relax module imports.
 from data import Relax_data_store; ds = Relax_data_store()
-from generic_fns.mol_res_spin import create_molecule, create_residue, 
create_spin, exists_mol_res_spin_data, generate_spin_id, return_spin, 
spin_index_loop, spin_loop
+from generic_fns.mol_res_spin import create_spin, exists_mol_res_spin_data, 
generate_spin_id, return_spin, spin_index_loop, spin_loop
 from generic_fns import pipes
 from generic_fns import value
 from relax_errors import RelaxError, RelaxNoRiError, RelaxNoSequenceError, 
RelaxNoSpinError, RelaxRiError
@@ -601,9 +601,7 @@
             if not gen_seq:
                 raise RelaxNoSpinError, id
             else:
-                create_molecule(mol_name)
-                create_residue(res_num, res_name, 
mol_id=generate_spin_id(mol_name=mol_name))
-                create_spin(spin_num, spin_name, 
res_id=generate_spin_id(mol_name=mol_name, res_num=res_num, 
res_name=res_name))
+                create_spin(spin_num=spin_num, spin_name=spin_name, 
res_num=res_num, res_name=res_name, mol_name=mol_name)
 
         # Update all data structures.
         update_data_structures_spin(spin, ri_label, frq_label, frq, value, 
error)

Modified: 1.3/prompt/residue.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/residue.py?rev=8932&r1=8931&r2=8932&view=diff
==============================================================================
--- 1.3/prompt/residue.py (original)
+++ 1.3/prompt/residue.py Sun Mar  8 23:35:24 2009
@@ -118,7 +118,7 @@
         copy_residue(pipe_from=pipe_from, res_from=res_from, 
pipe_to=pipe_to, res_to=res_to)
 
 
-    def create(self, res_num=None, res_name=None, mol_id=None):
+    def create(self, res_num=None, res_name=None, mol_name=None):
         """Function for creating a new residue.
 
         Keyword Arguments
@@ -128,7 +128,7 @@
 
         res_name:  The name of the residue.
 
-        mol_id:  The ID string for selecting the molecule to add the residue 
to.
+        mol_name:  The name of the molecule to add the residue to.
 
 
         Description
@@ -157,7 +157,7 @@
             text = sys.ps3 + "residue.create("
             text = text + "res_num=" + `res_num`
             text = text + ", res_name=" + `res_name`
-            text = text + ", mol_id=" + `mol_id` + ")"
+            text = text + ", mol_name=" + `mol_name` + ")"
             print text
 
         # Residue number.
@@ -168,12 +168,12 @@
         if res_name != None and type(res_name) != str:
             raise RelaxNoneStrError, ('residue name', res_name)
 
-        # The molecule ID.
-        if mol_id != None and type(mol_id) != str:
-            raise RelaxNoneStrError, ('molecule identification string', 
mol_id)
-
-        # Execute the functional code.
-        create_residue(res_num=res_num, res_name=res_name, mol_id=mol_id)
+        # The molecule name.
+        if mol_name != None and type(mol_name) != str:
+            raise RelaxNoneStrError, ('molecule name', mol_name)
+
+        # Execute the functional code.
+        create_residue(res_num=res_num, res_name=res_name, mol_name=mol_name)
 
 
     def delete(self, res_id=None):

Modified: 1.3/prompt/spin.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/spin.py?rev=8932&r1=8931&r2=8932&view=diff
==============================================================================
--- 1.3/prompt/spin.py (original)
+++ 1.3/prompt/spin.py Sun Mar  8 23:35:24 2009
@@ -118,7 +118,7 @@
         copy_spin(pipe_from=pipe_from, spin_from=spin_from, pipe_to=pipe_to, 
spin_to=spin_to)
 
 
-    def create(self, spin_num=None, spin_name=None, res_id=None):
+    def create(self, spin_num=None, spin_name=None, res_num=None, 
res_name=None, mol_name=None):
         """Function for creating a new spin.
 
         Keyword Arguments
@@ -128,7 +128,11 @@
 
         spin_name:  The name of the spin.
 
-        res_id:  The residue ID string identifying the residue to add the 
spin to.
+        res_num:  The number of the residue to add the spin to.
+
+        res_name:  The name of the residue to add the spin to.
+
+        mol_name:  The name of the molecule to add the spin to.
 
 
         Description
@@ -153,7 +157,9 @@
             text = sys.ps3 + "spin.create("
             text = text + "spin_num=" + `spin_num`
             text = text + ", spin_name=" + `spin_name`
-            text = text + ", res_id=" + `res_id` + ")"
+            text = text + ", res_num=" + `res_num`
+            text = text + ", res_name=" + `res_name`
+            text = text + ", mol_name=" + `mol_name` + ")"
             print text
 
         # Spin number.
@@ -164,12 +170,20 @@
         if spin_name != None and type(spin_name) != str:
             raise RelaxNoneStrError, ('spin name', spin_name)
 
-        # The residue ID.
-        if res_id != None and type(res_id) != str:
-            raise RelaxNoneStrError, ('residue identification string', 
res_id)
-
-        # Execute the functional code.
-        create_spin(spin_num=spin_num, spin_name=spin_name, res_id=res_id)
+        # The residue number.
+        if res_num != None and type(res_num) != int:
+            raise RelaxNoneIntError, ('residue number', res_num)
+
+        # The residue name.
+        if res_name != None and type(res_name) != str:
+            raise RelaxNoneStrError, ('residue name', res_name)
+
+        # The molecule name.
+        if mol_name != None and type(mol_name) != str:
+            raise RelaxNoneStrError, ('molecule name', mol_name)
+
+        # Execute the functional code.
+        create_spin(spin_num=spin_num, spin_name=spin_name, res_num=res_num, 
res_name=res_name, mol_name=mol_name)
 
 
     def delete(self, spin_id=None):

Modified: 1.3/test_suite/unit_tests/_prompt/test_residue.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/_prompt/test_residue.py?rev=8932&r1=8931&r2=8932&view=diff
==============================================================================
--- 1.3/test_suite/unit_tests/_prompt/test_residue.py (original)
+++ 1.3/test_suite/unit_tests/_prompt/test_residue.py Sun Mar  8 23:35:24 2009
@@ -118,17 +118,17 @@
             self.assertRaises(RelaxNoneStrError, self.residue_fns.create, 
res_name=data[1], res_num=1)
 
 
-    def test_create_argfail_mol_id(self):
-        """Test the proper failure of the residue.create() user function for 
the mol_id argument."""
-
-        # Loop over the data types.
-        for data in DATA_TYPES:
-            # Catch the None and str arguments, and skip them.
-            if data[0] == 'None' or data[0] == 'str':
-                continue
-
-            # The argument test.
-            self.assertRaises(RelaxNoneStrError, self.residue_fns.create, 
mol_id=data[1], res_num=1, res_name='NH')
+    def test_create_argfail_mol_name(self):
+        """Test the proper failure of the residue.create() user function for 
the mol_name argument."""
+
+        # Loop over the data types.
+        for data in DATA_TYPES:
+            # Catch the None and str arguments, and skip them.
+            if data[0] == 'None' or data[0] == 'str':
+                continue
+
+            # The argument test.
+            self.assertRaises(RelaxNoneStrError, self.residue_fns.create, 
mol_name=data[1], res_num=1, res_name='NH')
 
 
     def test_delete_argfail_res_id(self):

Modified: 1.3/test_suite/unit_tests/_prompt/test_spin.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/_prompt/test_spin.py?rev=8932&r1=8931&r2=8932&view=diff
==============================================================================
--- 1.3/test_suite/unit_tests/_prompt/test_spin.py (original)
+++ 1.3/test_suite/unit_tests/_prompt/test_spin.py Sun Mar  8 23:35:24 2009
@@ -118,17 +118,43 @@
             self.assertRaises(RelaxNoneStrError, self.spin_fns.create, 
spin_name=data[1], spin_num=1)
 
 
-    def test_create_argfail_res_id(self):
-        """Test the proper failure of the spin.create() user function for 
the res_id argument."""
-
-        # Loop over the data types.
-        for data in DATA_TYPES:
-            # Catch the None and str arguments, and skip them.
-            if data[0] == 'None' or data[0] == 'str':
-                continue
-
-            # The argument test.
-            self.assertRaises(RelaxNoneStrError, self.spin_fns.create, 
res_id=data[1], spin_num=1, spin_name='NH')
+    def test_create_argfail_res_num(self):
+        """Test the proper failure of the spin.create() user function for 
the res_num argument."""
+
+        # Loop over the data types.
+        for data in DATA_TYPES:
+            # Catch the int and bin arguments, and skip them.
+            if data[0] == 'None' or data[0] == 'int' or data[0] == 'bin':
+                continue
+
+            # The argument test.
+            self.assertRaises(RelaxNoneIntError, self.spin_fns.create, 
res_num=data[1], spin_name='NH')
+
+
+    def test_create_argfail_res_name(self):
+        """Test the proper failure of the spin.create() user function for 
the res_name argument."""
+
+        # Loop over the data types.
+        for data in DATA_TYPES:
+            # Catch the None and str arguments, and skip them.
+            if data[0] == 'None' or data[0] == 'str':
+                continue
+
+            # The argument test.
+            self.assertRaises(RelaxNoneStrError, self.spin_fns.create, 
res_name=data[1], spin_num=1, spin_name='NH')
+
+
+    def test_create_argfail_mol_name(self):
+        """Test the proper failure of the spin.create() user function for 
the mol_name argument."""
+
+        # Loop over the data types.
+        for data in DATA_TYPES:
+            # Catch the None and str arguments, and skip them.
+            if data[0] == 'None' or data[0] == 'str':
+                continue
+
+            # The argument test.
+            self.assertRaises(RelaxNoneStrError, self.spin_fns.create, 
mol_name=data[1], spin_num=1, spin_name='NH')
 
 
     def test_delete_argfail_spin_id(self):

Modified: 1.3/test_suite/unit_tests/spin_testing_base.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/spin_testing_base.py?rev=8932&r1=8931&r2=8932&view=diff
==============================================================================
--- 1.3/test_suite/unit_tests/spin_testing_base.py (original)
+++ 1.3/test_suite/unit_tests/spin_testing_base.py Sun Mar  8 23:35:24 2009
@@ -293,9 +293,9 @@
         """
 
         # Create a few new spins.
-        self.spin_fns.create(1, 'C3')
-        self.spin_fns.create(2, 'C17')
-        self.spin_fns.create(-3, 'N7', res_id='#New mol:6')
+        self.spin_fns.create(1, 'C3', res_num=1, mol_name='Old mol')
+        self.spin_fns.create(2, 'C17', res_num=1, mol_name='Old mol')
+        self.spin_fns.create(-3, 'N7', res_num=6, mol_name='New mol')
 
         # Get the data pipe.
         dp = pipes.get_pipe('orig')
@@ -319,10 +319,10 @@
         """
 
         # Create the first spin.
-        self.spin_fns.create(1, 'P1')
+        self.spin_fns.create(1, 'P1', res_num=1, mol_name='Old mol')
 
         # Assert that a RelaxError occurs when the next added spin has the 
same number as the first.
-        self.assertRaises(RelaxError, self.spin_fns.create, 1, 'P3')
+        self.assertRaises(RelaxError, self.spin_fns.create, 1, 'P3', 
res_num=1, mol_name='Old mol')
 
 
     def test_delete_spin_name(self):




Related Messages


Powered by MHonArc, Updated Sun Mar 08 23:40:05 2009