Author: bugman Date: Sun Nov 4 14:37:59 2007 New Revision: 3405 URL: http://svn.gna.org/viewcvs/relax?rev=3405&view=rev Log: Created the residue.display() user function. This has been added to the data model redesign document. Two unit tests have also been created for the function. Modified: 1.3/docs/data_model_redesign 1.3/generic_fns/residue.py 1.3/prompt/residue.py 1.3/test_suite/unit_tests/generic_fns/test_residue.py Modified: 1.3/docs/data_model_redesign URL: http://svn.gna.org/viewcvs/relax/1.3/docs/data_model_redesign?rev=3405&r1=3404&r2=3405&view=diff ============================================================================== --- 1.3/docs/data_model_redesign (original) +++ 1.3/docs/data_model_redesign Sun Nov 4 14:37:59 2007 @@ -72,6 +72,7 @@ residue.copy() residue.create() # This is currently named 'sequence.add()'. residue.delete() + residue.display() residue.rename() residue.renumber() Modified: 1.3/generic_fns/residue.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/residue.py?rev=3405&r1=3404&r2=3405&view=diff ============================================================================== --- 1.3/generic_fns/residue.py (original) +++ 1.3/generic_fns/residue.py Sun Nov 4 14:37:59 2007 @@ -158,6 +158,43 @@ mol.res.add_item() +def display(res_id=None): + """Function for displaying the information associated with the residue. + + @param res_id: The molecule and residue identifier string. + @type res_id: str + """ + + # Split up the selection string. + mol_token, res_token, spin_token = tokenise(res_id) + + # Disallow spin selections. + if spin_token != None: + raise RelaxSpinSelectDisallowError + + # The molecule selection string. + if mol_token: + mol_sel = '#' + mol_token + else: + mol_sel = None + + # Molecule loop. + for mol in molecule_loop(mol_sel): + # Print a header. + print "\n\nMolecule: " + `mol.name` + print "%-8s%-8s%-10s" % ("Number", "Name", "Number of spins") + + # The residue identifier for this molecule. + res_sel = '#' + mol.name + if res_token: + res_sel = res_sel + ':' + res_token + + # Loop over the residues of this molecule. + for res in residue_loop(res_sel): + # Print the residue data. + print "%-8i%-8s%-10i" % (res.num, res.name, len(res.spin)) + + def rename(res_id, new_name=None): """Function for renaming residues. @@ -239,24 +276,6 @@ return [ 'res' ] - - def display(self, run=None): - """Function for displaying the sequence.""" - - # Test if the run exists. - if not run in relax_data_store.run_names: - raise RelaxNoPipeError, run - - # Test if the sequence data is loaded. - if not relax_data_store.res.has_key(run): - raise RelaxNoSequenceError, run - - # Print a header. - print "%-8s%-8s%-10s" % ("Number", "Name", "Selected") - - # Print the sequence. - for i in xrange(len(relax_data_store.res[run])): - print "%-8i%-8s%-10i" % (relax_data_store.res[run][i].num, relax_data_store.res[run][i].name, relax_data_store.res[run][i].select) def load_PDB_sequence(self, run=None): Modified: 1.3/prompt/residue.py URL: http://svn.gna.org/viewcvs/relax/1.3/prompt/residue.py?rev=3405&r1=3404&r2=3405&view=diff ============================================================================== --- 1.3/prompt/residue.py (original) +++ 1.3/prompt/residue.py Sun Nov 4 14:37:59 2007 @@ -198,27 +198,27 @@ residue.delete(res_id=res_id) - def display(self, run=None): - """Function for displaying the sequence. - - Keyword Arguments - ~~~~~~~~~~~~~~~~~ - - run: The name of the run. - """ - - # Function intro text. - if self.__relax__.interpreter.intro: - text = sys.ps3 + "sequence.display(" - text = text + "run=" + `run` + ")" - print text - - # The run argument. - if type(run) != str: - raise RelaxStrError, ('run', run) - - # Execute the functional code. - self.__relax__.generic.sequence.display(run=run) + def display(self, res_id=None): + """Function for displaying information about the residue(s). + + Keyword Arguments + ~~~~~~~~~~~~~~~~~ + + res_id: The residue identification string. + """ + + # Function intro text. + if self.__relax__.interpreter.intro: + text = sys.ps3 + "residue.display(" + text = text + "res_id=" + `res_id` + ")" + print text + + # The res_id argument. + if type(res_id) != str: + raise RelaxStrError, ('residue identification string', res_id) + + # Execute the functional code. + residue.display(res_id=res_id) def rename(self, res_id=None, new_name=None): @@ -328,5 +328,6 @@ # Add the residue identification string description. copy.__doc__ = copy.__doc__ + "\n\n" + id_string_doc + "\n" delete.__doc__ = delete.__doc__ + "\n\n" + id_string_doc + "\n" + display.__doc__ = display.__doc__ + "\n\n" + id_string_doc + "\n" rename.__doc__ = rename.__doc__ + "\n\n" + id_string_doc + "\n" renumber.__doc__ = renumber.__doc__ + "\n\n" + id_string_doc + "\n" Modified: 1.3/test_suite/unit_tests/generic_fns/test_residue.py URL: http://svn.gna.org/viewcvs/relax/1.3/test_suite/unit_tests/generic_fns/test_residue.py?rev=3405&r1=3404&r2=3405&view=diff ============================================================================== --- 1.3/test_suite/unit_tests/generic_fns/test_residue.py (original) +++ 1.3/test_suite/unit_tests/generic_fns/test_residue.py Sun Nov 4 14:37:59 2007 @@ -55,12 +55,7 @@ relax_data_store.__reset__() - def test_copy_between_molecules(self): - """Test the copying of the residue data between different molecules. - - The function used is generic_fns.residue.copy(). - """ - + def setup_data(self): # Create the first residue and add some data to its spin container. residue.create(1, 'Ala') relax_data_store['orig'].mol[0].res[0].spin[0].num = 111 @@ -77,6 +72,16 @@ # Change the first residue's data. relax_data_store['orig'].mol[0].res[0].spin[0].num = 222 relax_data_store['orig'].mol[0].res[0].spin[0].x = 2 + + + def test_copy_between_molecules(self): + """Test the copying of the residue data between different molecules. + + The function used is generic_fns.residue.copy(). + """ + + # Set up some data. + self.setup_data() # Test the original residue. self.assertEqual(relax_data_store['orig'].mol[0].res[0].num, 1) @@ -359,6 +364,35 @@ self.assertRaises(RelaxSpinSelectDisallowError, residue.delete, res_id='@2') + def test_display(self): + """Test the display of residue information. + + The function used is generic_fns.residue.display(). + """ + + # Set up some data. + self.setup_data() + + # The following should all work without error. + residue.display() + residue.display(':1') + residue.display('#New mol:5') + residue.display('#Old mol:1') + + + def test_display_fail(self): + """Test the failure of the display of residue information. + + The function used is generic_fns.residue.display(). + """ + + # Set up some data. + self.setup_data() + + # The following should fail. + self.assertRaises(RelaxSpinSelectDisallowError, residue.display, '@N') + + def test_rename(self): """Test the renaming of a residue.