Author: bugman Date: Fri Mar 6 14:29:19 2009 New Revision: 8916 URL: http://svn.gna.org/viewcvs/relax?rev=8916&view=rev Log: The force flag has been introduced to the mol/res/spin naming and numbering functions. The default is now not to overwrite. Modified: 1.3/generic_fns/mol_res_spin.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=8916&r1=8915&r2=8916&view=diff ============================================================================== --- 1.3/generic_fns/mol_res_spin.py (original) +++ 1.3/generic_fns/mol_res_spin.py Fri Mar 6 14:29:19 2009 @@ -1340,13 +1340,15 @@ yield mol -def name_molecule(mol_id, name=None): +def name_molecule(mol_id, name=None, force=False): """Name the molecules. @param mol_id: The molecule identification string. @type mol_id: str @param name: The new molecule name. @type name: str + @keyword force: A flag which if True will cause the named molecule to be renamed. + @type force: bool """ # Get the single molecule data container. @@ -1361,16 +1363,21 @@ # Name the molecule is there is a single match. if mol: - mol.name = name + if mol.name and not force: + warn(RelaxWarning("The molecule '%s' is already named. Set the force flag to rename." % mol_id)) + else: + mol.name = name -def name_residue(res_id, name=None): +def name_residue(res_id, name=None, force=False): """Name the residues. @param res_id: The residue identification string. @type res_id: str @param name: The new residue name. @type name: str + @keyword force: A flag which if True will cause the named residue to be renamed. + @type force: bool """ # Disallow spin selections. @@ -1379,31 +1386,41 @@ raise RelaxSpinSelectDisallowError # Rename the matching residues. - for res in residue_loop(res_id): - res.name = name - - -def name_spin(spin_id=None, name=None): + for res, mol_name in residue_loop(res_id, full_info=True): + if res.name and not force: + warn(RelaxWarning("The residue '%s' is already named. Set the force flag to rename." % generate_spin_id(mol_name, res.num, res.name))) + else: + res.name = name + + +def name_spin(spin_id=None, name=None, force=False): """Name the spins. - @param spin_id: The spin identification string. + @keyword spin_id: The spin identification string. @type spin_id: str - @param name: The new spin name. + @keyword name: The new spin name. @type name: str + @keyword force: A flag which if True will cause the named spin to be renamed. + @type force: bool """ # Rename the matching spins. - for spin in spin_loop(spin_id): - spin.name = name - - -def number_residue(res_id, number=None): + for spin, id in spin_loop(spin_id, return_id=True): + if spin.name and not force: + warn(RelaxWarning("The spin '%s' is already named. Set the force flag to rename." % id)) + else: + spin.name = name + + +def number_residue(res_id, number=None, force=False): """Number the residues. @param res_id: The residue identification string. @type res_id: str @param number: The new residue number. @type number: int + @keyword force: A flag which if True will cause the numbered residue to be renumbered. + @type force: bool """ # Catch multiple numberings! @@ -1421,17 +1438,22 @@ raise RelaxSpinSelectDisallowError # Rename the residue. - for res in residue_loop(res_id): - res.num = number - - -def number_spin(spin_id=None, number=None): + for res, mol_name in residue_loop(res_id, full_info=True): + if res.num and not force: + warn(RelaxWarning("The residue '%s' is already numbered. Set the force flag to renumber." % generate_spin_id(mol_name, res.num, res.name))) + else: + res.num = number + + +def number_spin(spin_id=None, number=None, force=False): """Number the spins. @param spin_id: The spin identification string. @type spin_id: str @param number: The new spin number. @type number: int + @keyword force: A flag which if True will cause the numbered spin to be renumbered. + @type force: bool """ # Catch multiple renumberings! @@ -1444,8 +1466,11 @@ raise RelaxError, "The numbering of multiple spins is disallowed, as each spin requires a unique number." # Rename the spin. - for spin in spin_loop(spin_id): - spin.num = number + for spin, id in spin_loop(spin_id, return_id=True): + if spin.num and not force: + warn(RelaxWarning("The spin '%s' is already numbered. Set the force flag to renumber." % id)) + else: + spin.num = number def parse_token(token, verbosity=False):