Author: bugman Date: Sun Nov 4 17:28:45 2007 New Revision: 3416 URL: http://svn.gna.org/viewcvs/relax?rev=3416&view=rev Log: Created the molecule.create() user function. The user function and the function generic_fns.molecule.create() have been written. Two unit tests for the function have been created. Modified: 1.3/generic_fns/molecule.py 1.3/prompt/molecule.py 1.3/test_suite/unit_tests/generic_fns/test_molecule.py Modified: 1.3/generic_fns/molecule.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/molecule.py?rev=3416&r1=3415&r2=3416&view=diff ============================================================================== --- 1.3/generic_fns/molecule.py (original) +++ 1.3/generic_fns/molecule.py Sun Nov 4 17:28:45 2007 @@ -32,22 +32,21 @@ """ -def copy(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. +def copy(pipe_from=None, mol_from=None, pipe_to=None, mol_to=None): + """Copy the contents of a molecule container to a new molecule. + + 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. @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 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. @type pipe_to: str - @param res_to: The residue identification string for the structure to copy the data to. - @type res_to: str + @param mol_to: The molecule identification string for the structure to copy the data to. + @type mol_to: str """ # The current data pipe. @@ -99,8 +98,8 @@ mol_to_container.res[-1].name = res_name_to -def create(res_num=None, res_name=None): - """Function for adding a residue into the relax data store.""" +def create(mol_name=None): + """Function for adding a molecule into the relax data store.""" # Test if the current data pipe exists. if not relax_data_store.current_pipe: @@ -109,19 +108,18 @@ # Alias the current data pipe. cdp = relax_data_store[relax_data_store.current_pipe] - # Test if the residue number already exists. - for i in xrange(len(cdp.mol[0].res)): - if cdp.mol[0].res[i].num == res_num: - raise RelaxError, "The residue number '" + `res_num` + "' already exists in the sequence." - - # If no residue data exists, replace the empty first residue with this residue. - if cdp.mol[0].res[0].num == None and cdp.mol[0].res[0].name == None and len(cdp.mol[0].res) == 1: - cdp.mol[0].res[0].num = res_num - cdp.mol[0].res[0].name = res_name - - # Append the residue. + # Test if the molecule name already exists. + for i in xrange(len(cdp.mol)): + if cdp.mol[i].name == mol_name: + raise RelaxError, "The molecule '" + `mol_name` + "' already exists in the relax data store." + + # If no molecule data exists, replace the empty first molecule with this molecule (just a renaming). + if cdp.mol[0].name == None and len(cdp.mol[0].res) == 1 and len(cdp.mol[0].res[0].spin) == 1: + cdp.mol[0].name = mol_name + + # Append the molecule. else: - cdp.mol[0].res.add_item(res_num=res_num, res_name=res_name) + cdp.mol.add_item(mol_name=mol_name) def delete(res_id=None): Modified: 1.3/prompt/molecule.py URL: http://svn.gna.org/viewcvs/relax/1.3/prompt/molecule.py?rev=3416&r1=3415&r2=3416&view=diff ============================================================================== --- 1.3/prompt/molecule.py (original) +++ 1.3/prompt/molecule.py Sun Nov 4 17:28:45 2007 @@ -42,55 +42,44 @@ self.__relax__ = relax - def create(self, res_num=None, res_name=None): - """Function for creating a new residue. - - Keyword Arguments - ~~~~~~~~~~~~~~~~~ - - res_num: The residue number. - - res_name: The name of the residue. - - - Description - ~~~~~~~~~~~ - - Using this function a new sequence can be generated without using the sequence user - functions. However if the sequence already exists, the new residue will be added to the end - of the residue list (the residue numbers of this list need not be sequential). The same - residue number cannot be used more than once. A corresponding single spin system will be - created for this residue. The spin system number and name or additional spin systems can be - added later if desired. + def create(self, mol_name=None): + """Function for creating a new molecule. + + Keyword Arguments + ~~~~~~~~~~~~~~~~~ + + mol_name: The name of the molecule. + + + Description + ~~~~~~~~~~~ + + This function will add a new molecule data container to the relax data storage object. The + same molecule name cannot be used more than once. Examples ~~~~~~~~ - The following sequence of commands will generate the sequence 1 ALA, 2 GLY, 3 LYS: - - relax> residue.create(1, 'ALA') - relax> residue.create(2, 'GLY') - relax> residue.create(3, 'LYS') - """ - - # Function intro text. - if self.__relax__.interpreter.intro: - text = sys.ps3 + "residue.create(" - text = text + ", res_num=" + `res_num` - text = text + ", res_name=" + `res_name` + ")" - print text - - # Residue number. - if type(res_num) != int: - raise RelaxIntError, ('residue number', res_num) - - # Residue name. - if type(res_name) != str: - raise RelaxStrError, ('residue name', res_name) - - # Execute the functional code. - residue.create(res_num=res_num, res_name=res_name) + To create the molecules 'Ap4Aase', 'ATP', and 'MgF4', type: + + relax> molecule.create('Ap4Aase') + relax> molecule.create('ATP') + relax> molecule.create('MgF4') + """ + + # Function intro text. + if self.__relax__.interpreter.intro: + text = sys.ps3 + "molecule.create(" + text = text + "mol_name=" + `mol_name` + ")" + print text + + # Molecule name. + if type(mol_name) != str: + raise RelaxStrError, ('molecule name', mol_name) + + # Execute the functional code. + molecule.create(mol_name=mol_name) def copy(self, run1=None, run2=None): Modified: 1.3/test_suite/unit_tests/generic_fns/test_molecule.py URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/generic_fns/test_molecule.py?rev=3416&r1=3415&r2=3416&view=diff ============================================================================== --- 1.3/test_suite/unit_tests/generic_fns/test_molecule.py (original) +++ 1.3/test_suite/unit_tests/generic_fns/test_molecule.py Sun Nov 4 17:28:45 2007 @@ -24,15 +24,17 @@ from unittest import TestCase # relax module imports. +from data import Data as relax_data_store from generic_fns import molecule +from relax_errors import RelaxError -class Test_spin(TestCase): +class Test_molecule(TestCase): """Unit tests for the functions of the 'generic_fns.molecule' module.""" def setUp(self): - """Set up for all the residue unit tests.""" + """Set up for all the molecule unit tests.""" # Reset the relax data storage object. relax_data_store.__reset__() @@ -74,4 +76,32 @@ relax_data_store['orig'].mol[0].res[0].spin[0].x = 2 + def test_creation(self): + """Test the creation of a molecule data structure. + The function used is generic_fns.molecule.create(). + """ + + # Create a few new molecules. + molecule.create('Ap4Aase') + molecule.create('ATP') + molecule.create(mol_name='MgF4') + + # Test that the molecule names are correct. + self.assertEqual(relax_data_store['orig'].mol[0].name, 'Ap4Aase') + self.assertEqual(relax_data_store['orig'].mol[1].name, 'ATP') + self.assertEqual(relax_data_store['orig'].mol[2].name, 'MgF4') + + + def test_creation_fail(self): + """Test the failure of molecule creation by supplying two molecules with the same name. + + The function used is generic_fns.molecule.create(). + """ + + # Create the first molecule. + molecule.create('CaM') + + # Assert that a RelaxError occurs when the next added molecule has the same name as the first. + self.assertRaises(RelaxError, molecule.create, 'CaM') +