Author: bugman Date: Tue Dec 18 10:50:14 2012 New Revision: 18159 URL: http://svn.gna.org/viewcvs/relax?rev=18159&view=rev Log: Created the select.domain user function front and backend. Modified: branches/frame_order_testing/generic_fns/selection.py branches/frame_order_testing/user_functions/select.py Modified: branches/frame_order_testing/generic_fns/selection.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/generic_fns/selection.py?rev=18159&r1=18158&r2=18159&view=diff ============================================================================== --- branches/frame_order_testing/generic_fns/selection.py (original) +++ branches/frame_order_testing/generic_fns/selection.py Tue Dec 18 10:50:14 2012 @@ -27,9 +27,9 @@ # relax module imports. from generic_fns.interatomic import interatomic_loop -from generic_fns.mol_res_spin import exists_mol_res_spin_data, generate_spin_id, return_spin, spin_loop +from generic_fns.mol_res_spin import Selection, exists_mol_res_spin_data, generate_spin_id, return_spin, spin_loop from generic_fns import pipes -from relax_errors import RelaxError, RelaxNoSequenceError +from relax_errors import RelaxError, RelaxNoDomainError, RelaxNoSequenceError from relax_io import read_spin_data from relax_warnings import RelaxNoSpinWarning from user_functions.data import Uf_tables; uf_tables = Uf_tables() @@ -361,6 +361,77 @@ spin.select = True +def sel_domain(domain_id=None, boolean='OR', change_all=False): + """Select all spins and interatomic data containers of the given domain. + + @keyword domain_id: The domain ID string. + @type domain_id: str or None + @param boolean: The boolean operator used to select the spin systems with. It can be one of 'OR', 'NOR', 'AND', 'NAND', 'XOR', or 'XNOR'. This will be ignored if the change_all flag is set. + @type boolean: str + @keyword change_all: A flag which if True will cause all spins and interatomic data containers outside of the domain to be deselected. + @type change_all: bool + """ + + # Test if the current data pipe exists. + pipes.test() + + # Test if the domain is defined. + if not hasattr(cdp, 'domain') or domain_id not in cdp.domain: + raise RelaxNoDomainError(domain_id) + + # The domain selection object. + domain = Selection(cdp.domain[domain_id]) + + # Loop over the spins and select as required. + for spin, spin_id in spin_loop(return_id=True): + # Deselect spins outside of the domain. + if spin_id not in domain and change_all: + print "out: %s" % spin_id + spin.select = False + + # Inside the domain. + if spin_id in domain: + if boolean == 'OR': + print "OR: %s" % spin_id + spin.select = spin.select or True + elif boolean == 'NOR': + spin.select = not (spin.select or True) + elif boolean == 'AND': + spin.select = spin.select and True + elif boolean == 'NAND': + spin.select = not (spin.select and True) + elif boolean == 'XOR': + spin.select = not (spin.select and True) and (spin.select or True) + elif boolean == 'XNOR': + spin.select = (spin.select and True) or not (spin.select or True) + else: + raise RelaxError("Unknown boolean operator " + repr(boolean)) + + # Interatomic data loop. + for interatom in interatomic_loop(): + # Deselect containers outside of the domain. + if (interatom.spin_id1 not in domain and interatom.spin_id2 not in domain) and change_all: + interatom.select = False + + # Inside the domain. + if interatom.spin_id1 in domain or interatom.spin_id2 in domain: + if boolean == 'OR': + interatom.select = interatom.select or True + elif boolean == 'NOR': + interatom.select = not (interatom.select or True) + elif boolean == 'AND': + interatom.select = interatom.select and True + elif boolean == 'NAND': + interatom.select = not (interatom.select and True) + elif boolean == 'XOR': + interatom.select = not (interatom.select and True) and (interatom.select or True) + elif boolean == 'XNOR': + interatom.select = (interatom.select and True) or not (interatom.select or True) + else: + raise RelaxError("Unknown boolean operator " + repr(boolean)) + + + def sel_interatom(spin_id1=None, spin_id2=None, boolean='OR', change_all=False): """Select specific interatomic data containers. Modified: branches/frame_order_testing/user_functions/select.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/user_functions/select.py?rev=18159&r1=18158&r2=18159&view=diff ============================================================================== --- branches/frame_order_testing/user_functions/select.py (original) +++ branches/frame_order_testing/user_functions/select.py Tue Dec 18 10:50:14 2012 @@ -30,7 +30,7 @@ FD_OPEN = -1 # relax module imports. -from generic_fns import selection +from generic_fns import domain, selection from graphics import WIZARD_IMAGE_PATH from user_functions.data import Uf_info; uf_info = Uf_info() from user_functions.objects import Desc_container @@ -62,30 +62,24 @@ uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' -# The select.interatom user function. -uf = uf_info.add_uf("select.interatom") -uf.title = "Select specific interatomic data containers." -uf.title_short = "Interatomic data container selection." -uf.display = True -uf.add_keyarg( - name = "spin_id1", - py_type = "str", - arg_type = "spin ID", - desc_short = "first spin ID string", - desc = "The spin ID string of the first spin of the interatomic data container.", - can_be_none = True -) -uf.add_keyarg( - name = "spin_id2", - py_type = "str", - arg_type = "spin ID", - desc_short = "second spin ID string", - desc = "The spin ID string of the second spin of the interatomic data container.", - can_be_none = True +# The select.domain user function. +uf = uf_info.add_uf("select.domain") +uf.title = "Select all spins and interatomic data containers of a domain." +uf.title_short = "Selection of whole domains." +uf.display = True +uf.add_keyarg( + name = "domain_id", + py_type = "str", + arg_type = "domain ID", + desc_short = "domain ID string", + desc = "The domain ID string of the domain to select.", + wiz_element_type = 'combo', + wiz_combo_iter = domain.get_domain_ids, + can_be_none = False ) uf.add_keyarg( name = "boolean", - default = "OR", + default = "AND", py_type = "str", desc_short = "boolean operator", desc = "The boolean operator specifying how interatomic data containers should be selected.", @@ -102,6 +96,71 @@ ) uf.add_keyarg( name = "change_all", + default = True, + py_type = "bool", + desc_short = "change all flag", + desc = "A flag specifying if all non-matching spin and interatomic data containers should be deselected." +) +# Description. +uf.desc.append(Desc_container()) +uf.desc[-1].add_paragraph("This will select all spins and interatomic data containers of a given domain. This is defined by the domain ID string as specified by the previously executed domain-related user functions.") +uf.desc.append(selection.boolean_doc) +# Prompt examples. +uf.desc.append(Desc_container("Prompt examples")) +uf.desc[-1].add_paragraph("To select all spins of the domain 'N-dom', simply type one of:") +uf.desc[-1].add_prompt("relax> select.domain('N-dom', change_all=True)") +uf.desc[-1].add_prompt("relax> select.domain(domain_id='N-dom', change_all=True)") +uf.desc[-1].add_paragraph("To select all spins of the domain 'N-dom', preserving the current selections, simply type one of:") +uf.desc[-1].add_prompt("relax> select.domain('N-dom', 'AND', True)") +uf.desc[-1].add_prompt("relax> select.domain(domain_id='N-dom', boolean='AND', change_all=True)") +uf.backend = selection.sel_domain +uf.menu_text = "&domain" +uf.wizard_height_desc = 500 +uf.wizard_size = (1000, 750) +uf.wizard_apply_button = True +uf.wizard_image = WIZARD_IMAGE_PATH + 'select.png' + + +# The select.interatom user function. +uf = uf_info.add_uf("select.interatom") +uf.title = "Select specific interatomic data containers." +uf.title_short = "Interatomic data container selection." +uf.display = True +uf.add_keyarg( + name = "spin_id1", + py_type = "str", + arg_type = "spin ID", + desc_short = "first spin ID string", + desc = "The spin ID string of the first spin of the interatomic data container.", + can_be_none = True +) +uf.add_keyarg( + name = "spin_id2", + py_type = "str", + arg_type = "spin ID", + desc_short = "second spin ID string", + desc = "The spin ID string of the second spin of the interatomic data container.", + can_be_none = True +) +uf.add_keyarg( + name = "boolean", + default = "OR", + py_type = "str", + desc_short = "boolean operator", + desc = "The boolean operator specifying how interatomic data containers should be selected.", + wiz_element_type = "combo", + wiz_combo_choices = [ + "OR", + "NOR", + "AND", + "NAND", + "XOR", + "XNOR" + ], + wiz_read_only = True +) +uf.add_keyarg( + name = "change_all", default = False, py_type = "bool", desc_short = "change all",