Author: bugman Date: Wed Apr 9 10:52:46 2008 New Revision: 5473 URL: http://svn.gna.org/viewcvs/relax?rev=5473&view=rev Log: Fixes for the SpinContainer.__repr__() method. This method was fubar! Modified: 1.3/data/mol_res_spin.py Modified: 1.3/data/mol_res_spin.py URL: http://svn.gna.org/viewcvs/relax/1.3/data/mol_res_spin.py?rev=5473&r1=5472&r2=5473&view=diff ============================================================================== --- 1.3/data/mol_res_spin.py (original) +++ 1.3/data/mol_res_spin.py Wed Apr 9 10:52:46 2008 @@ -57,6 +57,134 @@ # Intro. text = "Class containing all the spin system specific data.\n\n" + + # Objects. + text = text + "\n" + text = text + "Objects:\n" + for name in dir(self): + # Skip the SpinContainer methods. + if name == 'is_empty': + continue + + # Skip special objects. + if match("^__", name): + continue + + # Add the object's attribute to the text string. + text = text + " " + name + ": " + `getattr(self, name)` + "\n" + + return text + + + def is_empty(self): + """Method for testing if this SpinContainer object is empty. + + @return: True if this container is empty and the spin number and name have not been set, + False otherwise. + @rtype: bool + """ + + # The spin number or spin name has been set. + if self.num != None or self.name != None: + return False + + # An object has been added to the container. + for name in dir(self): + # Skip the objects initialised in __init__(). + if name == 'num' or name == 'name' or name == 'select': + continue + + # Skip the SpinContainer methods. + if name == 'is_empty': + continue + + # Skip special objects. + if match("^__", name): + continue + + # An object has been added. + return False + + # The SpinContainer is unmodified. + return True + + +class SpinList(list): + """List type data container for spin system specific data.""" + + def __init__(self): + """Set up the first spin system data container.""" + + # Add the initial spin system container at index 0. + self.append(SpinContainer()) + + + def __repr__(self): + """The string representation of the object. + + Rather than using the standard Python conventions (either the string representation of the + value or the "<...desc...>" notation), a rich-formatted description of the object is given. + """ + + # Intro. + text = "Spin systems.\n\n" + + # Residue data. + text = text + "%-8s%-8s%-8s%-10s" % ("Index", "Number", "Name", "Selected") + "\n" + for i in xrange(len(self)): + text = text + "%-8i%-8s%-8s%-10s" % (i, `self[i].num`, self[i].name, self[i].select) + "\n" + text = text + "\nThese can be accessed by typing 'D.mol[i].res[j].spin[k]', where D is the relax data storage object.\n" + + return text + + + def add_item(self, spin_name=None, spin_num=None, select=True): + """Function for appending an empty container to the list.""" + + # Test if the spin number already exists. + for i in xrange(len(self)): + if self[i].num == spin_num: + raise RelaxError, "The spin number '" + `spin_num` + "' already exists." + + # If no spin data exists, replace the empty first spin with this spin. + if len(self) == 1 and self[0].is_empty(): + self[0].num = spin_num + self[0].name = spin_name + self[0].select = select + + # Append the spin. + else: + self.append(SpinContainer(spin_name, spin_num, select)) + + + +# The residue data. +################### + +class ResidueContainer(Prototype): + """Class containing all the residue specific data.""" + + def __init__(self, res_name=None, res_num=None, select=True): + """Set up the default objects of the residue data container.""" + + # The residue name and number. + self.name = res_name + self.num = res_num + self.select = select + + # The empty spin system list. + self.spin = SpinList() + + + def __repr__(self): + """The string representation of the object. + + Rather than using the standard Python conventions (either the string representation of the + value or the "<...desc...>" notation), a rich-formatted description of the object is given. + """ + + # Intro. + text = "Class containing all the residue specific data.\n" # Objects. text = text + "\n" @@ -76,134 +204,6 @@ return text - def is_empty(self): - """Method for testing if this SpinContainer object is empty. - - @return: True if this container is empty and the spin number and name have not been set, - False otherwise. - @rtype: bool - """ - - # The spin number or spin name has been set. - if self.num != None or self.name != None: - return False - - # An object has been added to the container. - for name in dir(self): - # Skip the objects initialised in __init__(). - if name == 'num' or name == 'name' or name == 'select': - continue - - # Skip the SpinContainer methods. - if name == 'is_empty': - continue - - # Skip special objects. - if match("^__", name): - continue - - # An object has been added. - return False - - # The SpinContainer is unmodified. - return True - - -class SpinList(list): - """List type data container for spin system specific data.""" - - def __init__(self): - """Set up the first spin system data container.""" - - # Add the initial spin system container at index 0. - self.append(SpinContainer()) - - - def __repr__(self): - """The string representation of the object. - - Rather than using the standard Python conventions (either the string representation of the - value or the "<...desc...>" notation), a rich-formatted description of the object is given. - """ - - # Intro. - text = "Spin systems.\n\n" - - # Residue data. - text = text + "%-8s%-8s%-8s%-10s" % ("Index", "Number", "Name", "Selected") + "\n" - for i in xrange(len(self)): - text = text + "%-8i%-8s%-8s%-10s" % (i, `self[i].num`, self[i].name, self[i].select) + "\n" - text = text + "\nThese can be accessed by typing 'D.mol[i].res[j].spin[k]', where D is the relax data storage object.\n" - - return text - - - def add_item(self, spin_name=None, spin_num=None, select=True): - """Function for appending an empty container to the list.""" - - # Test if the spin number already exists. - for i in xrange(len(self)): - if self[i].num == spin_num: - raise RelaxError, "The spin number '" + `spin_num` + "' already exists." - - # If no spin data exists, replace the empty first spin with this spin. - if len(self) == 1 and self[0].is_empty(): - self[0].num = spin_num - self[0].name = spin_name - self[0].select = select - - # Append the spin. - else: - self.append(SpinContainer(spin_name, spin_num, select)) - - - -# The residue data. -################### - -class ResidueContainer(Prototype): - """Class containing all the residue specific data.""" - - def __init__(self, res_name=None, res_num=None, select=True): - """Set up the default objects of the residue data container.""" - - # The residue name and number. - self.name = res_name - self.num = res_num - self.select = select - - # The empty spin system list. - self.spin = SpinList() - - - def __repr__(self): - """The string representation of the object. - - Rather than using the standard Python conventions (either the string representation of the - value or the "<...desc...>" notation), a rich-formatted description of the object is given. - """ - - # Intro. - text = "Class containing all the residue specific data.\n" - - # Objects. - text = text + "\n" - text = text + "Objects:\n" - for name in dir(self): - # Spin systems. - if name == 'spin': - text = text + " spin: The list of spin systems of the residues\n" - - # Skip certain objects. - if match("^_", name) or name == 'spin': - continue - - # Add the object's attribute to the text string. - text = text + " " + name + ": " + `getattr(self, name)` + "\n" - - return text - - class ResidueList(list): """List type data container for residue specific data."""