Author: bugman Date: Mon Oct 26 19:08:38 2009 New Revision: 9792 URL: http://svn.gna.org/viewcvs/relax?rev=9792&view=rev Log: Implemented the spin.element() user function. Modified: branches/bmrb/generic_fns/mol_res_spin.py branches/bmrb/prompt/spin.py Modified: branches/bmrb/generic_fns/mol_res_spin.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/generic_fns/mol_res_spin.py?rev=9792&r1=9791&r2=9792&view=diff ============================================================================== --- branches/bmrb/generic_fns/mol_res_spin.py (original) +++ branches/bmrb/generic_fns/mol_res_spin.py Mon Oct 26 19:08:38 2009 @@ -2200,6 +2200,41 @@ # The sequence is the same. return True + + +def set_spin_element(spin_id=None, element=None, force=False): + """Set the element type of the spins. + + @keyword spin_id: The spin identification string. + @type spin_id: str + @keyword element: The IUPAC element name. + @type element: str + @keyword force: A flag which if True will cause the element to be changed. + @type force: bool + """ + + # Valid names (for NMR active spins). + valid_names = ['H', + 'C', + 'N', + 'O', + 'F', + 'Na', + 'P', + 'Cd' + ] + + # Check. + if element not in valid_names: + raise(RelaxError("The element name '%s' is not valid and should be one of the IUPAC names %s." % (element, valid_names))) + + + # Set the element name for the matching spins. + for spin, id in spin_loop(spin_id, return_id=True): + if hasattr(spin, 'element') and spin.element and not force: + warn(RelaxWarning("The element type of the spin '%s' is already set. Set the force flag to True to rename." % id)) + else: + spin.element = element def spin_id_to_data_list(id): Modified: branches/bmrb/prompt/spin.py URL: http://svn.gna.org/viewcvs/relax/branches/bmrb/prompt/spin.py?rev=9792&r1=9791&r2=9792&view=diff ============================================================================== --- branches/bmrb/prompt/spin.py (original) +++ branches/bmrb/prompt/spin.py Mon Oct 26 19:08:38 2009 @@ -30,7 +30,7 @@ # relax module imports. from base_class import User_fn_class import check -from generic_fns.mol_res_spin import copy_spin, create_pseudo_spin, create_spin, delete_spin, display_spin, id_string_doc, name_spin, number_spin +from generic_fns.mol_res_spin import copy_spin, create_pseudo_spin, create_spin, delete_spin, display_spin, id_string_doc, name_spin, number_spin, set_spin_element class Spin(User_fn_class): @@ -259,6 +259,51 @@ # Execute the functional code. display_spin(spin_id=spin_id) + + + def element(self, spin_id=None, element=None, force=False): + """Set the element type of the spin. + + Keyword Arguments + ~~~~~~~~~~~~~~~~~ + + spin_id: The spin identification string corresponding to one or more spins. + + element: The IUPAC element name. + + force: A flag which if True will cause the element to be changed. + + + Description + ~~~~~~~~~~~ + + This function allows the element type of the spins to be set. + + + Examples + ~~~~~~~~ + + The set all spins of residue 1 to be carbons, type one of: + + relax> spin.element('@1', 'C', force=True) + relax> spin.element(spin_id='@1', element='C', force=True) + """ + + # Function intro text. + if self.__relax__.interpreter.intro: + text = sys.ps3 + "spin.element(" + text = text + "spin_id=" + repr(spin_id) + text = text + ", element=" + repr(element) + text = text + ", force=" + repr(force) + ")" + print(text) + + # The argument checks. + check.is_str(spin_id, 'spin identification string', can_be_none=True) + check.is_str(element, 'IUPAC element name') + check.is_bool(force, 'force flag') + + # Execute the functional code. + set_spin_element(spin_id=spin_id, element=element, force=force) def name(self, spin_id=None, name=None, force=False):